]> git.lyx.org Git - lyx.git/commitdiff
Menu icons, gtk stock icons in toolbar
authorJohn Spray <spray@lyx.org>
Mon, 15 Nov 2004 14:02:40 +0000 (14:02 +0000)
committerJohn Spray <spray@lyx.org>
Mon, 15 Nov 2004 14:02:40 +0000 (14:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9251 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/gtk/ChangeLog
src/frontends/gtk/GBox.C
src/frontends/gtk/GMenubar.C
src/frontends/gtk/GToolbar.C
src/frontends/gtk/ghelpers.C
src/frontends/gtk/ghelpers.h

index 8d9721f039c289d10442b07937738264d350c721..63f3c2ede5c81b11b644aa43e7672585f3bc2da2 100644 (file)
@@ -1,3 +1,10 @@
+2004-11-15  John Spray  <spray_john@users.sourceforge.net>
+
+       * ghelpers.[Ch]: getGTKStockIcon added to choose gtk
+               stock icons for FuncRequests
+       * GToolbar.C: use getGTKStockIcon for toolbutton icons
+       * GMenubar.C: add icons to menu items
+
 2004-11-14  John Spray  <spray_john@users.sourceforge.net>
 
        * The ERT dialog:
index d44c23ef639cb4f1c0b1da105410ac48f8beffcf..1be4cfbecb92948665e5c717c599dbf25f691bb5 100644 (file)
@@ -285,10 +285,10 @@ void GBox::updateInnerBoxCombo()
                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);
+               else
+                       innerboxcombo_->set_active(i);
        }
 
        // Update the width units list if we've changed inner box type
index bd8bd8e6f0f47a1a747f2043b29ef4e2b1955656..f015fa826e10f02a48b6c36163d144e98a7a4fa1 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Huang Ying
+ * \author John Spray
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GMenubar.h"
 #include "GView.h"
+#include "ghelpers.h"
+
+#include "ToolbarBackend.h" // for getIcon
+
 #include "debug.h"
 #include "lyxfunc.h"
 
@@ -133,6 +138,11 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
                item->submenu() :
                &menubackend.getMenu(item->submenuname());
 
+       // Choose size for icons on command items
+       int iconwidth = 16;
+       int iconheight = 16;
+       Gtk::IconSize::lookup(Gtk::ICON_SIZE_MENU, iconwidth, iconheight);
+
        menubackend.expand(*fmenu, lyxmenu->getBackMenu(), view_);
        Menu::const_iterator i = lyxmenu->getBackMenu().begin();
        Menu::const_iterator end = lyxmenu->getBackMenu().end();
@@ -168,10 +178,32 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
                                                gmenu->items().back());
                                citem.set_active(on);
                        } else {
-                               // This is necessary because add_accel_label is protected,
+                               // 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 {
+                                       Glib::ustring xpmName =
+                                               Glib::locale_to_utf8(toolbarbackend.getIcon(i->func()));
+                                       if (xpmName.find("unknown.xpm") == -1) {
+                                               // Load icon and shrink it for menu size
+                                               Glib::RefPtr<Gdk::Pixbuf> bigicon =
+                                                       Gdk::Pixbuf::create_from_file(xpmName);
+                                               Glib::RefPtr<Gdk::Pixbuf> smallicon =
+                                                       bigicon->scale_simple(iconwidth,iconheight,Gdk::INTERP_TILES);
+                                               image = Gtk::manage(new Gtk::Image(smallicon));
+                                       }
+                               }
+
+                               Gtk::ImageMenuItem * item = Gtk::manage(new Gtk::ImageMenuItem);
+                               if (image)
+                                       item->set_image(*image);
+
+                               // This hbox is necessary because add_accel_label is protected,
                                // and even if you subclass Gtk::MenuItem then add_accel_label
                                // doesn't do what you'd expect.
-                               Gtk::MenuItem * item = Gtk::manage(new Gtk::MenuItem);
                                Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox);
                                Gtk::Label * label1 = Gtk::manage(new Gtk::Label(
                                        labelTrans(i->label(), i->shortcut()), true));
index 3d420f75fe995cd53d4dbf513ed75b3cdca828b2..3f9b2678fc9b3554d5dad732b10da76f83a40cc0 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Huang Ying
+ * \author John Spray
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -13,6 +14,8 @@
 #include "GToolbar.h"
 #include "GView.h"
 
+#include "ghelpers.h"
+
 #include "buffer.h"
 #include "bufferparams.h"
 #include "debug.h"
@@ -219,17 +222,26 @@ void GToolbar::add(FuncRequest const & func, string const & tooltip)
        }
 
        default: {
-               Glib::ustring xpmName =
-                       Glib::locale_to_utf8(toolbarbackend.getIcon(func));
+               // choose an icon from the funcrequest
+               Gtk::BuiltinStockID stockID = getGTKStockIcon(func);
+
                Glib::ustring tip = Glib::locale_to_utf8(tooltip);
+
                Gtk::ToolButton * toolbutton;
-               if (xpmName.size() == 0) {
-                       toolbutton = Gtk::manage(new Gtk::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 {
+                       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));
                }
+
                // 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.
@@ -237,7 +249,6 @@ void GToolbar::add(FuncRequest const & func, string const & tooltip)
                        reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
 
                toolbutton->set_tooltip(*toolbar_.get_tooltips_object(),tip);
-               /*toolbar_.get_tooltips_object()->set_tip(*toolbutton, tip);*/
 
                toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
                        &GToolbar::clicked), FuncRequest(func)));
index 79dc933e082a374f7d88bd26e826291beff4d61f..2527c847b151472fd146978b6f735a447c3bc804 100644 (file)
@@ -4,6 +4,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.
  */
@@ -13,6 +14,7 @@
 #include "ghelpers.h"
 
 #include "lyxrc.h"
+#include "funcrequest.h"
 #include "debug.h"
 
 #include "support/filetools.h"
@@ -24,6 +26,44 @@ using std::vector;
 namespace lyx {
 namespace frontend {
 
+Gtk::BuiltinStockID getGTKStockIcon(FuncRequest const & func)
+{
+       switch (func.action) {
+
+               case LFUN_MENUWRITE: return Gtk::Stock::SAVE;
+               case LFUN_MENUNEW: return Gtk::Stock::NEW;
+               case LFUN_WRITEAS: return Gtk::Stock::SAVE_AS;
+
+               case LFUN_CENTER: return Gtk::Stock::JUSTIFY_CENTER;
+               case LFUN_TOCVIEW: return Gtk::Stock::INDEX;
+               case LFUN_CLOSEBUFFER: return Gtk::Stock::CLOSE;
+               case LFUN_QUIT: return Gtk::Stock::QUIT;
+               case LFUN_UNDO: return Gtk::Stock::UNDO;
+               case LFUN_REDO: return Gtk::Stock::REDO;
+               case LFUN_PASTE: return Gtk::Stock::PASTE;
+               case LFUN_PASTESELECTION: return Gtk::Stock::PASTE;
+               case LFUN_CUT: return Gtk::Stock::CUT;
+               case LFUN_COPY: return Gtk::Stock::COPY;
+               case LFUN_BOLD: return Gtk::Stock::BOLD;
+               case LFUN_ITAL: return Gtk::Stock::ITALIC;
+               case LFUN_FILE_OPEN: return Gtk::Stock::OPEN;
+               case LFUN_RECONFIGURE: return Gtk::Stock::REFRESH;
+               case LFUN_DIALOG_SHOW:
+                       if (func.argument == "findreplace")
+                               return Gtk::Stock::FIND_AND_REPLACE;
+                       else if (func.argument == "print")
+                               return Gtk::Stock::PRINT;
+                       else if (func.argument == "spellchecker")
+                               return Gtk::Stock::SPELL_CHECK;
+                       else if (func.argument == "prefs")
+                               return Gtk::Stock::PREFERENCES;
+                       else
+                               return Gtk::Stock::MISSING_IMAGE;
+                       break;
+               default: return Gtk::Stock::MISSING_IMAGE;
+       }
+}
+
 string const getDefaultUnit()
 {
        switch (lyxrc.default_papersize) {
index 6519353436ef4d71b2943c1e2fb24e59ae873788..3d215fe522ac65ee82a8156d2d78f868c0310b8b 100644 (file)
 #include <string>
 #include <vector>
 
+class FuncRequest;
+
 namespace lyx {
 namespace frontend {
 
+// 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);
+
 std::string const getDefaultUnit();
 
 void unitsComboFromLength(Gtk::ComboBox * combo,