2 * \file FormMathsPanel.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS
17 #pragma implementation
20 #include "ControlMath.h"
22 #include "frontends/LyXView.h"
23 #include "FormMathsPanel.h"
24 #include "forms/form_maths_panel.h"
25 #include "funcrequest.h"
27 #include "forms/form_maths_deco.h"
28 #include "forms/form_maths_delim.h"
29 #include "forms/form_maths_matrix.h"
30 #include "forms/form_maths_space.h"
31 #include "forms/form_maths_style.h"
33 #include "FormMathsBitmap.h"
34 #include "FormMathsDeco.h"
35 #include "FormMathsDelim.h"
36 #include "FormMathsMatrix.h"
37 #include "FormMathsSpace.h"
38 #include "FormMathsStyle.h"
40 #include FORMS_H_LOCATION
41 #include <boost/bind.hpp>
45 #include "equation.xpm"
62 #include "ams_misc.xbm"
63 #include "ams_arrows.xbm"
64 #include "ams_rel.xbm"
65 #include "ams_nrel.xbm"
66 #include "ams_ops.xbm"
69 FormMathsPanel::FormMathsPanel(LyXView & lv, Dialogs & d)
70 : FormBaseBD(lv, d, _("Maths Panel")),
71 active_(0), bc_(_("Close"))
73 deco_.reset( new FormMathsDeco( lv, d, *this));
74 delim_.reset( new FormMathsDelim( lv, d, *this));
75 matrix_.reset(new FormMathsMatrix(lv, d, *this));
76 space_.reset( new FormMathsSpace( lv, d, *this));
77 style_.reset( new FormMathsStyle( lv, d, *this));
79 typedef std::vector<string> StringVec;
80 char const * const * begin = latex_arrow;
81 char const * const * end = begin + nr_latex_arrow;
82 arrow_.reset(new FormMathsBitmap(lv, d, *this, _("Arrows"),
83 StringVec(begin, end)));
86 end = begin + nr_latex_bop;
87 boperator_.reset(new FormMathsBitmap(lv, d, *this, _("Binary Ops"),
88 StringVec(begin, end)));
91 end = begin + nr_latex_brel;
92 brelats_.reset(new FormMathsBitmap(lv, d, *this, _("Bin Relations"),
93 StringVec(begin, end)));
96 end = begin + nr_latex_greek;
97 greek_.reset(new FormMathsBitmap(lv, d, *this, _("Greek"),
98 StringVec(begin, end)));
101 end = begin + nr_latex_misc;
102 misc_.reset(new FormMathsBitmap(lv, d, *this, _("Misc"),
103 StringVec(begin, end)));
106 end = begin + nr_latex_dots;
107 dots_.reset(new FormMathsBitmap(lv, d, *this, _("Dots"),
108 StringVec(begin, end)));
111 end = begin + nr_latex_varsz;
112 varsize_.reset(new FormMathsBitmap(lv, d, *this, _("Big Operators"),
113 StringVec(begin, end)));
115 begin = latex_ams_misc;
116 end = begin + nr_latex_ams_misc;
117 ams_misc_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Misc"),
118 StringVec(begin, end)));
120 begin = latex_ams_arrows;
121 end = begin + nr_latex_ams_arrows;
122 ams_arrows_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Arrows"),
123 StringVec(begin, end)));
125 begin = latex_ams_rel;
126 end = begin + nr_latex_ams_rel;
127 ams_rel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Relations"),
128 StringVec(begin, end)));
130 begin = latex_ams_nrel;
131 end = begin + nr_latex_ams_nrel;
132 ams_nrel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Negated Rel"),
133 StringVec(begin, end)));
135 begin = latex_ams_ops;
136 end = begin + nr_latex_ams_ops;
137 ams_ops_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Operators"),
138 StringVec(begin, end)));
142 FL_FORM * FormMathsPanel::form() const
144 return dialog_.get() ? dialog_->form : 0;
148 void FormMathsPanel::setActive(FormMathsSub * a) const
154 void FormMathsPanel::build()
156 dialog_.reset(build_maths_panel(this));
158 for (int i = 0; i < nr_function_names; ++i)
159 fl_add_browser_line(dialog_->browser_funcs,
162 fl_set_pixmap_data(dialog_->button_sqrt,
163 const_cast<char**>(sqrt_xpm));
164 fl_set_pixmap_data(dialog_->button_frac,
165 const_cast<char**>(frac));
166 fl_set_pixmap_data(dialog_->button_super,
167 const_cast<char**>(super_xpm));
168 fl_set_pixmap_data(dialog_->button_sub,
169 const_cast<char**>(sub_xpm));
170 fl_set_pixmap_data(dialog_->button_delim,
171 const_cast<char**>(delim));
172 fl_set_pixmap_data(dialog_->button_deco,
173 const_cast<char**>(deco));
174 fl_set_pixmap_data(dialog_->button_space,
175 const_cast<char**>(space_xpm));
176 fl_set_pixmap_data(dialog_->button_style,
177 const_cast<char**>(style_xpm));
178 fl_set_pixmap_data(dialog_->button_matrix,
179 const_cast<char**>(matrix));
180 fl_set_pixmap_data(dialog_->button_equation,
181 const_cast<char**>(equation));
183 arrow_->addBitmap(20, 5, 4, arrow_width, arrow_height, arrow_bits);
184 arrow_->addBitmap(7, 2, 4, larrow_width, larrow_height, larrow_bits,
186 arrow_->addBitmap(4, 2, 2, darrow_width, darrow_height, darrow_bits);
188 boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
190 brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
192 greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
193 greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
195 misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
196 misc_->addBitmap(5, 5, 1, misc4_width, misc4_height, misc4_bits);
197 misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
198 misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
200 dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
202 varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
204 ams_misc_->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
205 ams_misc_->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
207 ams_arrows_->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
208 ams_arrows_->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
210 ams_rel_->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits);
212 ams_nrel_->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits);
214 ams_ops_->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits);
216 bc().setCancel(dialog_->button_close);
220 bool FormMathsPanel::input(FL_OBJECT * ob, long)
222 if (ob == dialog_->button_greek) {
223 if (active_ && active_ != greek_.get())
227 } else if (ob == dialog_->button_arrow) {
228 if (active_ && active_ != arrow_.get())
232 } else if (ob == dialog_->button_boperator) {
233 if (active_ && active_ != boperator_.get())
237 } else if (ob == dialog_->button_brelats) {
238 if (active_ && active_ != brelats_.get())
242 } else if (ob == dialog_->button_misc) {
243 if (active_ && active_ != misc_.get())
247 } else if (ob == dialog_->button_dots) {
248 if (active_ && active_ != dots_.get())
252 } else if (ob == dialog_->button_varsize) {
253 if (active_ && active_ != varsize_.get())
257 } else if (ob == dialog_->button_ams_misc) {
258 if (active_ && active_ != ams_misc_.get())
262 } else if (ob == dialog_->button_ams_arrows) {
263 if (active_ && active_ != ams_arrows_.get())
267 } else if (ob == dialog_->button_ams_brel) {
268 if (active_ && active_ != ams_rel_.get())
272 } else if (ob == dialog_->button_ams_nrel) {
273 if (active_ && active_ != ams_nrel_.get())
277 } else if (ob == dialog_->button_ams_ops) {
278 if (active_ && active_ != ams_ops_.get())
282 } else if (ob == dialog_->button_frac) {
283 insertSymbol("frac");
285 } else if (ob == dialog_->button_sqrt) {
286 insertSymbol("sqrt");
288 } else if (ob == dialog_->button_super) {
289 lv_.dispatch(FuncRequest(LFUN_SUPERSCRIPT));
291 } else if (ob == dialog_->button_sub) {
292 lv_.dispatch(FuncRequest(LFUN_SUBSCRIPT));
294 // } else if (ob == dialog_->???) {
295 // lv_.dispatch(FuncRequest(LFUN_SUBSCRIPT));
296 // lv_.dispatch(FuncRequest(LFUN_LEFT));
297 // lv_.dispatch(FuncRequest(LFUN_SUPERSCRIPT));
299 } else if (ob == dialog_->button_delim) {
300 if (active_ && active_ != delim_.get())
304 } else if (ob == dialog_->button_matrix) {
305 if (active_ && active_ != matrix_.get())
309 } else if (ob == dialog_->button_deco) {
310 if (active_ && active_ != deco_.get())
314 } else if (ob == dialog_->button_space) {
315 if (active_ && active_ != space_.get())
319 } else if (ob == dialog_->button_style) {
320 if (active_ && active_ != style_.get())
324 } else if (ob == dialog_->button_equation) {
327 } else if (ob == dialog_->browser_funcs) {
328 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
329 insertSymbol(function_names[i]);
336 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
339 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
341 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
345 void FormMathsPanel::dispatchFunc(kb_action action) const
347 lv_.dispatch(FuncRequest(action));
351 void FormMathsPanel::mathDisplay() const
353 lv_.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
358 FormMathsSub::FormMathsSub(LyXView & lv, Dialogs & d, FormMathsPanel const & p,
359 string const & t, bool allowResize)
360 : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_(_("Close"))
364 void FormMathsSub::connect()
366 parent_.setActive(this);
367 FormBaseBD::connect();
371 void FormMathsSub::disconnect()
373 parent_.setActive(0);
374 FormBaseBD::disconnect();