aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-02 15:21:24 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:57:20 (GMT)
commitf2709b26d8af7292f750fc05525ac90ad0d99c41 (patch)
tree794903544922abe2b90af6250de24124cd94d546 /src/FbTk
parent0584414d3845239202d5ea02da2ce6fb5b1b0cbb (diff)
downloadfluxbox_paul-f2709b26d8af7292f750fc05525ac90ad0d99c41.zip
fluxbox_paul-f2709b26d8af7292f750fc05525ac90ad0d99c41.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/FbTk')
-rw-r--r--src/FbTk/Menu.cc24
-rw-r--r--src/FbTk/Menu.hh4
-rw-r--r--src/FbTk/MenuItem.cc1
-rw-r--r--src/FbTk/MenuItem.hh10
-rw-r--r--src/FbTk/MultiButtonMenuItem.cc3
-rw-r--r--src/FbTk/MultiButtonMenuItem.hh2
-rw-r--r--src/FbTk/RadioMenuItem.hh2
7 files changed, 15 insertions, 31 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index e52b4dd..ccd76d3 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -126,8 +126,7 @@ Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl):
126 126
127 m_title_vis = true; 127 m_title_vis = true;
128 128
129 m_internal_menu = 129 m_moving =
130 m_moving =
131 m_closing = 130 m_closing =
132 m_torn = 131 m_torn =
133 m_visible = false; 132 m_visible = false;
@@ -227,7 +226,7 @@ int Menu::insert(const FbString &label, int pos) {
227 return insert(new MenuItem(label, *this), pos); 226 return insert(new MenuItem(label, *this), pos);
228} 227}
229 228
230int Menu::insert(const FbString &label, Menu *submenu, int pos) { 229int Menu::insert(const FbString &label, const RefCount<Menu> &submenu, int pos) {
231 return insert(new MenuItem(label, submenu, this), pos); 230 return insert(new MenuItem(label, submenu, this), pos);
232} 231}
233 232
@@ -274,19 +273,6 @@ int Menu::remove(unsigned int index) {
274 if (index != menuitems.size()) 273 if (index != menuitems.size())
275 fixMenuItemIndices(); 274 fixMenuItemIndices();
276 275
277 if (item->submenu() != 0) {
278 Menu *tmp = item->submenu();
279 // if menu is internal we should just hide it instead
280 // if destroying it
281 if (! tmp->m_internal_menu) {
282 delete tmp;
283 }
284 // We can't internal_hide here, as the child may be deleted!
285// } else
286// tmp->internal_hide();
287 }
288
289
290 delete item; 276 delete item;
291 } 277 }
292 278
@@ -374,8 +360,8 @@ void Menu::enterSubmenu() {
374 if (!validIndex(m_active_index)) 360 if (!validIndex(m_active_index))
375 return; 361 return;
376 362
377 Menu *submenu = menuitems[m_active_index]->submenu(); 363 RefCount<Menu> submenu = menuitems[m_active_index]->submenu();
378 if (submenu == 0) 364 if (! submenu)
379 return; 365 return;
380 366
381 if (submenu->menuitems.size() == 0) 367 if (submenu->menuitems.size() == 0)
@@ -759,7 +745,7 @@ void Menu::drawSubmenu(unsigned int index) {
759 clearItem(index); 745 clearItem(index);
760 746
761 if (! item->submenu()->isVisible() && item->submenu()->numberOfItems() > 0) { 747 if (! item->submenu()->isVisible() && item->submenu()->numberOfItems() > 0) {
762 shown = item->submenu(); 748 shown = item->submenu().get();
763 item->showSubmenu(); 749 item->showSubmenu();
764 item->submenu()->raise(); 750 item->submenu()->raise();
765 } 751 }
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:
65 /// add empty menu item 65 /// add empty menu item
66 int insert(const FbString &label, int pos=-1); 66 int insert(const FbString &label, int pos=-1);
67 /// add submenu 67 /// add submenu
68 int insert(const FbString &label, Menu *submenu, int pos= -1); 68 int insert(const FbString &label, const RefCount<Menu> &submenu, int pos= -1);
69 /// add menu item 69 /// add menu item
70 int insert(MenuItem *item, int pos=-1); 70 int insert(MenuItem *item, int pos=-1);
71 /// remove an item 71 /// remove an item
72 int remove(unsigned int item); 72 int remove(unsigned int item);
73 /// remove all items 73 /// remove all items
74 void removeAll(); 74 void removeAll();
75 void setInternalMenu(bool val = true) { m_internal_menu = val; }
76 void setAlignment(Alignment a) { m_alignment = a; } 75 void setAlignment(Alignment a) { m_alignment = a; }
77 76
78 /// raise this window 77 /// raise this window
@@ -213,7 +212,6 @@ private:
213 bool m_closing; ///< if we're right clicking on the menu title 212 bool m_closing; ///< if we're right clicking on the menu title
214 bool m_visible; ///< menu visibility 213 bool m_visible; ///< menu visibility
215 bool m_torn; ///< torn from parent 214 bool m_torn; ///< torn from parent
216 bool m_internal_menu; ///< whether we should destroy this menu or if it's managed somewhere else
217 bool m_title_vis; ///< title visibility 215 bool m_title_vis; ///< title visibility
218 216
219 int m_which_sub; 217 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 @@
27#include "Image.hh" 27#include "Image.hh"
28#include "App.hh" 28#include "App.hh"
29#include "StringUtil.hh" 29#include "StringUtil.hh"
30#include "Menu.hh"
31#include <X11/keysym.h> 30#include <X11/keysym.h>
32 31
33namespace FbTk { 32namespace 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 @@
22#ifndef FBTK_MENUITEM_HH 22#ifndef FBTK_MENUITEM_HH
23#define FBTK_MENUITEM_HH 23#define FBTK_MENUITEM_HH
24 24
25#include "Menu.hh"
25#include "RefCount.hh" 26#include "RefCount.hh"
26#include "Command.hh" 27#include "Command.hh"
27#include "PixmapWithMask.hh" 28#include "PixmapWithMask.hh"
@@ -32,7 +33,6 @@
32 33
33namespace FbTk { 34namespace FbTk {
34 35
35class Menu;
36class MenuTheme; 36class MenuTheme;
37class FbDrawable; 37class FbDrawable;
38template <class T> class ThemeProxy; 38template <class T> class ThemeProxy;
@@ -80,7 +80,7 @@ public:
80 m_toggle_item(false) 80 m_toggle_item(false)
81 { } 81 { }
82 82
83 MenuItem(const BiDiString &label, Menu *submenu, Menu *host_menu = 0) 83 MenuItem(const BiDiString &label, const RefCount<Menu> &submenu, Menu *host_menu = 0)
84 : m_label(label), 84 : m_label(label),
85 m_menu(host_menu), 85 m_menu(host_menu),
86 m_submenu(submenu), 86 m_submenu(submenu),
@@ -98,7 +98,7 @@ public:
98 virtual void setToggleItem(bool val) { m_toggle_item = val; } 98 virtual void setToggleItem(bool val) { m_toggle_item = val; }
99 void setCloseOnClick(bool val) { m_close_on_click = val; } 99 void setCloseOnClick(bool val) { m_close_on_click = val; }
100 void setIcon(const std::string &filename, int screen_num); 100 void setIcon(const std::string &filename, int screen_num);
101 virtual Menu *submenu() { return m_submenu; } 101 virtual const RefCount<Menu>& submenu() { return m_submenu; }
102 /** 102 /**
103 @name accessors 103 @name accessors
104 */ 104 */
@@ -107,7 +107,7 @@ public:
107 virtual const PixmapWithMask *icon() const { 107 virtual const PixmapWithMask *icon() const {
108 return m_icon.get() ? m_icon->pixmap.get() : 0; 108 return m_icon.get() ? m_icon->pixmap.get() : 0;
109 } 109 }
110 virtual const Menu *submenu() const { return m_submenu; } 110 virtual RefCount<const Menu> submenu() const { return m_submenu; }
111 virtual bool isEnabled() const { return m_enabled; } 111 virtual bool isEnabled() const { return m_enabled; }
112 virtual bool isSelected() const { return m_selected; } 112 virtual bool isSelected() const { return m_selected; }
113 virtual bool isToggleItem() const { return m_toggle_item; } 113 virtual bool isToggleItem() const { return m_toggle_item; }
@@ -150,7 +150,7 @@ public:
150private: 150private:
151 BiDiString m_label; ///< label of this item 151 BiDiString m_label; ///< label of this item
152 Menu *m_menu; ///< the menu we live in 152 Menu *m_menu; ///< the menu we live in
153 Menu *m_submenu; ///< a submenu, 0 if we don't have one 153 RefCount<Menu> m_submenu; ///< a submenu, 0 if we don't have one
154 RefCount<Command<void> > m_command; ///< command to be executed 154 RefCount<Command<void> > m_command; ///< command to be executed
155 bool m_enabled, m_selected; 155 bool m_enabled, m_selected;
156 bool m_close_on_click, m_toggle_item; 156 bool m_close_on_click, m_toggle_item;
diff --git a/src/FbTk/MultiButtonMenuItem.cc b/src/FbTk/MultiButtonMenuItem.cc
index 1b61a99..b10ba07 100644
--- a/src/FbTk/MultiButtonMenuItem.cc
+++ b/src/FbTk/MultiButtonMenuItem.cc
@@ -33,7 +33,8 @@ MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &la
33 init(buttons); 33 init(buttons);
34} 34}
35 35
36MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &label, Menu *submenu): 36MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbTk::BiDiString &label,
37 const RefCount<Menu> &submenu):
37 MenuItem(label, submenu), 38 MenuItem(label, submenu),
38 m_button_exe(0), 39 m_button_exe(0),
39 m_buttons(buttons) { 40 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 {
31class MultiButtonMenuItem: public FbTk::MenuItem { 31class MultiButtonMenuItem: public FbTk::MenuItem {
32public: 32public:
33 MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label); 33 MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label);
34 MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label, Menu *submenu); 34 MultiButtonMenuItem(int buttons, const FbTk::BiDiString& label, const RefCount<Menu> &submenu);
35 virtual ~MultiButtonMenuItem(); 35 virtual ~MultiButtonMenuItem();
36 /// sets command to specified button 36 /// sets command to specified button
37 void setCommand(int button, FbTk::RefCount<FbTk::Command<void> > &cmd); 37 void setCommand(int button, FbTk::RefCount<FbTk::Command<void> > &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:
47 setToggleItem(true); 47 setToggleItem(true);
48 } 48 }
49 49
50 RadioMenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0): 50 RadioMenuItem(const FbString &label, const RefCount<Menu> &submenu, Menu *host_menu = 0):
51 MenuItem(label, submenu, host_menu) { 51 MenuItem(label, submenu, host_menu) {
52 setToggleItem(true); 52 setToggleItem(true);
53 } 53 }