| OLD | NEW |
| 1 // Copyright (c) 2011 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 #include "ui/views/examples/message_box_example.h" | 5 #include "ui/views/examples/message_box_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/views/layout/grid_layout.h" | 8 #include "ui/views/layout/grid_layout.h" |
| 9 #include "views/controls/message_box_view.h" | 9 #include "views/controls/message_box_view.h" |
| 10 #include "views/view.h" | 10 #include "views/view.h" |
| 11 | 11 |
| 12 namespace views { |
| 12 namespace examples { | 13 namespace examples { |
| 13 | 14 |
| 14 MessageBoxExample::MessageBoxExample(ExamplesMain* main) | 15 MessageBoxExample::MessageBoxExample() : ExampleBase("Message Box View") { |
| 15 : ExampleBase(main, "Message Box View") { | |
| 16 } | 16 } |
| 17 | 17 |
| 18 MessageBoxExample::~MessageBoxExample() { | 18 MessageBoxExample::~MessageBoxExample() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void MessageBoxExample::CreateExampleView(views::View* container) { | 21 void MessageBoxExample::CreateExampleView(View* container) { |
| 22 message_box_view_ = new views::MessageBoxView( | 22 message_box_view_ = new MessageBoxView( |
| 23 0, | 23 0, |
| 24 ASCIIToUTF16("Message Box Message"), | 24 ASCIIToUTF16("Message Box Message"), |
| 25 ASCIIToUTF16("Default Prompt")); | 25 ASCIIToUTF16("Default Prompt")); |
| 26 status_ = new views::TextButton(this, ASCIIToUTF16("Show Status")); | 26 status_ = new TextButton(this, ASCIIToUTF16("Show Status")); |
| 27 toggle_ = new views::TextButton(this, ASCIIToUTF16("Toggle Checkbox")); | 27 toggle_ = new TextButton(this, ASCIIToUTF16("Toggle Checkbox")); |
| 28 | 28 |
| 29 views::GridLayout* layout = new views::GridLayout(container); | 29 GridLayout* layout = new GridLayout(container); |
| 30 container->SetLayoutManager(layout); | 30 container->SetLayoutManager(layout); |
| 31 | 31 |
| 32 message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box")); | 32 message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box")); |
| 33 | 33 |
| 34 const int message_box_column = 0; | 34 const int message_box_column = 0; |
| 35 views::ColumnSet* column_set = layout->AddColumnSet(message_box_column); | 35 ColumnSet* column_set = layout->AddColumnSet(message_box_column); |
| 36 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 36 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 37 views::GridLayout::USE_PREF, 0, 0); | 37 GridLayout::USE_PREF, 0, 0); |
| 38 layout->StartRow(1 /* expand */, message_box_column); | 38 layout->StartRow(1 /* expand */, message_box_column); |
| 39 layout->AddView(message_box_view_); | 39 layout->AddView(message_box_view_); |
| 40 | 40 |
| 41 const int button_column = 1; | 41 const int button_column = 1; |
| 42 column_set = layout->AddColumnSet(button_column); | 42 column_set = layout->AddColumnSet(button_column); |
| 43 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 43 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 44 0.5f, views::GridLayout::USE_PREF, 0, 0); | 44 0.5f, GridLayout::USE_PREF, 0, 0); |
| 45 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 45 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 46 0.5f, views::GridLayout::USE_PREF, 0, 0); | 46 0.5f, GridLayout::USE_PREF, 0, 0); |
| 47 | 47 |
| 48 layout->StartRow(0 /* no expand */, button_column); | 48 layout->StartRow(0 /* no expand */, button_column); |
| 49 | 49 |
| 50 layout->AddView(status_); | 50 layout->AddView(status_); |
| 51 layout->AddView(toggle_); | 51 layout->AddView(toggle_); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void MessageBoxExample::ButtonPressed(views::Button* sender, | 54 void MessageBoxExample::ButtonPressed(Button* sender, const Event& event) { |
| 55 const views::Event& event) { | |
| 56 if (sender == status_) { | 55 if (sender == status_) { |
| 57 message_box_view_->SetCheckBoxLabel( | 56 message_box_view_->SetCheckBoxLabel( |
| 58 ASCIIToUTF16(BoolToOnOff(message_box_view_->IsCheckBoxSelected()))); | 57 ASCIIToUTF16(BoolToOnOff(message_box_view_->IsCheckBoxSelected()))); |
| 59 PrintStatus(message_box_view_->IsCheckBoxSelected() ? | 58 PrintStatus(message_box_view_->IsCheckBoxSelected() ? |
| 60 "Check Box Selected" : "Check Box Not Selected"); | 59 "Check Box Selected" : "Check Box Not Selected"); |
| 61 } else if (sender == toggle_) { | 60 } else if (sender == toggle_) { |
| 62 message_box_view_->SetCheckBoxSelected( | 61 message_box_view_->SetCheckBoxSelected( |
| 63 !message_box_view_->IsCheckBoxSelected()); | 62 !message_box_view_->IsCheckBoxSelected()); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 | 65 |
| 67 } // namespace examples | 66 } // namespace examples |
| 67 } // namespace views |
| OLD | NEW |