]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
Martin's math panel patches.
[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 "deco.xpm"
40 #include "delim.xpm"
41 #include "equation.xpm"
42 #include "frac.xpm"
43 #include "matrix.xpm"
44 #include "space.xpm"
45 #include "style.xpm"
46 #include "sqrt.xpm"
47 #include "sub.xpm"
48 #include "super.xpm"
49
50 #include "arrows.xbm"
51 #include "bop.xbm"
52 #include "brel.xbm"
53 #include "dots.xbm"
54 #include "greek.xbm"
55 #include "misc.xbm"
56 #include "varsz.xbm"
57
58 using std::vector;
59 using SigC::slot;
60
61 FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d)
62         : FormBaseBD(lv, d, _("Maths Panel"), false),
63           active_(0), bc_("Close")
64 {
65         deco_.reset(  new FormMathsDeco(  lv, d, *this));
66         delim_.reset( new FormMathsDelim( lv, d, *this));
67         matrix_.reset(new FormMathsMatrix(lv, d, *this));
68         space_.reset( new FormMathsSpace( lv, d, *this));
69         style_.reset( new FormMathsStyle( lv, d, *this));
70
71         typedef vector<string> StringVec;
72         
73         StringVec latex(nr_latex_arrow);
74         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
75                 latex[i] = latex_arrow[i];
76         }
77         arrow_.reset(new FormMathsBitmap(lv, d, *this, latex));
78
79         latex.resize(nr_latex_bop);
80         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
81                 latex[i] = latex_bop[i];
82         }
83         boperator_.reset(new FormMathsBitmap(lv, d, *this, latex));
84
85         latex.resize(nr_latex_brel);
86         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
87                 latex[i] = latex_brel[i];
88         }
89         brelats_.reset(new FormMathsBitmap(lv, d, *this, latex));
90
91         latex.resize(nr_latex_greek);
92         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
93                 latex[i] = latex_greek[i];
94         }
95         greek_.reset(new FormMathsBitmap(lv, d, *this, latex));
96
97         latex.resize(nr_latex_misc);
98         for (StringVec::size_type i = 0; i < latex.size(); ++i) {
99                 latex[i] = latex_misc[i];
100         }
101         misc_.reset(new FormMathsBitmap(lv, d, *this, latex));
102
103         latex.resize(nr_latex_dots);
104         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
105                 latex[i] = latex_dots[i];
106         }
107
108         dots_.reset(new FormMathsBitmap(lv, d, *this, latex));
109
110         latex.resize(nr_latex_varsz);
111         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
112                 latex[i] = latex_varsz[i];
113         }
114         varsize_.reset(new FormMathsBitmap(lv, d, *this, latex));
115
116         d->showMathPanel.connect(slot(this, &FormMathsPanel::show));
117 }
118
119
120 FL_FORM * FormMathsPanel::form() const
121 {
122         if (dialog_.get())
123                 return dialog_->form;
124         return 0;
125 }
126
127
128 void FormMathsPanel::setActive(FormMathsSub * a) const
129 {
130         active_ = a;
131 }
132
133
134 void FormMathsPanel::build()
135 {
136         dialog_.reset(build_maths_panel());
137         
138         for (int i = 0; i < nr_function_names; ++i)
139                 fl_add_browser_line(dialog_->browser_funcs,
140                                     function_names[i]);
141         
142         fl_set_pixmap_data(dialog_->button_sqrt,
143                            const_cast<char**>(sqrt_xpm));
144         fl_set_pixmap_data(dialog_->button_frac,
145                            const_cast<char**>(frac));
146         fl_set_pixmap_data(dialog_->button_super,
147                            const_cast<char**>(super_xpm));
148         fl_set_pixmap_data(dialog_->button_sub,
149                            const_cast<char**>(sub_xpm));
150         fl_set_pixmap_data(dialog_->button_delim,
151                            const_cast<char**>(delim));
152         fl_set_pixmap_data(dialog_->button_deco,
153                            const_cast<char**>(deco));
154         fl_set_pixmap_data(dialog_->button_space,
155                            const_cast<char**>(space_xpm));
156         fl_set_pixmap_data(dialog_->button_style,
157                            const_cast<char**>(style_xpm));
158         fl_set_pixmap_data(dialog_->button_matrix,
159                            const_cast<char**>(matrix));
160         fl_set_pixmap_data(dialog_->button_equation,
161                            const_cast<char**>(equation));
162
163         arrow_->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
164         arrow_->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
165                           false);
166         arrow_->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
167         
168         boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
169
170         brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
171
172         greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
173         greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
174
175         misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
176         misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
177         misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
178  
179         dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
180
181         varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
182
183         bc().setCancel(dialog_->button_close);
184 }
185
186 bool FormMathsPanel::input(FL_OBJECT *, long data)
187 {
188         MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
189
190         switch (val) {
191         case MM_GREEK:
192                 if (active_ && active_ != greek_.get())
193                         active_->hide();
194                 greek_->show();
195                 break;
196
197         case MM_ARROW:
198                 if (active_ && active_ != arrow_.get())
199                         active_->hide();
200                 arrow_->show();
201                 break;
202
203         case MM_BOP:
204                 if (active_ && active_ != boperator_.get())
205                         active_->hide();
206                 boperator_->show();
207                 break;
208
209         case MM_BRELATS:
210                 if (active_ && active_ != brelats_.get())
211                         active_->hide();
212                 brelats_->show();
213                 break;
214
215         case MM_MISC:
216                 if (active_ && active_ != misc_.get())
217                         active_->hide();
218                 misc_->show();
219                 break;
220
221         case MM_DOTS:
222                 if (active_ && active_ != dots_.get())
223                         active_->hide();
224                 dots_->show();
225                 break;
226  
227         case MM_VARSIZE:
228                 if (active_ && active_ != varsize_.get())
229                         active_->hide();
230                 varsize_->show();
231                 break;
232
233         case MM_FRAC:
234                 insertSymbol("frac");
235                 break;
236
237         case MM_SQRT:
238                 insertSymbol("sqrt");
239                 break;
240
241         case MM_SUPER:
242                 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
243                 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
244                 break;
245
246         case MM_SUB:
247                 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
248                 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
249                 break;
250
251         case MM_SUBSUPER:
252                 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
253                 lv_->getLyXFunc()->dispatch(LFUN_LEFT);
254                 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
255                 break;
256
257         case MM_DELIM:
258                 if (active_ && active_ != delim_.get())
259                         active_->hide();
260                 delim_->show();
261                 break;
262
263         case MM_MATRIX:
264                 if (active_ && active_ != matrix_.get())
265                         active_->hide();
266                 matrix_->show();
267                 break;
268
269         case MM_DECO:
270                 if (active_ && active_ != deco_.get())
271                         active_->hide();
272                 deco_->show();
273                 break;
274
275         case MM_SPACE:
276                 if (active_ && active_ != space_.get())
277                         active_->hide();
278                 space_->show();
279                 break;
280
281         case MM_STYLE:
282                 if (active_ && active_ != style_.get())
283                         active_->hide();
284                 style_->show();
285                 break;
286
287         case MM_EQU:
288                 mathDisplay();
289                 break;
290
291         case MM_FUNC:
292                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
293                 insertSymbol(function_names[i]);
294                 break;
295         }
296
297         return true;
298 }
299
300
301 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
302 {
303         if (bs) 
304                 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, '\\' + sym);
305         else 
306                 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, sym);
307 }
308
309
310 void FormMathsPanel::dispatchFunc(kb_action action) const
311 {
312         lv_->getLyXFunc()->dispatch(action);
313 }
314
315
316 void FormMathsPanel::mathDisplay() const
317 {
318         lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
319 }
320
321
322
323 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
324                            string const & t, bool allowResize)
325     : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_("Close")
326 {}
327
328
329 void FormMathsSub::connect()
330 {
331         parent_.setActive(this);
332         FormBaseBD::connect();
333 }
334
335
336 void FormMathsSub::disconnect()
337 {
338         parent_.setActive(0);
339         FormBaseBD::disconnect();
340 }
341
342