diff options
author | fluxgen <fluxgen> | 2003-08-13 10:04:29 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-08-13 10:04:29 (GMT) |
commit | 07190d2133f22b89de3693867213c22e28d41d2e (patch) | |
tree | 1a6aba79c92e1e5a3c9eca93c5977d5c7c6b1feb /src/IconBar.cc | |
parent | 447486fd8be3900ceb6ee28bf9c8faf1a7b57a47 (diff) | |
download | fluxbox-07190d2133f22b89de3693867213c22e28d41d2e.zip fluxbox-07190d2133f22b89de3693867213c22e28d41d2e.tar.bz2 |
obsolete
Diffstat (limited to 'src/IconBar.cc')
-rw-r--r-- | src/IconBar.cc | 447 |
1 files changed, 0 insertions, 447 deletions
diff --git a/src/IconBar.cc b/src/IconBar.cc deleted file mode 100644 index 898c77e..0000000 --- a/src/IconBar.cc +++ /dev/null | |||
@@ -1,447 +0,0 @@ | |||
1 | // IconBar.cc for Fluxbox Window Manager | ||
2 | // Copyright (c) 2001 - 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: IconBar.cc,v 1.41 2003/08/04 12:57:23 fluxgen Exp $ | ||
23 | |||
24 | #include "IconBar.hh" | ||
25 | |||
26 | #include "I18n.hh" | ||
27 | #include "Screen.hh" | ||
28 | #include "Window.hh" | ||
29 | #include "ImageControl.hh" | ||
30 | #include "Text.hh" | ||
31 | #include "RootTheme.hh" | ||
32 | #include "FbWinFrameTheme.hh" | ||
33 | |||
34 | #include <algorithm> | ||
35 | |||
36 | //!! TODO THIS FILE NEEDS CLEANING | ||
37 | |||
38 | IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) | ||
39 | { | ||
40 | m_fluxboxwin = fluxboxwin; | ||
41 | m_iconwin = iconwin; | ||
42 | } | ||
43 | |||
44 | IconBarObj::~IconBarObj() { | ||
45 | |||
46 | } | ||
47 | |||
48 | /// @return the width of specified icon window | ||
49 | unsigned int IconBarObj::width() const { | ||
50 | Window root; | ||
51 | |||
52 | unsigned int width, height; | ||
53 | unsigned int border_width, depth; //not used | ||
54 | int x, y; //not used | ||
55 | |||
56 | Display *disp = FbTk::App::instance()->display(); | ||
57 | |||
58 | XGetGeometry(disp, m_iconwin, &root, &x, &y, | ||
59 | &width, &height, &border_width, &depth); | ||
60 | |||
61 | return width; | ||
62 | } | ||
63 | |||
64 | /// @return the width of specified icon window | ||
65 | unsigned int IconBarObj::height() const { | ||
66 | Window root; | ||
67 | |||
68 | unsigned int width, height; | ||
69 | unsigned int border_width, depth; //not used | ||
70 | int x, y; //not used | ||
71 | |||
72 | Display *disp = FbTk::App::instance()->display(); | ||
73 | |||
74 | XGetGeometry(disp, m_iconwin, &root, &x, &y, | ||
75 | &width, &height, &border_width, &depth); | ||
76 | |||
77 | return height; | ||
78 | } | ||
79 | |||
80 | |||
81 | IconBar::IconBar(BScreen &scrn, Window parent, FbTk::Font &font): | ||
82 | m_screen(scrn), | ||
83 | m_display(FbTk::App::instance()->display()), | ||
84 | m_parent(parent), | ||
85 | m_focus_pm(None), | ||
86 | m_vertical(false), | ||
87 | m_font(font), | ||
88 | allow_updates(0) | ||
89 | { | ||
90 | |||
91 | } | ||
92 | |||
93 | IconBar::~IconBar() { | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | Adds icon to iconbar and repostions the | ||
98 | icons. | ||
99 | returns window to iconobj | ||
100 | */ | ||
101 | Window IconBar::addIcon(FluxboxWindow *fluxboxwin) { | ||
102 | if (fluxboxwin == 0) | ||
103 | return 0; | ||
104 | |||
105 | // we don't want dublicate instances | ||
106 | IconList::iterator it = m_iconlist.begin(); | ||
107 | IconList::iterator it_end = m_iconlist.end(); | ||
108 | for (; it != it_end; ++it) { | ||
109 | if ((*it)->getFluxboxWin() == fluxboxwin) | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | Window iconwin = createIconWindow(fluxboxwin, m_parent); | ||
114 | decorate(iconwin); | ||
115 | //add window object to list | ||
116 | m_iconlist.push_back(new IconBarObj(fluxboxwin, iconwin)); | ||
117 | |||
118 | //reposition all icons to fit windowbar | ||
119 | repositionIcons(); | ||
120 | |||
121 | XMapSubwindows(m_display, iconwin); | ||
122 | XMapWindow(m_display, iconwin); | ||
123 | |||
124 | return iconwin; | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | Removes icon from list and | ||
129 | repositions the rest of the icons | ||
130 | Return X Window of the removed iconobj | ||
131 | returns None if no window was found | ||
132 | */ | ||
133 | Window IconBar::delIcon(FluxboxWindow *fluxboxwin) { | ||
134 | if (fluxboxwin == 0) | ||
135 | return 0; | ||
136 | |||
137 | Window retwin = None; | ||
138 | IconBarObj *obj = findIcon(fluxboxwin); | ||
139 | if (obj) { | ||
140 | IconList::iterator it = | ||
141 | std::find(m_iconlist.begin(), m_iconlist.end(), obj); | ||
142 | if (it != m_iconlist.end()) { | ||
143 | m_iconlist.erase(it); | ||
144 | retwin = obj->getIconWin(); | ||
145 | delete obj; | ||
146 | XDestroyWindow(m_display, retwin); | ||
147 | repositionIcons(); | ||
148 | } | ||
149 | } | ||
150 | return retwin; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * Removes all icons from list | ||
155 | * Return X Windows of the removed iconobjs | ||
156 | */ | ||
157 | IconBar::WindowList *IconBar::delAllIcons(bool ignore_stuck) { | ||
158 | Window retwin = None; | ||
159 | WindowList *ret = new WindowList(); | ||
160 | IconList::iterator it = m_iconlist.begin(); | ||
161 | IconList::iterator tmp = m_iconlist.end(); | ||
162 | IconList::iterator it_end = m_iconlist.end(); | ||
163 | while (it != it_end) { | ||
164 | IconBarObj *obj = *it; | ||
165 | if (!ignore_stuck || !obj->getFluxboxWin()->isStuck()) { | ||
166 | retwin = obj->getIconWin(); | ||
167 | ret->push_back(retwin); | ||
168 | tmp = it; | ||
169 | ++it; | ||
170 | m_iconlist.erase(tmp); | ||
171 | delete obj; | ||
172 | XDestroyWindow(m_display, retwin); | ||
173 | } else { | ||
174 | ++it; | ||
175 | } | ||
176 | } | ||
177 | repositionIcons(); | ||
178 | return ret; | ||
179 | } | ||
180 | |||
181 | /** | ||
182 | renders theme to m_focus_pm | ||
183 | with the size width * height | ||
184 | |||
185 | */ | ||
186 | void IconBar::loadTheme(unsigned int width, unsigned int height) { | ||
187 | //!! TODO: iconbar style theme | ||
188 | |||
189 | FbTk::ImageControl &image_ctrl = screen().imageControl(); | ||
190 | Pixmap tmp = m_focus_pm; | ||
191 | const FbTk::Texture *texture = &(screen().winFrameTheme().labelFocusTexture()); | ||
192 | |||
193 | //If we are working on a PARENTRELATIVE, change to right focus value | ||
194 | if (texture->type() & FbTk::Texture::PARENTRELATIVE ) { | ||
195 | texture = &(screen().winFrameTheme().titleFocusTexture()); | ||
196 | } | ||
197 | |||
198 | if (texture->type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { | ||
199 | m_focus_pm = None; | ||
200 | m_focus_pixel = texture->color().pixel(); | ||
201 | } else { | ||
202 | m_focus_pm = | ||
203 | image_ctrl.renderImage(width, height, *texture); | ||
204 | } | ||
205 | |||
206 | if (tmp) | ||
207 | image_ctrl.removeImage(tmp); | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | sets the background pixmap/color, | ||
212 | border, border width of the window | ||
213 | */ | ||
214 | void IconBar::decorate(Window win) { | ||
215 | //!! TODO iconbar border width style | ||
216 | XSetWindowBorderWidth(m_display, win, 1); | ||
217 | XSetWindowBorder(m_display, win, BlackPixel(FbTk::App::instance()->display(), | ||
218 | screen().screenNumber())); | ||
219 | if (m_focus_pm) | ||
220 | XSetWindowBackgroundPixmap(m_display, win, m_focus_pm); | ||
221 | else | ||
222 | XSetWindowBackground(m_display, win, m_focus_pixel); | ||
223 | } | ||
224 | |||
225 | |||
226 | /** | ||
227 | Reconfigures the icons | ||
228 | theme, pos and width | ||
229 | */ | ||
230 | void IconBar::reconfigure() { | ||
231 | repositionIcons(); | ||
232 | |||
233 | } | ||
234 | |||
235 | /** | ||
236 | Handles the expose event | ||
237 | just redraws all the icons | ||
238 | */ | ||
239 | void IconBar::exposeEvent(XExposeEvent *ee) { | ||
240 | IconBarObj *obj = 0; | ||
241 | IconList::iterator it = m_iconlist.begin(); | ||
242 | IconList::iterator it_end = m_iconlist.end(); | ||
243 | for (; it != it_end; ++it) { | ||
244 | if ((*it)->getIconWin() == ee->window) { | ||
245 | obj = (*it); | ||
246 | break; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | if (obj) { | ||
251 | |||
252 | Window root; | ||
253 | unsigned int width, height; | ||
254 | unsigned int border_width, depth; //not used | ||
255 | int x, y; | ||
256 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, | ||
257 | &border_width, &depth); | ||
258 | |||
259 | //max width on every icon | ||
260 | unsigned int icon_width = width / m_iconlist.size(); | ||
261 | |||
262 | //load right size of theme | ||
263 | loadTheme(icon_width, height); | ||
264 | |||
265 | draw(obj, icon_width); | ||
266 | |||
267 | } | ||
268 | } | ||
269 | |||
270 | void IconBar::enableUpdates() { | ||
271 | --allow_updates; | ||
272 | if (allow_updates <= 0) | ||
273 | repositionIcons(); | ||
274 | |||
275 | } | ||
276 | |||
277 | void IconBar::disableUpdates() { | ||
278 | ++allow_updates; | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | Calculates and moves/resizes the icons | ||
283 | */ | ||
284 | void IconBar::repositionIcons() { | ||
285 | if (m_iconlist.size() == 0 || allow_updates > 0) | ||
286 | return; | ||
287 | |||
288 | Window root; | ||
289 | unsigned int width, height; | ||
290 | unsigned int border_width, depth; //not used | ||
291 | int x, y; | ||
292 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, | ||
293 | &border_width, &depth); | ||
294 | |||
295 | //max width on every icon | ||
296 | unsigned int icon_width = width / m_iconlist.size(); | ||
297 | if (m_vertical) | ||
298 | icon_width = height / m_iconlist.size(); | ||
299 | //load right size of theme | ||
300 | loadTheme(icon_width, height); | ||
301 | |||
302 | IconList::iterator it = m_iconlist.begin(); | ||
303 | IconList::iterator it_end = m_iconlist.end(); | ||
304 | for (x = 0; it != it_end; ++it, x += icon_width) { | ||
305 | Window iconwin = (*it)->getIconWin(); | ||
306 | if (!m_vertical) { | ||
307 | XMoveResizeWindow(m_display, iconwin, | ||
308 | x, 0, | ||
309 | icon_width, height); | ||
310 | } else { | ||
311 | XMoveResizeWindow(m_display, iconwin, | ||
312 | 0, x, | ||
313 | height, icon_width); | ||
314 | } | ||
315 | draw((*it), icon_width); | ||
316 | decorate(iconwin); | ||
317 | } | ||
318 | |||
319 | } | ||
320 | |||
321 | /** | ||
322 | creates the X Window of icon | ||
323 | @return the created X Window | ||
324 | */ | ||
325 | Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) { | ||
326 | unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | | ||
327 | CWColormap | CWOverrideRedirect | CWEventMask; | ||
328 | XSetWindowAttributes attrib; | ||
329 | attrib.background_pixmap = None; | ||
330 | attrib.background_pixel = attrib.border_pixel = | ||
331 | BlackPixel(m_display, | ||
332 | screen().screenNumber()); | ||
333 | // fluxboxwin->screen().getWindowStyle()->tab.border_color.pixel(); | ||
334 | attrib.colormap = fluxboxwin->screen().rootWindow().colormap(); | ||
335 | attrib.override_redirect = True; | ||
336 | attrib.event_mask = ButtonPressMask | ButtonReleaseMask | | ||
337 | ButtonMotionMask | ExposureMask | EnterWindowMask; | ||
338 | |||
339 | //create iconwindow | ||
340 | Window iconwin = XCreateWindow(m_display, parent, 0, 0, 1, 1, 0, | ||
341 | fluxboxwin->screen().rootWindow().depth(), | ||
342 | InputOutput, fluxboxwin->screen().rootWindow().visual(), | ||
343 | attrib_mask, &attrib); | ||
344 | |||
345 | return iconwin; | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | Draws theme and string to Window w | ||
350 | */ | ||
351 | void IconBar::draw(const IconBarObj * const obj, int width) const { | ||
352 | if (!obj) | ||
353 | return; | ||
354 | |||
355 | const FluxboxWindow * const fluxboxwin = obj->getFluxboxWin(); | ||
356 | if (fluxboxwin == 0) | ||
357 | return; | ||
358 | |||
359 | Window iconwin = obj->getIconWin(); | ||
360 | unsigned int title_text_w; | ||
361 | |||
362 | title_text_w = m_font.textWidth(fluxboxwin->iconTitle().c_str(), | ||
363 | fluxboxwin->iconTitle().size()); | ||
364 | |||
365 | unsigned int bevel_w = screen().rootTheme().bevelWidth(); | ||
366 | int dx = bevel_w * 2; | ||
367 | |||
368 | // center by default | ||
369 | unsigned int newlen = 0; | ||
370 | dx = FbTk::doAlignment(m_vertical ? obj->height() : obj->width(), | ||
371 | bevel_w*2, FbTk::CENTER, m_font, | ||
372 | fluxboxwin->iconTitle().c_str(), | ||
373 | fluxboxwin->iconTitle().size(), | ||
374 | newlen); | ||
375 | // Draw title to m_iconwin | ||
376 | |||
377 | XClearWindow(m_display, iconwin); | ||
378 | int dy = 1 + m_font.ascent(); | ||
379 | if (m_vertical) { | ||
380 | int tmp = dy; | ||
381 | dy = obj->height() - dx; | ||
382 | dx = tmp + bevel_w; | ||
383 | } else | ||
384 | dy += bevel_w; | ||
385 | |||
386 | m_font.drawText(iconwin, | ||
387 | screen().screenNumber(), | ||
388 | screen().winFrameTheme().labelTextFocusGC(), | ||
389 | fluxboxwin->iconTitle().c_str(), newlen, | ||
390 | dx, dy, | ||
391 | m_vertical); | ||
392 | |||
393 | } | ||
394 | |||
395 | /** | ||
396 | Tries to find the FluxboxWindow of the X Window | ||
397 | in iconbar | ||
398 | @return the fluxboxwindow on success else 0 on failure | ||
399 | */ | ||
400 | FluxboxWindow *IconBar::findWindow(Window w) { | ||
401 | |||
402 | IconList::iterator it = m_iconlist.begin(); | ||
403 | IconList::iterator it_end = m_iconlist.end(); | ||
404 | for (; it != it_end; ++it) { | ||
405 | IconBarObj *tmp = (*it); | ||
406 | if (tmp) { | ||
407 | if (tmp->getIconWin() == w) | ||
408 | return tmp->getFluxboxWin(); | ||
409 | } | ||
410 | } | ||
411 | |||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | Tries to find a fluxboxwin icon in the iconlist | ||
417 | @return pointer to IconBarObj on success else 0 on failure | ||
418 | */ | ||
419 | IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { | ||
420 | |||
421 | IconList::iterator it = m_iconlist.begin(); | ||
422 | IconList::iterator it_end = m_iconlist.end(); | ||
423 | for (; it != it_end; ++it) { | ||
424 | IconBarObj *tmp = (*it); | ||
425 | if (tmp) { | ||
426 | if (tmp->getFluxboxWin() == fluxboxwin) | ||
427 | return tmp; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | const IconBarObj *IconBar::findIcon(const FluxboxWindow * const fluxboxwin) const { | ||
435 | |||
436 | IconList::const_iterator it = m_iconlist.begin(); | ||
437 | IconList::const_iterator it_end = m_iconlist.end(); | ||
438 | for (; it != it_end; ++it) { | ||
439 | IconBarObj *tmp = (*it); | ||
440 | if (tmp) { | ||
441 | if (tmp->getFluxboxWin() == fluxboxwin) | ||
442 | return tmp; | ||
443 | } | ||
444 | } | ||
445 | |||
446 | return 0; | ||
447 | } | ||