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"
32 static int const delim_rversion[] = {
33 1,1,3,3,4,5,7,7,9,9,10,11,
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
48 typedef FormController<ControlMath, FormView<FD_maths_delim> > base_class;
50 FormMathsDelim::FormMathsDelim(Dialog & parent)
51 : base_class(parent, _("Math Delimiters"), false)
55 void FormMathsDelim::build()
57 dialog_.reset(build_maths_delim(this));
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;
66 fl_set_bmtable_data(dialog_->bmtable, 12, 2,
67 delim_width, delim_height, delim_bits);
68 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
70 bcview().setOK(dialog_->button_ok);
71 bcview().setApply(dialog_->button_apply);
72 bcview().setCancel(dialog_->button_close);
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);
82 void FormMathsDelim::apply()
84 int const left = int(dialog_->radio_left->u_ldata);
85 int const right = int(dialog_->radio_right->u_ldata);
88 os << delim_values[left] << ' ' << delim_values[right];
89 controller().dispatchDelim(STRCONV(os.str()));
93 void FormMathsDelim::update()
99 ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
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);
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);
111 if (side || (button == FL_RIGHT_MOUSE))
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) {
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));
133 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
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);
139 dialog_->radio_left->u_ldata = left;
140 dialog_->radio_right->u_ldata = right;
142 return ButtonPolicy::SMI_VALID;