2 * \file FormMathsDelim.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
16 #include "FormMathsDelim.h"
17 #include "forms/form_maths_delim.h"
18 #include "ControlMath.h"
23 #include "controllers/ButtonController.h"
25 #include "support/std_sstream.h"
27 using std::ostringstream;
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
42 int const delim_size =
43 sizeof(delim_rversion) / sizeof(delim_rversion[0]);
45 char const * delim_values[] = {
46 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
47 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
48 "{", "}", "/", "backslash", "downarrow", "Downarrow",
49 "langle", "rangle", "|", "Vert", ".", 0
56 typedef FormController<ControlMath, FormView<FD_maths_delim> > base_class;
58 FormMathsDelim::FormMathsDelim(Dialog & parent)
59 : base_class(parent, _("Math Delimiters"), false)
63 void FormMathsDelim::build()
65 dialog_.reset(build_maths_delim(this));
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;
74 fl_set_bmtable_data(dialog_->bmtable, 12, 2,
75 delim_width, delim_height, delim_bits);
76 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
78 bcview().setOK(dialog_->button_ok);
79 bcview().setApply(dialog_->button_apply);
80 bcview().setCancel(dialog_->button_close);
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);
90 void FormMathsDelim::apply()
92 int const left = int(dialog_->radio_left->u_ldata);
93 int const right = int(dialog_->radio_right->u_ldata);
96 os << delim_values[left] << ' ' << delim_values[right];
97 controller().dispatchDelim(os.str());
101 void FormMathsDelim::update()
107 ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
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);
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);
119 if (side || (button == FL_RIGHT_MOUSE))
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) {
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));
141 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
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);
147 dialog_->radio_left->u_ldata = left;
148 dialog_->radio_right->u_ldata = right;
150 return ButtonPolicy::SMI_VALID;
153 } // namespace frontend