From 5352478c93006c0dc7dcb4c9f77e4b2051ecbc51 Mon Sep 17 00:00:00 2001 From: John Spray Date: Sun, 14 Nov 2004 17:10:04 +0000 Subject: [PATCH] GTK Box dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9239 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 8 + src/frontends/gtk/Dialogs.C | 5 +- src/frontends/gtk/GBox.C | 427 +++++++++++++++++++++++ src/frontends/gtk/GBox.h | 88 +++++ src/frontends/gtk/GGraphics.C | 54 +-- src/frontends/gtk/GGraphics.h | 3 - src/frontends/gtk/GWorkArea.C | 2 +- src/frontends/gtk/Makefile.am | 3 +- src/frontends/gtk/ghelpers.C | 42 ++- src/frontends/gtk/ghelpers.h | 11 + src/frontends/gtk/glade/box.glade | 550 ++++++++++++++++++++++++++++++ 11 files changed, 1145 insertions(+), 48 deletions(-) create mode 100644 src/frontends/gtk/GBox.C create mode 100644 src/frontends/gtk/GBox.h create mode 100644 src/frontends/gtk/glade/box.glade diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 341bdf50ed..7844882a65 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,11 @@ +2004-11-14 John Spray + + * The Box dialog: + Dialogs.C, Makefile.am, GBox.C, GBox.h + * ghelpers.[Ch], GGraphics.[Ch]: new functions unitsComboFromLength + and getDefaultUnit take functionality that was in GGraphics into + ghelpers + 2004-11-08 Jean-Marc Lasgouttes * GToolbar.C (selected): use layoutSelected() diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 86b99ca182..3636288878 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -54,7 +54,7 @@ #include "GMathDelim.h" #include "FormBibitem.h" #include "FormBibtex.h" -#include "FormBox.h" +#include "GBox.h" #include "FormBranch.h" #include "GChanges.h" #include "GCharacter.h" @@ -190,8 +190,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new FormBibtex(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "box") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlBox(*dialog)); - dialog->setView(new FormBox(*dialog)); + dialog->setView(new GBox(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "changes") { dialog->bc().view(new GBC(dialog->bc())); diff --git a/src/frontends/gtk/GBox.C b/src/frontends/gtk/GBox.C new file mode 100644 index 0000000000..d44c23ef63 --- /dev/null +++ b/src/frontends/gtk/GBox.C @@ -0,0 +1,427 @@ +/** + * \file GBox.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Spray + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GBox.h" + +#include "ghelpers.h" + +#include "controllers/ControlBox.h" + +#include "insets/insetbox.h" +#include "lengthcommon.h" +#include "lyxrc.h" // to set the default length values + +using std::string; +using std::vector; + +namespace lyx { +namespace frontend { + +namespace { +string defaultUnit("cm"); +} // namespace anon + +GBox::GBox(Dialog & parent) + : GViewCB(parent, _("Box Settings"), false) +{} + + +void GBox::doBuild() +{ + string const gladeName = findGladeFile("box"); + xml_ = Gnome::Glade::Xml::create(gladeName); + + Gtk::Button * closebutton; + xml_->get_widget("Close", closebutton); + setCancel(closebutton); + + xml_->get_widget("Type", typecombo_); + bcview().addReadOnly(typecombo_); + xml_->get_widget("InnerBox", innerboxcombo_); + bcview().addReadOnly(innerboxcombo_); + xml_->get_widget("WidthUnits", widthunitscombo_); + bcview().addReadOnly(widthunitscombo_); + xml_->get_widget("HeightUnits", heightunitscombo_); + bcview().addReadOnly(heightunitscombo_); + xml_->get_widget("BoxVertical", boxvertcombo_); + bcview().addReadOnly(boxvertcombo_); + xml_->get_widget("ContentVertical", contentvertcombo_); + bcview().addReadOnly(contentvertcombo_); + xml_->get_widget("ContentHorizontal", contenthorzcombo_); + bcview().addReadOnly(contenthorzcombo_); + xml_->get_widget("Width", widthspin_); + bcview().addReadOnly(widthspin_); + xml_->get_widget("Height", heightspin_); + bcview().addReadOnly(heightspin_); + + cols_.add(stringcol_); + + // fill the box type choice + box_gui_tokens(ids_, gui_names_); + PopulateComboBox(typecombo_, gui_names_); + typecombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onTypeComboChanged)); + + // set up innerbox (populated in setInnerType) + innerboxstore_ = Gtk::ListStore::create(cols_); + innerboxcombo_->set_model(innerboxstore_); + Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText); + innerboxcombo_->pack_start(*cell, true); + innerboxcombo_->add_attribute(*cell, "text", 0); + + innerboxcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onInnerBoxComboChanged)); + + boxvertcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onAlignChanged)); + contenthorzcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onAlignChanged)); + contentvertcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onAlignChanged)); + + heightunitscombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onHeightChanged)); + widthunitscombo_->signal_changed().connect( + sigc::mem_fun(*this, &GBox::onWidthChanged)); + + heightspin_->signal_value_changed().connect( + sigc::mem_fun(*this, &GBox::onHeightChanged)); + widthspin_->signal_value_changed().connect( + sigc::mem_fun(*this, &GBox::onWidthChanged)); + + + widthunitsstore_ = Gtk::ListStore::create(cols_); + widthunitscombo_->set_model(widthunitsstore_); + cell = Gtk::manage(new Gtk::CellRendererText); + widthunitscombo_->pack_start(*cell, true); + widthunitscombo_->add_attribute(*cell, "text", 0); + //widthunitscombo_ is populated in setSpecial + + box_gui_tokens_special_length(ids_spec_, gui_names_spec_); + vector heightunits = buildLengthUnitList(); + // Append special entries, skipping the first item "None" + heightunits.insert(heightunits.end(), + ++gui_names_spec_.begin(), gui_names_spec_.end()); + + PopulateComboBox(heightunitscombo_, heightunits); +} + + +void GBox::PopulateComboBox(Gtk::ComboBox * combo, + vector const & strings + ) +{ + Glib::RefPtr model = Gtk::ListStore::create(cols_); + vector::const_iterator it = strings.begin(); + vector::const_iterator end = strings.end(); + for(; it != end; ++it) + (*model->append())[stringcol_] = *it; + + combo->set_model(model); + Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText); + combo->pack_start(*cell, true); + combo->add_attribute(*cell, "text", 0); +} + + +void GBox::update() +{ + applylock_ = true; + + defaultUnit = getDefaultUnit(); + + char c = controller().params().pos; + boxvertcombo_->set_active(string("tcb").find(c, 0)); + c = controller().params().inner_pos; + contentvertcombo_->set_active(string("tcbs").find(c, 0)); + c = controller().params().hor_pos; + contenthorzcombo_->set_active(string("lcrs").find(c, 0)); + + string type(controller().params().type); + for (unsigned int i = 0; i < gui_names_.size(); ++i) { + if (type == ids_[i]) + typecombo_->set_active(i); + } + + applylock_ = false; + updateInnerBoxCombo(); + applylock_ = true; + + bool ibox = controller().params().inner_box; + boxvertcombo_->set_sensitive(ibox); + contentvertcombo_->set_sensitive(ibox); + contenthorzcombo_->set_sensitive(!ibox); + setSpecial(ibox); + + widthspin_->get_adjustment()->set_value(controller().params().width.value()); + unitsComboFromLength(widthunitscombo_, stringcol_, + controller().params().width, defaultUnit); + + string const special(controller().params().special); + if (!special.empty() && special != "none") { + string spc; + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + if (special == ids_spec_[i]) + spc = gui_names_spec_[i]; + } + for (int j = 0; j < widthunitsstore_->children().size(); ++j) { + if (widthunitsstore_->children()[j][stringcol_] == spc) + widthunitscombo_->set_active(j); + } + } + + heightspin_->get_adjustment()->set_value(controller().params().height.value()); + unitsComboFromLength(heightunitscombo_, stringcol_, + controller().params().height, defaultUnit); + + string const height_special(controller().params().height_special); + if (!height_special.empty() && height_special != "none") { + string hspc; + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + if (height_special == ids_spec_[i]) { + hspc = gui_names_spec_[i]; + } + } + for (int j = 0; j < heightunitscombo_->get_model()->children().size(); ++j) { + if (heightunitscombo_->get_model()->children()[j][stringcol_] == hspc) { + heightunitscombo_->set_active(j); + } + } + } + + heightspin_->set_sensitive(ibox); + heightunitscombo_->set_sensitive(ibox); + applylock_ = false; +} + + +void GBox::setSpecial(bool ibox) +{ + bool const oldlock = applylock_; + applylock_ = true; + + unsigned int const initselection = widthunitscombo_->get_active_row_number(); + widthunitsstore_->clear(); + vector normalunits = buildLengthUnitList(); + if (ibox) { + vector::const_iterator it = normalunits.begin(); + vector::const_iterator end = normalunits.end(); + for(; it != end; ++it) + (*widthunitsstore_->append())[stringcol_] = *it; + } else { + vector::const_iterator it = normalunits.begin(); + vector::const_iterator end = normalunits.end(); + for(; it != end; ++it) + (*widthunitsstore_->append())[stringcol_] = *it; + // Skip the first item "None" + it = ++gui_names_spec_.begin(); + end = gui_names_spec_.end(); + for(; it != end; ++it) + (*widthunitsstore_->append())[stringcol_] = *it; + } + + int const store_size = widthunitsstore_->children().size(); + if (initselection >= store_size) { + widthunitscombo_->set_active(0); + onWidthChanged(); + } else { + widthunitscombo_->set_active(initselection); + } + applylock_ = oldlock; +} + + +void GBox::updateInnerBoxCombo() +{ + bool const oldlock = applylock_; + applylock_ = true; + // with "frameless" boxes, inner box is mandatory (i.e. is the actual box) + // we have to remove "none" then and adjust the combo + + // default: minipage + unsigned int i = 2; + if (!controller().params().inner_box) + // none + i = 0; + if (controller().params().use_parbox) + // parbox + i = 1; + bool frameless = (controller().params().type == "Frameless"); + + int const oldsize = innerboxstore_->children().size(); + // Store the initial selection in 0,1,2 format + int oldselection = -1; + if (oldsize == 2) + oldselection = innerboxcombo_->get_active_row_number() + 1; + else if (oldsize == 3) + oldselection = innerboxcombo_->get_active_row_number(); + + if (frameless && oldsize != 2) { + innerboxstore_->clear(); + (*innerboxstore_->append())[stringcol_] = _("Parbox"); + (*innerboxstore_->append())[stringcol_] = _("Minipage"); + // Cope when the backend asks for no inner box in + // a frameless box + if (i == 0) { + applylock_ = false; + innerboxcombo_->set_active(i); + applylock_ = true; + } else + innerboxcombo_->set_active(i - 1); + } else if (!frameless && oldsize != 3) { + innerboxstore_->clear(); + (*innerboxstore_->append())[stringcol_] = _("None"); + (*innerboxstore_->append())[stringcol_] = _("Parbox"); + (*innerboxstore_->append())[stringcol_] = _("Minipage"); + innerboxcombo_->set_active(i); + } else { + // we're not changing the liststore, just selecting i + if (!frameless) + innerboxcombo_->set_active(i); + if (frameless) + innerboxcombo_->set_active(i - 1); + } + + // Update the width units list if we've changed inner box type + if (i != oldselection) + setSpecial(i != 0); + + applylock_ = oldlock; +} + + +void GBox::onInnerBoxComboChanged() +{ + if (applylock_) + return; + + controller().params().use_parbox = + (*innerboxcombo_->get_active())[stringcol_] == _("Parbox"); + + bool const ibox = (*innerboxcombo_->get_active())[stringcol_] != _("None"); + controller().params().inner_box = ibox; + setSpecial(ibox); + + boxvertcombo_->set_sensitive(ibox); + contentvertcombo_->set_sensitive(ibox); + contenthorzcombo_->set_sensitive(!ibox); + heightspin_->set_sensitive(ibox); + heightunitscombo_->set_sensitive(ibox); + // wtf? form_->set_sensitive(ibox); + + controller().dispatchParams(); +} + + +void GBox::onTypeComboChanged() +{ + int const index = typecombo_->get_active_row_number(); + controller().params().type = ids_[index]; + + bool frameless = (index == 0); + if (frameless) { + boxvertcombo_->set_sensitive(true); + contentvertcombo_->set_sensitive(true); + contenthorzcombo_->set_sensitive(false); + heightspin_->set_sensitive(true); + heightunitscombo_->set_sensitive(true); + //wtf? form_->setSpecial(true); + } + //int itype = innerboxcombo_->get_active_row_number(); + controller().dispatchParams(); + + updateInnerBoxCombo(); +} + + +void GBox::onHeightChanged() +{ + if (applylock_) + return; + + // "None" + int i = 0; + bool spec = false; + Glib::ustring special = (*heightunitscombo_->get_active())[stringcol_]; + for (int j = 1; j < gui_names_spec_.size() ; ++j) { + if (gui_names_spec_[j] == special) { + i=j; + spec = true; + } + } + controller().params().height_special = ids_spec_[i]; + + string height; + if (spec) { + height = heightspin_->get_text(); + // beware: bogosity! the unit is simply ignored in this case + height += "in"; + } else { + Glib::ustring const heightunit = + (*heightunitscombo_->get_active())[stringcol_]; + height = heightspin_->get_text() + heightunit; + } + + controller().params().height = LyXLength(height); + controller().dispatchParams(); +} + + +void GBox::onWidthChanged() +{ + if (applylock_) + return; + + int i = 0; + bool spec = false; + Glib::ustring special = (*widthunitscombo_->get_active())[stringcol_]; + for (int j = 1; j < gui_names_spec_.size() ; ++j) { + if (gui_names_spec_[j] == special) { + i=j; + spec = true; + } + } + controller().params().special = ids_spec_[i]; + + string width; + if (spec) { + width = widthspin_->get_text(); + // beware: bogosity! the unit is simply ignored in this case + width += "in"; + } else { + Glib::ustring const widthunit = + (*widthunitscombo_->get_active())[stringcol_]; + width = widthspin_->get_text() + widthunit; + } + + controller().params().width = LyXLength(width); + controller().dispatchParams(); +} + + +void GBox::onAlignChanged() +{ + if (applylock_) + return; + + controller().params().pos = + "tcb"[boxvertcombo_->get_active_row_number()]; + controller().params().inner_pos = + "tcbs"[contenthorzcombo_->get_active_row_number()]; + controller().params().hor_pos = + "lcrs"[contentvertcombo_->get_active_row_number()]; + + controller().dispatchParams(); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GBox.h b/src/frontends/gtk/GBox.h new file mode 100644 index 0000000000..a53ac0faf7 --- /dev/null +++ b/src/frontends/gtk/GBox.h @@ -0,0 +1,88 @@ +// -*- C++ -*- +/** + * \file GBox.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Spray + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GBOX_H +#define GBOX_H + +#include "GViewBase.h" + +#include "lyxlength.h" + +#include +#include + +namespace lyx { +namespace frontend { + +class ControlBox; + +class GBox + : public GViewCB +{ +public: + GBox(Dialog &); + + // This dialog is instant-apply + virtual void apply() {} + // update + virtual void update(); + // build the dialog + virtual void doBuild(); + + // Put strings into combo + void PopulateComboBox(Gtk::ComboBox * combo, + std::vector const & strings); + + // add or remove special lengths in widthunits combo + void setSpecial(bool ibox); + // only show valid inner box options + void updateInnerBoxCombo(); + + // Signal handlers + void onTypeComboChanged(); + void onInnerBoxComboChanged(); + void onAlignChanged(); + void onHeightChanged(); + void onWidthChanged(); + + // Some event handlers are disabled when this is true + bool applylock_; + + // The 'type' field keys and display strings + std::vector ids_; + std::vector gui_names_; + + // The special units for width and height + std::vector ids_spec_; + std::vector gui_names_spec_; + + // Widgets from glade + Gtk::ComboBox * typecombo_; + Gtk::ComboBox * innerboxcombo_; + Glib::RefPtr innerboxstore_; + Gtk::ComboBox * widthunitscombo_; + Glib::RefPtr widthunitsstore_; + Gtk::ComboBox * heightunitscombo_; + Gtk::ComboBox * boxvertcombo_; + Gtk::ComboBox * contentvertcombo_; + Gtk::ComboBox * contenthorzcombo_; + Gtk::SpinButton * widthspin_; + Gtk::SpinButton * heightspin_; + + // Treemodel objects for use in combobox liststores + Gtk::TreeModelColumn stringcol_; + Gtk::TreeModel::ColumnRecord cols_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GBOX_H diff --git a/src/frontends/gtk/GGraphics.C b/src/frontends/gtk/GGraphics.C index 1e4c56d446..8722f9d89c 100644 --- a/src/frontends/gtk/GGraphics.C +++ b/src/frontends/gtk/GGraphics.C @@ -192,18 +192,6 @@ void GGraphics::doBuild() // Store the identifiers for later origins_ = getSecond(origindata); PopulateComboBox(origincombo_, getFirst(origindata)); - - // set the right default unit - switch (lyxrc.default_papersize) { - case PAPER_DEFAULT: break; - case PAPER_USLETTER: - case PAPER_LEGALPAPER: - case PAPER_EXECUTIVEPAPER: defaultUnit = "in"; break; - case PAPER_A3PAPER: - case PAPER_A4PAPER: - case PAPER_A5PAPER: - case PAPER_B5PAPER: defaultUnit = "cm"; break; - } } @@ -239,28 +227,6 @@ void GGraphics::PopulateComboBox(Gtk::ComboBox * combo, } -void GGraphics::updateComboFromLength(Gtk::ComboBox * combo, - LyXLength const & len) -{ - string unit = stringFromUnit(len.unit()); - if (unit.empty()) - unit = defaultUnit; - - Gtk::TreeModel::iterator it = combo->get_model()->children().begin(); - Gtk::TreeModel::iterator end = combo->get_model()->children().end(); - for (; it != end ; ++it) { - if ((*it)[stringcol_] == unit) { - combo->set_active(it); - return; - } - } - // Fallen through, we didn't find the target length! - combo->set_active(0); - lyxerr << "GGraphics::updateComboFromLength: couldn't find " - "target unit '" << unit << "'\n"; -} - - void GGraphics::apply() { // Create the parameters structure and fill the data from the dialog. @@ -368,6 +334,9 @@ void GGraphics::apply() void GGraphics::update() { + // set the right default unit + defaultUnit = getDefaultUnit(); + // Update dialog with details from inset InsetGraphicsParams & igp = controller().params(); @@ -397,9 +366,11 @@ void GGraphics::update() { outputscalespin_->get_adjustment()->set_value(igp.scale); widthspin_->get_adjustment()->set_value(igp.width.value()); - updateComboFromLength(widthunitscombo_, igp.width); + unitsComboFromLength(widthunitscombo_, stringcol_, + igp.width, defaultUnit); heightspin_->get_adjustment()->set_value(igp.height.value()); - updateComboFromLength(heightunitscombo_, igp.height); + unitsComboFromLength(heightunitscombo_, stringcol_, + igp.height, defaultUnit); if (!float_equal(igp.scale, 0.0, 0.05)) { // scaling sizing mode @@ -470,7 +441,8 @@ void GGraphics::updateBB(string const & filename, string const & bb_inset) righttopxspin_->set_text(""); righttopyspin_->set_text(""); } - updateComboFromLength(bbunitscombo_,LyXLength("bp")); + unitsComboFromLength(bbunitscombo_, stringcol_, + LyXLength("bp"), defaultUnit); } else { // get the values from the inset lyxerr[Debug::GRAPHICS] @@ -480,7 +452,7 @@ void GGraphics::updateBB(string const & filename, string const & bb_inset) LyXLength anyLength; anyLength = LyXLength(token(bb_inset, ' ', 0)); - updateComboFromLength(bbunitscombo_, anyLength); + unitsComboFromLength(bbunitscombo_, stringcol_, anyLength, defaultUnit); leftbottomxspin_->get_adjustment()->set_value(anyLength.value()); @@ -533,7 +505,8 @@ void GGraphics::onBBFromFileClicked() leftbottomyspin_->set_text(token(bb, ' ', 1)); righttopxspin_->set_text(token(bb, ' ', 2)); righttopyspin_->set_text(token(bb, ' ', 3)); - updateComboFromLength(bbunitscombo_,LyXLength("bp")); + unitsComboFromLength(bbunitscombo_, stringcol_, + LyXLength("bp"), defaultUnit); } controller().bbChanged = false; } else { @@ -541,7 +514,8 @@ void GGraphics::onBBFromFileClicked() leftbottomyspin_->set_text(""); righttopxspin_->set_text(""); righttopyspin_->set_text(""); - updateComboFromLength(bbunitscombo_,LyXLength("bp")); + unitsComboFromLength(bbunitscombo_, stringcol_, + LyXLength("bp"), defaultUnit); } bc().input(ButtonPolicy::SMI_VALID); } diff --git a/src/frontends/gtk/GGraphics.h b/src/frontends/gtk/GGraphics.h index 3eb3af1e9f..3a943d5a4f 100644 --- a/src/frontends/gtk/GGraphics.h +++ b/src/frontends/gtk/GGraphics.h @@ -45,9 +45,6 @@ private: void PopulateComboBox(Gtk::ComboBox * combo, std::vector const & strings); - void updateComboFromLength(Gtk::ComboBox * combo, - LyXLength const & len); - bool updating_; /// Store the LaTeX names for the rotation origins. diff --git a/src/frontends/gtk/GWorkArea.C b/src/frontends/gtk/GWorkArea.C index 0e23e54029..4aa8ef86d3 100644 --- a/src/frontends/gtk/GWorkArea.C +++ b/src/frontends/gtk/GWorkArea.C @@ -43,7 +43,7 @@ mouse_button::state gButtonToLyx(guint gdkbutton) case 5: return mouse_button::button5; } - + // This shouldn't happen, according to gdk docs lyxerr << "gButtonToLyx: unhandled button index\n"; return mouse_button::button1; diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 9604c17ca5..331fdcfa40 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -24,6 +24,8 @@ libgtk_la_SOURCES = \ GAboutlyx.h \ GBC.C \ GBC.h \ + GBox.C \ + GBox.h \ GChanges.C \ GChanges.h \ GCharacter.C \ @@ -108,7 +110,6 @@ xforms_objects = \ ../xforms/fdesign_base.lo \ ../xforms/FormBibitem.lo \ ../xforms/FormBibtex.lo \ - ../xforms/FormBox.lo \ ../xforms/FormBranch.lo \ ../xforms/FormBrowser.lo \ ../xforms/FormCitation.lo \ diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C index 87d37574f8..79dc933e08 100644 --- a/src/frontends/gtk/ghelpers.C +++ b/src/frontends/gtk/ghelpers.C @@ -12,8 +12,8 @@ #include "ghelpers.h" +#include "lyxrc.h" #include "debug.h" -#include "lengthcommon.h" #include "support/filetools.h" #include "support/path_defines.h" @@ -24,6 +24,46 @@ using std::vector; namespace lyx { namespace frontend { +string const getDefaultUnit() +{ + switch (lyxrc.default_papersize) { + case PAPER_DEFAULT: return "cm"; + case PAPER_USLETTER: + case PAPER_LEGALPAPER: + case PAPER_EXECUTIVEPAPER: return "in"; break; + case PAPER_A3PAPER: + case PAPER_A4PAPER: + case PAPER_A5PAPER: + case PAPER_B5PAPER: return "cm"; break; + } +} + + +void unitsComboFromLength(Gtk::ComboBox * combo, + Gtk::TreeModelColumn const & stringcol, + LyXLength const & len, + std::string defunit) +{ + string unit = stringFromUnit(len.unit()); + if (unit.empty()) + unit = defunit; + + Gtk::TreeModel::iterator it = combo->get_model()->children().begin(); + Gtk::TreeModel::iterator end = combo->get_model()->children().end(); + for (; it != end ; ++it) { + if ((*it)[stringcol] == unit) { + combo->set_active(it); + return; + } + } + + // Fallen through, we didn't find the target length! + combo->set_active(0); + lyxerr << "unitsComboFromLength: couldn't find " + "target unit '" << unit << "'\n"; +} + + vector const buildLengthUnitList() { vector data(unit_name_gui, unit_name_gui + num_units); diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h index b0bce13b8b..6519353436 100644 --- a/src/frontends/gtk/ghelpers.h +++ b/src/frontends/gtk/ghelpers.h @@ -12,12 +12,23 @@ #ifndef GHELPERS_H #define GHELPERS_H +#include "lengthcommon.h" + +#include + #include #include namespace lyx { namespace frontend { +std::string const getDefaultUnit(); + +void unitsComboFromLength(Gtk::ComboBox * combo, + Gtk::TreeModelColumn const & stringcol, + LyXLength const & len, + std::string defunit); + std::vector const buildLengthUnitList(); /** name is the name of the glade file, without path or extension. diff --git a/src/frontends/gtk/glade/box.glade b/src/frontends/gtk/glade/box.glade new file mode 100644 index 0000000000..ec0304d9c7 --- /dev/null +++ b/src/frontends/gtk/glade/box.glade @@ -0,0 +1,550 @@ + + + + + + + dialog1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + -7 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 0 + + + + True + <b>Box</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 6 + 6 + 12 + 0 + + + + True + 2 + 2 + False + 6 + 6 + + + + True + T_ype: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Type + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Inner Box: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + InnerBox + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + True + + + 1 + 2 + 0 + 1 + fill + fill + + + + + + + 0 + True + True + + + + + + True + <b>Size</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 6 + 6 + 12 + 0 + + + + True + 2 + 3 + False + 6 + 6 + + + + True + _Width: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Width + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Height: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Height + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + + + 2 + 3 + 1 + 2 + fill + fill + + + + + + True + + + 2 + 3 + 0 + 1 + fill + fill + + + + + + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 666 0 10000 1 10 10 + + + 1 + 2 + 0 + 1 + fill + + + + + + + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 666 0 10000 1 10 10 + + + 1 + 2 + 1 + 2 + fill + + + + + + + + 0 + False + False + + + + + + True + <b>Alignment</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 6 + 6 + 12 + 0 + + + + True + 3 + 2 + False + 6 + 6 + + + + True + _Box vertical: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + BoxVertical + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + C_ontent vertical: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + ContentVertical + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Co_ntent horizontal: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + ContentHorizontal + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + Top +Center +Bottom +Fill + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + True + Top +Center +Bottom + + + 1 + 2 + 0 + 1 + fill + fill + + + + + + True + Left +Center +Right +Fill + + + 1 + 2 + 2 + 3 + fill + fill + + + + + + + 0 + False + False + + + + + 0 + True + True + + + + + + + -- 2.39.2