]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
Martin's prettification patch.
[lyx.git] / src / frontends / xforms / FormMathsPanel.C
1 /**
2  * \file FormMathsPanel.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 "Dialogs.h"
19 #include "LyXView.h"
20 #include "FormMathsPanel.h"
21 #include "form_maths_panel.h"
22 #include "MathsSymbols.h"
23 #include "debug.h"
24 #include "lyxfunc.h"
25
26 #include "form_maths_deco.h"
27 #include "form_maths_delim.h"
28 #include "form_maths_matrix.h"
29 #include "form_maths_space.h"
30 #include "form_maths_style.h"
31
32 #include "FormMathsBitmap.h"
33 #include "FormMathsDeco.h"
34 #include "FormMathsDelim.h"
35 #include "FormMathsMatrix.h"
36 #include "FormMathsSpace.h"
37 #include "FormMathsStyle.h"
38
39 #include "ButtonController.tmpl"
40
41 #include "deco.xpm"
42 #include "delim.xpm"
43 #include "equation.xpm"
44 #include "frac.xpm"
45 #include "matrix.xpm"
46 #include "space.xpm"
47 #include "style.xpm"
48 #include "sqrt.xpm"
49 #include "sub.xpm"
50 #include "super.xpm"
51
52 #include "arrows.xbm"
53 #include "bop.xbm"
54 #include "brel.xbm"
55 #include "dots.xbm"
56 #include "greek.xbm"
57 #include "misc.xbm"
58 #include "varsz.xbm"
59
60 #include "ams_misc.xbm"
61 #include "ams_arrows.xbm"
62 #include "ams_rel.xbm"
63 #include "ams_nrel.xbm"
64 #include "ams_ops.xbm"
65
66 using std::vector;
67 using SigC::slot;
68
69 FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d)
70         : FormBaseBD(lv, d, _("Maths Panel"), false),
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 vector<string> StringVec;
80         
81         StringVec latex(nr_latex_arrow);
82         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
83                 latex[i] = latex_arrow[i];
84         }
85         arrow_.reset(new FormMathsBitmap(lv, d, *this, _("Arrows"), latex));
86
87         latex.resize(nr_latex_bop);
88         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
89                 latex[i] = latex_bop[i];
90         }
91         boperator_.reset(new FormMathsBitmap(lv, d, *this, _("Binary Ops"), latex));
92
93         latex.resize(nr_latex_brel);
94         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
95                 latex[i] = latex_brel[i];
96         }
97         brelats_.reset(new FormMathsBitmap(lv, d, *this, _("Bin Relations"), latex));
98
99         latex.resize(nr_latex_greek);
100         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
101                 latex[i] = latex_greek[i];
102         }
103         greek_.reset(new FormMathsBitmap(lv, d, *this, _("Greek"),latex));
104
105         latex.resize(nr_latex_misc);
106         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
107                 latex[i] = latex_misc[i];
108         }
109         misc_.reset(new FormMathsBitmap(lv, d, *this, _("Misc"),latex));
110
111         latex.resize(nr_latex_dots);
112         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
113                 latex[i] = latex_dots[i];
114         }
115
116         dots_.reset(new FormMathsBitmap(lv, d, *this, _("Dots"), latex));
117
118         latex.resize(nr_latex_varsz);
119         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
120                 latex[i] = latex_varsz[i];
121         }
122         varsize_.reset(new FormMathsBitmap(lv, d, *this, _("Big Operators"),latex));
123
124         latex.resize(nr_latex_ams_misc);
125         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
126                 latex[i] = latex_ams_misc[i];
127         }
128         ams_misc_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Misc"), latex));
129
130         latex.resize(nr_latex_ams_arrows);
131         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
132                 latex[i] = latex_ams_arrows[i];
133         }
134         ams_arrows_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Arrows"), latex));
135
136         latex.resize(nr_latex_ams_rel);
137         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
138                 latex[i] = latex_ams_rel[i];
139         }
140         ams_rel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Relations"), latex));
141
142         latex.resize(nr_latex_ams_nrel);
143         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
144                 latex[i] = latex_ams_nrel[i];
145         }
146         ams_nrel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Negated Rel"), latex));
147
148         latex.resize(nr_latex_ams_ops);
149         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
150                 latex[i] = latex_ams_ops[i];
151         }
152         ams_ops_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Operators"), latex));
153
154         //showUnderMouse(false);
155         d->showMathPanel.connect(slot(this, &FormMathsPanel::show));
156 }
157
158
159 FL_FORM * FormMathsPanel::form() const
160 {
161         if (dialog_.get())
162                 return dialog_->form;
163         return 0;
164 }
165
166
167 void FormMathsPanel::setActive(FormMathsSub * a) const
168 {
169         active_ = a;
170 }
171
172
173 void FormMathsPanel::build()
174 {
175         dialog_.reset(build_maths_panel());
176         
177         for (int i = 0; i < nr_function_names; ++i)
178                 fl_add_browser_line(dialog_->browser_funcs,
179                                     function_names[i]);
180         
181         fl_set_pixmap_data(dialog_->button_sqrt,
182                            const_cast<char**>(sqrt_xpm));
183         fl_set_pixmap_data(dialog_->button_frac,
184                            const_cast<char**>(frac));
185         fl_set_pixmap_data(dialog_->button_super,
186                            const_cast<char**>(super_xpm));
187         fl_set_pixmap_data(dialog_->button_sub,
188                            const_cast<char**>(sub_xpm));
189         fl_set_pixmap_data(dialog_->button_delim,
190                            const_cast<char**>(delim));
191         fl_set_pixmap_data(dialog_->button_deco,
192                            const_cast<char**>(deco));
193         fl_set_pixmap_data(dialog_->button_space,
194                            const_cast<char**>(space_xpm));
195         fl_set_pixmap_data(dialog_->button_style,
196                            const_cast<char**>(style_xpm));
197         fl_set_pixmap_data(dialog_->button_matrix,
198                            const_cast<char**>(matrix));
199         fl_set_pixmap_data(dialog_->button_equation,
200                            const_cast<char**>(equation));
201
202         arrow_->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
203         arrow_->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
204                           false);
205         arrow_->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
206         
207         boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
208
209         brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
210
211         greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
212         greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
213
214         misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
215         misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
216         misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
217  
218         dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
219
220         varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
221
222         ams_misc_->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
223         ams_misc_->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
224         
225         ams_arrows_->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
226         ams_arrows_->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
227
228         ams_rel_->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits);
229
230         ams_nrel_->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits);
231         
232         ams_ops_->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits);
233
234         bc().setCancel(dialog_->button_close);
235 }
236
237 bool FormMathsPanel::input(FL_OBJECT *, long data)
238 {
239         MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
240
241         switch (val) {
242         case MM_GREEK:
243                 if (active_ && active_ != greek_.get())
244                         active_->hide();
245                 greek_->show();
246                 break;
247
248         case MM_ARROW:
249                 if (active_ && active_ != arrow_.get())
250                         active_->hide();
251                 arrow_->show();
252                 break;
253
254         case MM_BOP:
255                 if (active_ && active_ != boperator_.get())
256                         active_->hide();
257                 boperator_->show();
258                 break;
259
260         case MM_BRELATS:
261                 if (active_ && active_ != brelats_.get())
262                         active_->hide();
263                 brelats_->show();
264                 break;
265
266         case MM_MISC:
267                 if (active_ && active_ != misc_.get())
268                         active_->hide();
269                 misc_->show();
270                 break;
271
272         case MM_DOTS:
273                 if (active_ && active_ != dots_.get())
274                         active_->hide();
275                 dots_->show();
276                 break;
277  
278         case MM_VARSIZE:
279                 if (active_ && active_ != varsize_.get())
280                         active_->hide();
281                 varsize_->show();
282                 break;
283
284         case MM_AMS_MISC:
285                 if (active_ && active_ != ams_misc_.get())
286                         active_->hide();
287                 ams_misc_->show();
288                 break;
289         
290         case MM_AMS_ARROWS:
291                 if (active_ && active_ != ams_arrows_.get())
292                         active_->hide();
293                 ams_arrows_->show();
294                 break;
295
296         case MM_AMS_BREL:
297                 if (active_ && active_ != ams_rel_.get())
298                         active_->hide();
299                 ams_rel_->show();
300                 break;
301
302         case MM_AMS_NREL:
303                 if (active_ && active_ != ams_nrel_.get())
304                         active_->hide();
305                 ams_nrel_->show();
306                 break;
307
308         case MM_AMS_OPS:
309                 if (active_ && active_ != ams_ops_.get())
310                         active_->hide();
311                 ams_ops_->show();
312                 break;
313
314         case MM_FRAC:
315                 insertSymbol("frac");
316                 break;
317
318         case MM_SQRT:
319                 insertSymbol("sqrt");
320                 break;
321
322         case MM_SUPER:
323                 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
324                 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
325                 break;
326
327         case MM_SUB:
328                 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
329                 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
330                 break;
331
332         case MM_SUBSUPER:
333                 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
334                 lv_->getLyXFunc()->dispatch(LFUN_LEFT);
335                 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
336                 break;
337
338         case MM_DELIM:
339                 if (active_ && active_ != delim_.get())
340                         active_->hide();
341                 delim_->show();
342                 break;
343
344         case MM_MATRIX:
345                 if (active_ && active_ != matrix_.get())
346                         active_->hide();
347                 matrix_->show();
348                 break;
349
350         case MM_DECO:
351                 if (active_ && active_ != deco_.get())
352                         active_->hide();
353                 deco_->show();
354                 break;
355
356         case MM_SPACE:
357                 if (active_ && active_ != space_.get())
358                         active_->hide();
359                 space_->show();
360                 break;
361
362         case MM_STYLE:
363                 if (active_ && active_ != style_.get())
364                         active_->hide();
365                 style_->show();
366                 break;
367
368         case MM_EQU:
369                 mathDisplay();
370                 break;
371
372         case MM_FUNC:
373                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
374                 insertSymbol(function_names[i]);
375                 break;
376         }
377
378         return true;
379 }
380
381
382 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
383 {
384         if (bs) 
385                 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, '\\' + sym);
386         else 
387                 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, sym);
388 }
389
390
391 void FormMathsPanel::dispatchFunc(kb_action action) const
392 {
393         lv_->getLyXFunc()->dispatch(action);
394 }
395
396
397 void FormMathsPanel::mathDisplay() const
398 {
399         lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
400 }
401
402
403
404 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
405                            string const & t, bool allowResize)
406     : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_("Close")
407 {}
408
409
410 void FormMathsSub::connect()
411 {
412         parent_.setActive(this);
413         FormBaseBD::connect();
414 }
415
416
417 void FormMathsSub::disconnect()
418 {
419         parent_.setActive(0);
420         FormBaseBD::disconnect();
421 }
422
423