]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
Clean-up of the math dialog code; the first step towards a controller.
[lyx.git] / src / frontends / xforms / FormMathsPanel.C
1 /**
2  * \file FormMathsPanel.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlMath.h"
21
22 #include "frontends/LyXView.h"
23 #include "FormMathsPanel.h"
24 #include "forms/form_maths_panel.h"
25 #include "funcrequest.h"
26
27 #include "forms/form_maths_deco.h"
28 #include "forms/form_maths_delim.h"
29 #include "forms/form_maths_matrix.h"
30 #include "forms/form_maths_space.h"
31 #include "forms/form_maths_style.h"
32
33 #include "FormMathsBitmap.h"
34 #include "FormMathsDeco.h"
35 #include "FormMathsDelim.h"
36 #include "FormMathsMatrix.h"
37 #include "FormMathsSpace.h"
38 #include "FormMathsStyle.h"
39
40 #include FORMS_H_LOCATION
41 #include <boost/bind.hpp>
42
43 #include "deco.xpm"
44 #include "delim.xpm"
45 #include "equation.xpm"
46 #include "frac.xpm"
47 #include "matrix.xpm"
48 #include "space.xpm"
49 #include "style.xpm"
50 #include "sqrt.xpm"
51 #include "sub.xpm"
52 #include "super.xpm"
53
54 #include "arrows.xbm"
55 #include "bop.xbm"
56 #include "brel.xbm"
57 #include "dots.xbm"
58 #include "greek.xbm"
59 #include "misc.xbm"
60 #include "varsz.xbm"
61
62 #include "ams_misc.xbm"
63 #include "ams_arrows.xbm"
64 #include "ams_rel.xbm"
65 #include "ams_nrel.xbm"
66 #include "ams_ops.xbm"
67
68
69 FormMathsPanel::FormMathsPanel(LyXView & lv, Dialogs & d)
70         : FormBaseBD(lv, d, _("Maths Panel")),
71           active_(0), bc_(_("Close"))
72 {}
73
74
75 FL_FORM * FormMathsPanel::form() const
76 {
77         return dialog_.get() ? dialog_->form : 0;
78 }
79
80
81 FormMathsBitmap * FormMathsPanel::addDaughter(FL_OBJECT * button,
82                                               string const & title,
83                                               char const * const * data,
84                                               int size)
85 {
86         char const * const * end = data + size;
87         FormMathsBitmap * bitmap =
88                 new FormMathsBitmap(lv_, d_, *this, title,
89                                     std::vector<string>(data, end));
90         daughters_[button] = DaughterDialog(bitmap);
91         return bitmap;
92 }
93
94
95 void FormMathsPanel::build()
96 {
97         dialog_.reset(build_maths_panel(this));
98
99         for (int i = 0; i < nr_function_names; ++i)
100                 fl_add_browser_line(dialog_->browser_funcs,
101                                     function_names[i]);
102
103         fl_set_pixmap_data(dialog_->button_sqrt,
104                            const_cast<char**>(sqrt_xpm));
105         fl_set_pixmap_data(dialog_->button_frac,
106                            const_cast<char**>(frac));
107         fl_set_pixmap_data(dialog_->button_super,
108                            const_cast<char**>(super_xpm));
109         fl_set_pixmap_data(dialog_->button_sub,
110                            const_cast<char**>(sub_xpm));
111         fl_set_pixmap_data(dialog_->button_delim,
112                            const_cast<char**>(delim));
113         fl_set_pixmap_data(dialog_->button_deco,
114                            const_cast<char**>(deco));
115         fl_set_pixmap_data(dialog_->button_space,
116                            const_cast<char**>(space_xpm));
117         fl_set_pixmap_data(dialog_->button_style,
118                            const_cast<char**>(style_xpm));
119         fl_set_pixmap_data(dialog_->button_matrix,
120                            const_cast<char**>(matrix));
121         fl_set_pixmap_data(dialog_->button_equation,
122                            const_cast<char**>(equation));
123
124         daughters_[dialog_->button_deco] =
125                 DaughterDialog(new FormMathsDeco(lv_, d_, *this));
126         daughters_[dialog_->button_delim] =
127                 DaughterDialog(new FormMathsDelim(lv_, d_, *this));
128         daughters_[dialog_->button_matrix] =
129                 DaughterDialog(new FormMathsMatrix(lv_, d_, *this));
130         daughters_[dialog_->button_space] =
131                 DaughterDialog(new FormMathsSpace(lv_, d_, *this));
132         daughters_[dialog_->button_style] =
133                 DaughterDialog(new FormMathsStyle(lv_, d_, *this));
134
135         FormMathsBitmap * bitmap;
136         bitmap = addDaughter(dialog_->button_arrow, _("Arrows"),
137                              latex_arrow, nr_latex_arrow);
138         bitmap->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
139         bitmap->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
140                           false);
141         bitmap->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
142
143         bitmap = addDaughter(dialog_->button_boperator, _("Binary Ops"),
144                              latex_bop, nr_latex_bop);
145         bitmap->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
146
147         bitmap = addDaughter(dialog_->button_brelats, _("Bin Relations"),
148                              latex_brel, nr_latex_brel);
149         bitmap->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
150
151         bitmap = addDaughter(dialog_->button_greek, _("Greek"),
152                              latex_greek, nr_latex_greek);
153         bitmap->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
154         bitmap->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
155
156         bitmap = addDaughter(dialog_->button_misc,_("Misc"),
157                              latex_misc, nr_latex_misc);
158         bitmap->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
159         bitmap->addBitmap(5, 5, 1, misc4_width, misc4_height, misc4_bits);
160         bitmap->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits,
161                           false);
162         bitmap->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
163
164         bitmap = addDaughter(dialog_->button_dots, _("Dots"),
165                              latex_dots, nr_latex_dots);
166         bitmap->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
167
168         bitmap = addDaughter(dialog_->button_varsize, _("Big Operators"),
169                      latex_varsz, nr_latex_varsz);
170         bitmap->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
171
172         bitmap = addDaughter(dialog_->button_ams_misc, _("AMS Misc"),
173                              latex_ams_misc, nr_latex_ams_misc);
174         bitmap->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
175         bitmap->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
176
177         bitmap = addDaughter(dialog_->button_ams_arrows, _("AMS Arrows"),
178                              latex_ams_arrows, nr_latex_ams_arrows);
179         bitmap->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
180         bitmap->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
181
182         bitmap = addDaughter(dialog_->button_ams_brel, _("AMS Relations"),
183                              latex_ams_rel, nr_latex_ams_rel);
184         bitmap->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height,
185                           ams_rel_bits);
186
187         bitmap = addDaughter(dialog_->button_ams_nrel, _("AMS Negated Rel"),
188                              latex_ams_nrel, nr_latex_ams_nrel);
189         bitmap->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height,
190                           ams_nrel_bits);
191
192         bitmap = addDaughter(dialog_->button_ams_ops, _("AMS Operators"),
193                              latex_ams_ops, nr_latex_ams_ops);
194         bitmap->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height,
195                           ams_ops_bits);
196
197         bc().setCancel(dialog_->button_close);
198 }
199
200
201 void FormMathsPanel::showDaughter(FL_OBJECT * button)
202 {
203         Store::iterator it = daughters_.find(button);
204         FormMathsSub * const new_active =
205                 (it == daughters_.end()) ? 0 : it->second.get();
206
207         if (active_ != new_active) {
208                 if (active_ && active_->isVisible())
209                         active_->hide();
210                 active_ = new_active;
211         }
212
213         if (active_ && !active_->isVisible())
214                 active_->show();
215 }
216
217
218 bool FormMathsPanel::input(FL_OBJECT * ob, long)
219 {
220         if (ob == dialog_->button_arrow ||
221             ob == dialog_->button_boperator ||
222             ob == dialog_->button_brelats ||
223             ob == dialog_->button_greek ||
224             ob == dialog_->button_misc ||
225             ob == dialog_->button_dots ||
226             ob == dialog_->button_varsize ||
227             ob == dialog_->button_ams_misc ||
228             ob == dialog_->button_ams_arrows ||
229             ob == dialog_->button_ams_brel ||
230             ob == dialog_->button_ams_nrel ||
231             ob == dialog_->button_ams_ops ||
232             ob == dialog_->button_delim ||
233             ob == dialog_->button_matrix ||
234             ob == dialog_->button_deco ||
235             ob == dialog_->button_space ||
236             ob == dialog_->button_style) {
237                 showDaughter(ob);
238
239         } else if (ob == dialog_->button_super) {
240                 dispatchFunc(LFUN_SUPERSCRIPT);
241
242         } else if (ob == dialog_->button_sub) {
243                 dispatchFunc(LFUN_SUBSCRIPT);
244
245 //      } else if (ob == dialog_->???) {
246 //              dispatchFunc(LFUN_SUBSCRIPT);
247 //              dispatchFunc(LFUN_LEFT);
248 //              dispatchFunc(LFUN_SUPERSCRIPT);
249
250         } else if (ob == dialog_->button_equation) {
251                 dispatchFunc(LFUN_MATH_DISPLAY);
252
253         } else if (ob == dialog_->button_frac) {
254                 insertSymbol("frac");
255
256         } else if (ob == dialog_->button_sqrt) {
257                 insertSymbol("sqrt");
258
259         } else if (ob == dialog_->browser_funcs) {
260                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
261                 insertSymbol(function_names[i]);
262         }
263
264         return true;
265 }
266
267
268 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
269 {
270         if (bs)
271                 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
272         else
273                 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
274 }
275
276
277 void FormMathsPanel::dispatchFunc(kb_action action, string const & arg) const
278 {
279         lv_.dispatch(FuncRequest(action, arg));
280 }
281
282
283 FormMathsSub::FormMathsSub(LyXView & lv, Dialogs & d, FormMathsPanel const & p,
284                            string const & t, bool allowResize)
285         : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_(_("Close"))
286 {}
287
288
289 bool FormMathsSub::isVisible() const
290 {
291         return form() ? form()->visible : false;
292 }