Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: views/controls/menu/simple_menu_model.cc

Issue 119237: A new menu system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/simple_menu_model.h ('k') | views/view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "views/controls/menu/simple_menu_model.h"
6
7 #include "app/l10n_util.h"
8
9 namespace views {
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // SimpleMenuModel, public:
13
14 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) {
15 }
16
17 SimpleMenuModel::~SimpleMenuModel() {
18 }
19
20 void SimpleMenuModel::AddItem(int command_id, const std::wstring& label) {
21 Item item = { command_id, label, TYPE_COMMAND, -1, NULL };
22 items_.push_back(item);
23 }
24
25 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) {
26 AddItem(command_id, l10n_util::GetString(string_id));
27 }
28
29 void SimpleMenuModel::AddSeparator() {
30 Item item = { -1, std::wstring(), TYPE_SEPARATOR, -1, NULL };
31 items_.push_back(item);
32 }
33
34 void SimpleMenuModel::AddCheckItem(int command_id, const std::wstring& label) {
35 Item item = { command_id, label, TYPE_CHECK, -1, NULL };
36 items_.push_back(item);
37 }
38
39 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) {
40 AddCheckItem(command_id, l10n_util::GetString(string_id));
41 }
42
43 void SimpleMenuModel::AddRadioItem(int command_id, const std::wstring& label,
44 int group_id) {
45 Item item = { command_id, label, TYPE_RADIO, group_id, NULL };
46 items_.push_back(item);
47 }
48
49 void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id,
50 int group_id) {
51 AddRadioItem(command_id, l10n_util::GetString(string_id), group_id);
52 }
53
54 void SimpleMenuModel::AddSubMenu(const std::wstring& label, Menu2Model* model) {
55 Item item = { -1, label, TYPE_SUBMENU, -1, model };
56 items_.push_back(item);
57 }
58
59 void SimpleMenuModel::AddSubMenuWithStringId(int string_id, Menu2Model* model) {
60 AddSubMenu(l10n_util::GetString(string_id), model);
61 }
62
63 ////////////////////////////////////////////////////////////////////////////////
64 // SimpleMenuModel, Menu2Model implementation:
65
66 bool SimpleMenuModel::HasIcons() const {
67 return false;
68 }
69
70 int SimpleMenuModel::GetItemCount() const {
71 return static_cast<int>(items_.size());
72 }
73
74 Menu2Model::ItemType SimpleMenuModel::GetTypeAt(int index) const {
75 return items_.at(FlipIndex(index)).type;
76 }
77
78 int SimpleMenuModel::GetCommandIdAt(int index) const {
79 return items_.at(FlipIndex(index)).command_id;
80 }
81
82 std::wstring SimpleMenuModel::GetLabelAt(int index) const {
83 if (IsLabelDynamicAt(index))
84 return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
85 return items_.at(FlipIndex(index)).label;
86 }
87
88 bool SimpleMenuModel::IsLabelDynamicAt(int index) const {
89 if (delegate_)
90 return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index));
91 return false;
92 }
93
94 bool SimpleMenuModel::GetAcceleratorAt(int index,
95 views::Accelerator* accelerator) const {
96 if (delegate_) {
97 return delegate_->GetAcceleratorForCommandId(GetCommandIdAt(index),
98 accelerator);
99 }
100 return false;
101 }
102
103 bool SimpleMenuModel::IsItemCheckedAt(int index) const {
104 if (!delegate_)
105 return false;
106 return delegate_->IsCommandIdChecked(GetCommandIdAt(index));
107 }
108
109 int SimpleMenuModel::GetGroupIdAt(int index) const {
110 return items_.at(FlipIndex(index)).group_id;
111 }
112
113 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
114 return false;
115 }
116
117 bool SimpleMenuModel::IsEnabledAt(int index) const {
118 int command_id = GetCommandIdAt(index);
119 // Submenus have a command id of -1, they should always be enabled.
120 if (!delegate_ || command_id == -1)
121 return true;
122 return delegate_->IsCommandIdEnabled(command_id);
123 }
124
125 Menu2Model* SimpleMenuModel::GetSubmenuModelAt(int index) const {
126 return items_.at(FlipIndex(index)).submenu;
127 }
128
129 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/simple_menu_model.h ('k') | views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698