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();
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 > (signed)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(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 < (signed)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(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 < (signed)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 >= (signed)menuitems.size())
590 return (menuitems[index]->submenu());
594 void Basemenu::drawItem(int index, Bool highlight, Bool clear,
595 int x, int y, unsigned int w, unsigned int h)
597 if (index < 0 || index > (signed)menuitems.size()) return;
599 BasemenuItem *item = menuitems[index];
602 Bool dotext = True, dohilite = True, dosel = True;
603 const char *text = (item->ulabel()) ? *item->ulabel() : item->label();
604 int sbl = index / menu.persub, i = index - (sbl * menu.persub);
605 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h);
606 int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
607 int text_x = 0, text_y = 0, len = strlen(text), sel_x = 0, sel_y = 0;
608 unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h, text_w = 0,
610 unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
613 if (i18n.multibyte()) {
614 XRectangle ink, logical;
615 XmbTextExtents(screen.getMenuStyle()->f_fontset,
616 text, len, &ink, &logical);
617 text_w = logical.width;
618 text_y = item_y + (menu.bevel_w / 2) -
619 screen.getMenuStyle()->f_fontset_extents->max_ink_extent.y;
621 text_w = XTextWidth(screen.getMenuStyle()->f_font, text, len);
623 screen.getMenuStyle()->f_font->ascent +
627 switch(screen.getMenuStyle()->f_justify) {
628 case BScreen::LeftJustify:
629 text_x = item_x + menu.bevel_w + menu.item_h + 1;
632 case BScreen::RightJustify:
633 text_x = item_x + menu.item_w - (menu.item_h + menu.bevel_w + text_w);
636 case BScreen::CenterJustify:
637 text_x = item_x + ((menu.item_w + 1 - text_w) / 2);
641 text_h = menu.item_h - menu.bevel_w;
645 ((highlight || item->isSelected()) ? screen.getMenuStyle()->h_text_gc :
646 screen.getMenuStyle()->f_text_gc),
648 ((highlight) ? screen.getMenuStyle()->h_text_gc :
649 ((item->isEnabled()) ? screen.getMenuStyle()->f_text_gc :
650 screen.getMenuStyle()->d_text_gc));
653 if (screen.getMenuStyle()->bullet_pos == Right)
654 sel_x += (menu.item_w - menu.item_h - menu.bevel_w);
656 sel_y = item_y + quarter_w;
659 XClearArea(display, menu.frame, item_x, item_y, menu.item_w, menu.item_h,
661 } else if (! (x == y && y == -1 && w == h && h == 0)) {
662 // calculate the which part of the hilite to redraw
663 if (! (max(item_x, x) <= (signed) min(item_x + menu.item_w, x + w) &&
664 max(item_y, y) <= (signed) min(item_y + menu.item_h, y + h))) {
667 hilite_x = max(item_x, x);
668 hilite_y = max(item_y, y);
669 hilite_w = min(item_x + menu.item_w, x + w) - hilite_x;
670 hilite_h = min(item_y + menu.item_h, y + h) - hilite_y;
671 hoff_x = hilite_x % menu.item_w;
672 hoff_y = hilite_y % menu.item_h;
675 // check if we need to redraw the text
676 int text_ry = item_y + (menu.bevel_w / 2);
677 if (! (max(text_x, x) <= (signed) min(text_x + text_w, x + w) &&
678 max(text_ry, y) <= (signed) min(text_ry + text_h, y + h)))
681 // check if we need to redraw the select pixmap/menu bullet
682 if (! (max(sel_x, x) <= (signed) min(sel_x + half_w, x + w) &&
683 max(sel_y, y) <= (signed) min(sel_y + half_w, y + h)))
687 if (dohilite && highlight && (menu.hilite_pixmap != ParentRelative)) {
688 if (menu.hilite_pixmap)
689 XCopyArea(display, menu.hilite_pixmap, menu.frame,
690 screen.getMenuStyle()->hilite_gc, hoff_x, hoff_y,
691 hilite_w, hilite_h, hilite_x, hilite_y);
693 XFillRectangle(display, menu.frame,
694 screen.getMenuStyle()->hilite_gc,
695 hilite_x, hilite_y, hilite_w, hilite_h);
696 } else if (dosel && item->isSelected() &&
697 (menu.sel_pixmap != ParentRelative)) {
699 XCopyArea(display, menu.sel_pixmap, menu.frame,
700 screen.getMenuStyle()->hilite_gc, 0, 0,
701 half_w, half_w, sel_x, sel_y);
703 XFillRectangle(display, menu.frame,
704 screen.getMenuStyle()->hilite_gc,
705 sel_x, sel_y, half_w, half_w);
708 if (dotext && text) {
709 if (i18n.multibyte())
710 XmbDrawString(display, menu.frame, screen.getMenuStyle()->f_fontset,
711 tgc, text_x, text_y, text, len);
713 XDrawString(display, menu.frame, tgc, text_x, text_y, text, len);
716 if (dosel && item->submenu()) {
717 switch (screen.getMenuStyle()->bullet) {
719 XDrawRectangle(display, menu.frame, gc, sel_x, sel_y, half_w, half_w);
725 if (screen.getMenuStyle()->bullet_pos == Right) {
726 tri[0].x = sel_x + quarter_w - 2;
727 tri[0].y = sel_y + quarter_w - 2;
733 tri[0].x = sel_x + quarter_w - 2;
734 tri[0].y = item_y + half_w;
741 XFillPolygon(display, menu.frame, gc, tri, 3, Convex,
748 dia[0].x = sel_x + quarter_w - 3;
749 dia[0].y = item_y + half_w;
757 XFillPolygon(display, menu.frame, gc, dia, 4, Convex,
765 void Basemenu::setLabel(const char *l) {
767 delete [] menu.label;
769 if (l) menu.label = bstrdup(l);
774 void Basemenu::setItemSelected(int index, bool sel) {
775 if (index < 0 || index >= (signed)menuitems.size()) return;
777 BasemenuItem *item = find(index);
780 item->setSelected(sel);
781 if (visible) drawItem(index, (index == which_sub), True);
785 bool Basemenu::isItemSelected(int index) {
786 if (index < 0 || index >= (signed)menuitems.size()) return false;
788 BasemenuItem *item = find(index);
789 if (! item) return false;
791 return item->isSelected();
795 void Basemenu::setItemEnabled(int index, bool enable) {
796 if (index < 0 || index >= (signed)menuitems.size()) return;
798 BasemenuItem *item = find(index);
801 item->setEnabled(enable);
802 if (visible) drawItem(index, (index == which_sub), True);
806 bool Basemenu::isItemEnabled(int index) {
807 if (index < 0 || index >= (signed)menuitems.size()) return false;
809 BasemenuItem *item = find(index);
810 if (! item) return False;
812 return item->isEnabled();
816 void Basemenu::buttonPressEvent(XButtonEvent *be) {
817 if (be->window == menu.frame) {
818 int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
819 int w = (sbl * menu.persub) + i;
821 if (w < (signed)menuitems.size() && w >= 0) {
825 BasemenuItem *item = menuitems[w];
830 drawItem(w, (item->isEnabled()), True);
833 menu.x_move = be->x_root - menu.x;
834 menu.y_move = be->y_root - menu.y;
839 void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
840 if (re->window == menu.title) {
845 drawSubmenu(which_sub);
848 if (re->x >= 0 && re->x <= (signed) menu.width &&
849 re->y >= 0 && re->y <= (signed) menu.title_h)
852 } else if (re->window == menu.frame &&
853 re->x >= 0 && re->x < (signed) menu.width &&
854 re->y >= 0 && re->y < (signed) menu.frame_h) {
855 if (re->button == 3) {
858 int sbl = (re->x / menu.item_w), i = (re->y / menu.item_h),
859 ix = sbl * menu.item_w, iy = i * menu.item_h,
860 w = (sbl * menu.persub) + i,
861 p = (which_sbl * menu.persub) + which_press;
863 if (w < (signed)menuitems.size() && w >= 0) {
864 drawItem(p, (p == which_sub), True);
866 if (p == w && isItemEnabled(w)) {
867 if (re->x > ix && re->x < (signed) (ix + menu.item_w) &&
868 re->y > iy && re->y < (signed) (iy + menu.item_h)) {
869 itemSelected(re->button, w);
873 drawItem(p, False, True);
879 void Basemenu::motionNotifyEvent(XMotionEvent *me) {
880 if (me->window == menu.title && (me->state & Button1Mask)) {
883 if (parent && (! torn)) {
884 parent->drawItem(parent->which_sub, False, True);
885 parent->which_sub = -1;
888 moving = torn = True;
891 drawSubmenu(which_sub);
893 menu.x = me->x_root - menu.x_move,
894 menu.y = me->y_root - menu.y_move;
896 XMoveWindow(display, menu.window, menu.x, menu.y);
899 drawSubmenu(which_sub);
902 } else if ((! (me->state & Button1Mask)) && me->window == menu.frame &&
903 me->x >= 0 && me->x < (signed) menu.width &&
904 me->y >= 0 && me->y < (signed) menu.frame_h) {
905 int sbl = (me->x / menu.item_w), i = (me->y / menu.item_h),
906 w = (sbl * menu.persub) + i;
908 if ((i != which_press || sbl != which_sbl) &&
909 (w < (signed)menuitems.size() && w >= 0)) {
910 if (which_press != -1 && which_sbl != -1) {
911 int p = (which_sbl * menu.persub) + which_press;
912 BasemenuItem *item = menuitems[p];
914 drawItem(p, False, True);
916 if (item->submenu()->isVisible() &&
917 (! item->submenu()->isTorn())) {
918 item->submenu()->internal_hide();
926 BasemenuItem *itmp = menuitems[w];
931 drawItem(w, (itmp->isEnabled()), True);
937 void Basemenu::exposeEvent(XExposeEvent *ee) {
938 if (ee->window == menu.title) {
940 } else if (ee->window == menu.frame) {
941 // this is a compilicated algorithm... lets do it step by step...
942 // first... we see in which sub level the expose starts... and how many
943 // items down in that sublevel
945 int sbl = (ee->x / menu.item_w), id = (ee->y / menu.item_h),
946 // next... figure out how many sublevels over the redraw spans
947 sbl_d = ((ee->x + ee->width) / menu.item_w),
948 // then we see how many items down to redraw
949 id_d = ((ee->y + ee->height) / menu.item_h);
951 if (id_d > menu.persub) id_d = menu.persub;
953 // draw the sublevels and the number of items the exposure spans
954 menuitemList::const_iterator it = menuitems.begin();
956 for (i = sbl; i <= sbl_d; i++) {
957 // set the iterator to the first item in the sublevel needing redrawing
958 it = menuitems.begin() + (id + (i * menu.persub));
959 for (ii = id; ii <= id_d && it != menuitems.end(); it++, ii++) {
960 int index = ii + (i * menu.persub);
962 drawItem(index, (which_sub == index), False,
963 ee->x, ee->y, ee->width, ee->height);
970 void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
971 if (ce->window == menu.frame) {
972 menu.x_shift = menu.x, menu.y_shift = menu.y;
973 if (menu.x + menu.width > screen.size().w()) {
974 menu.x_shift = screen.size().w() - menu.width -
975 screen.getBorderWidth();
977 } else if (menu.x < 0) {
978 menu.x_shift = -screen.getBorderWidth();
982 if (menu.y + menu.height > screen.size().h()) {
983 menu.y_shift = screen.size().h() - menu.height -
984 screen.getBorderWidth();
986 } else if (menu.y + (signed) menu.title_h < 0) {
987 menu.y_shift = -screen.getBorderWidth();
992 XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
994 if (which_sub != -1) {
995 BasemenuItem *tmp = menuitems[which_sub];
996 if (tmp->submenu()->isVisible()) {
997 int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
998 w = (sbl * menu.persub) + i;
1000 if (w != which_sub && (! tmp->submenu()->isTorn())) {
1001 tmp->submenu()->internal_hide();
1003 drawItem(which_sub, False, True);
1012 void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
1013 if (ce->window == menu.frame) {
1014 if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
1015 int p = (which_sbl * menu.persub) + which_press;
1017 drawItem(p, (p == which_sub), True);
1019 which_sbl = which_press = -1;
1023 XMoveWindow(display, menu.window, menu.x, menu.y);
1026 if (which_sub != -1) drawSubmenu(which_sub);
1032 void Basemenu::reconfigure(void) {
1033 XSetWindowBackground(display, menu.window,
1034 screen.getBorderColor()->getPixel());
1035 XSetWindowBorder(display, menu.window,
1036 screen.getBorderColor()->getPixel());
1037 XSetWindowBorderWidth(display, menu.window, screen.getBorderWidth());
1039 menu.bevel_w = screen.getBevelWidth();