summaryrefslogtreecommitdiffstats
path: root/ui/views/examples/combobox_example.cc
blob: 2810450dc0d32b1c68b1accc78a13055640241ea (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
// 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/examples/combobox_example.h"

#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/layout/fill_layout.h"

namespace views {
namespace examples {

ComboboxModelExample::ComboboxModelExample() {
}

ComboboxModelExample::~ComboboxModelExample() {
}

int ComboboxModelExample::GetItemCount() const {
  return 10;
}

string16 ComboboxModelExample::GetItemAt(int index) {
  return UTF8ToUTF16(base::StringPrintf("Item %d", index));
}

ComboboxExample::ComboboxExample() : ExampleBase("Combo Box"), combobox_(NULL) {
}

ComboboxExample::~ComboboxExample() {
}

void ComboboxExample::CreateExampleView(View* container) {
  combobox_ = new Combobox(&combobox_model_);
  combobox_->set_listener(this);
  combobox_->SetSelectedIndex(3);

  container->SetLayoutManager(new FillLayout);
  container->AddChildView(combobox_);
}

void ComboboxExample::OnSelectedIndexChanged(Combobox* combobox) {
  DCHECK_EQ(combobox_, combobox);
  PrintStatus("Selected: %s", UTF16ToUTF8(combobox_model_.GetItemAt(
      combobox->selected_index())).c_str());
}

}  // namespace examples
}  // namespace views