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