| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_MESSAGE_BOX_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_ |
| 6 #define VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "views/controls/button/text_button.h" | 10 #include "views/controls/button/text_button.h" |
| 11 #include "views/controls/message_box_view.h" | 11 #include "views/controls/message_box_view.h" |
| 12 #include "views/controls/tabbed_pane/tabbed_pane.h" | 12 #include "views/controls/tabbed_pane/tabbed_pane.h" |
| 13 #include "views/examples/example_base.h" | 13 #include "views/examples/example_base.h" |
| 14 #include "views/grid_layout.h" | 14 #include "views/grid_layout.h" |
| 15 | 15 |
| 16 namespace examples { | 16 namespace examples { |
| 17 | 17 |
| 18 // A MessageBoxView example. This tests some of checkbox features as well. | 18 // A MessageBoxView example. This tests some of checkbox features as well. |
| 19 class MessageBoxExample : protected ExampleBase, private views::ButtonListener { | 19 class MessageBoxExample : public ExampleBase, |
| 20 public views::ButtonListener { |
| 20 public: | 21 public: |
| 21 explicit MessageBoxExample(ExamplesMain* main) : ExampleBase(main) { | 22 explicit MessageBoxExample(ExamplesMain* main) : ExampleBase(main) {} |
| 23 |
| 24 virtual ~MessageBoxExample() {} |
| 25 |
| 26 virtual std::wstring GetExampleTitle() { |
| 27 return L"Message Box View"; |
| 28 } |
| 29 |
| 30 virtual void CreateExampleView(views::View* container) { |
| 22 message_box_view_ = | 31 message_box_view_ = |
| 23 new MessageBoxView(0, L"Message Box Message", L"Default Prompt"); | 32 new MessageBoxView(0, L"Message Box Message", L"Default Prompt"); |
| 24 status_ = new views::TextButton(this, L"Show Status"); | 33 status_ = new views::TextButton(this, L"Show Status"); |
| 25 toggle_ = new views::TextButton(this, L"Toggle Checkbox"); | 34 toggle_ = new views::TextButton(this, L"Toggle Checkbox"); |
| 26 | 35 |
| 27 container_ = new views::View(); | 36 views::GridLayout* layout = new views::GridLayout(container); |
| 28 views::GridLayout* layout = new views::GridLayout(container_); | 37 container->SetLayoutManager(layout); |
| 29 container_->SetLayoutManager(layout); | |
| 30 | 38 |
| 31 message_box_view_->SetCheckBoxLabel(L"Check Box"); | 39 message_box_view_->SetCheckBoxLabel(L"Check Box"); |
| 32 | 40 |
| 33 const int message_box_column = 0; | 41 const int message_box_column = 0; |
| 34 views::ColumnSet* column_set = layout->AddColumnSet(message_box_column); | 42 views::ColumnSet* column_set = layout->AddColumnSet(message_box_column); |
| 35 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 43 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 36 views::GridLayout::USE_PREF, 0, 0); | 44 views::GridLayout::USE_PREF, 0, 0); |
| 37 layout->StartRow(1 /* expand */, message_box_column); | 45 layout->StartRow(1 /* expand */, message_box_column); |
| 38 layout->AddView(message_box_view_); | 46 layout->AddView(message_box_view_); |
| 39 | 47 |
| 40 const int button_column = 1; | 48 const int button_column = 1; |
| 41 column_set = layout->AddColumnSet(button_column); | 49 column_set = layout->AddColumnSet(button_column); |
| 42 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 50 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 43 0.5f, views::GridLayout::USE_PREF, 0, 0); | 51 0.5f, views::GridLayout::USE_PREF, 0, 0); |
| 44 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 52 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 45 0.5f, views::GridLayout::USE_PREF, 0, 0); | 53 0.5f, views::GridLayout::USE_PREF, 0, 0); |
| 46 | 54 |
| 47 layout->StartRow(0 /* no expand */, button_column); | 55 layout->StartRow(0 /* no expand */, button_column); |
| 48 | 56 |
| 49 layout->AddView(status_); | 57 layout->AddView(status_); |
| 50 layout->AddView(toggle_); | 58 layout->AddView(toggle_); |
| 51 } | 59 } |
| 52 | 60 |
| 53 virtual ~MessageBoxExample() {} | |
| 54 | |
| 55 virtual std::wstring GetExampleTitle() { | |
| 56 return L"Message Box View"; | |
| 57 } | |
| 58 | |
| 59 virtual views::View* GetExampleView() { | |
| 60 return container_; | |
| 61 } | |
| 62 | |
| 63 private: | 61 private: |
| 64 // ButtonListener overrides. | 62 // ButtonListener overrides. |
| 65 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { | 63 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { |
| 66 if (sender == status_) { | 64 if (sender == status_) { |
| 67 message_box_view_->SetCheckBoxLabel( | 65 message_box_view_->SetCheckBoxLabel( |
| 68 IntToOnOff(message_box_view_->IsCheckBoxSelected())); | 66 IntToOnOff(message_box_view_->IsCheckBoxSelected())); |
| 69 PrintStatus(message_box_view_->IsCheckBoxSelected() ? | 67 PrintStatus(message_box_view_->IsCheckBoxSelected() ? |
| 70 L"Check Box Selected" : L"Check Box Not Selected"); | 68 L"Check Box Selected" : L"Check Box Not Selected"); |
| 71 } else if (sender == toggle_) { | 69 } else if (sender == toggle_) { |
| 72 message_box_view_->SetCheckBoxSelected( | 70 message_box_view_->SetCheckBoxSelected( |
| 73 !message_box_view_->IsCheckBoxSelected()); | 71 !message_box_view_->IsCheckBoxSelected()); |
| 74 } | 72 } |
| 75 } | 73 } |
| 76 | 74 |
| 77 // The view containing this test's controls. | |
| 78 views::View* container_; | |
| 79 | |
| 80 // The MessageBoxView to be tested. | 75 // The MessageBoxView to be tested. |
| 81 MessageBoxView* message_box_view_; | 76 MessageBoxView* message_box_view_; |
| 82 | 77 |
| 83 // Control buttons to show the status and toggle checkbox in the | 78 // Control buttons to show the status and toggle checkbox in the |
| 84 // message box. | 79 // message box. |
| 85 views::Button* status_, *toggle_; | 80 views::Button* status_, *toggle_; |
| 86 | 81 |
| 87 DISALLOW_COPY_AND_ASSIGN(MessageBoxExample); | 82 DISALLOW_COPY_AND_ASSIGN(MessageBoxExample); |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 } // namespace examples | 85 } // namespace examples |
| 91 | 86 |
| 92 #endif // VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_ | 87 #endif // VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_ |
| 93 | 88 |
| OLD | NEW |