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
22 #include "controllers/ControlBox.h"
24 #include "insets/insetbox.h"
25 #include "lengthcommon.h"
26 #include "lyxrc.h" // to set the default length values
35 string defaultUnit("cm");
38 GBox::GBox(Dialog & parent)
39 : GViewCB<ControlBox, GViewGladeB>(parent, _("Box Settings"), false)
45 string const gladeName = findGladeFile("box");
46 xml_ = Gnome::Glade::Xml::create(gladeName);
48 Gtk::Button * closebutton;
49 xml_->get_widget("Close", closebutton);
50 setCancel(closebutton);
52 xml_->get_widget("Type", typecombo_);
53 bcview().addReadOnly(typecombo_);
54 xml_->get_widget("InnerBox", innerboxcombo_);
55 bcview().addReadOnly(innerboxcombo_);
56 xml_->get_widget("WidthUnits", widthunitscombo_);
57 bcview().addReadOnly(widthunitscombo_);
58 xml_->get_widget("HeightUnits", heightunitscombo_);
59 bcview().addReadOnly(heightunitscombo_);
60 xml_->get_widget("BoxVertical", boxvertcombo_);
61 bcview().addReadOnly(boxvertcombo_);
62 xml_->get_widget("ContentVertical", contentvertcombo_);
63 bcview().addReadOnly(contentvertcombo_);
64 xml_->get_widget("ContentHorizontal", contenthorzcombo_);
65 bcview().addReadOnly(contenthorzcombo_);
66 xml_->get_widget("Width", widthspin_);
67 bcview().addReadOnly(widthspin_);
68 xml_->get_widget("Height", heightspin_);
69 bcview().addReadOnly(heightspin_);
71 cols_.add(stringcol_);
73 // fill the box type choice
74 box_gui_tokens(ids_, gui_names_);
75 PopulateComboBox(typecombo_, gui_names_);
76 typecombo_->signal_changed().connect(
77 sigc::mem_fun(*this, &GBox::onTypeComboChanged));
79 // set up innerbox (populated in setInnerType)
80 innerboxstore_ = Gtk::ListStore::create(cols_);
81 innerboxcombo_->set_model(innerboxstore_);
82 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
83 innerboxcombo_->pack_start(*cell, true);
84 innerboxcombo_->add_attribute(*cell, "text", 0);
86 innerboxcombo_->signal_changed().connect(
87 sigc::mem_fun(*this, &GBox::onInnerBoxComboChanged));
89 boxvertcombo_->signal_changed().connect(
90 sigc::mem_fun(*this, &GBox::onAlignChanged));
91 contenthorzcombo_->signal_changed().connect(
92 sigc::mem_fun(*this, &GBox::onAlignChanged));
93 contentvertcombo_->signal_changed().connect(
94 sigc::mem_fun(*this, &GBox::onAlignChanged));
96 heightunitscombo_->signal_changed().connect(
97 sigc::mem_fun(*this, &GBox::onHeightChanged));
98 widthunitscombo_->signal_changed().connect(
99 sigc::mem_fun(*this, &GBox::onWidthChanged));
101 heightspin_->signal_value_changed().connect(
102 sigc::mem_fun(*this, &GBox::onHeightChanged));
103 widthspin_->signal_value_changed().connect(
104 sigc::mem_fun(*this, &GBox::onWidthChanged));
107 widthunitsstore_ = Gtk::ListStore::create(cols_);
108 widthunitscombo_->set_model(widthunitsstore_);
109 cell = Gtk::manage(new Gtk::CellRendererText);
110 widthunitscombo_->pack_start(*cell, true);
111 widthunitscombo_->add_attribute(*cell, "text", 0);
112 //widthunitscombo_ is populated in setSpecial
114 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
115 vector<string> heightunits = buildLengthUnitList();
116 // Append special entries, skipping the first item "None"
117 heightunits.insert(heightunits.end(),
118 ++gui_names_spec_.begin(), gui_names_spec_.end());
120 PopulateComboBox(heightunitscombo_, heightunits);
124 void GBox::PopulateComboBox(Gtk::ComboBox * combo,
125 vector<string> const & strings
128 Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
129 vector<string>::const_iterator it = strings.begin();
130 vector<string>::const_iterator end = strings.end();
131 for(; it != end; ++it)
132 (*model->append())[stringcol_] = *it;
134 combo->set_model(model);
135 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
136 combo->pack_start(*cell, true);
137 combo->add_attribute(*cell, "text", 0);
145 defaultUnit = getDefaultUnit();
147 char c = controller().params().pos;
148 boxvertcombo_->set_active(string("tcb").find(c, 0));
149 c = controller().params().inner_pos;
150 contentvertcombo_->set_active(string("tcbs").find(c, 0));
151 c = controller().params().hor_pos;
152 contenthorzcombo_->set_active(string("lcrs").find(c, 0));
154 string type(controller().params().type);
155 for (unsigned int i = 0; i < gui_names_.size(); ++i) {
157 typecombo_->set_active(i);
161 updateInnerBoxCombo();
164 bool ibox = controller().params().inner_box;
165 boxvertcombo_->set_sensitive(ibox);
166 contentvertcombo_->set_sensitive(ibox);
167 contenthorzcombo_->set_sensitive(!ibox);
170 widthspin_->get_adjustment()->set_value(controller().params().width.value());
171 unitsComboFromLength(widthunitscombo_, stringcol_,
172 controller().params().width, defaultUnit);
174 string const special(controller().params().special);
175 if (!special.empty() && special != "none") {
177 for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
178 if (special == ids_spec_[i])
179 spc = gui_names_spec_[i];
181 for (int j = 0; j < widthunitsstore_->children().size(); ++j) {
182 if (widthunitsstore_->children()[j][stringcol_] == spc)
183 widthunitscombo_->set_active(j);
187 heightspin_->get_adjustment()->set_value(controller().params().height.value());
188 unitsComboFromLength(heightunitscombo_, stringcol_,
189 controller().params().height, defaultUnit);
191 string const height_special(controller().params().height_special);
192 if (!height_special.empty() && height_special != "none") {
194 for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
195 if (height_special == ids_spec_[i]) {
196 hspc = gui_names_spec_[i];
199 for (int j = 0; j < heightunitscombo_->get_model()->children().size(); ++j) {
200 if (heightunitscombo_->get_model()->children()[j][stringcol_] == hspc) {
201 heightunitscombo_->set_active(j);
206 heightspin_->set_sensitive(ibox);
207 heightunitscombo_->set_sensitive(ibox);
212 void GBox::setSpecial(bool ibox)
214 bool const oldlock = applylock_;
217 unsigned int const initselection = widthunitscombo_->get_active_row_number();
218 widthunitsstore_->clear();
219 vector<string> normalunits = buildLengthUnitList();
221 vector<string>::const_iterator it = normalunits.begin();
222 vector<string>::const_iterator end = normalunits.end();
223 for(; it != end; ++it)
224 (*widthunitsstore_->append())[stringcol_] = *it;
226 vector<string>::const_iterator it = normalunits.begin();
227 vector<string>::const_iterator end = normalunits.end();
228 for(; it != end; ++it)
229 (*widthunitsstore_->append())[stringcol_] = *it;
230 // Skip the first item "None"
231 it = ++gui_names_spec_.begin();
232 end = gui_names_spec_.end();
233 for(; it != end; ++it)
234 (*widthunitsstore_->append())[stringcol_] = *it;
237 int const store_size = widthunitsstore_->children().size();
238 if (initselection >= store_size) {
239 widthunitscombo_->set_active(0);
242 widthunitscombo_->set_active(initselection);
244 applylock_ = oldlock;
248 void GBox::updateInnerBoxCombo()
250 bool const oldlock = applylock_;
252 // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
253 // we have to remove "none" then and adjust the combo
257 if (!controller().params().inner_box)
260 if (controller().params().use_parbox)
263 bool frameless = (controller().params().type == "Frameless");
265 int const oldsize = innerboxstore_->children().size();
266 // Store the initial selection in 0,1,2 format
267 int oldselection = -1;
269 oldselection = innerboxcombo_->get_active_row_number() + 1;
270 else if (oldsize == 3)
271 oldselection = innerboxcombo_->get_active_row_number();
273 if (frameless && oldsize != 2) {
274 innerboxstore_->clear();
275 (*innerboxstore_->append())[stringcol_] = _("Parbox");
276 (*innerboxstore_->append())[stringcol_] = _("Minipage");
277 // Cope when the backend asks for no inner box in
281 innerboxcombo_->set_active(i);
284 innerboxcombo_->set_active(i - 1);
285 } else if (!frameless && oldsize != 3) {
286 innerboxstore_->clear();
287 (*innerboxstore_->append())[stringcol_] = _("None");
288 (*innerboxstore_->append())[stringcol_] = _("Parbox");
289 (*innerboxstore_->append())[stringcol_] = _("Minipage");
290 innerboxcombo_->set_active(i);
292 // we're not changing the liststore, just selecting i
294 innerboxcombo_->set_active(i - 1);
296 innerboxcombo_->set_active(i);
299 // Update the width units list if we've changed inner box type
300 if (i != oldselection)
303 applylock_ = oldlock;
307 void GBox::onInnerBoxComboChanged()
312 controller().params().use_parbox =
313 (*innerboxcombo_->get_active())[stringcol_] == _("Parbox");
315 bool const ibox = (*innerboxcombo_->get_active())[stringcol_] != _("None");
316 controller().params().inner_box = ibox;
319 boxvertcombo_->set_sensitive(ibox);
320 contentvertcombo_->set_sensitive(ibox);
321 contenthorzcombo_->set_sensitive(!ibox);
322 heightspin_->set_sensitive(ibox);
323 heightunitscombo_->set_sensitive(ibox);
324 // wtf? form_->set_sensitive(ibox);
326 controller().dispatchParams();
330 void GBox::onTypeComboChanged()
332 int const index = typecombo_->get_active_row_number();
333 controller().params().type = ids_[index];
335 bool frameless = (index == 0);
337 boxvertcombo_->set_sensitive(true);
338 contentvertcombo_->set_sensitive(true);
339 contenthorzcombo_->set_sensitive(false);
340 heightspin_->set_sensitive(true);
341 heightunitscombo_->set_sensitive(true);
342 //wtf? form_->setSpecial(true);
344 //int itype = innerboxcombo_->get_active_row_number();
345 controller().dispatchParams();
347 updateInnerBoxCombo();
351 void GBox::onHeightChanged()
359 Glib::ustring special = (*heightunitscombo_->get_active())[stringcol_];
360 for (int j = 1; j < gui_names_spec_.size() ; ++j) {
361 if (gui_names_spec_[j] == special) {
366 controller().params().height_special = ids_spec_[i];
370 height = heightspin_->get_text();
371 // beware: bogosity! the unit is simply ignored in this case
374 Glib::ustring const heightunit =
375 (*heightunitscombo_->get_active())[stringcol_];
376 height = heightspin_->get_text() + heightunit;
379 controller().params().height = LyXLength(height);
380 controller().dispatchParams();
384 void GBox::onWidthChanged()
391 Glib::ustring special = (*widthunitscombo_->get_active())[stringcol_];
392 for (int j = 1; j < gui_names_spec_.size() ; ++j) {
393 if (gui_names_spec_[j] == special) {
398 controller().params().special = ids_spec_[i];
402 width = widthspin_->get_text();
403 // beware: bogosity! the unit is simply ignored in this case
406 Glib::ustring const widthunit =
407 (*widthunitscombo_->get_active())[stringcol_];
408 width = widthspin_->get_text() + widthunit;
411 controller().params().width = LyXLength(width);
412 controller().dispatchParams();
416 void GBox::onAlignChanged()
421 controller().params().pos =
422 "tcb"[boxvertcombo_->get_active_row_number()];
423 controller().params().inner_pos =
424 "tcbs"[contenthorzcombo_->get_active_row_number()];
425 controller().params().hor_pos =
426 "lcrs"[contentvertcombo_->get_active_row_number()];
428 controller().dispatchParams();
431 } // namespace frontend