| 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_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
| 6 #define UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 6 #define UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // The Delegate can be NULL, though if it is items can't be checked or | 69 // The Delegate can be NULL, though if it is items can't be checked or |
| 70 // disabled. | 70 // disabled. |
| 71 explicit SimpleMenuModel(Delegate* delegate); | 71 explicit SimpleMenuModel(Delegate* delegate); |
| 72 virtual ~SimpleMenuModel(); | 72 virtual ~SimpleMenuModel(); |
| 73 | 73 |
| 74 // Methods for adding items to the model. | 74 // Methods for adding items to the model. |
| 75 void AddItem(int command_id, const string16& label); | 75 void AddItem(int command_id, const string16& label); |
| 76 void AddItemWithStringId(int command_id, int string_id); | 76 void AddItemWithStringId(int command_id, int string_id); |
| 77 void AddSeparator(); | 77 void AddSeparator(MenuSeparatorType separator_type); |
| 78 void AddCheckItem(int command_id, const string16& label); | 78 void AddCheckItem(int command_id, const string16& label); |
| 79 void AddCheckItemWithStringId(int command_id, int string_id); | 79 void AddCheckItemWithStringId(int command_id, int string_id); |
| 80 void AddRadioItem(int command_id, const string16& label, int group_id); | 80 void AddRadioItem(int command_id, const string16& label, int group_id); |
| 81 void AddRadioItemWithStringId(int command_id, int string_id, int group_id); | 81 void AddRadioItemWithStringId(int command_id, int string_id, int group_id); |
| 82 | 82 |
| 83 // These three methods take pointers to various sub-models. These models | 83 // These three methods take pointers to various sub-models. These models |
| 84 // should be owned by the same owner of this SimpleMenuModel. | 84 // should be owned by the same owner of this SimpleMenuModel. |
| 85 void AddButtonItem(int command_id, ButtonMenuItemModel* model); | 85 void AddButtonItem(int command_id, ButtonMenuItemModel* model); |
| 86 void AddSubMenu(int command_id, const string16& label, MenuModel* model); | 86 void AddSubMenu(int command_id, const string16& label, MenuModel* model); |
| 87 void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); | 87 void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); |
| 88 | 88 |
| 89 // Methods for inserting items into the model. | 89 // Methods for inserting items into the model. |
| 90 void InsertItemAt(int index, int command_id, const string16& label); | 90 void InsertItemAt(int index, int command_id, const string16& label); |
| 91 void InsertItemWithStringIdAt(int index, int command_id, int string_id); | 91 void InsertItemWithStringIdAt(int index, int command_id, int string_id); |
| 92 void InsertSeparatorAt(int index); | 92 void InsertSeparatorAt(int index, MenuSeparatorType separator_type); |
| 93 void InsertCheckItemAt(int index, int command_id, const string16& label); | 93 void InsertCheckItemAt(int index, int command_id, const string16& label); |
| 94 void InsertCheckItemWithStringIdAt(int index, int command_id, int string_id); | 94 void InsertCheckItemWithStringIdAt(int index, int command_id, int string_id); |
| 95 void InsertRadioItemAt( | 95 void InsertRadioItemAt( |
| 96 int index, int command_id, const string16& label, int group_id); | 96 int index, int command_id, const string16& label, int group_id); |
| 97 void InsertRadioItemWithStringIdAt( | 97 void InsertRadioItemWithStringIdAt( |
| 98 int index, int command_id, int string_id, int group_id); | 98 int index, int command_id, int string_id, int group_id); |
| 99 void InsertSubMenuAt( | 99 void InsertSubMenuAt( |
| 100 int index, int command_id, const string16& label, MenuModel* model); | 100 int index, int command_id, const string16& label, MenuModel* model); |
| 101 void InsertSubMenuWithStringIdAt( | 101 void InsertSubMenuWithStringIdAt( |
| 102 int index, int command_id, int string_id, MenuModel* model); | 102 int index, int command_id, int string_id, MenuModel* model); |
| 103 | 103 |
| 104 // Sets the icon for the item at |index|. | 104 // Sets the icon for the item at |index|. |
| 105 void SetIcon(int index, const gfx::Image& icon); | 105 void SetIcon(int index, const gfx::Image& icon); |
| 106 | 106 |
| 107 // Clears all items. Note that it does not free MenuModel of submenu. | 107 // Clears all items. Note that it does not free MenuModel of submenu. |
| 108 void Clear(); | 108 void Clear(); |
| 109 | 109 |
| 110 // Returns the index of the item that has the given |command_id|. Returns | 110 // Returns the index of the item that has the given |command_id|. Returns |
| 111 // -1 if not found. | 111 // -1 if not found. |
| 112 int GetIndexOfCommandId(int command_id); | 112 int GetIndexOfCommandId(int command_id); |
| 113 | 113 |
| 114 // Overridden from MenuModel: | 114 // Overridden from MenuModel: |
| 115 virtual bool HasIcons() const OVERRIDE; | 115 virtual bool HasIcons() const OVERRIDE; |
| 116 virtual int GetItemCount() const OVERRIDE; | 116 virtual int GetItemCount() const OVERRIDE; |
| 117 virtual ItemType GetTypeAt(int index) const OVERRIDE; | 117 virtual ItemType GetTypeAt(int index) const OVERRIDE; |
| 118 virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE; |
| 118 virtual int GetCommandIdAt(int index) const OVERRIDE; | 119 virtual int GetCommandIdAt(int index) const OVERRIDE; |
| 119 virtual string16 GetLabelAt(int index) const OVERRIDE; | 120 virtual string16 GetLabelAt(int index) const OVERRIDE; |
| 120 virtual bool IsItemDynamicAt(int index) const OVERRIDE; | 121 virtual bool IsItemDynamicAt(int index) const OVERRIDE; |
| 121 virtual bool GetAcceleratorAt(int index, | 122 virtual bool GetAcceleratorAt(int index, |
| 122 ui::Accelerator* accelerator) const OVERRIDE; | 123 ui::Accelerator* accelerator) const OVERRIDE; |
| 123 virtual bool IsItemCheckedAt(int index) const OVERRIDE; | 124 virtual bool IsItemCheckedAt(int index) const OVERRIDE; |
| 124 virtual int GetGroupIdAt(int index) const OVERRIDE; | 125 virtual int GetGroupIdAt(int index) const OVERRIDE; |
| 125 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE; | 126 virtual bool GetIconAt(int index, gfx::Image* icon) OVERRIDE; |
| 126 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( | 127 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( |
| 127 int index) const OVERRIDE; | 128 int index) const OVERRIDE; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 MenuModelDelegate* menu_model_delegate_; | 173 MenuModelDelegate* menu_model_delegate_; |
| 173 | 174 |
| 174 base::WeakPtrFactory<SimpleMenuModel> method_factory_; | 175 base::WeakPtrFactory<SimpleMenuModel> method_factory_; |
| 175 | 176 |
| 176 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); | 177 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 } // namespace ui | 180 } // namespace ui |
| 180 | 181 |
| 181 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ | 182 #endif // UI_BASE_MODELS_SIMPLE_MENU_MODEL_H_ |
| OLD | NEW |