]> git.lyx.org Git - lyx.git/commitdiff
Rearrange GTK icon lookup code, get rid of comboBoxTextSet 1.4.0pre5
authorJohn Spray <spray@lyx.org>
Sun, 12 Feb 2006 23:58:29 +0000 (23:58 +0000)
committerJohn Spray <spray@lyx.org>
Sun, 12 Feb 2006 23:58:29 +0000 (23:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13220 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/gtk/ChangeLog
src/frontends/gtk/GDocument.C
src/frontends/gtk/GMenubar.C
src/frontends/gtk/GToolbar.C
src/frontends/gtk/GtkLengthEntry.C
src/frontends/gtk/ghelpers.C
src/frontends/gtk/ghelpers.h

index c006c360c80f43c95e94b6f847eb0f9a3876c20a..98e3b54af36cd474e5089526e832c725fdce2f7f 100644 (file)
@@ -1,5 +1,10 @@
 2006-02-12  John Spray  <spray@lyx.org>
        * 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  <bartek@runbox.com>
        * GMenubar.C: Fix crash with navigation submenus
index c9c253b786003c8515c7b140a4fe5274095f2c4f..08a8836e9bf966fe2f9e376d192b552eaa17392e 100644 (file)
@@ -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);
index 9084dc7b6ccc05446f2cfb46fdab12200cbdf5a0..15bc466f47313a930a7be4df2c0ed228404a4e1b 100644 (file)
@@ -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) {
index 4536f09799c561bae70f44f595e91ef447ad3054..23f3e1609000df07864a155b0c5d50ff434c0600 100644 (file)
@@ -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.
index 0caa787566724319434f1d8e3f5fd8379bd5e4bf..948fdfabe8391988471cccf461ceb5699cde7d0f 100644 (file)
@@ -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);
 }
 
 
index 9ced02b6410b0b07f1c6d204a36f9802696915d4..fabd52992e2d63357403c9a1bca06f5251be7106 100644 (file)
@@ -28,6 +28,8 @@
 #include "support/filetools.h"
 #include "support/package.h"
 
+#include "gtkmm/icontheme.h"
+
 #include <sstream>
 
 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<Gtk::IconTheme> 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<Glib::ustring> icons = theme->list_icons("mimetypes");
+                               for (std::vector<Glib::ustring>::iterator it = icons.begin(); it != icons.end(); ++it) {
+                                       std::cerr << (*it) << "\n";
+                               }
+                               std::vector<Glib::ustring> paths = theme->get_search_path();
+                               for (std::vector<Glib::ustring>::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<Gdk::Pixbuf> 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) {
index fb8ed98049cda2cd832f28a6763657289c5a6add..cda3bb6c2c0f811428f37ef228bd8b58b5634854 100644 (file)
@@ -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();