diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 15:21:24 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 15:21:24 (GMT) |
commit | 442e69c89b721329883113389f889675138e7da7 (patch) | |
tree | 211111eb98eb3da6155baea0a24c5cd9d8c6137d /src/Toolbar.cc | |
parent | bd94eaa6cadfd0a7d83f3068a84b27f987bdee4b (diff) | |
download | fluxbox_pavel-442e69c89b721329883113389f889675138e7da7.zip fluxbox_pavel-442e69c89b721329883113389f889675138e7da7.tar.bz2 |
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. :)
Diffstat (limited to 'src/Toolbar.cc')
-rw-r--r-- | src/Toolbar.cc | 79 |
1 files changed, 37 insertions, 42 deletions
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: | |||
118 | void click(int button, int time, unsigned int mods) { | 118 | void click(int button, int time, unsigned int mods) { |
119 | m_toolbar.setPlacement(m_place); | 119 | m_toolbar.setPlacement(m_place); |
120 | m_toolbar.reconfigure(); | 120 | m_toolbar.reconfigure(); |
121 | m_toolbar.placementMenu().reconfigure(); | 121 | m_toolbar.placementMenu()->reconfigure(); |
122 | Fluxbox::instance()->save_rc(); | 122 | Fluxbox::instance()->save_rc(); |
123 | } | 123 | } |
124 | private: | 124 | private: |
@@ -158,17 +158,17 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): | |||
158 | m_window_pm(0), | 158 | m_window_pm(0), |
159 | m_screen(scrn), | 159 | m_screen(scrn), |
160 | m_layeritem(frame.window, layer), | 160 | m_layeritem(frame.window, layer), |
161 | m_layermenu(scrn.menuTheme(), | 161 | m_layermenu(new LayerMenu(scrn.menuTheme(), |
162 | scrn.imageControl(), | 162 | scrn.imageControl(), |
163 | *scrn.layerManager().getLayer(ResourceLayer::MENU), | 163 | *scrn.layerManager().getLayer(ResourceLayer::MENU), |
164 | this, | 164 | this, |
165 | true), | 165 | true)), |
166 | m_placementmenu(scrn.menuTheme(), | 166 | m_placementmenu(new FbMenu(scrn.menuTheme(), |
167 | scrn.imageControl(), | 167 | scrn.imageControl(), |
168 | *scrn.layerManager().getLayer(ResourceLayer::MENU)), | 168 | *scrn.layerManager().getLayer(ResourceLayer::MENU))), |
169 | m_toolbarmenu(scrn.menuTheme(), | 169 | m_toolbarmenu(new FbMenu(scrn.menuTheme(), |
170 | scrn.imageControl(), | 170 | scrn.imageControl(), |
171 | *scrn.layerManager().getLayer(ResourceLayer::MENU)), | 171 | *scrn.layerManager().getLayer(ResourceLayer::MENU))), |
172 | #ifdef XINERAMA | 172 | #ifdef XINERAMA |
173 | m_xineramaheadmenu(0), | 173 | m_xineramaheadmenu(0), |
174 | #endif // XINERAMA | 174 | #endif // XINERAMA |
@@ -205,12 +205,9 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): | |||
205 | 205 | ||
206 | moveToLayer(static_cast<int>(*m_rc_layernum)); | 206 | moveToLayer(static_cast<int>(*m_rc_layernum)); |
207 | 207 | ||
208 | m_layermenu.setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); | 208 | m_layermenu->setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); |
209 | m_placementmenu.setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); | 209 | m_placementmenu->setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); |
210 | 210 | ||
211 | m_layermenu.setInternalMenu(); | ||
212 | m_placementmenu.setInternalMenu(); | ||
213 | m_toolbarmenu.setInternalMenu(); | ||
214 | setupMenus(); | 211 | setupMenus(); |
215 | // add menu to screen | 212 | // add menu to screen |
216 | screen().addConfigMenu(_FB_XTEXT(Toolbar, Toolbar, "Toolbar", "title of toolbar menu item"), menu()); | 213 | screen().addConfigMenu(_FB_XTEXT(Toolbar, Toolbar, "Toolbar", "title of toolbar menu item"), menu()); |
@@ -251,7 +248,7 @@ Toolbar::~Toolbar() { | |||
251 | // from the tools | 248 | // from the tools |
252 | screen().removeConfigMenu(menu()); | 249 | screen().removeConfigMenu(menu()); |
253 | 250 | ||
254 | menu().removeAll(); | 251 | menu()->removeAll(); |
255 | 252 | ||
256 | deleteItems(); | 253 | deleteItems(); |
257 | clearStrut(); | 254 | clearStrut(); |
@@ -370,7 +367,7 @@ void Toolbar::reconfigure() { | |||
370 | // destroy tools and rebuild them | 367 | // destroy tools and rebuild them |
371 | deleteItems(); | 368 | deleteItems(); |
372 | // they will be readded later | 369 | // they will be readded later |
373 | menu().removeAll(); | 370 | menu()->removeAll(); |
374 | setupMenus(true); // rebuild menu but skip rebuild of placement menu | 371 | setupMenus(true); // rebuild menu but skip rebuild of placement menu |
375 | 372 | ||
376 | m_tools = tools; // copy values | 373 | m_tools = tools; // copy values |
@@ -393,7 +390,7 @@ void Toolbar::reconfigure() { | |||
393 | } | 390 | } |
394 | 391 | ||
395 | } else { // just update the menu | 392 | } else { // just update the menu |
396 | menu().reconfigure(); | 393 | menu()->reconfigure(); |
397 | } | 394 | } |
398 | 395 | ||
399 | frame.bevel_w = theme()->bevelWidth(); | 396 | frame.bevel_w = theme()->bevelWidth(); |
@@ -485,7 +482,7 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) { | |||
485 | 482 | ||
486 | screen() | 483 | screen() |
487 | .placementStrategy() | 484 | .placementStrategy() |
488 | .placeAndShowMenu(menu(), be.x_root, be.y_root, false); | 485 | .placeAndShowMenu(*menu(), be.x_root, be.y_root, false); |
489 | } | 486 | } |
490 | 487 | ||
491 | void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { | 488 | void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { |
@@ -528,7 +525,7 @@ void Toolbar::leaveNotifyEvent(XCrossingEvent &event) { | |||
528 | if (isHidden()) { | 525 | if (isHidden()) { |
529 | if (m_hide_timer.isTiming()) | 526 | if (m_hide_timer.isTiming()) |
530 | m_hide_timer.stop(); | 527 | m_hide_timer.stop(); |
531 | } else if (! menu().isVisible() && ! m_hide_timer.isTiming()) | 528 | } else if (! menu()->isVisible() && ! m_hide_timer.isTiming()) |
532 | m_hide_timer.start(); | 529 | m_hide_timer.start(); |
533 | 530 | ||
534 | } | 531 | } |
@@ -742,7 +739,7 @@ void Toolbar::setupMenus(bool skip_new_placement) { | |||
742 | typedef RefCount<Command<void> > RefCommand; | 739 | typedef RefCount<Command<void> > RefCommand; |
743 | typedef SimpleCommand<Toolbar> ToolbarCommand; | 740 | typedef SimpleCommand<Toolbar> ToolbarCommand; |
744 | 741 | ||
745 | menu().setLabel(_FB_XTEXT(Toolbar, Toolbar, | 742 | menu()->setLabel(_FB_XTEXT(Toolbar, Toolbar, |
746 | "Toolbar", "Title of Toolbar menu")); | 743 | "Toolbar", "Title of Toolbar menu")); |
747 | 744 | ||
748 | RefCommand reconfig_toolbar(new ToolbarCommand(*this, &Toolbar::reconfigure)); | 745 | RefCommand reconfig_toolbar(new ToolbarCommand(*this, &Toolbar::reconfigure)); |
@@ -758,11 +755,11 @@ void Toolbar::setupMenus(bool skip_new_placement) { | |||
758 | visible_macro->add(reconfig_toolbar); | 755 | visible_macro->add(reconfig_toolbar); |
759 | visible_macro->add(save_resources); | 756 | visible_macro->add(save_resources); |
760 | RefCommand toggle_visible_cmd(visible_macro); | 757 | RefCommand toggle_visible_cmd(visible_macro); |
761 | menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, | 758 | menu()->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, |
762 | "Visible", "Whether this item is visible"), | 759 | "Visible", "Whether this item is visible"), |
763 | m_rc_visible, toggle_visible_cmd)); | 760 | m_rc_visible, toggle_visible_cmd)); |
764 | 761 | ||
765 | menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, | 762 | menu()->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, |
766 | "Auto hide", "Toggle auto hide of toolbar"), | 763 | "Auto hide", "Toggle auto hide of toolbar"), |
767 | m_rc_auto_hide, | 764 | m_rc_auto_hide, |
768 | reconfig_toolbar_and_save_resource)); | 765 | reconfig_toolbar_and_save_resource)); |
@@ -772,29 +769,27 @@ void Toolbar::setupMenus(bool skip_new_placement) { | |||
772 | "Toolbar width percent", | 769 | "Toolbar width percent", |
773 | "Percentage of screen width taken by toolbar"), | 770 | "Percentage of screen width taken by toolbar"), |
774 | m_rc_width_percent, | 771 | m_rc_width_percent, |
775 | 0, 100, menu()); // min/max value | 772 | 0, 100, *menu()); // min/max value |
776 | 773 | ||
777 | 774 | ||
778 | toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); | 775 | toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); |
779 | menu().insert(toolbar_menuitem); | 776 | menu()->insert(toolbar_menuitem); |
780 | 777 | ||
781 | menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, | 778 | menu()->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, |
782 | "Maximize Over", | 779 | "Maximize Over", |
783 | "Maximize over this thing when maximizing"), | 780 | "Maximize over this thing when maximizing"), |
784 | m_rc_maximize_over, | 781 | m_rc_maximize_over, |
785 | reconfig_toolbar_and_save_resource)); | 782 | reconfig_toolbar_and_save_resource)); |
786 | menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); | 783 | menu()->insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), layerMenu()); |
787 | #ifdef XINERAMA | 784 | #ifdef XINERAMA |
788 | if (screen().hasXinerama()) { | 785 | if (screen().hasXinerama()) { |
789 | menu().insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), | 786 | m_xineramaheadmenu.reset( new XineramaHeadMenu<Toolbar>(screen().menuTheme(), |
790 | m_xineramaheadmenu = | 787 | screen(), screen().imageControl(), |
791 | new XineramaHeadMenu<Toolbar>(screen().menuTheme(), | 788 | *screen().layerManager().getLayer(::ResourceLayer::MENU), *this, |
792 | screen(), | 789 | _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", |
793 | screen().imageControl(), | 790 | "Title of toolbar on head menu"))); |
794 | *screen().layerManager().getLayer(::ResourceLayer::MENU), | 791 | menu()->insert(_FB_XTEXT(Menu, OnHead, "On Head...", "Title of On Head menu"), |
795 | *this, | 792 | FbTk::RefCount<FbTk::Menu>(m_xineramaheadmenu) ); |
796 | _FB_XTEXT(Toolbar, OnHead, "Toolbar on Head", | ||
797 | "Title of toolbar on head menu"))); | ||
798 | } | 793 | } |
799 | #endif // XINERAMA | 794 | #endif // XINERAMA |
800 | 795 | ||
@@ -824,28 +819,28 @@ void Toolbar::setupMenus(bool skip_new_placement) { | |||
824 | { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Toolbar::BOTTOMRIGHT} | 819 | { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Toolbar::BOTTOMRIGHT} |
825 | }; | 820 | }; |
826 | 821 | ||
827 | placementMenu().setMinimumColumns(3); | 822 | placementMenu()->setMinimumColumns(3); |
828 | // create items in sub menu | 823 | // create items in sub menu |
829 | for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { | 824 | for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { |
830 | const PlacementP& p = place_menu[i]; | 825 | const PlacementP& p = place_menu[i]; |
831 | if (p.label == "") { | 826 | if (p.label == "") { |
832 | placementMenu().insert(p.label); | 827 | placementMenu()->insert(p.label); |
833 | placementMenu().setItemEnabled(i, false); | 828 | placementMenu()->setItemEnabled(i, false); |
834 | } else | 829 | } else |
835 | placementMenu().insert(new PlaceToolbarMenuItem(p.label, *this, | 830 | placementMenu()->insert(new PlaceToolbarMenuItem(p.label, *this, |
836 | p.placement)); | 831 | p.placement)); |
837 | } | 832 | } |
838 | } | 833 | } |
839 | 834 | ||
840 | menu().insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); | 835 | menu()->insert(_FB_XTEXT(Menu, Placement, "Placement", "Title of Placement menu"), placementMenu()); |
841 | placementMenu().updateMenu(); | 836 | placementMenu()->updateMenu(); |
842 | 837 | ||
843 | 838 | ||
844 | // this saves resources and clears the slit window to update alpha value | 839 | // this saves resources and clears the slit window to update alpha value |
845 | FbTk::MenuItem *alpha_menuitem = | 840 | FbTk::MenuItem *alpha_menuitem = |
846 | new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), | 841 | new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), |
847 | m_rc_alpha, | 842 | m_rc_alpha, |
848 | 0, 255, menu()); | 843 | 0, 255, *menu()); |
849 | // setup command for alpha value | 844 | // setup command for alpha value |
850 | MacroCommand *alpha_macrocmd = new MacroCommand(); | 845 | MacroCommand *alpha_macrocmd = new MacroCommand(); |
851 | RefCount<Command<void> > alpha_cmd(new SimpleCommand<Toolbar>(*this, &Toolbar::updateAlpha)); | 846 | RefCount<Command<void> > alpha_cmd(new SimpleCommand<Toolbar>(*this, &Toolbar::updateAlpha)); |
@@ -854,8 +849,8 @@ void Toolbar::setupMenus(bool skip_new_placement) { | |||
854 | RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd); | 849 | RefCount<Command<void> > set_alpha_cmd(alpha_macrocmd); |
855 | alpha_menuitem->setCommand(set_alpha_cmd); | 850 | alpha_menuitem->setCommand(set_alpha_cmd); |
856 | 851 | ||
857 | menu().insert(alpha_menuitem); | 852 | menu()->insert(alpha_menuitem); |
858 | menu().updateMenu(); | 853 | menu()->updateMenu(); |
859 | } | 854 | } |
860 | 855 | ||
861 | void Toolbar::saveOnHead(int head) { | 856 | void Toolbar::saveOnHead(int head) { |