blob: 64213844fe1dccb050d3766d10a9b7c930146a9c (
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) 2011 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/examples/combobox_example.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "ui/base/models/combobox_model.h"
namespace {
// An sample combobox model that generates list of "Item <index>".
class ComboboxModelExample : public ui::ComboboxModel {
public:
ComboboxModelExample() {}
virtual ~ComboboxModelExample() {}
// Overridden from ui::ComboboxModel:
virtual int GetItemCount() OVERRIDE { return 10; }
// Overridden from ui::ComboboxModel:
virtual string16 GetItemAt(int index) OVERRIDE {
return WideToUTF16Hack(base::StringPrintf(L"Item %d", index));
}
private:
DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample);
};
} // namespace
namespace examples {
ComboboxExample::ComboboxExample(ExamplesMain* main) : ExampleBase(main) {
}
ComboboxExample::~ComboboxExample() {
}
std::wstring ComboboxExample::GetExampleTitle() {
return L"Combo Box";
}
void ComboboxExample::CreateExampleView(views::View* container) {
combobox_ = new views::Combobox(new ComboboxModelExample());
combobox_->set_listener(this);
combobox_->SetSelectedItem(3);
container->SetLayoutManager(new views::FillLayout);
container->AddChildView(combobox_);
}
void ComboboxExample::ItemChanged(views::Combobox* combo_box,
int prev_index,
int new_index) {
PrintStatus(L"Selected: index=%d, label=%ls",
new_index, UTF16ToWideHack(
combo_box->model()->GetItemAt(new_index)).c_str());
}
} // namespace examples
|