| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 void ComboboxExample::CreateExampleView(View* container) { | 42 void ComboboxExample::CreateExampleView(View* container) { |
| 43 combobox_ = new Combobox(&combobox_model_); | 43 combobox_ = new Combobox(&combobox_model_); |
| 44 combobox_->set_listener(this); | 44 combobox_->set_listener(this); |
| 45 combobox_->SetSelectedIndex(3); | 45 combobox_->SetSelectedIndex(3); |
| 46 | 46 |
| 47 disabled_combobox_ = new Combobox(&combobox_model_); | 47 disabled_combobox_ = new Combobox(&combobox_model_); |
| 48 disabled_combobox_->set_listener(this); | 48 disabled_combobox_->set_listener(this); |
| 49 disabled_combobox_->SetSelectedIndex(4); | 49 disabled_combobox_->SetSelectedIndex(4); |
| 50 disabled_combobox_->SetEnabled(false); | 50 disabled_combobox_->SetEnabled(false); |
| 51 | 51 |
| 52 action_combobox_ = new Combobox(&combobox_model_); | 52 action_combobox_ = new Combobox(&combobox_model_, Combobox::STYLE_ACTION); |
| 53 action_combobox_->set_listener(this); | 53 action_combobox_->set_listener(this); |
| 54 action_combobox_->SetStyle(Combobox::STYLE_ACTION); | |
| 55 // Note: STYLE_ACTION comboboxes always have the first item selected by | 54 // Note: STYLE_ACTION comboboxes always have the first item selected by |
| 56 // default. | 55 // default. |
| 57 | 56 |
| 58 container->SetLayoutManager(new BoxLayout( | 57 container->SetLayoutManager(new BoxLayout( |
| 59 BoxLayout::kVertical, | 58 BoxLayout::kVertical, |
| 60 1, 1, 1)); | 59 1, 1, 1)); |
| 61 container->AddChildView(combobox_); | 60 container->AddChildView(combobox_); |
| 62 container->AddChildView(disabled_combobox_); | 61 container->AddChildView(disabled_combobox_); |
| 63 container->AddChildView(action_combobox_); | 62 container->AddChildView(action_combobox_); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void ComboboxExample::OnPerformAction(Combobox* combobox) { | 65 void ComboboxExample::OnPerformAction(Combobox* combobox) { |
| 67 if (combobox == combobox_) { | 66 if (combobox == combobox_) { |
| 68 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( | 67 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( |
| 69 combobox->selected_index())).c_str()); | 68 combobox->selected_index())).c_str()); |
| 70 } else if (combobox == action_combobox_) { | 69 } else if (combobox == action_combobox_) { |
| 71 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( | 70 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( |
| 72 combobox->selected_index())).c_str()); | 71 combobox->selected_index())).c_str()); |
| 73 } else { | 72 } else { |
| 74 NOTREACHED() << "Surprising combobox."; | 73 NOTREACHED() << "Surprising combobox."; |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 } // namespace examples | 77 } // namespace examples |
| 79 } // namespace views | 78 } // namespace views |
| OLD | NEW |