aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-12-10 23:08:06 (GMT)
committerfluxgen <fluxgen>2003-12-10 23:08:06 (GMT)
commit5ffb6290c12adc5c45a50758f90549fdfc693216 (patch)
tree6bed529f1d556b571dc0b6bfee5665aca408a6d9 /src/FbTk
parentcb8e8e8d054b044db602326278055dc10f1c0c57 (diff)
downloadfluxbox_paul-5ffb6290c12adc5c45a50758f90549fdfc693216.zip
fluxbox_paul-5ffb6290c12adc5c45a50758f90549fdfc693216.tar.bz2
cleaning in the menu code
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Menu.cc113
-rw-r--r--src/FbTk/Menu.hh14
2 files changed, 51 insertions, 76 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index e2aa3c5..59cc310 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.43 2003/11/28 23:26:27 fluxgen Exp $ 25// $Id: Menu.cc,v 1.44 2003/12/10 23:08:06 fluxgen Exp $
26 26
27//use GNU extensions 27//use GNU extensions
28#ifndef _GNU_SOURCE 28#ifndef _GNU_SOURCE
@@ -48,45 +48,18 @@
48 48
49using namespace std; 49using namespace std;
50 50
51namespace {
52Pixmap getRootPixmap(int screen_num) {
53 Pixmap root_pm = 0;
54 // get root pixmap for transparency
55 Display *disp = FbTk::App::instance()->display();
56 Atom real_type;
57 int real_format;
58 unsigned long items_read, items_left;
59 unsigned int *data;
60 if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
61 XInternAtom(disp, "_XROOTPMAP_ID", false),
62 0L, 1L,
63 false, XA_PIXMAP, &real_type,
64 &real_format, &items_read, &items_left,
65 (unsigned char **) &data) == Success &&
66 items_read) {
67 root_pm = (Pixmap) (*data);
68 XFree(data);
69 }
70
71 return root_pm;
72}
73
74}; // end anonymous namespace
75
76namespace FbTk { 51namespace FbTk {
77 52
78static Menu *shown = 0; 53static Menu *shown = 0;
79 54
80Menu *Menu::s_focused = 0; 55Menu *Menu::s_focused = 0;
81 56
82Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl): 57Menu::Menu(MenuTheme &tm, ImageControl &imgctrl):
83 m_theme(tm), 58 m_theme(tm),
84 m_screen_num(screen_num),
85 m_image_ctrl(imgctrl), 59 m_image_ctrl(imgctrl),
86 m_display(FbTk::App::instance()->display()),
87 m_parent(0), 60 m_parent(0),
88 m_screen_width(DisplayWidth(m_display, screen_num)), 61 m_screen_width(DisplayWidth(FbTk::App::instance()->display(), tm.screenNum())),
89 m_screen_height(DisplayHeight(m_display, screen_num)), 62 m_screen_height(DisplayHeight(FbTk::App::instance()->display(), tm.screenNum())),
90 m_alignment(ALIGNDONTCARE), 63 m_alignment(ALIGNDONTCARE),
91 m_border_width(0), 64 m_border_width(0),
92 m_themeobserver(*this), 65 m_themeobserver(*this),
@@ -123,7 +96,7 @@ Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl):
123 96
124 menu.bevel_w = 2; 97 menu.bevel_w = 2;
125 98
126 menu.width = menu.title_h = menu.item_w = menu.frame_h = 99 menu.title_h = menu.item_w = menu.frame_h =
127 m_theme.titleFont().height() + menu.bevel_w * 2; 100 m_theme.titleFont().height() + menu.bevel_w * 2;
128 101
129 menu.sublevels = 102 menu.sublevels =
@@ -132,13 +105,11 @@ Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl):
132 105
133 menu.item_h = m_theme.frameFont().height() + menu.bevel_w; 106 menu.item_h = m_theme.frameFont().height() + menu.bevel_w;
134 107
135 menu.height = menu.title_h + 2 + menu.frame_h;
136
137 long event_mask = ButtonPressMask | ButtonReleaseMask | 108 long event_mask = ButtonPressMask | ButtonReleaseMask |
138 ButtonMotionMask | KeyPressMask | ExposureMask | FocusChangeMask; 109 ButtonMotionMask | KeyPressMask | ExposureMask | FocusChangeMask;
139 //create menu window 110 // create menu window
140 menu.window = FbTk::FbWindow(screen_num, 111 menu.window = FbTk::FbWindow(tm.screenNum(),
141 menu.x, menu.y, menu.width, menu.height, 112 0, 0, 10, 10,
142 event_mask, 113 event_mask,
143 true); // override redirect 114 true); // override redirect
144 115
@@ -152,7 +123,7 @@ Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl):
152 event_mask |= EnterWindowMask | LeaveWindowMask; 123 event_mask |= EnterWindowMask | LeaveWindowMask;
153 //create menu title 124 //create menu title
154 menu.title = FbTk::FbWindow(menu.window, 125 menu.title = FbTk::FbWindow(menu.window,
155 0, 0, menu.width, menu.height, 126 0, 0, width(), menu.title_h,
156 event_mask); 127 event_mask);
157 128
158 evm.add(*this, menu.title); 129 evm.add(*this, menu.title);
@@ -160,7 +131,7 @@ Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl):
160 event_mask |= PointerMotionMask; 131 event_mask |= PointerMotionMask;
161 menu.frame = FbTk::FbWindow(menu.window, 132 menu.frame = FbTk::FbWindow(menu.window,
162 0, menu.title_h, 133 0, menu.title_h,
163 menu.width, menu.frame_h, 134 width(), menu.frame_h ? menu.frame_h : 1,
164 event_mask); 135 event_mask);
165 evm.add(*this, menu.frame); 136 evm.add(*this, menu.frame);
166 // update style 137 // update style
@@ -421,30 +392,36 @@ void Menu::update(int active_index) {
421 menu.persub = 0; 392 menu.persub = 0;
422 } 393 }
423 394
424 menu.width = (menu.sublevels * (menu.item_w));
425 if (! menu.width) menu.width = menu.item_w;
426
427 menu.frame_h = (menu.item_h * menu.persub); 395 menu.frame_h = (menu.item_h * menu.persub);
428 if (menu.frame_h < 0) 396 if (menu.frame_h < 0)
429 menu.frame_h = 0; 397 menu.frame_h = 0;
430 398
431 menu.height = menu.frame_h; 399
400 int new_width = (menu.sublevels * menu.item_w);
401 int new_height = menu.frame_h;
402
432 if (title_vis) 403 if (title_vis)
433 menu.height += menu.title_h + ((menu.frame_h>0)?menu.title.borderWidth():0); 404 new_height += menu.title_h + ((menu.frame_h>0)?menu.title.borderWidth():0);
405
406
407 if (new_width < 1)
408 new_width = menu.item_w;
409
410 if (new_height < 1)
411 new_height = 1;
434 412
435 if (menu.height < 1) 413 menu.window.resize(new_width, new_height);
436 menu.height = 1;
437 414
438 Pixmap tmp; 415 Pixmap tmp;
439 if (title_vis) { 416 if (title_vis) {
440 tmp = menu.title_pixmap; 417 tmp = menu.title_pixmap;
441 const FbTk::Texture &tex = m_theme.titleTexture(); 418 const FbTk::Texture &tex = m_theme.titleTexture();
442 if (tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { 419 if (!tex.usePixmap()) {
443 menu.title_pixmap = None; 420 menu.title_pixmap = None;
444 menu.title.setBackgroundColor(tex.color()); 421 menu.title.setBackgroundColor(tex.color());
445 } else { 422 } else {
446 menu.title_pixmap = 423 menu.title_pixmap =
447 m_image_ctrl.renderImage(menu.width, menu.title_h, tex); 424 m_image_ctrl.renderImage(width(), menu.title_h, tex);
448 menu.title.setBackgroundPixmap(menu.title_pixmap); 425 menu.title.setBackgroundPixmap(menu.title_pixmap);
449 } 426 }
450 427
@@ -455,11 +432,11 @@ void Menu::update(int active_index) {
455 432
456 tmp = menu.frame_pixmap; 433 tmp = menu.frame_pixmap;
457 const FbTk::Texture &frame_tex = m_theme.frameTexture(); 434 const FbTk::Texture &frame_tex = m_theme.frameTexture();
458 if (frame_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { 435 if (!frame_tex.usePixmap()) {
459 menu.frame_pixmap = None; 436 menu.frame_pixmap = None;
460 } else { 437 } else {
461 menu.frame_pixmap = 438 menu.frame_pixmap =
462 m_image_ctrl.renderImage(menu.width, menu.frame_h, frame_tex); 439 m_image_ctrl.renderImage(width(), menu.frame_h, frame_tex);
463 } 440 }
464 441
465 if (tmp) 442 if (tmp)
@@ -467,18 +444,18 @@ void Menu::update(int active_index) {
467 444
468 tmp = menu.hilite_pixmap; 445 tmp = menu.hilite_pixmap;
469 const FbTk::Texture &hilite_tex = m_theme.hiliteTexture(); 446 const FbTk::Texture &hilite_tex = m_theme.hiliteTexture();
470 if (hilite_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) 447 if (!hilite_tex.usePixmap()) {
471 menu.hilite_pixmap = None; 448 menu.hilite_pixmap = None;
472 else 449 } else
473 menu.hilite_pixmap = 450 menu.hilite_pixmap =
474 m_image_ctrl.renderImage(menu.item_w, menu.item_h, hilite_tex); 451 m_image_ctrl.renderImage(menu.item_w, menu.item_h, hilite_tex);
475 if (tmp) 452 if (tmp)
476 m_image_ctrl.removeImage(tmp); 453 m_image_ctrl.removeImage(tmp);
477 454
478 tmp = menu.sel_pixmap; 455 tmp = menu.sel_pixmap;
479 if (hilite_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) 456 if (!hilite_tex.usePixmap()) {
480 menu.sel_pixmap = None; 457 menu.sel_pixmap = None;
481 else { 458 } else {
482 int hw = menu.item_h / 2; 459 int hw = menu.item_h / 2;
483 menu.sel_pixmap = 460 menu.sel_pixmap =
484 m_image_ctrl.renderImage(hw, hw, hilite_tex); 461 m_image_ctrl.renderImage(hw, hw, hilite_tex);
@@ -486,11 +463,11 @@ void Menu::update(int active_index) {
486 if (tmp) 463 if (tmp)
487 m_image_ctrl.removeImage(tmp); 464 m_image_ctrl.removeImage(tmp);
488 465
489 menu.window.resize(menu.width, menu.height); 466
490 467
491 if (title_vis) { 468 if (title_vis) {
492 menu.title.moveResize(-menu.title.borderWidth(), -menu.title.borderWidth(), 469 menu.title.moveResize(-menu.title.borderWidth(), -menu.title.borderWidth(),
493 menu.width + menu.title.borderWidth(), menu.title_h); 470 width() + menu.title.borderWidth(), menu.title_h);
494 } 471 }
495 472
496 menu.frame.moveResize(0, ((title_vis) ? menu.title.y() + menu.title.height() + 473 menu.frame.moveResize(0, ((title_vis) ? menu.title.y() + menu.title.height() +
@@ -637,11 +614,11 @@ void Menu::redrawTitle() {
637 614
638 switch (m_theme.titleFontJustify()) { 615 switch (m_theme.titleFontJustify()) {
639 case FbTk::RIGHT: 616 case FbTk::RIGHT:
640 dx += menu.width - l; 617 dx += width() - l;
641 break; 618 break;
642 619
643 case FbTk::CENTER: 620 case FbTk::CENTER:
644 dx += (menu.width - l) / 2; 621 dx += (width() - l) / 2;
645 break; 622 break;
646 default: 623 default:
647 break; 624 break;
@@ -695,10 +672,10 @@ void Menu::drawSubmenu(unsigned int index) {
695 } 672 }
696 673
697 if (m_alignment == ALIGNBOTTOM && 674 if (m_alignment == ALIGNBOTTOM &&
698 (y + item->submenu()->menu.height) > ((shifted) ? menu.y_shift : 675 (y + item->submenu()->height()) > ((shifted) ? menu.y_shift :
699 menu.y) + menu.height) { 676 menu.y) + height()) {
700 y = (((shifted) ? menu.y_shift : menu.y) + 677 y = (((shifted) ? menu.y_shift : menu.y) +
701 menu.height - item->submenu()->menu.height); 678 height() - item->submenu()->height());
702 } 679 }
703 680
704 if ((x + item->submenu()->width()) > m_screen_width) { 681 if ((x + item->submenu()->width()) > m_screen_width) {
@@ -1090,13 +1067,13 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) {
1090 update(); 1067 update();
1091 } 1068 }
1092 1069
1093 if (re.x >= 0 && re.x <= (signed) menu.width && 1070 if (re.x >= 0 && re.x <= (signed) width() &&
1094 re.y >= 0 && re.y <= (signed) menu.title_h && 1071 re.y >= 0 && re.y <= (signed) menu.title_h &&
1095 re.button == 3) 1072 re.button == 3)
1096 hide(); 1073 hide();
1097 1074
1098 } else if (re.window == menu.frame && 1075 } else if (re.window == menu.frame &&
1099 re.x >= 0 && re.x < (signed) menu.width && 1076 re.x >= 0 && re.x < (signed) width() &&
1100 re.y >= 0 && re.y < (signed) menu.frame_h) { 1077 re.y >= 0 && re.y < (signed) menu.frame_h) {
1101 1078
1102 int sbl = (re.x / menu.item_w), i = (re.y / menu.item_h), 1079 int sbl = (re.x / menu.item_w), i = (re.y / menu.item_h),
@@ -1147,7 +1124,7 @@ void Menu::motionNotifyEvent(XMotionEvent &me) {
1147 } 1124 }
1148 } 1125 }
1149 } else if ((! (me.state & Button1Mask)) && me.window == menu.frame && 1126 } else if ((! (me.state & Button1Mask)) && me.window == menu.frame &&
1150 me.x >= 0 && me.x < (signed) menu.width && 1127 me.x >= 0 && me.x < (signed) width() &&
1151 me.y >= 0 && me.y < (signed) menu.frame_h) { 1128 me.y >= 0 && me.y < (signed) menu.frame_h) {
1152 int sbl = (me.x / menu.item_w), i = (me.y / menu.item_h), 1129 int sbl = (me.x / menu.item_w), i = (me.y / menu.item_h),
1153 w = (sbl * menu.persub) + i; 1130 w = (sbl * menu.persub) + i;
@@ -1230,16 +1207,16 @@ void Menu::enterNotifyEvent(XCrossingEvent &ce) {
1230 return; 1207 return;
1231 1208
1232 menu.x_shift = menu.x, menu.y_shift = menu.y; 1209 menu.x_shift = menu.x, menu.y_shift = menu.y;
1233 if (menu.x + menu.width > m_screen_width) { 1210 if (menu.x + width() > m_screen_width) {
1234 menu.x_shift = m_screen_width - menu.width - 2*m_border_width; 1211 menu.x_shift = m_screen_width - width() - 2*m_border_width;
1235 shifted = true; 1212 shifted = true;
1236 } else if (menu.x < 0) { 1213 } else if (menu.x < 0) {
1237 menu.x_shift = 0; //-m_border_width; 1214 menu.x_shift = 0; //-m_border_width;
1238 shifted = true; 1215 shifted = true;
1239 } 1216 }
1240 1217
1241 if (menu.y + menu.height + 2*m_border_width > m_screen_height) { 1218 if (menu.y + height() + 2*m_border_width > m_screen_height) {
1242 menu.y_shift = m_screen_height - menu.height - 2*m_border_width; 1219 menu.y_shift = m_screen_height - height() - 2*m_border_width;
1243 shifted = true; 1220 shifted = true;
1244 } else if (menu.y + (signed) menu.title_h < 0) { 1221 } else if (menu.y + (signed) menu.title_h < 0) {
1245 menu.y_shift = 0; // -m_border_width;; 1222 menu.y_shift = 0; // -m_border_width;;
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 333f6d8..9a3f425 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.24 2003/12/08 16:39:44 fluxgen Exp $ 25// $Id: Menu.hh,v 1.25 2003/12/10 23:08:06 fluxgen Exp $
26 26
27#ifndef FBTK_MENU_HH 27#ifndef FBTK_MENU_HH
28#define FBTK_MENU_HH 28#define FBTK_MENU_HH
@@ -57,7 +57,7 @@ public:
57 */ 57 */
58 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND }; 58 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };
59 59
60 Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl); 60 Menu(MenuTheme &tm, ImageControl &imgctrl);
61 virtual ~Menu(); 61 virtual ~Menu();
62 62
63 /** 63 /**
@@ -132,7 +132,7 @@ public:
132 //@{ 132 //@{
133 inline bool isTorn() const { return torn; } 133 inline bool isTorn() const { return torn; }
134 inline bool isVisible() const { return visible; } 134 inline bool isVisible() const { return visible; }
135 inline int screenNumber() const { return m_screen_num; } 135 inline int screenNumber() const { return menu.window.screenNumber(); }
136 inline Window window() const { return menu.window.window(); } 136 inline Window window() const { return menu.window.window(); }
137 inline FbWindow &fbwindow() { return menu.window; } 137 inline FbWindow &fbwindow() { return menu.window; }
138 inline const FbWindow &fbwindow() const { return menu.window; } 138 inline const FbWindow &fbwindow() const { return menu.window; }
@@ -141,8 +141,8 @@ public:
141 inline const std::string &label() const { return menu.label; } 141 inline const std::string &label() const { return menu.label; }
142 inline int x() const { return menu.x; } 142 inline int x() const { return menu.x; }
143 inline int y() const { return menu.y; } 143 inline int y() const { return menu.y; }
144 inline unsigned int width() const { return menu.width; } 144 inline unsigned int width() const { return menu.window.width(); }
145 inline unsigned int height() const { return menu.height; } 145 inline unsigned int height() const { return menu.window.height(); }
146 inline unsigned int numberOfItems() const { return menuitems.size(); } 146 inline unsigned int numberOfItems() const { return menuitems.size(); }
147 inline int currentSubmenu() const { return which_sub; } 147 inline int currentSubmenu() const { return which_sub; }
148 inline unsigned int titleHeight() const { return menu.title_h; } 148 inline unsigned int titleHeight() const { return menu.title_h; }
@@ -178,8 +178,6 @@ private:
178 178
179 typedef std::vector<MenuItem *> Menuitems; 179 typedef std::vector<MenuItem *> Menuitems;
180 const MenuTheme &m_theme; 180 const MenuTheme &m_theme;
181 Display *m_display;
182 const int m_screen_num;
183 Menu *m_parent; 181 Menu *m_parent;
184 ImageControl &m_image_ctrl; 182 ImageControl &m_image_ctrl;
185 Menuitems menuitems; 183 Menuitems menuitems;
@@ -198,7 +196,7 @@ private:
198 std::string label; 196 std::string label;
199 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, 197 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
200 grab_x, grab_y; 198 grab_x, grab_y;
201 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, 199 unsigned int title_h, frame_h, item_w, item_h, bevel_w,
202 bevel_h; 200 bevel_h;
203 } menu; 201 } menu;
204 202