]> icculus.org git repositories - mikachu/openbox.git/blob - src/Toolbar.cc
Using some references instead of pointers for the menus.
[mikachu/openbox.git] / src / Toolbar.cc
1 // Toolbar.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef   _GNU_SOURCE
26 #define   _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef    HAVE_CONFIG_H
30 #  include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include "i18n.h"
34 #include "openbox.h"
35 #include "Clientmenu.h"
36 #include "Iconmenu.h"
37 #include "Rootmenu.h"
38 #include "Screen.h"
39 #include "Toolbar.h"
40 #include "Window.h"
41 #include "Workspace.h"
42 #include "Workspacemenu.h"
43
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
46
47 #ifdef    STDC_HEADERS
48 #  include <string.h>
49 #endif // STDC_HEADERS
50
51 #ifdef    HAVE_STDIO_H
52 #  include <stdio.h>
53 #endif // HAVE_STDIO_H
54
55 #ifdef    TIME_WITH_SYS_TIME
56 # include <sys/time.h>
57 # include <time.h>
58 #else // !TIME_WITH_SYS_TIME
59 # ifdef    HAVE_SYS_TIME_H
60 #  include <sys/time.h>
61 # else // !HAVE_SYS_TIME_H
62 #  include <time.h>
63 # endif // HAVE_SYS_TIME_H
64 #endif // TIME_WITH_SYS_TIME
65
66
67 Toolbar::Toolbar(BScreen *scrn) {
68   screen = scrn;
69   openbox = screen->getOpenbox();
70
71   // get the clock updating every minute
72   clock_timer = new BTimer(*openbox, *this);
73   timeval now;
74   gettimeofday(&now, 0);
75   clock_timer->setTimeout((60 - (now.tv_sec % 60)) * 1000);
76   clock_timer->start();
77
78   hide_handler.toolbar = this;
79   hide_timer = new BTimer(*openbox, hide_handler);
80   hide_timer->setTimeout(openbox->getAutoRaiseDelay());
81   hide_timer->fireOnce(True);
82
83   image_ctrl = screen->getImageControl();
84
85   on_top = screen->isToolbarOnTop();
86   hidden = do_auto_hide = screen->doToolbarAutoHide();
87
88   editing = False;
89   new_workspace_name = (char *) 0;
90   new_name_pos = 0;
91   frame.grab_x = frame.grab_y = 0;
92
93   toolbarmenu = new Toolbarmenu(*this);
94
95   display = openbox->getXDisplay();
96   XSetWindowAttributes attrib;
97   unsigned long create_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
98                               CWColormap | CWOverrideRedirect | CWEventMask;
99   attrib.background_pixmap = None;
100   attrib.background_pixel = attrib.border_pixel =
101     screen->getBorderColor()->getPixel();
102   attrib.colormap = screen->getColormap();
103   attrib.override_redirect = True;
104   attrib.event_mask = ButtonPressMask | ButtonReleaseMask |
105                       EnterWindowMask | LeaveWindowMask;
106
107   frame.window =
108     XCreateWindow(display, screen->getRootWindow(), 0, 0, 1, 1, 0,
109                   screen->getDepth(), InputOutput, screen->getVisual(),
110                   create_mask, &attrib);
111   openbox->saveToolbarSearch(frame.window, this);
112
113   attrib.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask |
114                       KeyPressMask | EnterWindowMask;
115
116   frame.workspace_label =
117     XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
118                   InputOutput, screen->getVisual(), create_mask, &attrib);
119   openbox->saveToolbarSearch(frame.workspace_label, this);
120
121   frame.window_label =
122     XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
123                   InputOutput, screen->getVisual(), create_mask, &attrib);
124   openbox->saveToolbarSearch(frame.window_label, this);
125
126   frame.clock =
127     XCreateWindow(display, frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
128                   InputOutput, screen->getVisual(), create_mask, &attrib);
129   openbox->saveToolbarSearch(frame.clock, this);
130
131   frame.psbutton =
132     XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
133                   InputOutput, screen->getVisual(), create_mask, &attrib);
134   openbox->saveToolbarSearch(frame.psbutton, this);
135
136   frame.nsbutton =
137     XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
138                   InputOutput, screen->getVisual(), create_mask, &attrib);
139   openbox->saveToolbarSearch(frame.nsbutton, this);
140
141   frame.pwbutton =
142     XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
143                   InputOutput, screen->getVisual(), create_mask, &attrib);
144   openbox->saveToolbarSearch(frame.pwbutton, this);
145
146   frame.nwbutton =
147     XCreateWindow(display ,frame.window, 0, 0, 1, 1, 0, screen->getDepth(),
148                   InputOutput, screen->getVisual(), create_mask, &attrib);
149   openbox->saveToolbarSearch(frame.nwbutton, this);
150
151   frame.base = frame.label = frame.wlabel = frame.clk = frame.button =
152     frame.pbutton = None;
153
154   reconfigure();
155
156   XMapSubwindows(display, frame.window);
157   XMapWindow(display, frame.window);
158 }
159
160
161 Toolbar::~Toolbar(void) {
162   XUnmapWindow(display, frame.window);
163
164   if (frame.base) image_ctrl->removeImage(frame.base);
165   if (frame.label) image_ctrl->removeImage(frame.label);
166   if (frame.wlabel) image_ctrl->removeImage(frame.wlabel);
167   if (frame.clk) image_ctrl->removeImage(frame.clk);
168   if (frame.button) image_ctrl->removeImage(frame.button);
169   if (frame.pbutton) image_ctrl->removeImage(frame.pbutton);
170
171   openbox->removeToolbarSearch(frame.window);
172   openbox->removeToolbarSearch(frame.workspace_label);
173   openbox->removeToolbarSearch(frame.window_label);
174   openbox->removeToolbarSearch(frame.clock);
175   openbox->removeToolbarSearch(frame.psbutton);
176   openbox->removeToolbarSearch(frame.nsbutton);
177   openbox->removeToolbarSearch(frame.pwbutton);
178   openbox->removeToolbarSearch(frame.nwbutton);
179
180   XDestroyWindow(display, frame.workspace_label);
181   XDestroyWindow(display, frame.window_label);
182   XDestroyWindow(display, frame.clock);
183
184   XDestroyWindow(display, frame.window);
185
186   delete hide_timer;
187   delete clock_timer;
188   delete toolbarmenu;
189 }
190
191
192 void Toolbar::reconfigure(void) {
193   frame.bevel_w = screen->getBevelWidth();
194   frame.width = screen->getWidth() * screen->getToolbarWidthPercent() / 100;
195   
196   if (i18n->multibyte())
197     frame.height =
198       screen->getToolbarStyle()->fontset_extents->max_ink_extent.height;
199   else
200     frame.height = screen->getToolbarStyle()->font->ascent +
201                    screen->getToolbarStyle()->font->descent;
202   frame.button_w = frame.height;
203   frame.height += 2;
204   frame.label_h = frame.height;
205   frame.height += (frame.bevel_w * 2);
206   
207   switch (screen->getToolbarPlacement()) {
208   case TopLeft:
209     frame.x = 0;
210     frame.y = 0;
211     frame.x_hidden = 0;
212     frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth()
213                      - frame.height;
214     break;
215
216   case BottomLeft:
217     frame.x = 0;
218     frame.y = screen->getHeight() - frame.height
219       - (screen->getBorderWidth() * 2);
220     frame.x_hidden = 0;
221     frame.y_hidden = screen->getHeight() - screen->getBevelWidth()
222                      - screen->getBorderWidth();
223     break;
224
225   case TopCenter:
226     frame.x = (screen->getWidth() - frame.width) / 2;
227     frame.y = 0;
228     frame.x_hidden = frame.x;
229     frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth()
230                      - frame.height;
231     break;
232
233   case BottomCenter:
234   default:
235     frame.x = (screen->getWidth() - frame.width) / 2;
236     frame.y = screen->getHeight() - frame.height
237       - (screen->getBorderWidth() * 2);
238     frame.x_hidden = frame.x;
239     frame.y_hidden = screen->getHeight() - screen->getBevelWidth()
240                      - screen->getBorderWidth();
241     break;
242
243   case TopRight:
244     frame.x = screen->getWidth() - frame.width
245       - (screen->getBorderWidth() * 2);
246     frame.y = 0;
247     frame.x_hidden = frame.x;
248     frame.y_hidden = screen->getBevelWidth() - screen->getBorderWidth()
249                      - frame.height;
250     break;
251
252   case BottomRight:
253     frame.x = screen->getWidth() - frame.width
254       - (screen->getBorderWidth() * 2);
255     frame.y = screen->getHeight() - frame.height
256       - (screen->getBorderWidth() * 2);
257     frame.x_hidden = frame.x;
258     frame.y_hidden = screen->getHeight() - screen->getBevelWidth()
259                      - screen->getBorderWidth();
260     break;
261   }
262
263 #ifdef    HAVE_STRFTIME
264   time_t ttmp = time(NULL);
265   struct tm *tt = 0;
266
267   if (ttmp != -1) {
268     tt = localtime(&ttmp);
269     if (tt) {
270       char t[1025], *time_string = (char *) 0;
271       int len = strftime(t, 1024, screen->getStrftimeFormat(), tt);
272       t[len++-1] = ' ';   // add a space to the string for padding
273       t[len++-1] = ' ';   // add a space to the string for padding
274       t[len] = '\0';
275
276       if (i18n->multibyte()) {
277         XRectangle ink, logical;
278         XmbTextExtents(screen->getToolbarStyle()->fontset, t, len, &ink,
279                        &logical);
280         frame.clock_w = logical.width;
281
282         // ben's additional solution to pad some space beside the numbers
283         //frame.clock_w +=
284         //  screen->getToolbarStyle()->fontset_extents->max_logical_extent.width *
285         //  4;
286
287         // brad's solution, which is currently buggy, too big
288         //frame.clock_w =
289         //  screen->getToolbarStyle()->fontset_extents->max_logical_extent.width
290         //  * len;
291       } else {
292         frame.clock_w = XTextWidth(screen->getToolbarStyle()->font, t, len);
293         // ben's additional solution to pad some space beside the numbers
294         //frame.clock_w += screen->getToolbarStyle()->font->max_bounds.width * 4;
295         // brad's solution again, too big
296         //frame.clock_w = screen->getToolbarStyle()->font->max_bounds.width * len;
297       }
298       frame.clock_w += (frame.bevel_w * 4);
299       
300       delete [] time_string;
301     } else {
302       frame.clock_w = 0;
303     }
304   } else {
305     frame.clock_w = 0;
306   }
307 #else // !HAVE_STRFTIME
308   frame.clock_w =
309     XTextWidth(screen->getToolbarStyle()->font,
310                i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
311                                 "00:00000"),
312                strlen(i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
313                                        "00:00000"))) + (frame.bevel_w * 4);
314 #endif // HAVE_STRFTIME
315
316   int i;
317   unsigned int w = 0;
318   frame.workspace_label_w = 0;
319
320   for (i = 0; i < screen->getWorkspaceCount(); i++) {
321     if (i18n->multibyte()) {
322       XRectangle ink, logical;
323       XmbTextExtents(screen->getToolbarStyle()->fontset,
324                      screen->getWorkspace(i)->getName(),
325                      strlen(screen->getWorkspace(i)->getName()),
326                      &ink, &logical);
327       w = logical.width;
328     } else {
329       w = XTextWidth(screen->getToolbarStyle()->font,
330                      screen->getWorkspace(i)->getName(),
331                      strlen(screen->getWorkspace(i)->getName()));
332     }
333     w += (frame.bevel_w * 4);
334
335     if (w > frame.workspace_label_w) frame.workspace_label_w = w;
336   }
337
338   if (frame.workspace_label_w < frame.clock_w)
339     frame.workspace_label_w = frame.clock_w;
340   else if (frame.workspace_label_w > frame.clock_w)
341     frame.clock_w = frame.workspace_label_w;
342
343   frame.window_label_w =
344     (frame.width - (frame.clock_w + (frame.button_w * 4) +
345                     frame.workspace_label_w + (frame.bevel_w * 8) + 6));
346
347   if (hidden) {
348     XMoveResizeWindow(display, frame.window, frame.x_hidden, frame.y_hidden,
349                       frame.width, frame.height);
350   } else {
351     XMoveResizeWindow(display, frame.window, frame.x, frame.y,
352                       frame.width, frame.height);
353   }
354
355   XMoveResizeWindow(display, frame.workspace_label, frame.bevel_w,
356                     frame.bevel_w, frame.workspace_label_w,
357                     frame.label_h);
358   XMoveResizeWindow(display, frame.psbutton, (frame.bevel_w * 2) +
359                     frame.workspace_label_w + 1, frame.bevel_w + 1,
360                     frame.button_w, frame.button_w);
361   XMoveResizeWindow(display ,frame.nsbutton, (frame.bevel_w * 3) +
362                     frame.workspace_label_w + frame.button_w + 2,
363                     frame.bevel_w + 1, frame.button_w, frame.button_w);
364   XMoveResizeWindow(display, frame.window_label, (frame.bevel_w * 4) +
365                     (frame.button_w * 2) + frame.workspace_label_w + 3,
366                     frame.bevel_w, frame.window_label_w, frame.label_h);
367   XMoveResizeWindow(display, frame.pwbutton, (frame.bevel_w * 5) +
368                     (frame.button_w * 2) + frame.workspace_label_w +
369                     frame.window_label_w + 4, frame.bevel_w + 1,
370                     frame.button_w, frame.button_w);
371   XMoveResizeWindow(display, frame.nwbutton, (frame.bevel_w * 6) +
372                     (frame.button_w * 3) + frame.workspace_label_w +
373                     frame.window_label_w + 5, frame.bevel_w + 1,
374                     frame.button_w, frame.button_w);
375   XMoveResizeWindow(display, frame.clock, frame.width - frame.clock_w -
376                     frame.bevel_w, frame.bevel_w, frame.clock_w,
377                     frame.label_h);
378
379   Pixmap tmp = frame.base;
380   BTexture *texture = &(screen->getToolbarStyle()->toolbar);
381   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
382     frame.base = None;
383     XSetWindowBackground(display, frame.window,
384                          texture->getColor()->getPixel());
385   } else {
386     frame.base =
387       image_ctrl->renderImage(frame.width, frame.height, texture);
388     XSetWindowBackgroundPixmap(display, frame.window, frame.base);
389   }
390   if (tmp) image_ctrl->removeImage(tmp);
391
392   tmp = frame.label;
393   texture = &(screen->getToolbarStyle()->window);
394   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
395     frame.label = None;
396     XSetWindowBackground(display, frame.window_label,
397                          texture->getColor()->getPixel());
398   } else {
399     frame.label =
400       image_ctrl->renderImage(frame.window_label_w, frame.label_h, texture);
401     XSetWindowBackgroundPixmap(display, frame.window_label, frame.label);
402   }
403   if (tmp) image_ctrl->removeImage(tmp);
404
405   tmp = frame.wlabel;
406   texture = &(screen->getToolbarStyle()->label);
407   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
408     frame.wlabel = None;
409     XSetWindowBackground(display, frame.workspace_label,
410                          texture->getColor()->getPixel());
411   } else {
412     frame.wlabel =
413       image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
414     XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
415   }
416   if (tmp) image_ctrl->removeImage(tmp);
417
418   tmp = frame.clk;
419   texture = &(screen->getToolbarStyle()->clock);
420   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
421     frame.clk = None;
422     XSetWindowBackground(display, frame.clock,
423                          texture->getColor()->getPixel());
424   } else {
425     frame.clk =
426       image_ctrl->renderImage(frame.clock_w, frame.label_h, texture);
427     XSetWindowBackgroundPixmap(display, frame.clock, frame.clk);
428   }
429   if (tmp) image_ctrl->removeImage(tmp);
430
431   tmp = frame.button;
432   texture = &(screen->getToolbarStyle()->button);
433   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
434     frame.button = None;
435
436     frame.button_pixel = texture->getColor()->getPixel();
437     XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
438     XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
439     XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
440     XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
441   } else {
442     frame.button =
443       image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
444
445     XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
446     XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
447     XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
448     XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
449   }
450   if (tmp) image_ctrl->removeImage(tmp);
451
452   tmp = frame.pbutton;
453   texture = &(screen->getToolbarStyle()->pressed);
454   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
455     frame.pbutton = None;
456     frame.pbutton_pixel = texture->getColor()->getPixel();
457   } else {
458     frame.pbutton =
459       image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
460   }
461   if (tmp) image_ctrl->removeImage(tmp);
462
463   XSetWindowBorder(display, frame.window,
464                    screen->getBorderColor()->getPixel());
465   XSetWindowBorderWidth(display, frame.window, screen->getBorderWidth());
466
467   XClearWindow(display, frame.window);
468   XClearWindow(display, frame.workspace_label);
469   XClearWindow(display, frame.window_label);
470   XClearWindow(display, frame.clock);
471   XClearWindow(display, frame.psbutton);
472   XClearWindow(display, frame.nsbutton);
473   XClearWindow(display, frame.pwbutton);
474   XClearWindow(display, frame.nwbutton);
475
476   redrawWindowLabel();
477   redrawWorkspaceLabel();
478   redrawPrevWorkspaceButton();
479   redrawNextWorkspaceButton();
480   redrawPrevWindowButton();
481   redrawNextWindowButton();
482   checkClock(True);
483
484   toolbarmenu->reconfigure();
485 }
486
487
488 #ifdef    HAVE_STRFTIME
489 void Toolbar::checkClock(Bool redraw) {
490 #else // !HAVE_STRFTIME
491 void Toolbar::checkClock(Bool redraw, Bool date) {
492 #endif // HAVE_STRFTIME
493   time_t tmp = 0;
494   struct tm *tt = 0;
495
496   if ((tmp = time(NULL)) != -1) {
497     if (! (tt = localtime(&tmp))) return;
498     if (tt->tm_min != frame.minute || tt->tm_hour != frame.hour) {
499       frame.hour = tt->tm_hour;
500       frame.minute = tt->tm_min;
501       XClearWindow(display, frame.clock);
502       redraw = True;
503     }
504   }
505
506   if (redraw) {
507 #ifdef    HAVE_STRFTIME
508     char t[1024];
509     if (! strftime(t, 1024, screen->getStrftimeFormat(), tt))
510       return;
511 #else // !HAVE_STRFTIME
512     char t[9];
513     if (date) {
514       // format the date... with special consideration for y2k ;)
515       if (screen->getDateFormat() == Openbox::B_EuropeanDate)
516         sprintf(t, 18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormatEu,
517                                    "%02d.%02d.%02d"),
518                 tt->tm_mday, tt->tm_mon + 1,
519                 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
520       else
521         sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormat,
522                                     "%02d/%02d/%02d"),
523                 tt->tm_mon + 1, tt->tm_mday,
524                 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
525     } else {
526       if (screen->isClock24Hour())
527         sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat24,
528                                     "  %02d:%02d "),
529                 frame.hour, frame.minute);
530       else
531         sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat12,
532                                     "%02d:%02d %sm"),
533                 ((frame.hour > 12) ? frame.hour - 12 :
534                  ((frame.hour == 0) ? 12 : frame.hour)), frame.minute,
535                 ((frame.hour >= 12) ?
536                  i18n->getMessage(ToolbarSet,
537                                   ToolbarNoStrftimeTimeFormatP, "p") :
538                  i18n->getMessage(ToolbarSet,
539                                   ToolbarNoStrftimeTimeFormatA, "a")));
540     }
541 #endif // HAVE_STRFTIME
542
543     int dx = (frame.bevel_w * 2), dlen = strlen(t);
544     unsigned int l;
545
546     if (i18n->multibyte()) {
547       XRectangle ink, logical;
548       XmbTextExtents(screen->getToolbarStyle()->fontset,
549                      t, dlen, &ink, &logical);
550       l = logical.width;
551     } else {
552       l = XTextWidth(screen->getToolbarStyle()->font, t, dlen);
553     }
554     
555     l += (frame.bevel_w * 4);
556     
557     if (l > frame.clock_w) {
558       for (; dlen >= 0; dlen--) {
559         if (i18n->multibyte()) {
560           XRectangle ink, logical;
561           XmbTextExtents(screen->getToolbarStyle()->fontset,
562                          t, dlen, &ink, &logical);
563           l = logical.width;
564         } else {
565           l = XTextWidth(screen->getToolbarStyle()->font, t, dlen);
566         }
567         l+= (frame.bevel_w * 4);
568         
569         if (l < frame.clock_w)
570           break;
571       }
572     }
573     switch (screen->getToolbarStyle()->justify) {
574     case BScreen::RightJustify:
575       dx += frame.clock_w - l;
576       break;
577
578     case BScreen::CenterJustify:
579       dx += (frame.clock_w - l) / 2;
580       break;
581     }
582
583     ToolbarStyle *style = screen->getToolbarStyle();
584     if (i18n->multibyte())
585       XmbDrawString(display, frame.clock, style->fontset, style->c_text_gc,
586                     dx, (1 - style->fontset_extents->max_ink_extent.y),
587                     t, dlen);
588     else
589       XDrawString(display, frame.clock, style->c_text_gc, dx,
590                   (style->font->ascent + 1), t, dlen);
591   }
592 }
593
594
595 void Toolbar::redrawWindowLabel(Bool redraw) {
596   if (screen->getOpenbox()->getFocusedWindow()) {
597     if (redraw)
598       XClearWindow(display, frame.window_label);
599
600     OpenboxWindow *foc = screen->getOpenbox()->getFocusedWindow();
601     if (foc->getScreen() != screen) return;
602
603     int dx = (frame.bevel_w * 2), dlen = strlen(*foc->getTitle());
604     unsigned int l;
605
606     if (i18n->multibyte()) {
607       XRectangle ink, logical;
608       XmbTextExtents(screen->getToolbarStyle()->fontset, *foc->getTitle(),
609                      dlen, &ink, &logical);
610       l = logical.width;
611     } else {
612       l = XTextWidth(screen->getToolbarStyle()->font, *foc->getTitle(), dlen);
613     }
614     l += (frame.bevel_w * 4);
615
616     if (l > frame.window_label_w) {
617       for (; dlen >= 0; dlen--) {
618         if (i18n->multibyte()) {
619           XRectangle ink, logical;
620           XmbTextExtents(screen->getToolbarStyle()->fontset,
621                          *foc->getTitle(), dlen, &ink, &logical);
622           l = logical.width;
623         } else {
624           l = XTextWidth(screen->getToolbarStyle()->font,
625                          *foc->getTitle(), dlen);
626         }
627         l += (frame.bevel_w * 4);
628         
629         if (l < frame.window_label_w)
630           break;
631       }
632     }
633     switch (screen->getToolbarStyle()->justify) {
634     case BScreen::RightJustify:
635       dx += frame.window_label_w - l;
636       break;
637
638     case BScreen::CenterJustify:
639       dx += (frame.window_label_w - l) / 2;
640       break;
641     }
642
643     ToolbarStyle *style = screen->getToolbarStyle();
644     if (i18n->multibyte())
645       XmbDrawString(display, frame.window_label, style->fontset,
646                     style->w_text_gc, dx,
647                     (1 - style->fontset_extents->max_ink_extent.y),
648                     *foc->getTitle(), dlen);
649     else
650       XDrawString(display, frame.window_label, style->w_text_gc, dx,
651                   (style->font->ascent + 1), *foc->getTitle(), dlen);
652   } else {
653     XClearWindow(display, frame.window_label);
654   }
655 }
656  
657  
658 void Toolbar::redrawWorkspaceLabel(Bool redraw) {
659   if (screen->getCurrentWorkspace()->getName()) {
660     if (redraw)
661       XClearWindow(display, frame.workspace_label);
662     
663     int dx = (frame.bevel_w * 2), dlen =
664              strlen(screen->getCurrentWorkspace()->getName());
665     unsigned int l;
666     
667     if (i18n->multibyte()) {
668       XRectangle ink, logical;
669       XmbTextExtents(screen->getToolbarStyle()->fontset,
670                      screen->getCurrentWorkspace()->getName(), dlen,
671                      &ink, &logical);
672       l = logical.width;
673     } else {
674       l = XTextWidth(screen->getToolbarStyle()->font,
675                      screen->getCurrentWorkspace()->getName(), dlen);
676     }
677     l += (frame.bevel_w * 4);
678     
679     if (l > frame.workspace_label_w) {
680       for (; dlen >= 0; dlen--) {
681         if (i18n->multibyte()) {
682           XRectangle ink, logical;
683           XmbTextExtents(screen->getToolbarStyle()->fontset,
684                          screen->getCurrentWorkspace()->getName(), dlen,
685                          &ink, &logical);
686           l = logical.width;
687         } else {
688           l = XTextWidth(screen->getWindowStyle()->font,
689                          screen->getCurrentWorkspace()->getName(), dlen);
690         }
691         l += (frame.bevel_w * 4);
692         
693         if (l < frame.workspace_label_w)
694           break;
695       }
696     }
697     switch (screen->getToolbarStyle()->justify) {
698     case BScreen::RightJustify:
699       dx += frame.workspace_label_w - l;
700       break;
701
702     case BScreen::CenterJustify:
703       dx += (frame.workspace_label_w - l) / 2;
704       break;
705     }
706
707     ToolbarStyle *style = screen->getToolbarStyle();
708     if (i18n->multibyte())
709       XmbDrawString(display, frame.workspace_label, style->fontset,
710                     style->l_text_gc, dx,
711                     (1 - style->fontset_extents->max_ink_extent.y),
712                     (char *) screen->getCurrentWorkspace()->getName(), dlen);
713     else
714       XDrawString(display, frame.workspace_label, style->l_text_gc, dx,
715                   (style->font->ascent + 1),
716                   (char *) screen->getCurrentWorkspace()->getName(), dlen);
717   }
718 }
719
720
721 void Toolbar::redrawPrevWorkspaceButton(Bool pressed, Bool redraw) {
722   if (redraw) {
723     if (pressed) {
724       if (frame.pbutton)
725         XSetWindowBackgroundPixmap(display, frame.psbutton, frame.pbutton);
726       else
727         XSetWindowBackground(display, frame.psbutton, frame.pbutton_pixel);
728     } else {
729       if (frame.button)
730         XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
731       else
732         XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
733     }
734     XClearWindow(display, frame.psbutton);
735   }
736
737   int hh = frame.button_w / 2, hw = frame.button_w / 2;
738
739   XPoint pts[3];
740   pts[0].x = hw - 2; pts[0].y = hh;
741   pts[1].x = 4; pts[1].y = 2;
742   pts[2].x = 0; pts[2].y = -4;
743
744   XFillPolygon(display, frame.psbutton, screen->getToolbarStyle()->b_pic_gc,
745                pts, 3, Convex, CoordModePrevious);
746 }
747
748
749 void Toolbar::redrawNextWorkspaceButton(Bool pressed, Bool redraw) {
750   if (redraw) {
751     if (pressed) {
752       if (frame.pbutton)
753         XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.pbutton);
754       else
755         XSetWindowBackground(display, frame.nsbutton, frame.pbutton_pixel);
756     } else {
757       if (frame.button)
758         XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
759       else
760         XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
761     }
762     XClearWindow(display, frame.nsbutton);
763   }
764
765   int hh = frame.button_w / 2, hw = frame.button_w / 2;
766
767   XPoint pts[3];
768   pts[0].x = hw - 2; pts[0].y = hh - 2;
769   pts[1].x = 4; pts[1].y =  2;
770   pts[2].x = -4; pts[2].y = 2;
771
772   XFillPolygon(display, frame.nsbutton, screen->getToolbarStyle()->b_pic_gc,
773                pts, 3, Convex, CoordModePrevious);
774 }
775
776
777 void Toolbar::redrawPrevWindowButton(Bool pressed, Bool redraw) {
778   if (redraw) {
779     if (pressed) {
780       if (frame.pbutton)
781         XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.pbutton);
782       else
783         XSetWindowBackground(display, frame.pwbutton, frame.pbutton_pixel);
784     } else {
785       if (frame.button)
786         XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
787       else
788         XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
789     }
790     XClearWindow(display, frame.pwbutton);
791   }
792
793   int hh = frame.button_w / 2, hw = frame.button_w / 2;
794
795   XPoint pts[3];
796   pts[0].x = hw - 2; pts[0].y = hh;
797   pts[1].x = 4; pts[1].y = 2;
798   pts[2].x = 0; pts[2].y = -4;
799
800   XFillPolygon(display, frame.pwbutton, screen->getToolbarStyle()->b_pic_gc,
801                pts, 3, Convex, CoordModePrevious);
802 }
803
804
805 void Toolbar::redrawNextWindowButton(Bool pressed, Bool redraw) {
806   if (redraw) {
807     if (pressed) {
808       if (frame.pbutton)
809         XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.pbutton);
810       else
811         XSetWindowBackground(display, frame.nwbutton, frame.pbutton_pixel);
812     } else {
813       if (frame.button)
814         XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
815       else
816         XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
817     }
818     XClearWindow(display, frame.nwbutton);
819   }
820
821   int hh = frame.button_w / 2, hw = frame.button_w / 2;
822
823   XPoint pts[3];
824   pts[0].x = hw - 2; pts[0].y = hh - 2;
825   pts[1].x = 4; pts[1].y =  2;
826   pts[2].x = -4; pts[2].y = 2;
827
828   XFillPolygon(display, frame.nwbutton, screen->getToolbarStyle()->b_pic_gc,
829                pts, 3, Convex, CoordModePrevious);
830 }
831
832
833 void Toolbar::edit(void) {
834   Window window;
835   int foo;
836
837   editing = True;
838   if (XGetInputFocus(display, &window, &foo) &&
839       window == frame.workspace_label)
840     return;
841
842   XSetInputFocus(display, frame.workspace_label,
843                  ((screen->isSloppyFocus()) ? RevertToPointerRoot :
844                   RevertToParent),
845                  CurrentTime);
846   XClearWindow(display, frame.workspace_label);
847
848   openbox->setNoFocus(True);
849   if (openbox->getFocusedWindow())
850     openbox->getFocusedWindow()->setFocusFlag(False);
851
852   XDrawRectangle(display, frame.workspace_label,
853                  screen->getWindowStyle()->l_text_focus_gc,
854                  frame.workspace_label_w / 2, 0, 1,
855                  frame.label_h - 1);
856   
857   // change the background of the window to that of an active window label
858   Pixmap tmp = frame.wlabel;
859   BTexture *texture = &(screen->getWindowStyle()->l_focus);
860   if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
861     frame.wlabel = None;
862     XSetWindowBackground(display, frame.workspace_label,
863                          texture->getColor()->getPixel());
864   } else {
865     frame.wlabel =
866       image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
867     XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
868   }
869   if (tmp) image_ctrl->removeImage(tmp);
870 }
871
872
873 void Toolbar::buttonPressEvent(XButtonEvent *be) {
874   if (be->button == 1) {
875     if (be->window == frame.psbutton)
876       redrawPrevWorkspaceButton(True, True);
877     else if (be->window == frame.nsbutton)
878       redrawNextWorkspaceButton(True, True);
879     else if (be->window == frame.pwbutton)
880       redrawPrevWindowButton(True, True);
881     else if (be->window == frame.nwbutton)
882       redrawNextWindowButton(True, True);
883 #ifndef   HAVE_STRFTIME
884     else if (be->window == frame.clock) {
885       XClearWindow(display, frame.clock);
886       checkClock(True, True);
887     }
888 #endif // HAVE_STRFTIME
889     else if (! on_top) {
890       Window w[1] = { frame.window };
891       screen->raiseWindows(w, 1);
892     }
893   } else if (be->button == 2 && (! on_top)) {
894     XLowerWindow(display, frame.window);
895   } else if (be->button == 3) {
896     if (! toolbarmenu->isVisible()) {
897       int x, y;
898
899       x = be->x_root - (toolbarmenu->getWidth() / 2);
900       y = be->y_root - (toolbarmenu->getHeight() / 2);
901
902       if (x < 0)
903         x = 0;
904       else if (x + toolbarmenu->getWidth() > screen->getWidth())
905         x = screen->getWidth() - toolbarmenu->getWidth();
906
907       if (y < 0)
908         y = 0;
909       else if (y + toolbarmenu->getHeight() > screen->getHeight())
910         y = screen->getHeight() - toolbarmenu->getHeight();
911
912       toolbarmenu->move(x, y);
913       toolbarmenu->show();
914     } else
915       toolbarmenu->hide();
916   }
917 }
918
919
920
921 void Toolbar::buttonReleaseEvent(XButtonEvent *re) {
922   if (re->button == 1) {
923     if (re->window == frame.psbutton) {
924       redrawPrevWorkspaceButton(False, True);
925
926       if (re->x >= 0 && re->x < (signed) frame.button_w &&
927           re->y >= 0 && re->y < (signed) frame.button_w)
928        if (screen->getCurrentWorkspace()->getWorkspaceID() > 0)
929           screen->changeWorkspaceID(screen->getCurrentWorkspace()->
930                                     getWorkspaceID() - 1);
931         else
932           screen->changeWorkspaceID(screen->getWorkspaceCount() - 1);
933     } else if (re->window == frame.nsbutton) {
934       redrawNextWorkspaceButton(False, True);
935
936       if (re->x >= 0 && re->x < (signed) frame.button_w &&
937           re->y >= 0 && re->y < (signed) frame.button_w)
938         if (screen->getCurrentWorkspace()->getWorkspaceID() <
939             screen->getWorkspaceCount() - 1)
940           screen->changeWorkspaceID(screen->getCurrentWorkspace()->
941                                     getWorkspaceID() + 1);
942         else
943           screen->changeWorkspaceID(0);
944     } else if (re->window == frame.pwbutton) {
945       redrawPrevWindowButton(False, True);
946
947       if (re->x >= 0 && re->x < (signed) frame.button_w &&
948           re->y >= 0 && re->y < (signed) frame.button_w)
949         screen->prevFocus();
950     } else if (re->window == frame.nwbutton) {
951       redrawNextWindowButton(False, True);
952
953       if (re->x >= 0 && re->x < (signed) frame.button_w &&
954           re->y >= 0 && re->y < (signed) frame.button_w)
955         screen->nextFocus();
956     } else if (re->window == frame.window_label)
957       screen->raiseFocus();
958 #ifndef   HAVE_STRFTIME
959     else if (re->window == frame.clock) {
960       XClearWindow(display, frame.clock);
961       checkClock(True);
962     }
963 #endif // HAVE_STRFTIME
964   }
965 }
966
967
968 void Toolbar::enterNotifyEvent(XCrossingEvent *) {
969   if (! do_auto_hide)
970     return;
971
972   if (hidden) {
973     if (! hide_timer->isTiming()) hide_timer->start();
974   } else {
975     if (hide_timer->isTiming()) hide_timer->stop();
976   }
977 }
978
979 void Toolbar::leaveNotifyEvent(XCrossingEvent *) {
980   if (! do_auto_hide)
981     return;
982
983   if (hidden) {
984     if (hide_timer->isTiming()) hide_timer->stop();
985   } else if (! toolbarmenu->isVisible()) {
986     if (! hide_timer->isTiming()) hide_timer->start();
987   }
988 }
989
990
991 void Toolbar::exposeEvent(XExposeEvent *ee) {
992   if (ee->window == frame.clock) checkClock(True);
993   else if (ee->window == frame.workspace_label && (! editing))
994     redrawWorkspaceLabel();
995   else if (ee->window == frame.window_label) redrawWindowLabel();
996   else if (ee->window == frame.psbutton) redrawPrevWorkspaceButton();
997   else if (ee->window == frame.nsbutton) redrawNextWorkspaceButton();
998   else if (ee->window == frame.pwbutton) redrawPrevWindowButton();
999   else if (ee->window == frame.nwbutton) redrawNextWindowButton();
1000 }
1001
1002
1003 void Toolbar::keyPressEvent(XKeyEvent *ke) {
1004   if (ke->window == frame.workspace_label && editing) {
1005     openbox->grab();
1006
1007     if (! new_workspace_name) {
1008       new_workspace_name = new char[128];
1009       new_name_pos = 0;
1010
1011       if (! new_workspace_name) return;
1012     }
1013
1014     KeySym ks;
1015     char keychar[1];
1016     XLookupString(ke, keychar, 1, &ks, 0);
1017
1018     // either we are told to end with a return or we hit the end of the buffer
1019     if (ks == XK_Return || new_name_pos == 127) {
1020       *(new_workspace_name + new_name_pos) = 0;
1021
1022       editing = False;
1023
1024       openbox->setNoFocus(False);
1025       if (openbox->getFocusedWindow()) {
1026         openbox->getFocusedWindow()->setInputFocus();
1027         openbox->getFocusedWindow()->setFocusFlag(True);
1028       } else {
1029         XSetInputFocus(display, PointerRoot, None, CurrentTime);
1030       }
1031       // check to make sure that new_name[0] != 0... otherwise we have a null
1032       // workspace name which causes serious problems, especially for the
1033       // Openbox::LoadRC() method.
1034       if (*new_workspace_name) {
1035         screen->getCurrentWorkspace()->setName(new_workspace_name);
1036         screen->getCurrentWorkspace()->getMenu()->hide();
1037         screen->getWorkspacemenu()->
1038           remove(screen->getCurrentWorkspace()->getWorkspaceID() + 2);
1039         screen->getWorkspacemenu()->
1040           insert(screen->getCurrentWorkspace()->getName(),
1041                  screen->getCurrentWorkspace()->getMenu(),
1042                  screen->getCurrentWorkspace()->getWorkspaceID() + 2);
1043         screen->getWorkspacemenu()->update();
1044       }
1045
1046       delete [] new_workspace_name;
1047       new_workspace_name = (char *) 0;
1048       new_name_pos = 0;
1049
1050       // reset the background to that of the workspace label (its normal
1051       // setting)
1052       Pixmap tmp = frame.wlabel;
1053       BTexture *texture = &(screen->getToolbarStyle()->label);
1054       if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
1055         frame.wlabel = None;
1056         XSetWindowBackground(display, frame.workspace_label,
1057                             texture->getColor()->getPixel());
1058       } else {
1059         frame.wlabel =
1060           image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
1061         XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
1062       }
1063       if (tmp) image_ctrl->removeImage(tmp);
1064   
1065       reconfigure();
1066     } else if (! (ks == XK_Shift_L || ks == XK_Shift_R ||
1067                   ks == XK_Control_L || ks == XK_Control_R ||
1068                   ks == XK_Caps_Lock || ks == XK_Shift_Lock ||
1069                   ks == XK_Meta_L || ks == XK_Meta_R ||
1070                   ks == XK_Alt_L || ks == XK_Alt_R ||
1071                   ks == XK_Super_L || ks == XK_Super_R ||
1072                   ks == XK_Hyper_L || ks == XK_Hyper_R)) {
1073       if (ks == XK_BackSpace) {
1074         if (new_name_pos > 0) {
1075           --new_name_pos;
1076           *(new_workspace_name + new_name_pos) = '\0';
1077         } else {
1078           *new_workspace_name = '\0';
1079         }
1080       } else {
1081         *(new_workspace_name + new_name_pos) = *keychar;
1082         ++new_name_pos;
1083         *(new_workspace_name + new_name_pos) = '\0';
1084       }
1085
1086       XClearWindow(display, frame.workspace_label);
1087       int l = strlen(new_workspace_name), tw, x;
1088
1089       if (i18n->multibyte()) {
1090         XRectangle ink, logical;
1091         XmbTextExtents(screen->getToolbarStyle()->fontset,
1092                        new_workspace_name, l, &ink, &logical);
1093         tw = logical.width;
1094       } else {
1095         tw = XTextWidth(screen->getToolbarStyle()->font,
1096                         new_workspace_name, l);
1097       }
1098       x = (frame.workspace_label_w - tw) / 2;
1099
1100       if (x < (signed) frame.bevel_w) x = frame.bevel_w;
1101
1102       WindowStyle *style = screen->getWindowStyle();
1103       if (i18n->multibyte())
1104         XmbDrawString(display, frame.workspace_label, style->fontset,
1105                       style->l_text_focus_gc, x,
1106                       (1 - style->fontset_extents->max_ink_extent.y),
1107                       new_workspace_name, l);
1108       else
1109         XDrawString(display, frame.workspace_label, style->l_text_focus_gc, x,
1110                     (style->font->ascent + 1),
1111                     new_workspace_name, l);
1112       
1113       XDrawRectangle(display, frame.workspace_label,
1114                      screen->getWindowStyle()->l_text_focus_gc, x + tw, 0, 1,
1115                      frame.label_h - 1);
1116     }
1117     
1118     openbox->ungrab();
1119   }
1120 }
1121
1122
1123 void Toolbar::timeout(void) {
1124   checkClock(True);
1125
1126   timeval now;
1127   gettimeofday(&now, 0);
1128   clock_timer->setTimeout((60 - (now.tv_sec % 60)) * 1000);
1129 }
1130
1131
1132 void Toolbar::HideHandler::timeout(void) {
1133   toolbar->hidden = ! toolbar->hidden;
1134   if (toolbar->hidden)
1135     XMoveWindow(toolbar->display, toolbar->frame.window,
1136                 toolbar->frame.x_hidden, toolbar->frame.y_hidden);
1137   else
1138     XMoveWindow(toolbar->display, toolbar->frame.window,
1139                 toolbar->frame.x, toolbar->frame.y);
1140 }
1141
1142
1143 Toolbarmenu::Toolbarmenu(Toolbar &tb) : Basemenu(*tb.screen), toolbar(tb) {
1144   setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarTitle, "Toolbar"));
1145   setInternalMenu();
1146
1147   placementmenu = new Placementmenu(*this);
1148
1149   insert(i18n->getMessage(CommonSet, CommonPlacementTitle, "Placement"),
1150          placementmenu);
1151   insert(i18n->getMessage(CommonSet, CommonAlwaysOnTop, "Always on top"), 1);
1152   insert(i18n->getMessage(CommonSet, CommonAutoHide, "Auto hide"), 2);
1153   insert(i18n->getMessage(ToolbarSet, ToolbarEditWkspcName,
1154                           "Edit current workspace name"), 3);
1155
1156   update();
1157
1158   if (toolbar.isOnTop()) setItemSelected(1, True);
1159   if (toolbar.doAutoHide()) setItemSelected(2, True);
1160 }
1161
1162
1163 Toolbarmenu::~Toolbarmenu(void) {
1164   delete placementmenu;
1165 }
1166
1167
1168 void Toolbarmenu::itemSelected(int button, int index) {
1169   if (button != 1)
1170     return;
1171
1172   BasemenuItem *item = find(index);
1173   if (! item) return;
1174
1175   switch (item->function()) {
1176   case 1: { // always on top
1177     Bool change = ((toolbar.isOnTop()) ? False : True);
1178     toolbar.on_top = change;
1179     setItemSelected(1, change);
1180
1181     if (toolbar.isOnTop()) toolbar.screen->raiseWindows((Window *) 0, 0);
1182     break;
1183   }
1184
1185   case 2: { // auto hide
1186     Bool change = ((toolbar.doAutoHide()) ?  False : True);
1187     toolbar.do_auto_hide = change;
1188     setItemSelected(2, change);
1189
1190 #ifdef    SLIT
1191     toolbar.screen->getSlit()->reposition();
1192 #endif // SLIT
1193     break;
1194   }
1195
1196   case 3: { // edit current workspace name
1197     toolbar.edit();
1198     hide();
1199
1200     break;
1201   }
1202   } // switch
1203 }
1204
1205
1206 void Toolbarmenu::internal_hide(void) {
1207   Basemenu::internal_hide();
1208   if (toolbar.doAutoHide() && ! toolbar.isEditing())
1209     toolbar.hide_handler.timeout();
1210 }
1211
1212
1213 void Toolbarmenu::reconfigure(void) {
1214   placementmenu->reconfigure();
1215
1216   Basemenu::reconfigure();
1217 }
1218
1219
1220 Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu &tm)
1221   : Basemenu(*tm.toolbar.screen), toolbarmenu(tm) {
1222   setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarPlacement,
1223                             "Toolbar Placement"));
1224   setInternalMenu();
1225   setMinimumSublevels(3);
1226
1227   insert(i18n->getMessage(CommonSet, CommonPlacementTopLeft,
1228                           "Top Left"), Toolbar::TopLeft);
1229   insert(i18n->getMessage(CommonSet, CommonPlacementBottomLeft,
1230                           "Bottom Left"), Toolbar::BottomLeft);
1231   insert(i18n->getMessage(CommonSet, CommonPlacementTopCenter,
1232                           "Top Center"), Toolbar::TopCenter);
1233   insert(i18n->getMessage(CommonSet, CommonPlacementBottomCenter,
1234                           "Bottom Center"), Toolbar::BottomCenter);
1235   insert(i18n->getMessage(CommonSet, CommonPlacementTopRight,
1236                           "Top Right"), Toolbar::TopRight);
1237   insert(i18n->getMessage(CommonSet, CommonPlacementBottomRight,
1238                           "Bottom Right"), Toolbar::BottomRight);
1239   update();
1240 }
1241
1242
1243 void Toolbarmenu::Placementmenu::itemSelected(int button, int index) {
1244   if (button != 1)
1245     return;
1246
1247   BasemenuItem *item = find(index);
1248   if (! item) return;
1249
1250   toolbarmenu.toolbar.screen->saveToolbarPlacement(item->function());
1251   hide();
1252   toolbarmenu.toolbar.reconfigure();
1253
1254 #ifdef    SLIT
1255   // reposition the slit as well to make sure it doesn't intersect the
1256   // toolbar
1257   toolbarmenu.toolbar.screen->getSlit()->reposition();
1258 #endif // SLIT
1259 }