aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Button.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2006-04-14 14:22:16 (GMT)
committersimonb <simonb>2006-04-14 14:22:16 (GMT)
commit0780952b102b48e4448bbd514dad6297899be1e4 (patch)
treeec2213d7843b82ff8d03d6d2bcc2079970896ca4 /src/FbTk/Button.cc
parent33079d2593a7a598446cc837fc39eb2a914ebb1f (diff)
downloadfluxbox-0780952b102b48e4448bbd514dad6297899be1e4.zip
fluxbox-0780952b102b48e4448bbd514dad6297899be1e4.tar.bz2
fix window button image updates
Diffstat (limited to 'src/FbTk/Button.cc')
-rw-r--r--src/FbTk/Button.cc43
1 files changed, 27 insertions, 16 deletions
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,
37 m_pressed_pm(0), 37 m_pressed_pm(0),
38 m_pressed_color(), 38 m_pressed_color(),
39 m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)), 39 m_gc(DefaultGC(FbTk::App::instance()->display(), screen_num)),
40 m_pressed(false) { 40 m_pressed(false),
41 mark_if_deleted(0) {
41 42
42 // add this to eventmanager 43 // add this to eventmanager
43 FbTk::EventManager::instance()->add(*this, *this); 44 FbTk::EventManager::instance()->add(*this, *this);
@@ -51,13 +52,16 @@ Button::Button(const FbWindow &parent, int x, int y,
51 m_pressed_pm(0), 52 m_pressed_pm(0),
52 m_pressed_color(), 53 m_pressed_color(),
53 m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())), 54 m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
54 m_pressed(false) { 55 m_pressed(false),
56 mark_if_deleted(0) {
55 // add this to eventmanager 57 // add this to eventmanager
56 FbTk::EventManager::instance()->add(*this, *this); 58 FbTk::EventManager::instance()->add(*this, *this);
57} 59}
58 60
59Button::~Button() { 61Button::~Button() {
60 62 if (mark_if_deleted) {
63 *mark_if_deleted = true;
64 }
61} 65}
62 66
63void Button::setOnClick(RefCount<Command> &cmd, int button) { 67void Button::setOnClick(RefCount<Command> &cmd, int button) {
@@ -107,26 +111,33 @@ void Button::buttonPressEvent(XButtonEvent &event) {
107void Button::buttonReleaseEvent(XButtonEvent &event) { 111void Button::buttonReleaseEvent(XButtonEvent &event) {
108 m_pressed = false; 112 m_pressed = false;
109 bool update = false; 113 bool update = false;
110 if (m_background_pm) { 114 bool been_deleted = false;
111 if (m_pressed_pm != 0) { 115 mark_if_deleted = &been_deleted;
112 update = true;
113 setBackgroundPixmap(m_background_pm);
114 }
115 } else if (m_pressed_color.isAllocated()) {
116 update = true;
117 setBackgroundColor(m_background_color);
118 }
119
120 if (update)
121 clear(); // clear background
122 116
123 // finaly, execute command (this must be done last since this object might be deleted by the command) 117 // This command may result in this object being deleted
118 // hence the mark_if_deleted mechanism so that we can
119 // update our state after the command
124 if (event.button > 0 && event.button <= 5 && 120 if (event.button > 0 && event.button <= 5 &&
125 event.x > 0 && event.x < static_cast<signed>(width()) && 121 event.x > 0 && event.x < static_cast<signed>(width()) &&
126 event.y > 0 && event.y < static_cast<signed>(height()) && 122 event.y > 0 && event.y < static_cast<signed>(height()) &&
127 m_onclick[event.button -1].get() != 0) 123 m_onclick[event.button -1].get() != 0)
128 m_onclick[event.button - 1]->execute(); 124 m_onclick[event.button - 1]->execute();
129 125
126 if (!been_deleted) {
127 mark_if_deleted = 0;
128 if (m_background_pm) {
129 if (m_pressed_pm != 0) {
130 update = true;
131 setBackgroundPixmap(m_background_pm);
132 }
133 } else if (m_pressed_color.isAllocated()) {
134 update = true;
135 setBackgroundColor(m_background_color);
136 }
137
138 if (update)
139 clear(); // clear background
140 }
130 141
131} 142}
132 143