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