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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/menu/simple_menu_model.h ('k') | views/view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/menu/simple_menu_model.cc
===================================================================
--- views/controls/menu/simple_menu_model.cc (revision 0)
+++ views/controls/menu/simple_menu_model.cc (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include "views/controls/menu/simple_menu_model.h"
+
+#include "app/l10n_util.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// SimpleMenuModel, public:
+
+SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) {
+}
+
+SimpleMenuModel::~SimpleMenuModel() {
+}
+
+void SimpleMenuModel::AddItem(int command_id, const std::wstring& label) {
+ Item item = { command_id, label, TYPE_COMMAND, -1, NULL };
+ items_.push_back(item);
+}
+
+void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) {
+ AddItem(command_id, l10n_util::GetString(string_id));
+}
+
+void SimpleMenuModel::AddSeparator() {
+ Item item = { -1, std::wstring(), TYPE_SEPARATOR, -1, NULL };
+ items_.push_back(item);
+}
+
+void SimpleMenuModel::AddCheckItem(int command_id, const std::wstring& label) {
+ Item item = { command_id, label, TYPE_CHECK, -1, NULL };
+ items_.push_back(item);
+}
+
+void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) {
+ AddCheckItem(command_id, l10n_util::GetString(string_id));
+}
+
+void SimpleMenuModel::AddRadioItem(int command_id, const std::wstring& label,
+ int group_id) {
+ Item item = { command_id, label, TYPE_RADIO, group_id, NULL };
+ items_.push_back(item);
+}
+
+void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id,
+ int group_id) {
+ AddRadioItem(command_id, l10n_util::GetString(string_id), group_id);
+}
+
+void SimpleMenuModel::AddSubMenu(const std::wstring& label, Menu2Model* model) {
+ Item item = { -1, label, TYPE_SUBMENU, -1, model };
+ items_.push_back(item);
+}
+
+void SimpleMenuModel::AddSubMenuWithStringId(int string_id, Menu2Model* model) {
+ AddSubMenu(l10n_util::GetString(string_id), model);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// SimpleMenuModel, Menu2Model implementation:
+
+bool SimpleMenuModel::HasIcons() const {
+ return false;
+}
+
+int SimpleMenuModel::GetItemCount() const {
+ return static_cast<int>(items_.size());
+}
+
+Menu2Model::ItemType SimpleMenuModel::GetTypeAt(int index) const {
+ return items_.at(FlipIndex(index)).type;
+}
+
+int SimpleMenuModel::GetCommandIdAt(int index) const {
+ return items_.at(FlipIndex(index)).command_id;
+}
+
+std::wstring SimpleMenuModel::GetLabelAt(int index) const {
+ if (IsLabelDynamicAt(index))
+ return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
+ return items_.at(FlipIndex(index)).label;
+}
+
+bool SimpleMenuModel::IsLabelDynamicAt(int index) const {
+ if (delegate_)
+ return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index));
+ return false;
+}
+
+bool SimpleMenuModel::GetAcceleratorAt(int index,
+ views::Accelerator* accelerator) const {
+ if (delegate_) {
+ return delegate_->GetAcceleratorForCommandId(GetCommandIdAt(index),
+ accelerator);
+ }
+ return false;
+}
+
+bool SimpleMenuModel::IsItemCheckedAt(int index) const {
+ if (!delegate_)
+ return false;
+ return delegate_->IsCommandIdChecked(GetCommandIdAt(index));
+}
+
+int SimpleMenuModel::GetGroupIdAt(int index) const {
+ return items_.at(FlipIndex(index)).group_id;
+}
+
+bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
+ return false;
+}
+
+bool SimpleMenuModel::IsEnabledAt(int index) const {
+ int command_id = GetCommandIdAt(index);
+ // Submenus have a command id of -1, they should always be enabled.
+ if (!delegate_ || command_id == -1)
+ return true;
+ return delegate_->IsCommandIdEnabled(command_id);
+}
+
+Menu2Model* SimpleMenuModel::GetSubmenuModelAt(int index) const {
+ return items_.at(FlipIndex(index)).submenu;
+}
+
+} // namespace views
« 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