2 * \file FormMathsPanel.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
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
15 #pragma implementation
19 #include "frontends/LyXView.h"
20 #include "FormMathsPanel.h"
21 #include "forms/form_maths_panel.h"
22 #include "MathsSymbols.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"
70 FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d)
71 : FormBaseBD(lv, d, _("Maths Panel"), false),
72 active_(0), bc_(_("Close"))
74 deco_.reset( new FormMathsDeco( lv, d, *this));
75 delim_.reset( new FormMathsDelim( lv, d, *this));
76 matrix_.reset(new FormMathsMatrix(lv, d, *this));
77 space_.reset( new FormMathsSpace( lv, d, *this));
78 style_.reset( new FormMathsStyle( lv, d, *this));
80 typedef vector<string> StringVec;
82 StringVec latex(nr_latex_arrow);
83 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
84 latex[i] = latex_arrow[i];
86 arrow_.reset(new FormMathsBitmap(lv, d, *this, _("Arrows"), latex));
88 latex.resize(nr_latex_bop);
89 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
90 latex[i] = latex_bop[i];
92 boperator_.reset(new FormMathsBitmap(lv, d, *this, _("Binary Ops"), latex));
94 latex.resize(nr_latex_brel);
95 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
96 latex[i] = latex_brel[i];
98 brelats_.reset(new FormMathsBitmap(lv, d, *this, _("Bin Relations"), latex));
100 latex.resize(nr_latex_greek);
101 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
102 latex[i] = latex_greek[i];
104 greek_.reset(new FormMathsBitmap(lv, d, *this, _("Greek"), latex));
106 latex.resize(nr_latex_misc);
107 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
108 latex[i] = latex_misc[i];
110 misc_.reset(new FormMathsBitmap(lv, d, *this, _("Misc"), latex));
112 latex.resize(nr_latex_dots);
113 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
114 latex[i] = latex_dots[i];
116 dots_.reset(new FormMathsBitmap(lv, d, *this, _("Dots"), latex));
118 latex.resize(nr_latex_varsz);
119 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
120 latex[i] = latex_varsz[i];
122 varsize_.reset(new FormMathsBitmap(lv, d, *this, _("Big Operators"), latex));
124 latex.resize(nr_latex_ams_misc);
125 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
126 latex[i] = latex_ams_misc[i];
128 ams_misc_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Misc"), latex));
130 latex.resize(nr_latex_ams_arrows);
131 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
132 latex[i] = latex_ams_arrows[i];
134 ams_arrows_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Arrows"), latex));
136 latex.resize(nr_latex_ams_rel);
137 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
138 latex[i] = latex_ams_rel[i];
140 ams_rel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Relations"), latex));
142 latex.resize(nr_latex_ams_nrel);
143 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
144 latex[i] = latex_ams_nrel[i];
146 ams_nrel_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Negated Rel"), latex));
148 latex.resize(nr_latex_ams_ops);
149 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
150 latex[i] = latex_ams_ops[i];
152 ams_ops_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Operators"), latex));
154 //showUnderMouse(false);
158 FL_FORM * FormMathsPanel::form() const
161 return dialog_->form;
166 void FormMathsPanel::setActive(FormMathsSub * a) const
172 void FormMathsPanel::build()
174 dialog_.reset(build_maths_panel(this));
176 for (int i = 0; i < nr_function_names; ++i)
177 fl_add_browser_line(dialog_->browser_funcs,
180 fl_set_pixmap_data(dialog_->button_sqrt,
181 const_cast<char**>(sqrt_xpm));
182 fl_set_pixmap_data(dialog_->button_frac,
183 const_cast<char**>(frac));
184 fl_set_pixmap_data(dialog_->button_super,
185 const_cast<char**>(super_xpm));
186 fl_set_pixmap_data(dialog_->button_sub,
187 const_cast<char**>(sub_xpm));
188 fl_set_pixmap_data(dialog_->button_delim,
189 const_cast<char**>(delim));
190 fl_set_pixmap_data(dialog_->button_deco,
191 const_cast<char**>(deco));
192 fl_set_pixmap_data(dialog_->button_space,
193 const_cast<char**>(space_xpm));
194 fl_set_pixmap_data(dialog_->button_style,
195 const_cast<char**>(style_xpm));
196 fl_set_pixmap_data(dialog_->button_matrix,
197 const_cast<char**>(matrix));
198 fl_set_pixmap_data(dialog_->button_equation,
199 const_cast<char**>(equation));
201 arrow_->addBitmap(20, 5, 4, arrow_width, arrow_height, arrow_bits);
202 arrow_->addBitmap(7, 2, 4, larrow_width, larrow_height, larrow_bits,
204 arrow_->addBitmap(4, 2, 2, darrow_width, darrow_height, darrow_bits);
206 boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
208 brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
210 greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
211 greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
213 misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
214 misc_->addBitmap(5, 5, 1, misc4_width, misc4_height, misc4_bits);
215 misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
216 misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
218 dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
220 varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
222 ams_misc_->addBitmap(9, 5, 2, ams1_width, ams1_height, ams1_bits);
223 ams_misc_->addBitmap(26, 3, 9, ams7_width, ams7_height, ams7_bits);
225 ams_arrows_->addBitmap(32, 3, 11, ams2_width, ams2_height, ams2_bits);
226 ams_arrows_->addBitmap(6, 3, 2, ams3_width, ams3_height, ams3_bits);
228 ams_rel_->addBitmap(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits);
230 ams_nrel_->addBitmap(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits);
232 ams_ops_->addBitmap(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits);
234 bc().setCancel(dialog_->button_close);
237 bool FormMathsPanel::input(FL_OBJECT *, long data)
239 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
243 if (active_ && active_ != greek_.get())
249 if (active_ && active_ != arrow_.get())
255 if (active_ && active_ != boperator_.get())
261 if (active_ && active_ != brelats_.get())
267 if (active_ && active_ != misc_.get())
273 if (active_ && active_ != dots_.get())
279 if (active_ && active_ != varsize_.get())
285 if (active_ && active_ != ams_misc_.get())
291 if (active_ && active_ != ams_arrows_.get())
297 if (active_ && active_ != ams_rel_.get())
303 if (active_ && active_ != ams_nrel_.get())
309 if (active_ && active_ != ams_ops_.get())
315 insertSymbol("frac");
319 insertSymbol("sqrt");
323 //lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
324 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
328 //lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
329 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
333 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
334 lv_->getLyXFunc()->dispatch(LFUN_LEFT);
335 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
339 if (active_ && active_ != delim_.get())
345 if (active_ && active_ != matrix_.get())
351 if (active_ && active_ != deco_.get())
357 if (active_ && active_ != space_.get())
363 if (active_ && active_ != style_.get())
373 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
374 insertSymbol(function_names[i]);
382 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
385 lv_->getLyXFunc()->dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
387 lv_->getLyXFunc()->dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
391 void FormMathsPanel::dispatchFunc(kb_action action) const
393 lv_->getLyXFunc()->dispatch(action);
397 void FormMathsPanel::mathDisplay() const
399 lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
404 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
405 string const & t, bool allowResize)
406 : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_(_("Close"))
410 void FormMathsSub::connect()
412 parent_.setActive(this);
413 FormBaseBD::connect();
417 void FormMathsSub::disconnect()
419 parent_.setActive(0);
420 FormBaseBD::disconnect();