| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/views/examples/combobox_example.h" | 5 #include "ui/views/examples/combobox_example.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/views/controls/combobox/combobox.h" | 9 #include "ui/views/controls/combobox/combobox.h" |
| 10 #include "ui/views/layout/box_layout.h" | 10 #include "ui/views/layout/box_layout.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 base::string16 ComboboxModelExample::GetItemAt(int index) { | 25 base::string16 ComboboxModelExample::GetItemAt(int index) { |
| 26 return base::UTF8ToUTF16(base::StringPrintf("Item %d", index)); | 26 return base::UTF8ToUTF16(base::StringPrintf("Item %d", index)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ComboboxExample::ComboboxExample() : ExampleBase("Combo Box") { | 29 ComboboxExample::ComboboxExample() : ExampleBase("Combo Box") { |
| 30 } | 30 } |
| 31 | 31 |
| 32 ComboboxExample::~ComboboxExample() { | 32 ComboboxExample::~ComboboxExample() { |
| 33 // Delete |combobox_| first as it references |combobox_model_|. | 33 // Delete |combobox_| first as it references |combobox_model_|. |
| 34 delete combobox_; | 34 delete combobox_; |
| 35 delete disabled_combobox_; |
| 35 delete action_combobox_; | 36 delete action_combobox_; |
| 36 combobox_ = nullptr; | 37 combobox_ = nullptr; |
| 38 disabled_combobox_ = nullptr; |
| 37 action_combobox_ = nullptr; | 39 action_combobox_ = nullptr; |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ComboboxExample::CreateExampleView(View* container) { | 42 void ComboboxExample::CreateExampleView(View* container) { |
| 41 combobox_ = new Combobox(&combobox_model_); | 43 combobox_ = new Combobox(&combobox_model_); |
| 42 combobox_->set_listener(this); | 44 combobox_->set_listener(this); |
| 43 combobox_->SetSelectedIndex(3); | 45 combobox_->SetSelectedIndex(3); |
| 44 | 46 |
| 47 disabled_combobox_ = new Combobox(&combobox_model_); |
| 48 disabled_combobox_->set_listener(this); |
| 49 disabled_combobox_->SetSelectedIndex(4); |
| 50 disabled_combobox_->SetEnabled(false); |
| 51 |
| 45 action_combobox_ = new Combobox(&combobox_model_); | 52 action_combobox_ = new Combobox(&combobox_model_); |
| 46 action_combobox_->set_listener(this); | 53 action_combobox_->set_listener(this); |
| 47 action_combobox_->SetStyle(Combobox::STYLE_ACTION); | 54 action_combobox_->SetStyle(Combobox::STYLE_ACTION); |
| 48 // Note: STYLE_ACTION comboboxes always have the first item selected by | 55 // Note: STYLE_ACTION comboboxes always have the first item selected by |
| 49 // default. | 56 // default. |
| 50 | 57 |
| 51 container->SetLayoutManager(new BoxLayout( | 58 container->SetLayoutManager(new BoxLayout( |
| 52 BoxLayout::kVertical, | 59 BoxLayout::kVertical, |
| 53 1, 1, 1)); | 60 1, 1, 1)); |
| 54 container->AddChildView(combobox_); | 61 container->AddChildView(combobox_); |
| 62 container->AddChildView(disabled_combobox_); |
| 55 container->AddChildView(action_combobox_); | 63 container->AddChildView(action_combobox_); |
| 56 } | 64 } |
| 57 | 65 |
| 58 void ComboboxExample::OnPerformAction(Combobox* combobox) { | 66 void ComboboxExample::OnPerformAction(Combobox* combobox) { |
| 59 if (combobox == combobox_) { | 67 if (combobox == combobox_) { |
| 60 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( | 68 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( |
| 61 combobox->selected_index())).c_str()); | 69 combobox->selected_index())).c_str()); |
| 62 } else if (combobox == action_combobox_) { | 70 } else if (combobox == action_combobox_) { |
| 63 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( | 71 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( |
| 64 combobox->selected_index())).c_str()); | 72 combobox->selected_index())).c_str()); |
| 65 } else { | 73 } else { |
| 66 NOTREACHED() << "Surprising combobox."; | 74 NOTREACHED() << "Surprising combobox."; |
| 67 } | 75 } |
| 68 } | 76 } |
| 69 | 77 |
| 70 } // namespace examples | 78 } // namespace examples |
| 71 } // namespace views | 79 } // namespace views |
| OLD | NEW |