diff options
Diffstat (limited to 'src/WinButton.cc')
-rw-r--r-- | src/WinButton.cc | 291 |
1 files changed, 291 insertions, 0 deletions
diff --git a/src/WinButton.cc b/src/WinButton.cc new file mode 100644 index 0000000..32e51ff --- /dev/null +++ b/src/WinButton.cc | |||
@@ -0,0 +1,291 @@ | |||
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.6 2003/05/07 12:16:09 rathnor Exp $ | ||
23 | |||
24 | #include "WinButton.hh" | ||
25 | #include "App.hh" | ||
26 | #include "Window.hh" | ||
27 | #include "WinButtonTheme.hh" | ||
28 | |||
29 | namespace { | ||
30 | |||
31 | inline void scale(const FbTk::Button &btn, WinButtonTheme::PixmapWithMask &pm) { | ||
32 | // copy pixmap and scale it | ||
33 | pm.pixmap_scaled = pm.pixmap; | ||
34 | pm.mask_scaled = pm.mask; | ||
35 | |||
36 | if (pm.pixmap_scaled.drawable() != 0) | ||
37 | pm.pixmap_scaled.scale(btn.width(), btn.height()); | ||
38 | if (pm.mask_scaled.drawable() != 0) | ||
39 | pm.mask_scaled.scale(btn.width(), btn.height()); | ||
40 | } | ||
41 | |||
42 | void updateScale(const FbTk::Button &btn, WinButtonTheme &theme) { | ||
43 | |||
44 | // we need to scale our pixmaps to right size | ||
45 | scale(btn, theme.closePixmap()); | ||
46 | scale(btn, theme.closeUnfocusPixmap()); | ||
47 | scale(btn, theme.closePressedPixmap()); | ||
48 | |||
49 | scale(btn, theme.maximizePixmap()); | ||
50 | scale(btn, theme.maximizeUnfocusPixmap()); | ||
51 | scale(btn, theme.maximizePressedPixmap()); | ||
52 | |||
53 | scale(btn, theme.iconifyPixmap()); | ||
54 | scale(btn, theme.iconifyUnfocusPixmap()); | ||
55 | scale(btn, theme.iconifyPressedPixmap()); | ||
56 | |||
57 | scale(btn, theme.shadePixmap()); | ||
58 | scale(btn, theme.shadeUnfocusPixmap()); | ||
59 | scale(btn, theme.shadePressedPixmap()); | ||
60 | |||
61 | scale(btn, theme.stickPixmap()); | ||
62 | scale(btn, theme.stickUnfocusPixmap()); | ||
63 | scale(btn, theme.stickPressedPixmap()); | ||
64 | |||
65 | scale(btn, theme.stuckPixmap()); | ||
66 | scale(btn, theme.stuckUnfocusPixmap()); | ||
67 | } | ||
68 | |||
69 | }; | ||
70 | |||
71 | WinButton::WinButton(const FluxboxWindow &listen_to, | ||
72 | WinButtonTheme &theme, | ||
73 | Type buttontype, const FbTk::FbWindow &parent, | ||
74 | int x, int y, | ||
75 | unsigned int width, unsigned int height): | ||
76 | FbTk::Button(parent, x, y, width, height), | ||
77 | m_type(buttontype), m_listen_to(listen_to), m_theme(theme) { | ||
78 | |||
79 | theme.reconfigSig().attach(this); | ||
80 | } | ||
81 | |||
82 | void WinButton::exposeEvent(XExposeEvent &event) { | ||
83 | FbTk::Button::exposeEvent(event); | ||
84 | drawType(); | ||
85 | } | ||
86 | |||
87 | void WinButton::buttonReleaseEvent(XButtonEvent &event) { | ||
88 | FbTk::Button::buttonReleaseEvent(event); | ||
89 | clear(); | ||
90 | } | ||
91 | |||
92 | void WinButton::drawType() { | ||
93 | |||
94 | |||
95 | switch (m_type) { | ||
96 | case MAXIMIZE: | ||
97 | if (m_theme.maximizePixmap().pixmap_scaled.drawable() != 0) { | ||
98 | if (pressed()) { | ||
99 | window().setBackgroundPixmap(m_theme. | ||
100 | maximizePressedPixmap(). | ||
101 | pixmap_scaled.drawable()); | ||
102 | } else if (m_theme.maximizePixmap().pixmap_scaled.drawable()) { | ||
103 | // check focus | ||
104 | if (!m_listen_to.isFocused() && | ||
105 | m_theme.maximizeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
106 | // not focused | ||
107 | window().setBackgroundPixmap(m_theme. | ||
108 | maximizeUnfocusPixmap(). | ||
109 | pixmap_scaled.drawable()); | ||
110 | } else { // focused | ||
111 | window().setBackgroundPixmap(m_theme. | ||
112 | maximizePixmap(). | ||
113 | pixmap_scaled.drawable()); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | window().clear(); | ||
118 | |||
119 | } else { | ||
120 | if (gc() == 0) // must have valid graphic context | ||
121 | return; | ||
122 | window().drawRectangle(gc(), | ||
123 | 2, 2, width() - 5, height() - 5); | ||
124 | window().drawLine(gc(), | ||
125 | 2, 3, width() - 3, 3); | ||
126 | } | ||
127 | break; | ||
128 | case MINIMIZE: | ||
129 | if (m_theme.iconifyPixmap().pixmap_scaled.drawable() != 0) { | ||
130 | if (pressed()) { | ||
131 | window().setBackgroundPixmap(m_theme. | ||
132 | iconifyPressedPixmap(). | ||
133 | pixmap_scaled.drawable()); | ||
134 | } else if (m_theme.iconifyPixmap().pixmap_scaled.drawable()){ | ||
135 | // check focus | ||
136 | if (!m_listen_to.isFocused() && | ||
137 | m_theme.iconifyUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
138 | // not focused | ||
139 | window().setBackgroundPixmap(m_theme. | ||
140 | iconifyUnfocusPixmap(). | ||
141 | pixmap_scaled.drawable()); | ||
142 | } else { // focused | ||
143 | window().setBackgroundPixmap(m_theme. | ||
144 | iconifyPixmap(). | ||
145 | pixmap_scaled.drawable()); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | window().clear(); | ||
150 | |||
151 | } else { | ||
152 | if (gc() == 0) // must have valid graphic context | ||
153 | return; | ||
154 | window().drawRectangle(gc(), | ||
155 | 2, height() - 5, width() - 5, 2); | ||
156 | } | ||
157 | break; | ||
158 | case STICK: | ||
159 | if (m_theme.stickPixmap().pixmap_scaled.drawable() != 0) { | ||
160 | if (m_listen_to.isStuck() && | ||
161 | m_theme.stuckPixmap().pixmap_scaled.drawable() && | ||
162 | ! pressed()) { // we're using the same pixmap for pressed as in not stuck | ||
163 | // check focus | ||
164 | if (!m_listen_to.isFocused() && | ||
165 | m_theme.stuckUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
166 | // not focused | ||
167 | window().setBackgroundPixmap(m_theme. | ||
168 | stuckUnfocusPixmap(). | ||
169 | pixmap_scaled.drawable()); | ||
170 | } else { // focused | ||
171 | window().setBackgroundPixmap(m_theme. | ||
172 | stuckPixmap(). | ||
173 | pixmap_scaled.drawable()); | ||
174 | } | ||
175 | } else { // not stuck | ||
176 | |||
177 | if (pressed()) { | ||
178 | window().setBackgroundPixmap(m_theme. | ||
179 | stickPressedPixmap(). | ||
180 | pixmap_scaled.drawable()); | ||
181 | |||
182 | } else if (m_theme.stickPixmap().pixmap_scaled.drawable()) { | ||
183 | // check focus | ||
184 | if (!m_listen_to.isFocused() && | ||
185 | m_theme.stickUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
186 | // not focused | ||
187 | window().setBackgroundPixmap(m_theme. | ||
188 | stickUnfocusPixmap(). | ||
189 | pixmap_scaled.drawable()); | ||
190 | } else { // focused | ||
191 | window().setBackgroundPixmap(m_theme. | ||
192 | stickPixmap(). | ||
193 | pixmap_scaled.drawable()); | ||
194 | } | ||
195 | |||
196 | } | ||
197 | } // end if stuck | ||
198 | |||
199 | window().clear(); | ||
200 | |||
201 | } else { | ||
202 | if (m_listen_to.isStuck()) { | ||
203 | window().fillRectangle(gc(), | ||
204 | width()/2 - width()/4, height()/2 - height()/4, | ||
205 | width()/2, height()/2); | ||
206 | } else { | ||
207 | if (gc() == 0) // must have valid graphic context | ||
208 | return; | ||
209 | window().fillRectangle(gc(), | ||
210 | width()/2 - width()/10, height()/2 - height()/10, | ||
211 | width()/5, height()/5); | ||
212 | } | ||
213 | } | ||
214 | break; | ||
215 | case CLOSE: | ||
216 | |||
217 | if (m_theme.closePixmap().pixmap_scaled.drawable() != 0) { | ||
218 | if (pressed()) { | ||
219 | window().setBackgroundPixmap(m_theme. | ||
220 | closePressedPixmap(). | ||
221 | pixmap_scaled.drawable()); | ||
222 | |||
223 | } else if (m_theme.closePixmap().pixmap_scaled.drawable()) { | ||
224 | // check focus | ||
225 | if (!m_listen_to.isFocused() && | ||
226 | m_theme.closeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
227 | // not focused | ||
228 | window().setBackgroundPixmap(m_theme. | ||
229 | closeUnfocusPixmap(). | ||
230 | pixmap_scaled.drawable()); | ||
231 | } else { // focused | ||
232 | window().setBackgroundPixmap(m_theme. | ||
233 | closePixmap(). | ||
234 | pixmap_scaled.drawable()); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | window().clear(); | ||
239 | |||
240 | } else { | ||
241 | if (gc() == 0) // must have valid graphic context | ||
242 | return; | ||
243 | window().drawLine(gc(), | ||
244 | 2, 2, | ||
245 | width() - 3, height() - 3); | ||
246 | window().drawLine(gc(), | ||
247 | 2, width() - 3, | ||
248 | height() - 3, 2); | ||
249 | } | ||
250 | break; | ||
251 | case SHADE: | ||
252 | if (m_theme.shadePixmap().pixmap_scaled.drawable() != 0) { | ||
253 | if (pressed()) { | ||
254 | window().setBackgroundPixmap(m_theme. | ||
255 | shadePressedPixmap(). | ||
256 | pixmap_scaled.drawable()); | ||
257 | } else if (m_theme.shadePixmap().pixmap_scaled.drawable()) { | ||
258 | // check focus | ||
259 | if (!m_listen_to.isFocused() && | ||
260 | m_theme.shadeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | ||
261 | // not focused | ||
262 | window().setBackgroundPixmap(m_theme. | ||
263 | shadeUnfocusPixmap(). | ||
264 | pixmap_scaled.drawable()); | ||
265 | } else { // focused | ||
266 | window().setBackgroundPixmap(m_theme. | ||
267 | shadePixmap(). | ||
268 | pixmap_scaled.drawable()); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | window().clear(); | ||
273 | } | ||
274 | break; | ||
275 | } | ||
276 | } | ||
277 | |||
278 | void WinButton::clear() { | ||
279 | FbTk::Button::clear(); | ||
280 | drawType(); | ||
281 | } | ||
282 | |||
283 | void WinButton::update(FbTk::Subject *subj) { | ||
284 | clear(); | ||
285 | |||
286 | //!! TODO | ||
287 | // We need to optimize this | ||
288 | // This shouldn't be run on every button in every fluxbox window | ||
289 | updateScale(*this, m_theme); | ||
290 | drawType(); | ||
291 | } | ||