]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Menubar_pimpl.C
autosave cleanup, fix qt statusbar timeout, compile fix
[lyx.git] / src / frontends / qt2 / Menubar_pimpl.C
1 /**
2  * \file Menubar_pimpl.C
3  * Copyright 1999-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author  Lars Gullik Bjønnes, larsbj@lyx.org
7  */
8
9 #include <config.h>
10
11 #include <algorithm>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Menubar_pimpl.h"
18 #include "MenuBackend.h"
19 #include "LyXAction.h"
20 #include "kbmap.h"
21 #include "buffer.h"
22 #include "Dialogs.h"
23 #include "lyxfunc.h"
24 #include "FloatList.h"
25 #include "support/lstrings.h"
26 #include "support/LAssert.h"
27 #include "gettext.h"
28 #include "debug.h"
29
30 #include "QtView.h"
31  
32 #include <qmenubar.h>
33 #include <qpopupmenu.h>
34  
35 using std::endl;
36 using std::vector;
37 using std::max;
38 using std::min;
39 using std::for_each;
40
41 typedef vector<int>::size_type size_type;
42
43 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
44 extern LyXAction lyxaction;
45
46
47 Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe) 
48         : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
49 {
50         Menu::const_iterator m = mbe.getMenubar().begin();
51         Menu::const_iterator end = mbe.getMenubar().end();
52         for (; m != end; ++m) {
53                 makeMenu(owner_->menuBar(), *m);
54         }
55 }
56
57
58 void Menubar::Pimpl::makeMenu(QMenuData * parent, MenuItem const & menu)
59 {
60         // FIXME: leak
61         QPopupMenu * pm = new QPopupMenu();
62         parent->insertItem(menu.label().c_str(), pm);
63  
64         Menu md;
65         menubackend_.getMenu(menu.submenu()).expand(md, 0);
66         Menu::const_iterator m = md.begin();
67         Menu::const_iterator end = md.end();
68         for (; m != end; ++m) {
69                 if (m->kind() == MenuItem::Separator) {
70                         pm->insertSeparator();
71                 } else {
72                         pm->insertItem(m->label().c_str(), m->action());
73                 } 
74         }
75 }
76
77  
78 void Menubar::Pimpl::set(string const & menu_name) 
79 {
80         lyxerr[Debug::GUI] << "Entering Menubar::Pimpl::set " 
81                            << "for menu `" << menu_name << "'" << endl;
82
83 #if 0
84         if (menu_name != current_menu_name_) {
85                 MenubarMap::iterator mbit = menubarmap_.find(menu_name);
86
87                 if (mbit == menubarmap_.end()) {
88                         lyxerr << "ERROR:set: Unknown menu `" << menu_name
89                                << "'" << endl;
90                         return;
91                 }
92
93                 if (current_group_) {
94                         lyxerr[Debug::GUI] << "  hiding group "
95                                            << current_group_ << endl;
96                         fl_hide_object(current_group_);
97                 }
98                 
99                 lyxerr[Debug::GUI] << "  showing group "
100                                    << mbit->second << endl;
101                 fl_show_object(mbit->second);
102                 current_menu_name_ = menu_name;
103                 current_group_ = mbit->second;
104                 lyxerr[Debug::GUI] << "Menubar::Pimpl::set: Menubar set."
105                                    << endl;
106         } else
107                 lyxerr [Debug::GUI] << "Menubar::Pimpl::set: Nothing to do."
108                                     << endl;
109 #endif
110
111
112
113 void Menubar::Pimpl::openByName(string const & name)
114 {
115         lyxerr << "Menubar::Pimpl::openByName: menu " << name << endl;
116
117 #if 0
118         if (menubackend_->getMenu(current_menu_name_).hasSubmenu(name)) {
119                 for (ButtonList::const_iterator cit = buttonlist_.begin();
120                      cit != buttonlist_.end(); ++cit) {
121                         if ((*cit)->item_->submenu() == name) {
122                                 MenuCallback((*cit)->obj_, 1);
123                                 return;
124                         }
125                 }
126         }
127 #endif
128 }