diff options
author | Jim Ramsay <jim.ramsay@motorola.com> | 2010-01-14 16:49:48 (GMT) |
---|---|---|
committer | Jim Ramsay <jim.ramsay@motorola.com> | 2010-01-14 20:06:40 (GMT) |
commit | 6ceb786df329045b49dc4f2a8e7ba76b772746a9 (patch) | |
tree | ed74f7dec685921c5d4a6b7a3e5d143d1098dfd6 | |
parent | 46261a8284730a16d664fa89423fc5728ed284b4 (diff) | |
download | fluxbox_lack-6ceb786df329045b49dc4f2a8e7ba76b772746a9.zip fluxbox_lack-6ceb786df329045b49dc4f2a8e7ba76b772746a9.tar.bz2 |
Add Menu::setActive and MenuItem::setActive API
This provides a virtual function which may be overridden by subclasses so they
are notified when a different menu item is highlight. Menu::setActive is called
first, with the index of the item that is about to be highlighted, though this
may be '-1'. MenuItem::setActive will recieve a boolean which is true if this
MenuItem is highlighted and false otherwise.
-rw-r--r-- | src/FbTk/Menu.cc | 25 | ||||
-rw-r--r-- | src/FbTk/Menu.hh | 2 | ||||
-rw-r--r-- | src/FbTk/MenuItem.hh | 8 |
3 files changed, 24 insertions, 11 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index ded5dab..d44612e 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc | |||
@@ -220,7 +220,7 @@ int Menu::insert(MenuItem *item, int pos) { | |||
220 | menuitems.insert(menuitems.begin() + pos, item); | 220 | menuitems.insert(menuitems.begin() + pos, item); |
221 | fixMenuItemIndices(); | 221 | fixMenuItemIndices(); |
222 | if (m_active_index >= pos) | 222 | if (m_active_index >= pos) |
223 | m_active_index++; | 223 | setActive(m_active_index + 1); |
224 | } | 224 | } |
225 | m_need_update = true; // we need to redraw the menu | 225 | m_need_update = true; // we need to redraw the menu |
226 | return menuitems.size(); | 226 | return menuitems.size(); |
@@ -274,7 +274,7 @@ int Menu::remove(unsigned int index) { | |||
274 | m_which_sub--; | 274 | m_which_sub--; |
275 | 275 | ||
276 | if (static_cast<unsigned int>(m_active_index) > index) | 276 | if (static_cast<unsigned int>(m_active_index) > index) |
277 | m_active_index--; | 277 | setActive(m_active_index-1); |
278 | 278 | ||
279 | m_need_update = true; // we need to redraw the menu | 279 | m_need_update = true; // we need to redraw the menu |
280 | 280 | ||
@@ -335,7 +335,7 @@ void Menu::cycleItems(bool reverse) { | |||
335 | void Menu::setActiveIndex(int new_index) { | 335 | void Menu::setActiveIndex(int new_index) { |
336 | // clear the items and close any open submenus | 336 | // clear the items and close any open submenus |
337 | int old_active_index = m_active_index; | 337 | int old_active_index = m_active_index; |
338 | m_active_index = new_index; | 338 | setActive(new_index); |
339 | if (validIndex(old_active_index) && | 339 | if (validIndex(old_active_index) && |
340 | menuitems[old_active_index] != 0) { | 340 | menuitems[old_active_index] != 0) { |
341 | if (menuitems[old_active_index]->submenu()) { | 341 | if (menuitems[old_active_index]->submenu()) { |
@@ -361,7 +361,7 @@ void Menu::enterSubmenu() { | |||
361 | 361 | ||
362 | drawSubmenu(m_active_index); | 362 | drawSubmenu(m_active_index); |
363 | submenu->grabInputFocus(); | 363 | submenu->grabInputFocus(); |
364 | submenu->m_active_index = -1; // so we land on 0 after nextItem() | 364 | submenu->setActive(-1); // so we land on 0 after nextItem() |
365 | submenu->cycleItems(false); | 365 | submenu->cycleItems(false); |
366 | } | 366 | } |
367 | 367 | ||
@@ -386,11 +386,11 @@ void Menu::updateMenu() { | |||
386 | for (size_t i = 1; i < menuitems.size(); i++) { | 386 | for (size_t i = 1; i < menuitems.size(); i++) { |
387 | if (validIndex(m_active_index + i) && | 387 | if (validIndex(m_active_index + i) && |
388 | menuitems[m_active_index + i]->isEnabled()) { | 388 | menuitems[m_active_index + i]->isEnabled()) { |
389 | m_active_index += i; | 389 | setActive(m_active_index + i); |
390 | break; | 390 | break; |
391 | } else if (validIndex(m_active_index - i) && | 391 | } else if (validIndex(m_active_index - i) && |
392 | menuitems[m_active_index - i]->isEnabled()) { | 392 | menuitems[m_active_index - i]->isEnabled()) { |
393 | m_active_index -= i; | 393 | setActive(m_active_index - i); |
394 | break; | 394 | break; |
395 | } | 395 | } |
396 | } | 396 | } |
@@ -622,7 +622,7 @@ void Menu::internal_hide(bool first) { | |||
622 | // if we have an active index we need to redraw it | 622 | // if we have an active index we need to redraw it |
623 | // as non active | 623 | // as non active |
624 | int old = m_active_index; | 624 | int old = m_active_index; |
625 | m_active_index = -1; | 625 | setActive(-1); |
626 | clearItem(old); // clear old area from highlight | 626 | clearItem(old); // clear old area from highlight |
627 | 627 | ||
628 | if (shown == this) { | 628 | if (shown == this) { |
@@ -932,7 +932,7 @@ void Menu::buttonReleaseEvent(XButtonEvent &re) { | |||
932 | menuitems[w]->click(re.button, re.time, re.state); | 932 | menuitems[w]->click(re.button, re.time, re.state); |
933 | } else { | 933 | } else { |
934 | int old = m_active_index; | 934 | int old = m_active_index; |
935 | m_active_index = w; | 935 | setActive(w); |
936 | clearItem(old); | 936 | clearItem(old); |
937 | } | 937 | } |
938 | clearItem(w); | 938 | clearItem(w); |
@@ -983,7 +983,7 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { | |||
983 | 983 | ||
984 | if (itmp->isEnabled()) { | 984 | if (itmp->isEnabled()) { |
985 | int old = m_active_index; | 985 | int old = m_active_index; |
986 | m_active_index = w; | 986 | setActive(w); |
987 | clearItem(w); | 987 | clearItem(w); |
988 | clearItem(old); | 988 | clearItem(old); |
989 | 989 | ||
@@ -1148,7 +1148,7 @@ void Menu::leaveNotifyEvent(XCrossingEvent &ce) { | |||
1148 | if (validIndex(m_which_sub) && m_active_index != m_which_sub && | 1148 | if (validIndex(m_which_sub) && m_active_index != m_which_sub && |
1149 | menuitems[m_which_sub]->submenu()->isVisible()) { | 1149 | menuitems[m_which_sub]->submenu()->isVisible()) { |
1150 | int old = m_active_index; | 1150 | int old = m_active_index; |
1151 | m_active_index = m_which_sub; | 1151 | setActive(m_which_sub); |
1152 | clearItem(m_active_index); | 1152 | clearItem(m_active_index); |
1153 | clearItem(old); | 1153 | clearItem(old); |
1154 | menuitems[m_which_sub]->submenu()->stopHide(); | 1154 | menuitems[m_which_sub]->submenu()->stopHide(); |
@@ -1280,6 +1280,8 @@ void Menu::clearItem(int index, bool clear, int search_index) { | |||
1280 | true, false, item_x, item_y, | 1280 | true, false, item_x, item_y, |
1281 | item_w, item_h); | 1281 | item_w, item_h); |
1282 | 1282 | ||
1283 | item->setActive(highlight); | ||
1284 | |||
1283 | if (search_index < (int)m_matches.size()) | 1285 | if (search_index < (int)m_matches.size()) |
1284 | drawLine(index, m_type_ahead.stringSize()); | 1286 | drawLine(index, m_type_ahead.stringSize()); |
1285 | } | 1287 | } |
@@ -1313,6 +1315,9 @@ void Menu::highlightItem(int index) { | |||
1313 | item_x, item_y, | 1315 | item_x, item_y, |
1314 | item_w, item_h); | 1316 | item_w, item_h); |
1315 | 1317 | ||
1318 | MenuItem *item = menuitems[index]; | ||
1319 | if (item) | ||
1320 | item->setActive(true); | ||
1316 | } | 1321 | } |
1317 | 1322 | ||
1318 | void Menu::resetTypeAhead() { | 1323 | void Menu::resetTypeAhead() { |
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 09bdd8c..dfefbc0 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh | |||
@@ -188,6 +188,8 @@ protected: | |||
188 | 188 | ||
189 | virtual void update(FbTk::Subject *); | 189 | virtual void update(FbTk::Subject *); |
190 | 190 | ||
191 | virtual void setActive(int index) { m_active_index = index; } | ||
192 | |||
191 | private: | 193 | private: |
192 | 194 | ||
193 | void openSubmenu(); | 195 | void openSubmenu(); |
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh index 9150849..9a7a08f 100644 --- a/src/FbTk/MenuItem.hh +++ b/src/FbTk/MenuItem.hh | |||
@@ -46,6 +46,7 @@ public: | |||
46 | m_submenu(0), | 46 | m_submenu(0), |
47 | m_enabled(true), | 47 | m_enabled(true), |
48 | m_selected(false), | 48 | m_selected(false), |
49 | m_active(false), | ||
49 | m_close_on_click(true), | 50 | m_close_on_click(true), |
50 | m_toggle_item(false) | 51 | m_toggle_item(false) |
51 | { } | 52 | { } |
@@ -55,6 +56,7 @@ public: | |||
55 | m_submenu(0), | 56 | m_submenu(0), |
56 | m_enabled(true), | 57 | m_enabled(true), |
57 | m_selected(false), | 58 | m_selected(false), |
59 | m_active(false), | ||
58 | m_close_on_click(true), | 60 | m_close_on_click(true), |
59 | m_toggle_item(false) | 61 | m_toggle_item(false) |
60 | { } | 62 | { } |
@@ -65,6 +67,7 @@ public: | |||
65 | m_submenu(0), | 67 | m_submenu(0), |
66 | m_enabled(true), | 68 | m_enabled(true), |
67 | m_selected(false), | 69 | m_selected(false), |
70 | m_active(false), | ||
68 | m_close_on_click(true), | 71 | m_close_on_click(true), |
69 | m_toggle_item(false) | 72 | m_toggle_item(false) |
70 | { } | 73 | { } |
@@ -76,6 +79,7 @@ public: | |||
76 | m_command(cmd), | 79 | m_command(cmd), |
77 | m_enabled(true), | 80 | m_enabled(true), |
78 | m_selected(false), | 81 | m_selected(false), |
82 | m_active(false), | ||
79 | m_close_on_click(true), | 83 | m_close_on_click(true), |
80 | m_toggle_item(false) | 84 | m_toggle_item(false) |
81 | { } | 85 | { } |
@@ -86,6 +90,7 @@ public: | |||
86 | m_submenu(submenu), | 90 | m_submenu(submenu), |
87 | m_enabled(true), | 91 | m_enabled(true), |
88 | m_selected(false), | 92 | m_selected(false), |
93 | m_active(false), | ||
89 | m_close_on_click(true), | 94 | m_close_on_click(true), |
90 | m_toggle_item(false) | 95 | m_toggle_item(false) |
91 | { } | 96 | { } |
@@ -96,6 +101,7 @@ public: | |||
96 | virtual void setEnabled(bool enabled) { m_enabled = enabled; } | 101 | virtual void setEnabled(bool enabled) { m_enabled = enabled; } |
97 | virtual void setLabel(const FbString &label) { m_label = label; } | 102 | virtual void setLabel(const FbString &label) { m_label = label; } |
98 | virtual void setToggleItem(bool val) { m_toggle_item = val; } | 103 | virtual void setToggleItem(bool val) { m_toggle_item = val; } |
104 | virtual void setActive(bool val) { m_active = val; } | ||
99 | void setCloseOnClick(bool val) { m_close_on_click = val; } | 105 | void setCloseOnClick(bool val) { m_close_on_click = val; } |
100 | void setIcon(const std::string &filename, int screen_num); | 106 | void setIcon(const std::string &filename, int screen_num); |
101 | virtual Menu *submenu() { return m_submenu; } | 107 | virtual Menu *submenu() { return m_submenu; } |
@@ -152,7 +158,7 @@ private: | |||
152 | Menu *m_menu; ///< the menu we live in | 158 | Menu *m_menu; ///< the menu we live in |
153 | Menu *m_submenu; ///< a submenu, 0 if we don't have one | 159 | Menu *m_submenu; ///< a submenu, 0 if we don't have one |
154 | RefCount<Command<void> > m_command; ///< command to be executed | 160 | RefCount<Command<void> > m_command; ///< command to be executed |
155 | bool m_enabled, m_selected; | 161 | bool m_enabled, m_selected, m_active; |
156 | bool m_close_on_click, m_toggle_item; | 162 | bool m_close_on_click, m_toggle_item; |
157 | int m_index; | 163 | int m_index; |
158 | 164 | ||