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/FbTk/MenuItem.hh | |
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/FbTk/MenuItem.hh')
-rw-r--r-- | src/FbTk/MenuItem.hh | 10 |
1 files changed, 5 insertions, 5 deletions
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 | ||
33 | namespace FbTk { | 34 | namespace FbTk { |
34 | 35 | ||
35 | class Menu; | ||
36 | class MenuTheme; | 36 | class MenuTheme; |
37 | class FbDrawable; | 37 | class FbDrawable; |
38 | template <class T> class ThemeProxy; | 38 | template <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: | |||
150 | private: | 150 | private: |
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; |