2002-06-19 05:20:29 +00:00
|
|
|
/**
|
2003-07-25 21:34:45 +00:00
|
|
|
* \file qt2/QLMenubar.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 05:20:29 +00:00
|
|
|
*
|
2003-07-25 21:34:45 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-19 05:20:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
// Qt defines a macro 'signals' that clashes with a boost namespace.
|
|
|
|
// All is well if the namespace is visible first.
|
2002-06-19 05:20:29 +00:00
|
|
|
#include "QtView.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
#include "QLMenubar.h"
|
2002-08-25 18:26:45 +00:00
|
|
|
#include "QLPopupMenu.h"
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "MenuBackend.h"
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
#include <qmenubar.h>
|
2002-09-12 02:10:19 +00:00
|
|
|
#include <qcursor.h>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-09-12 02:10:19 +00:00
|
|
|
using std::pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-08-14 18:06:10 +00:00
|
|
|
QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
|
2002-06-21 16:40:54 +00:00
|
|
|
: owner_(static_cast<QtView*>(view)), menubackend_(mbe)
|
2004-06-09 14:10:27 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
, menubar_(new QMenuBar)
|
|
|
|
#endif
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
2002-07-21 01:38:24 +00:00
|
|
|
Menu::const_iterator m = mbe.getMenubar().begin();
|
|
|
|
Menu::const_iterator end = mbe.getMenubar().end();
|
|
|
|
for (; m != end; ++m) {
|
2002-09-12 02:10:19 +00:00
|
|
|
pair<int, QLPopupMenu *> menu =
|
2004-06-09 14:10:27 +00:00
|
|
|
createMenu(menuBar(), &(*m), this, true);
|
2002-09-12 02:10:19 +00:00
|
|
|
name_map_[m->submenuname()] = menu.second;
|
2004-08-14 18:06:10 +00:00
|
|
|
}
|
2004-01-15 16:07:17 +00:00
|
|
|
#ifdef Q_WS_MACX
|
2004-08-14 18:06:10 +00:00
|
|
|
// this is the name of the menu that contains our special entries
|
|
|
|
menubackend_.specialMenu("LyX");
|
|
|
|
// make sure that the special entries are added to the first
|
|
|
|
// menu even before this menu has been opened.
|
|
|
|
name_map_[mbe.getMenubar().begin()->submenuname()]->showing();
|
2003-07-10 14:39:38 +00:00
|
|
|
#endif
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
void QLMenubar::openByName(string const & name)
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
2002-09-24 13:57:09 +00:00
|
|
|
NameMap::const_iterator const cit = name_map_.find(name);
|
|
|
|
if (cit == name_map_.end())
|
2002-09-12 02:10:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// this will have to do I'm afraid.
|
|
|
|
cit->second->exec(QCursor::pos());
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
2003-05-14 09:17:22 +00:00
|
|
|
|
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
void QLMenubar::update()
|
2003-05-14 09:17:22 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
QtView * QLMenubar::view()
|
2003-05-14 09:17:22 +00:00
|
|
|
{
|
|
|
|
return owner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
MenuBackend const & QLMenubar::backend()
|
2003-05-14 09:17:22 +00:00
|
|
|
{
|
|
|
|
return menubackend_;
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
2004-06-09 14:10:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Here is what the Qt documentation says about how a menubar is chosen:
|
|
|
|
|
|
|
|
1) If the window has a QMenuBar then it is used. 2) If the window
|
|
|
|
is a modal then its menubar is used. If no menubar is specified
|
|
|
|
then a default menubar is used (as documented below) 3) If the
|
|
|
|
window has no parent then the default menubar is used (as
|
|
|
|
documented below).
|
|
|
|
|
|
|
|
The above 3 steps are applied all the way up the parent window
|
|
|
|
chain until one of the above are satisifed. If all else fails a
|
|
|
|
default menubar will be created, the default menubar on Qt/Mac is
|
|
|
|
an empty menubar, however you can create a different default
|
|
|
|
menubar by creating a parentless QMenuBar, the first one created
|
|
|
|
will thus be designated the default menubar, and will be used
|
|
|
|
whenever a default menubar is needed.
|
|
|
|
|
|
|
|
Thus, for Qt/Mac, we add the menus to a free standing menubar, so
|
|
|
|
that this menubar will be used also when one of LyX' dialogs has
|
|
|
|
focus. (JMarc)
|
|
|
|
*/
|
|
|
|
QMenuBar * QLMenubar::menuBar() const
|
|
|
|
{
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
return menubar_.get();
|
|
|
|
#else
|
|
|
|
return owner_->menuBar();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|