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"
26 #include "funcrequest.h"
29 #include "frontends/LyXView.h"
31 #include "support/lstrings.h"
35 #include FORMS_H_LOCATION
42 static int const delim_rversion[] = {
43 1,1,3,3,4,5,7,7,9,9,10,11,
44 13,13,14,15,16,17,19,19,20,21,22,23
48 static char const * delim_values[] = {
49 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
50 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
51 "{", "}", "/", "backslash", "downarrow", "Downarrow",
52 "langle", "rangle", "|", "Vert", ".", 0
57 FormMathsDelim::FormMathsDelim(LyXView & lv, Dialogs & d,
58 FormMathsPanel const & p)
59 : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
63 FL_FORM * FormMathsDelim::form() const
71 void FormMathsDelim::build()
73 dialog_.reset(build_maths_delim(this));
75 fl_set_button(dialog_->radio_left, 1);
76 // Initialize button_pix to "()" as found in images/delim0.xpm:
77 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
78 dialog_->radio_left->u_ldata = 0;
79 dialog_->radio_right->u_ldata = 1;
80 //dialog_->radio_both->u_ldata = 2;
82 fl_set_bmtable_data(dialog_->bmtable, 12, 2,
83 delim_width, delim_height, delim_bits);
84 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
86 bc().setOK(dialog_->button_ok);
87 bc().setApply(dialog_->button_apply);
88 bc().setCancel(dialog_->button_close);
90 bc().addReadOnly(dialog_->bmtable);
91 bc().addReadOnly(dialog_->radio_right);
92 bc().addReadOnly(dialog_->radio_left);
93 bc().addReadOnly(dialog_->radio_both);
94 bc().addReadOnly(dialog_->button_pix);
98 void FormMathsDelim::apply()
100 int const left = int(dialog_->radio_left->u_ldata);
101 int const right = int(dialog_->radio_right->u_ldata);
104 os << delim_values[left] << ' ' << delim_values[right];
105 parent_.dispatchFunc(LFUN_MATH_DELIM, STRCONV(os.str()));
109 bool FormMathsDelim::input(FL_OBJECT *, long)
111 int left = int(dialog_->radio_left->u_ldata);
112 int right= int(dialog_->radio_right->u_ldata);
113 int const side = (fl_get_button(dialog_->radio_right) != 0);
115 int const i = fl_get_bmtable(dialog_->bmtable);
116 int const button = fl_get_bmtable_numb(dialog_->bmtable);
117 bool const both = (button == FL_MIDDLE_MOUSE ||
118 fl_get_button(dialog_->radio_both) != 0);
121 if (side || (button == FL_RIGHT_MOUSE))
126 right = delim_rversion[i];
127 // Add left delimiter in "both" case if right one was pressed:
128 for (int j = 0; j <= 23; ++j) {
129 if (delim_rversion[j] == left) {
138 // Re-initialize button_pix to solid blue
139 // (not elegant but works, MV 24.5.2002)
140 fl_free_pixmap_pixmap(dialog_->button_pix);
141 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
143 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
145 fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
146 fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
147 fl_redraw_object(dialog_->button_pix);
149 dialog_->radio_left->u_ldata = left;
150 dialog_->radio_right->u_ldata = right;