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