summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/menu/menu.cc
blob: 597dba4419f2d3ca382f7552227f7302fac89efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2012 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 "ui/views/controls/menu/menu.h"

#include "base/i18n/rtl.h"
#include "ui/gfx/image/image_skia.h"

namespace views {

bool Menu::Delegate::IsItemChecked(int id) const {
  return false;
}

bool Menu::Delegate::IsItemDefault(int id) const {
  return false;
}

string16 Menu::Delegate::GetLabel(int id) const {
  return string16();
}

bool Menu::Delegate::GetAcceleratorInfo(int id, ui::Accelerator* accel) {
  return false;
}

const gfx::ImageSkia& Menu::Delegate::GetIcon(int id) const {
  return GetEmptyIcon();
}

int Menu::Delegate::GetItemCount() const {
  return 0;
}

bool Menu::Delegate::IsItemSeparator(int id) const {
  return false;
}

bool Menu::Delegate::HasIcon(int id) const {
  return false;
}

bool Menu::Delegate::SupportsCommand(int id) const {
  return true;
}

bool Menu::Delegate::IsCommandEnabled(int id) const {
  return true;
}

bool Menu::Delegate::GetContextualLabel(int id, string16* out) const {
  return false;
}

bool Menu::Delegate::IsRightToLeftUILayout() const {
  return base::i18n::IsRTL();
}

const gfx::ImageSkia& Menu::Delegate::GetEmptyIcon() const {
  static const gfx::ImageSkia* empty_icon = new gfx::ImageSkia();
  return *empty_icon;
}

Menu::Menu(Delegate* delegate, AnchorPoint anchor)
    : delegate_(delegate),
      anchor_(anchor) {
}

Menu::Menu(Menu* parent)
    : delegate_(parent->delegate_),
      anchor_(parent->anchor_) {
}

Menu::~Menu() {
}

void Menu::AppendMenuItem(int item_id,
                          const string16& label,
                          MenuItemType type) {
  AddMenuItem(-1, item_id, label, type);
}

void Menu::AddMenuItem(int index,
                       int item_id,
                       const string16& label,
                       MenuItemType type) {
  if (type == SEPARATOR)
    AddSeparator(index);
  else
    AddMenuItemInternal(index, item_id, label, gfx::ImageSkia(), type);
}

Menu* Menu::AppendSubMenu(int item_id, const string16& label) {
  return AddSubMenu(-1, item_id, label);
}

Menu* Menu::AddSubMenu(int index, int item_id, const string16& label) {
  return AddSubMenuWithIcon(index, item_id, label, gfx::ImageSkia());
}

Menu* Menu::AppendSubMenuWithIcon(int item_id,
                                  const string16& label,
                                  const gfx::ImageSkia& icon) {
  return AddSubMenuWithIcon(-1, item_id, label, icon);
}

void Menu::AppendMenuItemWithLabel(int item_id, const string16& label) {
  AddMenuItemWithLabel(-1, item_id, label);
}

void Menu::AddMenuItemWithLabel(int index,
                                int item_id,
                                const string16& label) {
  AddMenuItem(index, item_id, label, Menu::NORMAL);
}

void Menu::AppendDelegateMenuItem(int item_id) {
  AddDelegateMenuItem(-1, item_id);
}

void Menu::AddDelegateMenuItem(int index, int item_id) {
  AddMenuItem(index, item_id, string16(), Menu::NORMAL);
}

void Menu::AppendSeparator() {
  AddSeparator(-1);
}

void Menu::AppendMenuItemWithIcon(int item_id,
                                  const string16& label,
                                  const gfx::ImageSkia& icon) {
  AddMenuItemWithIcon(-1, item_id, label, icon);
}

void Menu::AddMenuItemWithIcon(int index,
                               int item_id,
                               const string16& label,
                               const gfx::ImageSkia& icon) {
  AddMenuItemInternal(index, item_id, label, icon, Menu::NORMAL);
}

Menu::Menu() : delegate_(NULL), anchor_(TOPLEFT) {
}

}  // namespace views