]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsDelim.C
the lfun3 patches (overall cleanup and "localizing" dispatch() in mathed)
[lyx.git] / src / frontends / xforms / FormMathsDelim.C
1 /**
2  * \file FormMathsDelim.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli, pdenapo@dm.uba.ar
8  * \author John Levon, moz@compsoc.man.ac.uk
9  * \author Angus Leeming, a.leeming@ic.ac.uk
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "FormMathsDelim.h"
19 #include "forms/form_maths_delim.h"
20 #include "Dialogs.h"
21 #include "frontends/LyXView.h"
22 #include "bmtable.h"
23 #include "debug.h"
24 #include "funcrequest.h"
25 #include "Lsstream.h"
26 #include FORMS_H_LOCATION
27
28 #include "delim.xbm"
29 #include "delim0.xpm"
30 #include "delim1.xpm"
31
32
33 static int const delim_rversion[] = {
34         1,1,3,3,4,5,7,7,9,9,10,11,
35         13,13,14,15,16,17,19,19,20,21,22,23
36 };
37
38
39 static char const * delim_values[] = {
40         "(", ")", "lceil",  "rceil",  "uparrow",  "Uparrow",
41         "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
42         "{", "}",  "/", "\\",  "downarrow",  "Downarrow",
43         "langle",  "rangle", "|", "Vert", ".", 0
44 };
45
46 using std::endl;
47
48 FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d,
49                                FormMathsPanel const & p)
50         : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
51 {}
52
53
54 FL_FORM * FormMathsDelim::form() const
55 {
56         if (dialog_.get())
57                 return dialog_->form;
58         return 0;
59 }
60
61
62 void FormMathsDelim::build()
63 {
64         dialog_.reset(build_maths_delim(this));
65
66         fl_set_button(dialog_->radio_left, 1);
67         // Initialize button_pix to "()" as found in images/delim0.xpm:
68         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
69         dialog_->radio_left->u_ldata = 0;
70         dialog_->radio_right->u_ldata = 1;
71         //dialog_->radio_both->u_ldata = 2;
72
73         fl_set_bmtable_data(dialog_->bmtable, 12, 2,
74                             delim_width, delim_height, delim_bits);
75         fl_set_bmtable_maxitems(dialog_->bmtable, 23);
76
77         bc().setOK(dialog_->button_ok);
78         bc().setApply(dialog_->button_apply);
79         bc().setCancel(dialog_->button_close);
80
81         bc().addReadOnly(dialog_->bmtable);
82         bc().addReadOnly(dialog_->radio_right);
83         bc().addReadOnly(dialog_->radio_left);
84         bc().addReadOnly(dialog_->radio_both);
85         bc().addReadOnly(dialog_->button_pix);
86 }
87
88
89 void FormMathsDelim::apply()
90 {
91         int const left  = int(dialog_->radio_left->u_ldata);
92         int const right = int(dialog_->radio_right->u_ldata);
93
94         ostringstream os;
95         os << delim_values[left] << ' ' << delim_values[right];
96
97         lv_->dispatch(FuncRequest(LFUN_MATH_DELIM, os.str().c_str()));
98 }
99
100
101 bool FormMathsDelim::input(FL_OBJECT *, long)
102 {
103         int left = int(dialog_->radio_left->u_ldata);
104         int right= int(dialog_->radio_right->u_ldata);
105         int const side = (fl_get_button(dialog_->radio_right) != 0);
106
107         int const i = fl_get_bmtable(dialog_->bmtable);
108         int const button = fl_get_bmtable_numb(dialog_->bmtable);
109         bool const both = (button == FL_MIDDLE_MOUSE ||
110                            fl_get_button(dialog_->radio_both) != 0);
111
112         if (i >= 0) {
113                 if (side || (button == FL_RIGHT_MOUSE))
114                         right = i;
115                 else {
116                         left = i;
117                         if (both) {
118                                 right = delim_rversion[i];
119                                 // Add left delimiter in "both" case if right one was pressed:
120                                 for (int j = 0; j <= 23; ++j) {
121                                         if (delim_rversion[j] == left) {
122                                                 right = left;
123                                                 left = j;
124                                         }
125                                 }
126                         }
127                 }
128         }
129
130         // Re-initialize button_pix to solid blue 
131         // (not elegant but works, MV 24.5.2002)
132         fl_free_pixmap_pixmap(dialog_->button_pix);
133         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
134         Pixmap p1;
135         fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
136         
137         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
138         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
139         fl_redraw_object(dialog_->button_pix);
140
141         dialog_->radio_left->u_ldata  = left;
142         dialog_->radio_right->u_ldata = right;
143
144         return true;
145 }