aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Menu.hh
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-15 13:24:46 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-15 13:25:05 (GMT)
commit8387742c8860694777f7c2c62da0a90c9e836988 (patch)
treee5bd5a50c3e033ea73a9339474750287d06aeb3f /src/FbTk/Menu.hh
parentb4cd45549013e8b45f95bf3e123cd14684948e91 (diff)
downloadfluxbox-8387742c8860694777f7c2c62da0a90c9e836988.zip
fluxbox-8387742c8860694777f7c2c62da0a90c9e836988.tar.bz2
Refactor menu code: be more explicit and compact
This commit is a preparation step for some menu cleanup ahead. To make it easier to understand which types of MenuItems are added where and when, I converted the overloaded FbTk::Menu::insert() functions into explicit ones (Menu::insertSubmenu(), Menu::insertItem(), etc. ). This makes it possible to just grep for 'insertSubmenu()'. Side effect this commit: it trims down the very verbose creation of menu items in regards to how the labels are created. Minor: FbTk::Menu::shown and FbTk::Menu::s_focused are moved out of the class.
Diffstat (limited to 'src/FbTk/Menu.hh')
-rw-r--r--src/FbTk/Menu.hh38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 5e1d98c..49893c1 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -60,28 +60,18 @@ public:
60 @name manipulators 60 @name manipulators
61 */ 61 */
62 //@{ 62 //@{
63 /// add a menu item with a label and a command 63 int insertCommand(const FbString &label, RefCount<Command<void> > &cmd, int pos=-1);
64 int insert(const FbString &label, RefCount<Command<void> > &cmd, int pos=-1);
65 /// add empty menu item
66 int insert(const FbString &label, int pos=-1); 64 int insert(const FbString &label, int pos=-1);
67 /// add submenu 65 int insertSubmenu(const FbString &label, Menu *submenu, int pos= -1);
68 int insert(const FbString &label, Menu *submenu, int pos= -1); 66 int insertItem(MenuItem *item, int pos=-1);
69 /// add menu item
70 int insert(MenuItem *item, int pos=-1);
71 /// remove an item
72 int remove(unsigned int item); 67 int remove(unsigned int item);
73 /// remove all items
74 void removeAll(); 68 void removeAll();
75 void setInternalMenu(bool val = true) { m_internal_menu = val; } 69 void setInternalMenu(bool val = true) { m_internal_menu = val; }
76 void setAlignment(Alignment a) { m_alignment = a; } 70 void setAlignment(Alignment a) { m_alignment = a; }
77 71
78 /// raise this window
79 virtual void raise(); 72 virtual void raise();
80 /// lower this window
81 virtual void lower(); 73 virtual void lower();
82 /// cycle through menuitems
83 void cycleItems(bool reverse); 74 void cycleItems(bool reverse);
84 /// set and highlight new active index
85 void setActiveIndex(int new_index); 75 void setActiveIndex(int new_index);
86 void enterSubmenu(); 76 void enterSubmenu();
87 77
@@ -89,7 +79,7 @@ public:
89 void enableTitle(); 79 void enableTitle();
90 bool isTitleVisible() const { return m_title_vis; } 80 bool isTitleVisible() const { return m_title_vis; }
91 81
92 void setScreen(int x, int y, int w, int h); 82 void setScreen(int x, int y, unsigned int w, unsigned int h);
93 83
94 /** 84 /**
95 @name event handlers 85 @name event handlers
@@ -103,21 +93,16 @@ public:
103 void keyPressEvent(XKeyEvent &ke); 93 void keyPressEvent(XKeyEvent &ke);
104 void leaveNotifyEvent(XCrossingEvent &ce); 94 void leaveNotifyEvent(XCrossingEvent &ce);
105 //@} 95 //@}
106 /// get input focus
107 void grabInputFocus(); 96 void grabInputFocus();
108 virtual void reconfigure(); 97 virtual void reconfigure();
109 /// set label string
110 void setLabel(const FbTk::BiDiString &labelstr); 98 void setLabel(const FbTk::BiDiString &labelstr);
111 /// move menu to x,y
112 virtual void move(int x, int y); 99 virtual void move(int x, int y);
113 virtual void updateMenu(); 100 virtual void updateMenu();
114 void setItemSelected(unsigned int index, bool val); 101 void setItemSelected(unsigned int index, bool val);
115 void setItemEnabled(unsigned int index, bool val); 102 void setItemEnabled(unsigned int index, bool val);
116 void setMinimumColumns(int columns) { m_min_columns = columns; } 103 void setMinimumColumns(int columns) { m_min_columns = columns; }
117 virtual void drawSubmenu(unsigned int index); 104 virtual void drawSubmenu(unsigned int index);
118 /// show menu
119 virtual void show(); 105 virtual void show();
120 /// hide menu
121 virtual void hide(bool force = false); 106 virtual void hide(bool force = false);
122 virtual void clearWindow(); 107 virtual void clearWindow();
123 /*@}*/ 108 /*@}*/
@@ -140,7 +125,7 @@ public:
140 int y() const { return m_window.y(); } 125 int y() const { return m_window.y(); }
141 unsigned int width() const { return m_window.width(); } 126 unsigned int width() const { return m_window.width(); }
142 unsigned int height() const { return m_window.height(); } 127 unsigned int height() const { return m_window.height(); }
143 size_t numberOfItems() const { return menuitems.size(); } 128 size_t numberOfItems() const { return m_items.size(); }
144 int currentSubmenu() const { return m_which_sub; } 129 int currentSubmenu() const { return m_which_sub; }
145 130
146 bool isItemSelected(unsigned int index) const; 131 bool isItemSelected(unsigned int index) const;
@@ -149,12 +134,11 @@ public:
149 FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; } 134 FbTk::ThemeProxy<MenuTheme> &theme() { return m_theme; }
150 const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; } 135 const FbTk::ThemeProxy<MenuTheme> &theme() const { return m_theme; }
151 unsigned char alpha() const { return theme()->alpha(); } 136 unsigned char alpha() const { return theme()->alpha(); }
152 static Menu *shownMenu() { return shown; } 137 static Menu* shownMenu();
153 static Menu *focused() { return s_focused; } 138 static Menu* focused();
154 static void hideShownMenu(); 139 static void hideShownMenu();
155 /// @return menuitem at index 140 const MenuItem *find(size_t i) const { return m_items[i]; }
156 const MenuItem *find(unsigned int index) const { return menuitems[index]; } 141 MenuItem *find(size_t i) { return m_items[i]; }
157 MenuItem *find(unsigned int index) { return menuitems[index]; }
158 //@} 142 //@}
159 /// @return true if index is valid 143 /// @return true if index is valid
160 bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); } 144 bool validIndex(int index) const { return (index < static_cast<int>(numberOfItems()) && index >= 0); }
@@ -198,7 +182,7 @@ private:
198 ImageControl &m_image_ctrl; 182 ImageControl &m_image_ctrl;
199 183
200 typedef std::vector<MenuItem *> Menuitems; 184 typedef std::vector<MenuItem *> Menuitems;
201 Menuitems menuitems; 185 Menuitems m_items;
202 TypeAhead<Menuitems, MenuItem *> m_type_ahead; 186 TypeAhead<Menuitems, MenuItem *> m_type_ahead;
203 Menuitems m_matches; 187 Menuitems m_matches;
204 188
@@ -250,8 +234,6 @@ private:
250 // the corners 234 // the corners
251 std::auto_ptr<FbTk::Shape> m_shape; 235 std::auto_ptr<FbTk::Shape> m_shape;
252 236
253 static Menu *shown; ///< used for determining if there's a menu open at all
254 static Menu *s_focused; ///< holds current input focused menu, so one can determine if a menu is focused
255 bool m_need_update; 237 bool m_need_update;
256 Timer m_submenu_timer; 238 Timer m_submenu_timer;
257 Timer m_hide_timer; 239 Timer m_hide_timer;