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