]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/QLPopupMenu.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / QLPopupMenu.C
index 9c3409e937841d16a8fce559b0b90faab06936dd..34fdacb6f6ac29e591780cee1c6601bae2ace0bb 100644 (file)
@@ -15,9 +15,9 @@
 
 // Qt defines a macro 'signals' that clashes with a boost namespace.
 // All is well if the namespace is visible first.
-#include "QtView.h"
+#include "GuiView.h"
 
-#include "QLAction.h"
+#include "Action.h"
 #include "QLPopupMenu.h"
 #include "QLMenubar.h"
 #include "qt_helpers.h"
@@ -50,7 +50,7 @@ namespace frontend {
 
 // MacOSX specific stuff is at the end.
 
-QLPopupMenu::QLPopupMenu(QLMenubar * owner, 
+QLPopupMenu::QLPopupMenu(QLMenubar * owner,
                                                 MenuItem const & mi, bool topLevelMenu)
        : owner_(owner)
 {
@@ -67,19 +67,18 @@ QLPopupMenu::QLPopupMenu(QLMenubar * owner,
 void QLPopupMenu::update()
 {
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION << endl;
-       lyxerr[Debug::GUI] << "\tTriggered menu: " << name_ << endl;
+       lyxerr[Debug::GUI] << "\tTriggered menu: " << lyx::to_utf8(name_) << endl;
 
        clear();
-       topLevelMenu_.clear();
 
        if (name_.empty())
                return;
 
        Menu const & fromLyxMenu = owner_->backend().getMenu(name_);
-       owner_->backend().expand(fromLyxMenu, topLevelMenu_, owner_->view());
-       
+       owner_->backend().expand(fromLyxMenu, topLevelMenu_, owner_->view()->buffer());
+
        if (!owner_->backend().hasMenu(topLevelMenu_.name())) {
-               lyxerr[Debug::GUI] << "\tWARNING: menu seems empty" << topLevelMenu_.name() << endl;
+               lyxerr[Debug::GUI] << "\tWARNING: menu seems empty" << lyx::to_utf8(topLevelMenu_.name()) << endl;
        }
        populate(this, &topLevelMenu_);
 
@@ -88,9 +87,9 @@ void QLPopupMenu::update()
 
 void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
 {
-       lyxerr[Debug::GUI] << "populating menu " << menu->name() ;
+       lyxerr[Debug::GUI] << "populating menu " << lyx::to_utf8(menu->name()) ;
        if (menu->size() == 0) {
-               lyxerr[Debug::GUI] << "\tERROR: empty menu " << menu->name() << endl;
+               lyxerr[Debug::GUI] << "\tERROR: empty menu " << lyx::to_utf8(menu->name()) << endl;
                return;
        }
        else {
@@ -99,59 +98,58 @@ void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
 
        Menu::const_iterator m = menu->begin();
        Menu::const_iterator end = menu->end();
-       
+
        for (; m != end; ++m) {
 
                if (m->kind() == MenuItem::Separator) {
-               
+
                        qMenu->addSeparator();
                        lyxerr[Debug::GUI] << "adding Menubar Separator" << endl;
 
                } else if (m->kind() == MenuItem::Submenu) {
-                       
-                       lyxerr[Debug::GUI] << "** creating New Sub-Menu " << getLabel(*m) << endl;
+
+                       lyxerr[Debug::GUI] << "** creating New Sub-Menu " << lyx::to_utf8(getLabel(*m)) << endl;
                        QMenu * subMenu = qMenu->addMenu(toqstr(getLabel(*m)));
                        populate(subMenu, m->submenu());
-                       
+
                } else { // we have a MenuItem::Command
 
-                       FuncStatus status = m->status();
-                       lyxerr[Debug::GUI] << "creating Menu Item " << m->label() << endl;
-                       
-                       string label = getLabel(*m);
+                       lyxerr[Debug::GUI] << "creating Menu Item " << lyx::to_utf8(m->label()) << endl;
+
+                       docstring label = getLabel(*m);
                        addBinding(label, *m);
-                       
-                       QLAction * action = new QLAction(*(owner_->view()), label, m->func());
-                       action->setEnabled(m->status().enabled());
-                       action->setChecked(m->status().onoff(true));
-                       // Actually insert the menu item
+
+                       Action * action = new Action(*(owner_->view()),
+                                                    lyx::to_utf8(label), m->func());
                        qMenu->addAction(action);
                }
        }
 }
 
-string const QLPopupMenu::getLabel(MenuItem const & mi)
+docstring const QLPopupMenu::getLabel(MenuItem const & mi)
 {
-       string const shortcut = mi.shortcut();
-       string label = support::subst(mi.label(), "&", "&&");
+       docstring const shortcut = mi.shortcut();
+       docstring label = support::subst(mi.label(),
+                                     lyx::from_ascii("&"),
+                                     lyx::from_ascii("&&"));
 
        if (!shortcut.empty()) {
-               string::size_type pos = label.find(shortcut);
-               if (pos != string::npos)
-                       label.insert(pos, 1, '&');
+               docstring::size_type pos = label.find(shortcut);
+               if (pos != docstring::npos)
+                       label.insert(pos, 1, char_type('&'));
        }
 
        return label;
 }
 
 /// \todo Mac specific binding handling.
-void QLPopupMenu::addBinding(string & label, MenuItem const & mi)
+void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi)
 {
 #ifndef Q_WS_MACX
 
-               string const binding(mi.binding());
+               docstring const binding(mi.binding());
                if (!binding.empty()) {
-                       label += '\t' + binding;
+                       label += char_type('\t') + binding;
                }
 
 #else
@@ -201,3 +199,5 @@ void QLPopupMenu::specialMacXmenuHack()
 
 } // namespace frontend
 } // namespace lyx
+
+#include "QLPopupMenu_moc.cpp"