OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_H_ |
6 #define UI_VIEWS_CONTROLS_MENU_MENU_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 virtual ~Delegate() {} | 38 virtual ~Delegate() {} |
39 | 39 |
40 // Whether or not an item should be shown as checked. | 40 // Whether or not an item should be shown as checked. |
41 virtual bool IsItemChecked(int id) const; | 41 virtual bool IsItemChecked(int id) const; |
42 | 42 |
43 // Whether or not an item should be shown as the default (using bold). | 43 // Whether or not an item should be shown as the default (using bold). |
44 // There can only be one default menu item. | 44 // There can only be one default menu item. |
45 virtual bool IsItemDefault(int id) const; | 45 virtual bool IsItemDefault(int id) const; |
46 | 46 |
47 // The string shown for the menu item. | 47 // The string shown for the menu item. |
48 virtual string16 GetLabel(int id) const; | 48 virtual base::string16 GetLabel(int id) const; |
49 | 49 |
50 // The delegate needs to implement this function if it wants to display | 50 // The delegate needs to implement this function if it wants to display |
51 // the shortcut text next to each menu item. If there is an accelerator | 51 // the shortcut text next to each menu item. If there is an accelerator |
52 // for a given item id, the implementor must return it. | 52 // for a given item id, the implementor must return it. |
53 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel); | 53 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel); |
54 | 54 |
55 // The icon shown for the menu item. | 55 // The icon shown for the menu item. |
56 virtual const gfx::ImageSkia& GetIcon(int id) const; | 56 virtual const gfx::ImageSkia& GetIcon(int id) const; |
57 | 57 |
58 // The number of items to show in the menu | 58 // The number of items to show in the menu |
(...skipping 28 matching lines...) Expand all Loading... |
87 // since there is no reason to show left-to-right menus for right-to-left | 87 // since there is no reason to show left-to-right menus for right-to-left |
88 // locales. However, subclasses can override this behavior so that the menu | 88 // locales. However, subclasses can override this behavior so that the menu |
89 // is a right-to-left menu only if the view's layout is right-to-left | 89 // is a right-to-left menu only if the view's layout is right-to-left |
90 // (since the view can use a different layout than the locale's language | 90 // (since the view can use a different layout than the locale's language |
91 // layout). | 91 // layout). |
92 virtual bool IsRightToLeftUILayout() const; | 92 virtual bool IsRightToLeftUILayout() const; |
93 | 93 |
94 // Controller | 94 // Controller |
95 virtual bool SupportsCommand(int id) const; | 95 virtual bool SupportsCommand(int id) const; |
96 virtual bool IsCommandEnabled(int id) const; | 96 virtual bool IsCommandEnabled(int id) const; |
97 virtual bool GetContextualLabel(int id, string16* out) const; | 97 virtual bool GetContextualLabel(int id, base::string16* out) const; |
98 virtual void ExecuteCommand(int id) { | 98 virtual void ExecuteCommand(int id) { |
99 } | 99 } |
100 | 100 |
101 protected: | 101 protected: |
102 // Returns an empty icon. | 102 // Returns an empty icon. |
103 const gfx::ImageSkia& GetEmptyIcon() const; | 103 const gfx::ImageSkia& GetEmptyIcon() const; |
104 }; | 104 }; |
105 | 105 |
106 // How this popup should align itself relative to the point it is run at. | 106 // How this popup should align itself relative to the point it is run at. |
107 enum AnchorPoint { | 107 enum AnchorPoint { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 // Adds an item to this menu. | 145 // Adds an item to this menu. |
146 // item_id The id of the item, used to identify it in delegate callbacks | 146 // item_id The id of the item, used to identify it in delegate callbacks |
147 // or (if delegate is NULL) to identify the command associated | 147 // or (if delegate is NULL) to identify the command associated |
148 // with this item with the controller specified in the ctor. Note | 148 // with this item with the controller specified in the ctor. Note |
149 // that this value should not be 0 as this has a special meaning | 149 // that this value should not be 0 as this has a special meaning |
150 // ("NULL command, no item selected") | 150 // ("NULL command, no item selected") |
151 // label The text label shown. | 151 // label The text label shown. |
152 // type The type of item. | 152 // type The type of item. |
153 void AppendMenuItem(int item_id, | 153 void AppendMenuItem(int item_id, |
154 const string16& label, | 154 const base::string16& label, |
155 MenuItemType type); | 155 MenuItemType type); |
156 void AddMenuItem(int index, | 156 void AddMenuItem(int index, |
157 int item_id, | 157 int item_id, |
158 const string16& label, | 158 const base::string16& label, |
159 MenuItemType type); | 159 MenuItemType type); |
160 | 160 |
161 // Append a submenu to this menu. | 161 // Append a submenu to this menu. |
162 // The returned pointer is owned by this menu. | 162 // The returned pointer is owned by this menu. |
163 Menu* AppendSubMenu(int item_id, | 163 Menu* AppendSubMenu(int item_id, |
164 const string16& label); | 164 const base::string16& label); |
165 Menu* AddSubMenu(int index, int item_id, const string16& label); | 165 Menu* AddSubMenu(int index, int item_id, const base::string16& label); |
166 | 166 |
167 // Append a submenu with an icon to this menu | 167 // Append a submenu with an icon to this menu |
168 // The returned pointer is owned by this menu. | 168 // The returned pointer is owned by this menu. |
169 // Unless the icon is empty, calling this function forces the Menu class | 169 // Unless the icon is empty, calling this function forces the Menu class |
170 // to draw the menu, instead of relying on Windows. | 170 // to draw the menu, instead of relying on Windows. |
171 Menu* AppendSubMenuWithIcon(int item_id, | 171 Menu* AppendSubMenuWithIcon(int item_id, |
172 const string16& label, | 172 const base::string16& label, |
173 const gfx::ImageSkia& icon); | 173 const gfx::ImageSkia& icon); |
174 virtual Menu* AddSubMenuWithIcon(int index, | 174 virtual Menu* AddSubMenuWithIcon(int index, |
175 int item_id, | 175 int item_id, |
176 const string16& label, | 176 const base::string16& label, |
177 const gfx::ImageSkia& icon) = 0; | 177 const gfx::ImageSkia& icon) = 0; |
178 | 178 |
179 // This is a convenience for standard text label menu items where the label | 179 // This is a convenience for standard text label menu items where the label |
180 // is provided with this call. | 180 // is provided with this call. |
181 void AppendMenuItemWithLabel(int item_id, const string16& label); | 181 void AppendMenuItemWithLabel(int item_id, const base::string16& label); |
182 void AddMenuItemWithLabel(int index, int item_id, const string16& label); | 182 void AddMenuItemWithLabel(int index, |
| 183 int item_id, |
| 184 const base::string16& label); |
183 | 185 |
184 // This is a convenience for text label menu items where the label is | 186 // This is a convenience for text label menu items where the label is |
185 // provided by the delegate. | 187 // provided by the delegate. |
186 void AppendDelegateMenuItem(int item_id); | 188 void AppendDelegateMenuItem(int item_id); |
187 void AddDelegateMenuItem(int index, int item_id); | 189 void AddDelegateMenuItem(int index, int item_id); |
188 | 190 |
189 // Adds a separator to this menu | 191 // Adds a separator to this menu |
190 void AppendSeparator(); | 192 void AppendSeparator(); |
191 virtual void AddSeparator(int index) = 0; | 193 virtual void AddSeparator(int index) = 0; |
192 | 194 |
193 // Appends a menu item with an icon. This is for the menu item which | 195 // Appends a menu item with an icon. This is for the menu item which |
194 // needs an icon. Calling this function forces the Menu class to draw | 196 // needs an icon. Calling this function forces the Menu class to draw |
195 // the menu, instead of relying on Windows. | 197 // the menu, instead of relying on Windows. |
196 void AppendMenuItemWithIcon(int item_id, | 198 void AppendMenuItemWithIcon(int item_id, |
197 const string16& label, | 199 const base::string16& label, |
198 const gfx::ImageSkia& icon); | 200 const gfx::ImageSkia& icon); |
199 virtual void AddMenuItemWithIcon(int index, | 201 virtual void AddMenuItemWithIcon(int index, |
200 int item_id, | 202 int item_id, |
201 const string16& label, | 203 const base::string16& label, |
202 const gfx::ImageSkia& icon); | 204 const gfx::ImageSkia& icon); |
203 | 205 |
204 // Enables or disables the item with the specified id. | 206 // Enables or disables the item with the specified id. |
205 virtual void EnableMenuItemByID(int item_id, bool enabled) = 0; | 207 virtual void EnableMenuItemByID(int item_id, bool enabled) = 0; |
206 virtual void EnableMenuItemAt(int index, bool enabled) = 0; | 208 virtual void EnableMenuItemAt(int index, bool enabled) = 0; |
207 | 209 |
208 // Sets menu label at specified index. | 210 // Sets menu label at specified index. |
209 virtual void SetMenuLabel(int item_id, const string16& label) = 0; | 211 virtual void SetMenuLabel(int item_id, const base::string16& label) = 0; |
210 | 212 |
211 // Sets an icon for an item with a given item_id. Calling this function | 213 // Sets an icon for an item with a given item_id. Calling this function |
212 // also forces the Menu class to draw the menu, instead of relying on Windows. | 214 // also forces the Menu class to draw the menu, instead of relying on Windows. |
213 // Returns false if the item with |item_id| is not found. | 215 // Returns false if the item with |item_id| is not found. |
214 virtual bool SetIcon(const gfx::ImageSkia& icon, int item_id) = 0; | 216 virtual bool SetIcon(const gfx::ImageSkia& icon, int item_id) = 0; |
215 | 217 |
216 // Shows the menu, blocks until the user dismisses the menu or selects an | 218 // Shows the menu, blocks until the user dismisses the menu or selects an |
217 // item, and executes the command for the selected item (if any). | 219 // item, and executes the command for the selected item (if any). |
218 // Warning: Blocking call. Will implicitly run a message loop. | 220 // Warning: Blocking call. Will implicitly run a message loop. |
219 virtual void RunMenuAt(int x, int y) = 0; | 221 virtual void RunMenuAt(int x, int y) = 0; |
220 | 222 |
221 // Cancels the menu. | 223 // Cancels the menu. |
222 virtual void Cancel() = 0; | 224 virtual void Cancel() = 0; |
223 | 225 |
224 // Returns the number of menu items. | 226 // Returns the number of menu items. |
225 virtual int ItemCount() = 0; | 227 virtual int ItemCount() = 0; |
226 | 228 |
227 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
228 // Returns the underlying menu handle | 230 // Returns the underlying menu handle |
229 virtual HMENU GetMenuHandle() const = 0; | 231 virtual HMENU GetMenuHandle() const = 0; |
230 #endif // defined(OS_WIN) | 232 #endif // defined(OS_WIN) |
231 | 233 |
232 protected: | 234 protected: |
233 explicit Menu(Menu* parent); | 235 explicit Menu(Menu* parent); |
234 | 236 |
235 virtual void AddMenuItemInternal(int index, | 237 virtual void AddMenuItemInternal(int index, |
236 int item_id, | 238 int item_id, |
237 const string16& label, | 239 const base::string16& label, |
238 const gfx::ImageSkia& icon, | 240 const gfx::ImageSkia& icon, |
239 MenuItemType type) = 0; | 241 MenuItemType type) = 0; |
240 | 242 |
241 private: | 243 private: |
242 // The delegate that is being used to get information about the presentation. | 244 // The delegate that is being used to get information about the presentation. |
243 Delegate* delegate_; | 245 Delegate* delegate_; |
244 | 246 |
245 // How this popup menu should be aligned relative to the point it is run at. | 247 // How this popup menu should be aligned relative to the point it is run at. |
246 AnchorPoint anchor_; | 248 AnchorPoint anchor_; |
247 | 249 |
248 DISALLOW_COPY_AND_ASSIGN(Menu); | 250 DISALLOW_COPY_AND_ASSIGN(Menu); |
249 }; | 251 }; |
250 | 252 |
251 } // namespace views | 253 } // namespace views |
252 | 254 |
253 #endif // UI_VIEWS_CONTROLS_MENU_MENU_H_ | 255 #endif // UI_VIEWS_CONTROLS_MENU_MENU_H_ |
OLD | NEW |