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"
41 #include "equation.xpm"
61 FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d)
62 : FormBaseBD(lv, d, _("Maths Panel"), false),
63 active_(0), bc_("Close")
65 deco_.reset( new FormMathsDeco( lv, d, *this));
66 delim_.reset( new FormMathsDelim( lv, d, *this));
67 matrix_.reset(new FormMathsMatrix(lv, d, *this));
68 space_.reset( new FormMathsSpace( lv, d, *this));
69 style_.reset( new FormMathsStyle( lv, d, *this));
71 typedef vector<string> StringVec;
73 StringVec latex(nr_latex_arrow);
74 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
75 latex[i] = latex_arrow[i];
77 arrow_.reset(new FormMathsBitmap(lv, d, *this, latex));
79 latex.resize(nr_latex_bop);
80 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
81 latex[i] = latex_bop[i];
83 boperator_.reset(new FormMathsBitmap(lv, d, *this, latex));
85 latex.resize(nr_latex_brel);
86 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
87 latex[i] = latex_brel[i];
89 brelats_.reset(new FormMathsBitmap(lv, d, *this, latex));
91 latex.resize(nr_latex_greek);
92 for (StringVec::size_type i = 0; i < latex.size(); ++i) {
93 latex[i] = latex_greek[i];
95 greek_.reset(new FormMathsBitmap(lv, d, *this, latex));
97 latex.resize(nr_latex_misc);
98 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
99 latex[i] = latex_misc[i];
101 misc_.reset(new FormMathsBitmap(lv, d, *this, latex));
103 latex.resize(nr_latex_dots);
104 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
105 latex[i] = latex_dots[i];
108 dots_.reset(new FormMathsBitmap(lv, d, *this, latex));
110 latex.resize(nr_latex_varsz);
111 for (StringVec::size_type i = 0; i<latex.size(); ++i) {
112 latex[i] = latex_varsz[i];
114 varsize_.reset(new FormMathsBitmap(lv, d, *this, latex));
116 d->showMathPanel.connect(slot(this, &FormMathsPanel::show));
120 FL_FORM * FormMathsPanel::form() const
123 return dialog_->form;
128 void FormMathsPanel::setActive(FormMathsSub * a) const
134 void FormMathsPanel::build()
136 dialog_.reset(build_maths_panel());
138 for (int i = 0; i < nr_function_names; ++i)
139 fl_add_browser_line(dialog_->browser_funcs,
142 fl_set_pixmap_data(dialog_->button_sqrt,
143 const_cast<char**>(sqrt_xpm));
144 fl_set_pixmap_data(dialog_->button_frac,
145 const_cast<char**>(frac));
146 fl_set_pixmap_data(dialog_->button_super,
147 const_cast<char**>(super_xpm));
148 fl_set_pixmap_data(dialog_->button_sub,
149 const_cast<char**>(sub_xpm));
150 fl_set_pixmap_data(dialog_->button_delim,
151 const_cast<char**>(delim));
152 fl_set_pixmap_data(dialog_->button_deco,
153 const_cast<char**>(deco));
154 fl_set_pixmap_data(dialog_->button_space,
155 const_cast<char**>(space_xpm));
156 fl_set_pixmap_data(dialog_->button_style,
157 const_cast<char**>(style_xpm));
158 fl_set_pixmap_data(dialog_->button_matrix,
159 const_cast<char**>(matrix));
160 fl_set_pixmap_data(dialog_->button_equation,
161 const_cast<char**>(equation));
163 arrow_->addBitmap(20, 5, 4, arrow_width, arrow_height, arrow_bits);
164 arrow_->addBitmap(7, 2, 4, larrow_width, larrow_height, larrow_bits,
166 arrow_->addBitmap(4, 2, 2, darrow_width, darrow_height, darrow_bits);
168 boperator_->addBitmap(31, 4, 8, bop_width, bop_height, bop_bits);
170 brelats_->addBitmap(35, 4, 9, brel_width, brel_height, brel_bits);
172 greek_->addBitmap(11, 6, 2, Greek_width, Greek_height, Greek_bits);
173 greek_->addBitmap(28, 7, 4, greek_width, greek_height, greek_bits);
175 misc_->addBitmap(29, 5, 6, misc_width, misc_height, misc_bits);
177 dots_->addBitmap(4, 4, 1, dots_width, dots_height, dots_bits);
179 varsize_->addBitmap(14, 3, 5, varsz_width, varsz_height, varsz_bits);
181 bc().setCancel(dialog_->button_close);
184 bool FormMathsPanel::input(FL_OBJECT *, long data)
186 MathsCallbackValues val = static_cast<MathsCallbackValues>(data);
190 if (active_ && active_ != greek_.get())
196 if (active_ && active_ != arrow_.get())
202 if (active_ && active_ != boperator_.get())
208 if (active_ && active_ != brelats_.get())
214 if (active_ && active_ != misc_.get())
220 if (active_ && active_ != dots_.get())
226 if (active_ && active_ != varsize_.get())
232 insertSymbol("frac");
236 insertSymbol("sqrt");
240 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
241 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
245 lv_->getLyXFunc()->dispatch(LFUN_MATH_MODE);
246 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
250 lv_->getLyXFunc()->dispatch(LFUN_SUBSCRIPT);
251 lv_->getLyXFunc()->dispatch(LFUN_LEFT);
252 lv_->getLyXFunc()->dispatch(LFUN_SUPERSCRIPT);
256 if (active_ && active_ != delim_.get())
262 if (active_ && active_ != matrix_.get())
268 if (active_ && active_ != deco_.get())
274 if (active_ && active_ != space_.get())
280 if (active_ && active_ != style_.get())
290 int const i = fl_get_browser(dialog_->browser_funcs) - 1;
291 insertSymbol(function_names[i]);
299 void FormMathsPanel::insertSymbol(string const & sym) const
301 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATH, '\\' + sym);
305 void FormMathsPanel::dispatchFunc(kb_action action) const
307 lv_->getLyXFunc()->dispatch(action);
311 void FormMathsPanel::mathDisplay() const
313 lv_->getLyXFunc()->dispatch(LFUN_MATH_DISPLAY);
318 FormMathsSub::FormMathsSub(LyXView * lv, Dialogs * d, FormMathsPanel const & p,
319 string const & t, bool allowResize)
320 : FormBaseBD(lv, d, t, allowResize), parent_(p), bc_("Close")
324 void FormMathsSub::connect()
326 parent_.setActive(this);
327 FormBaseBD::connect();
331 void FormMathsSub::disconnect()
333 parent_.setActive(0);
334 FormBaseBD::disconnect();