]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
change X-windows to X window
[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
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"), false),
58           active_(0), bc_("Close")
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_dots);
98         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
99                 latex[i] = latex_dots[i];
100         }
101
102         dots_.reset(new FormMathsBitmap(lv, d, *this, latex));
103
104         latex.resize(nr_latex_varsz);
105         for (StringVec::size_type i = 0; i<latex.size(); ++i) {
106                 latex[i] = latex_varsz[i];
107         }
108         varsize_.reset(new FormMathsBitmap(lv, d, *this, latex));
109
110         d->showMathPanel.connect(slot(this, &FormMathsPanel::show));
111 }
112
113
114 FL_FORM * FormMathsPanel::form() const
115 {
116         if (dialog_.get())
117                 return dialog_->form;
118         return 0;
119 }
120
121
122 void FormMathsPanel::setActive(FormMathsSub * a) const
123 {
124         active_ = a;
125 }
126
127
128 void FormMathsPanel::build()
129 {
130         dialog_.reset(build_maths_panel());
131         
132         for (int i = 0; i < nr_function_names; ++i)
133                 fl_add_browser_line(dialog_->browser_funcs,
134                                     function_names[i]);
135         
136         fl_set_pixmap_data(dialog_->button_sqrt,
137                            const_cast<char**>(sqrt_xpm));
138         fl_set_pixmap_data(dialog_->button_frac,
139                            const_cast<char**>(frac));
140         fl_set_pixmap_data(dialog_->button_delim,
141                            const_cast<char**>(delim));
142         fl_set_pixmap_data(dialog_->button_deco,
143                            const_cast<char**>(deco));
144         fl_set_pixmap_data(dialog_->button_space,
145                            const_cast<char**>(space_xpm));
146         fl_set_pixmap_data(dialog_->button_matrix,
147                            const_cast<char**>(matrix));
148         fl_set_pixmap_data(dialog_->button_equation,
149                            const_cast<char**>(equation));
150
151         arrow_->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
152         arrow_->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
153                           false);
154         arrow_->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
155         
156         boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
157
158         brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
159
160         greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
161         greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
162
163         misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
164  
165         dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
166
167         varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
168
169         bc().setCancel(dialog_->button_close);
170 }
171
172 bool FormMathsPanel::input(FL_OBJECT *, long data)
173 {
174         MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
175
176         switch (val) {
177         case MM_GREEK:
178                 if (active_ && active_ != greek_.get())
179                         active_->hide();
180                 greek_->show();
181                 break;
182
183         case MM_ARROW:
184                 if (active_ && active_ != arrow_.get())
185                         active_->hide();
186                 arrow_->show();
187                 break;
188
189         case MM_BOP:
190                 if (active_ && active_ != boperator_.get())
191                         active_->hide();
192                 boperator_->show();
193                 break;
194
195         case MM_BRELATS:
196                 if (active_ && active_ != brelats_.get())
197                         active_->hide();
198                 brelats_->show();
199                 break;
200
201         case MM_MISC:
202                 if (active_ && active_ != misc_.get())
203                         active_->hide();
204                 misc_->show();
205                 break;
206
207         case MM_DOTS:
208                 if (active_ && active_ != dots_.get())
209                         active_->hide();
210                 dots_->show();
211                 break;
212  
213         case MM_VARSIZE:
214                 if (active_ && active_ != varsize_.get())
215                         active_->hide();
216                 varsize_->show();
217                 break;
218
219         case MM_FRAC:
220                 insertSymbol("frac");
221                 break;
222
223         case MM_SQRT:
224                 insertSymbol("sqrt");
225                 break;
226
227         case MM_DELIM:
228                 if (active_ && active_ != delim_.get())
229                         active_->hide();
230                 delim_->show();
231                 break;
232
233         case MM_MATRIX:
234                 if (active_ && active_ != matrix_.get())
235                         active_->hide();
236                 matrix_->show();
237                 break;
238
239         case MM_DECO:
240                 if (active_ && active_ != deco_.get())
241                         active_->hide();
242                 deco_->show();
243                 break;
244
245         case MM_SPACE:
246                 if (active_ && active_ != space_.get())
247                         active_->hide();
248                 space_->show();
249                 break;
250
251         case MM_EQU:
252                 mathDisplay();
253                 break;
254
255         case MM_FUNC:
256                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
257                 insertSymbol(function_names[i]);
258                 break;
259         }
260
261         return true;
262 }
263
264
265 void FormMathsPanel::insertSymbol(string const & sym) const
266 {
267         lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, '\\' + sym);
268 }
269
270
271 void FormMathsPanel::mathDisplay() const
272 {
273         lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
274 }
275
276
277
278 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
279                            string const & t, bool allowResize)
280     : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_("Close")
281 {}
282
283
284 void FormMathsSub::connect()
285 {
286         parent_.setActive(this);
287         FormBaseBD::connect();
288 }
289
290
291 void FormMathsSub::disconnect()
292 {
293         parent_.setActive(0);
294         FormBaseBD::disconnect();
295 }
296
297