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 _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
21 #include "ControlMath.h"
22 #include "GMathDelim.h"
25 #include "support/lstrings.h"
27 #include <libglademm.h>
42 enum enumDelimType {LEFT, RIGHT, SINGLE};
45 int const delimType[] = {
47 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT,LEFT, RIGHT,
50 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT, SINGLE, SINGLE,
55 int const delimRevert[] = {
56 1,0,3,2,4,5,7,6,9,8,10,11,
57 13,12,15,14,16,17,19,18,20,21,22
61 char const * delimValues[] = {
62 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
63 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
64 "{", "}", "/", "backslash", "downarrow", "Downarrow",
65 "langle", "rangle", "|", "Vert", ".", 0
68 int const delimTblRows = 2;
70 int const delimTblCols = 12;
72 int const delimMax = 23;
75 GXpmBtnTbl::XbmData xbm =
84 inline int index(int row, int col)
86 return row * delimTblCols + col;
90 inline int indexToRow(int index)
92 return index / delimTblCols;
96 inline int indexToCol(int index)
98 return index % delimTblCols;
104 GMathDelim::GMathDelim(Dialog & parent) :
105 GViewCB<ControlMath, GViewGladeB>(parent, _("Math Delimiters")),
106 delimTbl_(delimTblRows, delimTblCols, xbm)
111 void GMathDelim::doBuild()
113 string const gladeName = findGladeFile("mathDelim");
114 xml_ = Gnome::Glade::Xml::create(gladeName);
119 xml_->get_widget("Left", left_);
120 xml_->get_widget("Right", right_);
121 xml_->get_widget("Both", both_);
122 xml_->get_widget("OK", ok);
123 xml_->get_widget("Apply", apply);
124 xml_->get_widget("Close", close);
125 xml_->get_widget("Demo", demo_);
129 // Initialize demo button pixmap to "()" as found in images/delim0.xpm
133 xml_->get_widget("Box", box);
134 delimTbl_.signalClicked().connect(
135 sigc::mem_fun(*this, &GMathDelim::onDelimTblClicked));
137 box->children().push_back(
138 Gtk::Box_Helpers::Element(delimTbl_));
139 bcview().addReadOnly(&delimTbl_);
140 bcview().addReadOnly(left_);
141 bcview().addReadOnly(right_);
142 bcview().addReadOnly(both_);
143 bcview().addReadOnly(demo_);
144 left_->signal_clicked().connect(
145 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
146 right_->signal_clicked().connect(
147 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
148 both_->signal_clicked().connect(
149 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
153 void GMathDelim::setDemoPixmap()
156 pixmap_ = Gdk::Pixmap::create_from_xpm(demo_->get_colormap(),
159 image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
162 gcMask_ = Gdk::GC::create(mask_);
166 void GMathDelim::apply()
168 std::ostringstream os;
169 os << delimValues[leftSel_] << ' ' << delimValues[rightSel_];
170 controller().dispatchDelim(os.str());
174 void GMathDelim::update()
180 void GMathDelim::onDelimTblClicked(int row, int col)
182 int const sel = index(row, col);
185 bool left = left_->get_active();
186 bool right = right_->get_active();
187 bool both = both_->get_active();
193 if (delimType[sel] == LEFT) {
195 rightSel_ = delimRevert[sel];
196 } else if (delimType[sel] == RIGHT) {
198 leftSel_ = delimRevert[sel];
200 leftSel_ = rightSel_ = sel;
206 void GMathDelim::updateDemoPixmap()
208 int const delimWidth = delim_width / delimTblCols;
209 Glib::RefPtr<Gdk::Pixmap> pixmap;
210 Glib::RefPtr<Gdk::Bitmap> mask;
211 GXpmBtnTbl::GXpmBtn * btn = delimTbl_.getBtn(indexToRow(leftSel_),
212 indexToCol(leftSel_));
213 pixmap = btn->getPixmap();
214 mask = btn->getMask();
215 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
219 mask_->draw_drawable(gcMask_,
223 btn = delimTbl_.getBtn(indexToRow(rightSel_),
224 indexToCol(rightSel_));
225 pixmap = btn->getPixmap();
226 mask = btn->getMask();
227 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
231 mask_->draw_drawable(gcMask_,
235 int x, y, width, height, depth;
236 demo_->get_window()->get_geometry(x, y, width, height, depth);
237 demo_->get_window()->invalidate_rect(
238 Gdk::Rectangle(x, y, width, height), true);
243 void GMathDelim::onRadioClicked()
248 } // namespace frontend