]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiMenubar.cpp
Free GuiPopupMenu from GuiMenubar.
[lyx.git] / src / frontends / qt4 / GuiMenubar.cpp
index 0bfd6a2fd6dc3a70a118980a8f9f53c7bd2b2a1a..5f3ee781643adc0aee2f56ad0d7059582aa1cae2 100644 (file)
 #include "GuiPopupMenu.h"
 
 #include "qt_helpers.h"
-#include "support/lstrings.h"
 
 #include "MenuBackend.h"
 
-#include "debug.h"
+#include "support/debug.h"
 
 #include <QCursor>
 #include <QMenuBar>
 
-using std::pair;
-using std::string;
-using std::endl;
 
 namespace lyx {
 namespace frontend {
 
 // MacOSX specific stuff is at the end.
 
-GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
-       : owner_(static_cast<GuiViewBase*>(view)), menubackend_(mbe)
+GuiMenubar::GuiMenubar(GuiView * view, MenuBackend & mbe)
+       : owner_(view), menubackend_(mbe)
 {
+       init();
+}
+
+
+void GuiMenubar::init()
+{
+       // Clear all menubar contents before filling it.
+       owner_->menuBar()->clear();
+       
+       // setup special mac specific menu item
        macxMenuBarInit();
 
-       LYXERR(Debug::GUI) << "populating menu bar" << to_utf8(menubackend_.getMenubar().name()) << endl;
+       LYXERR(Debug::GUI, "populating menu bar" << to_utf8(menubackend_.getMenubar().name()));
 
        if (menubackend_.getMenubar().size() == 0) {
-               LYXERR(Debug::GUI) << "\tERROR: empty menu bar"
-                       << to_utf8(menubackend_.getMenubar().name()) << endl;
+               LYXERR(Debug::GUI, "\tERROR: empty menu bar"
+                       << to_utf8(menubackend_.getMenubar().name()));
                return;
                //                      continue;
        }
        else {
-               LYXERR(Debug::GUI) << "menu bar entries "
-                       << menubackend_.getMenubar().size();
+               LYXERR(Debug::GUI, "menu bar entries "
+                       << menubackend_.getMenubar().size());
        }
 
        Menu menu;
@@ -64,25 +70,24 @@ GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
        for (; m != end; ++m) {
 
                if (m->kind() != MenuItem::Submenu) {
-                       LYXERR(Debug::GUI) << "\tERROR: not a submenu "
-                               << to_utf8(m->label()) << endl;
+                       LYXERR(Debug::GUI, "\tERROR: not a submenu " << to_utf8(m->label()));
                        continue;
                }
 
-               LYXERR(Debug::GUI) << "menu bar item " << to_utf8(m->label())
-                       << " is a submenu named " << to_utf8(m->submenuname()) << endl;
+               LYXERR(Debug::GUI, "menu bar item " << to_utf8(m->label())
+                       << " is a submenu named " << to_utf8(m->submenuname()));
 
                docstring name = m->submenuname();
                if (!menubackend_.hasMenu(name)) {
-                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
-                               << " submenu has no menu!" << endl;
+                       LYXERR(Debug::GUI, "\tERROR: " << to_utf8(name)
+                               << " submenu has no menu!");
                        continue;
                }
 
                Menu menu;
                menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
 
-               GuiPopupMenu * qMenu = new GuiPopupMenu(this, *m, true);
+               GuiPopupMenu * qMenu = new GuiPopupMenu(owner_, *m, true);
                owner_->menuBar()->addMenu(qMenu);
 
                name_map_[toqstr(name)] = qMenu;
@@ -96,6 +101,12 @@ GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
 }
 
 
+GuiMenubar::~GuiMenubar() {
+#ifdef Q_WS_MACX
+       delete mac_menubar_;
+#endif
+}
+
 void GuiMenubar::openByName(QString const & name)
 {
        if (QMenu * menu = name_map_.value(name))
@@ -142,9 +153,8 @@ extern void qt_mac_set_menubar_merge(bool b);
 void GuiMenubar::macxMenuBarInit()
 {
 #ifdef Q_WS_MACX
-       mac_menubar_.reset(new QMenuBar);
+       mac_menubar_ = new QMenuBar;
 
-# if QT_VERSION >= 0x040200
        /* Since Qt 4.2, the qt/mac menu code has special code for
           specifying the role of a menu entry. However, it does not
           work very well with our scheme of creating menus on demand,
@@ -198,15 +208,13 @@ void GuiMenubar::macxMenuBarInit()
        Menu::const_iterator cit = menubackend_.specialMenu().begin();
        Menu::const_iterator end = menubackend_.specialMenu().end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-               Action * action = new Action(*owner_, cit->label(),
-                                            cit->func());
+               Action * action = new Action(*owner_, QIcon(), 
+                                            toqstr(cit->label()),
+                                            cit->func(), QString());
                action->setMenuRole(entries[i].role);
                qMenu->addAction(action);
 
        }
-# else
-       qt_mac_set_menubar_merge(false);
-# endif // QT_VERSION >= 0x040200
 #endif // Q_WS_MACX
 }