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