blob: 7d2fa8acc4fdceb90f4bfd34e3a5123ab578e89c (
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
|
// Copyright (c) 2009 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_2.h"
#include "base/compiler_specific.h"
#include "views/controls/menu/menu_wrapper.h"
namespace views {
////////////////////////////////////////////////////////////////////////////////
// Menu2Model, public:
// static
bool Menu2Model::GetModelAndIndexForCommandId(int command_id,
Menu2Model** model, int* index) {
int item_count = (*model)->GetItemCount();
for (int i = 0; i < item_count; ++i) {
if ((*model)->GetTypeAt(i) == TYPE_SUBMENU) {
Menu2Model* submenu_model = (*model)->GetSubmenuModelAt(i);
if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) {
*model = submenu_model;
return true;
}
}
if ((*model)->GetCommandIdAt(i) == command_id) {
*index = i;
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Menu2, public:
Menu2::Menu2(Menu2Model* model, Menu2Delegate* delegate)
: model_(model),
delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(
wrapper_(MenuWrapper::CreateWrapper(this))) {
Rebuild();
}
gfx::NativeMenu Menu2::GetNativeMenu() const {
return wrapper_->GetNativeMenu();
}
void Menu2::RunMenuAt(const gfx::Point& point, Alignment alignment) {
wrapper_->RunMenuAt(point, alignment);
}
void Menu2::Rebuild() {
wrapper_->Rebuild();
}
void Menu2::UpdateStates() {
wrapper_->UpdateStates();
}
} // namespace
|