From 0780952b102b48e4448bbd514dad6297899be1e4 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 14 Apr 2006 14:22:16 +0000 Subject: fix window button image updates --- ChangeLog | 4 ++++ src/FbTk/Button.cc | 43 +++++++++++++++++++++++++++---------------- src/FbTk/Button.hh | 1 + src/WinButton.cc | 4 ++-- src/Window.cc | 1 + 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6a32df..83af74f 100644 --- a/ChangeLog +++ b/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: diff --git a/src/FbTk/Button.cc b/src/FbTk/Button.cc index e2ba7b5..8dba936 100644 --- a/src/FbTk/Button.cc +++ b/src/FbTk/Button.cc @@ -37,7 +37,8 @@ Button::Button(int screen_num, int x, int y, 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 @@ Button::Button(const FbWindow &parent, int x, int y, 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 &cmd, int button) { @@ -107,26 +111,33 @@ void Button::buttonPressEvent(XButtonEvent &event) { 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); - } - - if (update) - clear(); // clear background + bool been_deleted = false; + mark_if_deleted = &been_deleted; - // 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(width()) && event.y > 0 && event.y < static_cast(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 + } } diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh index fe65f1b..89a754c 100644 --- a/src/FbTk/Button.hh +++ b/src/FbTk/Button.hh @@ -87,6 +87,7 @@ private: 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 m_onclick[5]; ///< what to do when this button is clicked with button num }; diff --git a/src/WinButton.cc b/src/WinButton.cc index 6c51a6d..afdfb7f 100644 --- a/src/WinButton.cc +++ b/src/WinButton.cc @@ -187,9 +187,9 @@ Pixmap WinButton::getPressedPixmap() const { 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()) diff --git a/src/Window.cc b/src/Window.cc index 6330da5..0504deb 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -4008,6 +4008,7 @@ void FluxboxWindow::setupWindow() { frame().titlebar(), 0, 0, 10, 10); + stateSig().attach(winbtn); winbtn->setOnClick(stick_cmd); break; case WinButton::SHADE: -- cgit v0.11.2