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