diff options
Diffstat (limited to 'src/WinButton.cc')
-rw-r--r-- | src/WinButton.cc | 244 |
1 files changed, 244 insertions, 0 deletions
diff --git a/src/WinButton.cc b/src/WinButton.cc new file mode 100644 index 0000000..2534296 --- /dev/null +++ b/src/WinButton.cc | |||
@@ -0,0 +1,244 @@ | |||
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.10 2003/08/22 21:33:13 fluxgen Exp $ | ||
23 | |||
24 | #include "WinButton.hh" | ||
25 | #include "App.hh" | ||
26 | #include "Window.hh" | ||
27 | #include "WinButtonTheme.hh" | ||
28 | |||
29 | WinButton::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 | |||
40 | void WinButton::exposeEvent(XExposeEvent &event) { | ||
41 | FbTk::Button::exposeEvent(event); | ||
42 | drawType(); | ||
43 | updateTransparent(); | ||
44 | } | ||
45 | |||
46 | void WinButton::buttonReleaseEvent(XButtonEvent &event) { | ||
47 | FbTk::Button::buttonReleaseEvent(event); | ||
48 | clear(); | ||
49 | } | ||
50 | |||
51 | void WinButton::drawType() { | ||
52 | |||
53 | switch (m_type) { | ||
54 | case MAXIMIZE: | ||
55 | if (m_theme.maximizePixmap().pixmap().drawable() != 0) { | ||
56 | if (pressed()) { | ||
57 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
58 | maximizePressedPixmap(). | ||
59 | pixmap().drawable()); | ||
60 | } else if (m_theme.maximizePixmap().pixmap().drawable()) { | ||
61 | // check focus | ||
62 | if (!m_listen_to.isFocused() && | ||
63 | m_theme.maximizeUnfocusPixmap().pixmap().drawable() != 0) { | ||
64 | // not focused | ||
65 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
66 | maximizeUnfocusPixmap(). | ||
67 | pixmap().drawable()); | ||
68 | } else { // focused | ||
69 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
70 | maximizePixmap(). | ||
71 | pixmap().drawable()); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | FbTk::FbWindow::clear(); | ||
76 | |||
77 | } else { | ||
78 | if (gc() == 0) // must have valid graphic context | ||
79 | return; | ||
80 | drawRectangle(gc(), | ||
81 | 2, 2, width() - 5, height() - 5); | ||
82 | drawLine(gc(), | ||
83 | 2, 3, width() - 3, 3); | ||
84 | } | ||
85 | break; | ||
86 | case MINIMIZE: | ||
87 | if (m_theme.iconifyPixmap().pixmap().drawable() != 0) { | ||
88 | if (pressed()) { | ||
89 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
90 | iconifyPressedPixmap(). | ||
91 | pixmap().drawable()); | ||
92 | } else if (m_theme.iconifyPixmap().pixmap().drawable()){ | ||
93 | // check focus | ||
94 | if (!m_listen_to.isFocused() && | ||
95 | m_theme.iconifyUnfocusPixmap().pixmap().drawable() != 0) { | ||
96 | // not focused | ||
97 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
98 | iconifyUnfocusPixmap(). | ||
99 | pixmap().drawable()); | ||
100 | } else { // focused | ||
101 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
102 | iconifyPixmap(). | ||
103 | pixmap().drawable()); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | FbTk::FbWindow::clear(); | ||
108 | |||
109 | } else { | ||
110 | if (gc() == 0) // must have valid graphic context | ||
111 | return; | ||
112 | FbTk::FbWindow::drawRectangle(gc(), | ||
113 | 2, height() - 5, width() - 5, 2); | ||
114 | } | ||
115 | break; | ||
116 | case STICK: | ||
117 | if (m_theme.stickPixmap().pixmap().drawable() != 0) { | ||
118 | if (m_listen_to.isStuck() && | ||
119 | m_theme.stuckPixmap().pixmap().drawable() && | ||
120 | ! pressed()) { // we're using the same pixmap for pressed as in not stuck | ||
121 | // check focus | ||
122 | if (!m_listen_to.isFocused() && | ||
123 | m_theme.stuckUnfocusPixmap().pixmap().drawable() != 0) { | ||
124 | // not focused | ||
125 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
126 | stuckUnfocusPixmap(). | ||
127 | pixmap().drawable()); | ||
128 | } else { // focused | ||
129 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
130 | stuckPixmap(). | ||
131 | pixmap().drawable()); | ||
132 | } | ||
133 | } else { // not stuck | ||
134 | |||
135 | if (pressed()) { | ||
136 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
137 | stickPressedPixmap(). | ||
138 | pixmap().drawable()); | ||
139 | |||
140 | } else if (m_theme.stickPixmap().pixmap().drawable()) { | ||
141 | // check focus | ||
142 | if (!m_listen_to.isFocused() && | ||
143 | m_theme.stickUnfocusPixmap().pixmap().drawable() != 0) { | ||
144 | // not focused | ||
145 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
146 | stickUnfocusPixmap(). | ||
147 | pixmap().drawable()); | ||
148 | } else { // focused | ||
149 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
150 | stickPixmap(). | ||
151 | pixmap().drawable()); | ||
152 | } | ||
153 | |||
154 | } | ||
155 | } // end if stuck | ||
156 | |||
157 | FbTk::FbWindow::clear(); | ||
158 | |||
159 | } else { | ||
160 | if (m_listen_to.isStuck()) { | ||
161 | fillRectangle(gc(), | ||
162 | width()/2 - width()/4, height()/2 - height()/4, | ||
163 | width()/2, height()/2); | ||
164 | } else { | ||
165 | if (gc() == 0) // must have valid graphic context | ||
166 | return; | ||
167 | fillRectangle(gc(), | ||
168 | width()/2 - width()/10, height()/2 - height()/10, | ||
169 | width()/5, height()/5); | ||
170 | } | ||
171 | } | ||
172 | break; | ||
173 | case CLOSE: | ||
174 | |||
175 | if (m_theme.closePixmap().pixmap().drawable() != 0) { | ||
176 | if (pressed()) { | ||
177 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
178 | closePressedPixmap(). | ||
179 | pixmap().drawable()); | ||
180 | |||
181 | } else if (m_theme.closePixmap().pixmap().drawable()) { | ||
182 | // check focus | ||
183 | if (!m_listen_to.isFocused() && | ||
184 | m_theme.closeUnfocusPixmap().pixmap().drawable() != 0) { | ||
185 | // not focused | ||
186 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
187 | closeUnfocusPixmap(). | ||
188 | pixmap().drawable()); | ||
189 | } else { // focused | ||
190 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
191 | closePixmap(). | ||
192 | pixmap().drawable()); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | FbTk::FbWindow::clear(); | ||
197 | |||
198 | } else { | ||
199 | if (gc() == 0) // must have valid graphic context | ||
200 | return; | ||
201 | drawLine(gc(), | ||
202 | 2, 2, | ||
203 | width() - 3, height() - 3); | ||
204 | drawLine(gc(), | ||
205 | 2, width() - 3, | ||
206 | height() - 3, 2); | ||
207 | } | ||
208 | break; | ||
209 | case SHADE: | ||
210 | if (m_theme.shadePixmap().pixmap().drawable() != 0) { | ||
211 | if (pressed()) { | ||
212 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
213 | shadePressedPixmap(). | ||
214 | pixmap().drawable()); | ||
215 | } else if (m_theme.shadePixmap().pixmap().drawable()) { | ||
216 | // check focus | ||
217 | if (!m_listen_to.isFocused() && | ||
218 | m_theme.shadeUnfocusPixmap().pixmap().drawable() != 0) { | ||
219 | // not focused | ||
220 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
221 | shadeUnfocusPixmap(). | ||
222 | pixmap().drawable()); | ||
223 | } else { // focused | ||
224 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | ||
225 | shadePixmap(). | ||
226 | pixmap().drawable()); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | FbTk::FbWindow::clear(); | ||
231 | } | ||
232 | break; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | void WinButton::clear() { | ||
237 | FbTk::Button::clear(); | ||
238 | drawType(); | ||
239 | } | ||
240 | |||
241 | void WinButton::update(FbTk::Subject *subj) { | ||
242 | clear(); | ||
243 | drawType(); | ||
244 | } | ||