aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-09-22 05:32:02 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-09-22 05:32:02 (GMT)
commit3f33657fb721645292f798480e9e0b46d64aedf8 (patch)
tree71f3e5d97e984bbdf69ae6c3a3cf9fc72d060a69
parented53f3c623e7c3ae35672b33ae3b52759dc1a6ed (diff)
downloadfluxbox-3f33657fb721645292f798480e9e0b46d64aedf8.zip
fluxbox-3f33657fb721645292f798480e9e0b46d64aedf8.tar.bz2
fix active menu item when inserting or removing other items
-rw-r--r--src/FbTk/Menu.cc9
-rw-r--r--src/FbTk/Menu.hh2
-rw-r--r--src/WorkspaceMenu.cc6
3 files changed, 11 insertions, 6 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
369void Menu::updateMenu(int active_index) { 374void 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; }
diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc
index c343920..f03dd3c 100644
--- a/src/WorkspaceMenu.cc
+++ b/src/WorkspaceMenu.cc
@@ -80,7 +80,7 @@ void WorkspaceMenu::workspaceInfoChanged( BScreen& screen ) {
80 insert(mb_menu, workspace + IDX_AFTER_ICONS); 80 insert(mb_menu, workspace + IDX_AFTER_ICONS);
81 } 81 }
82 82
83 updateMenu(-1); 83 updateMenu();
84} 84}
85 85
86void WorkspaceMenu::workspaceChanged(BScreen& screen) { 86void WorkspaceMenu::workspaceChanged(BScreen& screen) {
@@ -89,12 +89,12 @@ void WorkspaceMenu::workspaceChanged(BScreen& screen) {
89 item = find(i + IDX_AFTER_ICONS); 89 item = find(i + IDX_AFTER_ICONS);
90 if (item && item->isSelected()) { 90 if (item && item->isSelected()) {
91 setItemSelected(i + IDX_AFTER_ICONS, false); 91 setItemSelected(i + IDX_AFTER_ICONS, false);
92 updateMenu(i + IDX_AFTER_ICONS); 92 updateMenu();
93 break; 93 break;
94 } 94 }
95 } 95 }
96 setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true); 96 setItemSelected(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS, true);
97 updateMenu(screen.currentWorkspace()->workspaceID() + IDX_AFTER_ICONS); 97 updateMenu();
98} 98}
99 99
100void WorkspaceMenu::init(BScreen &screen) { 100void WorkspaceMenu::init(BScreen &screen) {