From 8387742c8860694777f7c2c62da0a90c9e836988 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 15 Jan 2015 14:24:46 +0100 Subject: [PATCH] Refactor menu code: be more explicit and compact This commit is a preparation step for some menu cleanup ahead. To make it easier to understand which types of MenuItems are added where and when, I converted the overloaded FbTk::Menu::insert() functions into explicit ones (Menu::insertSubmenu(), Menu::insertItem(), etc. ). This makes it possible to just grep for 'insertSubmenu()'. Side effect this commit: it trims down the very verbose creation of menu items in regards to how the labels are created. Minor: FbTk::Menu::shown and FbTk::Menu::s_focused are moved out of the class. --- src/AlphaMenu.cc | 6 +- src/ClientMenu.cc | 4 +- src/ClockTool.cc | 10 +- src/FbTk/Menu.cc | 212 ++++++++++++++++++++++--------------------- src/FbTk/Menu.hh | 38 ++------ src/IconbarTool.cc | 111 ++++++++++------------ src/LayerMenu.cc | 4 +- src/MenuCreator.cc | 188 ++++++++++++++++++++------------------ src/Remember.cc | 35 +++---- src/Screen.cc | 52 +++++------ src/SendToMenu.cc | 4 +- src/Slit.cc | 54 ++++++----- src/Toolbar.cc | 41 +++++---- src/WorkspaceMenu.cc | 14 +-- src/Xinerama.hh | 6 +- 15 files changed, 373 insertions(+), 406 deletions(-) diff --git a/src/AlphaMenu.cc b/src/AlphaMenu.cc index 219d6ead..032e5b35 100644 --- a/src/AlphaMenu.cc +++ b/src/AlphaMenu.cc @@ -53,7 +53,7 @@ AlphaMenu::AlphaMenu(FbTk::ThemeProxy &tm, m_focused_alpha_item = new FbTk::IntMenuItem(focused_alpha_label, m_focused_alpha, 0, 255, *this); - insert(m_focused_alpha_item); + insertItem(m_focused_alpha_item); const FbTk::FbString unfocused_alpha_label = _FB_XTEXT(Configmenu, UnfocusedAlpha, @@ -62,14 +62,14 @@ AlphaMenu::AlphaMenu(FbTk::ThemeProxy &tm, m_unfocused_alpha_item = new FbTk::IntMenuItem(unfocused_alpha_label, m_unfocused_alpha, 0, 255, *this); - insert(m_unfocused_alpha_item); + insertItem(m_unfocused_alpha_item); const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, "Use Defaults", "Default transparency settings for this window"); FbTk::MenuItem *usedefault_item = new AlphaMenuSelectItem(usedefault_label, *this); - insert(usedefault_item); + insertItem(usedefault_item); updateMenu(); } diff --git a/src/ClientMenu.cc b/src/ClientMenu.cc index 96527ece..84f20254 100644 --- a/src/ClientMenu.cc +++ b/src/ClientMenu.cc @@ -118,9 +118,9 @@ void ClientMenu::refreshMenu() { FluxboxWindow::ClientList::iterator client_it_end = win->clientList().end(); for (; client_it != client_it_end; ++client_it) - insert(new ClientMenuItem(**client_it, *this)); + insertItem(new ClientMenuItem(**client_it, *this)); } else - insert(new ClientMenuItem(**win_it, *this)); + insertItem(new ClientMenuItem(**win_it, *this)); } updateMenu(); diff --git a/src/ClockTool.cc b/src/ClockTool.cc index f2a7333f..893d32be 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -37,11 +37,7 @@ #include "FbTk/I18n.hh" #include "FbTk/FbTime.hh" -#ifdef HAVE_CTIME - #include -#else - #include -#endif +#include #include #include @@ -171,9 +167,9 @@ ClockTool::ClockTool(const FbTk::FbWindow &parent, FbTk::RefCount > saverc(FbTk::CommandParser::instance().parse("saverc")); FbTk::MenuItem *item = new ClockMenuItem(*this); item->setCommand(saverc); - menu.insert(item); + menu.insertItem(item); FbTk::RefCount > editformat_cmd(new EditClockFormatCmd()); - menu.insert(_FB_XTEXT(Toolbar, ClockEditFormat, "Edit Clock Format", "edit Clock Format") , editformat_cmd); + menu.insertCommand(_FB_XTEXT(Toolbar, ClockEditFormat, "Edit Clock Format", "edit Clock Format") , editformat_cmd); updateTime(); } diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index cb58685f..4dbb48c1 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -85,9 +85,11 @@ void renderMenuPixmap(Pixmap& pm, FbTk::FbWindow* win, int width, int height, co namespace FbTk { -Menu *Menu::shown = 0; +Menu* s_shown = 0; // if there's a menu open at all +Menu* s_focused = 0; // holds currently focused menu -Menu *Menu::s_focused = 0; +Menu* Menu::shownMenu() { return s_shown; } +Menu* Menu::focused() { return s_focused; } Menu::Menu(FbTk::ThemeProxy &tm, ImageControl &imgctrl): m_theme(tm), @@ -101,8 +103,8 @@ Menu::Menu(FbTk::ThemeProxy &tm, ImageControl &imgctrl): m_active_index(-1), m_shape(0), m_need_update(true) { - // setup timers + // setup timers RefCount > show_cmd(new SimpleCommand(*this, &Menu::openSubmenu)); m_submenu_timer.setCommand(show_cmd); m_submenu_timer.fireOnce(true); @@ -192,8 +194,8 @@ Menu::~Menu() { m_window.hide(); - if (shown && shown->window() == window()) - shown = 0; + if (s_shown && s_shown->window() == window()) + s_shown = 0; removeAll(); @@ -210,59 +212,61 @@ Menu::~Menu() { s_focused = 0; } -int Menu::insert(const FbString &label, RefCount > &cmd, int pos) { - return insert(new MenuItem(label, cmd, this), pos); +int Menu::insertCommand(const FbString &label, RefCount > &cmd, int pos) { + return insertItem(new MenuItem(label, cmd, this), pos); } int Menu::insert(const FbString &label, int pos) { - return insert(new MenuItem(label, *this), pos); + return insertItem(new MenuItem(label, *this), pos); } -int Menu::insert(const FbString &label, Menu *submenu, int pos) { - return insert(new MenuItem(label, submenu, this), pos); +int Menu::insertSubmenu(const FbString &label, Menu *submenu, int pos) { + return insertItem(new MenuItem(label, submenu, this), pos); } -int Menu::insert(MenuItem *item, int pos) { +int Menu::insertItem(MenuItem *item, int pos) { if (item == 0) - return menuitems.size(); + return m_items.size(); if (pos == -1) { - item->setIndex(menuitems.size()); - menuitems.push_back(item); + item->setIndex(m_items.size()); + m_items.push_back(item); } else { - menuitems.insert(menuitems.begin() + pos, item); + m_items.insert(m_items.begin() + pos, item); fixMenuItemIndices(); if (m_active_index >= pos) m_active_index++; } m_need_update = true; // we need to redraw the menu - return menuitems.size(); + return m_items.size(); } void Menu::fixMenuItemIndices() { - for (size_t i = 0; i < menuitems.size(); i++) - menuitems[i]->setIndex(i); + for (size_t i = 0; i < m_items.size(); i++) + m_items[i]->setIndex(i); } int Menu::remove(unsigned int index) { - if (index >= menuitems.size()) { + if (index >= m_items.size()) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ") Bad index (" << index << ") given to Menu::remove()" - << " -- should be between 0 and " << menuitems.size()-1 + << " -- should be between 0 and " << m_items.size()-1 << " inclusive." << endl; #endif // DEBUG return -1; } - Menuitems::iterator it = menuitems.begin() + index; + Menuitems::iterator it = m_items.begin() + index; MenuItem *item = (*it); if (item) { if (!m_matches.empty()) resetTypeAhead(); - menuitems.erase(it); + + m_items.erase(it); + // avoid O(n^2) algorithm with removeAll() - if (index != menuitems.size()) + if (index != m_items.size()) fixMenuItemIndices(); if (item->submenu() != 0) { @@ -291,12 +295,12 @@ int Menu::remove(unsigned int index) { m_need_update = true; // we need to redraw the menu - return menuitems.size(); + return m_items.size(); } void Menu::removeAll() { - while (!menuitems.empty()) - remove(menuitems.size()-1); + while (!m_items.empty()) + remove(m_items.size()-1); } void Menu::raise() { @@ -308,26 +312,24 @@ void Menu::lower() { } void Menu::cycleItems(bool reverse) { - Menuitems vec; + Menuitems& items = m_items; if (m_type_ahead.stringSize()) - vec = m_matches; - else - vec = menuitems; + items = m_matches; - if (vec.size() < 1) + if (items.empty()) return; // find the next item to select // this algorithm assumes menuitems are sorted properly int new_index = -1; bool passed = !validIndex(m_active_index); - for (size_t i = 0; i < vec.size(); i++) { - if (!isItemSelectable(vec[i]->getIndex()) || - vec[i]->getIndex() == m_active_index) + for (size_t i = 0; i < items.size(); i++) { + if (!isItemSelectable(items[i]->getIndex()) || + items[i]->getIndex() == m_active_index) continue; // determine whether or not we've passed the active index - if (!passed && vec[i]->getIndex() > m_active_index) { + if (!passed && items[i]->getIndex() > m_active_index) { if (reverse && new_index != -1) break; passed = true; @@ -335,10 +337,10 @@ void Menu::cycleItems(bool reverse) { // decide if we want to keep this item if (passed && !reverse) { - new_index = vec[i]->getIndex(); + new_index = items[i]->getIndex(); break; } else if (reverse || new_index == -1) - new_index = vec[i]->getIndex(); + new_index = items[i]->getIndex(); } if (new_index != -1) @@ -350,11 +352,11 @@ void Menu::setActiveIndex(int new_index) { int old_active_index = m_active_index; m_active_index = new_index; if (validIndex(old_active_index) && - menuitems[old_active_index] != 0) { - if (menuitems[old_active_index]->submenu()) { + m_items[old_active_index] != 0) { + if (m_items[old_active_index]->submenu()) { // we need to do this explicitly on the m_window // since it might hide the parent if we use Menu::hide - menuitems[old_active_index]->submenu()->internal_hide(); + m_items[old_active_index]->submenu()->internal_hide(); } clearItem(old_active_index); } @@ -365,11 +367,11 @@ void Menu::enterSubmenu() { if (!validIndex(m_active_index)) return; - Menu *submenu = menuitems[m_active_index]->submenu(); + Menu *submenu = m_items[m_active_index]->submenu(); if (submenu == 0) return; - if (submenu->menuitems.empty()) + if (submenu->m_items.empty()) return; drawSubmenu(m_active_index); @@ -393,15 +395,15 @@ void Menu::updateMenu() { } else m_item_w = 1; - if (validIndex(m_active_index) && !menuitems[m_active_index]->isEnabled()) { + if (validIndex(m_active_index) && !m_items[m_active_index]->isEnabled()) { // find the nearest enabled menuitem and highlight it - for (size_t i = 1; i < menuitems.size(); i++) { + for (size_t i = 1; i < m_items.size(); i++) { if (validIndex(m_active_index + i) && - menuitems[m_active_index + i]->isEnabled()) { + m_items[m_active_index + i]->isEnabled()) { m_active_index += i; break; } else if (validIndex(m_active_index - i) && - menuitems[m_active_index - i]->isEnabled()) { + m_items[m_active_index - i]->isEnabled()) { m_active_index -= i; break; } @@ -409,8 +411,8 @@ void Menu::updateMenu() { } unsigned int ii = 0; - Menuitems::iterator it = menuitems.begin(); - Menuitems::iterator it_end = menuitems.end(); + Menuitems::iterator it = m_items.begin(); + Menuitems::iterator it_end = m_items.end(); for (; it != it_end; ++it) { ii = (*it)->width(theme()); m_item_w = (ii > m_item_w ? ii : m_item_w); @@ -419,10 +421,10 @@ void Menu::updateMenu() { if (m_item_w < 1) m_item_w = 1; - if (!menuitems.empty()) { + if (!m_items.empty()) { m_columns = 1; - while (theme()->itemHeight() * (menuitems.size() + 1) / m_columns + + while (theme()->itemHeight() * (m_items.size() + 1) / m_columns + theme()->titleHeight() + theme()->borderWidth() > m_screen_height) { m_columns++; } @@ -430,8 +432,8 @@ void Menu::updateMenu() { if (m_columns < m_min_columns) m_columns = m_min_columns; - m_rows_per_column = menuitems.size() / m_columns; - if (menuitems.size() % m_columns) m_rows_per_column++; + m_rows_per_column = m_items.size() / m_columns; + if (m_items.size() % m_columns) m_rows_per_column++; } else { m_columns = 0; m_rows_per_column = 0; @@ -522,7 +524,7 @@ void Menu::updateMenu() { void Menu::show() { - if (isVisible() || menuitems.empty()) + if (isVisible() || m_items.empty()) return; m_visible = true; @@ -537,9 +539,9 @@ void Menu::show() { m_window.show(); raise(); - if (shown && shown != this) - shown->hide(); - shown = this; + if (s_shown && s_shown != this) + s_shown->hide(); + s_shown = this; } @@ -565,8 +567,8 @@ void Menu::hide(bool force) { void Menu::grabInputFocus() { // if there's a submenu open, focus it instead if (validIndex(m_which_sub) && - menuitems[m_which_sub]->submenu()->isVisible()) { - menuitems[m_which_sub]->submenu()->grabInputFocus(); + m_items[m_which_sub]->submenu()->isVisible()) { + m_items[m_which_sub]->submenu()->grabInputFocus(); return; } @@ -582,14 +584,14 @@ void Menu::clearWindow() { m_frame.clear(); // clear foreground bits of frame items - for (size_t i = 0; i < menuitems.size(); i++) { + for (size_t i = 0; i < m_items.size(); i++) { clearItem(i, false); // no clear } m_shape->update(); } void Menu::redrawFrame(FbDrawable &drawable) { - for (size_t i = 0; i < menuitems.size(); i++) { + for (size_t i = 0; i < m_items.size(); i++) { drawItem(drawable, i); } @@ -598,7 +600,7 @@ void Menu::redrawFrame(FbDrawable &drawable) { void Menu::internal_hide(bool first) { if (validIndex(m_which_sub)) { - MenuItem *tmp = menuitems[m_which_sub]; + MenuItem *tmp = m_items[m_which_sub]; if (tmp && tmp->submenu() && tmp->submenu()->isVisible()) tmp->submenu()->internal_hide(false); } @@ -609,11 +611,11 @@ void Menu::internal_hide(bool first) { m_active_index = -1; clearItem(old); // clear old area from highlight - if (shown == this) { + if (s_shown == this) { if (m_parent && m_parent->isVisible()) - shown = m_parent; + s_shown = m_parent; else - shown = (Menu *) 0; + s_shown = 0; } m_torn = m_visible = m_closing = false; @@ -644,7 +646,7 @@ void Menu::move(int x, int y) { clearWindow(); if (validIndex(m_which_sub) && - menuitems[m_which_sub]->submenu()->isVisible()) + m_items[m_which_sub]->submenu()->isVisible()) drawSubmenu(m_which_sub); } @@ -676,17 +678,17 @@ void Menu::redrawTitle(FbDrawable &drawable) { void Menu::drawSubmenu(unsigned int index) { if (validIndex(m_which_sub) && static_cast(m_which_sub) != index) { - MenuItem *itmp = menuitems[m_which_sub]; + MenuItem *itmp = m_items[m_which_sub]; if (! itmp->submenu()->isTorn()) itmp->submenu()->internal_hide(); } - if (index >= menuitems.size()) + if (index >= m_items.size()) return; - MenuItem *item = menuitems[index]; + MenuItem *item = m_items[index]; if (item->submenu() && isVisible() && (! item->submenu()->isTorn()) && item->isEnabled()) { @@ -750,7 +752,7 @@ void Menu::drawSubmenu(unsigned int index) { clearItem(index); if (! item->submenu()->isVisible() && item->submenu()->numberOfItems() > 0) { - shown = item->submenu(); + s_shown = item->submenu(); item->showSubmenu(); item->submenu()->raise(); } @@ -764,11 +766,11 @@ void Menu::drawSubmenu(unsigned int index) { int Menu::drawItem(FbDrawable &drawable, unsigned int index, bool highlight, bool exclusive_drawable) { - if (index >= menuitems.size() || menuitems.empty() || + if (index >= m_items.size() || m_items.empty() || m_rows_per_column == 0) return 0; - MenuItem *item = menuitems[index]; + MenuItem *item = m_items[index]; if (! item) return 0; // ensure we do not divide by 0 and thus cause a SIGFPE @@ -804,7 +806,7 @@ void Menu::setLabel(const FbTk::BiDiString &labelstr) { void Menu::setItemSelected(unsigned int index, bool sel) { - if (index >= menuitems.size()) return; + if (index >= m_items.size()) return; MenuItem *item = find(index); if (! item) return; @@ -814,7 +816,7 @@ void Menu::setItemSelected(unsigned int index, bool sel) { bool Menu::isItemSelected(unsigned int index) const{ - if (index >= menuitems.size()) return false; + if (index >= m_items.size()) return false; const MenuItem *item = find(index); if (!item) @@ -825,7 +827,7 @@ bool Menu::isItemSelected(unsigned int index) const{ void Menu::setItemEnabled(unsigned int index, bool enable) { - if (index >= menuitems.size()) return; + if (index >= m_items.size()) return; MenuItem *item = find(index); if (! item) return; @@ -835,7 +837,7 @@ void Menu::setItemEnabled(unsigned int index, bool enable) { bool Menu::isItemEnabled(unsigned int index) const { - if (index >= menuitems.size()) return false; + if (index >= m_items.size()) return false; const MenuItem *item = find(index); if (!item) @@ -846,7 +848,7 @@ bool Menu::isItemEnabled(unsigned int index) const { bool Menu::isItemSelectable(unsigned int index) const { - if (index >= menuitems.size()) return false; + if (index >= m_items.size()) return false; const MenuItem *item = find(index); return (!item || !item->isEnabled()) ? false : true; @@ -864,8 +866,8 @@ void Menu::handleEvent(XEvent &event) { s_focused = this; // if there's a submenu open, focus it instead if (validIndex(m_which_sub) && - menuitems[m_which_sub]->submenu()->isVisible()) - menuitems[m_which_sub]->submenu()->grabInputFocus(); + m_items[m_which_sub]->submenu()->isVisible()) + m_items[m_which_sub]->submenu()->grabInputFocus(); } } @@ -883,7 +885,7 @@ void Menu::buttonPressEvent(XButtonEvent &be) { int w = (column * m_rows_per_column) + i; if (validIndex(w) && isItemSelectable(static_cast(w))) { - MenuItem *item = menuitems[w]; + MenuItem *item = m_items[w]; if (item->submenu()) { if (!item->submenu()->isVisible()) @@ -903,7 +905,7 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) { m_moving = false; if (validIndex(m_which_sub) && - menuitems[m_which_sub]->submenu()->isVisible()) + m_items[m_which_sub]->submenu()->isVisible()) drawSubmenu(m_which_sub); if (alpha() < 255) { @@ -929,7 +931,7 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) { if (m_active_index == w && isItemEnabled(w) && re.x > ix && re.x < (signed) (ix + m_item_w) && re.y > iy && re.y < (signed) (iy + theme()->itemHeight())) { - menuitems[w]->click(re.button, re.time, re.state); + m_items[w]->click(re.button, re.time, re.state); } else { int old = m_active_index; m_active_index = w; @@ -955,7 +957,7 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { clearItem(m_active_index); if (validIndex(m_which_sub) && - menuitems[m_which_sub]->submenu()->isVisible()) + m_items[m_which_sub]->submenu()->isVisible()) drawSubmenu(m_which_sub); } else { // we dont call ::move here 'cause we dont want to update transparency @@ -977,7 +979,7 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { if (s_focused != this && s_focused != 0) grabInputFocus(); - MenuItem *itmp = menuitems[w]; + MenuItem *itmp = m_items[w]; if (itmp == 0) return; @@ -987,7 +989,7 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { clearItem(w); clearItem(old); - MenuItem *item = validIndex(m_which_sub) ? menuitems[m_which_sub] : 0; + MenuItem *item = validIndex(m_which_sub) ? m_items[m_which_sub] : 0; if (item != 0 && item->submenu() && item->submenu()->isVisible() && !item->submenu()->isTorn()) { // setup hide timer for submenu @@ -1045,9 +1047,9 @@ void Menu::exposeEvent(XExposeEvent &ee) { // set the iterator to the first item in the column needing redrawing int index = id + i * m_rows_per_column; - if (index < static_cast(menuitems.size()) && index >= 0) { - Menuitems::iterator it = menuitems.begin() + index; - Menuitems::iterator it_end = menuitems.end(); + if (index < static_cast(m_items.size()) && index >= 0) { + Menuitems::iterator it = m_items.begin() + index; + Menuitems::iterator it_end = m_items.end(); for (ii = id; ii <= id_d && it != it_end; ++it, ii++) { int index = ii + (i * m_rows_per_column); // redraw the item @@ -1119,7 +1121,7 @@ void Menu::keyPressEvent(XKeyEvent &event) { isItemEnabled(m_active_index)) { // send fake button click int button = (event.state & ShiftMask) ? 3 : 1; - if (menuitems[m_active_index]->submenu() != 0 && button == 1) + if (m_items[m_active_index]->submenu() != 0 && button == 1) enterSubmenu(); else { find(m_active_index)->click(button, event.time, event.state); @@ -1131,7 +1133,7 @@ void Menu::keyPressEvent(XKeyEvent &event) { case XK_Tab: case XK_ISO_Left_Tab: if (validIndex(m_active_index) && isItemEnabled(m_active_index) && - menuitems[m_active_index]->submenu() && m_matches.size() == 1) { + m_items[m_active_index]->submenu() && m_matches.size() == 1) { enterSubmenu(); m_type_ahead.reset(); } else { @@ -1156,12 +1158,12 @@ void Menu::leaveNotifyEvent(XCrossingEvent &ce) { m_closing = false; // if there's a submenu open, highlight its index and stop hide if (validIndex(m_which_sub) && m_active_index != m_which_sub && - menuitems[m_which_sub]->submenu()->isVisible()) { + m_items[m_which_sub]->submenu()->isVisible()) { int old = m_active_index; m_active_index = m_which_sub; clearItem(m_active_index); clearItem(old); - menuitems[m_which_sub]->submenu()->stopHide(); + m_items[m_which_sub]->submenu()->stopHide(); } } @@ -1194,17 +1196,17 @@ void Menu::reconfigure() { void Menu::openSubmenu() { int item = m_active_index; - if (!isVisible() || !validIndex(item) || !menuitems[item]->isEnabled() || + if (!isVisible() || !validIndex(item) || !m_items[item]->isEnabled() || (s_focused != this && s_focused && s_focused->isVisible())) return; clearItem(item); - if (menuitems[item]->submenu() != 0) { + if (m_items[item]->submenu() != 0) { // stop hide timer, so it doesnt hides the menu if we // have the same submenu as the last shown submenu // (window menu for clients inside workspacemenu for example) - menuitems[item]->submenu()->m_hide_timer.stop(); + m_items[item]->submenu()->m_hide_timer.stop(); drawSubmenu(item); } @@ -1228,15 +1230,15 @@ void Menu::themeReconfigured() { m_need_update = true; - Menuitems::iterator it = menuitems.begin(); - Menuitems::iterator it_end = menuitems.end(); + Menuitems::iterator it = m_items.begin(); + Menuitems::iterator it_end = m_items.end(); for (; it != it_end; ++it) { (*it)->updateTheme(theme()); } reconfigure(); } -void Menu::setScreen(int x, int y, int w, int h) { +void Menu::setScreen(int x, int y, unsigned int w, unsigned int h) { m_screen_x = x; m_screen_y = y; m_screen_width = w; @@ -1277,28 +1279,28 @@ void Menu::clearItem(int index, bool clear, int search_index) { int item_y = (row * item_h); bool highlight = (index == m_active_index && isItemSelectable(index)); - if (search_index < 0) - // find if we need to underline the item + if (search_index < 0) // need to underline the item search_index = std::find(m_matches.begin(), m_matches.end(), find(index)) - m_matches.begin(); // don't highlight if moving, doesn't work with alpha on if (highlight && !m_moving) { highlightItem(index); - if (search_index < (int)m_matches.size()) + if (search_index < static_cast(m_matches.size())) drawLine(index, m_type_ahead.stringSize()); return; } else if (clear) m_frame.clearArea(item_x, item_y, item_w, item_h); - MenuItem *item = menuitems[index]; - if (! item) return; + MenuItem* item = m_items[index]; + if (!item) + return; item->draw(m_frame, theme(), highlight, true, false, item_x, item_y, item_w, item_h); - if (search_index < (int)m_matches.size()) + if (search_index < static_cast(m_matches.size())) drawLine(index, m_type_ahead.stringSize()); } @@ -1390,8 +1392,8 @@ void Menu::drawLine(int index, int size){ } void Menu::hideShownMenu() { - if (shown) - shown->hide(); + if (s_shown) + s_shown->hide(); } } // end namespace FbTk diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 5e1d98c7..49893c1a 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh @@ -60,28 +60,18 @@ public: @name manipulators */ //@{ - /// add a menu item with a label and a command - int insert(const FbString &label, RefCount > &cmd, int pos=-1); - /// add empty menu item + int insertCommand(const FbString &label, RefCount > &cmd, int pos=-1); int insert(const FbString &label, int pos=-1); - /// add submenu - int insert(const FbString &label, Menu *submenu, int pos= -1); - /// add menu item - int insert(MenuItem *item, int pos=-1); - /// remove an item + int insertSubmenu(const FbString &label, Menu *submenu, int pos= -1); + int insertItem(MenuItem *item, int pos=-1); int remove(unsigned int item); - /// remove all items void removeAll(); void setInternalMenu(bool val = true) { m_internal_menu = val; } void setAlignment(Alignment a) { m_alignment = a; } - /// raise this window virtual void raise(); - /// lower this window virtual void lower(); - /// cycle through menuitems void cycleItems(bool reverse); - /// set and highlight new active index void setActiveIndex(int new_index); void enterSubmenu(); @@ -89,7 +79,7 @@ public: void enableTitle(); bool isTitleVisible() const { return m_title_vis; } - void setScreen(int x, int y, int w, int h); + void setScreen(int x, int y, unsigned int w, unsigned int h); /** @name event handlers @@ -103,21 +93,16 @@ public: void keyPressEvent(XKeyEvent &ke); void leaveNotifyEvent(XCrossingEvent &ce); //@} - /// get input focus void grabInputFocus(); virtual void reconfigure(); - /// set label string void setLabel(const FbTk::BiDiString &labelstr); - /// move menu to x,y virtual void move(int x, int y); virtual void updateMenu(); void setItemSelected(unsigned int index, bool val); void setItemEnabled(unsigned int index, bool val); void setMinimumColumns(int columns) { m_min_columns = columns; } virtual void drawSubmenu(unsigned int index); - /// show menu virtual void show(); - /// hide menu virtual void hide(bool force = false); virtual void clearWindow(); /*@}*/ @@ -140,7 +125,7 @@ public: int y() const { return m_window.y(); } unsigned int width() const { return m_window.width(); } unsigned int height() const { return m_window.height(); } - size_t numberOfItems() const { return menuitems.size(); } + size_t numberOfItems() const { return m_items.size(); } int currentSubmenu() const { return m_which_sub; } bool isItemSelected(unsigned int index) const; @@ -149,12 +134,11 @@ public: FbTk::ThemeProxy &theme() { return m_theme; } const FbTk::ThemeProxy &theme() const { return m_theme; } unsigned char alpha() const { return theme()->alpha(); } - static Menu *shownMenu() { return shown; } - static Menu *focused() { return s_focused; } + static Menu* shownMenu(); + static Menu* focused(); static void hideShownMenu(); - /// @return menuitem at index - const MenuItem *find(unsigned int index) const { return menuitems[index]; } - MenuItem *find(unsigned int index) { return menuitems[index]; } + const MenuItem *find(size_t i) const { return m_items[i]; } + MenuItem *find(size_t i) { return m_items[i]; } //@} /// @return true if index is valid bool validIndex(int index) const { return (index < static_cast(numberOfItems()) && index >= 0); } @@ -198,7 +182,7 @@ private: ImageControl &m_image_ctrl; typedef std::vector Menuitems; - Menuitems menuitems; + Menuitems m_items; TypeAhead m_type_ahead; Menuitems m_matches; @@ -250,8 +234,6 @@ private: // the corners std::auto_ptr m_shape; - static Menu *shown; ///< used for determining if there's a menu open at all - static Menu *s_focused; ///< holds current input focused menu, so one can determine if a menu is focused bool m_need_update; Timer m_submenu_timer; Timer m_hide_timer; diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 45e3a454..294d17a4 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -54,11 +54,7 @@ #include #include -#ifdef HAVE_CSTRING - #include -#else - #include -#endif +#include using std::string; using std::list; @@ -134,73 +130,60 @@ private: FbTk::Container::Alignment m_mode; }; + +enum { + L_TITLE = 0, + L_MODE_NONE, + L_MODE_ICONS, + L_MODE_NO_ICONS, + L_MODE_ICONS_WORKSPACE, + L_MODE_NOICONS_WORKSPACE, + L_MODE_WORKSPACE, + L_MODE_ALL, + + L_LEFT, + L_RELATIVE, + L_RIGHT, +}; + void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) { + using namespace FbTk; _FB_USES_NLS; - menu.setLabel(_FB_XTEXT(Toolbar, IconbarMode, "Iconbar Mode", "Menu title - chooses which set of icons are shown in the iconbar")); + static const FbString _labels[] = { + _FB_XTEXT(Toolbar, IconbarMode, "Iconbar Mode", "Menu title - chooses which set of icons are shown in the iconbar"), + _FB_XTEXT(Toolbar, IconbarModeNone, "None", "No icons are shown in the iconbar"), + _FB_XTEXT(Toolbar, IconbarModeIcons, "Icons", "Iconified windows from all workspaces are shown"), + _FB_XTEXT(Toolbar, IconbarModeNoIcons, "NoIcons", "No iconified windows from all workspaces are shown"), + _FB_XTEXT(Toolbar, IconbarModeWorkspaceIcons, "WorkspaceIcons", "Iconified windows from this workspace are shown"), + _FB_XTEXT(Toolbar, IconbarModeWorkspaceNoIcons, "WorkspaceNoIcons", "No iconified windows from this workspace are shown"), + _FB_XTEXT(Toolbar, IconbarModeWorkspace, "Workspace", "Normal and iconified windows from this workspace are shown"), + _FB_XTEXT(Toolbar, IconbarModeAllWindows, "All Windows", "All windows are shown"), + + _FB_XTEXT(Align, Left, "Left", "Align to the left"), + _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"), + _FB_XTEXT(Align, Right, "Right", "Align to the right"), + }; RefCount > saverc_cmd(new FbCommands::SaveResources()); + menu.setLabel(_labels[L_TITLE]); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NONE], handler, "none", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ICONS], handler, "{static groups} (minimized=yes)", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NO_ICONS], handler, "{static groups} (minimized=no)", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ICONS_WORKSPACE], handler, "{static groups} (minimized=yes) (workspace)", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_NOICONS_WORKSPACE], handler, "{static groups} (minimized=no) (workspace)", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_WORKSPACE], handler, "{static groups} (workspace)", saverc_cmd)); + menu.insertItem(new ToolbarModeMenuItem(_labels[L_MODE_ALL], handler, "{static groups}", saverc_cmd)); - menu.insert(new ToolbarModeMenuItem(_FB_XTEXT(Toolbar, IconbarModeNone, - "None", "No icons are shown in the iconbar"), - handler, - "none", saverc_cmd)); + menu.insertItem(new FbTk::MenuSeparator()); - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeIcons, - "Icons", "Iconified windows from all workspaces are shown"), - handler, - "{static groups} (minimized=yes)", saverc_cmd)); + menu.insertItem(new ToolbarAlignMenuItem(_labels[L_LEFT], handler, FbTk::Container::LEFT, saverc_cmd)); + menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RELATIVE], handler, FbTk::Container::RELATIVE, saverc_cmd)); + menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RIGHT], handler, FbTk::Container::RIGHT, saverc_cmd)); - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeNoIcons, - "NoIcons", "No iconified windows from all workspaces are shown"), - handler, - "{static groups} (minimized=no)", saverc_cmd)); - - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeWorkspaceIcons, - "WorkspaceIcons", "Iconified windows from this workspace are shown"), - handler, - "{static groups} (minimized=yes) (workspace)", saverc_cmd)); - - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeWorkspaceNoIcons, - "WorkspaceNoIcons", "No iconified windows from this workspace are shown"), - handler, - "{static groups} (minimized=no) (workspace)", saverc_cmd)); - - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeWorkspace, - "Workspace", "Normal and iconified windows from this workspace are shown"), - handler, - "{static groups} (workspace)", saverc_cmd)); - - menu.insert(new ToolbarModeMenuItem( - _FB_XTEXT(Toolbar, IconbarModeAllWindows, "All Windows", "All windows are shown"), - handler, - "{static groups}", saverc_cmd)); - - menu.insert(new FbTk::MenuSeparator()); - - menu.insert(new ToolbarAlignMenuItem( - _FB_XTEXT(Align, Left, "Left", "Align to the left"), - handler, - FbTk::Container::LEFT, saverc_cmd)); - - menu.insert(new ToolbarAlignMenuItem( - _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"), - handler, - FbTk::Container::RELATIVE, saverc_cmd)); - - menu.insert(new ToolbarAlignMenuItem( - _FB_XTEXT(Align, Right, "Right", "Align to the right"), - handler, - FbTk::Container::RIGHT, saverc_cmd)); - - menu.insert(new FbTk::MenuSeparator()); + menu.insertItem(new FbTk::MenuSeparator()); menu.updateMenu(); } @@ -280,7 +263,7 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, save_and_reconfig->add(reconfig); save_and_reconfig->add(save); RefCount > s_and_reconfig(save_and_reconfig); - m_menu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, + m_menu.insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), m_rc_use_pixmap, s_and_reconfig)); m_menu.updateMenu(); @@ -288,7 +271,7 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, m_menu.setInternalMenu(); // add iconbar menu to toolbar menu - menu.insert(m_menu.label().logical(), &m_menu); + menu.insertSubmenu(m_menu.label().logical(), &m_menu); // setup signals m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); diff --git a/src/LayerMenu.cc b/src/LayerMenu.cc index 94a6622b..7617010c 100644 --- a/src/LayerMenu.cc +++ b/src/LayerMenu.cc @@ -55,10 +55,10 @@ LayerMenu::LayerMenu(FbTk::ThemeProxy &tm, for (size_t i=0; i < 6; ++i) { // TODO: fetch nls string if (save_rc) { - insert(new LayerMenuItem(layer_menuitems[i].default_str, + insertItem(new LayerMenuItem(layer_menuitems[i].default_str, object, layer_menuitems[i].layernum, saverc_cmd)); } else { - insert(new LayerMenuItem(layer_menuitems[i].default_str, + insertItem(new LayerMenuItem(layer_menuitems[i].default_str, object, layer_menuitems[i].layernum)); } } diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 41dcf733..b2b15f5a 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -71,6 +71,60 @@ FbTk::StringConvertor s_stringconvertor(FbTk::StringConvertor::ToFbString); list s_encoding_stack; list s_stacksize_stack; + + +enum { + L_SHADE = 0, + L_MAXIMIZE, + L_ICONIFY, + L_CLOSE, + L_KILL, + L_LOWER, + L_RAISE, + L_STICK, + L_TITLE, + L_SENDTO, + L_LAYER, + + L_ALPHA, + + L_MENU_EXIT, + L_MENU_ICONS, +}; + +// returns 'label' if not empty, otherwise a (translated) default +// value based upon 'type' +const FbTk::FbString& _l(const FbTk::FbString& label, size_t type) { + + _FB_USES_NLS; + static const FbTk::FbString _default_labels[] = { + _FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"), + _FB_XTEXT(Windowmenu, Maximize, "Maximize", "Maximize the window"), + _FB_XTEXT(Windowmenu, Iconify, "Iconify", "Iconify the window"), + _FB_XTEXT(Windowmenu, Close, "Close", "Close the window"), + _FB_XTEXT(Windowmenu, Kill, "Kill", "Kill the window"), + _FB_XTEXT(Windowmenu, Lower, "Lower", "Lower the window"), + _FB_XTEXT(Windowmenu, Raise, "Raise", "Raise the window"), + _FB_XTEXT(Windowmenu, Stick, "Stick", "Stick the window"), + _FB_XTEXT(Windowmenu, SetTitle, "Set Title", "Change the title of the window"), + _FB_XTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"), + _FB_XTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"), + + _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"), + + _FB_XTEXT(Menu, Exit, "Exit", "Exit Command"), + _FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"), + }; + + if (label.empty()) { + return _default_labels[type]; + } + + return label; +} + + + /** * Push the encoding onto the stack, and make it active. */ @@ -169,7 +223,7 @@ void createStyleMenu(FbTk::Menu &parent, const string &label, (style[style.length() - 1] != '~')) || FbTk::FileUtil::isRegularFile((style + "/theme.cfg").c_str()) || FbTk::FileUtil::isRegularFile((style + "/style.cfg").c_str())) - parent.insert(new StyleMenuItem(filelist[file_index], style)); + parent.insertItem(new StyleMenuItem(filelist[file_index], style)); } // update menu graphics parent.updateMenu(); @@ -208,7 +262,7 @@ void createRootCmdMenu(FbTk::Menu &parent, const string &label, if ((FbTk::FileUtil::isRegularFile(rootcmd.c_str()) && (filelist[file_index][0] != '.') && (rootcmd[rootcmd.length() - 1] != '~'))) - parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd)); + parent.insertItem(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd)); } // update menu graphics parent.updateMenu(); @@ -289,29 +343,22 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", menu.screenNumber()); if (submenu == 0) return; - if (str_label.empty()) - menu.insert(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title")); - else - menu.insert(str_label, submenu); + menu.insertSubmenu(_l(str_label, L_MENU_ICONS), submenu); } else if (str_key == "exit") { // exit FbTk::RefCount > exit_cmd(FbTk::CommandParser::instance().parse("exit")); - if (str_label.empty()) - menu.insert(_FB_XTEXT(Menu, Exit, "Exit", "Exit Command"), exit_cmd); - else - menu.insert(str_label, exit_cmd); + menu.insertCommand(_l(str_label, L_MENU_EXIT), exit_cmd); } else if (str_key == "exec") { - // execute and hide menu FbTk::RefCount > exec_cmd(FbTk::CommandParser::instance().parse("exec " + str_cmd)); - menu.insert(str_label, exec_cmd); + menu.insertCommand(str_label, exec_cmd); } else if (str_key == "macrocmd") { FbTk::RefCount > macro_cmd(FbTk::CommandParser::instance().parse("macrocmd " + str_cmd)); - menu.insert(str_label, macro_cmd); - } else if (str_key == "style") { // style - menu.insert(new StyleMenuItem(str_label, str_cmd)); + menu.insertCommand(str_label, macro_cmd); + } else if (str_key == "style") { + menu.insertItem(new StyleMenuItem(str_label, str_cmd)); } else if (str_key == "config") { BScreen *screen = Fluxbox::instance()->findScreen(screen_number); if (screen != 0) - menu.insert(str_label, &screen->configMenu()); + menu.insertSubmenu(str_label, &screen->configMenu()); } // end of config else if (str_key == "include") { // include @@ -363,7 +410,7 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, parseMenu(parse, *submenu, labelconvertor, reloader); submenu->updateMenu(); - menu.insert(str_label, submenu); + menu.insertSubmenu(str_label, submenu); } // end of submenu else if (str_key == "stylesdir" || str_key == "stylesmenu") { @@ -383,10 +430,10 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, BScreen *screen = Fluxbox::instance()->findScreen(screen_number); if (screen != 0) { screen->workspaceMenu().setInternalMenu(); - menu.insert(str_label, &screen->workspaceMenu()); + menu.insertSubmenu(str_label, &screen->workspaceMenu()); } } else if (str_key == "separator") { - menu.insert(new FbTk::MenuSeparator()); + menu.insertItem(new FbTk::MenuSeparator()); } else if (str_key == "encoding") { startEncoding(str_cmd); } else if (str_key == "endencoding") { @@ -400,14 +447,14 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, // special NLS default labels if (str_label.empty()) { if (str_key == "reconfig" || str_key == "reconfigure") { - menu.insert(_FB_XTEXT(Menu, Reconfigure, "Reload Config", "Reload all the configs"), command); + menu.insertCommand(_FB_XTEXT(Menu, Reconfigure, "Reload Config", "Reload all the configs"), command); return; } else if (str_key == "restart") { - menu.insert(_FB_XTEXT(Menu, Restart, "Restart", "Restart Command"), command); + menu.insertCommand(_FB_XTEXT(Menu, Restart, "Restart", "Restart Command"), command); return; } } - menu.insert(str_label, command); + menu.insertCommand(str_label, command); } } if (menu.numberOfItems() != 0) { @@ -498,122 +545,85 @@ bool MenuCreator::createWindowMenuItem(const string &type, _FB_USES_NLS; static MenuContext context; + int screen = menu.screenNumber(); if (type == "shade") { static WindowMenuAccessor res(&FluxboxWindow::isShaded, &FluxboxWindow::setShaded, false); - menu.insert(new FbTk::BoolMenuItem( - label.empty()?_FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label, - res)); - + menu.insertItem(new FbTk::BoolMenuItem(_l(label, L_SHADE), res)); } else if (type == "maximize") { RefCmd maximize_cmd(new WindowCmd(&FluxboxWindow::maximizeFull)); RefCmd maximize_vert_cmd(new WindowCmd(&FluxboxWindow::maximizeVertical)); RefCmd maximize_horiz_cmd(new WindowCmd(&FluxboxWindow::maximizeHorizontal)); FbTk::MultiButtonMenuItem *maximize_item = - new FbTk::MultiButtonMenuItem(3, - label.empty()? - _FB_XTEXT(Windowmenu, Maximize, - "Maximize", "Maximize the window"): - label); - // create maximize item with: - // button1: Maximize normal - // button2: Maximize Vertical - // button3: Maximize Horizontal + new FbTk::MultiButtonMenuItem(3, _l(label, L_MAXIMIZE)); maximize_item->setCommand(1, maximize_cmd); maximize_item->setCommand(2, maximize_vert_cmd); maximize_item->setCommand(3, maximize_horiz_cmd); - menu.insert(maximize_item); + menu.insertItem(maximize_item); } else if (type == "iconify") { static WindowMenuAccessor res(&FluxboxWindow::isIconic, &FluxboxWindow::setIconic, false); - menu.insert(new FbTk::BoolMenuItem( - label.empty() ? - _FB_XTEXT(Windowmenu, Iconify, - "Iconify", "Iconify the window") : - label, res)); + menu.insertItem(new FbTk::BoolMenuItem(_l(label, L_ICONIFY), res)); } else if (type == "close") { RefCmd close_cmd(new WindowCmd(&FluxboxWindow::close)); - menu.insert(label.empty() ? - _FB_XTEXT(Windowmenu, Close, - "Close", "Close the window") : - label, close_cmd); + menu.insertCommand(_l(label, L_CLOSE), close_cmd); } else if (type == "kill" || type == "killwindow") { RefCmd kill_cmd(new WindowCmd(&FluxboxWindow::kill)); - menu.insert(label.empty() ? - _FB_XTEXT(Windowmenu, Kill, - "Kill", "Kill the window"): - label, kill_cmd); + menu.insertCommand(_l(label, L_KILL), kill_cmd); } else if (type == "lower") { RefCmd lower_cmd(new WindowCmd(&FluxboxWindow::lower)); - menu.insert( label.empty() ? - _FB_XTEXT(Windowmenu, Lower, - "Lower", "Lower the window"): - label, lower_cmd); + menu.insertCommand(_l(label, L_LOWER), lower_cmd); } else if (type == "raise") { RefCmd raise_cmd(new WindowCmd(&FluxboxWindow::raise)); - menu.insert(label.empty() ? - _FB_XTEXT(Windowmenu, Raise, - "Raise", "Raise the window"): - label, raise_cmd); - + menu.insertCommand(_l(label, L_RAISE), raise_cmd); } else if (type == "stick") { static WindowMenuAccessor res(&FluxboxWindow::isStuck, &FluxboxWindow::setStuck, false); - menu.insert(new FbTk::BoolMenuItem( - label.empty() ? - _FB_XTEXT(Windowmenu, Stick, - "Stick", "Stick the window"): - label, res)); + menu.insertItem(new FbTk::BoolMenuItem(_l(label, L_STICK), res)); } else if (type == "settitledialog") { RefCmd setname_cmd(new SetTitleDialogCmd()); - menu.insert(label.empty() ? - _FB_XTEXT(Windowmenu, SetTitle, - "Set Title", "Change the title of the window"): - label, setname_cmd); + menu.insertCommand(_l(label, L_TITLE), setname_cmd); #ifdef HAVE_XRENDER } else if (type == "alpha") { if (FbTk::Transparent::haveComposite() || FbTk::Transparent::haveRender()) { - BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); - if (screen == 0) + BScreen* s = Fluxbox::instance()->findScreen(screen); + if (s == 0) return false; FbTk::Menu *submenu = - new AlphaMenu(screen->menuTheme(), - screen->imageControl(), - *screen->layerManager().getLayer(ResourceLayer::MENU)); + new AlphaMenu(s->menuTheme(), + s->imageControl(), + *(s->layerManager()).getLayer(ResourceLayer::MENU)); submenu->disableTitle(); - menu.insert(label.empty() ? _FB_XTEXT(Configmenu, Transparency, "Transparency", - "Menu containing various transparency options"): label, - submenu); + menu.insertSubmenu(_l(label, L_ALPHA), submenu); } #endif // HAVE_XRENDER } else if (type == "extramenus") { - BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); - BScreen::ExtraMenus::iterator it = screen->extraWindowMenus().begin(); - BScreen::ExtraMenus::iterator it_end = screen->extraWindowMenus().end(); + BScreen* s = Fluxbox::instance()->findScreen(screen); + BScreen::ExtraMenus::iterator it = s->extraWindowMenus().begin(); + BScreen::ExtraMenus::iterator it_end = s->extraWindowMenus().end(); for (; it != it_end; ++it) { it->second->disableTitle(); - menu.insert(it->first, it->second); + menu.insertSubmenu(it->first, it->second); } } else if (type == "sendto") { - menu.insert(label.empty() ? _FB_XTEXT(Windowmenu, SendTo, "Send To...", "Send to menu item name"): - label, new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber()))); + menu.insertSubmenu(_l(label, L_SENDTO), + new SendToMenu(*Fluxbox::instance()->findScreen(screen))); } else if (type == "layer") { - BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); - if (screen == 0) + BScreen* s = Fluxbox::instance()->findScreen(screen); + if (s == 0) return false; - FbTk::Menu *submenu = new LayerMenu(screen->menuTheme(), - screen->imageControl(), - *screen->layerManager().getLayer(ResourceLayer::MENU), + FbTk::Menu *submenu = new LayerMenu(s->menuTheme(), + s->imageControl(), + *(s->layerManager()).getLayer(ResourceLayer::MENU), &context, false); submenu->disableTitle(); - menu.insert(label.empty()?_FB_XTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"):label, submenu); - + menu.insertSubmenu(_l(label, L_LAYER), submenu); } else if (type == "separator") { - menu.insert(new FbTk::MenuSeparator()); + menu.insertItem(new FbTk::MenuSeparator()); } else return false; diff --git a/src/Remember.cc b/src/Remember.cc index 3557439e..41d72560 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -43,12 +43,7 @@ #include "FbTk/RefCount.hh" #include "FbTk/Util.hh" -#ifdef HAVE_CSTRING - #include -#else - #include -#endif - +#include #include @@ -323,35 +318,35 @@ FbTk::Menu *createRememberMenu(BScreen &screen) { } */ _FB_USES_NLS; - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), Remember::REM_WORKSPACE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), Remember::REM_JUMPWORKSPACE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Head, "Head", "Remember Head"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Head, "Head", "Remember Head"), Remember::REM_HEAD)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), Remember::REM_DIMENSIONS)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), Remember::REM_POSITION)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), Remember::REM_STUCKSTATE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), Remember::REM_DECOSTATE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Shaded, "Shaded", "Remember shaded"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Shaded, "Shaded", "Remember shaded"), Remember::REM_SHADEDSTATE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Minimized, "Minimized", "Remember minimized"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Minimized, "Minimized", "Remember minimized"), Remember::REM_MINIMIZEDSTATE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Maximized, "Maximized", "Remember maximized"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Maximized, "Maximized", "Remember maximized"), Remember::REM_MAXIMIZEDSTATE)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Fullscreen, "Fullscreen", "Remember fullscreen"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Fullscreen, "Fullscreen", "Remember fullscreen"), Remember::REM_FULLSCREENSTATE)); if (FbTk::Transparent::haveComposite() || FbTk::Transparent::haveRender()) - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Alpha, "Transparency", "Remember window tranparency settings"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Alpha, "Transparency", "Remember window tranparency settings"), Remember::REM_ALPHA)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, Layer, "Layer", "Remember Layer"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Layer, "Layer", "Remember Layer"), Remember::REM_LAYER)); - menu->insert(new RememberMenuItem(_FB_XTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"), + menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"), Remember::REM_SAVEONCLOSE)); menu->updateMenu(); diff --git a/src/Screen.cc b/src/Screen.cc index 1a42f339..bd998689 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -1443,12 +1443,10 @@ void BScreen::rereadMenu() { FbTk::RefCount > exit_fb(FbTk::CommandParser::instance().parse("exit")); FbTk::RefCount > execute_xterm(FbTk::CommandParser::instance().parse("exec xterm")); m_rootmenu->setInternalMenu(); - m_rootmenu->insert("xterm", execute_xterm); - m_rootmenu->insert(_FB_XTEXT(Menu, Reconfigure, "Reconfigure", - "Reload Configuration command")), - m_rootmenu->insert(_FB_XTEXT(Menu, Restart, "Restart", "Restart command"), + m_rootmenu->insertCommand("xterm", execute_xterm); + m_rootmenu->insertCommand(_FB_XTEXT(Menu, Restart, "Restart", "Restart command"), restart_fb); - m_rootmenu->insert(_FB_XTEXT(Menu, Exit, "Exit", "Exit command"), + m_rootmenu->insertCommand(_FB_XTEXT(Menu, Exit, "Exit", "Exit command"), exit_fb); } @@ -1571,11 +1569,11 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { "Method used to give focus to windows"); FbTk::Menu *focus_menu = createMenu(focusmenu_label); -#define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) +#define _BOOLITEM(m,a, b, c, d, e, f) (m).insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) #define _FOCUSITEM(a, b, c, d, e) \ - focus_menu->insert(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), focusControl(), \ + focus_menu->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), focusControl(), \ e, save_and_reconfigure)) _FOCUSITEM(Configmenu, ClickFocus, @@ -1591,17 +1589,17 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FocusControl::STRICTMOUSEFOCUS); #undef _FOCUSITEM - focus_menu->insert(new FbTk::MenuSeparator()); - focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, + focus_menu->insertItem(new FbTk::MenuSeparator()); + focus_menu->insertItem(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, ClickTabFocus, "ClickTabFocus", "Click tab to focus windows"), focusControl(), FocusControl::CLICKTABFOCUS, save_and_reconfigure)); - focus_menu->insert(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, + focus_menu->insertItem(new TabFocusModelMenuItem(_FB_XTEXT(Configmenu, MouseTabFocus, "MouseTabFocus", "Hover over tab to focus windows"), focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure)); - focus_menu->insert(new FbTk::MenuSeparator()); + focus_menu->insertItem(new FbTk::MenuSeparator()); try { - focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, + focus_menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, "Focus New Windows", "Focus newly created windows"), m_resource_manager.getResource(name() + ".focusNewWindows"), saverc_cmd)); @@ -1611,7 +1609,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { #ifdef XINERAMA try { - focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusSameHead, + focus_menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusSameHead, "Keep Head", "Only revert focus on same head"), m_resource_manager.getResource(name() + ".focusSameHead"), saverc_cmd)); @@ -1629,7 +1627,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { focus_menu->updateMenu(); - menu.insert(focusmenu_label, focus_menu); + menu.insertSubmenu(focusmenu_label, focus_menu); // END focus menu @@ -1654,7 +1652,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { resource.max_disable_resize, saverc_cmd); maxmenu->updateMenu(); - menu.insert(maxmenu_label, maxmenu); + menu.insertSubmenu(maxmenu_label, maxmenu); // END maximize menu @@ -1667,15 +1665,15 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::FbString tabplacement_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); FbTk::Menu *tabplacement_menu = createToggleMenu(tabplacement_label); - tab_menu->insert(tabplacement_label, tabplacement_menu); + tab_menu->insertSubmenu(tabplacement_label, tabplacement_menu); _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar, "Tabs in Titlebar", "Tabs in Titlebar", resource.default_internal_tabs, save_and_reconftabs); - tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, + tab_menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, "Maximize Over", "Maximize over this thing when maximizing"), resource.max_over_tabs, save_and_reconfigure)); - tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, + tab_menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), resource.tabs_use_pixmap, save_and_reconfigure)); @@ -1686,7 +1684,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { resource.tab_width, 10, 3000, /* silly number */ *tab_menu); tab_width_item->setCommand(save_and_reconftabs); - tab_menu->insert(tab_width_item); + tab_menu->insertItem(tab_width_item); // menu is 3 wide, 5 down struct PlacementP { @@ -1720,11 +1718,11 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { tabplacement_menu->insert(p.label); tabplacement_menu->setItemEnabled(i, false); } else - tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); + tabplacement_menu->insertItem(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); } tabplacement_menu->updateMenu(); - menu.insert(tabmenu_label, tab_menu); + menu.insertSubmenu(tabmenu_label, tab_menu); #ifdef HAVE_XRENDER if (FbTk::Transparent::haveRender() || @@ -1737,7 +1735,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { if (FbTk::Transparent::haveComposite(true)) { static FbTk::SimpleAccessor s_pseudo(Fluxbox::instance()->getPseudoTrans()); - alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, + alpha_menu->insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), s_pseudo, save_and_reconfigure)); @@ -1754,7 +1752,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { "Transparency level of the focused window"), resource.focused_alpha, 0, 255, *alpha_menu); focused_alpha_item->setCommand(delayed_save_and_reconf); - alpha_menu->insert(focused_alpha_item); + alpha_menu->insertItem(focused_alpha_item); FbTk::MenuItem *unfocused_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, @@ -1764,24 +1762,24 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { resource.unfocused_alpha, 0, 255, *alpha_menu); unfocused_alpha_item->setCommand(delayed_save_and_reconf); - alpha_menu->insert(unfocused_alpha_item); + alpha_menu->insertItem(unfocused_alpha_item); FbTk::MenuItem *menu_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu"), resource.menu_alpha, 0, 255, *alpha_menu); menu_alpha_item->setCommand(delayed_save_and_reconf); - alpha_menu->insert(menu_alpha_item); + alpha_menu->insertItem(menu_alpha_item); alpha_menu->updateMenu(); - menu.insert(alphamenu_label, alpha_menu); + menu.insertSubmenu(alphamenu_label, alpha_menu); } #endif // HAVE_XRENDER Configmenus::iterator it = m_configmenu_list.begin(); Configmenus::iterator it_end = m_configmenu_list.end(); for (; it != it_end; ++it) - menu.insert(it->first, it->second); + menu.insertSubmenu(it->first, it->second); _BOOLITEM(menu, Configmenu, OpaqueMove, "Opaque Window Moving", diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc index afdc854a..120a9398 100644 --- a/src/SendToMenu.cc +++ b/src/SendToMenu.cc @@ -84,12 +84,12 @@ void SendToMenu::rebuildMenu() { for (size_t i = 0; i < wlist.size(); ++i) { FbTk::RefCount > sendto_cmd(new SendToCmd(i, false)); FbTk::RefCount > sendto_follow_cmd(new SendToCmd(i, true)); - + FbTk::MultiButtonMenuItem* item = new FbTk::MultiButtonMenuItem(3, wlist[i]->name()); item->setCommand(1, sendto_cmd); item->setCommand(2, sendto_follow_cmd); item->setCommand(3, sendto_cmd); - insert(item); + insertItem(item); } updateMenu(); diff --git a/src/Slit.cc b/src/Slit.cc index 46390c72..1851a16a 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -1099,21 +1099,21 @@ void Slit::updateClientmenu() { FbTk::RefCount > cycle_up(new FbTk::SimpleCommand(*this, &Slit::cycleClientsUp)); FbTk::RefCount > cycle_down(new FbTk::SimpleCommand(*this, &Slit::cycleClientsDown)); - m_clientlist_menu.insert(_FB_XTEXT(Slit, CycleUp, "Cycle Up", "Cycle clients upwards"), cycle_up); - m_clientlist_menu.insert(_FB_XTEXT(Slit, CycleDown, "Cycle Down", "Cycle clients downwards"), cycle_down); + m_clientlist_menu.insertCommand(_FB_XTEXT(Slit, CycleUp, "Cycle Up", "Cycle clients upwards"), cycle_up); + m_clientlist_menu.insertCommand(_FB_XTEXT(Slit, CycleDown, "Cycle Down", "Cycle clients downwards"), cycle_down); - m_clientlist_menu.insert(new FbTk::MenuSeparator()); + m_clientlist_menu.insertItem(new FbTk::MenuSeparator()); FbTk::RefCount > reconfig(new FbTk::SimpleCommand(*this, &Slit::reconfigure)); SlitClients::iterator it = m_client_list.begin(); for (; it != m_client_list.end(); ++it) { if ((*it) != 0 && (*it)->window() != 0) - m_clientlist_menu.insert(new SlitClientMenuItem(*this, *(*it), reconfig)); + m_clientlist_menu.insertItem(new SlitClientMenuItem(*this, *(*it), reconfig)); } - m_clientlist_menu.insert(new FbTk::MenuSeparator()); + m_clientlist_menu.insertItem(new FbTk::MenuSeparator()); FbTk::RefCount > savecmd(new FbTk::SimpleCommand(*this, &Slit::saveClientList)); - m_clientlist_menu.insert(_FB_XTEXT(Slit, + m_clientlist_menu.insertCommand(_FB_XTEXT(Slit, SaveSlitList, "Save SlitList", "Saves the current order in the slit"), savecmd); @@ -1165,31 +1165,32 @@ void Slit::setupMenu() { // setup base menu m_slitmenu.setLabel(_FB_XTEXT(Slit, Slit, "Slit", "The Slit")); - m_slitmenu.insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), - placement_menu); + m_slitmenu.insertSubmenu( + _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), + placement_menu); - m_slitmenu.insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), m_layermenu.get()); + m_slitmenu.insertSubmenu( + _FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), + m_layermenu.get()); #ifdef XINERAMA if (screen().hasXinerama()) { - m_slitmenu.insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), - m_xineramaheadmenu = - new XineramaHeadMenu( - screen().menuTheme(), - screen(), - screen().imageControl(), - *screen().layerManager().getLayer(::ResourceLayer::MENU), - *this, - _FB_XTEXT(Slit, OnHead, "Slit on Head", "Title of Slits On Head menu") - )); + m_xineramaheadmenu = new XineramaHeadMenu( + screen().menuTheme(), + screen(), + screen().imageControl(), + *screen().layerManager().getLayer(::ResourceLayer::MENU), + *this, + _FB_XTEXT(Slit, OnHead, "Slit on Head", "Title of Slits On Head menu")); + m_slitmenu.insertSubmenu(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), m_xineramaheadmenu); } #endif //XINERAMA - m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), + m_slitmenu.insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), m_rc_auto_hide, save_and_reconfigure_slit)); - m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), + m_slitmenu.insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), m_rc_maximize_over, save_and_reconfigure_slit)); @@ -1206,9 +1207,9 @@ void Slit::setupMenu() { RefCount > set_alpha_cmd(alpha_macrocmd); alpha_menuitem->setCommand(set_alpha_cmd); - m_slitmenu.insert(alpha_menuitem); + m_slitmenu.insertItem(alpha_menuitem); - m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu); + m_slitmenu.insertSubmenu(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu); m_slitmenu.updateMenu(); // setup sub menu @@ -1249,10 +1250,8 @@ void Slit::setupMenu() { placement_menu->insert(""); placement_menu->setItemEnabled(i, false); } else { - placement_menu->insert(new PlaceSlitMenuItem(str, *this, - placement, - save_and_reconfigure)); - + FbTk::MenuItem* item = new PlaceSlitMenuItem(str, *this, placement, save_and_reconfigure); + placement_menu->insertItem(item); } place_menu.pop_front(); } @@ -1268,7 +1267,6 @@ void Slit::moveToLayer(int layernum) { void Slit::saveOnHead(int head) { m_rc_on_head = head; - // reposition reconfigure(); } diff --git a/src/Toolbar.cc b/src/Toolbar.cc index c65e9ca9..f7b01634 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -271,9 +271,13 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): } Toolbar::~Toolbar() { - if (Fluxbox::instance()->keys()) - Fluxbox::instance()->keys()->unregisterWindow(window().window()); + + Keys* keys = Fluxbox::instance()->keys(); + if (keys) + keys->unregisterWindow(window().window()); + FbTk::EventManager::instance()->remove(window()); + // remove menu items before we delete tools so we dont end up // with dangling pointers to old submenu items (internal menus) // from the tools @@ -786,11 +790,11 @@ void Toolbar::setupMenus(bool skip_new_placement) { visible_macro->add(reconfig_toolbar); visible_macro->add(save_resources); RefCommand toggle_visible_cmd(visible_macro); - menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, + menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, "Visible", "Whether this item is visible"), m_rc_visible, toggle_visible_cmd)); - menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, + menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "Toggle auto hide of toolbar"), m_rc_auto_hide, reconfig_toolbar_and_save_resource)); @@ -804,25 +808,24 @@ void Toolbar::setupMenus(bool skip_new_placement) { toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); - menu().insert(toolbar_menuitem); + menu().insertItem(toolbar_menuitem); - menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, + menu().insertItem(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, "Maximize Over", "Maximize over this thing when maximizing"), m_rc_maximize_over, reconfig_toolbar_and_save_resource)); - menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); + menu().insertSubmenu(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); #ifdef XINERAMA if (screen().hasXinerama()) { - menu().insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), - m_xineramaheadmenu = - new XineramaHeadMenu(screen().menuTheme(), - screen(), - screen().imageControl(), - *screen().layerManager().getLayer(::ResourceLayer::MENU), - *this, - _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", - "Title of toolbar on head menu"))); + + m_xineramaheadmenu = new XineramaHeadMenu(screen().menuTheme(), + screen(), + screen().imageControl(), + *screen().layerManager().getLayer(::ResourceLayer::MENU), + *this, + _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", "Title of toolbar on head menu")); + menu().insertSubmenu(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), m_xineramaheadmenu); } #endif // XINERAMA @@ -860,12 +863,12 @@ void Toolbar::setupMenus(bool skip_new_placement) { placementMenu().insert(p.label); placementMenu().setItemEnabled(i, false); } else - placementMenu().insert(new PlaceToolbarMenuItem(p.label, *this, + placementMenu().insertItem(new PlaceToolbarMenuItem(p.label, *this, p.placement)); } } - menu().insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); + menu().insertSubmenu(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); placementMenu().updateMenu(); @@ -882,7 +885,7 @@ void Toolbar::setupMenus(bool skip_new_placement) { RefCount > set_alpha_cmd(alpha_macrocmd); alpha_menuitem->setCommand(set_alpha_cmd); - menu().insert(alpha_menuitem); + menu().insertItem(alpha_menuitem); menu().updateMenu(); } diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc index d73947bb..d4be3535 100644 --- a/src/WorkspaceMenu.cc +++ b/src/WorkspaceMenu.cc @@ -60,7 +60,7 @@ void add_workspaces(WorkspaceMenu& menu, BScreen& screen) { FbTk::MultiButtonMenuItem* submenu = new FbTk::MultiButtonMenuItem(5, FbTk::BiDiString(w->name()), &w->menu()); FbTk::RefCount > jump_cmd(new JumpToWorkspaceCmd(w->workspaceID())); submenu->setCommand(3, jump_cmd); - menu.insert(submenu, i + IDX_AFTER_ICONS); + menu.insertItem(submenu, i + IDX_AFTER_ICONS); } } @@ -111,9 +111,9 @@ void WorkspaceMenu::init(BScreen &screen) { removeAll(); setLabel(_FB_XTEXT(Workspace, MenuTitle, "Workspaces", "Title of main workspace menu")); - insert(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"), + insertSubmenu(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"), MenuCreator::createMenuType("iconmenu", screen.screenNumber())); - insert(new FbTk::MenuSeparator()); + insertItem(new FbTk::MenuSeparator()); ::add_workspaces(*this, screen); setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true); @@ -134,12 +134,12 @@ void WorkspaceMenu::init(BScreen &screen) { RefCount > start_edit(FbTk::CommandParser::instance().parse("setworkspacenamedialog")); - insert(new FbTk::MenuSeparator()); - insert(_FB_XTEXT(Workspace, NewWorkspace, "New Workspace", "Add a new workspace"), + insertItem(new FbTk::MenuSeparator()); + insertCommand(_FB_XTEXT(Workspace, NewWorkspace, "New Workspace", "Add a new workspace"), new_workspace_cmd); - insert(_FB_XTEXT(Toolbar, EditWkspcName, "Edit current workspace name", "Edit current workspace name"), + insertCommand(_FB_XTEXT(Toolbar, EditWkspcName, "Edit current workspace name", "Edit current workspace name"), start_edit); - insert(_FB_XTEXT(Workspace, RemoveLast, "Remove Last", "Remove the last workspace"), + insertCommand(_FB_XTEXT(Workspace, RemoveLast, "Remove Last", "Remove the last workspace"), remove_last_cmd); updateMenu(); diff --git a/src/Xinerama.hh b/src/Xinerama.hh index b0ff70e3..5d305ed3 100644 --- a/src/Xinerama.hh +++ b/src/Xinerama.hh @@ -51,7 +51,7 @@ public: m_object.saveOnHead(m_headnum); FbTk::RadioMenuItem::click(button, time, mods); } - + private: ItemType &m_object; int m_headnum; @@ -103,11 +103,11 @@ void XineramaHeadMenu::reloadHeads() */ std::string tname("Head "); tname += FbTk::StringUtil::number2String(i); - insert(new XineramaHeadMenuItem( + insertItem(new XineramaHeadMenuItem( tname.c_str(), m_object, i, saverc_cmd)); } // TODO: nls - insert(new XineramaHeadMenuItem( + insertItem(new XineramaHeadMenuItem( "All Heads", m_object, 0, saverc_cmd)); updateMenu(); }