fix window button image updates

This commit is contained in:
simonb 2006-04-14 14:22:16 +00:00
parent 33079d2593
commit 0780952b10
5 changed files with 35 additions and 18 deletions

View file

@ -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:

View file

@ -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<Command> &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);
}
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
}
}

View file

@ -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<Command> m_onclick[5]; ///< what to do when this button is clicked with button num
};

View file

@ -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())

View file

@ -4008,6 +4008,7 @@ void FluxboxWindow::setupWindow() {
frame().titlebar(),
0, 0, 10, 10);
stateSig().attach(winbtn);
winbtn->setOnClick(stick_cmd);
break;
case WinButton::SHADE: