From de8a7a9214b857dbae78eaa6cf3c7bb3ae416a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 27 Sep 2004 18:52:43 +0000 Subject: [PATCH] the character dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9016 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 6 + src/frontends/gtk/Dialogs.C | 5 +- src/frontends/gtk/GCharacter.C | 245 ++++++++++ src/frontends/gtk/GCharacter.h | 71 +++ src/frontends/gtk/Makefile.am | 3 +- src/frontends/gtk/ghelpers.h | 12 + src/frontends/gtk/glade/Makefile.am | 10 +- src/frontends/gtk/glade/character.glade | 579 ++++++++++++++++++++++++ 8 files changed, 926 insertions(+), 5 deletions(-) create mode 100644 src/frontends/gtk/GCharacter.C create mode 100644 src/frontends/gtk/GCharacter.h create mode 100644 src/frontends/gtk/glade/character.glade diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 362747435a..674f172458 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,9 @@ +2004-09-27 John Spray + + * The Character dialog + * Dialogs.C, GCharacter.C, GCharacter.h, Makefile.am, ghelpers.h, + glade/Makefile.am, glade/character.glade + 2004-09-27 Lars Gullik Bjonnes * GXpmBtnTbl.C (construct): use Boost.Assert diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 54dd0fcdf6..8b6780ca1c 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -57,7 +57,7 @@ #include "FormBox.h" #include "FormBranch.h" #include "FormChanges.h" -#include "FormCharacter.h" +#include "GCharacter.h" #include "FormCitation.h" #include "FormDocument.h" #include "FormErrorList.h" @@ -198,8 +198,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new FormChanges(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "character") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlCharacter(*dialog)); - dialog->setView(new FormCharacter(*dialog)); + dialog->setView(new GCharacter(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "citation") { dialog->setController(new ControlCitation(*dialog)); diff --git a/src/frontends/gtk/GCharacter.C b/src/frontends/gtk/GCharacter.C new file mode 100644 index 0000000000..6f7d1abd73 --- /dev/null +++ b/src/frontends/gtk/GCharacter.C @@ -0,0 +1,245 @@ +/** + * \file GCharacter.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 "GCharacter.h" +#include "ghelpers.h" +#include "LColor.h" + +#include "controllers/frnt_lang.h" +#include "controllers/helper_funcs.h" + +#include "support/lstrings.h" + +#include + +using std::vector; +using std::string; + +namespace lyx { +namespace frontend { + + +GCharacter::GCharacter(Dialog & parent) + : GViewCB(parent, _("Text Style"), false) +{} + + +class stringcolumns : public Gtk::TreeModel::ColumnRecord { +public: + stringcolumns() + { + add(name); + } + + Gtk::TreeModelColumn name; +}; + + +void GCharacter::PopulateComboBox(Gtk::ComboBox * combo, + vector const & strings) +{ + stringcolumns * cols = new stringcolumns; + Glib::RefPtr model = Gtk::ListStore::create(*cols); + vector::const_iterator it = strings.begin(); + vector::const_iterator end = strings.end(); + for(; it != end; ++it){ + Gtk::TreeModel::iterator iter = model->append(); + Gtk::TreeModel::Row row = *iter; + row[cols->name] = *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 GCharacter::doBuild() +{ + string const gladeName = findGladeFile("character"); + xml_ = Gnome::Glade::Xml::create(gladeName); + Gtk::Button * button; + + // Manage the ok, apply and cancel/close buttons + xml_->get_widget("Ok", button); + setOK(button); + xml_->get_widget("Apply", button); + setApply(button); + xml_->get_widget("Cancel", button); + setCancel(button); + + xml_->get_widget("ToggleAll", toggleallcheck_); + + //Get combobox addresses + xml_->get_widget("Family", familycombo_); + xml_->get_widget("Series", seriescombo_); + xml_->get_widget("Shape", shapecombo_); + xml_->get_widget("Color", colorcombo_); + xml_->get_widget("Language", languagecombo_); + xml_->get_widget("Size", sizecombo_); + xml_->get_widget("Misc", misccombo_); + + //Don't let the user change anything for read only documents + bcview().addReadOnly(familycombo_); + bcview().addReadOnly(seriescombo_); + bcview().addReadOnly(shapecombo_); + bcview().addReadOnly(colorcombo_); + bcview().addReadOnly(languagecombo_); + bcview().addReadOnly(sizecombo_); + bcview().addReadOnly(misccombo_); + bcview().addReadOnly(toggleallcheck_); + + //Caption/identifier pairs for the parameters + vector const family = getFamilyData(); + vector const series = getSeriesData(); + vector const shape = getShapeData(); + vector const size = getSizeData(); + vector const bar = getBarData(); + vector const color = getColorData(); + vector const language = getLanguageData(true); + + // Store the identifiers for later + family_ = getSecond(family); + series_ = getSecond(series); + shape_ = getSecond(shape); + size_ = getSecond(size); + bar_ = getSecond(bar); + color_ = getSecond(color); + lang_ = getSecond(language); + + // Load the captions into the comboboxes + PopulateComboBox(familycombo_, getFirst(family)); + PopulateComboBox(seriescombo_, getFirst(series)); + PopulateComboBox(shapecombo_, getFirst(shape)); + PopulateComboBox(sizecombo_, getFirst(size)); + PopulateComboBox(misccombo_, getFirst(bar)); + PopulateComboBox(colorcombo_, getFirst(color)); + PopulateComboBox(languagecombo_, getFirst(language)); + + /* We use a table so that people with decent size screens don't + * have to scroll. However, this risks the popup being too wide + * for people with small screens, and it doesn't scroll horizontally. + * Hopefully this is not too wide (and hopefully gtk gets fixed).*/ + languagecombo_->set_wrap_width(3); + + //Load in the current settings + update(); + + familycombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + seriescombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + shapecombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + sizecombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + misccombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + colorcombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); + languagecombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCharacter::onChange)); +} + + +void GCharacter::apply() +{ + int pos = familycombo_->get_active_row_number(); + controller().setFamily(family_[pos]); + + pos = seriescombo_->get_active_row_number(); + controller().setSeries(series_[pos]); + + pos = shapecombo_->get_active_row_number(); + controller().setShape(shape_[pos]); + + pos = sizecombo_->get_active_row_number(); + controller().setSize(size_[pos]); + + pos = misccombo_->get_active_row_number(); + controller().setBar(bar_[pos]); + + pos = colorcombo_->get_active_row_number(); + controller().setColor(color_[pos]); + + pos = languagecombo_->get_active_row_number(); + controller().setLanguage(lang_[pos]); + + bool const toggleall = toggleallcheck_->get_active(); + controller().setToggleAll(toggleall); +} + + +void GCharacter::update() +{ + int pos = int(findPos(family_, controller().getFamily())); + familycombo_->set_active(pos); + + pos = int(findPos(series_, controller().getSeries())); + seriescombo_->set_active(pos); + + pos = int(findPos(shape_, controller().getShape())); + shapecombo_->set_active(pos); + + pos = int(findPos(size_, controller().getSize())); + sizecombo_->set_active(pos); + + pos = int(findPos(bar_, controller().getBar())); + misccombo_->set_active(pos); + + pos = int(findPos(color_, controller().getColor())); + colorcombo_->set_active(pos); + + pos = int(findPos(lang_, controller().getLanguage())); + languagecombo_->set_active(pos); + + toggleallcheck_->set_active(controller().getToggleAll()); +} + + +void GCharacter::onChange() +{ + ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP; + + int pos = familycombo_->get_active_row_number(); + if (family_[pos] != LyXFont::IGNORE_FAMILY) + activate = ButtonPolicy::SMI_VALID; + + pos = seriescombo_->get_active_row_number(); + if (series_[pos] != LyXFont::IGNORE_SERIES) + activate = ButtonPolicy::SMI_VALID; + + pos = shapecombo_->get_active_row_number(); + if (shape_[pos] != LyXFont::IGNORE_SHAPE) + activate = ButtonPolicy::SMI_VALID; + + pos = sizecombo_->get_active_row_number(); + if (size_[pos] != LyXFont::IGNORE_SIZE) + activate = ButtonPolicy::SMI_VALID; + + pos = misccombo_->get_active_row_number(); + if (bar_[pos] != IGNORE) + activate = ButtonPolicy::SMI_VALID; + + pos = colorcombo_->get_active_row_number(); + if (color_[pos] != LColor::ignore) + activate = ButtonPolicy::SMI_VALID; + + pos = languagecombo_->get_active_row_number(); + if (lang_[pos] != "No change") + activate = ButtonPolicy::SMI_VALID; + + bc().input(activate); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GCharacter.h b/src/frontends/gtk/GCharacter.h new file mode 100644 index 0000000000..ebd7990a12 --- /dev/null +++ b/src/frontends/gtk/GCharacter.h @@ -0,0 +1,71 @@ +// -*- C++ -*- +/** + * \file GCharacter.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Spray + * Based on version from xforms frontend + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GCHARACTER_H +#define GCHARACTER_H + +#include "GViewBase.h" +#include "ControlCharacter.h" // for ControlCharacter enum + +struct LColor_color; + +namespace lyx { +namespace frontend { + +/** + * This class provides a GTK+ implementation of the Character Dialog. + * The character dialog allows users to change the character settings + * in their documents. + */ +class GCharacter + : public GViewCB { +public: + /// + GCharacter(Dialog &); +private: + /// Apply from dialog + virtual void apply(); + + /// Build the dialog + virtual void doBuild(); + + /// Update the dialog. + virtual void update(); + + void PopulateComboBox(Gtk::ComboBox * combo, + std::vector const & strings); + + std::vector family_; + std::vector series_; + std::vector shape_; + std::vector size_; + std::vector bar_; + std::vector color_; + std::vector lang_; + + Gtk::ComboBox * familycombo_; + Gtk::ComboBox * seriescombo_; + Gtk::ComboBox * shapecombo_; + Gtk::ComboBox * colorcombo_; + Gtk::ComboBox * languagecombo_; + Gtk::ComboBox * sizecombo_; + Gtk::ComboBox * misccombo_; + + Gtk::CheckButton * toggleallcheck_; + + void GCharacter::onChange(); +}; + +} // namespace frontend +} // namespace lyx + +#endif diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index a46f161e5f..d1e50f55a8 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 \ + GCharacter.C \ + GCharacter.h \ GLyXKeySym.C \ GLyXKeySym.h \ GMathDelim.C \ @@ -90,7 +92,6 @@ xforms_objects = \ ../xforms/FormBranch.lo \ ../xforms/FormBrowser.lo \ ../xforms/FormChanges.lo \ - ../xforms/FormCharacter.lo \ ../xforms/FormCitation.lo \ ../xforms/FormColorpicker.lo \ ../xforms/FormDialogView.lo \ diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h index f86b921e09..738ca8a126 100644 --- a/src/frontends/gtk/ghelpers.h +++ b/src/frontends/gtk/ghelpers.h @@ -13,6 +13,7 @@ #define GHELPERS_H #include +#include namespace lyx { namespace frontend { @@ -22,6 +23,17 @@ namespace frontend { */ std::string const findGladeFile(std::string const & name); +template +typename std::vector::size_type +findPos(std::vector const & vec, A const & val) +{ + typename std::vector::const_iterator it = + std::find(vec.begin(), vec.end(), val); + if (it == vec.end()) + return 0; + return std::distance(vec.begin(), it); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/gtk/glade/Makefile.am b/src/frontends/gtk/glade/Makefile.am index 98b2f73596..46a275ac6c 100644 --- a/src/frontends/gtk/glade/Makefile.am +++ b/src/frontends/gtk/glade/Makefile.am @@ -4,8 +4,14 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in GLADE_DIR = glade GLADE_FILES = \ - aboutlyx.glade mathDelim.glade mathPanel.glade \ - print.glade search.glade tableCreate.glade text.glade \ + aboutlyx.glade \ + character.glade \ + mathDelim.glade \ + mathPanel.glade \ + print.glade \ + search.glade \ + tableCreate.glade \ + text.glade \ url.glade EXTRA_DIST = ${GLADE_FILES} diff --git a/src/frontends/gtk/glade/character.glade b/src/frontends/gtk/glade/character.glade new file mode 100644 index 0000000000..fbbde030c5 --- /dev/null +++ b/src/frontends/gtk/glade/character.glade @@ -0,0 +1,579 @@ + + + + + + + True + Character + 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-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + 3 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + 6 + 2 + False + 4 + 0 + + + + True + _Family: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Family + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Series + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Series + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + S_hape: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Shape + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + _Color + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Color + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + _Language: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Language + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + True + _Toggle all + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 5 + 6 + fill + + + + + + + True + + + 1 + 2 + 0 + 1 + 4 + fill + + + + + + True + + + 1 + 2 + 1 + 2 + 4 + fill + fill + + + + + + True + + + 1 + 2 + 2 + 3 + 4 + fill + fill + + + + + + True + + + 1 + 2 + 3 + 4 + 4 + fill + fill + + + + + + True + + + 1 + 2 + 4 + 5 + 4 + fill + fill + + + + + + + + + + True + <b>Character</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + True + True + + + + + + True + + + 3 + False + False + + + + + + True + False + 0 + + + + 3 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 6 + 6 + 12 + 0 + + + + True + False + 0 + + + + True + Si_ze: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + Size + + + 0 + False + False + + + + + + True + + + 3 + True + True + + + + + + + + + + True + <b>Never Toggled</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + False + True + + + + + + 3 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 6 + 6 + 12 + 0 + + + + True + False + 0 + + + + True + _Misc: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 1 + Misc + + + 0 + False + False + + + + + + True + + + 3 + True + True + + + + + + + + + + True + <b>Always Toggled</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + False + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + +