aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-16 07:36:49 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-16 07:36:49 (GMT)
commitb4958780650cfab97d4dc694a34c0c77bf99b26d (patch)
tree0982d91e368b1e9f020b606cb0f2b205cd619c4d /src/FbTk
parentbd9afcafb93382b5b7f32c222594699214581596 (diff)
downloadfluxbox-b4958780650cfab97d4dc694a34c0c77bf99b26d.zip
fluxbox-b4958780650cfab97d4dc694a34c0c77bf99b26d.tar.bz2
Reduce number of allocations for menu creation
Every time either the Slit menu or the Toolbar menu were added to the root menu, the whole root menu was (re)created from scratch. Now we create and remove only the menus needed. Side effect: the position of these menus is now at the end of the root menu and not somewhere in between. If users complaint, I' ll think about it.
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Menu.cc22
-rw-r--r--src/FbTk/Menu.hh14
2 files changed, 29 insertions, 7 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index 4dbb48c..8dddc16 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -91,6 +91,12 @@ Menu* s_focused = 0; // holds currently focused menu
91Menu* Menu::shownMenu() { return s_shown; } 91Menu* Menu::shownMenu() { return s_shown; }
92Menu* Menu::focused() { return s_focused; } 92Menu* Menu::focused() { return s_focused; }
93 93
94void Menu::hideShownMenu() {
95 if (s_shown)
96 s_shown->hide();
97}
98
99
94Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl): 100Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl):
95 m_theme(tm), 101 m_theme(tm),
96 m_parent(0), 102 m_parent(0),
@@ -240,6 +246,18 @@ int Menu::insertItem(MenuItem *item, int pos) {
240 return m_items.size(); 246 return m_items.size();
241} 247}
242 248
249
250int Menu::findSubmenuIndex(const FbTk::Menu* submenu) const {
251 size_t i;
252 for (i = 0; i < m_items.size(); i++) {
253 if (m_items[i]->submenu() == submenu) {
254 return i;
255 }
256 }
257 return -1;
258}
259
260
243void Menu::fixMenuItemIndices() { 261void Menu::fixMenuItemIndices() {
244 for (size_t i = 0; i < m_items.size(); i++) 262 for (size_t i = 0; i < m_items.size(); i++)
245 m_items[i]->setIndex(i); 263 m_items[i]->setIndex(i);
@@ -1391,9 +1409,5 @@ void Menu::drawLine(int index, int size){
1391 item->drawLine(m_frame, theme(), size, item_x, item_y, m_item_w); 1409 item->drawLine(m_frame, theme(), size, item_x, item_y, m_item_w);
1392} 1410}
1393 1411
1394void Menu::hideShownMenu() {
1395 if (s_shown)
1396 s_shown->hide();
1397}
1398 1412
1399} // end namespace FbTk 1413} // end namespace FbTk
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 49893c1..27d5b12 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -45,6 +45,12 @@ template <typename T> class RefCount;
45/// Base class for menus 45/// Base class for menus
46class Menu: public FbTk::EventHandler, FbTk::FbWindowRenderer { 46class Menu: public FbTk::EventHandler, FbTk::FbWindowRenderer {
47public: 47public:
48
49 static Menu* shownMenu();
50 static Menu* focused();
51 static void hideShownMenu();
52
53
48 enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; 54 enum Alignment{ ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM };
49 enum { RIGHT = 1, LEFT }; 55 enum { RIGHT = 1, LEFT };
50 56
@@ -134,11 +140,13 @@ public:
134 FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; } 140 FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; }
135 const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; } 141 const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; }
136 unsigned char alpha() const { return theme()->alpha(); } 142 unsigned char alpha() const { return theme()->alpha(); }
137 static Menu* shownMenu();
138 static Menu* focused();
139 static void hideShownMenu();
140 const MenuItem *find(size_t i) const { return m_items[i]; } 143 const MenuItem *find(size_t i) const { return m_items[i]; }
141 MenuItem *find(size_t i) { return m_items[i]; } 144 MenuItem *find(size_t i) { return m_items[i]; }
145
146 // returns index of 'submenu', it it is in the top most list of
147 // menu items. -1 if no match is found
148 int findSubmenuIndex(const Menu* submenu) const;
149
142 //@} 150 //@}
143 /// @return true if index is valid 151 /// @return true if index is valid
144 bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); } 152 bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); }