summaryrefslogtreecommitdiff
path: root/src/IconBar.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/IconBar.cc')
-rw-r--r--src/IconBar.cc166
1 files changed, 96 insertions, 70 deletions
diff --git a/src/IconBar.cc b/src/IconBar.cc
index dd80cec..60449e0 100644
--- a/src/IconBar.cc
+++ b/src/IconBar.cc
@@ -1,5 +1,5 @@
1// IconBar.cc for Fluxbox Window Manager 1// IconBar.cc for Fluxbox Window Manager
2// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org) 2// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
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,16 +19,19 @@
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.23 2003/01/09 22:03:06 fluxgen Exp $ 22// $Id: IconBar.cc,v 1.24 2003/02/23 00:51:40 fluxgen Exp $
23 23
24#include "IconBar.hh" 24#include "IconBar.hh"
25#include "i18n.hh" 25#include "i18n.hh"
26#include "Screen.hh" 26#include "Screen.hh"
27#include "fluxbox.hh" 27#include "fluxbox.hh"
28#include "ImageControl.hh" 28#include "ImageControl.hh"
29#include "Text.hh"
29 30
30#include <algorithm> 31#include <algorithm>
31 32
33//!! TODO THIS FILE NEEDS CLEANING
34
32IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) 35IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin)
33{ 36{
34 m_fluxboxwin = fluxboxwin; 37 m_fluxboxwin = fluxboxwin;
@@ -39,10 +42,7 @@ IconBarObj::~IconBarObj() {
39 42
40} 43}
41 44
42//---------- getIconWidth ------------ 45/// @return the width of specified icon window
43// will return the width of an icon
44// window
45//------------------------------------
46unsigned int IconBarObj::width() const { 46unsigned int IconBarObj::width() const {
47 Window root; 47 Window root;
48 48
@@ -58,10 +58,28 @@ unsigned int IconBarObj::width() const {
58 return width; 58 return width;
59} 59}
60 60
61/// @return the width of specified icon window
62unsigned int IconBarObj::height() const {
63 Window root;
64
65 unsigned int width, height;
66 unsigned int border_width, depth; //not used
67 int x, y; //not used
68
69 Display *m_display = Fluxbox::instance()->getXDisplay();
70
71 XGetGeometry(m_display, m_iconwin, &root, &x, &y,
72 &width, &height, &border_width, &depth);
73
74 return height;
75}
76
61 77
62IconBar::IconBar(BScreen *scrn, Window parent): 78IconBar::IconBar(BScreen *scrn, Window parent, FbTk::Font &font):
63 m_screen(scrn), 79 m_screen(scrn),
64 m_parent(parent) 80 m_parent(parent),
81 m_vertical(false),
82 m_font(font)
65{ 83{
66 m_display = scrn->getBaseDisplay()->getXDisplay(); 84 m_display = scrn->getBaseDisplay()->getXDisplay();
67} 85}
@@ -69,11 +87,11 @@ IconBar::IconBar(BScreen *scrn, Window parent):
69IconBar::~IconBar() { 87IconBar::~IconBar() {
70} 88}
71 89
72//------------ addIcon ----------------------- 90/**
73// Adds icon to iconbar and repostions the 91 Adds icon to iconbar and repostions the
74// icons. 92 icons.
75// returns window to iconobj 93 returns window to iconobj
76//-------------------------------------------- 94*/
77Window IconBar::addIcon(FluxboxWindow *fluxboxwin) { 95Window IconBar::addIcon(FluxboxWindow *fluxboxwin) {
78 96
79 Window iconwin = createIconWindow(fluxboxwin, m_parent); 97 Window iconwin = createIconWindow(fluxboxwin, m_parent);
@@ -89,12 +107,12 @@ Window IconBar::addIcon(FluxboxWindow *fluxboxwin) {
89 return iconwin; 107 return iconwin;
90} 108}
91 109
92//----------- delIcon ------------------- 110/**
93// Removes icon from list and 111 Removes icon from list and
94// repositions the rest of the icons 112 repositions the rest of the icons
95// Return X Window of the removed iconobj 113 Return X Window of the removed iconobj
96// returns None if no window was found 114 returns None if no window was found
97//--------------------------------------- 115*/
98Window IconBar::delIcon(FluxboxWindow *fluxboxwin) { 116Window IconBar::delIcon(FluxboxWindow *fluxboxwin) {
99 Window retwin = None; 117 Window retwin = None;
100 IconBarObj *obj = findIcon(fluxboxwin); 118 IconBarObj *obj = findIcon(fluxboxwin);
@@ -112,10 +130,10 @@ Window IconBar::delIcon(FluxboxWindow *fluxboxwin) {
112 return retwin; 130 return retwin;
113} 131}
114 132
115//------------ loadTheme --------------- 133/**
116// renders theme to m_focus_pm 134 renders theme to m_focus_pm
117// with the size width * height 135 with the size width * height
118//-------------------------------------- 136*/
119void IconBar::loadTheme(unsigned int width, unsigned int height) { 137void IconBar::loadTheme(unsigned int width, unsigned int height) {
120 FbTk::ImageControl *image_ctrl = m_screen->getImageControl(); 138 FbTk::ImageControl *image_ctrl = m_screen->getImageControl();
121 Pixmap tmp = m_focus_pm; 139 Pixmap tmp = m_focus_pm;
@@ -138,10 +156,10 @@ void IconBar::loadTheme(unsigned int width, unsigned int height) {
138 image_ctrl->removeImage(tmp); 156 image_ctrl->removeImage(tmp);
139} 157}
140 158
141//------------ decorate ------------------ 159/**
142// sets the background pixmap/color, 160 sets the background pixmap/color,
143// border, border width of the window 161 border, border width of the window
144//---------------------------------------- 162*/
145void IconBar::decorate(Window win) { 163void IconBar::decorate(Window win) {
146 164
147 XSetWindowBorderWidth(m_display, win, m_screen->getWindowStyle()->tab.border_width); 165 XSetWindowBorderWidth(m_display, win, m_screen->getWindowStyle()->tab.border_width);
@@ -153,18 +171,19 @@ void IconBar::decorate(Window win) {
153} 171}
154 172
155 173
156//------------ reconfigure --------------- 174/**
157// Reconfigures the icons 175 Reconfigures the icons
158// theme, pos and width 176 theme, pos and width
159//---------------------------------------- 177*/
160void IconBar::reconfigure() { 178void IconBar::reconfigure() {
161 repositionIcons(); 179 repositionIcons();
162 180
163} 181}
164//---------- exposeEvent ----------------- 182
165// Handles the expose event 183/**
166// just redraws all the icons 184 Handles the expose event
167//---------------------------------------- 185 just redraws all the icons
186*/
168void IconBar::exposeEvent(XExposeEvent *ee) { 187void IconBar::exposeEvent(XExposeEvent *ee) {
169 IconBarObj *obj=0; 188 IconBarObj *obj=0;
170 IconList::iterator it = m_iconlist.begin(); 189 IconList::iterator it = m_iconlist.begin();
@@ -196,9 +215,9 @@ void IconBar::exposeEvent(XExposeEvent *ee) {
196 } 215 }
197} 216}
198 217
199//------------ repositionIcons ------------ 218/**
200// Calculates and moves/resizes the icons 219 Calculates and moves/resizes the icons
201//----------------------------------------- 220*/
202void IconBar::repositionIcons() { 221void IconBar::repositionIcons() {
203 if (m_iconlist.size() == 0) 222 if (m_iconlist.size() == 0)
204 return; 223 return;
@@ -229,10 +248,10 @@ void IconBar::repositionIcons() {
229 248
230} 249}
231 250
232//------------ createIconWindow ---------------- 251/**
233// creates the X Window of icon 252 creates the X Window of icon
234// returns the created X Window 253 @return the created X Window
235//---------------------------------------------- 254*/
236Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) { 255Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) {
237 unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | 256 unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
238 CWColormap | CWOverrideRedirect | CWEventMask; 257 CWColormap | CWOverrideRedirect | CWEventMask;
@@ -253,9 +272,9 @@ Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) {
253 return iconwin; 272 return iconwin;
254} 273}
255 274
256//------------ draw ------------------ 275/**
257// Draws theme and string to Window w 276 Draws theme and string to Window w
258//------------------------------------ 277*/
259void IconBar::draw(const IconBarObj * const obj, int width) const { 278void IconBar::draw(const IconBarObj * const obj, int width) const {
260 if (!obj) 279 if (!obj)
261 return; 280 return;
@@ -264,15 +283,15 @@ void IconBar::draw(const IconBarObj * const obj, int width) const {
264 Window iconwin = obj->getIconWin(); 283 Window iconwin = obj->getIconWin();
265 unsigned int title_text_w; 284 unsigned int title_text_w;
266 285
267 title_text_w = m_screen->getWindowStyle()->font.textWidth( 286 title_text_w = m_font.textWidth(
268 fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size()); 287 fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size());
269 int l = title_text_w; 288 int l = title_text_w;
270 unsigned int dlen=fluxboxwin->getIconTitle().size(); 289 unsigned int dlen=fluxboxwin->getIconTitle().size();
271 unsigned int bevel_w = m_screen->getBevelWidth(); 290 unsigned int bevel_w = m_screen->getBevelWidth();
272 int dx=bevel_w*2; 291 int dx=bevel_w*2;
273 292 /*
274 for (; dlen >= 0; dlen--) { 293 for (; dlen >= 0; dlen--) {
275 l = m_screen->getWindowStyle()->tab.font.textWidth( 294 l = m_font.textWidth(
276 fluxboxwin->getIconTitle().c_str(), dlen); 295 fluxboxwin->getIconTitle().c_str(), dlen);
277 l += (bevel_w * 4); 296 l += (bevel_w * 4);
278 297
@@ -280,37 +299,46 @@ void IconBar::draw(const IconBarObj * const obj, int width) const {
280 break; 299 break;
281 } 300 }
282 301
283 switch (m_screen->getWindowStyle()->tab.justify) { 302 switch (m_screen->getWindowStyle()->tab.justify) {
284 case DrawUtil::Font::RIGHT: 303 case Text::Font::RIGHT:
285 dx += width - l; 304 dx += width - l;
286 break; 305 break;
287 case DrawUtil::Font::CENTER: 306 case Text::CENTER:
288 dx += (width - l) / 2; 307 dx += (width - l) / 2;
289 break; 308 break;
290 default: 309 default:
291 break; 310 break;
292 } 311 }*/
293 312 // center by default
313 unsigned int newlen = 0;
314 dx = FbTk::doAlignment(m_vertical ? obj->height() : obj->width(), bevel_w*2, FbTk::CENTER, m_font,
315 fluxboxwin->getIconTitle().c_str(), fluxboxwin->getIconTitle().size(),
316 newlen);
294 //Draw title to m_iconwin 317 //Draw title to m_iconwin
295 318
296 XClearWindow(m_display, iconwin); 319 XClearWindow(m_display, iconwin);
297 320 int dy = 1 + m_font.ascent();
298 m_screen->getWindowStyle()->tab.font.drawText( 321 if (m_vertical) {
322 int tmp = dy;
323 dy = obj->height() - dx;
324 dx = tmp;
325 }
326 //cerr<<"Drawing text: "<<dx<<", "<<dy<<endl;
327
328 m_font.drawText(
299 iconwin, 329 iconwin,
300 m_screen->getScreenNumber(), 330 m_screen->getScreenNumber(),
301 m_screen->getWindowStyle()->tab.l_text_focus_gc, 331 m_screen->getWindowStyle()->tab.l_text_focus_gc,
302 fluxboxwin->getIconTitle().c_str(), dlen, 332 fluxboxwin->getIconTitle().c_str(), newlen,
303 dx, 1+ m_screen->getWindowStyle()->tab.font.ascent(), 333 dx, dy, m_vertical);
304 false);
305 334
306} 335}
307 336
308//------------ findWindow ---------- 337/**
309// Tries to find the FluxboxWindow of the X Window 338 Tries to find the FluxboxWindow of the X Window
310// in iconbar 339 in iconbar
311// returns the fluxboxwindow on success else 340 @return the fluxboxwindow on success else 0 on failure
312// 0 on failure 341*/
313//----------------------------------
314FluxboxWindow *IconBar::findWindow(Window w) { 342FluxboxWindow *IconBar::findWindow(Window w) {
315 343
316 IconList::iterator it = m_iconlist.begin(); 344 IconList::iterator it = m_iconlist.begin();
@@ -325,12 +353,10 @@ FluxboxWindow *IconBar::findWindow(Window w) {
325 return 0; 353 return 0;
326} 354}
327 355
328//----------- findIcon --------------- 356/*
329// Tries to find a fluxboxwin icon in the iconlist 357 Tries to find a fluxboxwin icon in the iconlist
330// returns pointer to IconBarObj on success else 358 @return pointer to IconBarObj on success else 0 on failure
331// 0 on failure 359*/
332//------------------------------------
333
334IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) { 360IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) {
335 361
336 IconList::iterator it = m_iconlist.begin(); 362 IconList::iterator it = m_iconlist.begin();