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