summaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Menu.cc179
-rw-r--r--src/FbTk/Menu.hh18
2 files changed, 84 insertions, 113 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index 7ad09ed..204bede 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Menu.cc,v 1.64 2004/06/13 00:42:45 fluxgen Exp $ 25// $Id: Menu.cc,v 1.65 2004/06/13 10:58:34 fluxgen Exp $
26 26
27//use GNU extensions 27//use GNU extensions
28#ifndef _GNU_SOURCE 28#ifndef _GNU_SOURCE
@@ -89,7 +89,6 @@ Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
89 m_screen_width(DisplayWidth(FbTk::App::instance()->display(), tm.screenNum())), 89 m_screen_width(DisplayWidth(FbTk::App::instance()->display(), tm.screenNum())),
90 m_screen_height(DisplayHeight(FbTk::App::instance()->display(), tm.screenNum())), 90 m_screen_height(DisplayHeight(FbTk::App::instance()->display(), tm.screenNum())),
91 m_alignment(ALIGNDONTCARE), 91 m_alignment(ALIGNDONTCARE),
92 m_border_width(0),
93 m_need_update(true) { 92 m_need_update(true) {
94 93
95 // setup timers 94 // setup timers
@@ -106,9 +105,7 @@ Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
106 // make sure we get updated when the theme is reloaded 105 // make sure we get updated when the theme is reloaded
107 tm.reconfigSig().attach(this); 106 tm.reconfigSig().attach(this);
108 107
109 title_vis = 108 title_vis = true;
110 movable =
111 hide_tree = true;
112 109
113 shifted = 110 shifted =
114 internal_menu = 111 internal_menu =
@@ -133,15 +130,13 @@ Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
133 menu.sel_pixmap = None; 130 menu.sel_pixmap = None;
134 131
135 132
136 menu.title_h = menu.item_w = menu.frame_h = 133 menu.item_w = menu.frame_h =
137 theme().titleFont().height() + theme().bevelWidth() * 2; 134 theme().titleFont().height() + theme().bevelWidth() * 2;
138 135
139 menu.sublevels = 136 menu.sublevels =
140 menu.persub = 137 menu.persub =
141 menu.minsub = 0; 138 menu.minsub = 0;
142 139
143 menu.item_h = theme().frameFont().height() + theme().bevelWidth();
144
145 long event_mask = ButtonPressMask | ButtonReleaseMask | 140 long event_mask = ButtonPressMask | ButtonReleaseMask |
146 ButtonMotionMask | KeyPressMask | ExposureMask | FocusChangeMask; 141 ButtonMotionMask | KeyPressMask | ExposureMask | FocusChangeMask;
147 // create menu window 142 // create menu window
@@ -161,7 +156,7 @@ Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
161 event_mask |= EnterWindowMask | LeaveWindowMask; 156 event_mask |= EnterWindowMask | LeaveWindowMask;
162 //create menu title 157 //create menu title
163 menu.title = FbTk::FbWindow(menu.window, // parent 158 menu.title = FbTk::FbWindow(menu.window, // parent
164 0, 0, width(), menu.title_h, // pos and size 159 0, 0, width(), theme().titleHeight(), // pos and size
165 event_mask, // mask 160 event_mask, // mask
166 false, // override redirect 161 false, // override redirect
167 true); // save under 162 true); // save under
@@ -170,16 +165,13 @@ Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
170 165
171 event_mask |= PointerMotionMask; 166 event_mask |= PointerMotionMask;
172 menu.frame = FbTk::FbWindow(menu.window, // parent 167 menu.frame = FbTk::FbWindow(menu.window, // parent
173 0, menu.title_h, // pos 168 0, theme().titleHeight(), // pos
174 width(), menu.frame_h ? menu.frame_h : 1, // size 169 width(), menu.frame_h ? menu.frame_h : 1, // size
175 event_mask, // mask 170 event_mask, // mask
176 false, // override redirect 171 false, // override redirect
177 true); // save under 172 true); // save under
178 evm.add(*this, menu.frame); 173 evm.add(*this, menu.frame);
179 174
180
181 // update style
182 // reconfigure();
183} 175}
184 176
185Menu::~Menu() { 177Menu::~Menu() {
@@ -249,7 +241,7 @@ int Menu::remove(unsigned int index) {
249 241
250 if (item) { 242 if (item) {
251 menuitems.erase(it); 243 menuitems.erase(it);
252 if ((! internal_menu) && (item->submenu())) { 244 if (!internal_menu && item->submenu() != 0) {
253 Menu *tmp = item->submenu(); 245 Menu *tmp = item->submenu();
254 // if menu is interal we should just hide it instead 246 // if menu is interal we should just hide it instead
255 // if destroying it 247 // if destroying it
@@ -388,23 +380,6 @@ void Menu::enableTitle() {
388 380
389void Menu::update(int active_index) { 381void Menu::update(int active_index) {
390 382
391
392 if (m_border_width > 20)
393 m_border_width = 20;
394
395 if (theme().titleHeight() != 0)
396 menu.title_h = std::max(theme().titleHeight(),
397 theme().titleFont().height() + theme().bevelWidth());
398 else
399 menu.title_h = theme().titleFont().height() + theme().bevelWidth()*2;
400
401 if (theme().itemHeight() != 0)
402 menu.item_h = std::max(theme().itemHeight(),
403 theme().frameFont().height() + theme().bevelWidth());
404 else
405 menu.item_h = theme().frameFont().height() +theme().bevelWidth();
406
407
408 if (title_vis) { 383 if (title_vis) {
409 menu.item_w = theme().titleFont().textWidth(menu.label.c_str(), 384 menu.item_w = theme().titleFont().textWidth(menu.label.c_str(),
410 menu.label.size()); 385 menu.label.size());
@@ -424,8 +399,8 @@ void Menu::update(int active_index) {
424 if (!menuitems.empty()) { 399 if (!menuitems.empty()) {
425 menu.sublevels = 1; 400 menu.sublevels = 1;
426 401
427 while (menu.item_h * (menuitems.size() + 1) / menu.sublevels + 402 while (theme().itemHeight() * (menuitems.size() + 1) / menu.sublevels +
428 menu.title_h + m_border_width > m_screen_height) { 403 theme().titleHeight() + theme().borderWidth() > m_screen_height) {
429 menu.sublevels++; 404 menu.sublevels++;
430 } 405 }
431 406
@@ -439,14 +414,14 @@ void Menu::update(int active_index) {
439 menu.persub = 0; 414 menu.persub = 0;
440 } 415 }
441 416
442 int itmp = (menu.item_h * menu.persub); 417 int itmp = (theme().itemHeight() * menu.persub);
443 menu.frame_h = itmp < 0 ? 0 : itmp; 418 menu.frame_h = itmp < 0 ? 0 : itmp;
444 419
445 int new_width = (menu.sublevels * menu.item_w); 420 int new_width = (menu.sublevels * menu.item_w);
446 int new_height = menu.frame_h; 421 int new_height = menu.frame_h;
447 422
448 if (title_vis) 423 if (title_vis)
449 new_height += menu.title_h + ((menu.frame_h>0)?menu.title.borderWidth():0); 424 new_height += theme().titleHeight() + ((menu.frame_h>0)?menu.title.borderWidth():0);
450 425
451 426
452 if (new_width < 1) 427 if (new_width < 1)
@@ -465,7 +440,7 @@ void Menu::update(int active_index) {
465 menu.title_pixmap = None; 440 menu.title_pixmap = None;
466 } else { 441 } else {
467 menu.title_pixmap = 442 menu.title_pixmap =
468 m_image_ctrl.renderImage(width(), menu.title_h, tex); 443 m_image_ctrl.renderImage(width(), theme().titleHeight(), tex);
469 } 444 }
470 445
471 if (tmp) 446 if (tmp)
@@ -474,12 +449,12 @@ void Menu::update(int active_index) {
474 // if new size of title doesn't match our 449 // if new size of title doesn't match our
475 // buffer pixmap -> resize buffer pixmap 450 // buffer pixmap -> resize buffer pixmap
476 if (m_title_pm.width() != width() || 451 if (m_title_pm.width() != width() ||
477 m_title_pm.height() != menu.title_h) { 452 m_title_pm.height() != theme().titleHeight()) {
478 m_title_pm = FbPixmap(menu.title.window(), 453 m_title_pm = FbPixmap(menu.title.window(),
479 width(), menu.title_h, 454 width(), theme().titleHeight(),
480 menu.title.depth()); 455 menu.title.depth());
481 m_real_title_pm = FbPixmap(menu.title.window(), 456 m_real_title_pm = FbPixmap(menu.title.window(),
482 width(), menu.title_h, 457 width(), theme().titleHeight(),
483 menu.title.depth()); 458 menu.title.depth());
484 // set pixmap that we have as real face to the user 459 // set pixmap that we have as real face to the user
485 menu.title.setBackgroundPixmap(m_real_title_pm.drawable()); 460 menu.title.setBackgroundPixmap(m_real_title_pm.drawable());
@@ -532,7 +507,7 @@ void Menu::update(int active_index) {
532 menu.hilite_pixmap = None; 507 menu.hilite_pixmap = None;
533 } else 508 } else
534 menu.hilite_pixmap = 509 menu.hilite_pixmap =
535 m_image_ctrl.renderImage(menu.item_w, menu.item_h, hilite_tex); 510 m_image_ctrl.renderImage(menu.item_w, theme().itemHeight(), hilite_tex);
536 if (tmp) 511 if (tmp)
537 m_image_ctrl.removeImage(tmp); 512 m_image_ctrl.removeImage(tmp);
538 513
@@ -540,7 +515,7 @@ void Menu::update(int active_index) {
540 if (!hilite_tex.usePixmap()) { 515 if (!hilite_tex.usePixmap()) {
541 menu.sel_pixmap = None; 516 menu.sel_pixmap = None;
542 } else { 517 } else {
543 int hw = menu.item_h / 2; 518 int hw = theme().itemHeight() / 2;
544 menu.sel_pixmap = 519 menu.sel_pixmap =
545 m_image_ctrl.renderImage(hw, hw, hilite_tex); 520 m_image_ctrl.renderImage(hw, hw, hilite_tex);
546 } 521 }
@@ -551,7 +526,7 @@ void Menu::update(int active_index) {
551 526
552 if (title_vis) { 527 if (title_vis) {
553 menu.title.moveResize(-menu.title.borderWidth(), -menu.title.borderWidth(), 528 menu.title.moveResize(-menu.title.borderWidth(), -menu.title.borderWidth(),
554 width() + menu.title.borderWidth(), menu.title_h); 529 width() + menu.title.borderWidth(), theme().titleHeight());
555 } 530 }
556 531
557 menu.frame.moveResize(0, ((title_vis) ? menu.title.y() + menu.title.height() + 532 menu.frame.moveResize(0, ((title_vis) ? menu.title.y() + menu.title.height() +
@@ -571,6 +546,7 @@ void Menu::update(int active_index) {
571 menu.frame.depth()); 546 menu.frame.depth());
572 547
573 menu.frame.setBackgroundPixmap(m_real_frame_pm.drawable()); 548 menu.frame.setBackgroundPixmap(m_real_frame_pm.drawable());
549
574 if (m_frame_pm.drawable() == 0) { 550 if (m_frame_pm.drawable() == 0) {
575 _FB_USES_NLS; 551 _FB_USES_NLS;
576 cerr<<"FbTk::Menu: "<<_FBTKTEXT(Error, CreatePixmap, "Error creating pixmap", "Couldn't create a pixmap - image - for some reason")<<" ("<< 552 cerr<<"FbTk::Menu: "<<_FBTKTEXT(Error, CreatePixmap, "Error creating pixmap", "Couldn't create a pixmap - image - for some reason")<<" ("<<
@@ -613,7 +589,8 @@ void Menu::update(int active_index) {
613 if (title_vis && visible) 589 if (title_vis && visible)
614 redrawTitle(); 590 redrawTitle();
615 591
616 if (active_index >= 0 && visible) { 592 if (active_index >= 0 && isVisible()) {
593 move(x(), y());
617 renderTransp(0, 0, 594 renderTransp(0, 0,
618 m_real_frame_pm.width(), m_real_frame_pm.height()); 595 m_real_frame_pm.width(), m_real_frame_pm.height());
619 for (unsigned int i = 0; i < menuitems.size(); i++) { 596 for (unsigned int i = 0; i < menuitems.size(); i++) {
@@ -674,7 +651,7 @@ void Menu::hide() {
674 if (!isVisible()) 651 if (!isVisible())
675 return; 652 return;
676 653
677 if ((! torn) && hide_tree && m_parent && m_parent->isVisible()) { 654 if ((! torn) && m_parent && m_parent->isVisible()) {
678 Menu *p = m_parent; 655 Menu *p = m_parent;
679 656
680 while (p->isVisible() && (! p->torn) && p->m_parent) 657 while (p->isVisible() && (! p->torn) && p->m_parent)
@@ -787,7 +764,7 @@ void Menu::redrawTitle() {
787 screenNumber(), 764 screenNumber(),
788 theme().titleTextGC().gc(), // graphic context 765 theme().titleTextGC().gc(), // graphic context
789 text, len, // text string with lenght 766 text, len, // text string with lenght
790 dx, font.ascent() + theme().bevelWidth()); // position 767 dx, theme().titleHeight()/2 + (font.ascent() + theme().bevelWidth())/2); // position
791} 768}
792 769
793 770
@@ -816,15 +793,15 @@ void Menu::drawSubmenu(unsigned int index) {
816 793
817 if (m_alignment == ALIGNTOP) { 794 if (m_alignment == ALIGNTOP) {
818 new_y = (((shifted) ? menu.y_shift : y()) + 795 new_y = (((shifted) ? menu.y_shift : y()) +
819 ((title_vis) ? menu.title_h + menu.title.borderWidth() : 0) - 796 ((title_vis) ? theme().titleHeight() + menu.title.borderWidth() : 0) -
820 ((item->submenu()->title_vis) ? 797 ((item->submenu()->title_vis) ?
821 item->submenu()->menu.title_h + menu.window.borderWidth() : 0)); 798 item->submenu()->theme().titleHeight() + menu.window.borderWidth() : 0));
822 } else { 799 } else {
823 new_y = (((shifted) ? menu.y_shift : y()) + 800 new_y = (((shifted) ? menu.y_shift : y()) +
824 (menu.item_h * i) + 801 (theme().itemHeight() * i) +
825 ((title_vis) ? menu.title_h + menu.window.borderWidth() : 0) - 802 ((title_vis) ? theme().titleHeight() + menu.window.borderWidth() : 0) -
826 ((item->submenu()->title_vis) ? 803 ((item->submenu()->title_vis) ?
827 item->submenu()->menu.title_h + menu.window.borderWidth() : 0)); 804 item->submenu()->theme().titleHeight() + menu.window.borderWidth() : 0));
828 } 805 }
829 806
830 if (m_alignment == ALIGNBOTTOM && 807 if (m_alignment == ALIGNBOTTOM &&
@@ -890,11 +867,11 @@ int Menu::drawItem(unsigned int index, bool highlight, bool clear, bool render_t
890 if (! item) return 0; 867 if (! item) return 0;
891 868
892 int sbl = index / menu.persub, i = index - (sbl * menu.persub); 869 int sbl = index / menu.persub, i = index - (sbl * menu.persub);
893 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h); 870 int item_x = (sbl * menu.item_w), item_y = (i * theme().itemHeight());
894 int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0; 871 int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
895 int sel_x = 0, sel_y = 0; 872 int sel_x = 0, sel_y = 0;
896 unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h; 873 unsigned int hilite_w = menu.item_w, hilite_h = theme().itemHeight();
897 unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4; 874 unsigned int half_w = theme().itemHeight() / 2, quarter_w = theme().itemHeight() / 4;
898 875
899 GC gc = 876 GC gc =
900 ((highlight || item->isSelected()) ? theme().hiliteTextGC().gc() : 877 ((highlight || item->isSelected()) ? theme().hiliteTextGC().gc() :
@@ -903,7 +880,7 @@ int Menu::drawItem(unsigned int index, bool highlight, bool clear, bool render_t
903 sel_x = item_x; 880 sel_x = item_x;
904 881
905 if (theme().bulletPos() == FbTk::RIGHT) 882 if (theme().bulletPos() == FbTk::RIGHT)
906 sel_x += (menu.item_w - menu.item_h - theme().bevelWidth()); 883 sel_x += (menu.item_w - theme().itemHeight() - theme().bevelWidth());
907 884
908 sel_x += quarter_w; 885 sel_x += quarter_w;
909 sel_y = item_y + quarter_w; 886 sel_y = item_y + quarter_w;
@@ -912,25 +889,25 @@ int Menu::drawItem(unsigned int index, bool highlight, bool clear, bool render_t
912 GContext def_gc(menu.frame); 889 GContext def_gc(menu.frame);
913 if (menu.frame_pixmap == 0) { 890 if (menu.frame_pixmap == 0) {
914 def_gc.setForeground(theme().frameTexture().color()); 891 def_gc.setForeground(theme().frameTexture().color());
915 m_frame_pm.fillRectangle(def_gc.gc(), item_x, item_y, menu.item_w, menu.item_h); 892 m_frame_pm.fillRectangle(def_gc.gc(), item_x, item_y, menu.item_w, theme().itemHeight());
916 893
917 } else { 894 } else {
918 895
919 m_frame_pm.copyArea(menu.frame_pixmap, def_gc.gc(), 896 m_frame_pm.copyArea(menu.frame_pixmap, def_gc.gc(),
920 item_x, item_y, 897 item_x, item_y,
921 item_x, item_y, 898 item_x, item_y,
922 menu.item_w, menu.item_h); 899 menu.item_w, theme().itemHeight());
923 } 900 }
924 } else if (! (x == y && y == -1 && w == h && h == 0)) { 901 } else if (! (x == y && y == -1 && w == h && h == 0)) {
925 // calculate the which part of the hilite to redraw 902 // calculate the which part of the hilite to redraw
926 if (!(std::max(item_x, x) <= (signed) std::min(item_x + menu.item_w, x + w) && 903 if (!(std::max(item_x, x) <= (signed) std::min(item_x + menu.item_w, x + w) &&
927 std::max(item_y, y) <= (signed) std::min(item_y + menu.item_h, y + h))) { 904 std::max(item_y, y) <= (signed) std::min(item_y + theme().itemHeight(), y + h))) {
928 hilite_x = std::max(item_x, x); 905 hilite_x = std::max(item_x, x);
929 hilite_y = std::max(item_y, y); 906 hilite_y = std::max(item_y, y);
930 hilite_w = std::min(item_x + menu.item_w, x + w) - hilite_x; 907 hilite_w = std::min(item_x + menu.item_w, x + w) - hilite_x;
931 hilite_h = std::min(item_y + menu.item_h, y + h) - hilite_y; 908 hilite_h = std::min(item_y + theme().itemHeight(), y + h) - hilite_y;
932 hoff_x = hilite_x % menu.item_w; 909 hoff_x = hilite_x % menu.item_w;
933 hoff_y = hilite_y % menu.item_h; 910 hoff_y = hilite_y % theme().itemHeight();
934 } 911 }
935 912
936 } 913 }
@@ -985,16 +962,16 @@ int Menu::drawItem(unsigned int index, bool highlight, bool clear, bool render_t
985 962
986 if (render_trans) 963 if (render_trans)
987 renderTransp(item_x, item_y, 964 renderTransp(item_x, item_y,
988 width(), menu.item_h); 965 width(), theme().itemHeight());
989 966
990 item->draw(m_real_frame_pm, theme(), highlight, 967 item->draw(m_real_frame_pm, theme(), highlight,
991 item_x, item_y, 968 item_x, item_y,
992 menu.item_w, menu.item_h); 969 menu.item_w, theme().itemHeight());
993 970
994 971
995 if (clear) 972 if (clear)
996 menu.frame.clearArea(item_x, item_y, 973 menu.frame.clearArea(item_x, item_y,
997 menu.item_w, menu.item_h, False); 974 menu.item_w, theme().itemHeight(), False);
998 975
999 976
1000 return item_y; 977 return item_y;
@@ -1064,9 +1041,9 @@ void Menu::buttonPressEvent(XButtonEvent &be) {
1064 if (be.window == menu.title) 1041 if (be.window == menu.title)
1065 grabInputFocus(); 1042 grabInputFocus();
1066 1043
1067 if (be.window == menu.frame && menu.item_h != 0 && menu.item_w != 0) { 1044 if (be.window == menu.frame && menu.item_w != 0) {
1068 1045
1069 int sbl = (be.x / menu.item_w), i = (be.y / menu.item_h); 1046 int sbl = (be.x / menu.item_w), i = (be.y / theme().itemHeight());
1070 int w = (sbl * menu.persub) + i; 1047 int w = (sbl * menu.persub) + i;
1071 1048
1072 if (w < static_cast<int>(menuitems.size()) && w >= 0) { 1049 if (w < static_cast<int>(menuitems.size()) && w >= 0) {
@@ -1097,7 +1074,7 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) {
1097 } 1074 }
1098 1075
1099 if (re.x >= 0 && re.x <= (signed) width() && 1076 if (re.x >= 0 && re.x <= (signed) width() &&
1100 re.y >= 0 && re.y <= (signed) menu.title_h && 1077 re.y >= 0 && re.y <= (signed) theme().titleHeight() &&
1101 re.button == 3) 1078 re.button == 3)
1102 hide(); 1079 hide();
1103 1080
@@ -1105,15 +1082,15 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) {
1105 re.x >= 0 && re.x < (signed) width() && 1082 re.x >= 0 && re.x < (signed) width() &&
1106 re.y >= 0 && re.y < (signed) menu.frame_h) { 1083 re.y >= 0 && re.y < (signed) menu.frame_h) {
1107 1084
1108 int sbl = (re.x / menu.item_w), i = (re.y / menu.item_h), 1085 int sbl = (re.x / menu.item_w), i = (re.y / theme().itemHeight()),
1109 ix = sbl * menu.item_w, iy = i * menu.item_h, 1086 ix = sbl * menu.item_w, iy = i * theme().itemHeight(),
1110 w = (sbl * menu.persub) + i, 1087 w = (sbl * menu.persub) + i,
1111 p = (which_sbl * menu.persub) + which_press; 1088 p = (which_sbl * menu.persub) + which_press;
1112 1089
1113 if (w < static_cast<int>(menuitems.size()) && w >= 0) { 1090 if (w < static_cast<int>(menuitems.size()) && w >= 0) {
1114 if (p == w && isItemEnabled(w)) { 1091 if (p == w && isItemEnabled(w)) {
1115 if (re.x > ix && re.x < (signed) (ix + menu.item_w) && 1092 if (re.x > ix && re.x < (signed) (ix + menu.item_w) &&
1116 re.y > iy && re.y < (signed) (iy + menu.item_h)) { 1093 re.y > iy && re.y < (signed) (iy + theme().itemHeight())) {
1117 menuitems[w]->click(re.button, re.time); 1094 menuitems[w]->click(re.button, re.time);
1118 itemSelected(re.button, w); 1095 itemSelected(re.button, w);
1119 // just redraw this item 1096 // just redraw this item
@@ -1132,30 +1109,29 @@ void Menu::motionNotifyEvent(XMotionEvent &me) {
1132 // if draging the with the titlebar: 1109 // if draging the with the titlebar:
1133 if (me.window == menu.title && (me.state & Button1Mask)) { 1110 if (me.window == menu.title && (me.state & Button1Mask)) {
1134 stopHide(); 1111 stopHide();
1135 if (movable) {
1136 if (! moving) {
1137 // if not moving: start moving operation
1138 if (m_parent && (! torn)) {
1139 m_parent->drawItem(m_parent->which_sub, false, true, true);
1140 m_parent->which_sub = -1;
1141 }
1142 1112
1143 moving = torn = true; 1113 if (! moving) {
1114 // if not moving: start moving operation
1115 if (m_parent && (! torn)) {
1116 m_parent->drawItem(m_parent->which_sub, false, true, true);
1117 m_parent->which_sub = -1;
1118 }
1144 1119
1145 if (which_sub >= 0) 1120 moving = torn = true;
1146 drawSubmenu(which_sub);
1147 } else {
1148 menu.window.move(me.x_root - menu.x_move, me.y_root - menu.y_move);
1149 1121
1150 // if (which_sub >= 0) 1122 if (which_sub >= 0)
1151 // drawSubmenu(which_sub); 1123 drawSubmenu(which_sub);
1152 } 1124 } else {
1125 // we dont call ::move here 'cause we dont want to update transparency
1126 // while draging the menu (which is slow)
1127 menu.window.move(me.x_root - menu.x_move, me.y_root - menu.y_move);
1153 } 1128 }
1129
1154 } else if ((! (me.state & Button1Mask)) && me.window == menu.frame && 1130 } else if ((! (me.state & Button1Mask)) && me.window == menu.frame &&
1155 me.x >= 0 && me.x < (signed) width() && 1131 me.x >= 0 && me.x < (signed) width() &&
1156 me.y >= 0 && me.y < (signed) menu.frame_h) { 1132 me.y >= 0 && me.y < (signed) menu.frame_h) {
1157 stopHide(); 1133 stopHide();
1158 int sbl = (me.x / menu.item_w), i = (me.y / menu.item_h), 1134 int sbl = (me.x / menu.item_w), i = (me.y / theme().itemHeight()),
1159 w = (sbl * menu.persub) + i; 1135 w = (sbl * menu.persub) + i;
1160 1136
1161 if ((i != which_press || sbl != which_sbl) && 1137 if ((i != which_press || sbl != which_sbl) &&
@@ -1235,13 +1211,12 @@ void Menu::exposeEvent(XExposeEvent &ee) {
1235 1211
1236 if (menu.item_w == 0) 1212 if (menu.item_w == 0)
1237 menu.item_w = 1; 1213 menu.item_w = 1;
1238 if (menu.item_h == 0) 1214
1239 menu.item_h = 1;
1240 unsigned int 1215 unsigned int
1241 start_column = (ee.x / menu.item_w), 1216 start_column = (ee.x / menu.item_w),
1242 end_column = ((ee.x + ee.width) / menu.item_w), 1217 end_column = ((ee.x + ee.width) / menu.item_w),
1243 start_row = (ee.y / menu.item_h), 1218 start_row = (ee.y / theme().itemHeight()),
1244 end_row = ((ee.y + ee.height) / menu.item_h); 1219 end_row = ((ee.y + ee.height) / theme().itemHeight());
1245 if (static_cast<signed>(end_row) > menu.persub) 1220 if (static_cast<signed>(end_row) > menu.persub)
1246 end_row = menu.persub; 1221 end_row = menu.persub;
1247 1222
@@ -1277,18 +1252,18 @@ void Menu::enterNotifyEvent(XCrossingEvent &ce) {
1277 1252
1278 menu.x_shift = x(), menu.y_shift = y(); 1253 menu.x_shift = x(), menu.y_shift = y();
1279 if (x() + width() > m_screen_width) { 1254 if (x() + width() > m_screen_width) {
1280 menu.x_shift = m_screen_width - width() - 2*m_border_width; 1255 menu.x_shift = m_screen_width - width() - 2*theme().borderWidth();
1281 shifted = true; 1256 shifted = true;
1282 } else if (x() < 0) { 1257 } else if (x() < 0) {
1283 menu.x_shift = 0; //-m_border_width; 1258 menu.x_shift = 0; //-theme().borderWidth();
1284 shifted = true; 1259 shifted = true;
1285 } 1260 }
1286 1261
1287 if (y() + height() + 2*m_border_width > m_screen_height) { 1262 if (y() + height() + 2*theme().borderWidth() > m_screen_height) {
1288 menu.y_shift = m_screen_height - height() - 2*m_border_width; 1263 menu.y_shift = m_screen_height - height() - 2*theme().borderWidth();
1289 shifted = true; 1264 shifted = true;
1290 } else if (y() + (signed) menu.title_h < 0) { 1265 } else if (y() + (signed) theme().titleHeight() < 0) {
1291 menu.y_shift = 0; // -m_border_width;; 1266 menu.y_shift = 0; // -theme().borderWidth();;
1292 shifted = true; 1267 shifted = true;
1293 } 1268 }
1294 1269
@@ -1299,7 +1274,7 @@ void Menu::enterNotifyEvent(XCrossingEvent &ce) {
1299 if (which_sub >= 0 && static_cast<size_t>(which_sub) < menuitems.size()) { 1274 if (which_sub >= 0 && static_cast<size_t>(which_sub) < menuitems.size()) {
1300 MenuItem *tmp = menuitems[which_sub]; 1275 MenuItem *tmp = menuitems[which_sub];
1301 if (tmp->submenu()->isVisible()) { 1276 if (tmp->submenu()->isVisible()) {
1302 int sbl = (ce.x / menu.item_w), i = (ce.y / menu.item_h), 1277 int sbl = (ce.x / menu.item_w), i = (ce.y / theme().itemHeight()),
1303 w = (sbl * menu.persub) + i; 1278 w = (sbl * menu.persub) + i;
1304 1279
1305 if (w != which_sub && (! tmp->submenu()->isTorn())) { 1280 if (w != which_sub && (! tmp->submenu()->isTorn())) {
@@ -1386,12 +1361,6 @@ void Menu::reconfigure() {
1386 1361
1387 m_need_update = true; // redraw items 1362 m_need_update = true; // redraw items
1388 1363
1389 m_border_width = theme().borderWidth();
1390
1391 if (m_border_width > 20) // clamp to normal size
1392 m_border_width = 20;
1393 if (m_border_width < 0)
1394 m_border_width = 0;
1395 1364
1396 menu.title.setAlpha(alpha()); 1365 menu.title.setAlpha(alpha());
1397 1366
@@ -1399,8 +1368,8 @@ void Menu::reconfigure() {
1399 menu.title.setBorderColor(theme().borderColor()); 1368 menu.title.setBorderColor(theme().borderColor());
1400 menu.frame.setBorderColor(theme().borderColor()); 1369 menu.frame.setBorderColor(theme().borderColor());
1401 1370
1402 menu.window.setBorderWidth(m_border_width); 1371 menu.window.setBorderWidth(theme().borderWidth());
1403 menu.title.setBorderWidth(m_border_width); 1372 menu.title.setBorderWidth(theme().borderWidth());
1404 1373
1405 1374
1406 update(); 1375 update();
@@ -1466,7 +1435,7 @@ void Menu::renderTransp(int x, int y,
1466 1435
1467 if (m_transp.get() == 0) 1436 if (m_transp.get() == 0)
1468 return; 1437 return;
1469 1438
1470#ifdef HAVE_XRENDER 1439#ifdef HAVE_XRENDER
1471 1440
1472 Pixmap root = getRootPixmap(screenNumber()); 1441 Pixmap root = getRootPixmap(screenNumber());
@@ -1501,7 +1470,7 @@ void Menu::renderTransp(int x, int y,
1501 width, height); 1470 width, height);
1502 1471
1503#endif // HAVE_XRENDER 1472#endif // HAVE_XRENDER
1504 1473
1505} 1474}
1506 1475
1507}; // end namespace FbTk 1476}; // end namespace FbTk
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 6227c07..2d2d62d 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Menu.hh,v 1.34 2004/06/13 00:31:29 fluxgen Exp $ 25// $Id: Menu.hh,v 1.35 2004/06/13 10:58:34 fluxgen Exp $
26 26
27#ifndef FBTK_MENU_HH 27#ifndef FBTK_MENU_HH
28#define FBTK_MENU_HH 28#define FBTK_MENU_HH
@@ -146,7 +146,6 @@ public:
146 inline unsigned int height() const { return menu.window.height(); } 146 inline unsigned int height() const { return menu.window.height(); }
147 inline unsigned int numberOfItems() const { return menuitems.size(); } 147 inline unsigned int numberOfItems() const { return menuitems.size(); }
148 inline int currentSubmenu() const { return which_sub; } 148 inline int currentSubmenu() const { return which_sub; }
149 inline unsigned int titleHeight() const { return menu.title_h; }
150 bool hasSubmenu(unsigned int index) const; 149 bool hasSubmenu(unsigned int index) const;
151 bool isItemSelected(unsigned int index) const; 150 bool isItemSelected(unsigned int index) const;
152 bool isItemEnabled(unsigned int index) const; 151 bool isItemEnabled(unsigned int index) const;
@@ -161,8 +160,6 @@ public:
161protected: 160protected:
162 161
163 inline void setTitleVisibility(bool b) { title_vis = b; m_need_update = true; } 162 inline void setTitleVisibility(bool b) { title_vis = b; m_need_update = true; }
164 inline void setMovable(bool b) { movable = b; }
165 inline void setHideTree(bool h) { hide_tree = h; }
166 163
167 virtual void itemSelected(int button, unsigned int index) { } 164 virtual void itemSelected(int button, unsigned int index) { }
168 virtual int drawItem(unsigned int index, bool highlight = false, 165 virtual int drawItem(unsigned int index, bool highlight = false,
@@ -192,12 +189,16 @@ private:
192 Menuitems menuitems; 189 Menuitems menuitems;
193 190
194 const unsigned int m_screen_width, m_screen_height; 191 const unsigned int m_screen_width, m_screen_height;
195 bool moving, visible, movable, torn, internal_menu, title_vis, shifted, 192 bool moving; ///< if we're moving/draging or not
196 hide_tree; 193 bool visible; ///< menu visibility
194 bool torn; ///< torn from parent
195 bool internal_menu; ///< whether we should destroy this menu or if it's managed somewhere else
196 bool title_vis; ///< title visibility
197 bool shifted; ///< if the menu is shifted to the other side of the parent
197 198
198 int which_sub, which_press, which_sbl; 199 int which_sub, which_press, which_sbl;
199 Alignment m_alignment; 200 Alignment m_alignment;
200 int m_border_width; 201
201 struct _menu { 202 struct _menu {
202 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; 203 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
203 FbTk::FbWindow window, frame, title; 204 FbTk::FbWindow window, frame, title;
@@ -205,7 +206,8 @@ private:
205 std::string label; 206 std::string label;
206 int x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, 207 int x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
207 grab_x, grab_y; 208 grab_x, grab_y;
208 unsigned int title_h, frame_h, item_w, item_h, bevel_w; 209
210 unsigned int frame_h, item_w;
209 } menu; 211 } menu;
210 212
211 Drawable m_root_pm; 213 Drawable m_root_pm;