]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
Hose MathsCallbacks.h.
[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         deco_.reset(  new FormMathsDeco(  lv, d, *this));
74         delim_.reset( new FormMathsDelim( lv, d, *this));
75         matrix_.reset(new FormMathsMatrix(lv, d, *this));
76         space_.reset( new FormMathsSpace( lv, d, *this));
77         style_.reset( new FormMathsStyle( lv, d, *this));
78
79         typedef std::vector<string> StringVec;
80         char const * const * begin = latex_arrow;
81         char const * const * end   = begin + nr_latex_arrow;
82         arrow_.reset(new FormMathsBitmap(lv, d, *this, _("Arrows"),
83                                          StringVec(begin, end)));
84
85         begin = latex_bop;
86         end   = begin + nr_latex_bop;
87         boperator_.reset(new FormMathsBitmap(lv, d, *this, _("Binary Ops"),
88                                              StringVec(begin, end)));
89
90         begin = latex_brel;
91         end   = begin + nr_latex_brel;
92         brelats_.reset(new FormMathsBitmap(lv, d, *this, _("Bin Relations"),
93                                            StringVec(begin, end)));
94
95         begin = latex_greek;
96         end   = begin + nr_latex_greek;
97         greek_.reset(new FormMathsBitmap(lv, d, *this, _("Greek"),
98                                          StringVec(begin, end)));
99
100         begin = latex_misc;
101         end   = begin + nr_latex_misc;
102         misc_.reset(new FormMathsBitmap(lv, d, *this, _("Misc"),
103                                         StringVec(begin, end)));
104
105         begin = latex_dots;
106         end   = begin + nr_latex_dots;
107         dots_.reset(new FormMathsBitmap(lv, d, *this, _("Dots"),
108                                         StringVec(begin, end)));
109
110         begin = latex_varsz;
111         end   = begin + nr_latex_varsz;
112         varsize_.reset(new FormMathsBitmap(lv, d, *this, _("Big Operators"),
113                                            StringVec(begin, end)));
114
115         begin = latex_ams_misc;
116         end   = begin + nr_latex_ams_misc;
117         ams_misc_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Misc"),
118                                             StringVec(begin, end)));
119
120         begin = latex_ams_arrows;
121         end   = begin + nr_latex_ams_arrows;
122         ams_arrows_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Arrows"),
123                                               StringVec(begin, end)));
124
125         begin = latex_ams_rel;
126         end   = begin + nr_latex_ams_rel;
127         ams_rel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Relations"),
128                                            StringVec(begin, end)));
129
130         begin = latex_ams_nrel;
131         end   = begin + nr_latex_ams_nrel;
132         ams_nrel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Negated Rel"),
133                                             StringVec(begin, end)));
134
135         begin = latex_ams_ops;
136         end   = begin + nr_latex_ams_ops;
137         ams_ops_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Operators"),
138                                            StringVec(begin, end)));
139 }
140
141
142 FL_FORM * FormMathsPanel::form() const
143 {
144         return dialog_.get() ? dialog_->form : 0;
145 }
146
147
148 void FormMathsPanel::setActive(FormMathsSub * a) const
149 {
150         active_ = a;
151 }
152
153
154 void FormMathsPanel::build()
155 {
156         dialog_.reset(build_maths_panel(this));
157
158         for (int i = 0; i < nr_function_names; ++i)
159                 fl_add_browser_line(dialog_->browser_funcs,
160                                     function_names[i]);
161
162         fl_set_pixmap_data(dialog_->button_sqrt,
163                            const_cast<char**>(sqrt_xpm));
164         fl_set_pixmap_data(dialog_->button_frac,
165                            const_cast<char**>(frac));
166         fl_set_pixmap_data(dialog_->button_super,
167                            const_cast<char**>(super_xpm));
168         fl_set_pixmap_data(dialog_->button_sub,
169                            const_cast<char**>(sub_xpm));
170         fl_set_pixmap_data(dialog_->button_delim,
171                            const_cast<char**>(delim));
172         fl_set_pixmap_data(dialog_->button_deco,
173                            const_cast<char**>(deco));
174         fl_set_pixmap_data(dialog_->button_space,
175                            const_cast<char**>(space_xpm));
176         fl_set_pixmap_data(dialog_->button_style,
177                            const_cast<char**>(style_xpm));
178         fl_set_pixmap_data(dialog_->button_matrix,
179                            const_cast<char**>(matrix));
180         fl_set_pixmap_data(dialog_->button_equation,
181                            const_cast<char**>(equation));
182
183         arrow_->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
184         arrow_->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
185                           false);
186         arrow_->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
187
188         boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
189
190         brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
191
192         greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
193         greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
194
195         misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
196         misc_->addBitmap(5, 5, 1, misc4_width, misc4_height, misc4_bits);
197         misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
198         misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
199
200         dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
201
202         varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
203
204         ams_misc_->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
205         ams_misc_->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
206
207         ams_arrows_->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
208         ams_arrows_->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
209
210         ams_rel_->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits);
211
212         ams_nrel_->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits);
213
214         ams_ops_->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits);
215
216         bc().setCancel(dialog_->button_close);
217 }
218
219
220 bool FormMathsPanel::input(FL_OBJECT * ob, long)
221 {
222         if (ob == dialog_->button_greek) {
223                 if (active_ && active_ != greek_.get())
224                         active_->hide();
225                 greek_->show();
226
227         } else if (ob == dialog_->button_arrow) {
228                 if (active_ && active_ != arrow_.get())
229                         active_->hide();
230                 arrow_->show();
231
232         } else if (ob == dialog_->button_boperator) {
233                 if (active_ && active_ != boperator_.get())
234                         active_->hide();
235                 boperator_->show();
236
237         } else if (ob == dialog_->button_brelats) {
238                 if (active_ && active_ != brelats_.get())
239                         active_->hide();
240                 brelats_->show();
241
242         } else if (ob == dialog_->button_misc) {
243                 if (active_ && active_ != misc_.get())
244                         active_->hide();
245                 misc_->show();
246
247         } else if (ob == dialog_->button_dots) {
248                 if (active_ && active_ != dots_.get())
249                         active_->hide();
250                 dots_->show();
251
252         } else if (ob == dialog_->button_varsize) {
253                 if (active_ && active_ != varsize_.get())
254                         active_->hide();
255                 varsize_->show();
256
257         } else if (ob == dialog_->button_ams_misc) {
258                 if (active_ && active_ != ams_misc_.get())
259                         active_->hide();
260                 ams_misc_->show();
261
262         } else if (ob == dialog_->button_ams_arrows) {
263                 if (active_ && active_ != ams_arrows_.get())
264                         active_->hide();
265                 ams_arrows_->show();
266
267         } else if (ob == dialog_->button_ams_brel) {
268                 if (active_ && active_ != ams_rel_.get())
269                         active_->hide();
270                 ams_rel_->show();
271
272         } else if (ob == dialog_->button_ams_nrel) {
273                 if (active_ && active_ != ams_nrel_.get())
274                         active_->hide();
275                 ams_nrel_->show();
276
277         } else if (ob == dialog_->button_ams_ops) {
278                 if (active_ && active_ != ams_ops_.get())
279                         active_->hide();
280                 ams_ops_->show();
281
282         } else if (ob == dialog_->button_frac) {
283                 insertSymbol("frac");
284
285         } else if (ob == dialog_->button_sqrt) {
286                 insertSymbol("sqrt");
287
288         } else if (ob == dialog_->button_super) {
289                 lv_.dispatch(FuncRequest(LFUN_SUPERSCRIPT));
290
291         } else if (ob == dialog_->button_sub) {
292                 lv_.dispatch(FuncRequest(LFUN_SUBSCRIPT));
293
294 //      } else if (ob == dialog_->???) {
295 //              lv_.dispatch(FuncRequest(LFUN_SUBSCRIPT));
296 //              lv_.dispatch(FuncRequest(LFUN_LEFT));
297 //              lv_.dispatch(FuncRequest(LFUN_SUPERSCRIPT));
298
299         } else if (ob == dialog_->button_delim) {
300                 if (active_ && active_ != delim_.get())
301                         active_->hide();
302                 delim_->show();
303
304         } else if (ob == dialog_->button_matrix) {
305                 if (active_ && active_ != matrix_.get())
306                         active_->hide();
307                 matrix_->show();
308
309         } else if (ob == dialog_->button_deco) {
310                 if (active_ && active_ != deco_.get())
311                         active_->hide();
312                 deco_->show();
313
314         } else if (ob == dialog_->button_space) {
315                 if (active_ && active_ != space_.get())
316                         active_->hide();
317                 space_->show();
318
319         } else if (ob == dialog_->button_style) {
320                 if (active_ && active_ != style_.get())
321                         active_->hide();
322                 style_->show();
323
324         } else if (ob == dialog_->button_equation) {
325                 mathDisplay();
326
327         } else if (ob == dialog_->browser_funcs) {
328                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
329                 insertSymbol(function_names[i]);
330         }
331
332         return true;
333 }
334
335
336 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
337 {
338         if (bs)
339                 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
340         else
341                 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
342 }
343
344
345 void FormMathsPanel::dispatchFunc(kb_action action) const
346 {
347         lv_.dispatch(FuncRequest(action));
348 }
349
350
351 void FormMathsPanel::mathDisplay() const
352 {
353         lv_.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
354 }
355
356
357
358 FormMathsSub::FormMathsSub(LyXView & lv, Dialogs & d, FormMathsPanel const & p,
359                            string const & t, bool allowResize)
360         : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_(_("Close"))
361 {}
362
363
364 void FormMathsSub::connect()
365 {
366         parent_.setActive(this);
367         FormBaseBD::connect();
368 }
369
370
371 void FormMathsSub::disconnect()
372 {
373         parent_.setActive(0);
374         FormBaseBD::disconnect();
375 }