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

Unified Diff: views/controls/menu/simple_menu_model.h

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/native_menu_win.cc ('k') | views/controls/menu/simple_menu_model.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/menu/simple_menu_model.h
===================================================================
--- views/controls/menu/simple_menu_model.h (revision 0)
+++ views/controls/menu/simple_menu_model.h (revision 0)
@@ -0,0 +1,93 @@
+// 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.
+
+#ifndef CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
+#define CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
+
+#include <vector>
+
+#include "views/controls/menu/menu_2.h"
+
+namespace views {
+
+// A simple Menu2Model implementation with an imperative API for adding menu
+// items. This makes it easy to construct fixed menus. Menus populated by
+// dynamic data sources may be better off implementing Menu2Model directly.
+// The breadth of Menu2Model is not exposed through this API.
+class SimpleMenuModel : public Menu2Model {
+ public:
+ class Delegate {
+ public:
+ // Methods for determining the state of specific command ids.
+ virtual bool IsCommandIdChecked(int command_id) const = 0;
+ virtual bool IsCommandIdEnabled(int command_id) const = 0;
+
+ // Gets the accelerator for the specified command id. Returns true if the
+ // command id has a valid accelerator, false otherwise.
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ views::Accelerator* accelerator) = 0;
+
+ // Some command ids have labels that change over time.
+ virtual bool IsLabelForCommandIdDynamic(int command_id) const = 0;
+ virtual std::wstring GetLabelForCommandId(int command_id) const = 0;
+ };
+
+ // The Delegate can be NULL, though if it is items can't be checked or
+ // disabled.
+ explicit SimpleMenuModel(Delegate* delegate);
+ virtual ~SimpleMenuModel();
+
+ // Methods for adding items to the model.
+ void AddItem(int command_id, const std::wstring& label);
+ void AddItemWithStringId(int command_id, int string_id);
+ void AddSeparator();
+ void AddCheckItem(int command_id, const std::wstring& label);
+ void AddCheckItemWithStringId(int command_id, int string_id);
+ void AddRadioItem(int command_id, const std::wstring& label, int group_id);
+ void AddRadioItemWithStringId(int command_id, int string_id, int group_id);
+ void AddSubMenu(const std::wstring& label, Menu2Model* model);
+ void AddSubMenuWithStringId(int string_id, Menu2Model* model);
+
+ // Overridden from Menu2Model:
+ virtual bool HasIcons() const;
+ virtual int GetItemCount() const;
+ virtual ItemType GetTypeAt(int index) const;
+ virtual int GetCommandIdAt(int index) const;
+ virtual std::wstring GetLabelAt(int index) const;
+ virtual bool IsLabelDynamicAt(int index) const;
+ virtual bool GetAcceleratorAt(int index,
+ views::Accelerator* accelerator) const;
+ virtual bool IsItemCheckedAt(int index) const;
+ virtual int GetGroupIdAt(int index) const;
+ virtual bool GetIconAt(int index, SkBitmap* icon) const;
+ virtual bool IsEnabledAt(int index) const;
+ virtual Menu2Model* GetSubmenuModelAt(int index) const;
+
+ protected:
+ // Some variants of this model (SystemMenuModel) relies on items to be
+ // inserted backwards. This is counter-intuitive for the API, so rather than
+ // forcing customers to insert things backwards, we return the indices
+ // backwards instead. That's what this method is for. By default, it just
+ // returns what it's passed.
+ virtual int FlipIndex(int index) const { return index; }
+
+ private:
+ struct Item {
+ int command_id;
+ std::wstring label;
+ ItemType type;
+ int group_id;
+ Menu2Model* submenu;
+ };
+ std::vector<Item> items_;
+
+ Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel);
+};
+
+} // namespace views
+
+#endif // CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
« no previous file with comments | « views/controls/menu/native_menu_win.cc ('k') | views/controls/menu/simple_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698