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
54 static Basemenu *shown = (Basemenu *) 0;
56 Basemenu::Basemenu(BScreen &scrn) : openbox(scrn.getOpenbox()), screen(scrn) {
57 image_ctrl = screen.getImageControl();
58 display = openbox.getXDisplay();
59 parent = (Basemenu *) 0;
60 alignment = AlignDontCare;
86 menu.sel_pixmap = None;
88 menu.bevel_w = screen.getBevelWidth();
90 if (i18n->multibyte())
91 menu.width = menu.title_h = menu.item_w = menu.frame_h =
92 screen.getMenuStyle()->t_fontset_extents->max_ink_extent.height +
95 menu.width = menu.title_h = menu.item_w = menu.frame_h =
96 screen.getMenuStyle()->t_font->ascent +
97 screen.getMenuStyle()->t_font->descent + (menu.bevel_w * 2);
105 MenuStyle *style = screen.getMenuStyle();
106 if (i18n->multibyte()) {
107 menu.item_h = style->f_fontset_extents->max_ink_extent.height +
110 menu.item_h = style->f_font->ascent + style->f_font->descent +
114 menu.height = menu.title_h + screen.getBorderWidth() + menu.frame_h;
116 unsigned long attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel |
117 CWColormap | CWOverrideRedirect | CWEventMask;
118 XSetWindowAttributes attrib;
119 attrib.background_pixmap = None;
120 attrib.background_pixel = attrib.border_pixel =
121 screen.getBorderColor()->getPixel();
122 attrib.colormap = screen.getColormap();
123 attrib.override_redirect = True;
124 attrib.event_mask = ButtonPressMask | ButtonReleaseMask |
125 ButtonMotionMask | ExposureMask;
128 XCreateWindow(display, screen.getRootWindow(), menu.x, menu.y, menu.width,
129 menu.height, screen.getBorderWidth(), screen.getDepth(),
130 InputOutput, screen.getVisual(), attrib_mask, &attrib);
131 openbox.saveMenuSearch(menu.window, this);
133 attrib_mask = CWBackPixmap | CWBackPixel | CWBorderPixel | CWEventMask;
134 attrib.background_pixel = screen.getBorderColor()->getPixel();
135 attrib.event_mask |= EnterWindowMask | LeaveWindowMask;
138 XCreateWindow(display, menu.window, 0, 0, menu.width, menu.height, 0,
139 screen.getDepth(), InputOutput, screen.getVisual(),
140 attrib_mask, &attrib);
141 openbox.saveMenuSearch(menu.title, this);
143 attrib.event_mask |= PointerMotionMask;
144 menu.frame = XCreateWindow(display, menu.window, 0,
145 menu.title_h + screen.getBorderWidth(),
146 menu.width, menu.frame_h, 0,
147 screen.getDepth(), InputOutput,
148 screen.getVisual(), attrib_mask, &attrib);
149 openbox.saveMenuSearch(menu.frame, this);
151 // even though this is the end of the constructor the menu is still not
152 // completely created. items must be inserted and it must be update()'d
156 Basemenu::~Basemenu(void) {
157 XUnmapWindow(display, menu.window);
159 if (shown && shown->getWindowID() == getWindowID())
160 shown = (Basemenu *) 0;
162 while (!menuitems.empty())
166 delete [] menu.label;
168 if (menu.title_pixmap)
169 image_ctrl->removeImage(menu.title_pixmap);
171 if (menu.frame_pixmap)
172 image_ctrl->removeImage(menu.frame_pixmap);
174 if (menu.hilite_pixmap)
175 image_ctrl->removeImage(menu.hilite_pixmap);
178 image_ctrl->removeImage(menu.sel_pixmap);
180 openbox.removeMenuSearch(menu.title);
181 XDestroyWindow(display, menu.title);
183 openbox.removeMenuSearch(menu.frame);
184 XDestroyWindow(display, menu.frame);
186 openbox.removeMenuSearch(menu.window);
187 XDestroyWindow(display, menu.window);
191 int Basemenu::insert(const char *l, int function, const char *e, int pos) {
192 char *label = 0, *exec = 0;
194 if (l) label = bstrdup(l);
195 if (e) exec = bstrdup(e);
197 BasemenuItem *item = new BasemenuItem(label, function, exec);
199 menuitems.push_back(item);
201 menuitems.insert(menuitems.begin() + pos, item);
203 return menuitems.size();
207 int Basemenu::insert(const char *l, Basemenu *submenu, int pos) {
210 if (l) label = bstrdup(l);
212 BasemenuItem *item = new BasemenuItem(label, submenu);
214 menuitems.push_back(item);
216 menuitems.insert(menuitems.begin() + pos, item);
218 submenu->parent = this;
220 return menuitems.size();
224 int Basemenu::insert(const char **ulabel, int pos, int function) {
225 BasemenuItem *item = new BasemenuItem(ulabel, function);
227 menuitems.push_back(item);
229 menuitems.insert(menuitems.begin() + pos, item);
231 return menuitems.size();
235 int Basemenu::remove(int index) {
236 if (index < 0 || index > menuitems.size()) return -1;
238 BasemenuItem *item = menuitems[index];
239 menuitems.erase(menuitems.begin() + index);
242 if ((!internal_menu) && (item->submenu())) {
243 Basemenu *tmp = (Basemenu *) item->submenu();
245 if (! tmp->internal_menu) {
248 tmp->internal_hide();
253 delete [] item->label();
256 delete [] item->exec();
261 if (which_sub == index)
263 else if (which_sub > index)
266 return menuitems.size();
270 void Basemenu::update(void) {
271 MenuStyle *style = screen.getMenuStyle();
272 if (i18n->multibyte()) {
273 menu.item_h = style->f_fontset_extents->max_ink_extent.height +
275 menu.title_h = style->t_fontset_extents->max_ink_extent.height +
278 menu.item_h = style->f_font->ascent + style->f_font->descent +
280 menu.title_h = style->t_font->ascent + style->t_font->descent +
285 const char *s = (menu.label) ? menu.label :
286 i18n->getMessage(BasemenuSet, BasemenuOpenboxMenu,
291 if (i18n->multibyte()) {
292 XRectangle ink, logical;
293 XmbTextExtents(screen.getMenuStyle()->t_fontset, s, l, &ink, &logical);
294 menu.item_w = logical.width;
296 menu.item_w = XTextWidth(screen.getMenuStyle()->t_font, s, l);
299 menu.item_w += (menu.bevel_w * 2);
305 menuitemList::const_iterator it = menuitems.begin();
306 for (; it != menuitems.end(); it++) {
307 const char *s = (((*it)->u && *(*it)->u) ? *(*it)->u :
308 (((*it)->l) ? (*it)->l : (const char *) 0));
311 if (i18n->multibyte()) {
312 XRectangle ink, logical;
313 XmbTextExtents(screen.getMenuStyle()->f_fontset, s, l, &ink, &logical);
316 ii = XTextWidth(screen.getMenuStyle()->f_font, s, l);
318 ii += (menu.bevel_w * 2) + (menu.item_h * 2);
320 menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w);
323 if (menuitems.size()) {
326 while (((menu.item_h * (menuitems.size() + 1) / menu.sublevels)
327 + menu.title_h + screen.getBorderWidth()) >
331 if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub;
333 menu.persub = menuitems.size() / menu.sublevels;
334 if (menuitems.size() % menu.sublevels) menu.persub++;
340 menu.width = (menu.sublevels * (menu.item_w));
341 if (! menu.width) menu.width = menu.item_w;
343 menu.frame_h = (menu.item_h * menu.persub);
344 menu.height = ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) +
346 if (! menu.frame_h) menu.frame_h = 1;
347 if (menu.height < 1) menu.height = 1;
352 tmp = menu.title_pixmap;
353 texture = &(screen.getMenuStyle()->title);
354 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
355 menu.title_pixmap = None;
356 XSetWindowBackground(display, menu.title,
357 texture->getColor()->getPixel());
360 image_ctrl->renderImage(menu.width, menu.title_h, texture);
361 XSetWindowBackgroundPixmap(display, menu.title, menu.title_pixmap);
363 if (tmp) image_ctrl->removeImage(tmp);
364 XClearWindow(display, menu.title);
367 tmp = menu.frame_pixmap;
368 texture = &(screen.getMenuStyle()->frame);
369 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
370 menu.frame_pixmap = None;
371 XSetWindowBackground(display, menu.frame,
372 texture->getColor()->getPixel());
375 image_ctrl->renderImage(menu.width, menu.frame_h, texture);
376 XSetWindowBackgroundPixmap(display, menu.frame, menu.frame_pixmap);
378 if (tmp) image_ctrl->removeImage(tmp);
380 tmp = menu.hilite_pixmap;
381 texture = &(screen.getMenuStyle()->hilite);
382 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
383 menu.hilite_pixmap = None;
386 image_ctrl->renderImage(menu.item_w, menu.item_h, texture);
388 if (tmp) image_ctrl->removeImage(tmp);
390 tmp = menu.sel_pixmap;
391 if (texture->getTexture() == (BImage_Flat | BImage_Solid)) {
392 menu.sel_pixmap = None;
394 int hw = menu.item_h / 2;
396 image_ctrl->renderImage(hw, hw, texture);
398 if (tmp) image_ctrl->removeImage(tmp);
400 XResizeWindow(display, menu.window, menu.width, menu.height);
403 XResizeWindow(display, menu.title, menu.width, menu.title_h);
405 XMoveResizeWindow(display, menu.frame, 0,
406 ((title_vis) ? menu.title_h +
407 screen.getBorderWidth() : 0), menu.width,
410 XClearWindow(display, menu.window);
411 XClearWindow(display, menu.title);
412 XClearWindow(display, menu.frame);
414 if (title_vis && visible) redrawTitle();
416 for (int i = 0; visible && i < menuitems.size(); i++) {
417 if (i == which_sub) {
418 drawItem(i, True, 0);
421 drawItem(i, False, 0);
425 if (parent && visible)
426 parent->drawSubmenu(parent->which_sub);
428 XMapSubwindows(display, menu.window);
432 void Basemenu::show(void) {
433 XMapSubwindows(display, menu.window);
434 XMapWindow(display, menu.window);
438 if (shown && (! shown->torn))
446 void Basemenu::hide(void) {
447 if ((! torn) && hide_tree && parent && parent->isVisible()) {
448 Basemenu *p = parent;
450 while (p->isVisible() && (! p->torn) && p->parent) p = p->parent;
458 void Basemenu::internal_hide(void) {
459 if (which_sub != -1) {
460 BasemenuItem *tmp = menuitems[which_sub];
461 tmp->submenu()->internal_hide();
464 if (parent && (! torn)) {
465 parent->drawItem(parent->which_sub, False, True);
467 parent->which_sub = -1;
468 } else if (shown && shown->menu.window == menu.window) {
469 shown = (Basemenu *) 0;
472 torn = visible = False;
473 which_sub = which_press = which_sub = -1;
475 XUnmapWindow(display, menu.window);
479 void Basemenu::move(int x, int y) {
482 XMoveWindow(display, menu.window, x, y);
484 drawSubmenu(which_sub);
488 void Basemenu::redrawTitle(void) {
489 char *text = (char *) ((menu.label) ? menu.label :
490 i18n->getMessage(BasemenuSet, BasemenuOpenboxMenu,
492 int dx = menu.bevel_w, len = strlen(text);
495 if (i18n->multibyte()) {
496 XRectangle ink, logical;
497 XmbTextExtents(screen.getMenuStyle()->t_fontset, text, len, &ink, &logical);
500 l = XTextWidth(screen.getMenuStyle()->t_font, text, len);
503 l += (menu.bevel_w * 2);
505 switch (screen.getMenuStyle()->t_justify) {
506 case BScreen::RightJustify:
507 dx += menu.width - l;
510 case BScreen::CenterJustify:
511 dx += (menu.width - l) / 2;
515 MenuStyle *style = screen.getMenuStyle();
516 if (i18n->multibyte())
517 XmbDrawString(display, menu.title, style->t_fontset, style->t_text_gc, dx,
518 (menu.bevel_w - style->t_fontset_extents->max_ink_extent.y),
521 XDrawString(display, menu.title, style->t_text_gc, dx,
522 (style->t_font->ascent + menu.bevel_w), text, len);
526 void Basemenu::drawSubmenu(int index) {
527 if (which_sub != -1 && which_sub != index) {
528 BasemenuItem *itmp = menuitems[which_sub];
530 if (! itmp->submenu()->isTorn())
531 itmp->submenu()->internal_hide();
534 if (index >= 0 && index < menuitems.size()) {
535 BasemenuItem *item = menuitems[index];
536 if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
538 if (item->submenu()->parent != this) item->submenu()->parent = this;
539 int sbl = index / menu.persub, i = index - (sbl * menu.persub),
541 ((menu.item_w * (sbl + 1)) + screen.getBorderWidth()), y;
543 if (alignment == AlignTop)
544 y = (((shifted) ? menu.y_shift : menu.y) +
545 ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) -
546 ((item->submenu()->title_vis) ?
547 item->submenu()->menu.title_h + screen.getBorderWidth() : 0));
549 y = (((shifted) ? menu.y_shift : menu.y) +
551 ((title_vis) ? menu.title_h + screen.getBorderWidth() : 0) -
552 ((item->submenu()->title_vis) ?
553 item->submenu()->menu.title_h + screen.getBorderWidth() : 0));
555 if (alignment == AlignBottom &&
556 (y + item->submenu()->menu.height) > ((shifted) ? menu.y_shift :
557 menu.y) + menu.height)
558 y = (((shifted) ? menu.y_shift : menu.y) +
559 menu.height - item->submenu()->menu.height);
561 if ((x + item->submenu()->getWidth()) > screen.size().w()) {
562 x = ((shifted) ? menu.x_shift : menu.x) -
563 item->submenu()->getWidth() - screen.getBorderWidth();
568 if ((y + item->submenu()->getHeight()) > screen.size().h())
569 y = screen.size().h() - item->submenu()->getHeight() -
570 (screen.getBorderWidth() * 2);
573 item->submenu()->move(x, y);
574 if (! moving) drawItem(index, True);
576 if (! item->submenu()->isVisible())
577 item->submenu()->show();
578 item->submenu()->moving = moving;
587 Bool Basemenu::hasSubmenu(int index) {
588 if ((index >= 0) && (index < menuitems.size()))
589 if (menuitems[index]->submenu())
596 void Basemenu::drawItem(int index, Bool highlight, Bool clear,
597 int x, int y, unsigned int w, unsigned int h)
599 if (index < 0 || index > menuitems.size()) return;
601 BasemenuItem *item = menuitems[index];
604 Bool dotext = True, dohilite = True, dosel = True;
605 const char *text = (item->ulabel()) ? *item->ulabel() : item->label();
606 int sbl = index / menu.persub, i = index - (sbl * menu.persub);
607 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h);
608 int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
609 int text_x = 0, text_y = 0, len = strlen(text), sel_x = 0, sel_y = 0;
610 unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h, text_w = 0,
612 unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
615 if (i18n->multibyte()) {
616 XRectangle ink, logical;
617 XmbTextExtents(screen.getMenuStyle()->f_fontset,
618 text, len, &ink, &logical);
619 text_w = logical.width;
620 text_y = item_y + (menu.bevel_w / 2) -
621 screen.getMenuStyle()->f_fontset_extents->max_ink_extent.y;
623 text_w = XTextWidth(screen.getMenuStyle()->f_font, text, len);
625 screen.getMenuStyle()->f_font->ascent +
629 switch(screen.getMenuStyle()->f_justify) {
630 case BScreen::LeftJustify:
631 text_x = item_x + menu.bevel_w + menu.item_h + 1;
634 case BScreen::RightJustify:
635 text_x = item_x + menu.item_w - (menu.item_h + menu.bevel_w + text_w);
638 case BScreen::CenterJustify:
639 text_x = item_x + ((menu.item_w + 1 - text_w) / 2);
643 text_h = menu.item_h - menu.bevel_w;
647 ((highlight || item->isSelected()) ? screen.getMenuStyle()->h_text_gc :
648 screen.getMenuStyle()->f_text_gc),
650 ((highlight) ? screen.getMenuStyle()->h_text_gc :
651 ((item->isEnabled()) ? screen.getMenuStyle()->f_text_gc :
652 screen.getMenuStyle()->d_text_gc));
655 if (screen.getMenuStyle()->bullet_pos == Right)
656 sel_x += (menu.item_w - menu.item_h - menu.bevel_w);
658 sel_y = item_y + quarter_w;
661 XClearArea(display, menu.frame, item_x, item_y, menu.item_w, menu.item_h,
663 } else if (! (x == y && y == -1 && w == h && h == 0)) {
664 // calculate the which part of the hilite to redraw
665 if (! (max(item_x, x) <= (signed) min(item_x + menu.item_w, x + w) &&
666 max(item_y, y) <= (signed) min(item_y + menu.item_h, y + h))) {
669 hilite_x = max(item_x, x);
670 hilite_y = max(item_y, y);
671 hilite_w = min(item_x + menu.item_w, x + w) - hilite_x;
672 hilite_h = min(item_y + menu.item_h, y + h) - hilite_y;
673 hoff_x = hilite_x % menu.item_w;
674 hoff_y = hilite_y % menu.item_h;
677 // check if we need to redraw the text
678 int text_ry = item_y + (menu.bevel_w / 2);
679 if (! (max(text_x, x) <= (signed) min(text_x + text_w, x + w) &&
680 max(text_ry, y) <= (signed) min(text_ry + text_h, y + h)))
683 // check if we need to redraw the select pixmap/menu bullet
684 if (! (max(sel_x, x) <= (signed) min(sel_x + half_w, x + w) &&
685 max(sel_y, y) <= (signed) min(sel_y + half_w, y + h)))
689 if (dohilite && highlight && (menu.hilite_pixmap != ParentRelative)) {
690 if (menu.hilite_pixmap)
691 XCopyArea(display, menu.hilite_pixmap, menu.frame,
692 screen.getMenuStyle()->hilite_gc, hoff_x, hoff_y,
693 hilite_w, hilite_h, hilite_x, hilite_y);
695 XFillRectangle(display, menu.frame,
696 screen.getMenuStyle()->hilite_gc,
697 hilite_x, hilite_y, hilite_w, hilite_h);
698 } else if (dosel && item->isSelected() &&
699 (menu.sel_pixmap != ParentRelative)) {
701 XCopyArea(display, menu.sel_pixmap, menu.frame,
702 screen.getMenuStyle()->hilite_gc, 0, 0,
703 half_w, half_w, sel_x, sel_y);
705 XFillRectangle(display, menu.frame,
706 screen.getMenuStyle()->hilite_gc,
707 sel_x, sel_y, half_w, half_w);
710 if (dotext && text) {
711 if (i18n->multibyte())
712 XmbDrawString(display, menu.frame, screen.getMenuStyle()->f_fontset,
713 tgc, text_x, text_y, text, len);
715 XDrawString(display, menu.frame, tgc, text_x, text_y, text, len);
718 if (dosel && item->submenu()) {
719 switch (screen.getMenuStyle()->bullet) {
721 XDrawRectangle(display, menu.frame, gc, sel_x, sel_y, half_w, half_w);
727 if (screen.getMenuStyle()->bullet_pos == Right) {
728 tri[0].x = sel_x + quarter_w - 2;
729 tri[0].y = sel_y + quarter_w - 2;
735 tri[0].x = sel_x + quarter_w - 2;
736 tri[0].y = item_y + half_w;
743 XFillPolygon(display, menu.frame, gc, tri, 3, Convex,
750 dia[0].x = sel_x + quarter_w - 3;
751 dia[0].y = item_y + half_w;
759 XFillPolygon(display, menu.frame, gc, dia, 4, Convex,
767 void Basemenu::setLabel(const char *l) {
769 delete [] menu.label;
771 if (l) menu.label = bstrdup(l);
776 void Basemenu::setItemSelected(int index, Bool sel) {
777 if (index < 0 || index >= menuitems.size()) return;
779 BasemenuItem *item = find(index);
782 item->setSelected(sel);
783 if (visible) drawItem(index, (index == which_sub), True);
787 Bool Basemenu::isItemSelected(int index) {
788 if (index < 0 || index >= menuitems.size()) return False;
790 BasemenuItem *item = find(index);
791 if (! item) return False;
793 return item->isSelected();
797 void Basemenu::setItemEnabled(int index, Bool enable) {
798 if (index < 0 || index >= menuitems.size()) return;
800 BasemenuItem *item = find(index);
803 item->setEnabled(enable);
804 if (visible) drawItem(index, (index == which_sub), True);
808 Bool Basemenu::isItemEnabled(int index) {
809 if (index < 0 || index >= menuitems.size()) return False;
811 BasemenuItem *item = find(index);
812 if (! item) return False;
814 return item->isEnabled();
818 void Basemenu::buttonPressEvent(XButtonEvent *be) {
819 if (be->window == menu.frame) {
820 int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
821 int w = (sbl * menu.persub) + i;
823 if (w < menuitems.size() && w >= 0) {
827 BasemenuItem *item = menuitems[w];
832 drawItem(w, (item->isEnabled()), True);
835 menu.x_move = be->x_root - menu.x;
836 menu.y_move = be->y_root - menu.y;
841 void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
842 if (re->window == menu.title) {
847 drawSubmenu(which_sub);
850 if (re->x >= 0 && re->x <= (signed) menu.width &&
851 re->y >= 0 && re->y <= (signed) menu.title_h)
854 } else if (re->window == menu.frame &&
855 re->x >= 0 && re->x < (signed) menu.width &&
856 re->y >= 0 && re->y < (signed) menu.frame_h) {
857 if (re->button == 3) {
860 int sbl = (re->x / menu.item_w), i = (re->y / menu.item_h),
861 ix = sbl * menu.item_w, iy = i * menu.item_h,
862 w = (sbl * menu.persub) + i,
863 p = (which_sbl * menu.persub) + which_press;
865 if (w < menuitems.size() && w >= 0) {
866 drawItem(p, (p == which_sub), True);
868 if (p == w && isItemEnabled(w)) {
869 if (re->x > ix && re->x < (signed) (ix + menu.item_w) &&
870 re->y > iy && re->y < (signed) (iy + menu.item_h)) {
871 itemSelected(re->button, w);
875 drawItem(p, False, True);
881 void Basemenu::motionNotifyEvent(XMotionEvent *me) {
882 if (me->window == menu.title && (me->state & Button1Mask)) {
885 if (parent && (! torn)) {
886 parent->drawItem(parent->which_sub, False, True);
887 parent->which_sub = -1;
890 moving = torn = True;
893 drawSubmenu(which_sub);
895 menu.x = me->x_root - menu.x_move,
896 menu.y = me->y_root - menu.y_move;
898 XMoveWindow(display, menu.window, menu.x, menu.y);
901 drawSubmenu(which_sub);
904 } else if ((! (me->state & Button1Mask)) && me->window == menu.frame &&
905 me->x >= 0 && me->x < (signed) menu.width &&
906 me->y >= 0 && me->y < (signed) menu.frame_h) {
907 int sbl = (me->x / menu.item_w), i = (me->y / menu.item_h),
908 w = (sbl * menu.persub) + i;
910 if ((i != which_press || sbl != which_sbl) &&
911 (w < menuitems.size() && w >= 0)) {
912 if (which_press != -1 && which_sbl != -1) {
913 int p = (which_sbl * menu.persub) + which_press;
914 BasemenuItem *item = menuitems[p];
916 drawItem(p, False, True);
918 if (item->submenu()->isVisible() &&
919 (! item->submenu()->isTorn())) {
920 item->submenu()->internal_hide();
928 BasemenuItem *itmp = menuitems[w];
933 drawItem(w, (itmp->isEnabled()), True);
939 void Basemenu::exposeEvent(XExposeEvent *ee) {
940 if (ee->window == menu.title) {
942 } else if (ee->window == menu.frame) {
943 // this is a compilicated algorithm... lets do it step by step...
944 // first... we see in which sub level the expose starts... and how many
945 // items down in that sublevel
947 int sbl = (ee->x / menu.item_w), id = (ee->y / menu.item_h),
948 // next... figure out how many sublevels over the redraw spans
949 sbl_d = ((ee->x + ee->width) / menu.item_w),
950 // then we see how many items down to redraw
951 id_d = ((ee->y + ee->height) / menu.item_h);
953 if (id_d > menu.persub) id_d = menu.persub;
955 // draw the sublevels and the number of items the exposure spans
956 menuitemList::const_iterator it = menuitems.begin();
958 for (i = sbl; i <= sbl_d; i++) {
959 // set the iterator to the first item in the sublevel needing redrawing
960 it = menuitems.begin() + (id + (i * menu.persub));
961 for (ii = id; ii <= id_d && it != menuitems.end(); it++, ii++) {
962 int index = ii + (i * menu.persub);
964 drawItem(index, (which_sub == index), False,
965 ee->x, ee->y, ee->width, ee->height);
972 void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
973 if (ce->window == menu.frame) {
974 menu.x_shift = menu.x, menu.y_shift = menu.y;
975 if (menu.x + menu.width > screen.size().w()) {
976 menu.x_shift = screen.size().w() - menu.width -
977 screen.getBorderWidth();
979 } else if (menu.x < 0) {
980 menu.x_shift = -screen.getBorderWidth();
984 if (menu.y + menu.height > screen.size().h()) {
985 menu.y_shift = screen.size().h() - menu.height -
986 screen.getBorderWidth();
988 } else if (menu.y + (signed) menu.title_h < 0) {
989 menu.y_shift = -screen.getBorderWidth();
994 XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
996 if (which_sub != -1) {
997 BasemenuItem *tmp = menuitems[which_sub];
998 if (tmp->submenu()->isVisible()) {
999 int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
1000 w = (sbl * menu.persub) + i;
1002 if (w != which_sub && (! tmp->submenu()->isTorn())) {
1003 tmp->submenu()->internal_hide();
1005 drawItem(which_sub, False, True);
1014 void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
1015 if (ce->window == menu.frame) {
1016 if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
1017 int p = (which_sbl * menu.persub) + which_press;
1019 drawItem(p, (p == which_sub), True);
1021 which_sbl = which_press = -1;
1025 XMoveWindow(display, menu.window, menu.x, menu.y);
1028 if (which_sub != -1) drawSubmenu(which_sub);
1034 void Basemenu::reconfigure(void) {
1035 XSetWindowBackground(display, menu.window,
1036 screen.getBorderColor()->getPixel());
1037 XSetWindowBorder(display, menu.window,
1038 screen.getBorderColor()->getPixel());
1039 XSetWindowBorderWidth(display, menu.window, screen.getBorderWidth());
1041 menu.bevel_w = screen.getBevelWidth();