From 34649e86c5cbe9c9f231c049a0844afdda5a7db9 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 2 Jul 2011 17:21:24 +0200 Subject: Store menus if smart pointers (RefCount) This was originally intended to be a bugfix for an memory error reported by valgrind (accessing freed memory). While debugging it, I found the menu ownership semantics confusing (setInternalMenu() et al.), so I decided to get rid of it and store it in smart pointers everywhere. Looking back, I'm not sure if this was worth all the trouble, but the good news is that the valgrind error disappeared. :) --- src/FbCommands.cc | 2 +- src/FbTk/Menu.cc | 24 +++---------- src/FbTk/Menu.hh | 4 +-- src/FbTk/MenuItem.cc | 1 - src/FbTk/MenuItem.hh | 10 +++--- src/FbTk/MultiButtonMenuItem.cc | 3 +- src/FbTk/MultiButtonMenuItem.hh | 2 +- src/FbTk/RadioMenuItem.hh | 2 +- src/IconbarTool.cc | 18 +++++----- src/IconbarTool.hh | 2 +- src/MenuCreator.cc | 50 +++++++++++++------------- src/MenuCreator.hh | 3 +- src/Remember.cc | 4 +-- src/Screen.cc | 63 +++++++++----------------------- src/Screen.hh | 24 ++++++------- src/Slit.cc | 78 +++++++++++++++++++--------------------- src/Slit.hh | 8 ++--- src/ToolFactory.cc | 6 ++-- src/Toolbar.cc | 79 +++++++++++++++++++---------------------- src/Toolbar.hh | 18 +++++----- src/Workspace.cc | 12 +++---- src/Workspace.hh | 6 ++-- src/WorkspaceMenu.cc | 5 ++- 23 files changed, 179 insertions(+), 245 deletions(-) diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 02a614a..fa4c823 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -372,7 +372,7 @@ void ShowWorkspaceMenuCmd::execute() { if (screen == 0) return; - ::showMenu(*screen, screen->workspaceMenu()); + ::showMenu(*screen, *screen->workspaceMenu()); } REGISTER_COMMAND_WITH_ARGS(setworkspacename, FbCommands::SetWorkspaceNameCmd, void); diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index b6b4ec6..49e71e6 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -126,8 +126,7 @@ Menu::Menu(FbTk::ThemeProxy &tm, ImageControl &imgctrl): m_title_vis = true; - m_internal_menu = - m_moving = + m_moving = m_closing = m_torn = m_visible = false; @@ -227,7 +226,7 @@ int Menu::insert(const FbString &label, int pos) { return insert(new MenuItem(label, *this), pos); } -int Menu::insert(const FbString &label, Menu *submenu, int pos) { +int Menu::insert(const FbString &label, const RefCount &submenu, int pos) { return insert(new MenuItem(label, submenu, this), pos); } @@ -274,19 +273,6 @@ int Menu::remove(unsigned int index) { if (index != menuitems.size()) fixMenuItemIndices(); - if (item->submenu() != 0) { - Menu *tmp = item->submenu(); - // if menu is internal we should just hide it instead - // if destroying it - if (! tmp->m_internal_menu) { - delete tmp; - } - // We can't internal_hide here, as the child may be deleted! -// } else -// tmp->internal_hide(); - } - - delete item; } @@ -374,8 +360,8 @@ void Menu::enterSubmenu() { if (!validIndex(m_active_index)) return; - Menu *submenu = menuitems[m_active_index]->submenu(); - if (submenu == 0) + RefCount submenu = menuitems[m_active_index]->submenu(); + if (! submenu) return; if (submenu->menuitems.empty()) @@ -759,7 +745,7 @@ void Menu::drawSubmenu(unsigned int index) { clearItem(index); if (! item->submenu()->isVisible() && item->submenu()->numberOfItems() > 0) { - shown = item->submenu(); + shown = item->submenu().get(); item->showSubmenu(); item->submenu()->raise(); } diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 4096295..5807592 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh @@ -65,14 +65,13 @@ public: /// add empty menu item int insert(const FbString &label, int pos=-1); /// add submenu - int insert(const FbString &label, Menu *submenu, int pos= -1); + int insert(const FbString &label, const RefCount &submenu, int pos= -1); /// add menu item int insert(MenuItem *item, int pos=-1); /// remove an item 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 @@ -213,7 +212,6 @@ private: bool m_closing; ///< if we're right clicking on the menu title bool m_visible; ///< menu visibility bool m_torn; ///< torn from parent - bool m_internal_menu; ///< whether we should destroy this menu or if it's managed somewhere else bool m_title_vis; ///< title visibility int m_which_sub; diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc index c1357fb..36ff442 100644 --- a/src/FbTk/MenuItem.cc +++ b/src/FbTk/MenuItem.cc @@ -27,7 +27,6 @@ #include "Image.hh" #include "App.hh" #include "StringUtil.hh" -#include "Menu.hh" #include namespace FbTk { diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh index cc24228..227488f 100644 --- a/src/FbTk/MenuItem.hh +++ b/src/FbTk/MenuItem.hh @@ -22,6 +22,7 @@ #ifndef FBTK_MENUITEM_HH #define FBTK_MENUITEM_HH +#include "Menu.hh" #include "RefCount.hh" #include "Command.hh" #include "PixmapWithMask.hh" @@ -32,7 +33,6 @@ namespace FbTk { -class Menu; class MenuTheme; class FbDrawable; template class ThemeProxy; @@ -80,7 +80,7 @@ public: m_toggle_item(false) { } - MenuItem(const BiDiString &label, Menu *submenu, Menu *host_menu = 0) + MenuItem(const BiDiString &label, const RefCount &submenu, Menu *host_menu = 0) : m_label(label), m_menu(host_menu), m_submenu(submenu), @@ -98,7 +98,7 @@ public: virtual void setToggleItem(bool val) { m_toggle_item = val; } void setCloseOnClick(bool val) { m_close_on_click = val; } void setIcon(const std::string &filename, int screen_num); - virtual Menu *submenu() { return m_submenu; } + virtual const RefCount& submenu() { return m_submenu; } /** @name accessors */ @@ -107,7 +107,7 @@ public: virtual const PixmapWithMask *icon() const { return m_icon.get() ? m_icon->pixmap.get() : 0; } - virtual const Menu *submenu() const { return m_submenu; } + virtual RefCount submenu() const { return m_submenu; } virtual bool isEnabled() const { return m_enabled; } virtual bool isSelected() const { return m_selected; } virtual bool isToggleItem() const { return m_toggle_item; } @@ -150,7 +150,7 @@ public: private: BiDiString m_label; ///< label of this item Menu *m_menu; ///< the menu we live in - Menu *m_submenu; ///< a submenu, 0 if we don't have one + RefCount m_submenu; ///< a submenu, 0 if we don't have one RefCount > m_command; ///< command to be executed bool m_enabled, m_selected; bool m_close_on_click, m_toggle_item; diff --git a/src/FbTk/MultiButtonMenuItem.cc b/src/FbTk/MultiButtonMenuItem.cc index f5b9990..359e96c 100644 --- a/src/FbTk/MultiButtonMenuItem.cc +++ b/src/FbTk/MultiButtonMenuItem.cc @@ -33,7 +33,8 @@ MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &la init(buttons); } -MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &label, Menu *submenu): +MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &label, + const RefCount &submenu): MenuItem(label, submenu), m_button_exe(0), m_buttons(buttons) { diff --git a/src/FbTk/MultiButtonMenuItem.hh b/src/FbTk/MultiButtonMenuItem.hh index 0a9c5e6..427302c 100644 --- a/src/FbTk/MultiButtonMenuItem.hh +++ b/src/FbTk/MultiButtonMenuItem.hh @@ -31,7 +31,7 @@ namespace FbTk { class MultiButtonMenuItem: public FbTk::MenuItem { public: MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label); - MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label, Menu *submenu); + MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label, const RefCount &submenu); virtual ~MultiButtonMenuItem(); /// sets command to specified button void setCommand(int button, FbTk::RefCount > &cmd); diff --git a/src/FbTk/RadioMenuItem.hh b/src/FbTk/RadioMenuItem.hh index ddd2274..cc3f00a 100644 --- a/src/FbTk/RadioMenuItem.hh +++ b/src/FbTk/RadioMenuItem.hh @@ -47,7 +47,7 @@ public: setToggleItem(true); } - RadioMenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0): + RadioMenuItem(const FbString &label, const RefCount &submenu, Menu *host_menu = 0): MenuItem(label, submenu, host_menu) { setToggleItem(true); } diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index ebf67fe..070e45b 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -246,12 +246,12 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, m_rc_client_padding(screen.resourceManager(), 10, screen.name() + ".iconbar.iconTextPadding"), m_rc_use_pixmap(screen.resourceManager(), true, screen.name() + ".iconbar.usePixmap"), - m_menu(screen.menuTheme(), screen.imageControl(), - *screen.layerManager().getLayer(ResourceLayer::MENU)), + m_menu(new FbMenu(screen.menuTheme(), screen.imageControl(), + *screen.layerManager().getLayer(ResourceLayer::MENU)) ), m_alpha(255) { // setup mode menu - setupModeMenu(m_menu, *this); + setupModeMenu(*m_menu, *this); _FB_USES_NLS; using namespace FbTk; // setup use pixmap item to reconfig iconbar and save resource on click @@ -261,15 +261,13 @@ 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->insert(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(); - // must be internal menu, otherwise toolbar main menu tries to delete it. - m_menu.setInternalMenu(); + m_menu->updateMenu(); // add iconbar menu to toolbar menu - menu.insert(m_menu.label().logical(), &m_menu); + menu.insert(m_menu->label().logical(), FbTk::RefCount(m_menu)); // setup signals m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); @@ -313,7 +311,7 @@ void IconbarTool::hide() { void IconbarTool::setAlignment(FbTk::Container::Alignment align) { *m_rc_alignment = align; update(ALIGN, NULL); - m_menu.reconfigure(); + m_menu->reconfigure(); } void IconbarTool::setMode(string mode) { @@ -353,7 +351,7 @@ void IconbarTool::setMode(string mode) { renderTheme(); - m_menu.reconfigure(); + m_menu->reconfigure(); } unsigned int IconbarTool::width() const { diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 90df5cf..754cd50 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -116,7 +116,7 @@ private: FbTk::IntResource m_rc_client_width; ///< size of client button in LEFT/RIGHT mode FbTk::UIntResource m_rc_client_padding; ///< padding of the text FbTk::BoolResource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not - FbMenu m_menu; + FbTk::RefCount m_menu; int m_alpha; }; diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 6a6accc..46f233d 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -66,10 +66,10 @@ using FbTk::AutoReloadHelper; namespace { -std::auto_ptr createStyleMenu(int screen_number, const string &label, +FbTk::RefCount createStyleMenu(int screen_number, const string &label, AutoReloadHelper *reloader, const string &directory) { - std::auto_ptr menu(MenuCreator::createMenu(label, screen_number)); + FbTk::RefCount menu(MenuCreator::createMenu(label, screen_number)); // perform shell style ~ home directory expansion string stylesdir(FbTk::StringUtil::expandFilename(directory)); @@ -107,11 +107,11 @@ std::auto_ptr createStyleMenu(int screen_number, const string &label, return menu; } -std::auto_ptr createRootCmdMenu(int screen_number, const string &label, +FbTk::RefCount createRootCmdMenu(int screen_number, const string &label, const string &directory, AutoReloadHelper *reloader, const string &cmd) { - std::auto_ptr menu(MenuCreator::createMenu(label, screen_number)); + FbTk::RefCount menu(MenuCreator::createMenu(label, screen_number)); // perform shell style ~ home directory expansion string rootcmddir(FbTk::StringUtil::expandFilename(directory)); @@ -267,8 +267,8 @@ insertMenuItem(lua::state &l, FbTk::Menu &menu, FbTk::StringConvertor &parent_co int size = menu.insert(str_label); menu.setItemEnabled(size-1, false); } else if(str_key == "icons") { - FbTk::Menu *submenu = MenuCreator::createMenuType("iconmenu", screen_number); - if (submenu == 0) + FbTk::RefCount submenu = MenuCreator::createMenuType("iconmenu", screen_number); + if (! submenu) return; if (str_label.empty()) menu.insert(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"), submenu); @@ -281,12 +281,12 @@ insertMenuItem(lua::state &l, FbTk::Menu &menu, FbTk::StringConvertor &parent_co else menu.insert(str_label, exit_cmd); } else if (str_key == "config") { - menu.insert(str_label, &screen->configMenu()); + menu.insert(str_label, FbTk::RefCount(screen->configMenu()) ); } else if(str_key == "menu") { - std::auto_ptr t(MenuCreator::createMenu("", screen_number)); + FbTk::RefCount t(MenuCreator::createMenu("", screen_number)); l.pushvalue(-1); createMenu_(*t, l, *conv, reloader); - menu.insert(str_label, t.release()); + menu.insert(str_label, t); } else { // items that have a parameter const string &str_cmd = getField(l, -1, "param"); @@ -301,16 +301,15 @@ insertMenuItem(lua::state &l, FbTk::Menu &menu, FbTk::StringConvertor &parent_co menu.insert(new StyleMenuItem(str_label, str_cmd)); else if (str_key == "stylesdir") menu.insert(str_label, - createStyleMenu(screen_number, str_label, reloader, str_cmd).release()); + createStyleMenu(screen_number, str_label, reloader, str_cmd)); else if (str_key == "wallpapers") { string program = getField(l, -1, "program"); if(program.empty()) program = realProgramName("fbsetbg"); menu.insert(str_label, createRootCmdMenu(screen_number, str_label, str_cmd, - reloader, program).release() ); + reloader, program) ); } else if (str_key == "workspaces") { - screen->workspaceMenu().setInternalMenu(); - menu.insert(str_label, &screen->workspaceMenu()); + menu.insert(str_label, FbTk::RefCount(screen->workspaceMenu()) ); } else { // finally, try window-related commands MenuCreator::createWindowMenuItem(str_key, str_label, menu); @@ -396,17 +395,17 @@ void MenuCreator::createFromFile(const string &filename, createMenu(inject_into, l, reloader); } -FbMenu *MenuCreator::createMenuType(const string &type, int screen_num) { +FbTk::RefCount MenuCreator::createMenuType(const string &type, int screen_num) { + FbTk::RefCount menu; BScreen *screen = Fluxbox::instance()->findScreen(screen_num); - if (screen == 0) - return 0; + if (type == "iconmenu") - return new ClientMenu(*screen, screen->iconList(), - true); // listen to icon list changes + menu.reset(new ClientMenu(*screen, screen->iconList(), + true)); // listen to icon list changes else if (type == "workspacemenu") - return new WorkspaceMenu(*screen); + menu.reset(new WorkspaceMenu(*screen)); - return 0; + return menu; } bool MenuCreator::createWindowMenuItem(const string &type, @@ -494,10 +493,9 @@ bool MenuCreator::createWindowMenuItem(const string &type, if (screen == 0) return false; - FbTk::Menu *submenu = - new AlphaMenu(screen->menuTheme(), + FbTk::RefCount submenu( new AlphaMenu(screen->menuTheme(), screen->imageControl(), - *screen->layerManager().getLayer(ResourceLayer::MENU)); + *screen->layerManager().getLayer(ResourceLayer::MENU)) ); submenu->disableTitle(); menu.insert(label.empty() ? _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"): label, @@ -515,17 +513,17 @@ bool MenuCreator::createWindowMenuItem(const string &type, } 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()))); + label, FbTk::RefCount(new SendToMenu(*Fluxbox::instance()->findScreen(menu.screenNumber()))) ); } else if (type == "layer") { BScreen *screen = Fluxbox::instance()->findScreen(menu.screenNumber()); if (screen == 0) return false; - FbTk::Menu *submenu = new LayerMenu(screen->menuTheme(), + FbTk::RefCount submenu( new LayerMenu(screen->menuTheme(), screen->imageControl(), *screen->layerManager().getLayer(ResourceLayer::MENU), &context, - false); + false) ); submenu->disableTitle(); menu.insert(label.empty()?_FB_XTEXT(Windowmenu, Layer, "Layer ...", "Layer menu"):label, submenu); diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 60f931d..cdbba0c 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh @@ -24,6 +24,7 @@ #define MENUCREATOR_HH #include "FbTk/FbString.hh" +#include "FbTk/RefCount.hh" #include #include @@ -44,7 +45,7 @@ namespace MenuCreator { void createMenu(FbTk::Menu &inject_into, lua::state &l, FbTk::AutoReloadHelper *reloader = NULL); FbMenu *createMenu(const std::string &label, int screen_num); - FbMenu *createMenuType(const std::string &label, int screen_num); + FbTk::RefCount createMenuType(const std::string &label, int screen_num); void createFromFile(const std::string &filename, FbTk::Menu &inject_into, FbTk::AutoReloadHelper *reloader = NULL); diff --git a/src/Remember.cc b/src/Remember.cc index 626522c..294e1d5 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -312,10 +312,10 @@ private: Remember::Attribute m_attrib; }; -FbTk::Menu *createRememberMenu(BScreen &screen) { +FbTk::RefCount createRememberMenu(BScreen &screen) { // each fluxboxwindow has its own windowmenu // so we also create a remember menu just for it... - FbTk::Menu *menu = screen.createMenu("Remember"); + FbTk::RefCount menu( screen.createMenu("Remember") ); // if enabled, then we want this to be a unavailable menu /* diff --git a/src/Screen.cc b/src/Screen.cc index 73ccb4c..78932ae 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -42,7 +42,6 @@ #include "FbTk/RadioMenuItem.hh" // menus -#include "FbMenu.hh" #include "LayerMenu.hh" #include "MenuCreator.hh" @@ -427,7 +426,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, m_current_workspace = m_workspaces_list.front(); m_windowmenu.reset(createMenu("")); - m_windowmenu->setInternalMenu(); m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadWindowMenu))); @@ -438,7 +436,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration, "Configuration", "Title of configuration menu"))); setupConfigmenu(*m_configmenu.get()); - m_configmenu->setInternalMenu(); // check which desktop we should start on unsigned int first_desktop = 0; @@ -485,34 +482,7 @@ BScreen::~BScreen() { // we need to destroy it before we destroy workspaces m_workspacemenu.reset(0); - if (m_extramenus.size()) { - // check whether extramenus are included in windowmenu - // if not, we clean them ourselves - bool extramenus_in_windowmenu = false; - for (size_t i = 0, n = m_windowmenu->numberOfItems(); i < n; i++) - if (m_windowmenu->find(i)->submenu() == m_extramenus.begin()->second) { - extramenus_in_windowmenu = true; - break; - } - - ExtraMenus::iterator mit = m_extramenus.begin(); - ExtraMenus::iterator mit_end = m_extramenus.end(); - for (; mit != mit_end; ++mit) { - // we set them to NOT internal so that they will be deleted when the - // menu is cleaned up. We can't delete them here because they are - // still in the menu - // (They need to be internal for most of the time so that if we - // rebuild the menu, then they won't be removed. - if (! extramenus_in_windowmenu) { - // not attached to our windowmenu - // so we clean it up - delete mit->second; - } else { - // let the parent clean it up - mit->second->setInternalMenu(false); - } - } - } + m_extramenus.clear(); removeWorkspaceNames(); using namespace FbTk::STLUtil; @@ -540,9 +510,9 @@ BScreen::~BScreen() { m_slit.reset(0); - delete m_rootmenu.release(); - delete m_workspacemenu.release(); - delete m_windowmenu.release(); + m_rootmenu.reset(0); + m_workspacemenu.reset(0); + m_windowmenu.reset(0); // TODO fluxgen: check if this is the right place for (size_t i = 0; i < m_head_areas.size(); i++) @@ -835,8 +805,8 @@ FbMenu *BScreen::createToggleMenu(const string &label) { return menu; } -void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) { - menu->setInternalMenu(); +void +BScreen::addExtraWindowMenu(const FbTk::FbString &label, const FbTk::RefCount &menu) { menu->disableTitle(); m_extramenus.push_back(make_pair(label, menu)); rereadWindowMenu(); @@ -1384,7 +1354,7 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id, } void BScreen::initMenus() { - m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); + m_workspacemenu = MenuCreator::createMenuType("workspacemenu", screenNumber()); m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); m_windowmenu->reloadHelper()->setMainFile(windowMenuFilename()); @@ -1410,7 +1380,6 @@ void BScreen::rereadMenu() { FbTk::RefCount > restart_fb(FbTk::CommandParser::instance().parse("restart")); 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")), @@ -1441,16 +1410,16 @@ void BScreen::rereadWindowMenu() { MenuCreator::createMenu(*m_windowmenu, l, m_windowmenu->reloadHelper()); } -void BScreen::addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu) { - m_configmenu_list.push_back(make_pair(label, &menu)); +void BScreen::addConfigMenu(const FbTk::FbString &label, const FbTk::RefCount &menu) { + m_configmenu_list.push_back(make_pair(label, menu)); if (m_configmenu.get()) setupConfigmenu(*m_configmenu.get()); } -void BScreen::removeConfigMenu(FbTk::Menu &menu) { +void BScreen::removeConfigMenu(const FbTk::RefCount &menu) { Configmenus::iterator erase_it = find_if(m_configmenu_list.begin(), m_configmenu_list.end(), - FbTk::Compose(bind2nd(equal_to(), &menu), + FbTk::Compose(bind2nd(equal_to >(), menu), FbTk::Select2nd())); if (erase_it != m_configmenu_list.end()) m_configmenu_list.erase(erase_it); @@ -1541,7 +1510,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::FbString focusmenu_label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); - FbTk::Menu *focus_menu = createMenu(focusmenu_label); + FbTk::RefCount 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)) @@ -1598,7 +1567,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::FbString maxmenu_label = _FB_XTEXT(Configmenu, MaxMenu, "Maximize Options", "heading for maximization options"); - FbTk::Menu *maxmenu = createMenu(maxmenu_label); + FbTk::RefCount maxmenu( createMenu(maxmenu_label) ); _BOOLITEM(*maxmenu, Configmenu, FullMax, "Full Maximization", "Maximise over slit, toolbar, etc", @@ -1624,9 +1593,9 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::FbString tabmenu_label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); - FbTk::Menu *tab_menu = createMenu(tabmenu_label); + FbTk::RefCount tab_menu( createMenu(tabmenu_label) ); FbTk::FbString tabplacement_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); - FbTk::Menu *tabplacement_menu = createToggleMenu(tabplacement_label); + FbTk::RefCount tabplacement_menu( createToggleMenu(tabplacement_label) ); tab_menu->insert(tabplacement_label, tabplacement_menu); @@ -1694,7 +1663,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::FbString alphamenu_label = _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"); - FbTk::Menu *alpha_menu = createMenu(alphamenu_label); + FbTk::RefCount alpha_menu( createMenu(alphamenu_label) ); if (FbTk::Transparent::haveComposite(true)) { static FbTk::SimpleAccessor s_pseudo(Fluxbox::instance()->getPseudoTrans()); diff --git a/src/Screen.hh b/src/Screen.hh index 8c89ab2..3e062ac 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -25,6 +25,7 @@ #ifndef SCREEN_HH #define SCREEN_HH +#include "FbMenu.hh" #include "FbWinFrame.hh" #include "FbRootWindow.hh" #include "RootTheme.hh" @@ -56,7 +57,6 @@ #include class ClientPattern; -class FbMenu; class Focusable; class FluxboxWindow; class WinClient; @@ -87,7 +87,7 @@ public: typedef std::vector Workspaces; typedef std::vector WorkspaceNames; - typedef std::list > ExtraMenus; + typedef std::list > > ExtraMenus; BScreen(FbTk::ResourceManager_base &rm, const std::string &screenname, @@ -114,8 +114,8 @@ public: // menus const FbMenu &rootMenu() const { return *m_rootmenu.get(); } FbMenu &rootMenu() { return *m_rootmenu.get(); } - const FbMenu &configMenu() const { return *m_configmenu.get(); } - FbMenu &configMenu() { return *m_configmenu.get(); } + FbTk::RefCount configMenu() const { return m_configmenu; } + const FbTk::RefCount &configMenu() { return m_configmenu; } const FbMenu &windowMenu() const { return *m_windowmenu.get(); } FbMenu &windowMenu() { return *m_windowmenu.get(); } ExtraMenus &extraWindowMenus() { return m_extramenus; } @@ -151,9 +151,9 @@ public: Workspace *currentWorkspace() { return m_current_workspace; } const Workspace *currentWorkspace() const { return m_current_workspace; } /// @return the workspace menu - const FbMenu &workspaceMenu() const { return *m_workspacemenu.get(); } + FbTk::RefCount workspaceMenu() const { return m_workspacemenu; } /// @return the workspace menu - FbMenu &workspaceMenu() { return *m_workspacemenu.get(); } + const FbTk::RefCount &workspaceMenu() { return m_workspacemenu; } /// @return focus control handler const FocusControl &focusControl() const { return *m_focus_control; } /// @return focus control handler @@ -247,10 +247,8 @@ public: /** * For extras to add menus. - * These menus will be marked internal, - * and deleted when the window dies (as opposed to Screen */ - void addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu); + void addExtraWindowMenu(const FbTk::FbString &label, const FbTk::RefCount &menu); int getEdgeSnapThreshold() const { return *resource.edge_snap_threshold; } @@ -444,8 +442,8 @@ public: // for extras to add menus. These menus must be marked // internal for their safety, and __the extension__ must // delete and remove the menu itself (opposite to Window) - void addConfigMenu(const FbTk::FbString &label, FbTk::Menu &menu); - void removeConfigMenu(FbTk::Menu &menu); + void addConfigMenu(const FbTk::FbString &label, const FbTk::RefCount &menu); + void removeConfigMenu(const FbTk::RefCount &menu); /// Adds a resource to managed resource list @@ -495,11 +493,11 @@ private: bool root_colormap_installed, managed; std::auto_ptr m_image_control; - std::auto_ptr m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu; + FbTk::RefCount m_configmenu, m_rootmenu, m_workspacemenu, m_windowmenu; ExtraMenus m_extramenus; - typedef std::list > Configmenus; + typedef std::list > > Configmenus; Configmenus m_configmenu_list; diff --git a/src/Slit.cc b/src/Slit.cc index 55c0643..9a79ac5 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -227,12 +227,12 @@ void Slit::SlitClientsRes::pushToLua(lua::state &l) const { Slit::Slit(BScreen &scr, FbTk::Layer &layer) : m_hidden(false), m_visible(false), m_screen(scr), - m_clientlist_menu(scr.menuTheme(), + m_clientlist_menu(new FbMenu(scr.menuTheme(), scr.imageControl(), - *scr.layerManager().getLayer(ResourceLayer::MENU)), - m_slitmenu(scr.menuTheme(), + *scr.layerManager().getLayer(ResourceLayer::MENU)) ), + m_slitmenu(new FbMenu(scr.menuTheme(), scr.imageControl(), - *scr.layerManager().getLayer(ResourceLayer::MENU)), + *scr.layerManager().getLayer(ResourceLayer::MENU)) ), #ifdef XINERAMA m_xineramaheadmenu(0), #endif // XINERAMA @@ -727,7 +727,7 @@ void Slit::reconfigure() { else if (!doAutoHide() && isHidden()) toggleHidden(); // restore visible - m_slitmenu.reconfigure(); + m_slitmenu->reconfigure(); updateClientmenu(); updateStrut(); @@ -950,11 +950,11 @@ void Slit::buttonPressEvent(XButtonEvent &be) { return; if (be.button == Button3) { - if (! m_slitmenu.isVisible()) { + if (! m_slitmenu->isVisible()) { screen().placementStrategy() - .placeAndShowMenu(m_slitmenu, be.x_root, be.y_root, false); + .placeAndShowMenu(*m_slitmenu, be.x_root, be.y_root, false); } else - m_slitmenu.hide(); + m_slitmenu->hide(); } } @@ -983,7 +983,7 @@ void Slit::leaveNotifyEvent(XCrossingEvent &ev) { } else { if (! m_timer.isTiming()) { // the menu is open, keep it firing until it closes - if (m_slitmenu.isVisible()) + if (m_slitmenu->isVisible()) m_timer.fireOnce(false); m_timer.start(); } @@ -1046,7 +1046,7 @@ void Slit::clearWindow() { void Slit::toggleHidden() { if (doAutoHide()) { - if (!m_slitmenu.isVisible()) { + if (!m_slitmenu->isVisible()) { m_timer.fireOnce(true); } else return; @@ -1066,24 +1066,24 @@ void Slit::updateClientmenu() { _FB_USES_NLS; // clear old items - m_clientlist_menu.removeAll(); - m_clientlist_menu.setLabel(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu")); + m_clientlist_menu->removeAll(); + m_clientlist_menu->setLabel(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu")); 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->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.insert(new FbTk::MenuSeparator()); + m_clientlist_menu->insert(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->insert(new SlitClientMenuItem(*this, *(*it), reconfig)); } - m_clientlist_menu.updateMenu(); + m_clientlist_menu->updateMenu(); } void Slit::saveClientList() { @@ -1110,39 +1110,35 @@ void Slit::setupMenu() { FbTk::RefCount > save_and_reconfigure_slit(s_a_reconf_slit_macro); - // it'll be freed by the slitmenu (since not marked internal) - FbMenu *placement_menu = new FbMenu(m_screen.menuTheme(), + FbTk::RefCount placement_menu( new FbMenu(m_screen.menuTheme(), m_screen.imageControl(), - *m_screen.layerManager().getLayer(::ResourceLayer::MENU)); + *m_screen.layerManager().getLayer(::ResourceLayer::MENU)) ); // 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"), + 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.insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), m_layermenu.get()); + m_slitmenu->insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), + FbTk::RefCount(m_layermenu) ); #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.reset( 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->insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), + FbTk::RefCount(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->insert(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->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), m_rc_maximize_over, save_and_reconfigure_slit)); @@ -1150,7 +1146,7 @@ void Slit::setupMenu() { FbTk::MenuItem *alpha_menuitem = new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, - 0, 255, m_slitmenu); + 0, 255, *m_slitmenu); // setup command for alpha value MacroCommand *alpha_macrocmd = new MacroCommand(); RefCount > alpha_cmd(new SimpleCommand(*this, &Slit::updateAlpha)); @@ -1159,17 +1155,15 @@ void Slit::setupMenu() { RefCount > set_alpha_cmd(alpha_macrocmd); alpha_menuitem->setCommand(set_alpha_cmd); - m_slitmenu.insert(alpha_menuitem); + m_slitmenu->insert(alpha_menuitem); - m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu); - m_slitmenu.updateMenu(); + m_slitmenu->insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), + FbTk::RefCount(m_clientlist_menu) ); + m_slitmenu->updateMenu(); // setup sub menu placement_menu->setLabel(_FB_XTEXT(Slit, Placement, "Slit Placement", "Slit Placement")); placement_menu->setMinimumColumns(3); - m_layermenu->setInternalMenu(); - m_clientlist_menu.setInternalMenu(); - m_slitmenu.setInternalMenu(); typedef pair PlacementP; typedef list Placements; diff --git a/src/Slit.hh b/src/Slit.hh index 9384ad6..f12a740 100644 --- a/src/Slit.hh +++ b/src/Slit.hh @@ -117,7 +117,7 @@ public: Placement placement() const { return *m_rc_placement; } int getOnHead() const { return *m_rc_on_head; } void saveOnHead(int head); - FbTk::Menu &menu() { return m_slitmenu; } + FbTk::Menu &menu() { return *m_slitmenu; } const FbTk::FbWindow &window() const { return frame.window; } @@ -147,10 +147,10 @@ private: BScreen &m_screen; FbTk::Timer m_timer; - std::auto_ptr m_layermenu; - FbMenu m_clientlist_menu, m_slitmenu; + FbTk::RefCount m_layermenu; + FbTk::RefCount m_clientlist_menu, m_slitmenu; #ifdef XINERAMA - XineramaHeadMenu *m_xineramaheadmenu; + FbTk::RefCount > m_xineramaheadmenu; #endif // XINERAMA struct frame { diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc index ee4666e..d499141 100644 --- a/src/ToolFactory.cc +++ b/src/ToolFactory.cc @@ -49,7 +49,7 @@ public: m_tbar.screen() .placementStrategy() - .placeAndShowMenu(m_tbar.menu(), e.xbutton.x_root, e.xbutton.y_root, false); + .placeAndShowMenu(*m_tbar.menu(), e.xbutton.x_root, e.xbutton.y_root, false); } private: Toolbar &m_tbar; @@ -85,11 +85,11 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & witem->button().setOnClick(showmenu); item = witem; } else if (name == "iconbar") { - item = new IconbarTool(parent, m_iconbar_theme, m_focused_iconbar_theme, m_unfocused_iconbar_theme, screen(), tbar.menu()); + item = new IconbarTool(parent, m_iconbar_theme, m_focused_iconbar_theme, m_unfocused_iconbar_theme, screen(), *tbar.menu()); } else if (name == "systemtray") { item = new SystemTray(parent, dynamic_cast(*m_systray_theme), screen()); } else if (name == "clock") { - item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); + item = new ClockTool(parent, m_clock_theme, screen(), *tbar.menu()); } else { std::string cmd_str = name; diff --git a/src/Toolbar.cc b/src/Toolbar.cc index b9e2fbb..1be8215 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -118,7 +118,7 @@ public: void click(int button, int time, unsigned int mods) { m_toolbar.setPlacement(m_place); m_toolbar.reconfigure(); - m_toolbar.placementMenu().reconfigure(); + m_toolbar.placementMenu()->reconfigure(); Fluxbox::instance()->save_rc(); } private: @@ -158,17 +158,17 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): m_window_pm(0), m_screen(scrn), m_layeritem(frame.window, layer), - m_layermenu(scrn.menuTheme(), + m_layermenu(new LayerMenu(scrn.menuTheme(), scrn.imageControl(), *scrn.layerManager().getLayer(ResourceLayer::MENU), this, - true), - m_placementmenu(scrn.menuTheme(), + true)), + m_placementmenu(new FbMenu(scrn.menuTheme(), scrn.imageControl(), - *scrn.layerManager().getLayer(ResourceLayer::MENU)), - m_toolbarmenu(scrn.menuTheme(), + *scrn.layerManager().getLayer(ResourceLayer::MENU))), + m_toolbarmenu(new FbMenu(scrn.menuTheme(), scrn.imageControl(), - *scrn.layerManager().getLayer(ResourceLayer::MENU)), + *scrn.layerManager().getLayer(ResourceLayer::MENU))), #ifdef XINERAMA m_xineramaheadmenu(0), #endif // XINERAMA @@ -205,12 +205,9 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): moveToLayer(static_cast(*m_rc_layernum)); - m_layermenu.setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); - m_placementmenu.setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); + m_layermenu->setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); + m_placementmenu->setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); - m_layermenu.setInternalMenu(); - m_placementmenu.setInternalMenu(); - m_toolbarmenu.setInternalMenu(); setupMenus(); // add menu to screen screen().addConfigMenu(_FB_XTEXT(Toolbar, Toolbar, "Toolbar", "title of toolbar menu item"), menu()); @@ -251,7 +248,7 @@ Toolbar::~Toolbar() { // from the tools screen().removeConfigMenu(menu()); - menu().removeAll(); + menu()->removeAll(); deleteItems(); clearStrut(); @@ -370,7 +367,7 @@ void Toolbar::reconfigure() { // destroy tools and rebuild them deleteItems(); // they will be readded later - menu().removeAll(); + menu()->removeAll(); setupMenus(true); // rebuild menu but skip rebuild of placement menu m_tools = tools; // copy values @@ -393,7 +390,7 @@ void Toolbar::reconfigure() { } } else { // just update the menu - menu().reconfigure(); + menu()->reconfigure(); } frame.bevel_w = theme()->bevelWidth(); @@ -485,7 +482,7 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) { screen() .placementStrategy() - .placeAndShowMenu(menu(), be.x_root, be.y_root, false); + .placeAndShowMenu(*menu(), be.x_root, be.y_root, false); } void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { @@ -528,7 +525,7 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent &event) { if (isHidden()) { if (m_hide_timer.isTiming()) m_hide_timer.stop(); - } else if (! menu().isVisible() && ! m_hide_timer.isTiming()) + } else if (! menu()->isVisible() && ! m_hide_timer.isTiming()) m_hide_timer.start(); } @@ -742,7 +739,7 @@ void Toolbar::setupMenus(bool skip_new_placement) { typedef RefCount > RefCommand; typedef SimpleCommand ToolbarCommand; - menu().setLabel(_FB_XTEXT(Toolbar, Toolbar, + menu()->setLabel(_FB_XTEXT(Toolbar, Toolbar, "Toolbar", "Title of Toolbar menu")); RefCommand reconfig_toolbar(new ToolbarCommand(*this, &Toolbar::reconfigure)); @@ -758,11 +755,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()->insert(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()->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "Toggle auto hide of toolbar"), m_rc_auto_hide, reconfig_toolbar_and_save_resource)); @@ -772,29 +769,27 @@ void Toolbar::setupMenus(bool skip_new_placement) { "Toolbar width percent", "Percentage of screen width taken by toolbar"), m_rc_width_percent, - 0, 100, menu()); // min/max value + 0, 100, *menu()); // min/max value toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); - menu().insert(toolbar_menuitem); + menu()->insert(toolbar_menuitem); - menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, + menu()->insert(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()->insert(_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.reset( 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()->insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), + FbTk::RefCount(m_xineramaheadmenu) ); } #endif // XINERAMA @@ -824,28 +819,28 @@ void Toolbar::setupMenus(bool skip_new_placement) { { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Toolbar::BOTTOMRIGHT} }; - placementMenu().setMinimumColumns(3); + placementMenu()->setMinimumColumns(3); // create items in sub menu for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { const PlacementP& p = place_menu[i]; if (p.label == "") { - placementMenu().insert(p.label); - placementMenu().setItemEnabled(i, false); + placementMenu()->insert(p.label); + placementMenu()->setItemEnabled(i, false); } else - placementMenu().insert(new PlaceToolbarMenuItem(p.label, *this, + placementMenu()->insert(new PlaceToolbarMenuItem(p.label, *this, p.placement)); } } - menu().insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); - placementMenu().updateMenu(); + menu()->insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), placementMenu()); + placementMenu()->updateMenu(); // this saves resources and clears the slit window to update alpha value FbTk::MenuItem *alpha_menuitem = new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, - 0, 255, menu()); + 0, 255, *menu()); // setup command for alpha value MacroCommand *alpha_macrocmd = new MacroCommand(); RefCount > alpha_cmd(new SimpleCommand(*this, &Toolbar::updateAlpha)); @@ -854,8 +849,8 @@ void Toolbar::setupMenus(bool skip_new_placement) { RefCount > set_alpha_cmd(alpha_macrocmd); alpha_menuitem->setCommand(set_alpha_cmd); - menu().insert(alpha_menuitem); - menu().updateMenu(); + menu()->insert(alpha_menuitem); + menu()->updateMenu(); } void Toolbar::saveOnHead(int head) { diff --git a/src/Toolbar.hh b/src/Toolbar.hh index eca379b..b0aeb60 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh @@ -104,13 +104,13 @@ public: int layerNumber() const { return const_cast(m_layeritem).getLayerNum(); } - const FbTk::Menu &menu() const { return m_toolbarmenu; } - FbTk::Menu &menu() { return m_toolbarmenu; } - FbTk::Menu &placementMenu() { return m_placementmenu; } - const FbTk::Menu &placementMenu() const { return m_placementmenu; } + FbTk::RefCount menu() const { return m_toolbarmenu; } + FbTk::RefCount menu() { return m_toolbarmenu; } + FbTk::RefCount placementMenu() { return m_placementmenu; } + FbTk::RefCount placementMenu() const { return m_placementmenu; } - FbTk::Menu &layerMenu() { return m_layermenu; } - const FbTk::Menu &layerMenu() const { return m_layermenu; } + FbTk::RefCount layerMenu() { return m_layermenu; } + FbTk::RefCount layerMenu() const { return m_layermenu; } /// are we hidden? bool isHidden() const { return m_hidden; } @@ -165,10 +165,10 @@ private: FbTk::Timer m_hide_timer; ///< timer to for auto hide toolbar FbTk::LayerItem m_layeritem; ///< layer item, must be declared before layermenu - LayerMenu m_layermenu; - FbMenu m_placementmenu, m_toolbarmenu; + FbTk::RefCount m_layermenu; + FbTk::RefCount m_placementmenu, m_toolbarmenu; #ifdef XINERAMA - XineramaHeadMenu *m_xineramaheadmenu; + FbTk::RefCount > m_xineramaheadmenu; #endif // XINERAMA diff --git a/src/Workspace.cc b/src/Workspace.cc index a162b4c..8b3c411 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -65,17 +65,15 @@ using std::string; Workspace::Workspace(BScreen &scrn, const string &name, unsigned int id): m_screen(scrn), - m_clientmenu(scrn, m_windowlist, false), + m_clientmenu(new ClientMenu(scrn, m_windowlist, false) ), m_name(name), m_id(id) { - m_clientlist_sig.connect(FbTk::MemFun(m_clientmenu, + m_clientlist_sig.connect(FbTk::MemFun(*m_clientmenu, &ClientMenu::refreshMenu)); - menu().setInternalMenu(); setName(name); - } @@ -145,7 +143,7 @@ void Workspace::removeAll(unsigned int dest) { void Workspace::reconfigure() { - menu().reconfigure(); + menu()->reconfigure(); Windows::iterator it = m_windowlist.begin(); Windows::iterator it_end = m_windowlist.end(); @@ -176,8 +174,8 @@ void Workspace::setName(const string &name) { screen().updateWorkspaceName(m_id); - menu().setLabel(FbTk::BiDiString(m_name)); - menu().updateMenu(); + menu()->setLabel(FbTk::BiDiString(m_name)); + menu()->updateMenu(); } /** diff --git a/src/Workspace.hh b/src/Workspace.hh index 2dabb3e..829bdf0 100644 --- a/src/Workspace.hh +++ b/src/Workspace.hh @@ -65,8 +65,8 @@ public: BScreen &screen() { return m_screen; } const BScreen &screen() const { return m_screen; } - FbTk::Menu &menu() { return m_clientmenu; } - const FbTk::Menu &menu() const { return m_clientmenu; } + FbTk::RefCount menu() { return m_clientmenu; } + FbTk::RefCount menu() const { return m_clientmenu; } /// name of this workspace const FbTk::FbString &name() const { return m_name; } /** @@ -86,7 +86,7 @@ private: Windows m_windowlist; FbTk::Signal<> m_clientlist_sig; - ClientMenu m_clientmenu; + FbTk::RefCount m_clientmenu; FbTk::FbString m_name; ///< name of this workspace unsigned int m_id; ///< id, obsolete, this should be in BScreen diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc index d73947b..0b563aa 100644 --- a/src/WorkspaceMenu.cc +++ b/src/WorkspaceMenu.cc @@ -56,8 +56,7 @@ const unsigned int NR_STATIC_ITEMS = 6; void add_workspaces(WorkspaceMenu& menu, BScreen& screen) { for (size_t i = 0; i < screen.numberOfWorkspaces(); ++i) { Workspace* w = screen.getWorkspace(i); - w->menu().setInternalMenu(); - FbTk::MultiButtonMenuItem* submenu = new FbTk::MultiButtonMenuItem(5, FbTk::BiDiString(w->name()), &w->menu()); + 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); @@ -112,7 +111,7 @@ void WorkspaceMenu::init(BScreen &screen) { setLabel(_FB_XTEXT(Workspace, MenuTitle, "Workspaces", "Title of main workspace menu")); insert(_FB_XTEXT(Menu, Icons, "Icons", "Iconic windows menu title"), - MenuCreator::createMenuType("iconmenu", screen.screenNumber())); + FbTk::RefCount(MenuCreator::createMenuType("iconmenu", screen.screenNumber())) ); insert(new FbTk::MenuSeparator()); ::add_workspaces(*this, screen); -- cgit v0.11.2