aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Menu.cc
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/Menu.cc
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/Menu.cc')
-rw-r--r--src/FbTk/Menu.cc24
1 files changed, 5 insertions, 19 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 }