]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsDelim.C
remove defaults stuff, let Qt handle no toolbar
[lyx.git] / src / frontends / xforms / FormMathsDelim.C
1 /**
2  * \file FormMathsDelim.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #include <config.h>
15
16
17 #include "FormMathsDelim.h"
18 #include "forms/form_maths_delim.h"
19 #include "ControlMath.h"
20 #include "xformsBC.h"
21 #include "ButtonController.h"
22
23 #include "bmtable.h"
24
25 #include "support/lstrings.h"
26
27 #include "Lsstream.h"
28
29 #include FORMS_H_LOCATION
30
31 #include "delim.xbm"
32 #include "delim0.xpm"
33 #include "delim1.xpm"
34
35
36 static int const delim_rversion[] = {
37 1,1,3,3,4,5,7,7,9,9,10,11,
38
39 };
40
41
42 static char const * delim_values[] = {
43         "(", ")", "lceil",  "rceil",  "uparrow",  "Uparrow",
44         "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
45         "{", "}",  "/", "backslash",  "downarrow",  "Downarrow",
46         "langle",  "rangle", "|", "Vert", ".", 0
47 };
48
49 using std::endl;
50
51
52 typedef FormCB<ControlMathSub, FormDB<FD_maths_delim> > base_class;
53
54 FormMathsDelim::FormMathsDelim()
55         : base_class(_("Maths Delimiters"), false)
56 {}
57
58
59 void FormMathsDelim::build()
60 {
61         dialog_.reset(build_maths_delim(this));
62
63         fl_set_button(dialog_->radio_left, 1);
64         // Initialize button_pix to "()" as found in images/delim0.xpm:
65         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
66         dialog_->radio_left->u_ldata = 0;
67         dialog_->radio_right->u_ldata = 1;
68         //dialog_->radio_both->u_ldata = 2;
69
70         fl_set_bmtable_data(dialog_->bmtable, 12, 2,
71                             delim_width, delim_height, delim_bits);
72         fl_set_bmtable_maxitems(dialog_->bmtable, 23);
73
74         bcview().setOK(dialog_->button_ok);
75         bcview().setApply(dialog_->button_apply);
76         bcview().setCancel(dialog_->button_close);
77
78         bcview().addReadOnly(dialog_->bmtable);
79         bcview().addReadOnly(dialog_->radio_right);
80         bcview().addReadOnly(dialog_->radio_left);
81         bcview().addReadOnly(dialog_->radio_both);
82         bcview().addReadOnly(dialog_->button_pix);
83 }
84
85
86 void FormMathsDelim::apply()
87 {
88         int const left  = int(dialog_->radio_left->u_ldata);
89         int const right = int(dialog_->radio_right->u_ldata);
90
91         ostringstream os;
92         os << delim_values[left] << ' ' << delim_values[right];
93         controller().dispatchFunc(LFUN_MATH_DELIM, STRCONV(os.str()));
94 }
95
96
97 void FormMathsDelim::update()
98 {
99         bc().valid();
100 }
101
102
103 ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
104 {
105         int left = int(dialog_->radio_left->u_ldata);
106         int right= int(dialog_->radio_right->u_ldata);
107         int const side = (fl_get_button(dialog_->radio_right) != 0);
108
109         int const i = fl_get_bmtable(dialog_->bmtable);
110         int const button = fl_get_bmtable_numb(dialog_->bmtable);
111         bool const both = (button == FL_MIDDLE_MOUSE ||
112                            fl_get_button(dialog_->radio_both) != 0);
113
114         if (i >= 0) {
115                 if (side || (button == FL_RIGHT_MOUSE))
116                         right = i;
117                 else {
118                         left = i;
119                         if (both) {
120                                 right = delim_rversion[i];
121                                 // Add left delimiter in "both" case if right one was pressed:
122                                 for (int j = 0; j <= 23; ++j) {
123                                         if (delim_rversion[j] == left) {
124                                                 right = left;
125                                                 left = j;
126                                         }
127                                 }
128                         }
129                 }
130         }
131
132         // Re-initialize button_pix to solid blue
133         // (not elegant but works, MV 24.5.2002)
134         fl_free_pixmap_pixmap(dialog_->button_pix);
135         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
136         Pixmap p1;
137         fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
138
139         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
140         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
141         fl_redraw_object(dialog_->button_pix);
142
143         dialog_->radio_left->u_ldata  = left;
144         dialog_->radio_right->u_ldata = right;
145
146         return ButtonPolicy::SMI_VALID;
147 }