From 6d5781ce7198a8a82fd0cae8554e4c120d01df3d Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Fri, 16 Jan 2015 08:39:05 +0100 Subject: Refactor: move some menu-creation functions to MenuCreator Another patch to trim down the code that needs to be part of BScreen --- src/ConfigMenu.cc | 37 +++++++++++++++++++++++++------------ src/FbCommands.cc | 2 +- src/MenuCreator.cc | 18 +++++++++++------- src/MenuCreator.hh | 6 ++++-- src/Remember.cc | 3 ++- src/Screen.cc | 26 ++++---------------------- src/Screen.hh | 21 +-------------------- 7 files changed, 48 insertions(+), 65 deletions(-) diff --git a/src/ConfigMenu.cc b/src/ConfigMenu.cc index e4be129..cfce697 100644 --- a/src/ConfigMenu.cc +++ b/src/ConfigMenu.cc @@ -20,12 +20,14 @@ // DEALINGS IN THE SOFTWARE. #include "ConfigMenu.hh" +#include "MenuCreator.hh" #include "Screen.hh" #include "fluxbox.hh" #include "FocusModelMenuItem.hh" #include "ScreenPlacement.hh" #include "FbMenu.hh" +#include "ToggleMenu.hh" #include "FbTk/Menu.hh" #include "FbTk/BoolMenuItem.hh" #include "FbTk/IntMenuItem.hh" @@ -67,19 +69,30 @@ private: typedef FbTk::RefCount > _Cmd; -enum { - L_ALPHA = 0, - L_PSEUDO_TRANS, - L_FOCUS_ALPHA, - L_UNFOCUS_ALPHA, - L_MENU_ALPHA, -}; +// NOTE: might also be placed into MenuCreator; for now it ends up here +// because it's just used here +FbMenu *createToggleMenu(const std::string &label, BScreen& screen) { + FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU); + FbMenu *menu = new ToggleMenu(screen.menuTheme(), screen.imageControl(), *layer); + if (!label.empty()) + menu->setLabel(label); + + return menu; +} void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_reconf) { #ifdef HAVE_XRENDER _FB_USES_NLS; + enum { + L_ALPHA = 0, + L_PSEUDO_TRANS, + L_FOCUS_ALPHA, + L_UNFOCUS_ALPHA, + L_MENU_ALPHA, + }; + static const FbTk::FbString _labels[] = { _FB_XTEXT(Configmenu, Transparency, "Transparency", "Menu containing various transparency options"), _FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), @@ -90,7 +103,7 @@ void setupAlphaMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_ FbTk::FbString label = _labels[L_ALPHA]; - FbTk::Menu* menu = sh.screen.createMenu(label); + FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen); if (FbTk::Transparent::haveComposite(true)) { static FbTk::SimpleAccessor s_pseudo = Fluxbox::instance()->getPseudoTrans(); @@ -131,7 +144,7 @@ void setupFocusMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save_rc // we don't set this to internal menu so will // be deleted toghether with the parent FbTk::FbString label = _FB_XTEXT(Configmenu, FocusModel, "Focus Model", "Method used to give focus to windows"); - FbMenu* fm = sh.screen.createMenu(label); + FbMenu* fm = MenuCreator::createMenu(label, sh.screen); #define _FOCUSITEM(a, b, c, d, e) \ fm->insertItem(new FocusModelMenuItem(_FB_XTEXT(a, b, c, d), sh.screen.focusControl(), \ @@ -197,7 +210,7 @@ void setupMaximizeMenu(FbTk::Menu& menu, ConfigMenu::SetupHelper& sh, _Cmd& save FbTk::FbString label = _FB_XTEXT(Configmenu, MaxMenu, "Maximize Options", "heading for maximization options"); - FbTk::Menu* mm = sh.screen.createMenu(label); + FbTk::Menu* mm = MenuCreator::createMenu(label, sh.screen); _BOOLITEM(*mm, Configmenu, FullMax, "Full Maximization", "Maximise over slit, toolbar, etc", @@ -224,8 +237,8 @@ void setupTabMenu(FbTk::Menu& parent, ConfigMenu::SetupHelper& sh, _Cmd& save_re FbTk::FbString label = _FB_XTEXT(Configmenu, TabMenu, "Tab Options", "heading for tab-related options"); // TODO: main-category is 'Menu'?? should be 'ConfigMenu'??? FbTk::FbString p_label = _FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"); - FbTk::Menu* menu = sh.screen.createMenu(label); - FbTk::Menu* p_menu = sh.screen.createToggleMenu(p_label); + FbTk::Menu* menu = MenuCreator::createMenu(label, sh.screen); + FbTk::Menu* p_menu = createToggleMenu(p_label, sh.screen); menu->insertSubmenu(p_label, p_menu); diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 10d98e7..0708b1e 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc @@ -323,7 +323,7 @@ void ShowCustomMenuCmd::execute() { return; if (!m_menu.get() || screen->screenNumber() != m_menu->screenNumber()) { - m_menu.reset(screen->createMenu("")); + m_menu.reset(MenuCreator::createMenu("", *screen)); m_menu->setReloadHelper(new FbTk::AutoReloadHelper()); m_menu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &ShowCustomMenuCmd::reload))); m_menu->reloadHelper()->setMainFile(custom_menu_file); diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index b2b15f5..e8fb90b 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -482,20 +482,24 @@ bool getStart(FbMenuParser &parser, string &label, FbTk::StringConvertor &labelc } // end of anonymous namespace -FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { - BScreen *screen = Fluxbox::instance()->findScreen(screen_number); - if (screen == 0) - return 0; - FbMenu *menu = new FbMenu(screen->menuTheme(), - screen->imageControl(), - *screen->layerManager().getLayer(ResourceLayer::MENU)); + +FbMenu* MenuCreator::createMenu(const std::string& label, BScreen& screen) { + FbTk::Layer* layer = screen.layerManager().getLayer(ResourceLayer::MENU); + FbMenu *menu = new FbMenu(screen.menuTheme(), screen.imageControl(), *layer); if (!label.empty()) menu->setLabel(label); return menu; } +FbMenu *MenuCreator::createMenu(const string &label, int screen_number) { + BScreen *screen = Fluxbox::instance()->findScreen(screen_number); + if (screen == 0) + return 0; + return MenuCreator::createMenu(label, *screen); +} + bool MenuCreator::createFromFile(const string &filename, FbTk::Menu &inject_into, AutoReloadHelper *reloader, bool begin) { diff --git a/src/MenuCreator.hh b/src/MenuCreator.hh index 91add47..b8f260b 100644 --- a/src/MenuCreator.hh +++ b/src/MenuCreator.hh @@ -34,11 +34,13 @@ class Menu; class FbMenu; class FluxboxWindow; +class BScreen; namespace MenuCreator { - FbMenu *createMenu(const std::string &label, int screen_num); - FbMenu *createMenuType(const std::string &label, int screen_num); + FbMenu* createMenu(const std::string& label, BScreen& screen); + FbMenu* createMenu(const std::string& label, int screen_num); + FbMenu* createMenuType(const std::string &label, int screen_num); bool createFromFile(const std::string &filename, FbTk::Menu &inject_into, FbTk::AutoReloadHelper *reloader = NULL, diff --git a/src/Remember.cc b/src/Remember.cc index 41d7256..acbbddf 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -27,6 +27,7 @@ #include "Window.hh" #include "WinClient.hh" #include "FbMenu.hh" +#include "MenuCreator.hh" #include "FbCommands.hh" #include "fluxbox.hh" #include "Layer.hh" @@ -305,7 +306,7 @@ private: FbTk::Menu *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::Menu *menu = MenuCreator::createMenu("Remember", screen); // if enabled, then we want this to be a unavailable menu /* diff --git a/src/Screen.cc b/src/Screen.cc index 5e7ca8b..296fec0 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -359,17 +359,17 @@ BScreen::BScreen(FbTk::ResourceManager &rm, m_current_workspace = m_workspaces_list.front(); - m_windowmenu.reset(createMenu("")); + m_windowmenu.reset(MenuCreator::createMenu("", *this)); m_windowmenu->setInternalMenu(); m_windowmenu->setReloadHelper(new FbTk::AutoReloadHelper()); m_windowmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadWindowMenu))); - m_rootmenu.reset(createMenu("")); + m_rootmenu.reset(MenuCreator::createMenu("", *this)); m_rootmenu->setReloadHelper(new FbTk::AutoReloadHelper()); m_rootmenu->reloadHelper()->setReloadCmd(FbTk::RefCount >(new FbTk::SimpleCommand(*this, &BScreen::rereadMenu))); - m_configmenu.reset(createMenu(_FB_XTEXT(Menu, Configuration, - "Configuration", "Title of configuration menu"))); + m_configmenu.reset(MenuCreator::createMenu(_FB_XTEXT(Menu, Configuration, + "Configuration", "Title of configuration menu"), *this)); setupConfigmenu(*m_configmenu.get()); m_configmenu->setInternalMenu(); @@ -745,24 +745,6 @@ void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) { } -FbMenu *BScreen::createMenu(const string &label) { - FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); - FbMenu *menu = new FbMenu(menuTheme(), imageControl(), *layer); - if (!label.empty()) - menu->setLabel(label); - - return menu; -} - -FbMenu *BScreen::createToggleMenu(const string &label) { - FbTk::Layer* layer = layerManager().getLayer(ResourceLayer::MENU); - FbMenu *menu = new ToggleMenu(menuTheme(), imageControl(), *layer); - if (!label.empty()) - menu->setLabel(label); - - return menu; -} - void BScreen::addExtraWindowMenu(const FbTk::FbString &label, FbTk::Menu *menu) { menu->setInternalMenu(); menu->disableTitle(); diff --git a/src/Screen.hh b/src/Screen.hh index dcdcb06..eb2a306 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -43,13 +43,7 @@ #include "FocusControl.hh" -#include - -#ifdef HAVE_CSTDIO - #include -#else - #include -#endif +#include #include #include #include @@ -234,19 +228,6 @@ public: bool isCycling() const { return m_cycling; } /** - * Creates an empty menu with specified label - * @param label for the menu - * @return created menu - */ - FbMenu *createMenu(const std::string &label); - /** - * Creates an empty toggle menu with a specific label - * @param label - * @return created menu - */ - FbMenu *createToggleMenu(const std::string &label); - - /** * For extras to add menus. * These menus will be marked internal, * and deleted when the window dies (as opposed to Screen -- cgit v0.11.2