]> Dogcows Code - chaz/openbox/blob - src/Toolbar.cc
only add one extra space to pad the clock in the toolbar
[chaz/openbox] / 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] = '\0';
274
275 if (i18n->multibyte()) {
276 XRectangle ink, logical;
277 XmbTextExtents(screen->getToolbarStyle()->fontset, t, len, &ink,
278 &logical);
279 frame.clock_w = logical.width;
280
281 // ben's additional solution to pad some space beside the numbers
282 //frame.clock_w +=
283 // screen->getToolbarStyle()->fontset_extents->max_logical_extent.width *
284 // 4;
285
286 // brad's solution, which is currently buggy, too big
287 //frame.clock_w =
288 // screen->getToolbarStyle()->fontset_extents->max_logical_extent.width
289 // * len;
290 } else {
291 frame.clock_w = XTextWidth(screen->getToolbarStyle()->font, t, len);
292 // ben's additional solution to pad some space beside the numbers
293 //frame.clock_w += screen->getToolbarStyle()->font->max_bounds.width * 4;
294 // brad's solution again, too big
295 //frame.clock_w = screen->getToolbarStyle()->font->max_bounds.width * len;
296 }
297 frame.clock_w += (frame.bevel_w * 4);
298
299 delete [] time_string;
300 } else {
301 frame.clock_w = 0;
302 }
303 } else {
304 frame.clock_w = 0;
305 }
306 #else // !HAVE_STRFTIME
307 frame.clock_w =
308 XTextWidth(screen->getToolbarStyle()->font,
309 i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
310 "00:00000"),
311 strlen(i18n->getMessage(ToolbarSet, ToolbarNoStrftimeLength,
312 "00:00000"))) + (frame.bevel_w * 4);
313 #endif // HAVE_STRFTIME
314
315 int i;
316 unsigned int w = 0;
317 frame.workspace_label_w = 0;
318
319 for (i = 0; i < screen->getWorkspaceCount(); i++) {
320 if (i18n->multibyte()) {
321 XRectangle ink, logical;
322 XmbTextExtents(screen->getToolbarStyle()->fontset,
323 screen->getWorkspace(i)->getName(),
324 strlen(screen->getWorkspace(i)->getName()),
325 &ink, &logical);
326 w = logical.width;
327 } else {
328 w = XTextWidth(screen->getToolbarStyle()->font,
329 screen->getWorkspace(i)->getName(),
330 strlen(screen->getWorkspace(i)->getName()));
331 }
332 w += (frame.bevel_w * 4);
333
334 if (w > frame.workspace_label_w) frame.workspace_label_w = w;
335 }
336
337 if (frame.workspace_label_w < frame.clock_w)
338 frame.workspace_label_w = frame.clock_w;
339 else if (frame.workspace_label_w > frame.clock_w)
340 frame.clock_w = frame.workspace_label_w;
341
342 frame.window_label_w =
343 (frame.width - (frame.clock_w + (frame.button_w * 4) +
344 frame.workspace_label_w + (frame.bevel_w * 8) + 6));
345
346 if (hidden) {
347 XMoveResizeWindow(display, frame.window, frame.x_hidden, frame.y_hidden,
348 frame.width, frame.height);
349 } else {
350 XMoveResizeWindow(display, frame.window, frame.x, frame.y,
351 frame.width, frame.height);
352 }
353
354 XMoveResizeWindow(display, frame.workspace_label, frame.bevel_w,
355 frame.bevel_w, frame.workspace_label_w,
356 frame.label_h);
357 XMoveResizeWindow(display, frame.psbutton, (frame.bevel_w * 2) +
358 frame.workspace_label_w + 1, frame.bevel_w + 1,
359 frame.button_w, frame.button_w);
360 XMoveResizeWindow(display ,frame.nsbutton, (frame.bevel_w * 3) +
361 frame.workspace_label_w + frame.button_w + 2,
362 frame.bevel_w + 1, frame.button_w, frame.button_w);
363 XMoveResizeWindow(display, frame.window_label, (frame.bevel_w * 4) +
364 (frame.button_w * 2) + frame.workspace_label_w + 3,
365 frame.bevel_w, frame.window_label_w, frame.label_h);
366 XMoveResizeWindow(display, frame.pwbutton, (frame.bevel_w * 5) +
367 (frame.button_w * 2) + frame.workspace_label_w +
368 frame.window_label_w + 4, frame.bevel_w + 1,
369 frame.button_w, frame.button_w);
370 XMoveResizeWindow(display, frame.nwbutton, (frame.bevel_w * 6) +
371 (frame.button_w * 3) + frame.workspace_label_w +
372 frame.window_label_w + 5, frame.bevel_w + 1,
373 frame.button_w, frame.button_w);
374 XMoveResizeWindow(display, frame.clock, frame.width - frame.clock_w -
375 frame.bevel_w, frame.bevel_w, frame.clock_w,
376 frame.label_h);
377
378 Pixmap tmp = frame.base;
379 BTexture *texture = &(screen->getToolbarStyle()->toolbar);
380 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
381 frame.base = None;
382 XSetWindowBackground(display, frame.window,
383 texture->getColor()->getPixel());
384 } else {
385 frame.base =
386 image_ctrl->renderImage(frame.width, frame.height, texture);
387 XSetWindowBackgroundPixmap(display, frame.window, frame.base);
388 }
389 if (tmp) image_ctrl->removeImage(tmp);
390
391 tmp = frame.label;
392 texture = &(screen->getToolbarStyle()->window);
393 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
394 frame.label = None;
395 XSetWindowBackground(display, frame.window_label,
396 texture->getColor()->getPixel());
397 } else {
398 frame.label =
399 image_ctrl->renderImage(frame.window_label_w, frame.label_h, texture);
400 XSetWindowBackgroundPixmap(display, frame.window_label, frame.label);
401 }
402 if (tmp) image_ctrl->removeImage(tmp);
403
404 tmp = frame.wlabel;
405 texture = &(screen->getToolbarStyle()->label);
406 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
407 frame.wlabel = None;
408 XSetWindowBackground(display, frame.workspace_label,
409 texture->getColor()->getPixel());
410 } else {
411 frame.wlabel =
412 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
413 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
414 }
415 if (tmp) image_ctrl->removeImage(tmp);
416
417 tmp = frame.clk;
418 texture = &(screen->getToolbarStyle()->clock);
419 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
420 frame.clk = None;
421 XSetWindowBackground(display, frame.clock,
422 texture->getColor()->getPixel());
423 } else {
424 frame.clk =
425 image_ctrl->renderImage(frame.clock_w, frame.label_h, texture);
426 XSetWindowBackgroundPixmap(display, frame.clock, frame.clk);
427 }
428 if (tmp) image_ctrl->removeImage(tmp);
429
430 tmp = frame.button;
431 texture = &(screen->getToolbarStyle()->button);
432 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
433 frame.button = None;
434
435 frame.button_pixel = texture->getColor()->getPixel();
436 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
437 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
438 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
439 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
440 } else {
441 frame.button =
442 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
443
444 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
445 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
446 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
447 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
448 }
449 if (tmp) image_ctrl->removeImage(tmp);
450
451 tmp = frame.pbutton;
452 texture = &(screen->getToolbarStyle()->pressed);
453 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
454 frame.pbutton = None;
455 frame.pbutton_pixel = texture->getColor()->getPixel();
456 } else {
457 frame.pbutton =
458 image_ctrl->renderImage(frame.button_w, frame.button_w, texture);
459 }
460 if (tmp) image_ctrl->removeImage(tmp);
461
462 XSetWindowBorder(display, frame.window,
463 screen->getBorderColor()->getPixel());
464 XSetWindowBorderWidth(display, frame.window, screen->getBorderWidth());
465
466 XClearWindow(display, frame.window);
467 XClearWindow(display, frame.workspace_label);
468 XClearWindow(display, frame.window_label);
469 XClearWindow(display, frame.clock);
470 XClearWindow(display, frame.psbutton);
471 XClearWindow(display, frame.nsbutton);
472 XClearWindow(display, frame.pwbutton);
473 XClearWindow(display, frame.nwbutton);
474
475 redrawWindowLabel();
476 redrawWorkspaceLabel();
477 redrawPrevWorkspaceButton();
478 redrawNextWorkspaceButton();
479 redrawPrevWindowButton();
480 redrawNextWindowButton();
481 checkClock(True);
482
483 toolbarmenu->reconfigure();
484 }
485
486
487 #ifdef HAVE_STRFTIME
488 void Toolbar::checkClock(Bool redraw) {
489 #else // !HAVE_STRFTIME
490 void Toolbar::checkClock(Bool redraw, Bool date) {
491 #endif // HAVE_STRFTIME
492 time_t tmp = 0;
493 struct tm *tt = 0;
494
495 if ((tmp = time(NULL)) != -1) {
496 if (! (tt = localtime(&tmp))) return;
497 if (tt->tm_min != frame.minute || tt->tm_hour != frame.hour) {
498 frame.hour = tt->tm_hour;
499 frame.minute = tt->tm_min;
500 XClearWindow(display, frame.clock);
501 redraw = True;
502 }
503 }
504
505 if (redraw) {
506 #ifdef HAVE_STRFTIME
507 char t[1024];
508 if (! strftime(t, 1024, screen->getStrftimeFormat(), tt))
509 return;
510 #else // !HAVE_STRFTIME
511 char t[9];
512 if (date) {
513 // format the date... with special consideration for y2k ;)
514 if (screen->getDateFormat() == Openbox::B_EuropeanDate)
515 sprintf(t, 18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormatEu,
516 "%02d.%02d.%02d"),
517 tt->tm_mday, tt->tm_mon + 1,
518 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
519 else
520 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeDateFormat,
521 "%02d/%02d/%02d"),
522 tt->tm_mon + 1, tt->tm_mday,
523 (tt->tm_year >= 100) ? tt->tm_year - 100 : tt->tm_year);
524 } else {
525 if (screen->isClock24Hour())
526 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat24,
527 " %02d:%02d "),
528 frame.hour, frame.minute);
529 else
530 sprintf(t, i18n->getMessage(ToolbarSet, ToolbarNoStrftimeTimeFormat12,
531 "%02d:%02d %sm"),
532 ((frame.hour > 12) ? frame.hour - 12 :
533 ((frame.hour == 0) ? 12 : frame.hour)), frame.minute,
534 ((frame.hour >= 12) ?
535 i18n->getMessage(ToolbarSet,
536 ToolbarNoStrftimeTimeFormatP, "p") :
537 i18n->getMessage(ToolbarSet,
538 ToolbarNoStrftimeTimeFormatA, "a")));
539 }
540 #endif // HAVE_STRFTIME
541
542 int dx = (frame.bevel_w * 2), dlen = strlen(t);
543 unsigned int l;
544
545 if (i18n->multibyte()) {
546 XRectangle ink, logical;
547 XmbTextExtents(screen->getToolbarStyle()->fontset,
548 t, dlen, &ink, &logical);
549 l = logical.width;
550 } else {
551 l = XTextWidth(screen->getToolbarStyle()->font, t, dlen);
552 }
553
554 l += (frame.bevel_w * 4);
555
556 if (l > frame.clock_w) {
557 for (; dlen >= 0; dlen--) {
558 if (i18n->multibyte()) {
559 XRectangle ink, logical;
560 XmbTextExtents(screen->getToolbarStyle()->fontset,
561 t, dlen, &ink, &logical);
562 l = logical.width;
563 } else {
564 l = XTextWidth(screen->getToolbarStyle()->font, t, dlen);
565 }
566 l+= (frame.bevel_w * 4);
567
568 if (l < frame.clock_w)
569 break;
570 }
571 }
572 switch (screen->getToolbarStyle()->justify) {
573 case BScreen::RightJustify:
574 dx += frame.clock_w - l;
575 break;
576
577 case BScreen::CenterJustify:
578 dx += (frame.clock_w - l) / 2;
579 break;
580 }
581
582 ToolbarStyle *style = screen->getToolbarStyle();
583 if (i18n->multibyte())
584 XmbDrawString(display, frame.clock, style->fontset, style->c_text_gc,
585 dx, (1 - style->fontset_extents->max_ink_extent.y),
586 t, dlen);
587 else
588 XDrawString(display, frame.clock, style->c_text_gc, dx,
589 (style->font->ascent + 1), t, dlen);
590 }
591 }
592
593
594 void Toolbar::redrawWindowLabel(Bool redraw) {
595 if (screen->getOpenbox()->getFocusedWindow()) {
596 if (redraw)
597 XClearWindow(display, frame.window_label);
598
599 OpenboxWindow *foc = screen->getOpenbox()->getFocusedWindow();
600 if (foc->getScreen() != screen) return;
601
602 int dx = (frame.bevel_w * 2), dlen = strlen(*foc->getTitle());
603 unsigned int l;
604
605 if (i18n->multibyte()) {
606 XRectangle ink, logical;
607 XmbTextExtents(screen->getToolbarStyle()->fontset, *foc->getTitle(),
608 dlen, &ink, &logical);
609 l = logical.width;
610 } else {
611 l = XTextWidth(screen->getToolbarStyle()->font, *foc->getTitle(), dlen);
612 }
613 l += (frame.bevel_w * 4);
614
615 if (l > frame.window_label_w) {
616 for (; dlen >= 0; dlen--) {
617 if (i18n->multibyte()) {
618 XRectangle ink, logical;
619 XmbTextExtents(screen->getToolbarStyle()->fontset,
620 *foc->getTitle(), dlen, &ink, &logical);
621 l = logical.width;
622 } else {
623 l = XTextWidth(screen->getToolbarStyle()->font,
624 *foc->getTitle(), dlen);
625 }
626 l += (frame.bevel_w * 4);
627
628 if (l < frame.window_label_w)
629 break;
630 }
631 }
632 switch (screen->getToolbarStyle()->justify) {
633 case BScreen::RightJustify:
634 dx += frame.window_label_w - l;
635 break;
636
637 case BScreen::CenterJustify:
638 dx += (frame.window_label_w - l) / 2;
639 break;
640 }
641
642 ToolbarStyle *style = screen->getToolbarStyle();
643 if (i18n->multibyte())
644 XmbDrawString(display, frame.window_label, style->fontset,
645 style->w_text_gc, dx,
646 (1 - style->fontset_extents->max_ink_extent.y),
647 *foc->getTitle(), dlen);
648 else
649 XDrawString(display, frame.window_label, style->w_text_gc, dx,
650 (style->font->ascent + 1), *foc->getTitle(), dlen);
651 } else {
652 XClearWindow(display, frame.window_label);
653 }
654 }
655
656
657 void Toolbar::redrawWorkspaceLabel(Bool redraw) {
658 if (screen->getCurrentWorkspace()->getName()) {
659 if (redraw)
660 XClearWindow(display, frame.workspace_label);
661
662 int dx = (frame.bevel_w * 2), dlen =
663 strlen(screen->getCurrentWorkspace()->getName());
664 unsigned int l;
665
666 if (i18n->multibyte()) {
667 XRectangle ink, logical;
668 XmbTextExtents(screen->getToolbarStyle()->fontset,
669 screen->getCurrentWorkspace()->getName(), dlen,
670 &ink, &logical);
671 l = logical.width;
672 } else {
673 l = XTextWidth(screen->getToolbarStyle()->font,
674 screen->getCurrentWorkspace()->getName(), dlen);
675 }
676 l += (frame.bevel_w * 4);
677
678 if (l > frame.workspace_label_w) {
679 for (; dlen >= 0; dlen--) {
680 if (i18n->multibyte()) {
681 XRectangle ink, logical;
682 XmbTextExtents(screen->getToolbarStyle()->fontset,
683 screen->getCurrentWorkspace()->getName(), dlen,
684 &ink, &logical);
685 l = logical.width;
686 } else {
687 l = XTextWidth(screen->getWindowStyle()->font,
688 screen->getCurrentWorkspace()->getName(), dlen);
689 }
690 l += (frame.bevel_w * 4);
691
692 if (l < frame.workspace_label_w)
693 break;
694 }
695 }
696 switch (screen->getToolbarStyle()->justify) {
697 case BScreen::RightJustify:
698 dx += frame.workspace_label_w - l;
699 break;
700
701 case BScreen::CenterJustify:
702 dx += (frame.workspace_label_w - l) / 2;
703 break;
704 }
705
706 ToolbarStyle *style = screen->getToolbarStyle();
707 if (i18n->multibyte())
708 XmbDrawString(display, frame.workspace_label, style->fontset,
709 style->l_text_gc, dx,
710 (1 - style->fontset_extents->max_ink_extent.y),
711 (char *) screen->getCurrentWorkspace()->getName(), dlen);
712 else
713 XDrawString(display, frame.workspace_label, style->l_text_gc, dx,
714 (style->font->ascent + 1),
715 (char *) screen->getCurrentWorkspace()->getName(), dlen);
716 }
717 }
718
719
720 void Toolbar::redrawPrevWorkspaceButton(Bool pressed, Bool redraw) {
721 if (redraw) {
722 if (pressed) {
723 if (frame.pbutton)
724 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.pbutton);
725 else
726 XSetWindowBackground(display, frame.psbutton, frame.pbutton_pixel);
727 } else {
728 if (frame.button)
729 XSetWindowBackgroundPixmap(display, frame.psbutton, frame.button);
730 else
731 XSetWindowBackground(display, frame.psbutton, frame.button_pixel);
732 }
733 XClearWindow(display, frame.psbutton);
734 }
735
736 int hh = frame.button_w / 2, hw = frame.button_w / 2;
737
738 XPoint pts[3];
739 pts[0].x = hw - 2; pts[0].y = hh;
740 pts[1].x = 4; pts[1].y = 2;
741 pts[2].x = 0; pts[2].y = -4;
742
743 XFillPolygon(display, frame.psbutton, screen->getToolbarStyle()->b_pic_gc,
744 pts, 3, Convex, CoordModePrevious);
745 }
746
747
748 void Toolbar::redrawNextWorkspaceButton(Bool pressed, Bool redraw) {
749 if (redraw) {
750 if (pressed) {
751 if (frame.pbutton)
752 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.pbutton);
753 else
754 XSetWindowBackground(display, frame.nsbutton, frame.pbutton_pixel);
755 } else {
756 if (frame.button)
757 XSetWindowBackgroundPixmap(display, frame.nsbutton, frame.button);
758 else
759 XSetWindowBackground(display, frame.nsbutton, frame.button_pixel);
760 }
761 XClearWindow(display, frame.nsbutton);
762 }
763
764 int hh = frame.button_w / 2, hw = frame.button_w / 2;
765
766 XPoint pts[3];
767 pts[0].x = hw - 2; pts[0].y = hh - 2;
768 pts[1].x = 4; pts[1].y = 2;
769 pts[2].x = -4; pts[2].y = 2;
770
771 XFillPolygon(display, frame.nsbutton, screen->getToolbarStyle()->b_pic_gc,
772 pts, 3, Convex, CoordModePrevious);
773 }
774
775
776 void Toolbar::redrawPrevWindowButton(Bool pressed, Bool redraw) {
777 if (redraw) {
778 if (pressed) {
779 if (frame.pbutton)
780 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.pbutton);
781 else
782 XSetWindowBackground(display, frame.pwbutton, frame.pbutton_pixel);
783 } else {
784 if (frame.button)
785 XSetWindowBackgroundPixmap(display, frame.pwbutton, frame.button);
786 else
787 XSetWindowBackground(display, frame.pwbutton, frame.button_pixel);
788 }
789 XClearWindow(display, frame.pwbutton);
790 }
791
792 int hh = frame.button_w / 2, hw = frame.button_w / 2;
793
794 XPoint pts[3];
795 pts[0].x = hw - 2; pts[0].y = hh;
796 pts[1].x = 4; pts[1].y = 2;
797 pts[2].x = 0; pts[2].y = -4;
798
799 XFillPolygon(display, frame.pwbutton, screen->getToolbarStyle()->b_pic_gc,
800 pts, 3, Convex, CoordModePrevious);
801 }
802
803
804 void Toolbar::redrawNextWindowButton(Bool pressed, Bool redraw) {
805 if (redraw) {
806 if (pressed) {
807 if (frame.pbutton)
808 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.pbutton);
809 else
810 XSetWindowBackground(display, frame.nwbutton, frame.pbutton_pixel);
811 } else {
812 if (frame.button)
813 XSetWindowBackgroundPixmap(display, frame.nwbutton, frame.button);
814 else
815 XSetWindowBackground(display, frame.nwbutton, frame.button_pixel);
816 }
817 XClearWindow(display, frame.nwbutton);
818 }
819
820 int hh = frame.button_w / 2, hw = frame.button_w / 2;
821
822 XPoint pts[3];
823 pts[0].x = hw - 2; pts[0].y = hh - 2;
824 pts[1].x = 4; pts[1].y = 2;
825 pts[2].x = -4; pts[2].y = 2;
826
827 XFillPolygon(display, frame.nwbutton, screen->getToolbarStyle()->b_pic_gc,
828 pts, 3, Convex, CoordModePrevious);
829 }
830
831
832 void Toolbar::edit(void) {
833 Window window;
834 int foo;
835
836 editing = True;
837 if (XGetInputFocus(display, &window, &foo) &&
838 window == frame.workspace_label)
839 return;
840
841 XSetInputFocus(display, frame.workspace_label,
842 ((screen->isSloppyFocus()) ? RevertToPointerRoot :
843 RevertToParent),
844 CurrentTime);
845 XClearWindow(display, frame.workspace_label);
846
847 openbox->setNoFocus(True);
848 if (openbox->getFocusedWindow())
849 openbox->getFocusedWindow()->setFocusFlag(False);
850
851 XDrawRectangle(display, frame.workspace_label,
852 screen->getWindowStyle()->l_text_focus_gc,
853 frame.workspace_label_w / 2, 0, 1,
854 frame.label_h - 1);
855
856 // change the background of the window to that of an active window label
857 Pixmap tmp = frame.wlabel;
858 BTexture *texture = &(screen->getWindowStyle()->l_focus);
859 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
860 frame.wlabel = None;
861 XSetWindowBackground(display, frame.workspace_label,
862 texture->getColor()->getPixel());
863 } else {
864 frame.wlabel =
865 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
866 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
867 }
868 if (tmp) image_ctrl->removeImage(tmp);
869 }
870
871
872 void Toolbar::buttonPressEvent(XButtonEvent *be) {
873 if (be->button == 1) {
874 if (be->window == frame.psbutton)
875 redrawPrevWorkspaceButton(True, True);
876 else if (be->window == frame.nsbutton)
877 redrawNextWorkspaceButton(True, True);
878 else if (be->window == frame.pwbutton)
879 redrawPrevWindowButton(True, True);
880 else if (be->window == frame.nwbutton)
881 redrawNextWindowButton(True, True);
882 #ifndef HAVE_STRFTIME
883 else if (be->window == frame.clock) {
884 XClearWindow(display, frame.clock);
885 checkClock(True, True);
886 }
887 #endif // HAVE_STRFTIME
888 else if (! on_top) {
889 Window w[1] = { frame.window };
890 screen->raiseWindows(w, 1);
891 }
892 } else if (be->button == 2 && (! on_top)) {
893 XLowerWindow(display, frame.window);
894 } else if (be->button == 3) {
895 if (! toolbarmenu->isVisible()) {
896 int x, y;
897
898 x = be->x_root - (toolbarmenu->getWidth() / 2);
899 y = be->y_root - (toolbarmenu->getHeight() / 2);
900
901 if (x < 0)
902 x = 0;
903 else if (x + toolbarmenu->getWidth() > screen->getWidth())
904 x = screen->getWidth() - toolbarmenu->getWidth();
905
906 if (y < 0)
907 y = 0;
908 else if (y + toolbarmenu->getHeight() > screen->getHeight())
909 y = screen->getHeight() - toolbarmenu->getHeight();
910
911 toolbarmenu->move(x, y);
912 toolbarmenu->show();
913 } else
914 toolbarmenu->hide();
915 }
916 }
917
918
919
920 void Toolbar::buttonReleaseEvent(XButtonEvent *re) {
921 if (re->button == 1) {
922 if (re->window == frame.psbutton) {
923 redrawPrevWorkspaceButton(False, True);
924
925 if (re->x >= 0 && re->x < (signed) frame.button_w &&
926 re->y >= 0 && re->y < (signed) frame.button_w)
927 if (screen->getCurrentWorkspace()->getWorkspaceID() > 0)
928 screen->changeWorkspaceID(screen->getCurrentWorkspace()->
929 getWorkspaceID() - 1);
930 else
931 screen->changeWorkspaceID(screen->getWorkspaceCount() - 1);
932 } else if (re->window == frame.nsbutton) {
933 redrawNextWorkspaceButton(False, True);
934
935 if (re->x >= 0 && re->x < (signed) frame.button_w &&
936 re->y >= 0 && re->y < (signed) frame.button_w)
937 if (screen->getCurrentWorkspace()->getWorkspaceID() <
938 screen->getWorkspaceCount() - 1)
939 screen->changeWorkspaceID(screen->getCurrentWorkspace()->
940 getWorkspaceID() + 1);
941 else
942 screen->changeWorkspaceID(0);
943 } else if (re->window == frame.pwbutton) {
944 redrawPrevWindowButton(False, True);
945
946 if (re->x >= 0 && re->x < (signed) frame.button_w &&
947 re->y >= 0 && re->y < (signed) frame.button_w)
948 screen->prevFocus();
949 } else if (re->window == frame.nwbutton) {
950 redrawNextWindowButton(False, True);
951
952 if (re->x >= 0 && re->x < (signed) frame.button_w &&
953 re->y >= 0 && re->y < (signed) frame.button_w)
954 screen->nextFocus();
955 } else if (re->window == frame.window_label)
956 screen->raiseFocus();
957 #ifndef HAVE_STRFTIME
958 else if (re->window == frame.clock) {
959 XClearWindow(display, frame.clock);
960 checkClock(True);
961 }
962 #endif // HAVE_STRFTIME
963 }
964 }
965
966
967 void Toolbar::enterNotifyEvent(XCrossingEvent *) {
968 if (! do_auto_hide)
969 return;
970
971 if (hidden) {
972 if (! hide_timer->isTiming()) hide_timer->start();
973 } else {
974 if (hide_timer->isTiming()) hide_timer->stop();
975 }
976 }
977
978 void Toolbar::leaveNotifyEvent(XCrossingEvent *) {
979 if (! do_auto_hide)
980 return;
981
982 if (hidden) {
983 if (hide_timer->isTiming()) hide_timer->stop();
984 } else if (! toolbarmenu->isVisible()) {
985 if (! hide_timer->isTiming()) hide_timer->start();
986 }
987 }
988
989
990 void Toolbar::exposeEvent(XExposeEvent *ee) {
991 if (ee->window == frame.clock) checkClock(True);
992 else if (ee->window == frame.workspace_label && (! editing))
993 redrawWorkspaceLabel();
994 else if (ee->window == frame.window_label) redrawWindowLabel();
995 else if (ee->window == frame.psbutton) redrawPrevWorkspaceButton();
996 else if (ee->window == frame.nsbutton) redrawNextWorkspaceButton();
997 else if (ee->window == frame.pwbutton) redrawPrevWindowButton();
998 else if (ee->window == frame.nwbutton) redrawNextWindowButton();
999 }
1000
1001
1002 void Toolbar::keyPressEvent(XKeyEvent *ke) {
1003 if (ke->window == frame.workspace_label && editing) {
1004 openbox->grab();
1005
1006 if (! new_workspace_name) {
1007 new_workspace_name = new char[128];
1008 new_name_pos = 0;
1009
1010 if (! new_workspace_name) return;
1011 }
1012
1013 KeySym ks;
1014 char keychar[1];
1015 XLookupString(ke, keychar, 1, &ks, 0);
1016
1017 // either we are told to end with a return or we hit the end of the buffer
1018 if (ks == XK_Return || new_name_pos == 127) {
1019 *(new_workspace_name + new_name_pos) = 0;
1020
1021 editing = False;
1022
1023 openbox->setNoFocus(False);
1024 if (openbox->getFocusedWindow()) {
1025 openbox->getFocusedWindow()->setInputFocus();
1026 openbox->getFocusedWindow()->setFocusFlag(True);
1027 } else {
1028 XSetInputFocus(display, PointerRoot, None, CurrentTime);
1029 }
1030 // check to make sure that new_name[0] != 0... otherwise we have a null
1031 // workspace name which causes serious problems, especially for the
1032 // Openbox::LoadRC() method.
1033 if (*new_workspace_name) {
1034 screen->getCurrentWorkspace()->setName(new_workspace_name);
1035 screen->getCurrentWorkspace()->getMenu()->hide();
1036 screen->getWorkspacemenu()->
1037 remove(screen->getCurrentWorkspace()->getWorkspaceID() + 2);
1038 screen->getWorkspacemenu()->
1039 insert(screen->getCurrentWorkspace()->getName(),
1040 screen->getCurrentWorkspace()->getMenu(),
1041 screen->getCurrentWorkspace()->getWorkspaceID() + 2);
1042 screen->getWorkspacemenu()->update();
1043 }
1044
1045 delete [] new_workspace_name;
1046 new_workspace_name = (char *) 0;
1047 new_name_pos = 0;
1048
1049 // reset the background to that of the workspace label (its normal
1050 // setting)
1051 Pixmap tmp = frame.wlabel;
1052 BTexture *texture = &(screen->getToolbarStyle()->label);
1053 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
1054 frame.wlabel = None;
1055 XSetWindowBackground(display, frame.workspace_label,
1056 texture->getColor()->getPixel());
1057 } else {
1058 frame.wlabel =
1059 image_ctrl->renderImage(frame.workspace_label_w, frame.label_h, texture);
1060 XSetWindowBackgroundPixmap(display, frame.workspace_label, frame.wlabel);
1061 }
1062 if (tmp) image_ctrl->removeImage(tmp);
1063
1064 reconfigure();
1065 } else if (! (ks == XK_Shift_L || ks == XK_Shift_R ||
1066 ks == XK_Control_L || ks == XK_Control_R ||
1067 ks == XK_Caps_Lock || ks == XK_Shift_Lock ||
1068 ks == XK_Meta_L || ks == XK_Meta_R ||
1069 ks == XK_Alt_L || ks == XK_Alt_R ||
1070 ks == XK_Super_L || ks == XK_Super_R ||
1071 ks == XK_Hyper_L || ks == XK_Hyper_R)) {
1072 if (ks == XK_BackSpace) {
1073 if (new_name_pos > 0) {
1074 --new_name_pos;
1075 *(new_workspace_name + new_name_pos) = '\0';
1076 } else {
1077 *new_workspace_name = '\0';
1078 }
1079 } else {
1080 *(new_workspace_name + new_name_pos) = *keychar;
1081 ++new_name_pos;
1082 *(new_workspace_name + new_name_pos) = '\0';
1083 }
1084
1085 XClearWindow(display, frame.workspace_label);
1086 int l = strlen(new_workspace_name), tw, x;
1087
1088 if (i18n->multibyte()) {
1089 XRectangle ink, logical;
1090 XmbTextExtents(screen->getToolbarStyle()->fontset,
1091 new_workspace_name, l, &ink, &logical);
1092 tw = logical.width;
1093 } else {
1094 tw = XTextWidth(screen->getToolbarStyle()->font,
1095 new_workspace_name, l);
1096 }
1097 x = (frame.workspace_label_w - tw) / 2;
1098
1099 if (x < (signed) frame.bevel_w) x = frame.bevel_w;
1100
1101 WindowStyle *style = screen->getWindowStyle();
1102 if (i18n->multibyte())
1103 XmbDrawString(display, frame.workspace_label, style->fontset,
1104 style->l_text_focus_gc, x,
1105 (1 - style->fontset_extents->max_ink_extent.y),
1106 new_workspace_name, l);
1107 else
1108 XDrawString(display, frame.workspace_label, style->l_text_focus_gc, x,
1109 (style->font->ascent + 1),
1110 new_workspace_name, l);
1111
1112 XDrawRectangle(display, frame.workspace_label,
1113 screen->getWindowStyle()->l_text_focus_gc, x + tw, 0, 1,
1114 frame.label_h - 1);
1115 }
1116
1117 openbox->ungrab();
1118 }
1119 }
1120
1121
1122 void Toolbar::timeout(void) {
1123 checkClock(True);
1124
1125 timeval now;
1126 gettimeofday(&now, 0);
1127 clock_timer->setTimeout((60 - (now.tv_sec % 60)) * 1000);
1128 }
1129
1130
1131 void Toolbar::HideHandler::timeout(void) {
1132 toolbar->hidden = ! toolbar->hidden;
1133 if (toolbar->hidden)
1134 XMoveWindow(toolbar->display, toolbar->frame.window,
1135 toolbar->frame.x_hidden, toolbar->frame.y_hidden);
1136 else
1137 XMoveWindow(toolbar->display, toolbar->frame.window,
1138 toolbar->frame.x, toolbar->frame.y);
1139 }
1140
1141
1142 Toolbarmenu::Toolbarmenu(Toolbar &tb) : Basemenu(*tb.screen), toolbar(tb) {
1143 setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarTitle, "Toolbar"));
1144 setInternalMenu();
1145
1146 placementmenu = new Placementmenu(*this);
1147
1148 insert(i18n->getMessage(CommonSet, CommonPlacementTitle, "Placement"),
1149 placementmenu);
1150 insert(i18n->getMessage(CommonSet, CommonAlwaysOnTop, "Always on top"), 1);
1151 insert(i18n->getMessage(CommonSet, CommonAutoHide, "Auto hide"), 2);
1152 insert(i18n->getMessage(ToolbarSet, ToolbarEditWkspcName,
1153 "Edit current workspace name"), 3);
1154
1155 update();
1156
1157 if (toolbar.isOnTop()) setItemSelected(1, True);
1158 if (toolbar.doAutoHide()) setItemSelected(2, True);
1159 }
1160
1161
1162 Toolbarmenu::~Toolbarmenu(void) {
1163 delete placementmenu;
1164 }
1165
1166
1167 void Toolbarmenu::itemSelected(int button, int index) {
1168 if (button != 1)
1169 return;
1170
1171 BasemenuItem *item = find(index);
1172 if (! item) return;
1173
1174 switch (item->function()) {
1175 case 1: { // always on top
1176 Bool change = ((toolbar.isOnTop()) ? False : True);
1177 toolbar.on_top = change;
1178 setItemSelected(1, change);
1179
1180 if (toolbar.isOnTop()) toolbar.screen->raiseWindows((Window *) 0, 0);
1181 break;
1182 }
1183
1184 case 2: { // auto hide
1185 Bool change = ((toolbar.doAutoHide()) ? False : True);
1186 toolbar.do_auto_hide = change;
1187 setItemSelected(2, change);
1188
1189 #ifdef SLIT
1190 toolbar.screen->getSlit()->reposition();
1191 #endif // SLIT
1192 break;
1193 }
1194
1195 case 3: { // edit current workspace name
1196 toolbar.edit();
1197 hide();
1198
1199 break;
1200 }
1201 } // switch
1202 }
1203
1204
1205 void Toolbarmenu::internal_hide(void) {
1206 Basemenu::internal_hide();
1207 if (toolbar.doAutoHide() && ! toolbar.isEditing())
1208 toolbar.hide_handler.timeout();
1209 }
1210
1211
1212 void Toolbarmenu::reconfigure(void) {
1213 placementmenu->reconfigure();
1214
1215 Basemenu::reconfigure();
1216 }
1217
1218
1219 Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu &tm)
1220 : Basemenu(*tm.toolbar.screen), toolbarmenu(tm) {
1221 setLabel(i18n->getMessage(ToolbarSet, ToolbarToolbarPlacement,
1222 "Toolbar Placement"));
1223 setInternalMenu();
1224 setMinimumSublevels(3);
1225
1226 insert(i18n->getMessage(CommonSet, CommonPlacementTopLeft,
1227 "Top Left"), Toolbar::TopLeft);
1228 insert(i18n->getMessage(CommonSet, CommonPlacementBottomLeft,
1229 "Bottom Left"), Toolbar::BottomLeft);
1230 insert(i18n->getMessage(CommonSet, CommonPlacementTopCenter,
1231 "Top Center"), Toolbar::TopCenter);
1232 insert(i18n->getMessage(CommonSet, CommonPlacementBottomCenter,
1233 "Bottom Center"), Toolbar::BottomCenter);
1234 insert(i18n->getMessage(CommonSet, CommonPlacementTopRight,
1235 "Top Right"), Toolbar::TopRight);
1236 insert(i18n->getMessage(CommonSet, CommonPlacementBottomRight,
1237 "Bottom Right"), Toolbar::BottomRight);
1238 update();
1239 }
1240
1241
1242 void Toolbarmenu::Placementmenu::itemSelected(int button, int index) {
1243 if (button != 1)
1244 return;
1245
1246 BasemenuItem *item = find(index);
1247 if (! item) return;
1248
1249 toolbarmenu.toolbar.screen->saveToolbarPlacement(item->function());
1250 hide();
1251 toolbarmenu.toolbar.reconfigure();
1252
1253 #ifdef SLIT
1254 // reposition the slit as well to make sure it doesn't intersect the
1255 // toolbar
1256 toolbarmenu.toolbar.screen->getSlit()->reposition();
1257 #endif // SLIT
1258 }
This page took 0.137606 seconds and 5 git commands to generate.