* 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>
-#include <gtkmm.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"
using std::string;
+namespace lyx {
+namespace frontend {
+
namespace
{
-class LyxMenu : public Gtk::Menu
-{
+class LyxMenu : public Gtk::Menu {
public:
LyxMenu() { menu_.reset(new ::Menu); }
void ClearMenu(Gtk::MenuShell * menu)
{
- Gtk::Menu_Helpers::MenuList::iterator m, end;
- m = menu->items().begin();
- end = menu->items().end();
+ Gtk::Menu_Helpers::MenuList::iterator m = menu->items().begin();
+ Gtk::Menu_Helpers::MenuList::iterator end = menu->items().end();
Gtk::Menu * subMenu;
for (; m != end; ++m) {
if ((subMenu = m->get_submenu()) != 0) {
}
-GMenubar::GMenubar(LyXView *lyxView, MenuBackend const & /*menuBackend*/) :
+GMenubar::GMenubar(LyXView * lyxView, MenuBackend const & /*menuBackend*/) :
view_(lyxView)
{
GView * gview = static_cast<GView*>(lyxView);
- Gtk::VBox& vbox = gview->getVBox();
Menu const & menu = menubackend.getMenubar();
Menu::const_iterator i = menu.begin();
Menu::const_iterator end = menu.end();
labelTrans(i->label(), i->shortcut()),
*gmenu));
menubar_.items().back().signal_activate().connect(
- SigC::bind(SigC::slot(*this, &GMenubar::onSubMenuActivate), &(*i),
+ sigc::bind(sigc::mem_fun(*this, &GMenubar::onSubMenuActivate), &(*i),
&menubar_.items().back()));
mainMenuNames_.push_back(i->submenuname());
}
menubar_.show();
- vbox.children().push_back(Gtk::Box_Helpers::Element(menubar_,
- Gtk::PACK_SHRINK));
+ gview->getBox(GView::Top).children().push_back(
+ Gtk::Box_Helpers::Element(menubar_, Gtk::PACK_SHRINK));
}
}
-bool GMenubar::submenuDisabled(MenuItem const * item)
-{
- Menu & from = menubackend.getMenu(item->submenuname());
- Menu to;
- menubackend.expand(from, to, view_);
- Menu::const_iterator i = to.begin();
- Menu::const_iterator end = to.end();
- for (; i != end; ++i) {
- switch (i->kind()) {
- case MenuItem::Submenu:
- if (!submenuDisabled(&(*i)))
- return false;
- break;
- case MenuItem::Command:
- {
- FuncStatus const flag =
- view_->getLyXFunc().getStatus(i->func());
- if (flag.enabled())
- return false;
- break;
- }
- default:
- break;
- }
- }
- return true;
-}
-
-
void GMenubar::onSubMenuActivate(MenuItem const * item,
Gtk::MenuItem * gitem)
{
ClearMenu(gmenu);
LyxMenu * lyxmenu = static_cast<LyxMenu*>(gmenu);
lyxmenu->clearBackMenu();
- Menu * fmenu = &menubackend.getMenu(item->submenuname());
+ Menu * fmenu = item->submenuname().empty() ?
+ 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();
labelTrans(i->label(), i->shortcut()),
*gmenu_new));
gmenu->items().back().signal_activate().connect(
- SigC::bind(SigC::slot(*this, &GMenubar::onSubMenuActivate),
+ sigc::bind(sigc::mem_fun(*this, &GMenubar::onSubMenuActivate),
&(*i),
&gmenu->items().back()));
- if (submenuDisabled(&(*i)))
+ if (!i->status().enabled())
gmenu->items().back().set_sensitive(false);
break;
case MenuItem::Command:
{
-#ifdef WITH_WARNINGS
-#warning Bindings are not inserted into the menu labels here. (Lgb)
-#endif
- FuncStatus const flag =
- view_->getLyXFunc().getStatus(i->func());
+ FuncStatus const flag = i->status();
bool on = flag.onoff(true);
bool off = flag.onoff(false);
gmenu->items().back());
citem.set_active(on);
} else {
- gmenu->items().push_back(
- Gtk::Menu_Helpers::MenuElem(
- labelTrans(i->label(),
- i->shortcut())));
+ // 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::HBox * hbox = Gtk::manage(new Gtk::HBox);
+ Gtk::Label * label1 = Gtk::manage(new Gtk::Label(
+ labelTrans(i->label(), i->shortcut()), true));
+ Gtk::Label * label2 = Gtk::manage(new Gtk::Label(
+ " " + i->binding(), false));
+ hbox->pack_start(*label1, false, false, 0);
+ hbox->pack_end(*label2, false, false, 0);
+ item->add(*hbox);
+
+ gmenu->append(*item);
+ item->show_all();
}
Gtk::MenuItem & item = gmenu->items().back();
item.signal_activate().connect(
- SigC::bind(SigC::slot(*this, &GMenubar::onCommandActivate),
+ sigc::bind(sigc::mem_fun(*this, &GMenubar::onCommandActivate),
&(*i), &item));
if (!flag.enabled())
item.set_sensitive(false);
void GMenubar::onCommandActivate(MenuItem const * item,
Gtk::MenuItem * /*gitem*/)
{
- view_->getLyXFunc().dispatch(item->func(), true);
+ view_->getLyXFunc().dispatch(item->func());
}
+
+} // namespace frontend
+} // namespace lyx