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