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
19 #include "ControlVSpace.h"
22 #include <libglademm.h>
31 string defaultUnit("cm");
34 GVSpace::GVSpace(Dialog & parent)
35 : GViewCB<ControlVSpace, GViewGladeB>(parent, _("VSpace Settings"), false)
39 void GVSpace::doBuild()
41 string const gladeName = findGladeFile("vspace");
42 xml_ = Gnome::Glade::Xml::create(gladeName);
45 xml_->get_widget("Cancel", button);
47 xml_->get_widget("Insert", button);
50 xml_->get_widget("Spacing", spacingcombo_);
51 xml_->get_widget("Value", valuespin_);
52 xml_->get_widget("ValueUnits", valueunitscombo_);
53 xml_->get_widget("Protect", protectcheck_);
55 cols_.add(stringcol_);
57 PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList());
59 spacingcombo_->signal_changed().connect(
60 sigc::mem_fun(*this, &GVSpace::onSpacingComboChanged));
64 void GVSpace::PopulateComboBox(Gtk::ComboBox * combo,
65 vector<string> const & strings)
67 Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
68 vector<string>::const_iterator it = strings.begin();
69 vector<string>::const_iterator end = strings.end();
70 for (int rowindex = 0; it != end; ++it, ++rowindex) {
71 Gtk::TreeModel::iterator row = model->append();
72 (*row)[stringcol_] = *it;
75 combo->set_model(model);
76 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
77 combo->pack_start(*cell, true);
78 combo->add_attribute(*cell, "text", 0);
82 void GVSpace::update()
84 // set the right default unit
85 defaultUnit = getDefaultUnit();
87 VSpace const space = controller().params();
90 switch (space.kind()) {
94 case VSpace::SMALLSKIP:
100 case VSpace::BIGSKIP:
111 spacingcombo_->set_active(pos);
113 protectcheck_->set_active(space.keep());
115 bool const custom_vspace = space.kind() == VSpace::LENGTH;
117 LyXLength length(space.length().asString());
118 valuespin_->get_adjustment()->set_value(length.value());
119 unitsComboFromLength(valueunitscombo_, stringcol_,
120 length, defaultUnit);
122 valuespin_->get_adjustment()->set_value(0.0f);
123 unitsComboFromLength(valueunitscombo_, stringcol_,
124 LyXLength(defaultUnit), defaultUnit);
129 void GVSpace::apply()
132 switch (spacingcombo_->get_active_row_number()) {
134 space = VSpace(VSpace::DEFSKIP);
137 space = VSpace(VSpace::SMALLSKIP);
140 space = VSpace(VSpace::MEDSKIP);
143 space = VSpace(VSpace::BIGSKIP);
146 space = VSpace(VSpace::VFILL);
149 Glib::ustring const valueunit =
150 (*valueunitscombo_->get_active())[stringcol_];
151 space = VSpace(LyXGlueLength(valuespin_->get_text() + valueunit));
155 space.setKeep(protectcheck_->get_active());
157 controller().params() = space;
161 void GVSpace::onSpacingComboChanged()
163 bool const custom = spacingcombo_->get_active_row_number() == 5;
164 valueunitscombo_->set_sensitive(custom);
165 valuespin_->set_sensitive(custom);
168 } // namespace frontend