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