From 1d0b23bd020c9185dc9cbf8952ab97a27f061be0 Mon Sep 17 00:00:00 2001 From: simonb Date: Sat, 24 Jun 2006 13:11:27 +0000 Subject: fix disappearing menu selection boxes --- ChangeLog | 4 ++++ src/FbTk/FbPixmap.cc | 19 +++++++++++-------- src/FbTk/FbPixmap.hh | 7 +++++++ src/FbTk/Menu.cc | 4 ++-- src/FbTk/MenuTheme.hh | 13 +++++++++++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6da5371..8547ce9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ (Format: Year/Month/Day) Changes for 1.0rc2: +*06/06/24: + * Fix bug #1362463, menu selection pixmaps disappear (Simon) + - pixmap from image cache was put into FbPixmap, which freed it. + FbPixmap.hh/cc MenuTheme.hh Menu.cc *06/06/23: * Make startfluxbox aware of --program-prefix and --program-suffix (Mark) configure.in util/Makefile.am util/startfluxbox.in diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc index c605feb..46ee97c 100644 --- a/src/FbTk/FbPixmap.cc +++ b/src/FbTk/FbPixmap.cc @@ -54,18 +54,18 @@ Atom FbPixmap::root_prop_atoms[] = { FbPixmap::FbPixmap():m_pm(0), m_width(0), m_height(0), - m_depth(0) { + m_depth(0), m_dont_free(false) { } FbPixmap::FbPixmap(const FbPixmap &the_copy):FbDrawable(), m_pm(0), m_width(0), m_height(0), - m_depth(0){ + m_depth(0), m_dont_free(false) { copy(the_copy); } FbPixmap::FbPixmap(Pixmap pm):m_pm(0), m_width(0), m_height(0), - m_depth(0) { + m_depth(0), m_dont_free(false) { if (pm == 0) return; // assign X pixmap to this @@ -76,7 +76,7 @@ FbPixmap::FbPixmap(const FbDrawable &src, unsigned int width, unsigned int height, unsigned int depth):m_pm(0), m_width(0), m_height(0), - m_depth(0) { + m_depth(0), m_dont_free(false) { create(src.drawable(), width, height, depth); } @@ -85,7 +85,7 @@ FbPixmap::FbPixmap(Drawable src, unsigned int width, unsigned int height, unsigned int depth):m_pm(0), m_width(0), m_height(0), - m_depth(0) { + m_depth(0), m_dont_free(false) { create(src, width, height, depth); } @@ -470,10 +470,13 @@ void FbPixmap::checkAtoms() { } void FbPixmap::free() { - if (m_pm != 0) { + if (!m_dont_free && m_pm != 0) XFreePixmap(display(), m_pm); - m_pm = 0; - } + + /* note: m_dont_free shouldnt be required anywhere else, + because then free() isn't being called appropriately! */ + m_dont_free = false; + m_pm = 0; m_width = 0; m_height = 0; m_depth = 0; diff --git a/src/FbTk/FbPixmap.hh b/src/FbTk/FbPixmap.hh index 2935978..dab364a 100644 --- a/src/FbTk/FbPixmap.hh +++ b/src/FbTk/FbPixmap.hh @@ -77,12 +77,19 @@ public: unsigned int width, unsigned int height, unsigned int depth); + /* Will be reset to false whenever this pixmap is reassigned */ + void dontFree() { m_dont_free = true; } + private: void free(); + Pixmap m_pm; unsigned int m_width, m_height; unsigned int m_depth; + // if pixmap not *owned* by this object (eg assigned from cache object) + bool m_dont_free; + /// Functions relating to the maintenance of root window pixmap caching static void checkAtoms(); diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index b0e5c4e..b067361 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -470,11 +470,11 @@ void Menu::updateMenu(int active_index) { if (!theme().selectedPixmap().pixmap().drawable()) { int hw = theme().itemHeight() / 2; - m_theme.setSelectedPixmap(m_image_ctrl.renderImage(hw, hw, theme().hiliteTexture())); + m_theme.setSelectedPixmap(m_image_ctrl.renderImage(hw, hw, theme().hiliteTexture()), true); if (!theme().highlightSelectedPixmap().pixmap().drawable()) { int hw = theme().itemHeight() / 2; - m_theme.setHighlightSelectedPixmap(m_image_ctrl.renderImage(hw, hw, theme().frameTexture())); + m_theme.setHighlightSelectedPixmap(m_image_ctrl.renderImage(hw, hw, theme().frameTexture()), true); } } diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh index c423cf4..da5b65c 100644 --- a/src/FbTk/MenuTheme.hh +++ b/src/FbTk/MenuTheme.hh @@ -126,8 +126,17 @@ public: inline const FbTk::Color &borderColor() const { return *m_border_color; } // special override - inline void setSelectedPixmap(Pixmap pm) { m_selected_pixmap->pixmap() = pm; } - inline void setHighlightSelectedPixmap(Pixmap pm) { m_hl_selected_pixmap->pixmap() = pm; } + inline void setSelectedPixmap(Pixmap pm, bool is_imagecached) { + m_selected_pixmap->pixmap() = pm; + if (is_imagecached) + m_selected_pixmap->pixmap().dontFree(); + } + + inline void setHighlightSelectedPixmap(Pixmap pm, bool is_imagecached) { + m_hl_selected_pixmap->pixmap() = pm; + if (is_imagecached) + m_hl_selected_pixmap->pixmap().dontFree(); + } private: FbTk::ThemeItem t_text, f_text, h_text, d_text; -- cgit v0.11.2