| 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_TABBED_PANE_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ |
| 6 #define VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ |
| 7 | 7 |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "views/controls/button/text_button.h" | 9 #include "views/controls/button/text_button.h" |
| 10 #include "views/examples/example_base.h" | 10 #include "views/examples/example_base.h" |
| 11 | 11 |
| 12 namespace examples { | 12 namespace examples { |
| 13 | 13 |
| 14 // A TabbedPane example tests adding/removing/selecting tabs. | 14 // A TabbedPane example tests adding/removing/selecting tabs. |
| 15 class TabbedPaneExample : protected ExampleBase, | 15 class TabbedPaneExample : public ExampleBase, |
| 16 private views::ButtonListener, | 16 public views::ButtonListener, |
| 17 views::TabbedPane::Listener { | 17 views::TabbedPane::Listener { |
| 18 public: | 18 public: |
| 19 explicit TabbedPaneExample(ExamplesMain* main) : ExampleBase(main) { | 19 explicit TabbedPaneExample(ExamplesMain* main) : ExampleBase(main) {} |
| 20 |
| 21 virtual ~TabbedPaneExample() {} |
| 22 |
| 23 virtual std::wstring GetExampleTitle() { |
| 24 return L"Tabbed Pane"; |
| 25 } |
| 26 |
| 27 virtual void CreateExampleView(views::View* container) { |
| 20 tabbed_pane_ = new views::TabbedPane(); | 28 tabbed_pane_ = new views::TabbedPane(); |
| 21 add_ = new views::TextButton(this, L"Add"); | 29 add_ = new views::TextButton(this, L"Add"); |
| 22 add_at_ = new views::TextButton(this, L"Add At 1"); | 30 add_at_ = new views::TextButton(this, L"Add At 1"); |
| 23 remove_at_ = new views::TextButton(this, L"Remove At 1"); | 31 remove_at_ = new views::TextButton(this, L"Remove At 1"); |
| 24 select_at_ = new views::TextButton(this, L"Select At 1"); | 32 select_at_ = new views::TextButton(this, L"Select At 1"); |
| 25 | 33 |
| 26 container_ = new views::View(); | 34 views::GridLayout* layout = new views::GridLayout(container); |
| 27 views::GridLayout* layout = new views::GridLayout(container_); | 35 container->SetLayoutManager(layout); |
| 28 container_->SetLayoutManager(layout); | |
| 29 | 36 |
| 30 const int tabbed_pane_column = 0; | 37 const int tabbed_pane_column = 0; |
| 31 views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); | 38 views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); |
| 32 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 39 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 33 1.0f, views::GridLayout::USE_PREF, 0, 0); | 40 1.0f, views::GridLayout::USE_PREF, 0, 0); |
| 34 layout->StartRow(1 /* expand */, tabbed_pane_column); | 41 layout->StartRow(1 /* expand */, tabbed_pane_column); |
| 35 layout->AddView(tabbed_pane_); | 42 layout->AddView(tabbed_pane_); |
| 36 | 43 |
| 37 // Create a few tabs with a button first. | 44 // Create a few tabs with a button first. |
| 38 AddButton(L"Tab 1"); | 45 AddButton(L"Tab 1"); |
| 39 AddButton(L"Tab 2"); | 46 AddButton(L"Tab 2"); |
| 40 | 47 |
| 41 // Add control buttons horizontally. | 48 // Add control buttons horizontally. |
| 42 const int button_column = 1; | 49 const int button_column = 1; |
| 43 column_set = layout->AddColumnSet(button_column); | 50 column_set = layout->AddColumnSet(button_column); |
| 44 for (int i = 0; i < 4; i++) { | 51 for (int i = 0; i < 4; i++) { |
| 45 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 52 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 46 1.0f, views::GridLayout::USE_PREF, 0, 0); | 53 1.0f, views::GridLayout::USE_PREF, 0, 0); |
| 47 } | 54 } |
| 48 | 55 |
| 49 layout->StartRow(0 /* no expand */, button_column); | 56 layout->StartRow(0 /* no expand */, button_column); |
| 50 layout->AddView(add_); | 57 layout->AddView(add_); |
| 51 layout->AddView(add_at_); | 58 layout->AddView(add_at_); |
| 52 layout->AddView(remove_at_); | 59 layout->AddView(remove_at_); |
| 53 layout->AddView(select_at_); | 60 layout->AddView(select_at_); |
| 54 } | 61 } |
| 55 | 62 |
| 56 virtual ~TabbedPaneExample() {} | |
| 57 | |
| 58 virtual std::wstring GetExampleTitle() { | |
| 59 return L"Tabbed Pane"; | |
| 60 } | |
| 61 | |
| 62 virtual views::View* GetExampleView() { | |
| 63 return container_; | |
| 64 } | |
| 65 | |
| 66 private: | 63 private: |
| 67 // ButtonListener overrides. | 64 // ButtonListener overrides. |
| 68 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { | 65 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { |
| 69 if (sender == add_) { | 66 if (sender == add_) { |
| 70 AddButton(L"Added"); | 67 AddButton(L"Added"); |
| 71 } else if (sender == add_at_) { | 68 } else if (sender == add_at_) { |
| 72 const std::wstring label = L"Added at 1"; | 69 const std::wstring label = L"Added at 1"; |
| 73 tabbed_pane_->AddTabAtIndex(1, label, | 70 tabbed_pane_->AddTabAtIndex(1, label, |
| 74 new views::TextButton(NULL, label), true); | 71 new views::TextButton(NULL, label), true); |
| 75 } else if (sender == remove_at_) { | 72 } else if (sender == remove_at_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 ExampleBase::PrintStatus(L"Tab Count:%d, Selected Tab:%d", | 90 ExampleBase::PrintStatus(L"Tab Count:%d, Selected Tab:%d", |
| 94 tabbed_pane_->GetTabCount(), | 91 tabbed_pane_->GetTabCount(), |
| 95 tabbed_pane_->GetSelectedTabIndex()); | 92 tabbed_pane_->GetSelectedTabIndex()); |
| 96 } | 93 } |
| 97 | 94 |
| 98 void AddButton(const std::wstring& label) { | 95 void AddButton(const std::wstring& label) { |
| 99 views::TextButton* button = new views::TextButton(NULL, label); | 96 views::TextButton* button = new views::TextButton(NULL, label); |
| 100 tabbed_pane_->AddTab(label, button); | 97 tabbed_pane_->AddTab(label, button); |
| 101 } | 98 } |
| 102 | 99 |
| 103 // The view containing this test's controls. | |
| 104 views::View* container_; | |
| 105 | |
| 106 // The tabbed pane to be tested. | 100 // The tabbed pane to be tested. |
| 107 views::TabbedPane* tabbed_pane_; | 101 views::TabbedPane* tabbed_pane_; |
| 108 | 102 |
| 109 // Control buttons to add, remove or select tabs. | 103 // Control buttons to add, remove or select tabs. |
| 110 views::Button* add_, *add_at_, *remove_at_, *select_at_; | 104 views::Button* add_, *add_at_, *remove_at_, *select_at_; |
| 111 | 105 |
| 112 DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample); | 106 DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample); |
| 113 }; | 107 }; |
| 114 | 108 |
| 115 } // namespace examples | 109 } // namespace examples |
| 116 | 110 |
| 117 #endif // VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ | 111 #endif // VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ |
| 118 | 112 |
| OLD | NEW |