2 * \file Menubar_pimpl.C
3 * Copyright 1999-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Lars Gullik Bjønnes, larsbj@lyx.org
14 #pragma implementation
17 #include "Menubar_pimpl.h"
18 #include "MenuBackend.h"
19 #include "LyXAction.h"
24 #include "FloatList.h"
25 #include "support/lstrings.h"
26 #include "support/LAssert.h"
33 #include <qpopupmenu.h>
43 string const getLabel(MenuItem const & mi)
45 string const shortcut = mi.shortcut();
46 string label = mi.label();
48 label = subst(label, "&", "&&");
53 string::size_type pos = label.find(shortcut);
54 if (pos == string::npos)
56 label.insert(pos, "&");
63 typedef vector<int>::size_type size_type;
65 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
66 extern LyXAction lyxaction;
69 Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe)
70 : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
72 Menu::const_iterator m = mbe.getMenubar().begin();
73 Menu::const_iterator end = mbe.getMenubar().end();
74 for (; m != end; ++m) {
75 makeMenu(owner_->menuBar(), *m);
80 void Menubar::Pimpl::makeMenu(QMenuData * parent, MenuItem const & menu)
82 // FIXME: does this leak or not ?
83 QPopupMenu * pm = new QPopupMenu();
84 int const parentid = parent->insertItem(getLabel(menu).c_str(), pm);
87 menubackend_.getMenu(menu.submenu()).expand(md, 0);
88 Menu::const_iterator m = md.begin();
89 Menu::const_iterator end = md.end();
90 for (; m != end; ++m) {
91 // FIXME: handle the special stuff here
92 if (m->kind() == MenuItem::Separator) {
93 pm->insertSeparator();
94 } else if (m->kind() == MenuItem::Submenu) {
97 pm->insertItem(getLabel(*m).c_str(), m->action());
98 MenuItemInfo const info(pm, m->action(), m);
99 items_[m->label()] = info;
104 MenuItemInfo const info(parent, parentid, &menu);
105 items_[menu.label()] = info;
110 // FIXME: this is probably buggy with respect to enabling
111 // two-level submenus
112 void Menubar::Pimpl::updateSubmenu(MenuItemInfo const & i)
118 // FIXME FIXME SEGFAULTS
119 menubackend_.getMenu(i.item_->submenu()).expand(md, 0);
120 Menu::const_iterator m = md.begin();
121 Menu::const_iterator end = md.end();
122 for (; m != end; ++m) {
123 if (m->action() > 0) {
124 FuncStatus const status =
125 owner_->getLyXFunc()->getStatus(m->action());
126 if (!status.disabled())
131 i.parent_->setItemEnabled(i.id_, enable);
135 void Menubar::Pimpl::updateItem(MenuItemInfo const & i)
137 if (i.item_->kind() == MenuItem::Submenu) {
146 FuncStatus const status = owner_->getLyXFunc()->getStatus(i.id_);
147 i.parent_->setItemEnabled(i.id_, !status.disabled());
148 i.parent_->setItemChecked(i.id_, status.onoff(true));
152 void Menubar::Pimpl::update()
154 // FIXME: handle special stuff to be updated.
156 ItemMap::const_iterator cit = items_.begin();
157 ItemMap::const_iterator end = items_.end();
159 for (; cit != end; ++cit)
160 updateItem(cit->second);
164 void Menubar::Pimpl::openByName(string const & name)
166 lyxerr << "Menubar::Pimpl::openByName: menu " << name << endl;
168 ItemMap::iterator it = items_.find(name);
170 if (it == items_.end())
171 lyxerr << "NOT FOUND " << name << endl;