3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "ControlMath.h"
14 #include "GMathDelim.h"
17 #include "support/lstrings.h"
19 #include <libglademm.h>
34 enum enumDelimType {LEFT, RIGHT, SINGLE};
37 int const delimType[] = {
39 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT,LEFT, RIGHT,
42 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT, SINGLE, SINGLE,
47 int const delimRevert[] = {
48 1,0,3,2,4,5,7,6,9,8,10,11,
49 13,12,15,14,16,17,19,18,20,21,22
53 char const * delimValues[] = {
54 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
55 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
56 "{", "}", "/", "backslash", "downarrow", "Downarrow",
57 "langle", "rangle", "|", "Vert", ".", 0
60 int const delimTblRows = 2;
62 int const delimTblCols = 12;
64 int const delimMax = 23;
67 GXpmBtnTbl::XbmData xbm =
76 inline int index(int row, int col)
78 return row * delimTblCols + col;
82 inline int indexToRow(int index)
84 return index / delimTblCols;
88 inline int indexToCol(int index)
90 return index % delimTblCols;
96 GMathDelim::GMathDelim(Dialog & parent) :
97 GViewCB<ControlMath, GViewGladeB>(parent, _("Math Delimiters")),
98 delimTbl_(delimTblRows, delimTblCols, xbm)
103 void GMathDelim::doBuild()
105 string const gladeName = findGladeFile("mathDelim");
106 xml_ = Gnome::Glade::Xml::create(gladeName);
111 xml_->get_widget("Left", left_);
112 xml_->get_widget("Right", right_);
113 xml_->get_widget("Both", both_);
114 xml_->get_widget("OK", ok);
115 xml_->get_widget("Apply", apply);
116 xml_->get_widget("Close", close);
117 xml_->get_widget("Demo", demo_);
121 // Initialize demo button pixmap to "()" as found in images/delim0.xpm
125 xml_->get_widget("Box", box);
126 delimTbl_.signalClicked().connect(
127 sigc::mem_fun(*this, &GMathDelim::onDelimTblClicked));
129 box->children().push_back(
130 Gtk::Box_Helpers::Element(delimTbl_));
131 bcview().addReadOnly(&delimTbl_);
132 bcview().addReadOnly(left_);
133 bcview().addReadOnly(right_);
134 bcview().addReadOnly(both_);
135 bcview().addReadOnly(demo_);
136 left_->signal_clicked().connect(
137 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
138 right_->signal_clicked().connect(
139 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
140 both_->signal_clicked().connect(
141 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
145 void GMathDelim::setDemoPixmap()
148 pixmap_ = Gdk::Pixmap::create_from_xpm(demo_->get_colormap(),
151 image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
154 gcMask_ = Gdk::GC::create(mask_);
158 void GMathDelim::apply()
160 std::ostringstream os;
161 os << delimValues[leftSel_] << ' ' << delimValues[rightSel_];
162 controller().dispatchDelim(os.str());
166 void GMathDelim::update()
172 void GMathDelim::onDelimTblClicked(int row, int col)
174 int const sel = index(row, col);
177 bool left = left_->get_active();
178 bool right = right_->get_active();
179 bool both = both_->get_active();
185 if (delimType[sel] == LEFT) {
187 rightSel_ = delimRevert[sel];
188 } else if (delimType[sel] == RIGHT) {
190 leftSel_ = delimRevert[sel];
192 leftSel_ = rightSel_ = sel;
198 void GMathDelim::updateDemoPixmap()
200 int const delimWidth = delim_width / delimTblCols;
201 Glib::RefPtr<Gdk::Pixmap> pixmap;
202 Glib::RefPtr<Gdk::Bitmap> mask;
203 GXpmBtnTbl::GXpmBtn * btn = delimTbl_.getBtn(indexToRow(leftSel_),
204 indexToCol(leftSel_));
205 pixmap = btn->getPixmap();
206 mask = btn->getMask();
207 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
211 mask_->draw_drawable(gcMask_,
215 btn = delimTbl_.getBtn(indexToRow(rightSel_),
216 indexToCol(rightSel_));
217 pixmap = btn->getPixmap();
218 mask = btn->getMask();
219 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
223 mask_->draw_drawable(gcMask_,
227 int x, y, width, height, depth;
228 demo_->get_window()->get_geometry(x, y, width, height, depth);
229 demo_->get_window()->invalidate_rect(
230 Gdk::Rectangle(x, y, width, height), true);
235 void GMathDelim::onRadioClicked()
240 } // namespace frontend