| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
| 15 | 15 |
| 16 class SkBitmap; | |
| 17 | |
| 18 namespace gfx { | 16 namespace gfx { |
| 17 class ImageSkia; |
| 19 class Point; | 18 class Point; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace ui { | 21 namespace ui { |
| 23 class Accelerator; | 22 class Accelerator; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace views { | 25 namespace views { |
| 27 | 26 |
| 28 class VIEWS_EXPORT Menu { | 27 class VIEWS_EXPORT Menu { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 } | 55 } |
| 57 | 56 |
| 58 // The delegate needs to implement this function if it wants to display | 57 // The delegate needs to implement this function if it wants to display |
| 59 // the shortcut text next to each menu item. If there is an accelerator | 58 // the shortcut text next to each menu item. If there is an accelerator |
| 60 // for a given item id, the implementor must return it. | 59 // for a given item id, the implementor must return it. |
| 61 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel) { | 60 virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel) { |
| 62 return false; | 61 return false; |
| 63 } | 62 } |
| 64 | 63 |
| 65 // The icon shown for the menu item. | 64 // The icon shown for the menu item. |
| 66 virtual const SkBitmap& GetIcon(int id) const { | 65 virtual const gfx::ImageSkia& GetIcon(int id) const { |
| 67 return GetEmptyIcon(); | 66 return GetEmptyIcon(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 // The number of items to show in the menu | 69 // The number of items to show in the menu |
| 71 virtual int GetItemCount() const { | 70 virtual int GetItemCount() const { |
| 72 return 0; | 71 return 0; |
| 73 } | 72 } |
| 74 | 73 |
| 75 // Whether or not an item is a separator. | 74 // Whether or not an item is a separator. |
| 76 virtual bool IsItemSeparator(int id) const { | 75 virtual bool IsItemSeparator(int id) const { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| 119 virtual bool GetContextualLabel(int id, string16* out) const { | 118 virtual bool GetContextualLabel(int id, string16* out) const { |
| 120 return false; | 119 return false; |
| 121 } | 120 } |
| 122 virtual void ExecuteCommand(int id) { | 121 virtual void ExecuteCommand(int id) { |
| 123 } | 122 } |
| 124 | 123 |
| 125 protected: | 124 protected: |
| 126 // Returns an empty icon. | 125 // Returns an empty icon. |
| 127 const SkBitmap& GetEmptyIcon() const; | 126 const gfx::ImageSkia& GetEmptyIcon() const; |
| 128 }; | 127 }; |
| 129 | 128 |
| 130 // How this popup should align itself relative to the point it is run at. | 129 // How this popup should align itself relative to the point it is run at. |
| 131 enum AnchorPoint { | 130 enum AnchorPoint { |
| 132 TOPLEFT, | 131 TOPLEFT, |
| 133 TOPRIGHT | 132 TOPRIGHT |
| 134 }; | 133 }; |
| 135 | 134 |
| 136 // Different types of menu items | 135 // Different types of menu items |
| 137 enum MenuItemType { | 136 enum MenuItemType { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 Menu* AppendSubMenu(int item_id, | 186 Menu* AppendSubMenu(int item_id, |
| 188 const string16& label); | 187 const string16& label); |
| 189 Menu* AddSubMenu(int index, int item_id, const string16& label); | 188 Menu* AddSubMenu(int index, int item_id, const string16& label); |
| 190 | 189 |
| 191 // Append a submenu with an icon to this menu | 190 // Append a submenu with an icon to this menu |
| 192 // The returned pointer is owned by this menu. | 191 // The returned pointer is owned by this menu. |
| 193 // Unless the icon is empty, calling this function forces the Menu class | 192 // Unless the icon is empty, calling this function forces the Menu class |
| 194 // to draw the menu, instead of relying on Windows. | 193 // to draw the menu, instead of relying on Windows. |
| 195 Menu* AppendSubMenuWithIcon(int item_id, | 194 Menu* AppendSubMenuWithIcon(int item_id, |
| 196 const string16& label, | 195 const string16& label, |
| 197 const SkBitmap& icon); | 196 const gfx::ImageSkia& icon); |
| 198 virtual Menu* AddSubMenuWithIcon(int index, | 197 virtual Menu* AddSubMenuWithIcon(int index, |
| 199 int item_id, | 198 int item_id, |
| 200 const string16& label, | 199 const string16& label, |
| 201 const SkBitmap& icon) = 0; | 200 const gfx::ImageSkia& icon) = 0; |
| 202 | 201 |
| 203 // This is a convenience for standard text label menu items where the label | 202 // This is a convenience for standard text label menu items where the label |
| 204 // is provided with this call. | 203 // is provided with this call. |
| 205 void AppendMenuItemWithLabel(int item_id, const string16& label); | 204 void AppendMenuItemWithLabel(int item_id, const string16& label); |
| 206 void AddMenuItemWithLabel(int index, int item_id, const string16& label); | 205 void AddMenuItemWithLabel(int index, int item_id, const string16& label); |
| 207 | 206 |
| 208 // This is a convenience for text label menu items where the label is | 207 // This is a convenience for text label menu items where the label is |
| 209 // provided by the delegate. | 208 // provided by the delegate. |
| 210 void AppendDelegateMenuItem(int item_id); | 209 void AppendDelegateMenuItem(int item_id); |
| 211 void AddDelegateMenuItem(int index, int item_id); | 210 void AddDelegateMenuItem(int index, int item_id); |
| 212 | 211 |
| 213 // Adds a separator to this menu | 212 // Adds a separator to this menu |
| 214 void AppendSeparator(); | 213 void AppendSeparator(); |
| 215 virtual void AddSeparator(int index) = 0; | 214 virtual void AddSeparator(int index) = 0; |
| 216 | 215 |
| 217 // Appends a menu item with an icon. This is for the menu item which | 216 // Appends a menu item with an icon. This is for the menu item which |
| 218 // needs an icon. Calling this function forces the Menu class to draw | 217 // needs an icon. Calling this function forces the Menu class to draw |
| 219 // the menu, instead of relying on Windows. | 218 // the menu, instead of relying on Windows. |
| 220 void AppendMenuItemWithIcon(int item_id, | 219 void AppendMenuItemWithIcon(int item_id, |
| 221 const string16& label, | 220 const string16& label, |
| 222 const SkBitmap& icon); | 221 const gfx::ImageSkia& icon); |
| 223 virtual void AddMenuItemWithIcon(int index, | 222 virtual void AddMenuItemWithIcon(int index, |
| 224 int item_id, | 223 int item_id, |
| 225 const string16& label, | 224 const string16& label, |
| 226 const SkBitmap& icon); | 225 const gfx::ImageSkia& icon); |
| 227 | 226 |
| 228 // Enables or disables the item with the specified id. | 227 // Enables or disables the item with the specified id. |
| 229 virtual void EnableMenuItemByID(int item_id, bool enabled) = 0; | 228 virtual void EnableMenuItemByID(int item_id, bool enabled) = 0; |
| 230 virtual void EnableMenuItemAt(int index, bool enabled) = 0; | 229 virtual void EnableMenuItemAt(int index, bool enabled) = 0; |
| 231 | 230 |
| 232 // Sets menu label at specified index. | 231 // Sets menu label at specified index. |
| 233 virtual void SetMenuLabel(int item_id, const string16& label) = 0; | 232 virtual void SetMenuLabel(int item_id, const string16& label) = 0; |
| 234 | 233 |
| 235 // Sets an icon for an item with a given item_id. Calling this function | 234 // Sets an icon for an item with a given item_id. Calling this function |
| 236 // also forces the Menu class to draw the menu, instead of relying on Windows. | 235 // also forces the Menu class to draw the menu, instead of relying on Windows. |
| 237 // Returns false if the item with |item_id| is not found. | 236 // Returns false if the item with |item_id| is not found. |
| 238 virtual bool SetIcon(const SkBitmap& icon, int item_id) = 0; | 237 virtual bool SetIcon(const gfx::ImageSkia& icon, int item_id) = 0; |
| 239 | 238 |
| 240 // Shows the menu, blocks until the user dismisses the menu or selects an | 239 // Shows the menu, blocks until the user dismisses the menu or selects an |
| 241 // item, and executes the command for the selected item (if any). | 240 // item, and executes the command for the selected item (if any). |
| 242 // Warning: Blocking call. Will implicitly run a message loop. | 241 // Warning: Blocking call. Will implicitly run a message loop. |
| 243 virtual void RunMenuAt(int x, int y) = 0; | 242 virtual void RunMenuAt(int x, int y) = 0; |
| 244 | 243 |
| 245 // Cancels the menu. | 244 // Cancels the menu. |
| 246 virtual void Cancel() = 0; | 245 virtual void Cancel() = 0; |
| 247 | 246 |
| 248 // Returns the number of menu items. | 247 // Returns the number of menu items. |
| 249 virtual int ItemCount() = 0; | 248 virtual int ItemCount() = 0; |
| 250 | 249 |
| 251 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 252 // Returns the underlying menu handle | 251 // Returns the underlying menu handle |
| 253 virtual HMENU GetMenuHandle() const = 0; | 252 virtual HMENU GetMenuHandle() const = 0; |
| 254 #endif // defined(OS_WIN) | 253 #endif // defined(OS_WIN) |
| 255 | 254 |
| 256 protected: | 255 protected: |
| 257 explicit Menu(Menu* parent); | 256 explicit Menu(Menu* parent); |
| 258 | 257 |
| 259 virtual void AddMenuItemInternal(int index, | 258 virtual void AddMenuItemInternal(int index, |
| 260 int item_id, | 259 int item_id, |
| 261 const string16& label, | 260 const string16& label, |
| 262 const SkBitmap& icon, | 261 const gfx::ImageSkia& icon, |
| 263 MenuItemType type) = 0; | 262 MenuItemType type) = 0; |
| 264 | 263 |
| 265 private: | 264 private: |
| 266 // The delegate that is being used to get information about the presentation. | 265 // The delegate that is being used to get information about the presentation. |
| 267 Delegate* delegate_; | 266 Delegate* delegate_; |
| 268 | 267 |
| 269 // How this popup menu should be aligned relative to the point it is run at. | 268 // How this popup menu should be aligned relative to the point it is run at. |
| 270 AnchorPoint anchor_; | 269 AnchorPoint anchor_; |
| 271 | 270 |
| 272 DISALLOW_COPY_AND_ASSIGN(Menu); | 271 DISALLOW_COPY_AND_ASSIGN(Menu); |
| 273 }; | 272 }; |
| 274 | 273 |
| 275 } // namespace views | 274 } // namespace views |
| 276 | 275 |
| 277 #endif // UI_VIEWS_CONTROLS_MENU_MENU_H_ | 276 #endif // UI_VIEWS_CONTROLS_MENU_MENU_H_ |
| OLD | NEW |