]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsPanel.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / FormMathsPanel.C
1 /**
2  * \file FormMathsPanel.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlMath.h"
21 #include "FormMathsPanel.h"
22 #include "forms/form_maths_panel.h"
23 #include "xformsBC.h"
24
25 #include "FormMathsBitmap.h"
26 #include "FormMathsDeco.h"
27 #include "FormMathsDelim.h"
28 #include "FormMathsMatrix.h"
29 #include "FormMathsSpace.h"
30 #include "FormMathsStyle.h"
31
32 #include "forms/form_maths_deco.h"
33 #include "forms/form_maths_delim.h"
34 #include "forms/form_maths_matrix.h"
35 #include "forms/form_maths_space.h"
36 #include "forms/form_maths_style.h"
37
38 #include FORMS_H_LOCATION
39
40 #include "deco.xpm"
41 #include "delim.xpm"
42 #include "equation.xpm"
43 #include "frac.xpm"
44 #include "matrix.xpm"
45 #include "space.xpm"
46 #include "style.xpm"
47 #include "sqrt.xpm"
48 #include "sub.xpm"
49 #include "super.xpm"
50
51 #include "arrows.xbm"
52 #include "bop.xbm"
53 #include "brel.xbm"
54 #include "dots.xbm"
55 #include "greek.xbm"
56 #include "misc.xbm"
57 #include "varsz.xbm"
58
59 #include "ams_misc.xbm"
60 #include "ams_arrows.xbm"
61 #include "ams_rel.xbm"
62 #include "ams_nrel.xbm"
63 #include "ams_ops.xbm"
64
65
66 typedef FormCB<ControlMath, FormDB<FD_maths_panel> > base_class;
67
68 FormMathsPanel::FormMathsPanel()
69         : base_class(_("Maths Panel"))
70 {}
71
72
73 FormMathsBitmap * FormMathsPanel::addDaughter(void * key,
74                                               string const & title,
75                                               char const * const * data,
76                                               int size)
77 {
78         char const * const * const end = data + size;
79         FormMathsBitmap * const view =
80                 new FormMathsBitmap(title, std::vector<string>(data, end));
81
82         typedef ButtonController<IgnorantPolicy, xformsBC> BC;
83         BC * const bc = new BC;
84
85         controller().addDaughter(key, view, bc);
86         return view;
87 }
88
89
90 void FormMathsPanel::build()
91 {
92         dialog_.reset(build_maths_panel(this));
93
94         for (int i = 0; i < nr_function_names; ++i)
95                 fl_add_browser_line(dialog_->browser_funcs,
96                                     function_names[i]);
97
98         fl_set_pixmap_data(dialog_->button_sqrt,
99                            const_cast<char**>(sqrt_xpm));
100         fl_set_pixmap_data(dialog_->button_frac,
101                            const_cast<char**>(frac));
102         fl_set_pixmap_data(dialog_->button_super,
103                            const_cast<char**>(super_xpm));
104         fl_set_pixmap_data(dialog_->button_sub,
105                            const_cast<char**>(sub_xpm));
106         fl_set_pixmap_data(dialog_->button_delim,
107                            const_cast<char**>(delim));
108         fl_set_pixmap_data(dialog_->button_deco,
109                            const_cast<char**>(deco));
110         fl_set_pixmap_data(dialog_->button_space,
111                            const_cast<char**>(space_xpm));
112         fl_set_pixmap_data(dialog_->button_style,
113                            const_cast<char**>(style_xpm));
114         fl_set_pixmap_data(dialog_->button_matrix,
115                            const_cast<char**>(matrix));
116         fl_set_pixmap_data(dialog_->button_equation,
117                            const_cast<char**>(equation));
118
119         typedef ButtonController<IgnorantPolicy, xformsBC> BC_ignorant;
120         typedef ButtonController<OkApplyCancelReadOnlyPolicy, xformsBC> BC_ok;
121
122         controller().addDaughter(dialog_->button_deco,
123                                  new FormMathsDeco, new BC_ignorant);
124         controller().addDaughter(dialog_->button_delim,
125                                  new FormMathsDelim, new BC_ok);
126         controller().addDaughter(dialog_->button_matrix,
127                                  new FormMathsMatrix, new BC_ok);
128         controller().addDaughter(dialog_->button_space,
129                                  new FormMathsSpace, new BC_ignorant);
130         controller().addDaughter(dialog_->button_style,
131                                  new FormMathsStyle,  new BC_ignorant);
132
133         FormMathsBitmap * bitmap;
134         bitmap = addDaughter(dialog_->button_arrow, _("Arrows"),
135                              latex_arrow, nr_latex_arrow);
136         bitmap->addBitmap(20, 5, 4, arrow_width,  arrow_height,  arrow_bits);
137         bitmap->addBitmap(7,  2, 4, larrow_width, larrow_height, larrow_bits,
138                           false);
139         bitmap->addBitmap(4,  2, 2, darrow_width,  darrow_height, darrow_bits);
140
141         bitmap = addDaughter(dialog_->button_boperator, _("Binary Ops"),
142                              latex_bop, nr_latex_bop);
143         bitmap->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
144
145         bitmap = addDaughter(dialog_->button_brelats, _("Bin Relations"),
146                              latex_brel, nr_latex_brel);
147         bitmap->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
148
149         bitmap = addDaughter(dialog_->button_greek, _("Greek"),
150                              latex_greek, nr_latex_greek);
151         bitmap->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
152         bitmap->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
153
154         bitmap = addDaughter(dialog_->button_misc,_("Misc"),
155                              latex_misc, nr_latex_misc);
156         bitmap->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
157         bitmap->addBitmap(5, 5, 1, misc4_width, misc4_height, misc4_bits);
158         bitmap->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits,
159                           false);
160         bitmap->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
161
162         bitmap = addDaughter(dialog_->button_dots, _("Dots"),
163                              latex_dots, nr_latex_dots);
164         bitmap->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
165
166         bitmap = addDaughter(dialog_->button_varsize, _("Big Operators"),
167                      latex_varsz, nr_latex_varsz);
168         bitmap->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
169
170         bitmap = addDaughter(dialog_->button_ams_misc, _("AMS Misc"),
171                              latex_ams_misc, nr_latex_ams_misc);
172         bitmap->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
173         bitmap->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
174
175         bitmap = addDaughter(dialog_->button_ams_arrows, _("AMS Arrows"),
176                              latex_ams_arrows, nr_latex_ams_arrows);
177         bitmap->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
178         bitmap->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
179
180         bitmap = addDaughter(dialog_->button_ams_brel, _("AMS Relations"),
181                              latex_ams_rel, nr_latex_ams_rel);
182         bitmap->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height,
183                           ams_rel_bits);
184
185         bitmap = addDaughter(dialog_->button_ams_nrel, _("AMS Negated Rel"),
186                              latex_ams_nrel, nr_latex_ams_nrel);
187         bitmap->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height,
188                           ams_nrel_bits);
189
190         bitmap = addDaughter(dialog_->button_ams_ops, _("AMS Operators"),
191                              latex_ams_ops, nr_latex_ams_ops);
192         bitmap->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height,
193                           ams_ops_bits);
194
195         bc().setCancel(dialog_->button_close);
196 }
197
198
199 ButtonPolicy::SMInput FormMathsPanel::input(FL_OBJECT * ob, long)
200 {
201         if (ob == dialog_->button_arrow ||
202             ob == dialog_->button_boperator ||
203             ob == dialog_->button_brelats ||
204             ob == dialog_->button_greek ||
205             ob == dialog_->button_misc ||
206             ob == dialog_->button_dots ||
207             ob == dialog_->button_varsize ||
208             ob == dialog_->button_ams_misc ||
209             ob == dialog_->button_ams_arrows ||
210             ob == dialog_->button_ams_brel ||
211             ob == dialog_->button_ams_nrel ||
212             ob == dialog_->button_ams_ops ||
213             ob == dialog_->button_delim ||
214             ob == dialog_->button_matrix ||
215             ob == dialog_->button_deco ||
216             ob == dialog_->button_space ||
217             ob == dialog_->button_style) {
218                 controller().showDaughter(ob);
219
220         } else if (ob == dialog_->button_super) {
221                 controller().dispatchFunc(LFUN_SUPERSCRIPT);
222
223         } else if (ob == dialog_->button_sub) {
224                 controller().dispatchFunc(LFUN_SUBSCRIPT);
225
226 //      } else if (ob == dialog_->???) {
227 //              controller().dispatchFunc(LFUN_SUBSCRIPT);
228 //              controller().dispatchFunc(LFUN_LEFT);
229 //              controller().dispatchFunc(LFUN_SUPERSCRIPT);
230
231         } else if (ob == dialog_->button_equation) {
232                 controller().dispatchFunc(LFUN_MATH_DISPLAY);
233
234         } else if (ob == dialog_->button_frac) {
235                 controller().insertSymbol("frac");
236
237         } else if (ob == dialog_->button_sqrt) {
238                 controller().insertSymbol("sqrt");
239
240         } else if (ob == dialog_->browser_funcs) {
241                 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
242                 controller().insertSymbol(function_names[i]);
243         }
244
245         return ButtonPolicy::SMI_VALID;
246 }