]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QLMenubar.C
Joao latest bits
[lyx.git] / src / frontends / qt2 / QLMenubar.C
1 /**
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.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "MenuBackend.h"
14
15 #include "QtView.h"
16 #include "QLMenubar.h"
17 #include "QLPopupMenu.h"
18
19 #include <qmenubar.h>
20 #include <qcursor.h>
21
22
23 using std::pair;
24 using std::string;
25
26
27 QLMenubar::QLMenubar(LyXView * view, MenuBackend const & mbe)
28         : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
29 {
30         Menu::const_iterator m = mbe.getMenubar().begin();
31         Menu::const_iterator end = mbe.getMenubar().end();
32         for (; m != end; ++m) {
33                 pair<int, QLPopupMenu *> menu =
34                         createMenu(owner_->menuBar(), &(*m), this, true);
35                 name_map_[m->submenuname()] = menu.second;
36 #ifdef Q_WS_MAC
37                 /* The qt/mac menu code has a very silly hack that
38                    moves some menu entries that it recognizes by name
39                    (ex: "Preferences...") to the "LyX" menu. This
40                    feature can only work if the menu entries are
41                    always available. Since we build menus on demand,
42                    we have to have a reasonable default value before
43                    the menus have been explicitely opened. (JMarc)
44                 */
45                 menu.second->showing();
46 #endif
47         }
48 }
49
50
51 void QLMenubar::openByName(string const & name)
52 {
53         NameMap::const_iterator const cit = name_map_.find(name);
54         if (cit == name_map_.end())
55                 return;
56
57         // this will have to do I'm afraid.
58         cit->second->exec(QCursor::pos());
59 }
60
61
62 void QLMenubar::update()
63 {}
64
65
66 QtView * QLMenubar::view()
67 {
68         return owner_;
69 }
70
71
72 MenuBackend const & QLMenubar::backend()
73 {
74         return menubackend_;
75 }