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 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
18 #include "ControlMath.h"
19 #include "GMathDelim.h"
22 #include "support/lstrings.h"
24 #include <libglademm.h>
39 enum enumDelimType {LEFT, RIGHT, SINGLE};
42 int const delimType[] = {
44 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT,LEFT, RIGHT,
47 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT, SINGLE, SINGLE,
52 int const delimRevert[] = {
53 1,0,3,2,4,5,7,6,9,8,10,11,
54 13,12,15,14,16,17,19,18,20,21,22
58 char const * delimValues[] = {
59 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
60 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
61 "{", "}", "/", "backslash", "downarrow", "Downarrow",
62 "langle", "rangle", "|", "Vert", ".", 0
65 int const delimTblRows = 2;
67 int const delimTblCols = 12;
69 int const delimMax = 23;
72 GXpmBtnTbl::XbmData xbm =
81 inline int index(int row, int col)
83 return row * delimTblCols + col;
87 inline int indexToRow(int index)
89 return index / delimTblCols;
93 inline int indexToCol(int index)
95 return index % delimTblCols;
101 GMathDelim::GMathDelim(Dialog & parent) :
102 GViewCB<ControlMath, GViewGladeB>(parent, _("Math Delimiters")),
103 delimTbl_(delimTblRows, delimTblCols, xbm)
108 void GMathDelim::doBuild()
110 string const gladeName = findGladeFile("mathDelim");
111 xml_ = Gnome::Glade::Xml::create(gladeName);
116 xml_->get_widget("Left", left_);
117 xml_->get_widget("Right", right_);
118 xml_->get_widget("Both", both_);
119 xml_->get_widget("OK", ok);
120 xml_->get_widget("Apply", apply);
121 xml_->get_widget("Close", close);
122 xml_->get_widget("Demo", demo_);
126 // Initialize demo button pixmap to "()" as found in images/delim0.xpm
130 xml_->get_widget("Box", box);
131 delimTbl_.signalClicked().connect(
132 sigc::mem_fun(*this, &GMathDelim::onDelimTblClicked));
134 box->children().push_back(
135 Gtk::Box_Helpers::Element(delimTbl_));
136 bcview().addReadOnly(&delimTbl_);
137 bcview().addReadOnly(left_);
138 bcview().addReadOnly(right_);
139 bcview().addReadOnly(both_);
140 bcview().addReadOnly(demo_);
141 left_->signal_clicked().connect(
142 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
143 right_->signal_clicked().connect(
144 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
145 both_->signal_clicked().connect(
146 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
150 void GMathDelim::setDemoPixmap()
153 pixmap_ = Gdk::Pixmap::create_from_xpm(demo_->get_colormap(),
156 image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
159 gcMask_ = Gdk::GC::create(mask_);
163 void GMathDelim::apply()
165 std::ostringstream os;
166 os << delimValues[leftSel_] << ' ' << delimValues[rightSel_];
167 controller().dispatchDelim(os.str());
171 void GMathDelim::update()
177 void GMathDelim::onDelimTblClicked(int row, int col)
179 int const sel = index(row, col);
182 bool left = left_->get_active();
183 bool right = right_->get_active();
184 bool both = both_->get_active();
190 if (delimType[sel] == LEFT) {
192 rightSel_ = delimRevert[sel];
193 } else if (delimType[sel] == RIGHT) {
195 leftSel_ = delimRevert[sel];
197 leftSel_ = rightSel_ = sel;
203 void GMathDelim::updateDemoPixmap()
205 int const delimWidth = delim_width / delimTblCols;
206 Glib::RefPtr<Gdk::Pixmap> pixmap;
207 Glib::RefPtr<Gdk::Bitmap> mask;
208 GXpmBtnTbl::GXpmBtn * btn = delimTbl_.getBtn(indexToRow(leftSel_),
209 indexToCol(leftSel_));
210 pixmap = btn->getPixmap();
211 mask = btn->getMask();
212 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
216 mask_->draw_drawable(gcMask_,
220 btn = delimTbl_.getBtn(indexToRow(rightSel_),
221 indexToCol(rightSel_));
222 pixmap = btn->getPixmap();
223 mask = btn->getMask();
224 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
228 mask_->draw_drawable(gcMask_,
232 int x, y, width, height, depth;
233 demo_->get_window()->get_geometry(x, y, width, height, depth);
234 demo_->get_window()->invalidate_rect(
235 Gdk::Rectangle(x, y, width, height), true);
240 void GMathDelim::onRadioClicked()
245 } // namespace frontend