2 * \file qt4/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"
43 // MacOSX specific stuff is at the end.
45 QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
46 : owner_(static_cast<GuiView*>(view)), menubackend_(mbe)
50 lyxerr[Debug::GUI] << "populating menu bar" << menubackend_.getMenubar().name() << endl;
52 if (menubackend_.getMenubar().size() == 0) {
53 lyxerr[Debug::GUI] << "\tERROR: empty menu bar" << menubackend_.getMenubar().name() << endl;
58 lyxerr[Debug::GUI] << "menu bar entries " << menubackend_.getMenubar().size();
60 // for (; m != end; ++m) {
63 menubackend_.expand(menubackend_.getMenubar(), menu, owner_);
65 Menu::const_iterator m = menu.begin();
66 Menu::const_iterator end = menu.end();
68 for (; m != end; ++m) {
70 if (m->kind() != MenuItem::Submenu) {
71 lyxerr[Debug::GUI] << "\tERROR: not a submenu " << m->label() << endl;
75 lyxerr[Debug::GUI] << "menu bar item " << m->label() << " is a submenu named " << m->submenuname() << endl;
77 string name = m->submenuname();
78 if (!menubackend_.hasMenu(name)) {
79 lyxerr[Debug::GUI] << "\tERROR: " << name << " submenu has no menu!" << endl;
84 menubackend_.expand(menubackend_.getMenubar(), menu, owner_);
86 QLPopupMenu * qMenu = new QLPopupMenu(this, *m, true);
87 owner_->menuBar()->addMenu(qMenu);
89 pair<NameMap::iterator, bool> I = name_map_.insert(make_pair(name, qMenu));
91 lyxerr[Debug::GUI] << "\tERROR: " << name << " submenu is already there!" << endl;
94 QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
95 QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
96 QObject::connect(qMenu->menuAction(), SIGNAL(triggered()), this, SLOT(update()));
99 //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
102 void QLMenubar::openByName(string const & name)
104 NameMap::const_iterator const cit = name_map_.find(name);
105 if (cit == name_map_.end())
108 // I (Abdel) don't understand this comment:
109 // this will have to do I'm afraid.
110 cit->second->exec(QCursor::pos());
114 void QLMenubar::update()
117 GuiView * QLMenubar::view()
123 MenuBackend const & QLMenubar::backend()
130 Here is what the Qt documentation says about how a menubar is chosen:
132 1) If the window has a QMenuBar then it is used. 2) If the window
133 is a modal then its menubar is used. If no menubar is specified
134 then a default menubar is used (as documented below) 3) If the
135 window has no parent then the default menubar is used (as
138 The above 3 steps are applied all the way up the parent window
139 chain until one of the above are satisifed. If all else fails a
140 default menubar will be created, the default menubar on Qt/Mac is
141 an empty menubar, however you can create a different default
142 menubar by creating a parentless QMenuBar, the first one created
143 will thus be designated the default menubar, and will be used
144 whenever a default menubar is needed.
146 Thus, for Qt/Mac, we add the menus to a free standing menubar, so
147 that this menubar will be used also when one of LyX' dialogs has
150 QMenuBar * QLMenubar::menuBar() const
153 return mac_menubar_.get();
155 return owner_->menuBar();
159 void QLMenubar::macxMenuBarInit()
162 mac_menubar_.reset(new QMenuBar);
164 // this is the name of the menu that contains our special entries
165 menubackend_.specialMenu("LyX");
166 // make sure that the special entries are added to the first
167 // menu even before this menu has been opened.
168 //name_map_[menubackend_.getMenubar().begin()->submenuname()]->update();
172 } // namespace frontend
175 #include "QLMenubar_moc.cpp"