]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QLMenubar.C
Extracted from r14281
[lyx.git] / src / frontends / qt3 / QLMenubar.C
1 /**
2  * \file qt3/QLMenubar.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Qt defines a macro 'signals' that clashes with a boost namespace.
14 // All is well if the namespace is visible first.
15 #include "QtView.h"
16
17 #include "QLMenubar.h"
18 #include "QLPopupMenu.h"
19
20 #include "MenuBackend.h"
21
22 #include <qmenubar.h>
23 #include <qcursor.h>
24
25 using std::pair;
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
32         : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
33 #ifdef Q_WS_MACX
34         , menubar_(new QMenuBar)
35 #endif
36 {
37         Menu::const_iterator m = mbe.getMenubar().begin();
38         Menu::const_iterator end = mbe.getMenubar().end();
39         for (; m != end; ++m) {
40                 pair<int, QLPopupMenu *> menu =
41                         createMenu(menuBar(), &(*m), this, true);
42                 name_map_[m->submenuname()] = menu.second;
43         }
44 #ifdef Q_WS_MACX
45         // this is the name of the menu that contains our special entries
46         menubackend_.specialMenu("LyX");
47         // make sure that the special entries are added to the first
48         // menu even before this menu has been opened.
49         name_map_[mbe.getMenubar().begin()->submenuname()]->showing();
50 #endif
51 }
52
53 void QLMenubar::openByName(string const & name)
54 {
55         NameMap::const_iterator const cit = name_map_.find(name);
56         if (cit == name_map_.end())
57                 return;
58
59         // this will have to do I'm afraid.
60         cit->second->exec(QCursor::pos());
61 }
62
63
64 void QLMenubar::update()
65 {}
66
67
68 QtView * QLMenubar::view()
69 {
70         return owner_;
71 }
72
73
74 MenuBackend const & QLMenubar::backend()
75 {
76         return menubackend_;
77 }
78
79
80 /*
81   Here is what the Qt documentation says about how a menubar is chosen:
82
83      1) If the window has a QMenuBar then it is used. 2) If the window
84      is a modal then its menubar is used. If no menubar is specified
85      then a default menubar is used (as documented below) 3) If the
86      window has no parent then the default menubar is used (as
87      documented below).
88
89      The above 3 steps are applied all the way up the parent window
90      chain until one of the above are satisifed. If all else fails a
91      default menubar will be created, the default menubar on Qt/Mac is
92      an empty menubar, however you can create a different default
93      menubar by creating a parentless QMenuBar, the first one created
94      will thus be designated the default menubar, and will be used
95      whenever a default menubar is needed.
96
97   Thus, for Qt/Mac, we add the menus to a free standing menubar, so
98   that this menubar will be used also when one of LyX' dialogs has
99   focus. (JMarc)
100 */
101 QMenuBar * QLMenubar::menuBar() const
102 {
103 #ifdef Q_WS_MAC
104         return menubar_.get();
105 #else
106         return owner_->menuBar();
107 #endif
108 }
109
110 } // namespace frontend
111 } // namespace lyx