]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Menubar_pimpl.C
Missing files, get keyboard partly working
[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 & mb) 
48         : owner_(static_cast<QtView*>(view)), menubackend_(mb)
49 {
50         MenuBackend::const_iterator mb = menubackend_.begin(); 
51         MenuBackend::const_iterator mbend = menubackend_.end();
52         for (; mb != mbend; ++mb) {
53                 if (mb->menubar() && mb->name() == "main") {
54                         Menu::const_iterator m = mb->begin();
55                         Menu::const_iterator end = mb->end();
56                         for (; m != end; ++m) {
57                                 makeMenu(owner_->menuBar(), *m);
58                         }
59                 }
60         }
61 }
62
63
64 void Menubar::Pimpl::makeMenu(QMenuData * parent, MenuItem const & menu)
65 {
66         // FIXME: leak
67         QPopupMenu * pm = new QPopupMenu();
68         parent->insertItem(menu.label().c_str(), pm);
69  
70         Menu md;
71         menubackend_.getMenu(menu.submenu()).expand(md, 0);
72         Menu::const_iterator m = md.begin();
73         Menu::const_iterator end = md.end();
74         for (; m != end; ++m) {
75                 if (m->kind() == MenuItem::Separator) {
76                         pm->insertSeparator();
77                 } else {
78                         pm->insertItem(m->label().c_str(), m->action());
79                 } 
80         }
81 }
82
83  
84 void Menubar::Pimpl::set(string const & menu_name) 
85 {
86         lyxerr[Debug::GUI] << "Entering Menubar::Pimpl::set " 
87                            << "for menu `" << menu_name << "'" << endl;
88
89 #if 0
90         if (menu_name != current_menu_name_) {
91                 MenubarMap::iterator mbit = menubarmap_.find(menu_name);
92
93                 if (mbit == menubarmap_.end()) {
94                         lyxerr << "ERROR:set: Unknown menu `" << menu_name
95                                << "'" << endl;
96                         return;
97                 }
98
99                 if (current_group_) {
100                         lyxerr[Debug::GUI] << "  hiding group "
101                                            << current_group_ << endl;
102                         fl_hide_object(current_group_);
103                 }
104                 
105                 lyxerr[Debug::GUI] << "  showing group "
106                                    << mbit->second << endl;
107                 fl_show_object(mbit->second);
108                 current_menu_name_ = menu_name;
109                 current_group_ = mbit->second;
110                 lyxerr[Debug::GUI] << "Menubar::Pimpl::set: Menubar set."
111                                    << endl;
112         } else
113                 lyxerr [Debug::GUI] << "Menubar::Pimpl::set: Nothing to do."
114                                     << endl;
115 #endif
116
117
118
119 void Menubar::Pimpl::openByName(string const & name)
120 {
121         lyxerr << "Menubar::Pimpl::openByName: menu " << name << endl;
122
123 #if 0
124         if (menubackend_->getMenu(current_menu_name_).hasSubmenu(name)) {
125                 for (ButtonList::const_iterator cit = buttonlist_.begin();
126                      cit != buttonlist_.end(); ++cit) {
127                         if ((*cit)->item_->submenu() == name) {
128                                 MenuCallback((*cit)->obj_, 1);
129                                 return;
130                         }
131                 }
132         }
133 #endif
134 }