aboutsummaryrefslogtreecommitdiff
path: root/src/WinButton.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/WinButton.cc')
-rw-r--r--src/WinButton.cc289
1 files changed, 289 insertions, 0 deletions
diff --git a/src/WinButton.cc b/src/WinButton.cc
new file mode 100644
index 0000000..6af0dae
--- /dev/null
+++ b/src/WinButton.cc
@@ -0,0 +1,289 @@
1// WinButton.cc for Fluxbox Window Manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22/// $Id: WinButton.cc,v 1.17 2004/01/10 00:37:35 rathnor Exp $
23
24#include "WinButton.hh"
25#include "App.hh"
26#include "Window.hh"
27#include "WinButtonTheme.hh"
28
29WinButton::WinButton(const FluxboxWindow &listen_to,
30 WinButtonTheme &theme,
31 Type buttontype, const FbTk::FbWindow &parent,
32 int x, int y,
33 unsigned int width, unsigned int height):
34 FbTk::Button(parent, x, y, width, height),
35 m_type(buttontype), m_listen_to(listen_to), m_theme(theme) {
36
37 theme.reconfigSig().attach(this);
38}
39
40void WinButton::exposeEvent(XExposeEvent &event) {
41 FbTk::Button::exposeEvent(event);
42 drawType(false, false);
43}
44
45void WinButton::buttonReleaseEvent(XButtonEvent &event) {
46 FbTk::Button::buttonReleaseEvent(event);
47 clear();
48 updateTransparent();
49}
50
51// clear is used to force this to clear the window (e.g. called from clear())
52void WinButton::drawType(bool clear, bool no_trans) {
53 bool used = false;
54
55 // if it's odd and we're centring, we need to add one
56 int oddW = width()%2;
57 int oddH = height()%2;
58
59 switch (m_type) {
60 case MAXIMIZE:
61
62 if (pressed() && m_theme.maximizePressedPixmap().pixmap().drawable() != 0) {
63 FbTk::FbWindow::setBackgroundPixmap(m_theme.
64 maximizePressedPixmap().
65 pixmap().drawable());
66 used = true;
67 } else {
68 // check focus
69 if (!m_listen_to.isFocused()) {
70 if (m_theme.maximizeUnfocusPixmap().pixmap().drawable() != 0) {
71 // not focused
72 FbTk::FbWindow::setBackgroundPixmap(m_theme.
73 maximizeUnfocusPixmap().
74 pixmap().drawable());
75 used = true;
76 }
77 } else if (m_theme.maximizePixmap().pixmap().drawable() != 0) {
78 FbTk::FbWindow::setBackgroundPixmap(m_theme.
79 maximizePixmap().
80 pixmap().drawable());
81 used = true;
82 }
83 }
84 if (used || clear)
85 FbTk::FbWindow::clear();
86
87 // if no pixmap was used, use old style
88 if (!used) {
89 if (gc() == 0) // must have valid graphic context
90 return;
91
92 drawRectangle(gc(),
93 2, 2, width() - 5, height() - 5);
94 drawLine(gc(),
95 2, 3, width() - 3, 3);
96 }
97 break;
98 case MINIMIZE:
99
100 if (pressed() && m_theme.iconifyPressedPixmap().pixmap().drawable() != 0) {
101 FbTk::FbWindow::setBackgroundPixmap(m_theme.
102 iconifyPressedPixmap().
103 pixmap().drawable());
104 used = true;
105 } else {
106 if (m_theme.iconifyPixmap().pixmap().drawable()){
107 // check focus
108 if (!m_listen_to.isFocused()) {
109 if (m_theme.iconifyUnfocusPixmap().pixmap().drawable() != 0) {
110 // not focused
111 FbTk::FbWindow::setBackgroundPixmap(m_theme.
112 iconifyUnfocusPixmap().
113 pixmap().drawable());
114 used = true;
115 }
116 } else if (m_theme.iconifyPixmap().pixmap().drawable() != 0) {
117 FbTk::FbWindow::setBackgroundPixmap(m_theme.
118 iconifyPixmap().
119 pixmap().drawable());
120 used = true;
121 }
122 }
123
124 }
125
126 if (used || clear) {
127 FbTk::FbWindow::clear();
128 }
129 if (!used && gc() != 0) { // must have valid graphic context
130 FbTk::FbWindow::drawRectangle(gc(),
131 2, height() - 5, width() - 5, 2);
132 }
133 break;
134 case STICK:
135
136 if (m_listen_to.isStuck() && !pressed()) {
137 if ( m_theme.stuckPixmap().pixmap().drawable() &&
138 ! pressed()) { // we're using the same pixmap for pressed as in not stuck
139 // check focus
140 if (!m_listen_to.isFocused()) {
141 if ( m_theme.stuckUnfocusPixmap().pixmap().drawable() != 0) {
142 // not focused
143 FbTk::FbWindow::setBackgroundPixmap(m_theme.
144 stuckUnfocusPixmap().
145 pixmap().drawable());
146 used = true;
147 }
148 } else if (m_theme.stuckPixmap().pixmap().drawable() != 0) {
149 // focused
150 FbTk::FbWindow::setBackgroundPixmap(m_theme.
151 stuckPixmap().
152 pixmap().drawable());
153 used = true;
154 }
155 }
156 } else { // not stuck and pressed
157 if (pressed()) {
158 if (m_theme.stickPressedPixmap().pixmap().drawable() != 0) {
159 FbTk::FbWindow::setBackgroundPixmap(m_theme.
160 stickPressedPixmap().
161 pixmap().drawable());
162 used = true;
163 }
164 } else { // not pressed
165 // check focus
166 if (!m_listen_to.isFocused()) {
167 if (m_theme.stickUnfocusPixmap().pixmap().drawable() != 0) {
168 // not focused
169 FbTk::FbWindow::setBackgroundPixmap(m_theme.
170 stickUnfocusPixmap().
171 pixmap().drawable());
172 used = true;
173 }
174 } else if (m_theme.stickPixmap().pixmap().drawable()) { // focused
175 FbTk::FbWindow::setBackgroundPixmap(m_theme.
176 stickPixmap().
177 pixmap().drawable());
178 used = true;
179 }
180
181 }
182
183 }
184
185 if (used || clear)
186 FbTk::FbWindow::clear();
187
188 if (!used && gc() != 0) {
189 // width/4 != width/2, so we use /4*2 so that it's properly centred
190 if (m_listen_to.isStuck()) {
191 fillRectangle(gc(),
192 width()/2 - width()/4, height()/2 - height()/4,
193 width()/4*2 + oddW, height()/4*2 + oddH);
194 } else {
195 fillRectangle(gc(),
196 width()/2 - width()/10, height()/2 - height()/10,
197 width()/10*2 + oddW, height()/10*2 + oddH);
198 }
199 }
200 break;
201 case CLOSE:
202
203 if (pressed()) {
204 if (m_theme.closePressedPixmap().pixmap().drawable()) {
205 FbTk::FbWindow::setBackgroundPixmap(m_theme.
206 closePressedPixmap().
207 pixmap().drawable());
208 used = true;
209 }
210 } else { // not pressed
211 // check focus
212 if (!m_listen_to.isFocused()) {
213 if (m_theme.closeUnfocusPixmap().pixmap().drawable() != 0) {
214 // not focused
215 FbTk::FbWindow::setBackgroundPixmap(m_theme.
216 closeUnfocusPixmap().
217 pixmap().drawable());
218 used = true;
219 }
220 } else if (m_theme.closePixmap().pixmap().drawable() != 0) { // focused
221 FbTk::FbWindow::setBackgroundPixmap(m_theme.
222 closePixmap().
223 pixmap().drawable());
224 used = true;
225 }
226 }
227
228
229 if (used || clear)
230 FbTk::FbWindow::clear();
231
232 if (!used && gc() != 0) { // must have valid graphic context
233
234 drawLine(gc(),
235 2, 2,
236 width() - 2, height() - 2);
237 // I can't figure out why this second one needs a y offset of 1?????
238 // but it does - at least on my box:
239 // XFree86 Version 4.2.1.1 (Debian 4.2.1-12.1 20031003005825)
240 // (protocol Version 11, revision 0, vendor release 6600)
241
242 drawLine(gc(),
243 2, height() - 3,
244 width() - 2, 1);
245 }
246 break;
247 case SHADE:
248
249 if (pressed()) {
250 if (m_theme.shadePressedPixmap().pixmap().drawable()) {
251 FbTk::FbWindow::setBackgroundPixmap(m_theme.
252 shadePressedPixmap().
253 pixmap().drawable());
254 used = true;
255 }
256 } else { // not pressed
257 // check focus
258 if (!m_listen_to.isFocused()) {
259 if ( m_theme.shadeUnfocusPixmap().pixmap().drawable() != 0) {
260 // not focused
261 FbTk::FbWindow::setBackgroundPixmap(m_theme.
262 shadeUnfocusPixmap().
263 pixmap().drawable());
264 used = true;
265 }
266 } else if (m_theme.shadePixmap().pixmap().drawable() != 0) { // focused
267 FbTk::FbWindow::setBackgroundPixmap(m_theme.
268 shadePixmap().
269 pixmap().drawable());
270 used = true;
271 }
272 }
273
274 if (used || clear)
275 FbTk::FbWindow::clear();
276
277 break;
278 }
279 if ((used || clear) && !no_trans)
280 updateTransparent();
281}
282
283void WinButton::clear() {
284 drawType(true, true);
285}
286
287void WinButton::update(FbTk::Subject *subj) {
288 clear();
289}