]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsDelim.C
fix tooltips in toolbar
[lyx.git] / src / frontends / xforms / FormMathsDelim.C
1 /**
2  * \file FormMathsDelim.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
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
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "FormMathsDelim.h"
19 #include "forms/form_maths_delim.h"
20 #include "Dialogs.h"
21 #include "frontends/LyXView.h"
22 #include "bmtable.h"
23 #include "debug.h"
24 #include "support/lstrings.h"
25 #include "lyxfunc.h"
26 #include FORMS_H_LOCATION
27
28 #include "delim.xbm"
29 #include "delim0.xpm"
30 #include "delim1.xpm"
31
32 static int const delim_rversion[] = {
33         1,1,3,3,4,5,7,7,9,9,10,11,
34         13,13,14,15,16,17,19,19,20,21,22,23 };
35
36 static char const * delim_values[] = {
37         "(", ")", "lceil",  "rceil",  "uparrow",  "Uparrow",
38         "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
39         "{", "}",  "/", "\\",  "downarrow",  "Downarrow",
40         "langle",  "rangle", "|", "Vert", ".", 0
41 };
42
43 using std::endl;
44
45 FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d,
46                                FormMathsPanel const & p)
47         : FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
48 {}
49
50
51 FL_FORM * FormMathsDelim::form() const
52 {
53         if (dialog_.get())
54                 return dialog_->form;
55         return 0;
56 }
57
58
59 void FormMathsDelim::build()
60 {
61         dialog_.reset(build_maths_delim(this));
62
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;
69
70         fl_set_bmtable_data(dialog_->bmtable, 12, 2,
71                             delim_width, delim_height, delim_bits);
72         fl_set_bmtable_maxitems(dialog_->bmtable, 23);
73
74         bc().setOK(dialog_->button_ok);
75         bc().setApply(dialog_->button_apply);
76         bc().setCancel(dialog_->button_close);
77
78         bc().addReadOnly(dialog_->bmtable);
79         bc().addReadOnly(dialog_->radio_right);
80         bc().addReadOnly(dialog_->radio_left);
81         bc().addReadOnly(dialog_->radio_both);
82         bc().addReadOnly(dialog_->button_pix);
83 }
84
85
86 void FormMathsDelim::apply()
87 {
88         int const left = int(dialog_->radio_left->u_ldata);
89         int const right= int(dialog_->radio_right->u_ldata);
90
91         ostringstream ost;
92         ost << delim_values[left] << ' ' << delim_values[right];
93
94         lv_->getLyXFunc()->dispatch(LFUN_MATH_DELIM, ost.str().c_str(), false);
95 }
96
97 bool FormMathsDelim::input(FL_OBJECT *, long)
98 {
99         int left = int(dialog_->radio_left->u_ldata);
100         int right= int(dialog_->radio_right->u_ldata);
101         int const side = (fl_get_button(dialog_->radio_right) != 0);
102
103         int const i = fl_get_bmtable(dialog_->bmtable);
104         int const button = fl_get_bmtable_numb(dialog_->bmtable);
105         bool const both = (button == FL_MIDDLE_MOUSE ||
106                            fl_get_button(dialog_->radio_both) != 0);
107
108         if (i >= 0) {
109                 if (side || (button == FL_RIGHT_MOUSE))
110                         right = i;
111                 else {
112                         left = i;
113                         if (both) {
114                                 right = delim_rversion[i];
115                                 // Add left delimiter in "both" case if right one was pressed:
116                                 for (int j = 0; j <= 23; ++j) {
117                                         if (delim_rversion[j] == left) {
118                                                 right = left;
119                                                 left = j;
120                                         }
121                                 }
122                         }
123                 }
124         }
125
126         // Re-initialize button_pix to solid blue 
127         // (not elegant but works, MV 24.5.2002)
128         fl_free_pixmap_pixmap(dialog_->button_pix);
129         fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
130         Pixmap p1;
131         fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
132         
133         fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
134         fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
135         fl_redraw_object(dialog_->button_pix);
136
137         dialog_->radio_left->u_ldata  = left;
138         dialog_->radio_right->u_ldata = right;
139
140         return true;
141 }