]> git.lyx.org Git - features.git/blob - src/frontends/qt3/QLMenubar.C
Change MenuBackend and the other menuclasses to store a docstring. Do the required...
[features.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 lyx::docstring;
26
27 using std::pair;
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
34         : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
35 #ifdef Q_WS_MACX
36         , menubar_(new QMenuBar)
37 #endif
38 {
39         Menu::const_iterator m = mbe.getMenubar().begin();
40         Menu::const_iterator end = mbe.getMenubar().end();
41         for (; m != end; ++m) {
42                 pair<int, QLPopupMenu *> menu =
43                         createMenu(menuBar(), &(*m), this, true);
44                 name_map_[m->submenuname()] = menu.second;
45         }
46 #ifdef Q_WS_MACX
47         // this is the name of the menu that contains our special entries
48         menubackend_.specialMenu("LyX");
49         // make sure that the special entries are added to the first
50         // menu even before this menu has been opened.
51         name_map_[mbe.getMenubar().begin()->submenuname()]->showing();
52 #endif
53 }
54
55 void QLMenubar::openByName(docstring const & name)
56 {
57         NameMap::const_iterator const cit = name_map_.find(name);
58         if (cit == name_map_.end())
59                 return;
60
61         // this will have to do I'm afraid.
62         cit->second->exec(QCursor::pos());
63 }
64
65
66 void QLMenubar::update()
67 {}
68
69
70 QtView * QLMenubar::view()
71 {
72         return owner_;
73 }
74
75
76 MenuBackend const & QLMenubar::backend()
77 {
78         return menubackend_;
79 }
80
81
82 /*
83   Here is what the Qt documentation says about how a menubar is chosen:
84
85      1) If the window has a QMenuBar then it is used. 2) If the window
86      is a modal then its menubar is used. If no menubar is specified
87      then a default menubar is used (as documented below) 3) If the
88      window has no parent then the default menubar is used (as
89      documented below).
90
91      The above 3 steps are applied all the way up the parent window
92      chain until one of the above are satisifed. If all else fails a
93      default menubar will be created, the default menubar on Qt/Mac is
94      an empty menubar, however you can create a different default
95      menubar by creating a parentless QMenuBar, the first one created
96      will thus be designated the default menubar, and will be used
97      whenever a default menubar is needed.
98
99   Thus, for Qt/Mac, we add the menus to a free standing menubar, so
100   that this menubar will be used also when one of LyX' dialogs has
101   focus. (JMarc)
102 */
103 QMenuBar * QLMenubar::menuBar() const
104 {
105 #ifdef Q_WS_MAC
106         return menubar_.get();
107 #else
108         return owner_->menuBar();
109 #endif
110 }
111
112 } // namespace frontend
113 } // namespace lyx