aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BoolMenuItem.hh4
-rw-r--r--src/FbTk/Menu.cc21
-rw-r--r--src/FbTk/Menu.hh4
-rw-r--r--src/FbTk/MenuItem.cc2
-rw-r--r--src/FbTk/MenuItem.hh40
-rw-r--r--src/IntResMenuItem.hh1
-rw-r--r--src/RootCmdMenuItem.cc1
-rw-r--r--src/StyleMenuItem.cc1
8 files changed, 43 insertions, 31 deletions
diff --git a/src/BoolMenuItem.hh b/src/BoolMenuItem.hh
index 29eef15..d10a7ac 100644
--- a/src/BoolMenuItem.hh
+++ b/src/BoolMenuItem.hh
@@ -34,11 +34,13 @@ public:
34 FbTk::MenuItem(label, cmd), m_item(item) { 34 FbTk::MenuItem(label, cmd), m_item(item) {
35 FbTk::MenuItem::setSelected(m_item); 35 FbTk::MenuItem::setSelected(m_item);
36 setToggleItem(true); 36 setToggleItem(true);
37 setCloseOnClick(false);
37 } 38 }
38 BoolMenuItem(const FbTk::FbString &label, bool &item): 39 BoolMenuItem(const FbTk::FbString &label, bool &item):
39 FbTk::MenuItem(label), m_item(item) { 40 FbTk::MenuItem(label), m_item(item) {
40 FbTk::MenuItem::setSelected(m_item); 41 FbTk::MenuItem::setSelected(m_item);
41 setToggleItem(true); 42 setToggleItem(true);
43 setCloseOnClick(false);
42 } 44 }
43 bool isSelected() const { return m_item; } 45 bool isSelected() const { return m_item; }
44 // toggle state 46 // toggle state
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index 88240f1..3be0d14 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -199,15 +199,15 @@ Menu::~Menu() {
199} 199}
200 200
201int Menu::insert(const FbString &label, RefCount<Command> &cmd, int pos) { 201int Menu::insert(const FbString &label, RefCount<Command> &cmd, int pos) {
202 return insert(new MenuItem(label, cmd), pos); 202 return insert(new MenuItem(label, cmd, this), pos);
203} 203}
204 204
205int Menu::insert(const FbString &label, int pos) { 205int Menu::insert(const FbString &label, int pos) {
206 return insert(new MenuItem(label), pos); 206 return insert(new MenuItem(label, *this), pos);
207} 207}
208 208
209int Menu::insert(const FbString &label, Menu *submenu, int pos) { 209int Menu::insert(const FbString &label, Menu *submenu, int pos) {
210 return insert(new MenuItem(label, submenu), pos); 210 return insert(new MenuItem(label, submenu, this), pos);
211} 211}
212 212
213int Menu::insert(MenuItem *item, int pos) { 213int Menu::insert(MenuItem *item, int pos) {
@@ -516,15 +516,15 @@ void Menu::show() {
516 raise(); 516 raise();
517 517
518 if (shown && shown != this && shown != m_parent) 518 if (shown && shown != this && shown != m_parent)
519 shown->hide(true); 519 shown->hide();
520 shown = this; 520 shown = this;
521 521
522} 522}
523 523
524 524
525void Menu::hide(bool force) { 525void Menu::hide() {
526 526
527 if (!isVisible() || m_torn && !force) 527 if (!isVisible())
528 return; 528 return;
529 529
530 // if parent is visible, go to first parent and hide it 530 // if parent is visible, go to first parent and hide it
@@ -570,6 +570,9 @@ void Menu::redrawFrame(FbDrawable &drawable) {
570 570
571void Menu::internal_hide(bool first) { 571void Menu::internal_hide(bool first) {
572 572
573 if (!first && m_torn)
574 return;
575
573 if (validIndex(m_which_sub)) { 576 if (validIndex(m_which_sub)) {
574 MenuItem *tmp = menuitems[m_which_sub]; 577 MenuItem *tmp = menuitems[m_which_sub];
575 tmp->submenu()->internal_hide(false); 578 tmp->submenu()->internal_hide(false);
@@ -815,8 +818,6 @@ void Menu::handleEvent(XEvent &event) {
815 if (event.type == FocusOut) { 818 if (event.type == FocusOut) {
816 if (s_focused == this) 819 if (s_focused == this)
817 s_focused = 0; 820 s_focused = 0;
818 if (shown == this && !m_torn)
819 hide();
820 // I don't know why, but I get a FocusIn event when closing the menu with 821 // I don't know why, but I get a FocusIn event when closing the menu with
821 // the mouse over it -- probably an xorg bug, but it's easy to address here 822 // the mouse over it -- probably an xorg bug, but it's easy to address here
822 } else if (event.type == FocusIn && m_visible) { 823 } else if (event.type == FocusIn && m_visible) {
@@ -1275,9 +1276,9 @@ void Menu::drawLine(int index, int size){
1275 item->drawLine(menu.frame, theme(), size, item_x, item_y, menu.item_w); 1276 item->drawLine(menu.frame, theme(), size, item_x, item_y, menu.item_w);
1276} 1277}
1277 1278
1278void Menu::hideShownMenu(bool force) { 1279void Menu::hideShownMenu() {
1279 if (shown) 1280 if (shown)
1280 shown->hide(force); 1281 shown->hide();
1281} 1282}
1282 1283
1283}; // end namespace FbTk 1284}; // end namespace FbTk
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 2a84c77..53dc494 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -124,7 +124,7 @@ public:
124 /// show menu 124 /// show menu
125 virtual void show(); 125 virtual void show();
126 /// hide menu 126 /// hide menu
127 virtual void hide(bool force = false); 127 virtual void hide();
128 virtual void clearWindow(); 128 virtual void clearWindow();
129#ifdef NOT_USED 129#ifdef NOT_USED
130 void setActiveIndex(int index) { m_active_index = index; } 130 void setActiveIndex(int index) { m_active_index = index; }
@@ -160,7 +160,7 @@ public:
160 inline unsigned char alpha() const { return theme().alpha(); } 160 inline unsigned char alpha() const { return theme().alpha(); }
161 inline static Menu *shownMenu() { return shown; } 161 inline static Menu *shownMenu() { return shown; }
162 inline static Menu *focused() { return s_focused; } 162 inline static Menu *focused() { return s_focused; }
163 static void hideShownMenu(bool force = true); 163 static void hideShownMenu();
164 /// @return menuitem at index 164 /// @return menuitem at index
165 inline const MenuItem *find(unsigned int index) const { return menuitems[index]; } 165 inline const MenuItem *find(unsigned int index) const { return menuitems[index]; }
166 inline MenuItem *find(unsigned int index) { return menuitems[index]; } 166 inline MenuItem *find(unsigned int index) { return menuitems[index]; }
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index 2576d2b..7d309f4 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -35,6 +35,8 @@ namespace FbTk {
35 35
36void MenuItem::click(int button, int time) { 36void MenuItem::click(int button, int time) {
37 if (m_command.get() != 0) { 37 if (m_command.get() != 0) {
38 if (m_menu && m_close_on_click)
39 m_menu->hide();
38 // we need a local variable, since the command may destroy this object 40 // we need a local variable, since the command may destroy this object
39 RefCount<Command> tmp(m_command); 41 RefCount<Command> tmp(m_command);
40 tmp->execute(); 42 tmp->execute();
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh
index 7fac8c7..3b02f2e 100644
--- a/src/FbTk/MenuItem.hh
+++ b/src/FbTk/MenuItem.hh
@@ -47,15 +47,16 @@ public:
47 m_submenu(0), 47 m_submenu(0),
48 m_enabled(true), 48 m_enabled(true),
49 m_selected(false), 49 m_selected(false),
50 m_close_on_click(true),
50 m_toggle_item(false) 51 m_toggle_item(false)
51 { } 52 { }
52 explicit MenuItem( 53 explicit MenuItem(const FbString &label)
53 const FbString &label)
54 : m_label(label), 54 : m_label(label),
55 m_menu(0), 55 m_menu(0),
56 m_submenu(0), 56 m_submenu(0),
57 m_enabled(true), 57 m_enabled(true),
58 m_selected(false), 58 m_selected(false),
59 m_close_on_click(true),
59 m_toggle_item(false) 60 m_toggle_item(false)
60 { } 61 { }
61 62
@@ -65,26 +66,28 @@ public:
65 m_submenu(0), 66 m_submenu(0),
66 m_enabled(true), 67 m_enabled(true),
67 m_selected(false), 68 m_selected(false),
69 m_close_on_click(true),
68 m_toggle_item(false) 70 m_toggle_item(false)
69 { } 71 { }
70 /// create a menu item with a specific command to be executed on click 72 /// create a menu item with a specific command to be executed on click
71 MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0): 73 MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0)
72 m_label(label), 74 : m_label(label),
73 m_menu(menu), 75 m_menu(menu),
74 m_submenu(0), 76 m_submenu(0),
75 m_command(cmd), 77 m_command(cmd),
76 m_enabled(true), 78 m_enabled(true),
77 m_selected(false), 79 m_selected(false),
78 m_toggle_item(false) { 80 m_close_on_click(true),
79 81 m_toggle_item(false)
80 } 82 { }
81 83
82 MenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0) 84 MenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0)
83 : m_label(label) 85 : m_label(label),
84 , m_menu(host_menu) 86 m_menu(host_menu),
85 , m_submenu(submenu) 87 m_submenu(submenu),
86 , m_enabled(true) 88 m_enabled(true),
87 , m_selected(false), 89 m_selected(false),
90 m_close_on_click(true),
88 m_toggle_item(false) 91 m_toggle_item(false)
89 { } 92 { }
90 virtual ~MenuItem() { } 93 virtual ~MenuItem() { }
@@ -94,6 +97,7 @@ public:
94 virtual void setEnabled(bool enabled) { m_enabled = enabled; } 97 virtual void setEnabled(bool enabled) { m_enabled = enabled; }
95 virtual void setLabel(const FbString &label) { m_label = label; } 98 virtual void setLabel(const FbString &label) { m_label = label; }
96 virtual void setToggleItem(bool val) { m_toggle_item = val; } 99 virtual void setToggleItem(bool val) { m_toggle_item = val; }
100 void setCloseOnClick(bool val) { m_close_on_click = val; }
97 void setIcon(const std::string &filename, int screen_num); 101 void setIcon(const std::string &filename, int screen_num);
98 virtual Menu *submenu() { return m_submenu; } 102 virtual Menu *submenu() { return m_submenu; }
99 /** 103 /**
@@ -150,7 +154,7 @@ private:
150 Menu *m_submenu; ///< a submenu, 0 if we don't have one 154 Menu *m_submenu; ///< a submenu, 0 if we don't have one
151 RefCount<Command> m_command; ///< command to be executed 155 RefCount<Command> m_command; ///< command to be executed
152 bool m_enabled, m_selected; 156 bool m_enabled, m_selected;
153 bool m_toggle_item; 157 bool m_close_on_click, m_toggle_item;
154 int m_index; 158 int m_index;
155 159
156 struct Icon { 160 struct Icon {
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh
index 768870e..e49681f 100644
--- a/src/IntResMenuItem.hh
+++ b/src/IntResMenuItem.hh
@@ -37,6 +37,7 @@ public:
37 FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), 37 FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()),
38 m_max(max_val), m_min(min_val), m_res(res) { 38 m_max(max_val), m_min(min_val), m_res(res) {
39 updateLabel(); 39 updateLabel();
40 setCloseOnClick(false);
40 } 41 }
41 42
42 /* Utility, but doesn't get found in anonymous namespace? */ 43 /* Utility, but doesn't get found in anonymous namespace? */
diff --git a/src/RootCmdMenuItem.cc b/src/RootCmdMenuItem.cc
index a52a4d8..0e51b03 100644
--- a/src/RootCmdMenuItem.cc
+++ b/src/RootCmdMenuItem.cc
@@ -40,6 +40,7 @@ RootCmdMenuItem::RootCmdMenuItem(const FbTk::FbString &label,
40 setwp_cmd(new FbCommands::ExecuteCmd(prog + " \"" + m_filename + "\"")); 40 setwp_cmd(new FbCommands::ExecuteCmd(prog + " \"" + m_filename + "\""));
41 setCommand(setwp_cmd); 41 setCommand(setwp_cmd);
42 setToggleItem(true); 42 setToggleItem(true);
43 setCloseOnClick(false);
43} 44}
44 45
45 46
diff --git a/src/StyleMenuItem.cc b/src/StyleMenuItem.cc
index b1325e5..7d9954d 100644
--- a/src/StyleMenuItem.cc
+++ b/src/StyleMenuItem.cc
@@ -39,6 +39,7 @@ StyleMenuItem::StyleMenuItem(const FbTk::FbString &label, const std::string &fil
39 SetStyleCmd(m_filename)); 39 SetStyleCmd(m_filename));
40 setCommand(setstyle_cmd); 40 setCommand(setstyle_cmd);
41 setToggleItem(true); 41 setToggleItem(true);
42 setCloseOnClick(false);
42} 43}
43 44
44 45