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
|
// Copyright (c) 2006-2008 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 "views/controls/menu/menu.h"
#include "app/l10n_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace views {
bool Menu::Delegate::IsRightToLeftUILayout() const {
return l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT;
}
const SkBitmap& Menu::Delegate::GetEmptyIcon() const {
static const SkBitmap* empty_icon = new SkBitmap();
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 std::wstring& label,
MenuItemType type) {
AddMenuItem(-1, item_id, label, type);
}
void Menu::AddMenuItem(int index,
int item_id,
const std::wstring& label,
MenuItemType type) {
if (type == SEPARATOR)
AddSeparator(index);
else
AddMenuItemInternal(index, item_id, label, SkBitmap(), type);
}
Menu* Menu::AppendSubMenu(int item_id, const std::wstring& label) {
return AddSubMenu(-1, item_id, label);
}
Menu* Menu::AddSubMenu(int index, int item_id, const std::wstring& label) {
return AddSubMenuWithIcon(index, item_id, label, SkBitmap());
}
Menu* Menu::AppendSubMenuWithIcon(int item_id,
const std::wstring& label,
const SkBitmap& icon) {
return AddSubMenuWithIcon(-1, item_id, label, icon);
}
void Menu::AppendMenuItemWithLabel(int item_id, const std::wstring& label) {
AddMenuItemWithLabel(-1, item_id, label);
}
void Menu::AddMenuItemWithLabel(int index, int item_id,
const std::wstring& 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, std::wstring(), Menu::NORMAL);
}
void Menu::AppendSeparator() {
AddSeparator(-1);
}
void Menu::AppendMenuItemWithIcon(int item_id,
const std::wstring& label,
const SkBitmap& icon) {
AddMenuItemWithIcon(-1, item_id, label, icon);
}
void Menu::AddMenuItemWithIcon(int index,
int item_id,
const std::wstring& label,
const SkBitmap& icon) {
AddMenuItemInternal(index, item_id, label, icon, Menu::NORMAL);
}
Menu::Menu() : delegate_(NULL), anchor_(TOPLEFT) {
}
} // namespace views
|