]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gtk/GMenubar.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / gtk / GMenubar.C
index 646947f47a1043d26e7a4db7d0736dc38d0f3505..76a679d455fe4a6847cefe5eb21df1529d0dabbb 100644 (file)
@@ -4,14 +4,24 @@
  * 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 <config.h>
 
+// Too hard to make concept checks work with this file
+#ifdef _GLIBCPP_CONCEPT_CHECKS
+#undef _GLIBCPP_CONCEPT_CHECKS
+#endif
+
 #include "GMenubar.h"
 #include "GView.h"
+#include "ghelpers.h"
+
+#include "ToolbarBackend.h" // for getIcon
+
 #include "debug.h"
 #include "lyxfunc.h"
 
@@ -133,6 +143,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 +183,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));
@@ -208,7 +245,7 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
 void GMenubar::onCommandActivate(MenuItem const * item,
                                       Gtk::MenuItem * /*gitem*/)
 {
-       view_->getLyXFunc().dispatch(item->func(), true);
+       view_->getLyXFunc().dispatch(item->func());
 }
 
 } // namespace frontend