diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-02 15:21:24 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:57:20 (GMT) |
commit | f2709b26d8af7292f750fc05525ac90ad0d99c41 (patch) | |
tree | 794903544922abe2b90af6250de24124cd94d546 /src/IconbarTool.cc | |
parent | 0584414d3845239202d5ea02da2ce6fb5b1b0cbb (diff) | |
download | fluxbox_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/IconbarTool.cc')
-rw-r--r-- | src/IconbarTool.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index ebf67fe..070e45b 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc | |||
@@ -246,12 +246,12 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, | |||
246 | m_rc_client_padding(screen.resourceManager(), 10, | 246 | m_rc_client_padding(screen.resourceManager(), 10, |
247 | screen.name() + ".iconbar.iconTextPadding"), | 247 | screen.name() + ".iconbar.iconTextPadding"), |
248 | m_rc_use_pixmap(screen.resourceManager(), true, screen.name() + ".iconbar.usePixmap"), | 248 | m_rc_use_pixmap(screen.resourceManager(), true, screen.name() + ".iconbar.usePixmap"), |
249 | m_menu(screen.menuTheme(), screen.imageControl(), | 249 | m_menu(new FbMenu(screen.menuTheme(), screen.imageControl(), |
250 | *screen.layerManager().getLayer(ResourceLayer::MENU)), | 250 | *screen.layerManager().getLayer(ResourceLayer::MENU)) ), |
251 | m_alpha(255) { | 251 | m_alpha(255) { |
252 | 252 | ||
253 | // setup mode menu | 253 | // setup mode menu |
254 | setupModeMenu(m_menu, *this); | 254 | setupModeMenu(*m_menu, *this); |
255 | _FB_USES_NLS; | 255 | _FB_USES_NLS; |
256 | using namespace FbTk; | 256 | using namespace FbTk; |
257 | // setup use pixmap item to reconfig iconbar and save resource on click | 257 | // setup use pixmap item to reconfig iconbar and save resource on click |
@@ -261,15 +261,13 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, | |||
261 | save_and_reconfig->add(reconfig); | 261 | save_and_reconfig->add(reconfig); |
262 | save_and_reconfig->add(save); | 262 | save_and_reconfig->add(save); |
263 | RefCount<Command<void> > s_and_reconfig(save_and_reconfig); | 263 | RefCount<Command<void> > s_and_reconfig(save_and_reconfig); |
264 | m_menu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, | 264 | m_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, |
265 | "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), | 265 | "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), |
266 | m_rc_use_pixmap, s_and_reconfig)); | 266 | m_rc_use_pixmap, s_and_reconfig)); |
267 | m_menu.updateMenu(); | 267 | m_menu->updateMenu(); |
268 | // must be internal menu, otherwise toolbar main menu tries to delete it. | ||
269 | m_menu.setInternalMenu(); | ||
270 | 268 | ||
271 | // add iconbar menu to toolbar menu | 269 | // add iconbar menu to toolbar menu |
272 | menu.insert(m_menu.label().logical(), &m_menu); | 270 | menu.insert(m_menu->label().logical(), FbTk::RefCount<FbTk::Menu>(m_menu)); |
273 | 271 | ||
274 | // setup signals | 272 | // setup signals |
275 | m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); | 273 | m_tracker.join(theme.reconfigSig(), FbTk::MemFun(*this, &IconbarTool::themeReconfigured)); |
@@ -313,7 +311,7 @@ void IconbarTool::hide() { | |||
313 | void IconbarTool::setAlignment(FbTk::Container::Alignment align) { | 311 | void IconbarTool::setAlignment(FbTk::Container::Alignment align) { |
314 | *m_rc_alignment = align; | 312 | *m_rc_alignment = align; |
315 | update(ALIGN, NULL); | 313 | update(ALIGN, NULL); |
316 | m_menu.reconfigure(); | 314 | m_menu->reconfigure(); |
317 | } | 315 | } |
318 | 316 | ||
319 | void IconbarTool::setMode(string mode) { | 317 | void IconbarTool::setMode(string mode) { |
@@ -353,7 +351,7 @@ void IconbarTool::setMode(string mode) { | |||
353 | 351 | ||
354 | renderTheme(); | 352 | renderTheme(); |
355 | 353 | ||
356 | m_menu.reconfigure(); | 354 | m_menu->reconfigure(); |
357 | } | 355 | } |
358 | 356 | ||
359 | unsigned int IconbarTool::width() const { | 357 | unsigned int IconbarTool::width() const { |