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>
39 // FIXME: Implement fixed size delimiters (see qt3 frontend)
44 enum enumDelimType {LEFT, RIGHT, SINGLE};
47 int const delimType[] = {
49 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT,LEFT, RIGHT,
52 LEFT, RIGHT, LEFT, RIGHT, SINGLE, SINGLE, LEFT, RIGHT, SINGLE, SINGLE,
57 int const delimRevert[] = {
58 1,0,3,2,4,5,7,6,9,8,10,11,
59 13,12,15,14,16,17,19,18,20,21,22
63 char const * delimValues[] = {
64 "(", ")", "lceil", "rceil", "uparrow", "Uparrow",
65 "[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
66 "{", "}", "/", "backslash", "downarrow", "Downarrow",
67 "langle", "rangle", "|", "Vert", ".", 0
70 int const delimTblRows = 2;
72 int const delimTblCols = 12;
74 int const delimMax = 23;
77 GXpmBtnTbl::XbmData xbm =
86 inline int index(int row, int col)
88 return row * delimTblCols + col;
92 inline int indexToRow(int index)
94 return index / delimTblCols;
98 inline int indexToCol(int index)
100 return index % delimTblCols;
106 GMathDelim::GMathDelim(Dialog & parent) :
107 GViewCB<ControlMath, GViewGladeB>(parent, _("Math Delimiters")),
108 delimTbl_(delimTblRows, delimTblCols, xbm)
113 void GMathDelim::doBuild()
115 string const gladeName = findGladeFile("mathDelim");
116 xml_ = Gnome::Glade::Xml::create(gladeName);
121 xml_->get_widget("Left", left_);
122 xml_->get_widget("Right", right_);
123 xml_->get_widget("Both", both_);
124 xml_->get_widget("OK", ok);
125 xml_->get_widget("Apply", apply);
126 xml_->get_widget("Close", close);
127 xml_->get_widget("Demo", demo_);
131 // Initialize demo button pixmap to "()" as found in images/delim0.xpm
135 xml_->get_widget("Box", box);
136 delimTbl_.signalClicked().connect(
137 sigc::mem_fun(*this, &GMathDelim::onDelimTblClicked));
139 box->children().push_back(
140 Gtk::Box_Helpers::Element(delimTbl_));
141 bcview().addReadOnly(&delimTbl_);
142 bcview().addReadOnly(left_);
143 bcview().addReadOnly(right_);
144 bcview().addReadOnly(both_);
145 bcview().addReadOnly(demo_);
146 left_->signal_clicked().connect(
147 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
148 right_->signal_clicked().connect(
149 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
150 both_->signal_clicked().connect(
151 sigc::mem_fun(*this, &GMathDelim::onRadioClicked));
155 void GMathDelim::setDemoPixmap()
158 pixmap_ = Gdk::Pixmap::create_from_xpm(demo_->get_colormap(),
161 image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
164 gcMask_ = Gdk::GC::create(mask_);
168 void GMathDelim::apply()
170 std::ostringstream os;
171 os << delimValues[leftSel_] << ' ' << delimValues[rightSel_];
172 controller().dispatchDelim(os.str());
176 void GMathDelim::update()
182 void GMathDelim::onDelimTblClicked(int row, int col)
184 int const sel = index(row, col);
187 bool left = left_->get_active();
188 bool right = right_->get_active();
189 bool both = both_->get_active();
195 if (delimType[sel] == LEFT) {
197 rightSel_ = delimRevert[sel];
198 } else if (delimType[sel] == RIGHT) {
200 leftSel_ = delimRevert[sel];
202 leftSel_ = rightSel_ = sel;
208 void GMathDelim::updateDemoPixmap()
210 int const delimWidth = delim_width / delimTblCols;
211 Glib::RefPtr<Gdk::Pixmap> pixmap;
212 Glib::RefPtr<Gdk::Bitmap> mask;
213 GXpmBtnTbl::GXpmBtn * btn = delimTbl_.getBtn(indexToRow(leftSel_),
214 indexToCol(leftSel_));
215 pixmap = btn->getPixmap();
216 mask = btn->getMask();
217 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
221 mask_->draw_drawable(gcMask_,
225 btn = delimTbl_.getBtn(indexToRow(rightSel_),
226 indexToCol(rightSel_));
227 pixmap = btn->getPixmap();
228 mask = btn->getMask();
229 pixmap_->draw_drawable(left_->get_style()->get_black_gc(),
233 mask_->draw_drawable(gcMask_,
237 int x, y, width, height, depth;
238 demo_->get_window()->get_geometry(x, y, width, height, depth);
239 demo_->get_window()->invalidate_rect(
240 Gdk::Rectangle(x, y, width, height), true);
245 void GMathDelim::onRadioClicked()
250 } // namespace frontend