OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ |
6 #define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/utf_string_conversions.h" | |
11 #include "ui/base/models/combobox_model.h" | |
12 #include "views/controls/combobox/combobox.h" | 10 #include "views/controls/combobox/combobox.h" |
13 #include "views/examples/example_base.h" | 11 #include "views/examples/example_base.h" |
14 #include "views/fill_layout.h" | 12 #include "views/fill_layout.h" |
15 | 13 |
16 using ui::ComboboxModel; // TODO(beng): remove | |
17 | |
18 namespace examples { | 14 namespace examples { |
19 | 15 |
20 // ComboboxExample | 16 class ComboboxExample : public ExampleBase, |
21 class ComboboxExample : public ExampleBase, public views::Combobox::Listener { | 17 public views::Combobox::Listener { |
22 public: | 18 public: |
23 explicit ComboboxExample(ExamplesMain* main) : ExampleBase(main) { | 19 explicit ComboboxExample(ExamplesMain* main); |
24 combobox_ = new views::Combobox(new ComboboxModelExample()); | 20 virtual ~ComboboxExample(); |
25 combobox_->set_listener(this); | |
26 combobox_->SetSelectedItem(3); | |
27 } | |
28 virtual ~ComboboxExample() {} | |
29 | 21 |
30 virtual std::wstring GetExampleTitle() { | 22 // Overridden from ExampleBase: |
31 return L"Combo Box"; | 23 virtual std::wstring GetExampleTitle() OVERRIDE; |
32 } | 24 virtual void CreateExampleView(views::View* container) OVERRIDE; |
33 | |
34 virtual void CreateExampleView(views::View* container) { | |
35 container->SetLayoutManager(new views::FillLayout); | |
36 container->AddChildView(combobox_); | |
37 } | |
38 | 25 |
39 private: | 26 private: |
40 // An sample combobox model that generates list of "Item <index>". | 27 // Overridden from views::Combobox::Listener: |
41 class ComboboxModelExample : public ComboboxModel { | |
42 public: | |
43 ComboboxModelExample() {} | |
44 virtual ~ComboboxModelExample() {} | |
45 | |
46 virtual int GetItemCount() { | |
47 return 10; | |
48 } | |
49 | |
50 virtual string16 GetItemAt(int index) { | |
51 return WideToUTF16Hack(StringPrintf(L"Item %d", index)); | |
52 } | |
53 | |
54 private: | |
55 DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); | |
56 }; | |
57 | |
58 // Lister implementation. | |
59 virtual void ItemChanged(views::Combobox* combo_box, | 28 virtual void ItemChanged(views::Combobox* combo_box, |
60 int prev_index, | 29 int prev_index, |
61 int new_index) { | 30 int new_index) OVERRIDE; |
62 PrintStatus(L"Selected: index=%d, label=%ls", | |
63 new_index, UTF16ToWideHack( | |
64 combo_box->model()->GetItemAt(new_index)).c_str()); | |
65 } | |
66 | 31 |
67 // This test only control. | 32 // This test only control. |
68 views::Combobox* combobox_; | 33 views::Combobox* combobox_; |
69 | 34 |
70 DISALLOW_COPY_AND_ASSIGN(ComboboxExample); | 35 DISALLOW_COPY_AND_ASSIGN(ComboboxExample); |
71 }; | 36 }; |
72 | 37 |
73 } // namespace examples | 38 } // namespace examples |
74 | 39 |
75 #endif // VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ | 40 #endif // VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ |
OLD | NEW |