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 "GMathsMatrix.h"
19 #include "ControlMath.h"
21 #include "GViewBase.h"
27 using std::ostringstream;
34 GMathsMatrix::GMathsMatrix(Dialog & parent)
35 : GViewCB<ControlMath, GViewGladeB>(parent, _("Math Matrix"), false)
39 void GMathsMatrix::doBuild()
41 string const gladeName = findGladeFile("mathMatrix");
42 xml_ = Gnome::Glade::Xml::create(gladeName);
45 xml_->get_widget("Cancel",button);
47 xml_->get_widget("Insert",button);
49 // No inserting matrices into readonly docs!
50 bcview().addReadOnly(button);
52 // Get widget pointers
53 xml_->get_widget("Top", topradio_);
54 xml_->get_widget("Bottom", bottomradio_);
55 xml_->get_widget("Center", centerradio_);
56 xml_->get_widget("Columns", columnsspin_);
57 xml_->get_widget("Rows", rowsspin_);
58 xml_->get_widget("HorzAlign", horzalignentry_);
60 // Make center vertical alignment the default
61 centerradio_->set_active(true);
63 // Allow only [clr], keep length as number of cols
64 ignoreHorzAlign_ = false;
65 horzalignentry_->signal_changed().connect(
66 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
67 columnsspin_->signal_value_changed().connect(
68 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
72 void GMathsMatrix::apply()
74 string const h_align = horzalignentry_->get_text();
76 static_cast<int>(columnsspin_->get_adjustment()->get_value());
78 static_cast<int>(rowsspin_->get_adjustment()->get_value());
80 if (topradio_->get_active())
82 else if (centerradio_->get_active())
84 else if (bottomradio_->get_active())
88 os << nx << ' ' << ny << ' ' << v_align << ' ' << h_align;
89 controller().dispatchMatrix(os.str());
93 void GMathsMatrix::update()
95 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
100 void GMathsMatrix::updateHorzAlignEntry()
102 if (ignoreHorzAlign_) return;
104 Glib::ustring orig = horzalignentry_->get_text();
105 Glib::ustring stripped;
107 Glib::ustring::iterator cur;
108 for (cur = orig.begin(); cur != orig.end(); ++cur) {
109 if (*cur == 'c' || *cur == 'l' ||
110 *cur == 'r' || *cur == '|')
114 int barcount = countbars(stripped);
115 while (stripped.length() - barcount >
116 columnsspin_->get_adjustment()->get_value()) {
117 // erase last character of stripped
118 stripped = stripped.erase(stripped.length() - 1,1);
119 barcount = countbars(stripped);
122 while (stripped.length() - barcount <
123 columnsspin_->get_adjustment()->get_value()) {
124 stripped = stripped + "c";
125 barcount = countbars(stripped);
128 if (orig.compare(stripped) != 0) {
129 ignoreHorzAlign_ = true;
130 horzalignentry_->set_text(stripped);
131 ignoreHorzAlign_ = false;
135 int GMathsMatrix::countbars(Glib::ustring str)
138 Glib::ustring::iterator cur = str.begin();
139 Glib::ustring::iterator end = str.end();
140 for (; cur != end; ++cur) {
148 } // namespace frontend