]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/Menubar_pimpl.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / Menubar_pimpl.C
index b452a101612cfe63a825a4d741687d356ca90933..2274f6a8698f3f587c90ae9d2ed06aa0ee727a7e 100644 (file)
@@ -1,9 +1,11 @@
 /**
  * \file Menubar_pimpl.C
- * Copyright 1999-2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author  Lars Gullik Bjønnes, larsbj@lyx.org
+ * \author  Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 #include "Dialogs.h"
 #include "XFormsView.h"
 #include "lyxfunc.h"
-#include "FloatList.h"
 #include "support/lstrings.h"
 #include "support/LAssert.h"
 #include "gettext.h"
 #include "debug.h"
-#include "toc.h"
 #include FORMS_H_LOCATION
 
 #include <boost/scoped_ptr.hpp>
@@ -40,7 +40,6 @@ using std::for_each;
 typedef vector<int>::size_type size_type;
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern LyXAction lyxaction;
 
 namespace {
 
@@ -93,6 +92,10 @@ Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb)
 }
 
 
+Menubar::Pimpl::~Pimpl()
+{}
+
+
 void Menubar::Pimpl::makeMenubar(Menu const & menu)
 {
        FL_FORM * form = owner_->getForm();
@@ -200,7 +203,8 @@ string const fixlabel(string const & str)
 
 
 int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
-                                  Menu const & menu, vector<int> & smn)
+                                  Menu const & menu, vector<int> & smn,
+                                  bool & all_disabled)
 {
        const int menuid = get_new_submenu(smn, win);
        lyxerr[Debug::GUI] << "Menubar::Pimpl::create_submenu: creating "
@@ -234,11 +238,12 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                if (i->kind() == MenuItem::Separator)
                        *last = "%l";
                else if (!i->optional() ||
-                        !(view->getLyXFunc()->getStatus(i->action()).disabled()))
+                        !(view->getLyXFunc().getStatus(i->action()).disabled()))
                        last = it;
 
        it = extra_labels.begin();
        size_type count = 0;
+       all_disabled = true;
        int curmenuid = menuid;
        for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it) {
                MenuItem const & item = (*i);
@@ -259,7 +264,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                switch (item.kind()) {
                case MenuItem::Command: {
                        FuncStatus const flag =
-                               view->getLyXFunc()->getStatus(item.action());
+                               view->getLyXFunc().getStatus(item.action());
                        // handle optional entries.
                        if (item.optional()
                            && (flag.disabled())) {
@@ -295,6 +300,8 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                                pupmode += "%b";
                        if (flag.disabled() || flag.unknown())
                                pupmode += "%i";
+                       else
+                               all_disabled = false;
                        label += pupmode;
 
                        // Finally the menu shortcut
@@ -318,12 +325,17 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                }
 
                case MenuItem::Submenu: {
+                       bool sub_all_disabled;
                        int submenuid = create_submenu(win, view,
-                                                      *item.submenu(), smn);
+                                                      *item.submenu(), smn,
+                                                      sub_all_disabled);
+                       all_disabled &= sub_all_disabled;
                        if (submenuid == -1)
                                return -1;
                        string label = fixlabel(item.label());
                        label += extra_label + "%m";
+                       if (sub_all_disabled)
+                               label += "%i";
                        string shortcut = item.shortcut();
                        if (!shortcut.empty()) {
                                shortcut += lowercase(shortcut[0]);
@@ -377,8 +389,10 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
        Menu const frommenu = menubackend_->getMenu(item->submenuname());
        menubackend_->expand(frommenu, tomenu, view->buffer());
        vector<int> submenus;
+       bool all_disabled = true;
        int menu = iteminfo->pimpl_->
-               create_submenu(FL_ObjWin(ob), view, tomenu, submenus);
+               create_submenu(FL_ObjWin(ob), view, tomenu,
+                              submenus, all_disabled);
        if (menu != -1) {
                // place popup
                fl_setpup_position(view->getForm()->x + ob->x,
@@ -394,7 +408,7 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
                // If the action value is too low, then it is not a
                // valid action, but something else.
                if (choice >= action_offset + 1) {
-                       view->getLyXFunc()->dispatch(choice - action_offset, true);
+                       view->getLyXFunc().dispatch(choice - action_offset, true);
                } else {
                        lyxerr[Debug::GUI]
                                << "MenuCallback: ignoring bogus action "
@@ -409,3 +423,15 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
        fl_set_tabstop(default_tabstop);
 
 }
+
+
+Menubar::Pimpl::ItemInfo::ItemInfo
+       (Menubar::Pimpl * p, MenuItem const * i, FL_OBJECT * o)
+       : pimpl_(p), obj_(o)
+{
+       item_.reset(i);
+}
+
+
+Menubar::Pimpl::ItemInfo::~ItemInfo()
+{}