aboutsummaryrefslogtreecommitdiff
path: root/src/IconBar.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
committerfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
commit18830ac9add80cbd3bf7369307d7e35a519dca9b (patch)
tree4759a5434a34ba317fe77bbf8b0ed9bb57bb6018 /src/IconBar.cc
parent1523b48bff07dead084af3064ad11c79a9b25df0 (diff)
downloadfluxbox-18830ac9add80cbd3bf7369307d7e35a519dca9b.zip
fluxbox-18830ac9add80cbd3bf7369307d7e35a519dca9b.tar.bz2
Initial revision
Diffstat (limited to 'src/IconBar.cc')
-rw-r--r--src/IconBar.cc341
1 files changed, 341 insertions, 0 deletions
diff --git a/src/IconBar.cc b/src/IconBar.cc
new file mode 100644
index 0000000..db3eabc
--- /dev/null
+++ b/src/IconBar.cc
@@ -0,0 +1,341 @@
1// IconBar.cc
2// Copyright (c) 2001 Henrik Kinnunen (fluxgen@linuxmail.org)
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#include "IconBar.hh"
23#include "i18n.hh"
24
25IconBarObj::IconBarObj(FluxboxWindow *fluxboxwin, Window iconwin) {
26 m_iconwin = iconwin;
27 m_fluxboxwin = fluxboxwin;
28}
29
30IconBarObj::~IconBarObj() {
31
32}
33
34IconBar::IconBar(BScreen *scrn, Window parent) {
35 m_parent = parent;
36 m_screen = scrn;
37 m_iconlist = new IconList;
38 m_display = scrn->getBaseDisplay()->getXDisplay();
39}
40
41IconBar::~IconBar() {
42 delete m_iconlist;
43}
44
45//------------ addIcon -----------------------
46// Adds icon to iconbar and repostions the
47// icons.
48// returns window to iconobj
49//--------------------------------------------
50Window IconBar::addIcon(FluxboxWindow *fluxboxwin) {
51
52 Window iconwin = createIconWindow(fluxboxwin, m_parent);
53 decorate(iconwin);
54 //add window object to list
55 m_iconlist->insert(new IconBarObj(fluxboxwin, iconwin));
56 //reposition all icons to fit windowbar
57 repositionIcons();
58
59 XMapSubwindows(m_display, iconwin);
60 XMapWindow(m_display, iconwin);
61
62 return iconwin;
63}
64
65//----------- delIcon -------------------
66// Removes icon from list and
67// repositions the rest of the icons
68// Return X Window of the removed iconobj
69// returns None if no window was found
70//---------------------------------------
71Window IconBar::delIcon(FluxboxWindow *fluxboxwin) {
72 Window retwin = None;
73 IconBarObj *obj = findIcon(fluxboxwin);
74 if (obj) {
75 m_iconlist->remove(obj);
76 retwin = obj->getIconWin();
77 delete obj;
78 XDestroyWindow(m_display, retwin);
79 repositionIcons();
80 }
81 return retwin;
82}
83
84//------------ loadTheme ---------------
85// renders theme to m_focus_pm
86// with the size width * height
87//--------------------------------------
88void IconBar::loadTheme(unsigned int width, unsigned int height) {
89 BImageControl *image_ctrl = m_screen->getImageControl();
90 Pixmap tmp = m_focus_pm;
91 BTexture *texture = &(m_screen->getWindowStyle()->tab.l_focus);
92
93 if (texture->getTexture() & BImage_ParentRelative ) {
94
95 BTexture *pt = &(m_screen->getWindowStyle()->tab.t_focus);
96 if (pt->getTexture() == (BImage_Flat | BImage_Solid)) {
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
103 } else {
104
105 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
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 }
112 if (tmp) image_ctrl->removeImage(tmp);
113}
114
115//------------ decorate ------------------
116// sets the background pixmap/color,
117// border, border width of the window
118//----------------------------------------
119void IconBar::decorate(Window win) {
120
121 XSetWindowBorderWidth(m_display, win, m_screen->getWindowStyle()->tab.border_width);
122 XSetWindowBorder(m_display, win, m_screen->getWindowStyle()->tab.border_color.getPixel());
123 if (m_focus_pm)
124 XSetWindowBackgroundPixmap(m_display, win, m_focus_pm);
125 else
126 XSetWindowBackground(m_display, win, m_focus_pixel);
127}
128
129
130//------------ reconfigure ---------------
131// Reconfigures the icons
132// theme, pos and width
133//----------------------------------------
134void IconBar::reconfigure() {
135 repositionIcons();
136
137}
138//---------- exposeEvent -----------------
139// Handles the expose event
140// just redraws all the icons
141//----------------------------------------
142void IconBar::exposeEvent(XExposeEvent *ee) {
143 IconBarObj *obj=0;
144 IconListIterator it(m_iconlist);
145 for (; it.current(); it++) {
146 if (it.current()->getIconWin() == ee->window) {
147 obj = it.current();
148 break;
149 }
150 }
151
152 if (obj) {
153
154 Window root;
155 unsigned int width, height;
156 unsigned int border_width, depth; //not used
157 int x, y;
158 XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height,
159 &border_width, &depth);
160
161 //max width on every icon
162 unsigned int icon_width = width / m_iconlist->count();
163
164 //load right size of theme
165 loadTheme(icon_width, height);
166
167 draw(obj, icon_width);
168
169 }
170}
171
172//------------ repositionIcons ------------
173// Calculates and moves/resizes the icons
174//-----------------------------------------
175void IconBar::repositionIcons(void) {
176 if (!m_iconlist->count())
177 return;
178
179 Window root;
180 unsigned int width, height;
181 unsigned int border_width, depth; //not used
182 int x, y;
183 XGetGeometry(m_display, m_parent, &root, &x, &y, &width, &height,
184 &border_width, &depth);
185
186 //max width on every icon
187 unsigned int icon_width = width / m_iconlist->count();
188
189 //load right size of theme
190 loadTheme(icon_width, height);
191
192 IconListIterator it(m_iconlist);
193
194 for (x = 0; it.current(); it++, x+=icon_width) {
195 Window iconwin = it.current()->getIconWin();
196 XMoveResizeWindow(m_display, iconwin,
197 x, 0,
198 icon_width, height);
199 draw(it.current(), icon_width);
200 decorate(iconwin);
201 }
202
203}
204
205//------------ createIconWindow ----------------
206// creates the X Window of icon
207// returns the created X Window
208//----------------------------------------------
209Window IconBar::createIconWindow(FluxboxWindow *fluxboxwin, Window parent) {
210 unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
211 CWColormap | CWOverrideRedirect | CWEventMask;
212 XSetWindowAttributes attrib;
213 attrib.background_pixmap = None;
214 attrib.background_pixel = attrib.border_pixel =
215 fluxboxwin->getScreen()->getWindowStyle()->tab.border_color.getPixel();
216 attrib.colormap = fluxboxwin->getScreen()->getColormap();
217 attrib.override_redirect = True;
218 attrib.event_mask = ButtonPressMask | ButtonReleaseMask |
219 ButtonMotionMask | ExposureMask | EnterWindowMask;
220
221 //create iconwindow
222 Window iconwin = XCreateWindow(m_display, parent, 0, 0, 1, 1, 0,
223 fluxboxwin->getScreen()->getDepth(), InputOutput, fluxboxwin->getScreen()->getVisual(),
224 attrib_mask, &attrib);
225
226 return iconwin;
227}
228
229//------------ draw ------------------
230// Draws theme and string to Window w
231//------------------------------------
232void IconBar::draw(IconBarObj *obj, int width) {
233 if (!obj)
234 return;
235
236 FluxboxWindow *fluxboxwin = obj->getFluxboxWin();
237 Window iconwin = obj->getIconWin();
238 char *title = *fluxboxwin->getIconTitle();
239 unsigned int title_len = strlen(title);
240 unsigned int title_text_w;
241
242 if (I18n::instance()->multibyte()) {
243 XRectangle ink, logical;
244 XmbTextExtents(m_screen->getWindowStyle()->font.set,
245 title, title_len, &ink, &logical);
246 title_text_w = logical.width;
247 } else {
248 title_text_w = XTextWidth(m_screen->getWindowStyle()->font.fontstruct,
249 title, title_len);
250 }
251
252 int l = title_text_w;
253 int dlen=title_len;
254 unsigned int bevel_w = m_screen->getBevelWidth();
255 int dx=bevel_w*2;
256
257 for (; dlen >= 0; dlen--) {
258 if (I18n::instance()->multibyte()) {
259 XRectangle ink, logical;
260 XmbTextExtents(m_screen->getWindowStyle()->tab.font.set,
261 title, dlen,
262 &ink, &logical);
263 l = logical.width;
264 } else
265 l = XTextWidth(m_screen->getWindowStyle()->tab.font.fontstruct,
266 title, dlen);
267 l += (bevel_w * 4);
268
269 if (l < width)
270 break;
271 }
272
273
274 switch (m_screen->getWindowStyle()->tab.font.justify) {
275 case FFont::Right:
276 dx += width - l;
277 break;
278 case FFont::Center:
279 dx += (width - l) / 2;
280 break;
281 default:
282 break;
283 }
284
285 //Draw title to m_tabwin
286
287 XClearWindow(m_display, iconwin);
288
289 if (I18n::instance()->multibyte()) {
290 XmbDrawString(m_display, iconwin,
291 m_screen->getWindowStyle()->tab.font.set,
292 m_screen->getWindowStyle()->tab.l_text_focus_gc, dx,
293 1 - m_screen->getWindowStyle()->tab.font.set_extents->max_ink_extent.y,
294 title, dlen);
295 } else {
296 XDrawString(m_display, iconwin,
297 m_screen->getWindowStyle()->tab.l_text_focus_gc, dx,
298 m_screen->getWindowStyle()->tab.font.fontstruct->ascent + 1,
299 title, dlen);
300 }
301
302}
303
304//------------ findWindow ----------
305// Tries to find the FluxboxWindow of the X Window
306// in iconbar
307// returns the fluxboxwindow on success else
308// 0 on failure
309//----------------------------------
310FluxboxWindow *IconBar::findWindow(Window w) {
311
312 IconListIterator it(m_iconlist);
313
314 for (; it.current(); it++) {
315 IconBarObj *tmp = it.current();
316 if (tmp)
317 if (tmp->getIconWin() == w)
318 return tmp->getFluxboxWin();
319 }
320
321 return 0;
322}
323
324//----------- findIcon ---------------
325// Tries to find a fluxboxwin icon in the iconlist
326// returns pointer to IconBarObj on success else
327// 0 on failure
328//------------------------------------
329IconBarObj *IconBar::findIcon(FluxboxWindow *fluxboxwin) {
330
331 IconListIterator it(m_iconlist);
332
333 for (; it.current(); it++) {
334 IconBarObj *tmp = it.current();
335 if (tmp)
336 if (tmp->getFluxboxWin() == fluxboxwin)
337 return tmp;
338 }
339
340 return 0;
341}