fix window button image updates
simonb simonb
5 files changed,
35 insertions(+),
18 deletions(-)
M
ChangeLog
→
ChangeLog
@@ -1,5 +1,9 @@
(Format: Year/Month/Day) Changes for 0.9.16: +*06/04/14: + * Fix updating of button state (esp stick/shade) (Simon) + (sf.net #1281724, #1213257) + FbTk/Button.hh/cc WinButton.cc Window.cc *06/04/13: * Provide "Key Modes" (Thanks Mark Tiefenbruck, mark at tiefenbruck dot org) - New action in keys file:
M
src/FbTk/Button.cc
→
src/FbTk/Button.cc
@@ -37,7 +37,8 @@ m_background_pm(0),
m_pressed_pm(0), m_pressed_color(), m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)), - m_pressed(false) { + m_pressed(false), + mark_if_deleted(0) { // add this to eventmanager FbTk::EventManager::instance()->add(*this, *this);@@ -51,13 +52,16 @@ m_background_pm(0),
m_pressed_pm(0), m_pressed_color(), m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())), - m_pressed(false) { + m_pressed(false), + mark_if_deleted(0) { // add this to eventmanager FbTk::EventManager::instance()->add(*this, *this); } Button::~Button() { - + if (mark_if_deleted) { + *mark_if_deleted = true; + } } void Button::setOnClick(RefCount<Command> &cmd, int button) {@@ -107,26 +111,33 @@
void Button::buttonReleaseEvent(XButtonEvent &event) { m_pressed = false; bool update = false; - if (m_background_pm) { - if (m_pressed_pm != 0) { - update = true; - setBackgroundPixmap(m_background_pm); - } - } else if (m_pressed_color.isAllocated()) { - update = true; - setBackgroundColor(m_background_color); - } + bool been_deleted = false; + mark_if_deleted = &been_deleted; - if (update) - clear(); // clear background - - // finaly, execute command (this must be done last since this object might be deleted by the command) + // This command may result in this object being deleted + // hence the mark_if_deleted mechanism so that we can + // update our state after the command if (event.button > 0 && event.button <= 5 && event.x > 0 && event.x < static_cast<signed>(width()) && event.y > 0 && event.y < static_cast<signed>(height()) && m_onclick[event.button -1].get() != 0) m_onclick[event.button - 1]->execute(); + if (!been_deleted) { + mark_if_deleted = 0; + if (m_background_pm) { + if (m_pressed_pm != 0) { + update = true; + setBackgroundPixmap(m_background_pm); + } + } else if (m_pressed_color.isAllocated()) { + update = true; + setBackgroundColor(m_background_color); + } + + if (update) + clear(); // clear background + } }
M
src/FbTk/Button.hh
→
src/FbTk/Button.hh
@@ -87,6 +87,7 @@ Pixmap m_pressed_pm; ///< pressed pixmap
Color m_pressed_color; GC m_gc; ///< graphic context for button bool m_pressed; ///< if the button is pressed + bool *mark_if_deleted; ///< if the button is deleted and this is set, make it true RefCount<Command> m_onclick[5]; ///< what to do when this button is clicked with button num };
M
src/WinButton.cc
→
src/WinButton.cc
@@ -187,9 +187,9 @@ case CLOSE:
return m_theme.closePressedPixmap().pixmap().drawable(); case SHADE: if (m_listen_to.isShaded()) - return m_theme.unshadePressedPixmap().pixmap().drawable(); - else return m_theme.shadePressedPixmap().pixmap().drawable(); + else + return m_theme.unshadePressedPixmap().pixmap().drawable(); case MENUICON: if (m_icon_pixmap.drawable()) if (m_listen_to.isFocused())
M
src/Window.cc
→
src/Window.cc
@@ -4008,6 +4008,7 @@ dir[i],
frame().titlebar(), 0, 0, 10, 10); + stateSig().attach(winbtn); winbtn->setOnClick(stick_cmd); break; case WinButton::SHADE: