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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
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 #ifndef CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
6 #define CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
7
8 #include <vector>
9
10 #include "views/controls/menu/menu_2.h"
11
12 namespace views {
13
14 // A simple Menu2Model implementation with an imperative API for adding menu
15 // items. This makes it easy to construct fixed menus. Menus populated by
16 // dynamic data sources may be better off implementing Menu2Model directly.
17 // The breadth of Menu2Model is not exposed through this API.
18 class SimpleMenuModel : public Menu2Model {
19 public:
20 class Delegate {
21 public:
22 // Methods for determining the state of specific command ids.
23 virtual bool IsCommandIdChecked(int command_id) const = 0;
24 virtual bool IsCommandIdEnabled(int command_id) const = 0;
25
26 // Gets the accelerator for the specified command id. Returns true if the
27 // command id has a valid accelerator, false otherwise.
28 virtual bool GetAcceleratorForCommandId(
29 int command_id,
30 views::Accelerator* accelerator) = 0;
31
32 // Some command ids have labels that change over time.
33 virtual bool IsLabelForCommandIdDynamic(int command_id) const = 0;
34 virtual std::wstring GetLabelForCommandId(int command_id) const = 0;
35 };
36
37 // The Delegate can be NULL, though if it is items can't be checked or
38 // disabled.
39 explicit SimpleMenuModel(Delegate* delegate);
40 virtual ~SimpleMenuModel();
41
42 // Methods for adding items to the model.
43 void AddItem(int command_id, const std::wstring& label);
44 void AddItemWithStringId(int command_id, int string_id);
45 void AddSeparator();
46 void AddCheckItem(int command_id, const std::wstring& label);
47 void AddCheckItemWithStringId(int command_id, int string_id);
48 void AddRadioItem(int command_id, const std::wstring& label, int group_id);
49 void AddRadioItemWithStringId(int command_id, int string_id, int group_id);
50 void AddSubMenu(const std::wstring& label, Menu2Model* model);
51 void AddSubMenuWithStringId(int string_id, Menu2Model* model);
52
53 // Overridden from Menu2Model:
54 virtual bool HasIcons() const;
55 virtual int GetItemCount() const;
56 virtual ItemType GetTypeAt(int index) const;
57 virtual int GetCommandIdAt(int index) const;
58 virtual std::wstring GetLabelAt(int index) const;
59 virtual bool IsLabelDynamicAt(int index) const;
60 virtual bool GetAcceleratorAt(int index,
61 views::Accelerator* accelerator) const;
62 virtual bool IsItemCheckedAt(int index) const;
63 virtual int GetGroupIdAt(int index) const;
64 virtual bool GetIconAt(int index, SkBitmap* icon) const;
65 virtual bool IsEnabledAt(int index) const;
66 virtual Menu2Model* GetSubmenuModelAt(int index) const;
67
68 protected:
69 // Some variants of this model (SystemMenuModel) relies on items to be
70 // inserted backwards. This is counter-intuitive for the API, so rather than
71 // forcing customers to insert things backwards, we return the indices
72 // backwards instead. That's what this method is for. By default, it just
73 // returns what it's passed.
74 virtual int FlipIndex(int index) const { return index; }
75
76 private:
77 struct Item {
78 int command_id;
79 std::wstring label;
80 ItemType type;
81 int group_id;
82 Menu2Model* submenu;
83 };
84 std::vector<Item> items_;
85
86 Delegate* delegate_;
87
88 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel);
89 };
90
91 } // namespace views
92
93 #endif // CONTROLS_MENU_VIEWS_SIMPLE_MENU_MODEL_H_
OLDNEW
« 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