| 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/tabbed_pane_example.h" | 5 #include "ui/views/examples/tabbed_pane_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 8 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
| 9 #include "ui/views/layout/grid_layout.h" | 9 #include "ui/views/layout/grid_layout.h" |
| 10 | 10 |
| 11 namespace views { | 11 namespace views { |
| 12 namespace examples { | 12 namespace examples { |
| 13 | 13 |
| 14 TabbedPaneExample::TabbedPaneExample() : ExampleBase("Tabbed Pane") { | 14 TabbedPaneExample::TabbedPaneExample() : ExampleBase("Tabbed Pane") { |
| 15 } | 15 } |
| 16 | 16 |
| 17 TabbedPaneExample::~TabbedPaneExample() { | 17 TabbedPaneExample::~TabbedPaneExample() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void TabbedPaneExample::CreateExampleView(View* container) { | 20 void TabbedPaneExample::CreateExampleView(View* container) { |
| 21 tabbed_pane_ = new TabbedPane(); | 21 tabbed_pane_ = new TabbedPane(); |
| 22 tabbed_pane_->set_listener(this); | 22 tabbed_pane_->set_listener(this); |
| 23 add_ = new TextButton(this, ASCIIToUTF16("Add")); | 23 add_ = new TextButton(this, ASCIIToUTF16("Add")); |
| 24 add_at_ = new TextButton(this, ASCIIToUTF16("Add At 1")); | 24 add_at_ = new TextButton(this, ASCIIToUTF16("Add At 1")); |
| 25 remove_at_ = new TextButton(this, ASCIIToUTF16("Remove At 1")); |
| 25 select_at_ = new TextButton(this, ASCIIToUTF16("Select At 1")); | 26 select_at_ = new TextButton(this, ASCIIToUTF16("Select At 1")); |
| 26 | 27 |
| 27 GridLayout* layout = new GridLayout(container); | 28 GridLayout* layout = new GridLayout(container); |
| 28 container->SetLayoutManager(layout); | 29 container->SetLayoutManager(layout); |
| 29 | 30 |
| 30 const int tabbed_pane_column = 0; | 31 const int tabbed_pane_column = 0; |
| 31 ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); | 32 ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); |
| 32 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 33 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 33 1.0f, GridLayout::USE_PREF, 0, 0); | 34 1.0f, GridLayout::USE_PREF, 0, 0); |
| 34 layout->StartRow(1 /* expand */, tabbed_pane_column); | 35 layout->StartRow(1 /* expand */, tabbed_pane_column); |
| 35 layout->AddView(tabbed_pane_); | 36 layout->AddView(tabbed_pane_); |
| 36 | 37 |
| 37 // Create a few tabs with a button first. | 38 // Create a few tabs with a button first. |
| 38 AddButton("Tab 1"); | 39 AddButton("Tab 1"); |
| 39 AddButton("Tab 2"); | 40 AddButton("Tab 2"); |
| 40 | 41 |
| 41 // Add control buttons horizontally. | 42 // Add control buttons horizontally. |
| 42 const int button_column = 1; | 43 const int button_column = 1; |
| 43 column_set = layout->AddColumnSet(button_column); | 44 column_set = layout->AddColumnSet(button_column); |
| 44 for (int i = 0; i < 3; i++) { | 45 for (int i = 0; i < 4; i++) { |
| 45 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 46 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 46 1.0f, GridLayout::USE_PREF, 0, 0); | 47 1.0f, GridLayout::USE_PREF, 0, 0); |
| 47 } | 48 } |
| 48 | 49 |
| 49 layout->StartRow(0 /* no expand */, button_column); | 50 layout->StartRow(0 /* no expand */, button_column); |
| 50 layout->AddView(add_); | 51 layout->AddView(add_); |
| 51 layout->AddView(add_at_); | 52 layout->AddView(add_at_); |
| 53 layout->AddView(remove_at_); |
| 52 layout->AddView(select_at_); | 54 layout->AddView(select_at_); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void TabbedPaneExample::ButtonPressed(Button* sender, const ui::Event& event) { | 57 void TabbedPaneExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 56 if (sender == add_) { | 58 if (sender == add_) { |
| 57 AddButton("Added"); | 59 AddButton("Added"); |
| 58 } else if (sender == add_at_) { | 60 } else if (sender == add_at_) { |
| 59 const string16 label = ASCIIToUTF16("Added at 1"); | 61 const string16 label = ASCIIToUTF16("Added at 1"); |
| 60 tabbed_pane_->AddTabAtIndex(1, label, new TextButton(NULL, label)); | 62 tabbed_pane_->AddTabAtIndex(1, label, new TextButton(NULL, label), true); |
| 63 } else if (sender == remove_at_) { |
| 64 if (tabbed_pane_->GetTabCount() > 1) |
| 65 delete tabbed_pane_->RemoveTabAtIndex(1); |
| 61 } else if (sender == select_at_) { | 66 } else if (sender == select_at_) { |
| 62 if (tabbed_pane_->GetTabCount() > 1) | 67 if (tabbed_pane_->GetTabCount() > 1) |
| 63 tabbed_pane_->SelectTabAt(1); | 68 tabbed_pane_->SelectTabAt(1); |
| 64 } | 69 } |
| 65 PrintStatus(); | 70 PrintStatus(); |
| 66 } | 71 } |
| 67 | 72 |
| 68 void TabbedPaneExample::TabSelectedAt(int index) { | 73 void TabbedPaneExample::TabSelectedAt(int index) { |
| 69 // Just print the status when selection changes. | 74 // Just print the status when selection changes. |
| 70 PrintStatus(); | 75 PrintStatus(); |
| 71 } | 76 } |
| 72 | 77 |
| 73 void TabbedPaneExample::PrintStatus() { | 78 void TabbedPaneExample::PrintStatus() { |
| 74 ExampleBase::PrintStatus("Tab Count:%d, Selected Tab:%d", | 79 ExampleBase::PrintStatus("Tab Count:%d, Selected Tab:%d", |
| 75 tabbed_pane_->GetTabCount(), | 80 tabbed_pane_->GetTabCount(), |
| 76 tabbed_pane_->selected_tab_index()); | 81 tabbed_pane_->GetSelectedTabIndex()); |
| 77 } | 82 } |
| 78 | 83 |
| 79 void TabbedPaneExample::AddButton(const std::string& label) { | 84 void TabbedPaneExample::AddButton(const std::string& label) { |
| 80 TextButton* button = new TextButton(NULL, ASCIIToUTF16(label)); | 85 TextButton* button = new TextButton(NULL, ASCIIToUTF16(label)); |
| 81 tabbed_pane_->AddTab(ASCIIToUTF16(label), button); | 86 tabbed_pane_->AddTab(ASCIIToUTF16(label), button); |
| 82 } | 87 } |
| 83 | 88 |
| 84 } // namespace examples | 89 } // namespace examples |
| 85 } // namespace views | 90 } // namespace views |
| OLD | NEW |