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