OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #ifndef CONTROLS_MENU_VIEWS_MENU_2_H_ |
| 6 #define CONTROLS_MENU_VIEWS_MENU_2_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/gfx/native_widget_types.h" |
| 11 |
| 12 namespace gfx { |
| 13 class Point; |
| 14 } |
| 15 class SkBitmap; |
| 16 |
| 17 namespace views { |
| 18 |
| 19 class Accelerator; |
| 20 class Menu2; |
| 21 class MenuWrapper; |
| 22 |
| 23 // The Menu2Model is an interface implemented by an object that provides the |
| 24 // content of a menu. |
| 25 class Menu2Model { |
| 26 public: |
| 27 virtual ~Menu2Model() {} |
| 28 |
| 29 // The type of item. |
| 30 enum ItemType { |
| 31 TYPE_COMMAND, |
| 32 TYPE_CHECK, |
| 33 TYPE_RADIO, |
| 34 TYPE_SEPARATOR, |
| 35 TYPE_SUBMENU |
| 36 }; |
| 37 |
| 38 // Returns true if any of the items within the model have icons. Not all |
| 39 // platforms support icons in menus natively and so this is a hint for |
| 40 // triggering a custom rendering mode. |
| 41 virtual bool HasIcons() const = 0; |
| 42 |
| 43 // Returns the index of the first item. This is 0 for most menus except the |
| 44 // system menu on Windows. |native_menu| is the menu to locate the start index |
| 45 // within. It is guaranteed to be reset to a clean default state. |
| 46 // IMPORTANT: If the model implementation returns something _other_ than 0 |
| 47 // here, it must offset the values for |index| it passes to the |
| 48 // methods below by this number - this is NOT done automatically! |
| 49 virtual int GetFirstItemIndex(gfx::NativeMenu native_menu) const { return 0; } |
| 50 |
| 51 // Returns the number of items in the menu. |
| 52 virtual int GetItemCount() const = 0; |
| 53 |
| 54 // Returns the type of item at the specified index. |
| 55 virtual ItemType GetTypeAt(int index) const = 0; |
| 56 |
| 57 // Returns the command id of the item at the specified index. |
| 58 virtual int GetCommandIdAt(int index) const = 0; |
| 59 |
| 60 // Returns the label of the item at the specified index. |
| 61 virtual std::wstring GetLabelAt(int index) const = 0; |
| 62 |
| 63 // Returns true if the label at the specified index can change over the course |
| 64 // of the menu's lifetime. If this function returns true, the label of the |
| 65 // menu item will be updated each time the menu is shown. |
| 66 virtual bool IsLabelDynamicAt(int index) const = 0; |
| 67 |
| 68 // Gets the acclerator information for the specified index, returning true if |
| 69 // there is a shortcut accelerator for the item, false otherwise. |
| 70 virtual bool GetAcceleratorAt(int index, |
| 71 views::Accelerator* accelerator) const = 0; |
| 72 |
| 73 // Returns the checked state of the item at the specified index. |
| 74 virtual bool IsItemCheckedAt(int index) const = 0; |
| 75 |
| 76 // Returns the id of the group of radio items that the item at the specified |
| 77 // index belongs to. |
| 78 virtual int GetGroupIdAt(int index) const = 0; |
| 79 |
| 80 // Gets the icon for the item at the specified index, returning true if there |
| 81 // is an icon, false otherwise. |
| 82 virtual bool GetIconAt(int index, SkBitmap* icon) const = 0; |
| 83 |
| 84 // Returns the enabled state of the item at the specified index. |
| 85 virtual bool IsEnabledAt(int index) const = 0; |
| 86 |
| 87 // Returns the model for the submenu at the specified index. |
| 88 virtual Menu2Model* GetSubmenuModelAt(int index) const = 0; |
| 89 |
| 90 // Retrieves the model and index that contains a specific command id. Returns |
| 91 // true if an item with the specified command id is found. |model| is inout, |
| 92 // and specifies the model to start searching from. |
| 93 static bool GetModelAndIndexForCommandId(int command_id, Menu2Model** model, |
| 94 int* index); |
| 95 }; |
| 96 |
| 97 // The Menu2Delegate is an interface implemented by an object that performs |
| 98 // tasks that the Menu2 cannot itself. |
| 99 class Menu2Delegate { |
| 100 public: |
| 101 // Executes the command with the specified identifier. |
| 102 virtual void ExecuteCommand(Menu2Model* model, int command_id) = 0; |
| 103 }; |
| 104 |
| 105 // A menu. Populated from a model, and relies on a delegate to execute commands. |
| 106 class Menu2 { |
| 107 public: |
| 108 Menu2(Menu2Model* model, Menu2Delegate* delegate); |
| 109 virtual ~Menu2() {} |
| 110 |
| 111 // How the menu is aligned relative to the point it is shown at. |
| 112 enum Alignment { |
| 113 ALIGN_TOPLEFT, |
| 114 ALIGN_TOPRIGHT |
| 115 }; |
| 116 |
| 117 // Runs the menu at the specified point. This may or may not block, depending |
| 118 // on the platform and type of menu in use. |
| 119 void RunMenuAt(const gfx::Point& point, Alignment alignment); |
| 120 |
| 121 // Called when the model supplying data to this menu has changed, and the menu |
| 122 // must be rebuilt. |
| 123 void Rebuild(); |
| 124 |
| 125 // Called when the states of the menu items in the menu should be refreshed |
| 126 // from the model. |
| 127 void UpdateStates(); |
| 128 |
| 129 // For submenus. |
| 130 gfx::NativeMenu GetNativeMenu() const; |
| 131 |
| 132 // Accessors. |
| 133 Menu2Model* model() const { return model_; } |
| 134 Menu2Delegate* delegate() const { return delegate_; } |
| 135 |
| 136 private: |
| 137 Menu2Model* model_; |
| 138 Menu2Delegate* delegate_; |
| 139 |
| 140 // The object that actually implements the menu. |
| 141 MenuWrapper* wrapper_; |
| 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(Menu2); |
| 144 }; |
| 145 |
| 146 } // namespace views |
| 147 |
| 148 #endif // CONTROLS_MENU_VIEWS_MENU_2_H_ |
OLD | NEW |