1 // Basemenu.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
35 #endif // HAVE_STDIO_H
39 #endif // HAVE_STDLIB_H
43 #endif // HAVE_STRING_H
53 static Basemenu *shown = (Basemenu *) 0;
55 Basemenu::Basemenu(BScreen &scrn) : openbox(scrn.getOpenbox()), screen(scrn) {
56 image_ctrl = screen.getImageControl();
57 display = openbox.getXDisplay();
58 parent = (Basemenu *) 0;
59 alignment = AlignDontCare;
85 menu.sel_pixmap = None;
87 menu.bevel_w = screen.getBevelWidth();
89 if (i18n->multibyte())
90 menu.width = menu.title_h = menu.item_w = menu.frame_h =
91 screen.getMenuStyle()->t_fontset_extents->max_ink_extent.height +
94 menu.width = menu.title_h = menu.item_w = menu.frame_h =
95 screen.getMenuStyle()->t_font->ascent +
96 screen.getMenuStyle()->t_font->descent + (menu.bevel_w * 2);
104 MenuStyle *style = screen.getMenuStyle();
105 if (i18n->multibyte()) {
106 menu.item_h = style->f_fontset_extents->max_ink_extent.height +
109 menu.item_h = style->f_font->ascent + style->f_font->descent +
113 menu.height = menu.title_h + screen.getBorderWidth() + menu.frame_h;
115 unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
116 CWColormap | CWOverrideRedirect | CWEventMask;
117 XSetWindowAttributes attrib;
118 attrib.background_pixmap = None;
119 attrib.background_pixel = attrib.border_pixel =
120 screen.getBorderColor()->getPixel();
121 attrib.colormap = screen.getColormap();
122 attrib.override_redirect = True;
123 attrib.event_mask = ButtonPressMask | ButtonReleaseMask |
124 ButtonMotionMask | ExposureMask;
127 XCreateWindow(display, screen.getRootWindow(), menu.x, menu.y, menu.width,
128 menu.height, screen.getBorderWidth(), screen.getDepth(),
129 InputOutput, screen.getVisual(), attrib_mask, &attrib);
130 openbox.saveMenuSearch(menu.window, this);
132 attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | CWEventMask;
133 attrib.background_pixel = screen.getBorderColor()->getPixel();
134 attrib.event_mask |= EnterWindowMask | LeaveWindowMask;
137 XCreateWindow(display, menu.window, 0, 0, menu.width, menu.height, 0,
138 screen.getDepth(), InputOutput, screen.getVisual(),
139 attrib_mask, &attrib);
140 openbox.saveMenuSearch(menu.title, this);
142 attrib.event_mask |= PointerMotionMask;
143 menu.frame = XCreateWindow(display, menu.window, 0,
144 menu.title_h + screen.getBorderWidth(),
145 menu.width, menu.frame_h, 0,
146 screen.getDepth(), InputOutput,
147 screen.getVisual(), attrib_mask, &attrib);
148 openbox.saveMenuSearch(menu.frame, this);
150 // even though this is the end of the constructor the menu is still not
151 // completely created. items must be inserted and it must be update()'d
155 Basemenu::~Basemenu(void) {
156 XUnmapWindow(display, menu.window);
158 if (shown && shown->getWindowID() == getWindowID())
159 shown = (Basemenu *) 0;
161 while (!menuitems.empty())
165 delete [] menu.label;
167 if (menu.title_pixmap)
168 image_ctrl->removeImage(menu.title_pixmap);
170 if (menu.frame_pixmap)
171 image_ctrl->removeImage(menu.frame_pixmap);
173 if (menu.hilite_pixmap)
174 image_ctrl->removeImage(menu.hilite_pixmap);
177 image_ctrl->removeImage(menu.sel_pixmap);
179 openbox.removeMenuSearch(menu.title);
180 XDestroyWindow(display, menu.title);
182 openbox.removeMenuSearch(menu.frame);
183 XDestroyWindow(display, menu.frame);
185 openbox.removeMenuSearch(menu.window);
186 XDestroyWindow(display, menu.window);
190 int Basemenu::insert(const char *l, int function, const char *e, int pos) {
191 char *label = 0, *exec = 0;
193 if (l) label = bstrdup(l);
194 if (e) exec = bstrdup(e);
196 BasemenuItem *item = new BasemenuItem(label, function, exec);
198 menuitems.push_back(item);
200 menuitems.insert(menuitems.begin() + pos, item);
202 return menuitems.size();
206 int Basemenu::insert(const char *l, Basemenu *submenu, int pos) {
209 if (l) label = bstrdup(l);
211 BasemenuItem *item = new BasemenuItem(label, submenu);
213 menuitems.push_back(item);
215 menuitems.insert(menuitems.begin() + pos, item);
217 submenu->parent = this;
219 return menuitems.size();
223 int Basemenu::insert(const char **ulabel, int pos, int function) {
224 BasemenuItem *item = new BasemenuItem(ulabel, function);
226 menuitems.push_back(item);
228 menuitems.insert(menuitems.begin() + pos, item);
230 return menuitems.size();
234 int Basemenu::remove(int index) {
235 if (index < 0 || index > menuitems.size()) return -1;
237 BasemenuItem *item = menuitems[index];
238 menuitems.erase(menuitems.begin() + index);
241 if ((!internal_menu) && (item->submenu())) {
242 Basemenu *tmp = (Basemenu *) item->submenu();
244 if (! tmp->internal_menu) {
247 tmp->internal_hide();
252 delete [] item->label();
255 delete [] item->exec();
260 if (which_sub == index)
262 else if (which_sub > index)
265 return menuitems.size();
269 void Basemenu::update(void) {
270 MenuStyle *style = screen.getMenuStyle();
271 if (i18n->multibyte()) {
272 menu.item_h = style->f_fontset_extents->max_ink_extent.height +
274 menu.title_h = style->t_fontset_extents->max_ink_extent.height +
277 menu.item_h = style->f_font->ascent + style->f_font->descent +
279 menu.title_h = style->t_font->ascent + style->t_font->descent +
284 const char *s = (menu.label) ? menu.label :
285 i18n->getMessage(BasemenuSet, BasemenuOpenboxMenu,
290 if (i18n->multibyte()) {
291 XRectangle ink, logical;
292 XmbTextExtents(screen.getMenuStyle()->t_fontset, s, l, &ink, &logical);
293 menu.item_w = logical.width;
295 menu.item_w = XTextWidth(screen.getMenuStyle()->t_font, s, l);
298 menu.item_w += (menu.bevel_w * 2);
304 menuitemList::const_iterator it = menuitems.begin();
305 for (; it != menuitems.end(); it++) {
306 const char *s = (((*it)->u && *(*it)->u) ? *(*it)->u :
307 (((*it)->l) ? (*it)->l : (const char *) 0));
310 if (i18n->multibyte()) {
311 XRectangle ink, logical;
312 XmbTextExtents(screen.getMenuStyle()->f_fontset, s, l, &ink, &logical);
315 ii = XTextWidth(screen.getMenuStyle()->f_font, s, l);
317 ii += (menu.bevel_w * 2) + (menu.item_h * 2);
319 menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w);
322 if (menuitems.size()) {
325 while (((menu.item_h * (menuitems.size() + 1) / menu.sublevels)
326 + menu.title_h + screen.getBorderWidth()) >
330 if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub;
332 menu.persub = menuitems.size() / menu.sublevels;
333 if (menuitems.size() % menu.sublevels) menu.persub++;
339 menu.width = (menu.sublevels * (menu.item_w));
340 if (! menu.width) menu.width = menu.item_w;
342 menu.frame_h = (menu.item_h * menu.persub);
343 menu.height = ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) +
345 if (! menu.frame_h) menu.frame_h = 1;
346 if (menu.height < 1) menu.height = 1;
351 tmp = menu.title_pixmap;
352 texture = &(screen.getMenuStyle()->title);
353 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
354 menu.title_pixmap = None;
355 XSetWindowBackground(display, menu.title,
356 texture->getColor()->getPixel());
359 image_ctrl->renderImage(menu.width, menu.title_h, texture);
360 XSetWindowBackgroundPixmap(display, menu.title, menu.title_pixmap);
362 if (tmp) image_ctrl->removeImage(tmp);
363 XClearWindow(display, menu.title);
366 tmp = menu.frame_pixmap;
367 texture = &(screen.getMenuStyle()->frame);
368 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
369 menu.frame_pixmap = None;
370 XSetWindowBackground(display, menu.frame,
371 texture->getColor()->getPixel());
374 image_ctrl->renderImage(menu.width, menu.frame_h, texture);
375 XSetWindowBackgroundPixmap(display, menu.frame, menu.frame_pixmap);
377 if (tmp) image_ctrl->removeImage(tmp);
379 tmp = menu.hilite_pixmap;
380 texture = &(screen.getMenuStyle()->hilite);
381 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
382 menu.hilite_pixmap = None;
385 image_ctrl->renderImage(menu.item_w, menu.item_h, texture);
387 if (tmp) image_ctrl->removeImage(tmp);
389 tmp = menu.sel_pixmap;
390 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
391 menu.sel_pixmap = None;
393 int hw = menu.item_h / 2;
395 image_ctrl->renderImage(hw, hw, texture);
397 if (tmp) image_ctrl->removeImage(tmp);
399 XResizeWindow(display, menu.window, menu.width, menu.height);
402 XResizeWindow(display, menu.title, menu.width, menu.title_h);
404 XMoveResizeWindow(display, menu.frame, 0,
405 ((title_vis) ? menu.title_h +
406 screen.getBorderWidth() : 0), menu.width,
409 XClearWindow(display, menu.window);
410 XClearWindow(display, menu.title);
411 XClearWindow(display, menu.frame);
413 if (title_vis && visible) redrawTitle();
415 for (int i = 0; visible && i < menuitems.size(); i++) {
416 if (i == which_sub) {
417 drawItem(i, True, 0);
420 drawItem(i, False, 0);
424 if (parent && visible)
425 parent->drawSubmenu(parent->which_sub);
427 XMapSubwindows(display, menu.window);
431 void Basemenu::show(void) {
432 XMapSubwindows(display, menu.window);
433 XMapWindow(display, menu.window);
437 if (shown && (! shown->torn))
445 void Basemenu::hide(void) {
446 if ((! torn) && hide_tree && parent && parent->isVisible()) {
447 Basemenu *p = parent;
449 while (p->isVisible() && (! p->torn) && p->parent) p = p->parent;
457 void Basemenu::internal_hide(void) {
458 if (which_sub != -1) {
459 BasemenuItem *tmp = menuitems[which_sub];
460 tmp->submenu()->internal_hide();
463 if (parent && (! torn)) {
464 parent->drawItem(parent->which_sub, False, True);
466 parent->which_sub = -1;
467 } else if (shown && shown->menu.window == menu.window) {
468 shown = (Basemenu *) 0;
471 torn = visible = False;
472 which_sub = which_press = which_sub = -1;
474 XUnmapWindow(display, menu.window);
478 void Basemenu::move(int x, int y) {
481 XMoveWindow(display, menu.window, x, y);
483 drawSubmenu(which_sub);
487 void Basemenu::redrawTitle(void) {
488 char *text = (char *) ((menu.label) ? menu.label :
489 i18n->getMessage(BasemenuSet, BasemenuOpenboxMenu,
491 int dx = menu.bevel_w, len = strlen(text);
494 if (i18n->multibyte()) {
495 XRectangle ink, logical;
496 XmbTextExtents(screen.getMenuStyle()->t_fontset, text, len, &ink, &logical);
499 l = XTextWidth(screen.getMenuStyle()->t_font, text, len);
502 l += (menu.bevel_w * 2);
504 switch (screen.getMenuStyle()->t_justify) {
505 case BScreen::RightJustify:
506 dx += menu.width - l;
509 case BScreen::CenterJustify:
510 dx += (menu.width - l) / 2;
514 MenuStyle *style = screen.getMenuStyle();
515 if (i18n->multibyte())
516 XmbDrawString(display, menu.title, style->t_fontset, style->t_text_gc, dx,
517 (menu.bevel_w - style->t_fontset_extents->max_ink_extent.y),
520 XDrawString(display, menu.title, style->t_text_gc, dx,
521 (style->t_font->ascent + menu.bevel_w), text, len);
525 void Basemenu::drawSubmenu(int index) {
526 if (which_sub != -1 && which_sub != index) {
527 BasemenuItem *itmp = menuitems[which_sub];
529 if (! itmp->submenu()->isTorn())
530 itmp->submenu()->internal_hide();
533 if (index >= 0 && index < menuitems.size()) {
534 BasemenuItem *item = menuitems[index];
535 if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
537 if (item->submenu()->parent != this) item->submenu()->parent = this;
538 int sbl = index / menu.persub, i = index - (sbl * menu.persub),
540 ((menu.item_w * (sbl + 1)) + screen.getBorderWidth()), y;
542 if (alignment == AlignTop)
543 y = (((shifted) ? menu.y_shift : menu.y) +
544 ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) -
545 ((item->submenu()->title_vis) ?
546 item->submenu()->menu.title_h + screen.getBorderWidth() : 0));
548 y = (((shifted) ? menu.y_shift : menu.y) +
550 ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) -
551 ((item->submenu()->title_vis) ?
552 item->submenu()->menu.title_h + screen.getBorderWidth() : 0));
554 if (alignment == AlignBottom &&
555 (y + item->submenu()->menu.height) > ((shifted) ? menu.y_shift :
556 menu.y) + menu.height)
557 y = (((shifted) ? menu.y_shift : menu.y) +
558 menu.height - item->submenu()->menu.height);
560 if ((x + item->submenu()->getWidth()) > screen.size().w()) {
561 x = ((shifted) ? menu.x_shift : menu.x) -
562 item->submenu()->getWidth() - screen.getBorderWidth();
567 if ((y + item->submenu()->getHeight()) > screen.size().h())
568 y = screen.size().h() - item->submenu()->getHeight() -
569 (screen.getBorderWidth() * 2);
572 item->submenu()->move(x, y);
573 if (! moving) drawItem(index, True);
575 if (! item->submenu()->isVisible())
576 item->submenu()->show();
577 item->submenu()->moving = moving;
586 Bool Basemenu::hasSubmenu(int index) {
587 if ((index >= 0) && (index < menuitems.size()))
588 if (menuitems[index]->submenu())
595 void Basemenu::drawItem(int index, Bool highlight, Bool clear,
596 int x, int y, unsigned int w, unsigned int h)
598 if (index < 0 || index > menuitems.size()) return;
600 BasemenuItem *item = menuitems[index];
603 Bool dotext = True, dohilite = True, dosel = True;
604 const char *text = (item->ulabel()) ? *item->ulabel() : item->label();
605 int sbl = index / menu.persub, i = index - (sbl * menu.persub);
606 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h);
607 int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
608 int text_x = 0, text_y = 0, len = strlen(text), sel_x = 0, sel_y = 0;
609 unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h, text_w = 0,
611 unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
614 if (i18n->multibyte()) {
615 XRectangle ink, logical;
616 XmbTextExtents(screen.getMenuStyle()->f_fontset,
617 text, len, &ink, &logical);
618 text_w = logical.width;
619 text_y = item_y + (menu.bevel_w / 2) -
620 screen.getMenuStyle()->f_fontset_extents->max_ink_extent.y;
622 text_w = XTextWidth(screen.getMenuStyle()->f_font, text, len);
624 screen.getMenuStyle()->f_font->ascent +
628 switch(screen.getMenuStyle()->f_justify) {
629 case BScreen::LeftJustify:
630 text_x = item_x + menu.bevel_w + menu.item_h + 1;
633 case BScreen::RightJustify:
634 text_x = item_x + menu.item_w - (menu.item_h + menu.bevel_w + text_w);
637 case BScreen::CenterJustify:
638 text_x = item_x + ((menu.item_w + 1 - text_w) / 2);
642 text_h = menu.item_h - menu.bevel_w;
646 ((highlight || item->isSelected()) ? screen.getMenuStyle()->h_text_gc :
647 screen.getMenuStyle()->f_text_gc),
649 ((highlight) ? screen.getMenuStyle()->h_text_gc :
650 ((item->isEnabled()) ? screen.getMenuStyle()->f_text_gc :
651 screen.getMenuStyle()->d_text_gc));
654 if (screen.getMenuStyle()->bullet_pos == Right)
655 sel_x += (menu.item_w - menu.item_h - menu.bevel_w);
657 sel_y = item_y + quarter_w;
660 XClearArea(display, menu.frame, item_x, item_y, menu.item_w, menu.item_h,
662 } else if (! (x == y && y == -1 && w == h && h == 0)) {
663 // calculate the which part of the hilite to redraw
664 if (! (max(item_x, x) <= (signed) min(item_x + menu.item_w, x + w) &&
665 max(item_y, y) <= (signed) min(item_y + menu.item_h, y + h))) {
668 hilite_x = max(item_x, x);
669 hilite_y = max(item_y, y);
670 hilite_w = min(item_x + menu.item_w, x + w) - hilite_x;
671 hilite_h = min(item_y + menu.item_h, y + h) - hilite_y;
672 hoff_x = hilite_x % menu.item_w;
673 hoff_y = hilite_y % menu.item_h;
676 // check if we need to redraw the text
677 int text_ry = item_y + (menu.bevel_w / 2);
678 if (! (max(text_x, x) <= (signed) min(text_x + text_w, x + w) &&
679 max(text_ry, y) <= (signed) min(text_ry + text_h, y + h)))
682 // check if we need to redraw the select pixmap/menu bullet
683 if (! (max(sel_x, x) <= (signed) min(sel_x + half_w, x + w) &&
684 max(sel_y, y) <= (signed) min(sel_y + half_w, y + h)))
688 if (dohilite && highlight && (menu.hilite_pixmap != ParentRelative)) {
689 if (menu.hilite_pixmap)
690 XCopyArea(display, menu.hilite_pixmap, menu.frame,
691 screen.getMenuStyle()->hilite_gc, hoff_x, hoff_y,
692 hilite_w, hilite_h, hilite_x, hilite_y);
694 XFillRectangle(display, menu.frame,
695 screen.getMenuStyle()->hilite_gc,
696 hilite_x, hilite_y, hilite_w, hilite_h);
697 } else if (dosel && item->isSelected() &&
698 (menu.sel_pixmap != ParentRelative)) {
700 XCopyArea(display, menu.sel_pixmap, menu.frame,
701 screen.getMenuStyle()->hilite_gc, 0, 0,
702 half_w, half_w, sel_x, sel_y);
704 XFillRectangle(display, menu.frame,
705 screen.getMenuStyle()->hilite_gc,
706 sel_x, sel_y, half_w, half_w);
709 if (dotext && text) {
710 if (i18n->multibyte())
711 XmbDrawString(display, menu.frame, screen.getMenuStyle()->f_fontset,
712 tgc, text_x, text_y, text, len);
714 XDrawString(display, menu.frame, tgc, text_x, text_y, text, len);
717 if (dosel && item->submenu()) {
718 switch (screen.getMenuStyle()->bullet) {
720 XDrawRectangle(display, menu.frame, gc, sel_x, sel_y, half_w, half_w);
726 if (screen.getMenuStyle()->bullet_pos == Right) {
727 tri[0].x = sel_x + quarter_w - 2;
728 tri[0].y = sel_y + quarter_w - 2;
734 tri[0].x = sel_x + quarter_w - 2;
735 tri[0].y = item_y + half_w;
742 XFillPolygon(display, menu.frame, gc, tri, 3, Convex,
749 dia[0].x = sel_x + quarter_w - 3;
750 dia[0].y = item_y + half_w;
758 XFillPolygon(display, menu.frame, gc, dia, 4, Convex,
766 void Basemenu::setLabel(const char *l) {
768 delete [] menu.label;
770 if (l) menu.label = bstrdup(l);
775 void Basemenu::setItemSelected(int index, Bool sel) {
776 if (index < 0 || index >= menuitems.size()) return;
778 BasemenuItem *item = find(index);
781 item->setSelected(sel);
782 if (visible) drawItem(index, (index == which_sub), True);
786 Bool Basemenu::isItemSelected(int index) {
787 if (index < 0 || index >= menuitems.size()) return False;
789 BasemenuItem *item = find(index);
790 if (! item) return False;
792 return item->isSelected();
796 void Basemenu::setItemEnabled(int index, Bool enable) {
797 if (index < 0 || index >= menuitems.size()) return;
799 BasemenuItem *item = find(index);
802 item->setEnabled(enable);
803 if (visible) drawItem(index, (index == which_sub), True);
807 Bool Basemenu::isItemEnabled(int index) {
808 if (index < 0 || index >= menuitems.size()) return False;
810 BasemenuItem *item = find(index);
811 if (! item) return False;
813 return item->isEnabled();
817 void Basemenu::buttonPressEvent(XButtonEvent *be) {
818 if (be->window == menu.frame) {
819 int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
820 int w = (sbl * menu.persub) + i;
822 if (w < menuitems.size() && w >= 0) {
826 BasemenuItem *item = menuitems[w];
831 drawItem(w, (item->isEnabled()), True);
834 menu.x_move = be->x_root - menu.x;
835 menu.y_move = be->y_root - menu.y;
840 void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
841 if (re->window == menu.title) {
846 drawSubmenu(which_sub);
849 if (re->x >= 0 && re->x <= (signed) menu.width &&
850 re->y >= 0 && re->y <= (signed) menu.title_h)
853 } else if (re->window == menu.frame &&
854 re->x >= 0 && re->x < (signed) menu.width &&
855 re->y >= 0 && re->y < (signed) menu.frame_h) {
856 if (re->button == 3) {
859 int sbl = (re->x / menu.item_w), i = (re->y / menu.item_h),
860 ix = sbl * menu.item_w, iy = i * menu.item_h,
861 w = (sbl * menu.persub) + i,
862 p = (which_sbl * menu.persub) + which_press;
864 if (w < menuitems.size() && w >= 0) {
865 drawItem(p, (p == which_sub), True);
867 if (p == w && isItemEnabled(w)) {
868 if (re->x > ix && re->x < (signed) (ix + menu.item_w) &&
869 re->y > iy && re->y < (signed) (iy + menu.item_h)) {
870 itemSelected(re->button, w);
874 drawItem(p, False, True);
880 void Basemenu::motionNotifyEvent(XMotionEvent *me) {
881 if (me->window == menu.title && (me->state & Button1Mask)) {
884 if (parent && (! torn)) {
885 parent->drawItem(parent->which_sub, False, True);
886 parent->which_sub = -1;
889 moving = torn = True;
892 drawSubmenu(which_sub);
894 menu.x = me->x_root - menu.x_move,
895 menu.y = me->y_root - menu.y_move;
897 XMoveWindow(display, menu.window, menu.x, menu.y);
900 drawSubmenu(which_sub);
903 } else if ((! (me->state & Button1Mask)) && me->window == menu.frame &&
904 me->x >= 0 && me->x < (signed) menu.width &&
905 me->y >= 0 && me->y < (signed) menu.frame_h) {
906 int sbl = (me->x / menu.item_w), i = (me->y / menu.item_h),
907 w = (sbl * menu.persub) + i;
909 if ((i != which_press || sbl != which_sbl) &&
910 (w < menuitems.size() && w >= 0)) {
911 if (which_press != -1 && which_sbl != -1) {
912 int p = (which_sbl * menu.persub) + which_press;
913 BasemenuItem *item = menuitems[p];
915 drawItem(p, False, True);
917 if (item->submenu()->isVisible() &&
918 (! item->submenu()->isTorn())) {
919 item->submenu()->internal_hide();
927 BasemenuItem *itmp = menuitems[w];
932 drawItem(w, (itmp->isEnabled()), True);
938 void Basemenu::exposeEvent(XExposeEvent *ee) {
939 if (ee->window == menu.title) {
941 } else if (ee->window == menu.frame) {
942 // this is a compilicated algorithm... lets do it step by step...
943 // first... we see in which sub level the expose starts... and how many
944 // items down in that sublevel
946 int sbl = (ee->x / menu.item_w), id = (ee->y / menu.item_h),
947 // next... figure out how many sublevels over the redraw spans
948 sbl_d = ((ee->x + ee->width) / menu.item_w),
949 // then we see how many items down to redraw
950 id_d = ((ee->y + ee->height) / menu.item_h);
952 if (id_d > menu.persub) id_d = menu.persub;
954 // draw the sublevels and the number of items the exposure spans
955 menuitemList::const_iterator it = menuitems.begin();
957 for (i = sbl; i <= sbl_d; i++) {
958 // set the iterator to the first item in the sublevel needing redrawing
959 it = menuitems.begin() + (id + (i * menu.persub));
960 for (ii = id; ii <= id_d && it != menuitems.end(); it++, ii++) {
961 int index = ii + (i * menu.persub);
963 drawItem(index, (which_sub == index), False,
964 ee->x, ee->y, ee->width, ee->height);
971 void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
972 if (ce->window == menu.frame) {
973 menu.x_shift = menu.x, menu.y_shift = menu.y;
974 if (menu.x + menu.width > screen.size().w()) {
975 menu.x_shift = screen.size().w() - menu.width -
976 screen.getBorderWidth();
978 } else if (menu.x < 0) {
979 menu.x_shift = -screen.getBorderWidth();
983 if (menu.y + menu.height > screen.size().h()) {
984 menu.y_shift = screen.size().h() - menu.height -
985 screen.getBorderWidth();
987 } else if (menu.y + (signed) menu.title_h < 0) {
988 menu.y_shift = -screen.getBorderWidth();
993 XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
995 if (which_sub != -1) {
996 BasemenuItem *tmp = menuitems[which_sub];
997 if (tmp->submenu()->isVisible()) {
998 int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
999 w = (sbl * menu.persub) + i;
1001 if (w != which_sub && (! tmp->submenu()->isTorn())) {
1002 tmp->submenu()->internal_hide();
1004 drawItem(which_sub, False, True);
1013 void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
1014 if (ce->window == menu.frame) {
1015 if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
1016 int p = (which_sbl * menu.persub) + which_press;
1018 drawItem(p, (p == which_sub), True);
1020 which_sbl = which_press = -1;
1024 XMoveWindow(display, menu.window, menu.x, menu.y);
1027 if (which_sub != -1) drawSubmenu(which_sub);
1033 void Basemenu::reconfigure(void) {
1034 XSetWindowBackground(display, menu.window,
1035 screen.getBorderColor()->getPixel());
1036 XSetWindowBorder(display, menu.window,
1037 screen.getBorderColor()->getPixel());
1038 XSetWindowBorderWidth(display, menu.window, screen.getBorderWidth());
1040 menu.bevel_w = screen.getBevelWidth();