2 * \file FormMathsDelim.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli, pdenapo@dm.uba.ar
8 * \author John Levon, moz@compsoc.man.ac.uk
9 * \author Angus Leeming, a.leeming@ic.ac.uk
15 #pragma implementation
18 #include "FormMathsDelim.h"
19 #include "form_maths_delim.h"
21 #include "frontends/LyXView.h"
24 #include "support/lstrings.h"
31 static int const delim_rversion[] = {
32 1,1,3,3,4,5,7,7,9,9,10,11,
33 13,13,14,15,16,17,19,19,20,21,22,23 };
35 static char const * delim_values[] = {
36 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
37 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
38 "{", "}", "/", "\\", "downarrow", "Downarrow",
39 "langle", "rangle", "|", "Vert", ".", 0
44 FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d,
45 FormMathsPanel const & p)
46 : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
50 FL_FORM * FormMathsDelim::form() const
58 void FormMathsDelim::build()
60 dialog_.reset(build_maths_delim());
62 fl_set_button(dialog_->radio_left, 1);
63 // Initialize button_pix to "()" as found in images/delim0.xpm:
64 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
65 dialog_->radio_left->u_ldata = 0;
66 dialog_->radio_right->u_ldata = 1;
67 //dialog_->radio_both->u_ldata = 2;
69 fl_set_bmtable_data(dialog_->bmtable, 6, 4,
70 delim_width, delim_height, delim_bits);
71 fl_set_bmtable_maxitems(dialog_->bmtable, 23);
73 bc().setOK(dialog_->button_ok);
74 bc().setApply(dialog_->button_apply);
75 bc().setCancel(dialog_->button_close);
77 bc().addReadOnly(dialog_->bmtable);
78 bc().addReadOnly(dialog_->radio_right);
79 bc().addReadOnly(dialog_->radio_left);
80 bc().addReadOnly(dialog_->radio_both);
81 bc().addReadOnly(dialog_->button_pix);
85 void FormMathsDelim::apply()
87 int const left = int(dialog_->radio_left->u_ldata);
88 int const right= int(dialog_->radio_right->u_ldata);
91 ost << delim_values[left] << ' ' << delim_values[right];
93 lv_->getLyXFunc()->dispatch(LFUN_MATH_DELIM, ost.str().c_str());
96 bool FormMathsDelim::input(FL_OBJECT *, long)
98 int left = int(dialog_->radio_left->u_ldata);
99 int right= int(dialog_->radio_right->u_ldata);
100 int const side = (fl_get_button(dialog_->radio_right) != 0);
102 int const i = fl_get_bmtable(dialog_->bmtable);
103 int const button = fl_get_bmtable_numb(dialog_->bmtable);
104 bool const both = (button == FL_MIDDLE_MOUSE ||
105 fl_get_button(dialog_->radio_both) != 0);
108 if (side || (button == FL_RIGHT_MOUSE))
113 right = delim_rversion[i];
114 // Add left delimiter in "both" case if right one was pressed:
115 for (int j = 0; j <= 23; ++j) {
116 if (delim_rversion[j] == left) {
125 // Re-initialize button_pix to solid blue
126 // (not elegant but works, MV 24.5.2002)
127 fl_free_pixmap_pixmap(dialog_->button_pix);
128 fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
130 fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
132 fl_draw_bmtable_item(dialog_->bmtable, left, p1, -2, 0);
133 fl_draw_bmtable_item(dialog_->bmtable, right, p1, 14, 0);
134 fl_redraw_object(dialog_->button_pix);
136 dialog_->radio_left->u_ldata = left;
137 dialog_->radio_right->u_ldata = right;