diff options
Diffstat (limited to 'src/IconBar.cc')
-rw-r--r-- | src/IconBar.cc | 202 |
1 files changed, 114 insertions, 88 deletions
diff --git a/src/IconBar.cc b/src/IconBar.cc index db3eabc..3ed4f54 100644 --- a/src/IconBar.cc +++ b/src/IconBar.cc | |||
@@ -1,5 +1,5 @@ | |||
1 | // IconBar.cc | 1 | // IconBar.cc for Fluxbox Window Manager |
2 | // Copyright (c) 2001 Henrik Kinnunen (fluxgen@linuxmail.org) | 2 | // Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org) |
3 | // | 3 | // |
4 | // Permission is hereby granted, free of charge, to any person obtaining a | 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
5 | // copy of this software and associated documentation files (the "Software"), | 5 | // copy of this software and associated documentation files (the "Software"), |
@@ -19,27 +19,52 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: IconBar.cc,v 1.15 2002/08/04 15:23:24 fluxgen Exp $ | ||
23 | |||
22 | #include "IconBar.hh" | 24 | #include "IconBar.hh" |
23 | #include "i18n.hh" | 25 | #include "i18n.hh" |
26 | #include "Screen.hh" | ||
27 | |||
28 | #include <algorithm> | ||
24 | 29 | ||
25 | IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) { | 30 | IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) |
31 | { | ||
32 | m_fluxboxwin = fluxboxwin; | ||
26 | m_iconwin = iconwin; | 33 | m_iconwin = iconwin; |
27 | m_fluxboxwin = fluxboxwin; | ||
28 | } | 34 | } |
29 | 35 | ||
30 | IconBarObj::~IconBarObj() { | 36 | IconBarObj::~IconBarObj() { |
31 | 37 | ||
32 | } | 38 | } |
33 | 39 | ||
34 | IconBar::IconBar(BScreen *scrn, Window parent) { | 40 | //---------- getIconWidth ------------ |
35 | m_parent = parent; | 41 | // will return the width of an icon |
36 | m_screen = scrn; | 42 | // window |
37 | m_iconlist = new IconList; | 43 | //------------------------------------ |
44 | unsigned int IconBarObj::width() const { | ||
45 | Window root; | ||
46 | |||
47 | unsigned int width, height; | ||
48 | unsigned int border_width, depth; //not used | ||
49 | int x, y; //not used | ||
50 | |||
51 | Display *m_display = Fluxbox::instance()->getXDisplay(); | ||
52 | |||
53 | XGetGeometry(m_display, m_iconwin, &root, &x, &y, | ||
54 | &width, &height, &border_width, &depth); | ||
55 | |||
56 | return width; | ||
57 | } | ||
58 | |||
59 | |||
60 | IconBar::IconBar(BScreen *scrn, Window parent): | ||
61 | m_screen(scrn), | ||
62 | m_parent(parent) | ||
63 | { | ||
38 | m_display = scrn->getBaseDisplay()->getXDisplay(); | 64 | m_display = scrn->getBaseDisplay()->getXDisplay(); |
39 | } | 65 | } |
40 | 66 | ||
41 | IconBar::~IconBar() { | 67 | IconBar::~IconBar() { |
42 | delete m_iconlist; | ||
43 | } | 68 | } |
44 | 69 | ||
45 | //------------ addIcon ----------------------- | 70 | //------------ addIcon ----------------------- |
@@ -52,7 +77,7 @@ Window IconBar::addIcon(FluxboxWindow *fluxboxwin) { | |||
52 | Window iconwin = createIconWindow(fluxboxwin, m_parent); | 77 | Window iconwin = createIconWindow(fluxboxwin, m_parent); |
53 | decorate(iconwin); | 78 | decorate(iconwin); |
54 | //add window object to list | 79 | //add window object to list |
55 | m_iconlist->insert(new IconBarObj(fluxboxwin, iconwin)); | 80 | m_iconlist.push_back(new IconBarObj(fluxboxwin, iconwin)); |
56 | //reposition all icons to fit windowbar | 81 | //reposition all icons to fit windowbar |
57 | repositionIcons(); | 82 | repositionIcons(); |
58 | 83 | ||
@@ -72,11 +97,15 @@ Window IconBar::delIcon(FluxboxWindow *fluxboxwin) { | |||
72 | Window retwin = None; | 97 | Window retwin = None; |
73 | IconBarObj *obj = findIcon(fluxboxwin); | 98 | IconBarObj *obj = findIcon(fluxboxwin); |
74 | if (obj) { | 99 | if (obj) { |
75 | m_iconlist->remove(obj); | 100 | IconList::iterator it = |
76 | retwin = obj->getIconWin(); | 101 | std::find(m_iconlist.begin(), m_iconlist.end(), obj); |
77 | delete obj; | 102 | if (it != m_iconlist.end()) { |
78 | XDestroyWindow(m_display, retwin); | 103 | m_iconlist.erase(it); |
79 | repositionIcons(); | 104 | retwin = obj->getIconWin(); |
105 | delete obj; | ||
106 | XDestroyWindow(m_display, retwin); | ||
107 | repositionIcons(); | ||
108 | } | ||
80 | } | 109 | } |
81 | return retwin; | 110 | return retwin; |
82 | } | 111 | } |
@@ -88,28 +117,23 @@ Window IconBar::delIcon(FluxboxWindow *fluxboxwin) { | |||
88 | void IconBar::loadTheme(unsigned int width, unsigned int height) { | 117 | void IconBar::loadTheme(unsigned int width, unsigned int height) { |
89 | BImageControl *image_ctrl = m_screen->getImageControl(); | 118 | BImageControl *image_ctrl = m_screen->getImageControl(); |
90 | Pixmap tmp = m_focus_pm; | 119 | Pixmap tmp = m_focus_pm; |
91 | BTexture *texture = &(m_screen->getWindowStyle()->tab.l_focus); | 120 | FbTk::Texture *texture = &(m_screen->getWindowStyle()->tab.l_focus); |
92 | 121 | ||
93 | if (texture->getTexture() & BImage_ParentRelative ) { | 122 | //If we are working on a PARENTRELATIVE, change to right focus value |
94 | 123 | if (texture->type() & FbTk::Texture::PARENTRELATIVE ) { | |
95 | BTexture *pt = &(m_screen->getWindowStyle()->tab.t_focus); | 124 | texture = &(m_screen->getWindowStyle()->tab.t_focus); |
96 | if (pt->getTexture() == (BImage_Flat | BImage_Solid)) { | 125 | } |
97 | m_focus_pm = None; | ||
98 | m_focus_pixel = pt->getColor()->getPixel(); | ||
99 | } else | ||
100 | m_focus_pm = | ||
101 | image_ctrl->renderImage(width, height, pt); | ||
102 | 126 | ||
127 | if (texture->type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { | ||
128 | m_focus_pm = None; | ||
129 | m_focus_pixel = texture->color().pixel(); | ||
103 | } else { | 130 | } else { |
104 | 131 | m_focus_pm = | |
105 | if (texture->getTexture() == (BImage_Flat | BImage_Solid)) { | 132 | image_ctrl->renderImage(width, height, texture); |
106 | m_focus_pm = None; | ||
107 | m_focus_pixel = texture->getColor()->getPixel(); | ||
108 | } else | ||
109 | m_focus_pm = | ||
110 | image_ctrl->renderImage(width, height, texture); | ||
111 | } | 133 | } |
112 | if (tmp) image_ctrl->removeImage(tmp); | 134 | |
135 | if (tmp) | ||
136 | image_ctrl->removeImage(tmp); | ||
113 | } | 137 | } |
114 | 138 | ||
115 | //------------ decorate ------------------ | 139 | //------------ decorate ------------------ |
@@ -119,7 +143,7 @@ void IconBar::loadTheme(unsigned int width, unsigned int height) { | |||
119 | void IconBar::decorate(Window win) { | 143 | void IconBar::decorate(Window win) { |
120 | 144 | ||
121 | XSetWindowBorderWidth(m_display, win, m_screen->getWindowStyle()->tab.border_width); | 145 | XSetWindowBorderWidth(m_display, win, m_screen->getWindowStyle()->tab.border_width); |
122 | XSetWindowBorder(m_display, win, m_screen->getWindowStyle()->tab.border_color.getPixel()); | 146 | XSetWindowBorder(m_display, win, m_screen->getWindowStyle()->tab.border_color.pixel()); |
123 | if (m_focus_pm) | 147 | if (m_focus_pm) |
124 | XSetWindowBackgroundPixmap(m_display, win, m_focus_pm); | 148 | XSetWindowBackgroundPixmap(m_display, win, m_focus_pm); |
125 | else | 149 | else |
@@ -141,25 +165,26 @@ void IconBar::reconfigure() { | |||
141 | //---------------------------------------- | 165 | //---------------------------------------- |
142 | void IconBar::exposeEvent(XExposeEvent *ee) { | 166 | void IconBar::exposeEvent(XExposeEvent *ee) { |
143 | IconBarObj *obj=0; | 167 | IconBarObj *obj=0; |
144 | IconListIterator it(m_iconlist); | 168 | IconList::iterator it = m_iconlist.begin(); |
145 | for (; it.current(); it++) { | 169 | IconList::iterator it_end = m_iconlist.end(); |
146 | if (it.current()->getIconWin() == ee->window) { | 170 | for (; it != it_end; ++it) { |
147 | obj = it.current(); | 171 | if ((*it)->getIconWin() == ee->window) { |
172 | obj = (*it); | ||
148 | break; | 173 | break; |
149 | } | 174 | } |
150 | } | 175 | } |
151 | 176 | ||
152 | if (obj) { | 177 | if (obj) { |
153 | 178 | ||
154 | Window root; | 179 | Window root; |
155 | unsigned int width, height; | 180 | unsigned int width, height; |
156 | unsigned int border_width, depth; //not used | 181 | unsigned int border_width, depth; //not used |
157 | int x, y; | 182 | int x, y; |
158 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, | 183 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, |
159 | &border_width, &depth); | 184 | &border_width, &depth); |
160 | 185 | ||
161 | //max width on every icon | 186 | //max width on every icon |
162 | unsigned int icon_width = width / m_iconlist->count(); | 187 | unsigned int icon_width = width / m_iconlist.size(); |
163 | 188 | ||
164 | //load right size of theme | 189 | //load right size of theme |
165 | loadTheme(icon_width, height); | 190 | loadTheme(icon_width, height); |
@@ -173,7 +198,7 @@ void IconBar::exposeEvent(XExposeEvent *ee) { | |||
173 | // Calculates and moves/resizes the icons | 198 | // Calculates and moves/resizes the icons |
174 | //----------------------------------------- | 199 | //----------------------------------------- |
175 | void IconBar::repositionIcons(void) { | 200 | void IconBar::repositionIcons(void) { |
176 | if (!m_iconlist->count()) | 201 | if (m_iconlist.size() == 0) |
177 | return; | 202 | return; |
178 | 203 | ||
179 | Window root; | 204 | Window root; |
@@ -181,22 +206,22 @@ void IconBar::repositionIcons(void) { | |||
181 | unsigned int border_width, depth; //not used | 206 | unsigned int border_width, depth; //not used |
182 | int x, y; | 207 | int x, y; |
183 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, | 208 | XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height, |
184 | &border_width, &depth); | 209 | &border_width, &depth); |
185 | 210 | ||
186 | //max width on every icon | 211 | //max width on every icon |
187 | unsigned int icon_width = width / m_iconlist->count(); | 212 | unsigned int icon_width = width / m_iconlist.size(); |
188 | 213 | ||
189 | //load right size of theme | 214 | //load right size of theme |
190 | loadTheme(icon_width, height); | 215 | loadTheme(icon_width, height); |
191 | |||
192 | IconListIterator it(m_iconlist); | ||
193 | 216 | ||
194 | for (x = 0; it.current(); it++, x+=icon_width) { | 217 | IconList::iterator it = m_iconlist.begin(); |
195 | Window iconwin = it.current()->getIconWin(); | 218 | IconList::iterator it_end = m_iconlist.end(); |
219 | for (x = 0; it != it_end; ++it, x += icon_width) { | ||
220 | Window iconwin = (*it)->getIconWin(); | ||
196 | XMoveResizeWindow(m_display, iconwin, | 221 | XMoveResizeWindow(m_display, iconwin, |
197 | x, 0, | 222 | x, 0, |
198 | icon_width, height); | 223 | icon_width, height); |
199 | draw(it.current(), icon_width); | 224 | draw((*it), icon_width); |
200 | decorate(iconwin); | 225 | decorate(iconwin); |
201 | } | 226 | } |
202 | 227 | ||
@@ -208,20 +233,20 @@ void IconBar::repositionIcons(void) { | |||
208 | //---------------------------------------------- | 233 | //---------------------------------------------- |
209 | Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) { | 234 | Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) { |
210 | unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | | 235 | unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | |
211 | CWColormap | CWOverrideRedirect | CWEventMask; | 236 | CWColormap | CWOverrideRedirect | CWEventMask; |
212 | XSetWindowAttributes attrib; | 237 | XSetWindowAttributes attrib; |
213 | attrib.background_pixmap = None; | 238 | attrib.background_pixmap = None; |
214 | attrib.background_pixel = attrib.border_pixel = | 239 | attrib.background_pixel = attrib.border_pixel = |
215 | fluxboxwin->getScreen()->getWindowStyle()->tab.border_color.getPixel(); | 240 | fluxboxwin->getScreen()->getWindowStyle()->tab.border_color.pixel(); |
216 | attrib.colormap = fluxboxwin->getScreen()->getColormap(); | 241 | attrib.colormap = fluxboxwin->getScreen()->colormap(); |
217 | attrib.override_redirect = True; | 242 | attrib.override_redirect = True; |
218 | attrib.event_mask = ButtonPressMask | ButtonReleaseMask | | 243 | attrib.event_mask = ButtonPressMask | ButtonReleaseMask | |
219 | ButtonMotionMask | ExposureMask | EnterWindowMask; | 244 | ButtonMotionMask | ExposureMask | EnterWindowMask; |
220 | 245 | ||
221 | //create iconwindow | 246 | //create iconwindow |
222 | Window iconwin = XCreateWindow(m_display, parent, 0, 0, 1, 1, 0, | 247 | Window iconwin = XCreateWindow(m_display, parent, 0, 0, 1, 1, 0, |
223 | fluxboxwin->getScreen()->getDepth(), InputOutput, fluxboxwin->getScreen()->getVisual(), | 248 | fluxboxwin->getScreen()->getDepth(), InputOutput, fluxboxwin->getScreen()->getVisual(), |
224 | attrib_mask, &attrib); | 249 | attrib_mask, &attrib); |
225 | 250 | ||
226 | return iconwin; | 251 | return iconwin; |
227 | } | 252 | } |
@@ -235,68 +260,67 @@ void IconBar::draw(IconBarObj *obj, int width) { | |||
235 | 260 | ||
236 | FluxboxWindow *fluxboxwin = obj->getFluxboxWin(); | 261 | FluxboxWindow *fluxboxwin = obj->getFluxboxWin(); |
237 | Window iconwin = obj->getIconWin(); | 262 | Window iconwin = obj->getIconWin(); |
238 | char *title = *fluxboxwin->getIconTitle(); | ||
239 | unsigned int title_len = strlen(title); | ||
240 | unsigned int title_text_w; | 263 | unsigned int title_text_w; |
241 | 264 | ||
242 | if (I18n::instance()->multibyte()) { | 265 | const int multibyte = I18n::instance()->multibyte(); |
266 | |||
267 | if (multibyte) { | ||
243 | XRectangle ink, logical; | 268 | XRectangle ink, logical; |
244 | XmbTextExtents(m_screen->getWindowStyle()->font.set, | 269 | XmbTextExtents(m_screen->getWindowStyle()->font.set, |
245 | title, title_len, &ink, &logical); | 270 | fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size(), &ink, &logical); |
246 | title_text_w = logical.width; | 271 | title_text_w = logical.width; |
247 | } else { | 272 | } else { |
248 | title_text_w = XTextWidth(m_screen->getWindowStyle()->font.fontstruct, | 273 | title_text_w = XTextWidth(m_screen->getWindowStyle()->font.fontstruct, |
249 | title, title_len); | 274 | fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size()); |
250 | } | 275 | } |
251 | 276 | ||
252 | int l = title_text_w; | 277 | int l = title_text_w; |
253 | int dlen=title_len; | 278 | unsigned int dlen=fluxboxwin->getIconTitle().size(); |
254 | unsigned int bevel_w = m_screen->getBevelWidth(); | 279 | unsigned int bevel_w = m_screen->getBevelWidth(); |
255 | int dx=bevel_w*2; | 280 | int dx=bevel_w*2; |
256 | 281 | ||
257 | for (; dlen >= 0; dlen--) { | 282 | for (; dlen >= 0; dlen--) { |
258 | if (I18n::instance()->multibyte()) { | 283 | if (multibyte) { |
259 | XRectangle ink, logical; | 284 | XRectangle ink, logical; |
260 | XmbTextExtents(m_screen->getWindowStyle()->tab.font.set, | 285 | XmbTextExtents(m_screen->getWindowStyle()->tab.font.set, |
261 | title, dlen, | 286 | fluxboxwin->getIconTitle().c_str(), dlen, |
262 | &ink, &logical); | 287 | &ink, &logical); |
263 | l = logical.width; | 288 | l = logical.width; |
264 | } else | 289 | } else |
265 | l = XTextWidth(m_screen->getWindowStyle()->tab.font.fontstruct, | 290 | l = XTextWidth(m_screen->getWindowStyle()->tab.font.fontstruct, |
266 | title, dlen); | 291 | fluxboxwin->getIconTitle().c_str(), dlen); |
267 | l += (bevel_w * 4); | 292 | l += (bevel_w * 4); |
268 | 293 | ||
269 | if (l < width) | 294 | if (l < width) |
270 | break; | 295 | break; |
271 | } | 296 | } |
272 | 297 | ||
273 | |||
274 | switch (m_screen->getWindowStyle()->tab.font.justify) { | 298 | switch (m_screen->getWindowStyle()->tab.font.justify) { |
275 | case FFont::Right: | 299 | case DrawUtil::Font::RIGHT: |
276 | dx += width - l; | 300 | dx += width - l; |
277 | break; | 301 | break; |
278 | case FFont::Center: | 302 | case DrawUtil::Font::CENTER: |
279 | dx += (width - l) / 2; | 303 | dx += (width - l) / 2; |
280 | break; | 304 | break; |
281 | default: | 305 | default: |
282 | break; | 306 | break; |
283 | } | 307 | } |
284 | 308 | ||
285 | //Draw title to m_tabwin | 309 | //Draw title to m_iconwin |
286 | 310 | ||
287 | XClearWindow(m_display, iconwin); | 311 | XClearWindow(m_display, iconwin); |
288 | 312 | ||
289 | if (I18n::instance()->multibyte()) { | 313 | if (multibyte) { |
290 | XmbDrawString(m_display, iconwin, | 314 | XmbDrawString(m_display, iconwin, |
291 | m_screen->getWindowStyle()->tab.font.set, | 315 | m_screen->getWindowStyle()->tab.font.set, |
292 | m_screen->getWindowStyle()->tab.l_text_focus_gc, dx, | 316 | m_screen->getWindowStyle()->tab.l_text_focus_gc, dx, |
293 | 1 - m_screen->getWindowStyle()->tab.font.set_extents->max_ink_extent.y, | 317 | 1 - m_screen->getWindowStyle()->tab.font.set_extents->max_ink_extent.y, |
294 | title, dlen); | 318 | fluxboxwin->getIconTitle().c_str(), dlen); |
295 | } else { | 319 | } else { |
296 | XDrawString(m_display, iconwin, | 320 | XDrawString(m_display, iconwin, |
297 | m_screen->getWindowStyle()->tab.l_text_focus_gc, dx, | 321 | m_screen->getWindowStyle()->tab.l_text_focus_gc, dx, |
298 | m_screen->getWindowStyle()->tab.font.fontstruct->ascent + 1, | 322 | m_screen->getWindowStyle()->tab.font.fontstruct->ascent + 1, |
299 | title, dlen); | 323 | fluxboxwin->getIconTitle().c_str(), dlen); |
300 | } | 324 | } |
301 | 325 | ||
302 | } | 326 | } |
@@ -309,10 +333,10 @@ void IconBar::draw(IconBarObj *obj, int width) { | |||
309 | //---------------------------------- | 333 | //---------------------------------- |
310 | FluxboxWindow *IconBar::findWindow(Window w) { | 334 | FluxboxWindow *IconBar::findWindow(Window w) { |
311 | 335 | ||
312 | IconListIterator it(m_iconlist); | 336 | IconList::iterator it = m_iconlist.begin(); |
313 | 337 | IconList::iterator it_end = m_iconlist.end(); | |
314 | for (; it.current(); it++) { | 338 | for (; it != it_end; ++it) { |
315 | IconBarObj *tmp = it.current(); | 339 | IconBarObj *tmp = (*it); |
316 | if (tmp) | 340 | if (tmp) |
317 | if (tmp->getIconWin() == w) | 341 | if (tmp->getIconWin() == w) |
318 | return tmp->getFluxboxWin(); | 342 | return tmp->getFluxboxWin(); |
@@ -326,12 +350,13 @@ FluxboxWindow *IconBar::findWindow(Window w) { | |||
326 | // returns pointer to IconBarObj on success else | 350 | // returns pointer to IconBarObj on success else |
327 | // 0 on failure | 351 | // 0 on failure |
328 | //------------------------------------ | 352 | //------------------------------------ |
353 | |||
329 | IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { | 354 | IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { |
330 | 355 | ||
331 | IconListIterator it(m_iconlist); | 356 | IconList::iterator it = m_iconlist.begin(); |
332 | 357 | IconList::iterator it_end = m_iconlist.end(); | |
333 | for (; it.current(); it++) { | 358 | for (; it != it_end; ++it) { |
334 | IconBarObj *tmp = it.current(); | 359 | IconBarObj *tmp = (*it); |
335 | if (tmp) | 360 | if (tmp) |
336 | if (tmp->getFluxboxWin() == fluxboxwin) | 361 | if (tmp->getFluxboxWin() == fluxboxwin) |
337 | return tmp; | 362 | return tmp; |
@@ -339,3 +364,4 @@ IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { | |||
339 | 364 | ||
340 | return 0; | 365 | return 0; |
341 | } | 366 | } |
367 | |||