]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GMathPanel.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / gtk / GMathPanel.C
1 /**
2  * \file GMathPanel.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <gtkmm.h>
13
14 #include <libglademm.h>
15
16 #include "ControlMath.h"
17 #include "GMathPanel.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
20
21 #include "deco.xpm"
22 #include "delim.xpm"
23 #include "equation.xpm"
24 #include "frac.xpm"
25 #include "matrix.xpm"
26 #include "space.xpm"
27 #include "style.xpm"
28 #include "sqrt.xpm"
29 #include "sub.xpm"
30 #include "super.xpm"
31
32 using std::string;
33
34 GMathPanel::GMathPanel(Dialog & parent)
35         : GViewCB<ControlMath, GViewGladeB>(parent, _("Math Panel"))
36 {
37 }
38
39
40 void GMathPanel::doBuild()
41 {
42         string const gladeName =
43                 lyx::support::LibFileSearch("glade", "mathPanel", "glade");
44         xml_ = Gnome::Glade::Xml::create(gladeName);
45         Gtk::Button * close;
46
47         //1
48         Gtk::Button * sqrt;
49         Gtk::Button * frac;
50         Gtk::Button * delim;
51         Gtk::Button * deco;
52         Gtk::Button * space;
53
54         //2
55         Gtk::Button * super;
56         Gtk::Button * sub;
57         Gtk::Button * style;
58         Gtk::Button * matrix;
59         Gtk::Button * equation;
60
61         //3
62         Gtk::Button * boperator;
63         Gtk::Button * brelats;
64         Gtk::Button * arrow;
65
66         //4
67         Gtk::Button * varSize;
68         Gtk::Button * dots;
69         Gtk::Button * misc;
70
71         //5
72         Gtk::Button * greek;
73         Gtk::Button * amsArrows;
74         Gtk::Button * amsBrel;
75
76         //6
77         Gtk::Button * amsNrel;
78         Gtk::Button * amsOps;
79         Gtk::Button * amsMisc;
80
81         xml_->get_widget("Close", close);
82         close->signal_clicked().connect(
83                 SigC::slot(*this, &GViewBase::onCancel));
84
85         //1
86         xml_->get_widget("Sqrt", sqrt);
87         xml_->get_widget("Frac", frac);
88         xml_->get_widget("Delim", delim);
89         xml_->get_widget("Deco", deco);
90         xml_->get_widget("Space", space);
91
92         //2
93         xml_->get_widget("Super", super);
94         xml_->get_widget("Sub", sub);
95         xml_->get_widget("Style", style);
96         xml_->get_widget("Matrix", matrix);
97         xml_->get_widget("Equation", equation);
98
99         //3
100         xml_->get_widget("Boperator", boperator);
101         xml_->get_widget("Brelate", brelats);
102         xml_->get_widget("Arrow", arrow);
103
104         //4
105         xml_->get_widget("VarSize", varSize);
106         xml_->get_widget("Dots", dots);
107         xml_->get_widget("Misc", misc);
108
109         //5
110         xml_->get_widget("Greek", greek);
111         xml_->get_widget("AmsArrow", amsArrows);
112         xml_->get_widget("AmsBrel", amsBrel);
113
114         //6
115         xml_->get_widget("AmsNrel", amsNrel);
116         xml_->get_widget("AmsOps", amsOps);
117         xml_->get_widget("AmsMisc", amsMisc);
118
119         Glib::RefPtr<Gdk::Bitmap> mask;
120         Glib::RefPtr<Gdk::Pixmap> pixmap;
121         Glib::RefPtr<Gdk::Colormap> clrmap = window()->get_colormap();
122
123         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::sqrt_xpm);
124         Gtk::Image * iSqrt = SigC::manage(new Gtk::Image(pixmap, mask));
125         iSqrt->show();
126         sqrt->add(*iSqrt);
127
128         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::frac);
129         Gtk::Image * iFrac = SigC::manage(new Gtk::Image(pixmap, mask));
130         iFrac->show();
131         frac->add(*iFrac);
132
133         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::delim);
134         Gtk::Image * iDelim = SigC::manage(new Gtk::Image(pixmap, mask));
135         iDelim->show();
136         delim->add(*iDelim);
137
138         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::deco);
139         Gtk::Image * iDeco = SigC::manage(new Gtk::Image(pixmap, mask));
140         iDeco->show();
141         deco->add(*iDeco);
142
143         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::space_xpm);
144         Gtk::Image * iSpace = SigC::manage(new Gtk::Image(pixmap, mask));
145         iSpace->show();
146         space->add(*iSpace);
147
148         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::super_xpm);
149         Gtk::Image * iSuper = SigC::manage(new Gtk::Image(pixmap, mask));
150         iSuper->show();
151         super->add(*iSuper);
152
153         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::sub_xpm);
154         Gtk::Image * iSub = SigC::manage(new Gtk::Image(pixmap, mask));
155         iSub->show();
156         sub->add(*iSub);
157
158         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::style_xpm);
159         Gtk::Image * iStyle = SigC::manage(new Gtk::Image(pixmap, mask));
160         iStyle->show();
161         style->add(*iStyle);
162
163         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::matrix);
164         Gtk::Image * iMatrix = SigC::manage(new Gtk::Image(pixmap, mask));
165         iMatrix->show();
166         matrix->add(*iMatrix);
167
168         pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, ::equation);
169         Gtk::Image * iEquation = SigC::manage(new Gtk::Image(pixmap, mask));
170         iEquation->show();
171         equation->add(*iEquation);
172
173         arrow->signal_clicked().connect(
174                 SigC::bind<char const *>(
175                         SigC::slot(*this,
176                                    &GMathPanel::onShowDialog),
177                         "matharrows"));
178         deco->signal_clicked().connect(
179                 SigC::bind<char const *>(
180                         SigC::slot(*this,
181                                    &GMathPanel::onShowDialog),
182                         "mathaccents"));
183         boperator->signal_clicked().connect(
184                 SigC::bind<char const *>(
185                         SigC::slot(*this,
186                                    &GMathPanel::onShowDialog),
187                         "mathoperators"));
188         brelats->signal_clicked().connect(
189                 SigC::bind<char const *>(
190                         SigC::slot(*this,
191                                    &GMathPanel::onShowDialog),
192                         "mathrelations"));
193         greek->signal_clicked().connect(
194                 SigC::bind<char const *>(
195                         SigC::slot(*this,
196                                    &GMathPanel::onShowDialog),
197                         "mathgreek"));
198         misc->signal_clicked().connect(
199                 SigC::bind<char const *>(
200                         SigC::slot(*this,
201                                    &GMathPanel::onShowDialog),
202                         "mathmisc"));
203         dots->signal_clicked().connect(
204                 SigC::bind<char const *>(
205                         SigC::slot(*this,
206                                    &GMathPanel::onShowDialog),
207                         "mathdots"));
208         varSize->signal_clicked().connect(
209                 SigC::bind<char const *>(
210                         SigC::slot(*this,
211                                    &GMathPanel::onShowDialog),
212                         "mathbigoperators"));
213         amsMisc->signal_clicked().connect(
214                 SigC::bind<char const *>(
215                         SigC::slot(*this,
216                                    &GMathPanel::onShowDialog),
217                         "mathamsmisc"));
218         amsArrows->signal_clicked().connect(
219                 SigC::bind<char const *>(
220                         SigC::slot(*this,
221                                    &GMathPanel::onShowDialog),
222                         "mathamsarrows"));
223         amsBrel->signal_clicked().connect(
224                 SigC::bind<char const *>(
225                         SigC::slot(*this,
226                                    &GMathPanel::onShowDialog),
227                         "mathamsrelations"));
228         amsNrel->signal_clicked().connect(
229                 SigC::bind<char const *>(
230                         SigC::slot(*this,
231                                    &GMathPanel::onShowDialog),
232                         "mathamsnegatedrelations"));
233         amsOps->signal_clicked().connect(
234                 SigC::bind<char const *>(
235                         SigC::slot(*this,
236                                    &GMathPanel::onShowDialog),
237                         "mathamsoperators"));
238         delim->signal_clicked().connect(
239                 SigC::bind<char const *>(
240                         SigC::slot(*this,
241                                    &GMathPanel::onShowDialog),
242                         "mathdelimiter"));
243         matrix->signal_clicked().connect(
244                 SigC::bind<char const *>(
245                         SigC::slot(*this,
246                                    &GMathPanel::onShowDialog),
247                         "mathmatrix"));
248         space->signal_clicked().connect(
249                 SigC::bind<char const *>(
250                         SigC::slot(*this,
251                                    &GMathPanel::onShowDialog),
252                         "mathspace"));
253         style->signal_clicked().connect(
254                 SigC::bind<char const *>(
255                         SigC::slot(*this,
256                                    &GMathPanel::onShowDialog),
257                         "mathstyle"));
258
259         super->signal_clicked().connect(
260                 SigC::slot(*this, &GMathPanel::onSuperClicked));
261         sub->signal_clicked().connect(
262                 SigC::slot(*this, &GMathPanel::onSubClicked));
263         equation->signal_clicked().connect(
264                 SigC::slot(*this, &GMathPanel::onEquationClicked));
265         
266         frac->signal_clicked().connect(
267                 SigC::bind<char const *>(
268                         SigC::slot(*this,
269                                    &GMathPanel::onInsert),
270                         "frac"));
271         sqrt->signal_clicked().connect(
272                 SigC::bind<char const *>(
273                         SigC::slot(*this,
274                                    &GMathPanel::onInsert),
275                         "sqrt"));
276
277         // Functions ListView
278         xml_->get_widget("Functions", functions_);
279         listCols_.add(listCol_);
280         listStore_ = Gtk::ListStore::create(listCols_);
281         functions_->set_model(listStore_);
282         functions_->append_column("Functions", listCol_);
283         listSel_ = functions_->get_selection();
284         listSel_->signal_changed().connect(
285                 SigC::slot(*this, &GMathPanel::onFunctionSelected));
286         for (int i = 0; i < nr_function_names; ++i)
287                 (*listStore_->append())[listCol_] =
288                         Glib::locale_to_utf8(function_names[i]);
289 }
290
291
292 void GMathPanel::onFunctionSelected()
293 {
294         Gtk::TreeModel::iterator it = listSel_->get_selected();
295         Glib::ustring sel = (*it)[listCol_];
296         controller().dispatchInsert(
297                 Glib::locale_from_utf8(sel));
298 }
299
300
301 void GMathPanel::onShowDialog(char const * dialogName)
302 {
303         controller().showDialog(dialogName);
304 }
305
306
307 void GMathPanel::onSuperClicked()
308 {
309         controller().dispatchSuperscript();
310 }
311
312
313 void GMathPanel::onSubClicked()
314 {
315         controller().dispatchSubscript();
316 }
317
318
319 void GMathPanel::onEquationClicked()
320 {
321         controller().dispatchToggleDisplay();
322 }
323
324
325 void GMathPanel::onInsert(char const * what)
326 {
327         controller().dispatchInsert(what);
328 }