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
20 #include "FormMathsPanel.h"
21 #include "form_maths_panel.h"
22 #include "MathsSymbols.h"
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 #include "form_maths_style.h"
32 #include "FormMathsBitmap.h"
33 #include "FormMathsDeco.h"
34 #include "FormMathsDelim.h"
35 #include "FormMathsMatrix.h"
36 #include "FormMathsSpace.h"
37 #include "FormMathsStyle.h"
39 #include "ButtonController.tmpl"
43 #include "equation.xpm"
63 FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d)
64 : FormBaseBD(lv, d, _("Maths Panel"), false),
65 active_(0), bc_("Close")
67 deco_.reset( new FormMathsDeco( lv, d, *this));
68 delim_.reset( new FormMathsDelim( lv, d, *this));
69 matrix_.reset(new FormMathsMatrix(lv, d, *this));
70 space_.reset( new FormMathsSpace( lv, d, *this));
71 style_.reset( new FormMathsStyle( lv, d, *this));
73 typedef vector<string> StringVec;
75 StringVec latex(nr_latex_arrow);
76 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
77 latex[i] = latex_arrow[i];
79 arrow_.reset(new FormMathsBitmap(lv, d, *this, latex));
81 latex.resize(nr_latex_bop);
82 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
83 latex[i] = latex_bop[i];
85 boperator_.reset(new FormMathsBitmap(lv, d, *this, latex));
87 latex.resize(nr_latex_brel);
88 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
89 latex[i] = latex_brel[i];
91 brelats_.reset(new FormMathsBitmap(lv, d, *this, latex));
93 latex.resize(nr_latex_greek);
94 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
95 latex[i] = latex_greek[i];
97 greek_.reset(new FormMathsBitmap(lv, d, *this, latex));
99 latex.resize(nr_latex_misc);
100 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
101 latex[i] = latex_misc[i];
103 misc_.reset(new FormMathsBitmap(lv, d, *this, latex));
105 latex.resize(nr_latex_dots);
106 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
107 latex[i] = latex_dots[i];
110 dots_.reset(new FormMathsBitmap(lv, d, *this, latex));
112 latex.resize(nr_latex_varsz);
113 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
114 latex[i] = latex_varsz[i];
116 varsize_.reset(new FormMathsBitmap(lv, d, *this, latex));
118 d->showMathPanel.connect(slot(this, &FormMathsPanel::show));
122 FL_FORM * FormMathsPanel::form() const
125 return dialog_->form;
130 void FormMathsPanel::setActive(FormMathsSub * a) const
136 void FormMathsPanel::build()
138 dialog_.reset(build_maths_panel());
140 for (int i = 0; i < nr_function_names; ++i)
141 fl_add_browser_line(dialog_->browser_funcs,
144 fl_set_pixmap_data(dialog_->button_sqrt,
145 const_cast<char**>(sqrt_xpm));
146 fl_set_pixmap_data(dialog_->button_frac,
147 const_cast<char**>(frac));
148 fl_set_pixmap_data(dialog_->button_super,
149 const_cast<char**>(super_xpm));
150 fl_set_pixmap_data(dialog_->button_sub,
151 const_cast<char**>(sub_xpm));
152 fl_set_pixmap_data(dialog_->button_delim,
153 const_cast<char**>(delim));
154 fl_set_pixmap_data(dialog_->button_deco,
155 const_cast<char**>(deco));
156 fl_set_pixmap_data(dialog_->button_space,
157 const_cast<char**>(space_xpm));
158 fl_set_pixmap_data(dialog_->button_style,
159 const_cast<char**>(style_xpm));
160 fl_set_pixmap_data(dialog_->button_matrix,
161 const_cast<char**>(matrix));
162 fl_set_pixmap_data(dialog_->button_equation,
163 const_cast<char**>(equation));
165 arrow_->addBitmap(20, 5, 4, arrow_width, arrow_height, arrow_bits);
166 arrow_->addBitmap(7, 2, 4, larrow_width, larrow_height, larrow_bits,
168 arrow_->addBitmap(4, 2, 2, darrow_width, darrow_height, darrow_bits);
170 boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
172 brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
174 greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
175 greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
177 misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
178 misc_->addBitmap(6, 3, 2, misc2_width, misc2_height, misc2_bits, false);
179 misc_->addBitmap(4, 2, 2, misc3_width, misc3_height, misc3_bits);
181 dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
183 varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
185 bc().setCancel(dialog_->button_close);
188 bool FormMathsPanel::input(FL_OBJECT *, long data)
190 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
194 if (active_ && active_ != greek_.get())
200 if (active_ && active_ != arrow_.get())
206 if (active_ && active_ != boperator_.get())
212 if (active_ && active_ != brelats_.get())
218 if (active_ && active_ != misc_.get())
224 if (active_ && active_ != dots_.get())
230 if (active_ && active_ != varsize_.get())
236 insertSymbol("frac");
240 insertSymbol("sqrt");
244 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
245 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
249 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
250 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
254 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
255 lv_->getLyXFunc()->dispatch(LFUN_LEFT);
256 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
260 if (active_ && active_ != delim_.get())
266 if (active_ && active_ != matrix_.get())
272 if (active_ && active_ != deco_.get())
278 if (active_ && active_ != space_.get())
284 if (active_ && active_ != style_.get())
294 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
295 insertSymbol(function_names[i]);
303 void FormMathsPanel::insertSymbol(string const & sym, bool bs) const
306 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, '\\' + sym);
308 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, sym);
312 void FormMathsPanel::dispatchFunc(kb_action action) const
314 lv_->getLyXFunc()->dispatch(action);
318 void FormMathsPanel::mathDisplay() const
320 lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
325 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
326 string const & t, bool allowResize)
327 : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_("Close")
331 void FormMathsSub::connect()
333 parent_.setActive(this);
334 FormBaseBD::connect();
338 void FormMathsSub::disconnect()
340 parent_.setActive(0);
341 FormBaseBD::disconnect();