From 2bb86211292f416cd584023feb23dc3b86bc1761 Mon Sep 17 00:00:00 2001 From: John Spray Date: Sun, 12 Feb 2006 23:58:29 +0000 Subject: [PATCH] Rearrange GTK icon lookup code, get rid of comboBoxTextSet git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13220 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 5 +++ src/frontends/gtk/GDocument.C | 12 +++---- src/frontends/gtk/GMenubar.C | 8 ++--- src/frontends/gtk/GToolbar.C | 21 +++++------- src/frontends/gtk/GtkLengthEntry.C | 2 +- src/frontends/gtk/ghelpers.C | 54 ++++++++++++++++++++++-------- src/frontends/gtk/ghelpers.h | 9 +++-- 7 files changed, 66 insertions(+), 45 deletions(-) diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index c006c360c8..98e3b54af3 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,5 +1,10 @@ 2006-02-12 John Spray * GMenubar.C: assume backend strings in latin1 (bug 1954) + * GDocument.C, GtkLengthEntry.C: replace comboBoxTextSet with + Gtk::ComboBoxText::set_active_text + * ghelpers.[Ch]: remove comboBoxTextSet, rearrange GTK icon + lookup code in preparation for using icon themes. + * GMenubar.C, GToolbar.C: use the new icon lookup function 2006-02-12 Bartek Kostrzewa * GMenubar.C: Fix crash with navigation submenus diff --git a/src/frontends/gtk/GDocument.C b/src/frontends/gtk/GDocument.C index c9c253b786..08a8836e9b 100644 --- a/src/frontends/gtk/GDocument.C +++ b/src/frontends/gtk/GDocument.C @@ -349,11 +349,11 @@ void GDocument::update() extraoptionsentry_->set_text(params.options); // Postscript driver - comboBoxTextSet(psdrivercombo_, params.graphicsDriver); + psdrivercombo_.set_active_text (params.graphicsDriver); // Font & Size - comboBoxTextSet(fontcombo_, params.fonts); - comboBoxTextSet(fontsizecombo_, params.fontsize); + fontcombo_.set_active_text (params.fonts); + fontsizecombo_.set_active_text (params.fontsize); // Line Spacing linespacingadj_->set_value(params.spacing().getValue()); @@ -396,7 +396,7 @@ void GDocument::update() doublesidedtoggle_->set_active(params.sides == LyXTextClass::TwoSides); - comboBoxTextSet(pagestylecombo_, params.pagestyle); + pagestylecombo_.set_active_text (params.pagestyle); // *** End "Page" Page *** defaultmargins_->set_active(!params.use_geometry); @@ -784,7 +784,7 @@ void GDocument::classChanged() for (int n = 0; !token(fontsizeitems, '|', n).empty(); ++n) fontsizecombo_.append_text(token(fontsizeitems, '|', n)); - comboBoxTextSet(fontsizecombo_, params.fontsize); + fontsizecombo_.set_active_text (params.fontsize); pagestylecombo_.clear(); pagestylecombo_.append_text("default"); @@ -793,7 +793,7 @@ void GDocument::classChanged() for (int n=0; !token(pagestyleitems,'|',n).empty(); ++n) pagestylecombo_.append_text(token(pagestyleitems,'|',n)); - comboBoxTextSet(pagestylecombo_, params.pagestyle); + pagestylecombo_.set_active_text (params.pagestyle); } } else { classcombo_.set_active(params.textclass); diff --git a/src/frontends/gtk/GMenubar.C b/src/frontends/gtk/GMenubar.C index 9084dc7b6c..15bc466f47 100644 --- a/src/frontends/gtk/GMenubar.C +++ b/src/frontends/gtk/GMenubar.C @@ -195,12 +195,8 @@ void GMenubar::onSubMenuActivate(MenuItem const * item, checkitem.set_active(on); } else { // Choose an icon from the funcrequest - Gtk::BuiltinStockID stockID = getGTKStockIcon(i->func()); - Gtk::Image * image = NULL; - // Prefer stock graphics - if (stockID != Gtk::Stock::MISSING_IMAGE) { - image = Gtk::manage(new Gtk::Image(stockID, Gtk::ICON_SIZE_MENU)); - } else { + Gtk::Image * image = getGTKIcon(i->func(), Gtk::ICON_SIZE_MENU); + if (!image) { Glib::ustring xpmName = Glib::locale_to_utf8(toolbarbackend.getIcon(i->func())); if (xpmName.find("unknown.xpm") == Glib::ustring::npos) { diff --git a/src/frontends/gtk/GToolbar.C b/src/frontends/gtk/GToolbar.C index 4536f09799..23f3e16090 100644 --- a/src/frontends/gtk/GToolbar.C +++ b/src/frontends/gtk/GToolbar.C @@ -231,26 +231,21 @@ void GToolbar::add(FuncRequest const & func, string const & tooltip) } default: { - // choose an icon from the funcrequest - Gtk::BuiltinStockID stockID = getGTKStockIcon(func); - Glib::ustring tip = Glib::locale_to_utf8(tooltip); Gtk::ToolButton * toolbutton; - if (stockID != Gtk::Stock::MISSING_IMAGE) { - // Prefer stock gtk graphics - Gtk::IconSize size(Gtk::ICON_SIZE_LARGE_TOOLBAR); - Gtk::Image * image = Gtk::manage(new Gtk::Image(stockID, size)); - image->show(); - toolbutton = Gtk::manage(new Gtk::ToolButton(*image)); - } else { + Gtk::Image * image = NULL; + image = getGTKIcon(func, Gtk::ICON_SIZE_LARGE_TOOLBAR); + if (!image) { Glib::ustring xpmName = Glib::locale_to_utf8(toolbarbackend.getIcon(func)); - Gtk::Image * image = Gtk::manage(new Gtk::Image(xpmName)); - image->show(); - toolbutton = Gtk::manage(new Gtk::ToolButton(*image)); + if (xpmName.find("unknown.xpm") == Glib::ustring::npos) { + image = Gtk::manage(new Gtk::Image(xpmName)); + } } + image->show(); + toolbutton = Gtk::manage(new Gtk::ToolButton(*image)); // This code is putting a function reference into the GObject data field // named gToolData. That's how we know how to update the status of the // toolitem later. diff --git a/src/frontends/gtk/GtkLengthEntry.C b/src/frontends/gtk/GtkLengthEntry.C index 0caa787566..948fdfabe8 100644 --- a/src/frontends/gtk/GtkLengthEntry.C +++ b/src/frontends/gtk/GtkLengthEntry.C @@ -51,7 +51,7 @@ void setWidgetsFromLength(Gtk::Adjustment & adj, Gtk::ComboBoxText & combo, LyXL if (unit.empty()) unit = getDefaultUnit(); - comboBoxTextSet(combo,unit); + combo.set_active_text (unit); } diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C index 9ced02b641..fabd52992e 100644 --- a/src/frontends/gtk/ghelpers.C +++ b/src/frontends/gtk/ghelpers.C @@ -28,6 +28,8 @@ #include "support/filetools.h" #include "support/package.h" +#include "gtkmm/icontheme.h" + #include using std::string; @@ -36,20 +38,8 @@ using std::vector; namespace lyx { namespace frontend { -// This function should be replaced by Gtk::ComboBoxText::set_active_text -// Which was introduced in gtkmm 2.6 -int comboBoxTextSet(Gtk::ComboBoxText & combo, Glib::ustring target) -{ - int const children = combo.get_model()->children().size(); - for (int i = 0; i < children; i++) { - combo.set_active(i); - if (combo.get_active_text() == target) - return 0; - } - return -1; -} - - +// Get a GTK stockID from a lyx function id. +// Return Gtk::Stock::MISSING_IMAGE if no suitable stock found Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func) { switch (func.action) { @@ -90,6 +80,42 @@ Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func) } +Gtk::Image *getGTKIcon(FuncRequest const & func, Gtk::IconSize const & size) +{ + /*static Glib::RefPtr theme; + if (!theme) + theme = Gtk::IconTheme::get_default();*/ + + Gtk::Image *image = NULL; + + Gtk::BuiltinStockID const stockID = getGTKStockIcon(func); + if (stockID != Gtk::Stock::MISSING_IMAGE) { + // Prefer stock gtk graphics + image = Gtk::manage(new Gtk::Image(stockID, size)); + } else { + /*if (func.action == LFUN_MENUNEW) { + std::cerr << "Looking for icon\n"; + std::vector icons = theme->list_icons("mimetypes"); + for (std::vector::iterator it = icons.begin(); it != icons.end(); ++it) { + std::cerr << (*it) << "\n"; + } + std::vector paths = theme->get_search_path(); + for (std::vector::iterator it = paths.begin(); it != paths.end(); ++it) { + std::cerr << (*it) << "\n"; + } + std::cerr << theme->get_example_icon_name() << "\n"; + if (theme->has_icon("table-center")) { + std::cerr << "Found icon\n"; + Glib::RefPtr pbuf = theme->load_icon("table-center", 64, Gtk::ICON_LOOKUP_USE_BUILTIN); + image = Gtk::manage(new Gtk::Image(pbuf)); + } + }*/ + } + + return image; +} + + string const getDefaultUnit() { switch (lyxrc.default_papersize) { diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h index fb8ed98049..cda3bb6c2c 100644 --- a/src/frontends/gtk/ghelpers.h +++ b/src/frontends/gtk/ghelpers.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Angus Leeming + * \author John Spray * * Full author contact details are available in file CREDITS. */ @@ -24,11 +25,9 @@ class FuncRequest; namespace lyx { namespace frontend { -int comboBoxTextSet(Gtk::ComboBoxText & combo, Glib::ustring target); - -// Get a GTK stockID from a lyx function id. -// Return Gtk::Stock::MISSING_IMAGE if no suitable stock found -Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func); +// Load an icon from GTK icon theme +// Return NULL if no suitable icon found +Gtk::Image *getGTKIcon(FuncRequest const & func, Gtk::IconSize const & size); std::string const getDefaultUnit(); -- 2.39.2