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
17 #pragma implementation
20 #include "FormMathsDelim.h"
21 #include "forms/form_maths_delim.h"
22 #include "ControlMath.h"
27 #include "support/lstrings.h"
31 #include FORMS_H_LOCATION
38 static int const delim_rversion[] = {
39 1,1,3,3,4,5,7,7,9,9,10,11,
40 13,13,14,15,16,17,19,19,20,21,22,23
44 static char const * delim_values[] = {
45 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
46 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
47 "{", "}", "/", "backslash", "downarrow", "Downarrow",
48 "langle", "rangle", "|", "Vert", ".", 0
54 typedef FormCB<ControlMathSub, FormDB<FD_maths_delim> > base_class;
56 FormMathsDelim::FormMathsDelim()
57 : base_class(_("Maths Delimiters"), false)
61 void FormMathsDelim::build()
63 dialog_.reset(build_maths_delim(this));
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;
72 fl_set_bmtable_data(dialog_->bmtable, 12, 2,
73 delim_width, delim_height, delim_bits);
74 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
76 bc().setOK(dialog_->button_ok);
77 bc().setApply(dialog_->button_apply);
78 bc().setCancel(dialog_->button_close);
80 bc().addReadOnly(dialog_->bmtable);
81 bc().addReadOnly(dialog_->radio_right);
82 bc().addReadOnly(dialog_->radio_left);
83 bc().addReadOnly(dialog_->radio_both);
84 bc().addReadOnly(dialog_->button_pix);
88 void FormMathsDelim::apply()
90 int const left = int(dialog_->radio_left->u_ldata);
91 int const right = int(dialog_->radio_right->u_ldata);
94 os << delim_values[left] << ' ' << delim_values[right];
95 controller().dispatchFunc(LFUN_MATH_DELIM, STRCONV(os.str()));
99 void FormMathsDelim::update()
105 ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
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);
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);
117 if (side || (button == FL_RIGHT_MOUSE))
122 right = delim_rversion[i];
123 // Add left delimiter in "both" case if right one was pressed:
124 for (int j = 0; j <= 23; ++j) {
125 if (delim_rversion[j] == left) {
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));
139 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
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);
145 dialog_->radio_left->u_ldata = left;
146 dialog_->radio_right->u_ldata = right;
148 return ButtonPolicy::SMI_VALID;