1// Copyright (c) 2012 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.
4
5#include "ui/views/controls/menu/menu.h"
6
7#include "base/i18n/rtl.h"
8#include "ui/gfx/image/image_skia.h"
9
10namespace views {
11
12bool Menu::Delegate::IsItemChecked(int id) const {
13  return false;
14}
15
16bool Menu::Delegate::IsItemDefault(int id) const {
17  return false;
18}
19
20string16 Menu::Delegate::GetLabel(int id) const {
21  return string16();
22}
23
24bool Menu::Delegate::GetAcceleratorInfo(int id, ui::Accelerator* accel) {
25  return false;
26}
27
28const gfx::ImageSkia& Menu::Delegate::GetIcon(int id) const {
29  return GetEmptyIcon();
30}
31
32int Menu::Delegate::GetItemCount() const {
33  return 0;
34}
35
36bool Menu::Delegate::IsItemSeparator(int id) const {
37  return false;
38}
39
40bool Menu::Delegate::HasIcon(int id) const {
41  return false;
42}
43
44bool Menu::Delegate::SupportsCommand(int id) const {
45  return true;
46}
47
48bool Menu::Delegate::IsCommandEnabled(int id) const {
49  return true;
50}
51
52bool Menu::Delegate::GetContextualLabel(int id, string16* out) const {
53  return false;
54}
55
56bool Menu::Delegate::IsRightToLeftUILayout() const {
57  return base::i18n::IsRTL();
58}
59
60const gfx::ImageSkia& Menu::Delegate::GetEmptyIcon() const {
61  static const gfx::ImageSkia* empty_icon = new gfx::ImageSkia();
62  return *empty_icon;
63}
64
65Menu::Menu(Delegate* delegate, AnchorPoint anchor)
66    : delegate_(delegate),
67      anchor_(anchor) {
68}
69
70Menu::Menu(Menu* parent)
71    : delegate_(parent->delegate_),
72      anchor_(parent->anchor_) {
73}
74
75Menu::~Menu() {
76}
77
78void Menu::AppendMenuItem(int item_id,
79                          const string16& label,
80                          MenuItemType type) {
81  AddMenuItem(-1, item_id, label, type);
82}
83
84void Menu::AddMenuItem(int index,
85                       int item_id,
86                       const string16& label,
87                       MenuItemType type) {
88  if (type == SEPARATOR)
89    AddSeparator(index);
90  else
91    AddMenuItemInternal(index, item_id, label, gfx::ImageSkia(), type);
92}
93
94Menu* Menu::AppendSubMenu(int item_id, const string16& label) {
95  return AddSubMenu(-1, item_id, label);
96}
97
98Menu* Menu::AddSubMenu(int index, int item_id, const string16& label) {
99  return AddSubMenuWithIcon(index, item_id, label, gfx::ImageSkia());
100}
101
102Menu* Menu::AppendSubMenuWithIcon(int item_id,
103                                  const string16& label,
104                                  const gfx::ImageSkia& icon) {
105  return AddSubMenuWithIcon(-1, item_id, label, icon);
106}
107
108void Menu::AppendMenuItemWithLabel(int item_id, const string16& label) {
109  AddMenuItemWithLabel(-1, item_id, label);
110}
111
112void Menu::AddMenuItemWithLabel(int index,
113                                int item_id,
114                                const string16& label) {
115  AddMenuItem(index, item_id, label, Menu::NORMAL);
116}
117
118void Menu::AppendDelegateMenuItem(int item_id) {
119  AddDelegateMenuItem(-1, item_id);
120}
121
122void Menu::AddDelegateMenuItem(int index, int item_id) {
123  AddMenuItem(index, item_id, string16(), Menu::NORMAL);
124}
125
126void Menu::AppendSeparator() {
127  AddSeparator(-1);
128}
129
130void Menu::AppendMenuItemWithIcon(int item_id,
131                                  const string16& label,
132                                  const gfx::ImageSkia& icon) {
133  AddMenuItemWithIcon(-1, item_id, label, icon);
134}
135
136void Menu::AddMenuItemWithIcon(int index,
137                               int item_id,
138                               const string16& label,
139                               const gfx::ImageSkia& icon) {
140  AddMenuItemInternal(index, item_id, label, icon, Menu::NORMAL);
141}
142
143Menu::Menu() : delegate_(NULL), anchor_(TOPLEFT) {
144}
145
146}  // namespace views
147