2 * \file qt2/QLMenubar.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Qt defines a macro 'signals' that clashes with a boost namespace.
14 // All is well if the namespace is visible first.
17 #include "QLMenubar.h"
18 #include "QLPopupMenu.h"
20 #include "qt_helpers.h"
21 #include "support/lstrings.h"
23 #include "MenuBackend.h"
24 #include "support/lstrings.h"
30 #include "QLyXKeySym.h"
31 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
50 // MacOSX specific stuff is at the end.
52 QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
53 : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
57 lyxerr[Debug::GUI] << "populating menu bar" << menubackend_.getMenubar().name() << endl;
59 if (menubackend_.getMenubar().size() == 0) {
60 lyxerr[Debug::GUI] << "\tERROR: empty menu bar" << menubackend_.getMenubar().name() << endl;
65 lyxerr[Debug::GUI] << "menu bar entries " << menubackend_.getMenubar().size();
67 // for (; m != end; ++m) {
70 menubackend_.expand(menubackend_.getMenubar(), menu, owner_);
72 Menu::const_iterator m = menu.begin();
73 Menu::const_iterator end = menu.end();
75 for (; m != end; ++m) {
77 if (m->kind() != MenuItem::Submenu) {
78 lyxerr[Debug::GUI] << "\tERROR: not a submenu " << m->label() << endl;
82 lyxerr[Debug::GUI] << "menu bar item " << m->label() << " is a submenu named " << m->submenuname() << endl;
84 string name = m->submenuname();
85 if (!menubackend_.hasMenu(name)) {
86 lyxerr[Debug::GUI] << "\tERROR: " << name << " submenu has no menu!" << endl;
91 menubackend_.expand(menubackend_.getMenubar(), menu, owner_);
93 QLPopupMenu * qMenu = new QLPopupMenu(this, *m, true);
94 owner_->menuBar()->addMenu(qMenu);
96 pair<NameMap::iterator, bool> I = name_map_.insert(make_pair(name, qMenu));
98 lyxerr[Debug::GUI] << "\tERROR: " << name << " submenu is already there!" << endl;
101 QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
102 QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
103 QObject::connect(qMenu->menuAction(), SIGNAL(triggered()), this, SLOT(update()));
106 //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
109 void QLMenubar::openByName(string const & name)
111 NameMap::const_iterator const cit = name_map_.find(name);
112 if (cit == name_map_.end())
115 // I (Abdel) don't understand this comment:
116 // this will have to do I'm afraid.
117 cit->second->exec(QCursor::pos());
121 void QLMenubar::update()
124 QtView * QLMenubar::view()
130 MenuBackend const & QLMenubar::backend()
137 Here is what the Qt documentation says about how a menubar is chosen:
139 1) If the window has a QMenuBar then it is used. 2) If the window
140 is a modal then its menubar is used. If no menubar is specified
141 then a default menubar is used (as documented below) 3) If the
142 window has no parent then the default menubar is used (as
145 The above 3 steps are applied all the way up the parent window
146 chain until one of the above are satisifed. If all else fails a
147 default menubar will be created, the default menubar on Qt/Mac is
148 an empty menubar, however you can create a different default
149 menubar by creating a parentless QMenuBar, the first one created
150 will thus be designated the default menubar, and will be used
151 whenever a default menubar is needed.
153 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
154 that this menubar will be used also when one of LyX' dialogs has
157 QMenuBar * QLMenubar::menuBar() const
160 return menubar_.get();
162 return owner_->menuBar();
166 void QLMenubar::macxMenuBarInit()
169 menubar_ = new QMenuBar;
171 // this is the name of the menu that contains our special entries
172 menubackend_.specialMenu("LyX");
173 // make sure that the special entries are added to the first
174 // menu even before this menu has been opened.
175 name_map_[menubackend_.getMenubar().begin()->submenuname()]->showing();
179 } // namespace frontend