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