diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-09-22 05:32:02 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-09-22 05:32:02 (GMT) |
commit | 3f33657fb721645292f798480e9e0b46d64aedf8 (patch) | |
tree | 71f3e5d97e984bbdf69ae6c3a3cf9fc72d060a69 /src/FbTk | |
parent | ed53f3c623e7c3ae35672b33ae3b52759dc1a6ed (diff) | |
download | fluxbox_lack-3f33657fb721645292f798480e9e0b46d64aedf8.zip fluxbox_lack-3f33657fb721645292f798480e9e0b46d64aedf8.tar.bz2 |
fix active menu item when inserting or removing other items
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/Menu.cc | 9 | ||||
-rw-r--r-- | src/FbTk/Menu.hh | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 7d50302..7cb5599 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc | |||
@@ -219,6 +219,8 @@ int Menu::insert(MenuItem *item, int pos) { | |||
219 | } else { | 219 | } else { |
220 | menuitems.insert(menuitems.begin() + pos, item); | 220 | menuitems.insert(menuitems.begin() + pos, item); |
221 | fixMenuItemIndices(); | 221 | fixMenuItemIndices(); |
222 | if (m_active_index >= pos) | ||
223 | m_active_index++; | ||
222 | } | 224 | } |
223 | m_need_update = true; // we need to redraw the menu | 225 | m_need_update = true; // we need to redraw the menu |
224 | return menuitems.size(); | 226 | return menuitems.size(); |
@@ -233,7 +235,7 @@ int Menu::remove(unsigned int index) { | |||
233 | if (index >= menuitems.size()) { | 235 | if (index >= menuitems.size()) { |
234 | #ifdef DEBUG | 236 | #ifdef DEBUG |
235 | cout << "Bad index (" << index << ") given to Menu::remove()" | 237 | cout << "Bad index (" << index << ") given to Menu::remove()" |
236 | << " -- should be between 0 and " << menuitems.size() | 238 | << " -- should be between 0 and " << menuitems.size()-1 |
237 | << " inclusive." << endl; | 239 | << " inclusive." << endl; |
238 | #endif // DEBUG | 240 | #endif // DEBUG |
239 | return -1; | 241 | return -1; |
@@ -271,6 +273,9 @@ int Menu::remove(unsigned int index) { | |||
271 | else if (static_cast<unsigned int>(m_which_sub) > index) | 273 | else if (static_cast<unsigned int>(m_which_sub) > index) |
272 | m_which_sub--; | 274 | m_which_sub--; |
273 | 275 | ||
276 | if (static_cast<unsigned int>(m_active_index) > index) | ||
277 | m_active_index--; | ||
278 | |||
274 | m_need_update = true; // we need to redraw the menu | 279 | m_need_update = true; // we need to redraw the menu |
275 | 280 | ||
276 | return menuitems.size(); | 281 | return menuitems.size(); |
@@ -366,7 +371,7 @@ void Menu::enableTitle() { | |||
366 | setTitleVisibility(true); | 371 | setTitleVisibility(true); |
367 | } | 372 | } |
368 | 373 | ||
369 | void Menu::updateMenu(int active_index) { | 374 | void Menu::updateMenu() { |
370 | if (m_title_vis) { | 375 | if (m_title_vis) { |
371 | menu.item_w = theme()->titleFont().textWidth(menu.label, | 376 | menu.item_w = theme()->titleFont().textWidth(menu.label, |
372 | menu.label.size()); | 377 | menu.label.size()); |
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index ee57a23..519a78b 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh | |||
@@ -109,7 +109,7 @@ public: | |||
109 | void setLabel(const FbString &labelstr); | 109 | void setLabel(const FbString &labelstr); |
110 | /// move menu to x,y | 110 | /// move menu to x,y |
111 | virtual void move(int x, int y); | 111 | virtual void move(int x, int y); |
112 | virtual void updateMenu(int active_index = -1); | 112 | virtual void updateMenu(); |
113 | void setItemSelected(unsigned int index, bool val); | 113 | void setItemSelected(unsigned int index, bool val); |
114 | void setItemEnabled(unsigned int index, bool val); | 114 | void setItemEnabled(unsigned int index, bool val); |
115 | void setMinimumSublevels(int m) { menu.minsub = m; } | 115 | void setMinimumSublevels(int m) { menu.minsub = m; } |