OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "views/examples/combobox_example.h" |
| 6 |
| 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "ui/base/models/combobox_model.h" |
| 10 #include "views/fill_layout.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 // An sample combobox model that generates list of "Item <index>". |
| 15 class ComboboxModelExample : public ui::ComboboxModel { |
| 16 public: |
| 17 ComboboxModelExample() {} |
| 18 virtual ~ComboboxModelExample() {} |
| 19 |
| 20 // Overridden from ui::ComboboxModel: |
| 21 virtual int GetItemCount() OVERRIDE { return 10; } |
| 22 |
| 23 // Overridden from ui::ComboboxModel: |
| 24 virtual string16 GetItemAt(int index) OVERRIDE { |
| 25 return WideToUTF16Hack(base::StringPrintf(L"Item %d", index)); |
| 26 } |
| 27 |
| 28 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); |
| 30 }; |
| 31 |
| 32 } // namespace |
| 33 |
| 34 namespace examples { |
| 35 |
| 36 ComboboxExample::ComboboxExample(ExamplesMain* main) : ExampleBase(main) { |
| 37 } |
| 38 |
| 39 ComboboxExample::~ComboboxExample() { |
| 40 } |
| 41 |
| 42 std::wstring ComboboxExample::GetExampleTitle() { |
| 43 return L"Combo Box"; |
| 44 } |
| 45 |
| 46 void ComboboxExample::CreateExampleView(views::View* container) { |
| 47 combobox_ = new views::Combobox(new ComboboxModelExample()); |
| 48 combobox_->set_listener(this); |
| 49 combobox_->SetSelectedItem(3); |
| 50 |
| 51 container->SetLayoutManager(new views::FillLayout); |
| 52 container->AddChildView(combobox_); |
| 53 } |
| 54 |
| 55 void ComboboxExample::ItemChanged(views::Combobox* combo_box, |
| 56 int prev_index, |
| 57 int new_index) { |
| 58 PrintStatus(L"Selected: index=%d, label=%ls", |
| 59 new_index, UTF16ToWideHack( |
| 60 combo_box->model()->GetItemAt(new_index)).c_str()); |
| 61 } |
| 62 |
| 63 } // namespace examples |
OLD | NEW |