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 "GMathsMatrix.h"
22 #include "ControlMath.h"
24 #include "GViewBase.h"
30 using std::ostringstream;
37 GMathsMatrix::GMathsMatrix(Dialog & parent)
38 : GViewCB<ControlMath, GViewGladeB>(parent, _("Math Matrix"), false)
42 void GMathsMatrix::doBuild()
44 string const gladeName = findGladeFile("mathMatrix");
45 xml_ = Gnome::Glade::Xml::create(gladeName);
48 xml_->get_widget("Cancel",button);
50 xml_->get_widget("Insert",button);
52 // No inserting matrices into readonly docs!
53 bcview().addReadOnly(button);
55 // Get widget pointers
56 xml_->get_widget("Top", topradio_);
57 xml_->get_widget("Bottom", bottomradio_);
58 xml_->get_widget("Center", centerradio_);
59 xml_->get_widget("Columns", columnsspin_);
60 xml_->get_widget("Rows", rowsspin_);
61 xml_->get_widget("HorzAlign", horzalignentry_);
63 // Make center vertical alignment the default
64 centerradio_->set_active(true);
66 // Allow only [clr], keep length as number of cols
67 ignoreHorzAlign_ = false;
68 horzalignentry_->signal_changed().connect(
69 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
70 columnsspin_->signal_value_changed().connect(
71 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
75 void GMathsMatrix::apply()
77 string const h_align = horzalignentry_->get_text();
79 static_cast<int>(columnsspin_->get_adjustment()->get_value());
81 static_cast<int>(rowsspin_->get_adjustment()->get_value());
83 if (topradio_->get_active())
85 else if (centerradio_->get_active())
87 else if (bottomradio_->get_active())
91 os << nx << ' ' << ny << ' ' << v_align << ' ' << h_align;
92 controller().dispatchMatrix(os.str());
96 void GMathsMatrix::update()
98 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
103 void GMathsMatrix::updateHorzAlignEntry()
105 if (ignoreHorzAlign_) return;
107 Glib::ustring orig = horzalignentry_->get_text();
108 Glib::ustring stripped;
110 Glib::ustring::iterator cur;
111 for (cur = orig.begin(); cur != orig.end(); ++cur) {
112 if (*cur == 'c' || *cur == 'l' ||
113 *cur == 'r' || *cur == '|')
117 int barcount = countbars(stripped);
118 while (stripped.length() - barcount >
119 columnsspin_->get_adjustment()->get_value()) {
120 // erase last character of stripped
121 stripped = stripped.erase(stripped.length() - 1,1);
122 barcount = countbars(stripped);
125 while (stripped.length() - barcount <
126 columnsspin_->get_adjustment()->get_value()) {
127 stripped = stripped + "c";
128 barcount = countbars(stripped);
131 if (orig.compare(stripped) != 0) {
132 ignoreHorzAlign_ = true;
133 horzalignentry_->set_text(stripped);
134 ignoreHorzAlign_ = false;
138 int GMathsMatrix::countbars(Glib::ustring str)
141 Glib::ustring::iterator cur = str.begin();
142 Glib::ustring::iterator end = str.end();
143 for (; cur != end; ++cur) {
151 } // namespace frontend