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