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