1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_
6 #define UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_
10 #include "base/strings/string16.h"
11 #include "ui/base/ui_base_export.h"
15 // A model representing the rows of buttons that should be inserted in a button
16 // containing menu item.
17 class UI_BASE_EXPORT ButtonMenuItemModel
{
26 class UI_BASE_EXPORT Delegate
{
28 // Some command ids have labels that change over time.
29 virtual bool IsItemForCommandIdDynamic(int command_id
) const;
30 virtual base::string16
GetLabelForCommandId(int command_id
) const;
32 // Performs the action associated with the specified command id.
33 virtual void ExecuteCommand(int command_id
, int event_flags
) = 0;
34 virtual bool IsCommandIdEnabled(int command_id
) const;
35 virtual bool DoesCommandIdDismissMenu(int command_id
) const;
38 virtual ~Delegate() {}
41 ButtonMenuItemModel(int string_id
, ButtonMenuItemModel::Delegate
* delegate
);
42 ~ButtonMenuItemModel();
44 // Adds a button that will emit |command_id|. All buttons created through
45 // this method will have the same size, based on the largest button.
46 void AddGroupItemWithStringId(int command_id
, int string_id
);
48 // Adds a button that has an icon instead of a label.
49 void AddItemWithImage(int command_id
, int icon_idr
);
51 // Adds a non-clickable button with a desensitized label that doesn't do
52 // anything. Usually combined with IsItemForCommandIdDynamic() to add
54 void AddButtonLabel(int command_id
, int string_id
);
56 // Adds a small horizontal space.
59 // Returns the number of items for iteration.
60 int GetItemCount() const;
62 // Returns what kind of item is at |index|.
63 ButtonType
GetTypeAt(int index
) const;
65 // Changes a position into a command ID.
66 int GetCommandIdAt(int index
) const;
68 // Whether the label for item |index| changes.
69 bool IsItemDynamicAt(int index
) const;
71 // Returns the current label value for the button at |index|.
72 base::string16
GetLabelAt(int index
) const;
74 // If the button at |index| should have an icon instead, returns true and
75 // sets the IDR |icon|.
76 bool GetIconAt(int index
, int* icon
) const;
78 // If the button at |index| should have its size equalized along with all
79 // other items that have their PartOfGroup bit set.
80 bool PartOfGroup(int index
) const;
82 // Called from implementations.
83 void ActivatedCommand(int command_id
);
85 // Returns the enabled state of the button at |index|.
86 bool IsEnabledAt(int index
) const;
88 // Returns whether clicking on the button at |index| dismisses the menu.
89 bool DismissesMenuAt(int index
) const;
91 // Returns the enabled state of the command specified by |command_id|.
92 bool IsCommandIdEnabled(int command_id
) const;
94 // Returns whether clicking on |command_id| dismisses the menu.
95 bool DoesCommandIdDismissMenu(int command_id
) const;
97 const base::string16
& label() const { return item_label_
; }
100 // The non-clickable label to the left of the buttons.
101 base::string16 item_label_
;
104 std::vector
<Item
> items_
;
108 DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel
);
113 #endif // UI_BASE_MODELS_BUTTON_MENU_ITEM_MODEL_H_