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 #include "GMathsMatrix.h"
14 #include "ControlMath.h"
16 #include "GViewBase.h"
22 using std::ostringstream;
29 GMathsMatrix::GMathsMatrix(Dialog & parent)
30 : GViewCB<ControlMath, GViewGladeB>(parent, _("Math Matrix"), false)
34 void GMathsMatrix::doBuild()
36 string const gladeName = findGladeFile("mathMatrix");
37 xml_ = Gnome::Glade::Xml::create(gladeName);
40 xml_->get_widget("Cancel",button);
42 xml_->get_widget("Insert",button);
44 // No inserting matrices into readonly docs!
45 bcview().addReadOnly(button);
47 // Get widget pointers
48 xml_->get_widget("Top", topradio_);
49 xml_->get_widget("Bottom", bottomradio_);
50 xml_->get_widget("Center", centerradio_);
51 xml_->get_widget("Columns", columnsspin_);
52 xml_->get_widget("Rows", rowsspin_);
53 xml_->get_widget("HorzAlign", horzalignentry_);
55 // Make center vertical alignment the default
56 centerradio_->set_active(true);
58 // Allow only [clr], keep length as number of cols
59 ignoreHorzAlign_ = false;
60 horzalignentry_->signal_changed().connect(
61 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
62 columnsspin_->signal_value_changed().connect(
63 sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry));
67 void GMathsMatrix::apply()
69 string const h_align = horzalignentry_->get_text();
71 static_cast<int>(columnsspin_->get_adjustment()->get_value());
73 static_cast<int>(rowsspin_->get_adjustment()->get_value());
75 if (topradio_->get_active())
77 else if (centerradio_->get_active())
79 else if (bottomradio_->get_active())
83 os << nx << ' ' << ny << ' ' << v_align << ' ' << h_align;
84 controller().dispatchMatrix(os.str());
88 void GMathsMatrix::update()
90 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
95 void GMathsMatrix::updateHorzAlignEntry()
97 if (ignoreHorzAlign_) return;
99 Glib::ustring orig = horzalignentry_->get_text();
100 Glib::ustring stripped;
102 Glib::ustring::iterator cur;
103 for (cur = orig.begin(); cur != orig.end(); ++cur) {
104 if (*cur == 'c' || *cur == 'l' ||
105 *cur == 'r' || *cur == '|')
109 int barcount = countbars(stripped);
110 while (stripped.length() - barcount >
111 columnsspin_->get_adjustment()->get_value()) {
112 // erase last character of stripped
113 stripped = stripped.erase(stripped.length() - 1,1);
114 barcount = countbars(stripped);
117 while (stripped.length() - barcount <
118 columnsspin_->get_adjustment()->get_value()) {
119 stripped = stripped + "c";
120 barcount = countbars(stripped);
123 if (orig.compare(stripped) != 0) {
124 ignoreHorzAlign_ = true;
125 horzalignentry_->set_text(stripped);
126 ignoreHorzAlign_ = false;
130 int GMathsMatrix::countbars(Glib::ustring str)
133 Glib::ustring::iterator cur = str.begin();
134 Glib::ustring::iterator end = str.end();
135 for (; cur != end; ++cur) {
143 } // namespace frontend