From: John Spray Date: Tue, 16 Nov 2004 00:20:59 +0000 (+0000) Subject: gtk vspace dialog X-Git-Tag: 1.6.10~14826 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=59cd5ec1732eb4d45e9f290500e0ac9fe4b0584f;p=features.git gtk vspace dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9257 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 272f673df5..393834a801 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,11 +1,14 @@ 2004-11-15 John Spray + * The VSpace Dialog: + Dialogs.C, Makefile.am, GVSpace.C, GVSpace.h * The Note Dialog: Dialogs.C, Makefile.am, GNote.C, GNote.h * The Float Dialog: Dialogs.C, Makefile.am, GFloat.C, GFloat.h * ghelpers.[Ch]: getGTKStockIcon added to choose gtk - stock icons for FuncRequests + stock icons for FuncRequests, buildLengthNoRelUnitList() + to get vector of units not containing "%" * GToolbar.C: use getGTKStockIcon for toolbutton icons * GMenubar.C: add icons to menu items diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 7d5b4d1222..bfb1fc939e 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -87,7 +87,7 @@ #include "GTableCreate.h" #include "GToc.h" #include "GUrl.h" -#include "FormVSpace.h" +#include "GVSpace.h" #include "FormWrap.h" #ifdef HAVE_LIBAIKSAURUS @@ -523,8 +523,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GUrl(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "vspace") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlVSpace(*dialog)); - dialog->setView(new FormVSpace(*dialog)); + dialog->setView(new GVSpace(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "wrap") { dialog->setController(new ControlWrap(*dialog)); diff --git a/src/frontends/gtk/GSpellchecker.C b/src/frontends/gtk/GSpellchecker.C index 815de850c2..cda95eea4c 100644 --- a/src/frontends/gtk/GSpellchecker.C +++ b/src/frontends/gtk/GSpellchecker.C @@ -132,7 +132,7 @@ void GSpellchecker::partialUpdate(int s) void GSpellchecker::onSuggestionActivate( Gtk::TreeModel::Path const & path, - Gtk::TreeViewColumn * col) + Gtk::TreeViewColumn * /*col*/) { Glib::ustring const suggestion = (*suggestionsstore_->get_iter(path))[listCol_]; diff --git a/src/frontends/gtk/GVSpace.C b/src/frontends/gtk/GVSpace.C new file mode 100644 index 0000000000..f016d9d0a5 --- /dev/null +++ b/src/frontends/gtk/GVSpace.C @@ -0,0 +1,164 @@ +/** + * \file GVSpace.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 "GVSpace.h" +#include "ControlVSpace.h" +#include "ghelpers.h" + +#include + +using std::string; +using std::vector; + +namespace lyx { +namespace frontend { + +namespace { +string defaultUnit("cm"); +} // namespace anon + +GVSpace::GVSpace(Dialog & parent) + : GViewCB(parent, _("VSpace Settings"), false) +{} + + +void GVSpace::doBuild() +{ + string const gladeName = findGladeFile("vspace"); + xml_ = Gnome::Glade::Xml::create(gladeName); + + Gtk::Button * button; + xml_->get_widget("Cancel", button); + setCancel(button); + xml_->get_widget("Insert", button); + setOK(button); + + xml_->get_widget("Spacing", spacingcombo_); + xml_->get_widget("Value", valuespin_); + xml_->get_widget("ValueUnits", valueunitscombo_); + xml_->get_widget("Protect", protectcheck_); + + cols_.add(stringcol_); + + PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList()); + + spacingcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GVSpace::onSpacingComboChanged)); +} + + +void GVSpace::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 (int rowindex = 0; it != end; ++it, ++rowindex) { + Gtk::TreeModel::iterator row = model->append(); + (*row)[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 GVSpace::update() +{ + // set the right default unit + defaultUnit = getDefaultUnit(); + + VSpace const space = controller().params(); + + int pos = 0; + switch (space.kind()) { + case VSpace::DEFSKIP: + pos = 0; + break; + case VSpace::SMALLSKIP: + pos = 1; + break; + case VSpace::MEDSKIP: + pos = 2; + break; + case VSpace::BIGSKIP: + pos = 3; + break; + case VSpace::VFILL: + pos = 4; + break; + case VSpace::LENGTH: + pos = 5; + break; + } + + spacingcombo_->set_active(pos); + + protectcheck_->set_active(space.keep()); + + bool const custom_vspace = space.kind() == VSpace::LENGTH; + if (custom_vspace) { + LyXLength length(space.length().asString()); + valuespin_->get_adjustment()->set_value(length.value()); + unitsComboFromLength(valueunitscombo_, stringcol_, + length, defaultUnit); + } else { + valuespin_->get_adjustment()->set_value(0.0f); + unitsComboFromLength(valueunitscombo_, stringcol_, + LyXLength(defaultUnit), defaultUnit); + } +} + + +void GVSpace::apply() +{ + VSpace space; + switch (spacingcombo_->get_active_row_number()) { + case 0: + space = VSpace(VSpace::DEFSKIP); + break; + case 1: + space = VSpace(VSpace::SMALLSKIP); + break; + case 2: + space = VSpace(VSpace::MEDSKIP); + break; + case 3: + space = VSpace(VSpace::BIGSKIP); + break; + case 4: + space = VSpace(VSpace::VFILL); + break; + case 5: + Glib::ustring const valueunit = + (*valueunitscombo_->get_active())[stringcol_]; + space = VSpace(LyXGlueLength(valuespin_->get_text() + valueunit)); + break; + } + + space.setKeep(protectcheck_->get_active()); + + controller().params() = space; +} + + +void GVSpace::onSpacingComboChanged() +{ + bool const custom = spacingcombo_->get_active_row_number() == 5; + valueunitscombo_->set_sensitive(custom); + valuespin_->set_sensitive(custom); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GVSpace.h b/src/frontends/gtk/GVSpace.h new file mode 100644 index 0000000000..3619245d51 --- /dev/null +++ b/src/frontends/gtk/GVSpace.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +/** + * \file GVSpace.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 GVSPACE_H +#define GVSPACE_H + +#include "GViewBase.h" + +namespace lyx { +namespace frontend { + +class ControlVSpace; + +/** This class provides a GTK+ implementation of the VSpace Dialog. + */ +class GVSpace : public GViewCB { +public: + GVSpace(Dialog & parent); +private: + virtual void apply(); + virtual void doBuild(); + virtual void update(); + + void PopulateComboBox(Gtk::ComboBox * combo, + std::vector const & strings); + + void onSpacingComboChanged(); + + Gtk::TreeModelColumn stringcol_; + Gtk::TreeModel::ColumnRecord cols_; + + Gtk::ComboBox * spacingcombo_; + Gtk::SpinButton * valuespin_; + Gtk::ComboBox * valueunitscombo_; + Gtk::CheckButton * protectcheck_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GVSPACE_H diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index f8997542db..a234212839 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -86,6 +86,8 @@ libgtk_la_SOURCES = \ GView.h \ GViewBase.C \ GViewBase.h \ + GVSpace.C \ + GVSpace.h \ GWorkArea.C \ GWorkArea.h \ GXpmBtnTbl.C \ @@ -136,7 +138,6 @@ xforms_objects = \ ../xforms/FormTabular.lo \ ../xforms/FormText.lo \ ../xforms/FormThesaurus.lo \ - ../xforms/FormVSpace.lo \ ../xforms/FormWrap.lo \ ../xforms/freebrowser.lo \ ../xforms/input_validators.lo \ diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C index 2527c847b1..9dd1ed7541 100644 --- a/src/frontends/gtk/ghelpers.C +++ b/src/frontends/gtk/ghelpers.C @@ -112,6 +112,19 @@ vector const buildLengthUnitList() } +vector const buildLengthNoRelUnitList() +{ + vector data; + for (int i = 0; i < num_units; ++i) { + string str(unit_name_gui[i]); + if (str.find("%") == -1) + data.push_back(unit_name_gui[i]); + } + + return data; +} + + string const findGladeFile(string const & name) { // First, search in the installation directories. diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h index 3d215fe522..3700e13209 100644 --- a/src/frontends/gtk/ghelpers.h +++ b/src/frontends/gtk/ghelpers.h @@ -37,6 +37,8 @@ void unitsComboFromLength(Gtk::ComboBox * combo, std::vector const buildLengthUnitList(); +std::vector const buildLengthNoRelUnitList(); + /** name is the name of the glade file, without path or extension. * Eg, "aboutlyx", "tableCreate". */ diff --git a/src/frontends/gtk/glade/vspace.glade b/src/frontends/gtk/glade/vspace.glade new file mode 100644 index 0000000000..e583b56949 --- /dev/null +++ b/src/frontends/gtk/glade/vspace.glade @@ -0,0 +1,279 @@ + + + + + + + True + 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-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + GTK_RELIEF_NORMAL + True + -5 + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-ok + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Insert + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + 3 + 2 + False + 6 + 6 + + + + True + _Spacing: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Value: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + DefSkip +SmallSkip +MedSkip +BigSkip +VFill +Custom + + + 1 + 2 + 0 + 1 + fill + + + + + + True + False + 0 + + + + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 1 0 10000 1 10 10 + + + 0 + True + True + + + + + + True + + + 4 + False + True + + + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + True + True + _Protect + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 2 + 3 + fill + + + + + + 0 + True + True + + + + + + +