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 #include "FormMathsDelim.h"
18 #include "forms/form_maths_delim.h"
19 #include "ControlMath2.h"
21 #include "ButtonController.h"
25 #include "support/lstrings.h"
29 #include "lyx_forms.h"
36 static int const delim_rversion[] = {
37 1,1,3,3,4,5,7,7,9,9,10,11,
42 static char const * delim_values[] = {
43 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
44 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
45 "{", "}", "/", "backslash", "downarrow", "Downarrow",
46 "langle", "rangle", "|", "Vert", ".", 0
52 typedef FormController<ControlMath2, FormView<FD_maths_delim> > base_class;
54 FormMathsDelim::FormMathsDelim(Dialog & parent)
55 : base_class(parent, _("Math Delimiters"), false)
59 void FormMathsDelim::build()
61 dialog_.reset(build_maths_delim(this));
63 fl_set_button(dialog_->radio_left, 1);
64 // Initialize button_pix to "()" as found in images/delim0.xpm:
65 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
66 dialog_->radio_left->u_ldata = 0;
67 dialog_->radio_right->u_ldata = 1;
68 //dialog_->radio_both->u_ldata = 2;
70 fl_set_bmtable_data(dialog_->bmtable, 12, 2,
71 delim_width, delim_height, delim_bits);
72 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
74 bcview().setOK(dialog_->button_ok);
75 bcview().setApply(dialog_->button_apply);
76 bcview().setCancel(dialog_->button_close);
78 bcview().addReadOnly(dialog_->bmtable);
79 bcview().addReadOnly(dialog_->radio_right);
80 bcview().addReadOnly(dialog_->radio_left);
81 bcview().addReadOnly(dialog_->radio_both);
82 bcview().addReadOnly(dialog_->button_pix);
86 void FormMathsDelim::apply()
88 int const left = int(dialog_->radio_left->u_ldata);
89 int const right = int(dialog_->radio_right->u_ldata);
92 os << delim_values[left] << ' ' << delim_values[right];
93 controller().dispatchDelim(STRCONV(os.str()));
97 void FormMathsDelim::update()
103 ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
105 int left = int(dialog_->radio_left->u_ldata);
106 int right= int(dialog_->radio_right->u_ldata);
107 int const side = (fl_get_button(dialog_->radio_right) != 0);
109 int const i = fl_get_bmtable(dialog_->bmtable);
110 int const button = fl_get_bmtable_numb(dialog_->bmtable);
111 bool const both = (button == FL_MIDDLE_MOUSE ||
112 fl_get_button(dialog_->radio_both) != 0);
115 if (side || (button == FL_RIGHT_MOUSE))
120 right = delim_rversion[i];
121 // Add left delimiter in "both" case if right one was pressed:
122 for (int j = 0; j <= 23; ++j) {
123 if (delim_rversion[j] == left) {
132 // Re-initialize button_pix to solid blue
133 // (not elegant but works, MV 24.5.2002)
134 fl_free_pixmap_pixmap(dialog_->button_pix);
135 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
137 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
139 fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
140 fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
141 fl_redraw_object(dialog_->button_pix);
143 dialog_->radio_left->u_ldata = left;
144 dialog_->radio_right->u_ldata = right;
146 return ButtonPolicy::SMI_VALID;