From: John Spray Date: Mon, 15 Nov 2004 14:02:40 +0000 (+0000) Subject: Menu icons, gtk stock icons in toolbar X-Git-Tag: 1.6.10~14831 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6640822be5360197493f65e5cdcafdce16e84573;p=lyx.git Menu icons, gtk stock icons in toolbar git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9251 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 8d9721f039..63f3c2ede5 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,10 @@ +2004-11-15 John Spray + + * 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 * The ERT dialog: diff --git a/src/frontends/gtk/GBox.C b/src/frontends/gtk/GBox.C index d44c23ef63..1be4cfbecb 100644 --- a/src/frontends/gtk/GBox.C +++ b/src/frontends/gtk/GBox.C @@ -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 diff --git a/src/frontends/gtk/GMenubar.C b/src/frontends/gtk/GMenubar.C index bd8bd8e6f0..f015fa826e 100644 --- a/src/frontends/gtk/GMenubar.C +++ b/src/frontends/gtk/GMenubar.C @@ -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. */ @@ -12,6 +13,10 @@ #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 bigicon = + Gdk::Pixbuf::create_from_file(xpmName); + Glib::RefPtr 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)); diff --git a/src/frontends/gtk/GToolbar.C b/src/frontends/gtk/GToolbar.C index 3d420f75fe..3f9b2678fc 100644 --- a/src/frontends/gtk/GToolbar.C +++ b/src/frontends/gtk/GToolbar.C @@ -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(&const_cast(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, >oolbar::clicked), FuncRequest(func))); diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C index 79dc933e08..2527c847b1 100644 --- a/src/frontends/gtk/ghelpers.C +++ b/src/frontends/gtk/ghelpers.C @@ -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) { diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h index 6519353436..3d215fe522 100644 --- a/src/frontends/gtk/ghelpers.h +++ b/src/frontends/gtk/ghelpers.h @@ -19,9 +19,15 @@ #include #include +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,