]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GMathPanel.C
Extracted from r14281
[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
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "ControlMath.h"
22 #include "GMathPanel.h"
23 #include "ghelpers.h"
24
25 #include "support/lstrings.h"
26
27 #include <libglademm.h>
28
29 #include "deco.xpm"
30 #include "delim.xpm"
31 #include "equation.xpm"
32 #include "frac-square.xpm"
33 #include "matrix.xpm"
34 #include "space.xpm"
35 #include "style.xpm"
36 #include "sqrt-square.xpm"
37 #include "sub.xpm"
38 #include "super.xpm"
39
40 #include "gimages/ams_arrow.xpm"
41 #include "gimages/ams_misc.xpm"
42 #include "gimages/ams_brel.xpm"
43 #include "gimages/ams_nrel.xpm"
44 #include "gimages/ams_ops.xpm"
45 #include "gimages/arrow.xpm"
46 #include "gimages/boperator.xpm"
47 #include "gimages/brelats.xpm"
48 #include "gimages/dots.xpm"
49 #include "gimages/greek.xpm"
50 #include "gimages/misc.xpm"
51 #include "gimages/varsize.xpm"
52
53 using std::string;
54
55 namespace lyx {
56 namespace frontend {
57
58 namespace {
59
60 char const * infoUp[][5] =
61 {
62         //row 1
63         {0, 0, "mathdelimiter", "mathaccents", "mathspace"},
64         //row 2
65         {0, 0, "mathstyle", "mathmatrix", 0}
66 };
67
68
69 GXpmBtnTbl::XpmData xpmUp[] =
70 {
71         //row 1
72         sqrt_xpm, frac, delim, deco, space_xpm,
73         //row 2
74         super_xpm, sub_xpm, style_xpm, matrix, equation
75 };
76
77
78 char const * infoDown[][3] =
79 {
80         //row 1
81         {"mathoperators", "mathrelations", "matharrows"},
82         //row 2
83         {"mathbigoperators", "mathdots", "mathmisc"},
84         //row 3
85         {"mathgreek", "mathamsarrows", "mathamsrelations"},
86         //row 4
87         {"mathamsnegatedrelations", "mathamsoperators", "mathamsmisc"}
88 };
89
90
91 GXpmBtnTbl::XpmData xpmDown[] =
92 {
93         //row 1
94         boperator_xpm, brelats_xpm, arrow_xpm,
95         //row 2
96         varsize_xpm, dots_xpm, misc_xpm,
97         //row 3
98         greek_xpm, ams_arrow_xpm, ams_brel_xpm,
99         //row 4
100         ams_nrel_xpm, ams_ops_xpm, ams_misc_xpm
101 };
102
103 }
104
105
106 GMathPanel::GMathPanel(Dialog & parent)
107         : GViewCB<ControlMath, GViewGladeB>(parent, _("Math Panel")),
108           tableUp_(2, 5, xpmUp), tableDown_(4, 3, xpmDown)
109 {
110 }
111
112
113 void GMathPanel::doBuild()
114 {
115         string const gladeName = findGladeFile("mathPanel");
116         xml_ = Gnome::Glade::Xml::create(gladeName);
117         Gtk::Button * close;
118         Gtk::VBox * vbox;
119
120         xml_->get_widget("Close", close);
121         setCancel(close);
122
123         tableUp_.signalClicked().connect(
124                 sigc::mem_fun(*this, &GMathPanel::onTableUpClicked));
125         tableUp_.show();
126         tableDown_.signalClicked().connect(
127                 sigc::mem_fun(*this, &GMathPanel::onTableDownClicked));
128         tableDown_.show();
129
130         xml_->get_widget("Vbox", vbox);
131         vbox->pack_start(tableUp_, false, false, 0);
132         vbox->pack_start(tableDown_, false, false, 0);
133
134         // Functions ListView
135         xml_->get_widget("Functions", functions_);
136         listCols_.add(listCol_);
137         listStore_ = Gtk::ListStore::create(listCols_);
138         functions_->set_model(listStore_);
139         functions_->append_column("Functions", listCol_);
140
141         listSel_ = functions_->get_selection();
142         listSel_->signal_changed().connect(
143                 sigc::mem_fun(*this, &GMathPanel::onFunctionSelected));
144         for (int i = 0; i < nr_function_names; ++i)
145                 (*listStore_->append())[listCol_] =
146                         Glib::locale_to_utf8(function_names[i]);
147 }
148
149
150 void GMathPanel::onTableUpClicked(int row, int col)
151 {
152         if (infoUp[row][col])
153                 controller().showDialog(infoUp[row][col]);
154         else if (row == 0 && col == 0)
155                 controller().dispatchInsert("sqrt");
156         else if (row == 0 && col == 1)
157                 controller().dispatchInsert("frac");
158         else if (row == 1 && col == 0)
159         controller().dispatchSuperscript();
160         else if (row == 1 && col == 1)
161         controller().dispatchSubscript();
162         else if (row == 1 && col == 4)
163                 controller().dispatchToggleDisplay();
164 }
165
166
167 void GMathPanel::onTableDownClicked(int row, int col)
168 {
169         controller().showDialog(infoDown[row][col]);
170 }
171
172
173 void GMathPanel::onFunctionSelected()
174 {
175         Gtk::TreeModel::iterator it = listSel_->get_selected();
176         Glib::ustring sel = (*it)[listCol_];
177         controller().dispatchInsert(
178                 Glib::locale_from_utf8(sel));
179 }
180
181 } // namespace frontend
182 } // namespace lyx