OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/combobox_model.h" | 9 #include "app/combobox_model.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" |
11 #include "views/controls/combobox/combobox.h" | 12 #include "views/controls/combobox/combobox.h" |
12 #include "views/examples/example_base.h" | 13 #include "views/examples/example_base.h" |
13 #include "views/fill_layout.h" | 14 #include "views/fill_layout.h" |
14 | 15 |
15 namespace examples { | 16 namespace examples { |
16 | 17 |
17 // ComboboxExample | 18 // ComboboxExample |
18 class ComboboxExample : public ExampleBase, public views::Combobox::Listener { | 19 class ComboboxExample : public ExampleBase, public views::Combobox::Listener { |
19 public: | 20 public: |
20 explicit ComboboxExample(ExamplesMain* main) : ExampleBase(main) { | 21 explicit ComboboxExample(ExamplesMain* main) : ExampleBase(main) { |
(...skipping 16 matching lines...) Expand all Loading... |
37 // An sample combobox model that generates list of "Item <index>". | 38 // An sample combobox model that generates list of "Item <index>". |
38 class ComboboxModelExample : public ComboboxModel { | 39 class ComboboxModelExample : public ComboboxModel { |
39 public: | 40 public: |
40 ComboboxModelExample() {} | 41 ComboboxModelExample() {} |
41 virtual ~ComboboxModelExample() {} | 42 virtual ~ComboboxModelExample() {} |
42 | 43 |
43 virtual int GetItemCount() { | 44 virtual int GetItemCount() { |
44 return 10; | 45 return 10; |
45 } | 46 } |
46 | 47 |
47 virtual std::wstring GetItemAt(int index) { | 48 virtual string16 GetItemAt(int index) { |
48 return StringPrintf(L"Item %d", index); | 49 return WideToUTF16Hack(StringPrintf(L"Item %d", index)); |
49 } | 50 } |
50 | 51 |
51 private: | 52 private: |
52 DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); | 53 DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); |
53 }; | 54 }; |
54 | 55 |
55 // Lister implementation. | 56 // Lister implementation. |
56 virtual void ItemChanged(views::Combobox* combo_box, | 57 virtual void ItemChanged(views::Combobox* combo_box, |
57 int prev_index, | 58 int prev_index, |
58 int new_index) { | 59 int new_index) { |
59 PrintStatus(L"Selected: index=%d, label=%ls", | 60 PrintStatus(L"Selected: index=%d, label=%ls", |
60 new_index, combo_box->model()->GetItemAt(new_index).c_str()); | 61 new_index, UTF16ToWideHack( |
| 62 combo_box->model()->GetItemAt(new_index)).c_str()); |
61 } | 63 } |
62 | 64 |
63 // This test only control. | 65 // This test only control. |
64 views::Combobox* combobox_; | 66 views::Combobox* combobox_; |
65 | 67 |
66 DISALLOW_COPY_AND_ASSIGN(ComboboxExample); | 68 DISALLOW_COPY_AND_ASSIGN(ComboboxExample); |
67 }; | 69 }; |
68 | 70 |
69 } // namespace examples | 71 } // namespace examples |
70 | 72 |
71 #endif // VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ | 73 #endif // VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ |
OLD | NEW |