Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: views/examples/tabbed_pane_example.h

Issue 6283008: views: Move the implementation of TabbedPaneExample from the header file to the source file. (Closed)
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | views/examples/tabbed_pane_example.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 #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 #pragma once 7 #pragma once
8 8
9 #include "base/string_util.h"
10 #include "views/controls/button/text_button.h" 9 #include "views/controls/button/text_button.h"
11 #include "views/examples/example_base.h" 10 #include "views/examples/example_base.h"
11 #include "views/controls/tabbed_pane/tabbed_pane.h"
12 12
13 namespace examples { 13 namespace examples {
14 14
15 // A TabbedPane example tests adding/removing/selecting tabs. 15 // A TabbedPane example tests adding/removing/selecting tabs.
16 class TabbedPaneExample : public ExampleBase, 16 class TabbedPaneExample : public ExampleBase,
17 public views::ButtonListener, 17 public views::ButtonListener,
18 views::TabbedPane::Listener { 18 public views::TabbedPane::Listener {
19 public: 19 public:
20 explicit TabbedPaneExample(ExamplesMain* main) : ExampleBase(main) {} 20 explicit TabbedPaneExample(ExamplesMain* main);
21 virtual ~TabbedPaneExample();
21 22
22 virtual ~TabbedPaneExample() {} 23 // Overridden from ExampleBase:
23 24 virtual std::wstring GetExampleTitle();
24 virtual std::wstring GetExampleTitle() { 25 virtual void CreateExampleView(views::View* container);
25 return L"Tabbed Pane";
26 }
27
28 virtual void CreateExampleView(views::View* container) {
29 tabbed_pane_ = new views::TabbedPane();
30 add_ = new views::TextButton(this, L"Add");
31 add_at_ = new views::TextButton(this, L"Add At 1");
32 remove_at_ = new views::TextButton(this, L"Remove At 1");
33 select_at_ = new views::TextButton(this, L"Select At 1");
34
35 views::GridLayout* layout = new views::GridLayout(container);
36 container->SetLayoutManager(layout);
37
38 const int tabbed_pane_column = 0;
39 views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column);
40 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
41 1.0f, views::GridLayout::USE_PREF, 0, 0);
42 layout->StartRow(1 /* expand */, tabbed_pane_column);
43 layout->AddView(tabbed_pane_);
44
45 // Create a few tabs with a button first.
46 AddButton(L"Tab 1");
47 AddButton(L"Tab 2");
48
49 // Add control buttons horizontally.
50 const int button_column = 1;
51 column_set = layout->AddColumnSet(button_column);
52 for (int i = 0; i < 4; i++) {
53 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
54 1.0f, views::GridLayout::USE_PREF, 0, 0);
55 }
56
57 layout->StartRow(0 /* no expand */, button_column);
58 layout->AddView(add_);
59 layout->AddView(add_at_);
60 layout->AddView(remove_at_);
61 layout->AddView(select_at_);
62 }
63 26
64 private: 27 private:
65 // ButtonListener overrides. 28 // Overridden from views::ButtonListener:
66 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { 29 virtual void ButtonPressed(views::Button* sender, const views::Event& event);
67 if (sender == add_) {
68 AddButton(L"Added");
69 } else if (sender == add_at_) {
70 const std::wstring label = L"Added at 1";
71 tabbed_pane_->AddTabAtIndex(1, label,
72 new views::TextButton(NULL, label), true);
73 } else if (sender == remove_at_) {
74 if (tabbed_pane_->GetTabCount() > 1)
75 delete tabbed_pane_->RemoveTabAtIndex(1);
76 } else if (sender == select_at_) {
77 if (tabbed_pane_->GetTabCount() > 1)
78 tabbed_pane_->SelectTabAt(1);
79 }
80 PrintStatus();
81 }
82 30
83 // TabbedPane::Listener overrides. 31 // Overridden from views::TabbedPane::Listener:
84 virtual void TabSelectedAt(int index) { 32 virtual void TabSelectedAt(int index);
85 // Just print the status when selection changes.
86 PrintStatus();
87 }
88 33
89 // Print the status of the tab in the status area. 34 // Print the status of the tab in the status area.
90 void PrintStatus() { 35 void PrintStatus();
91 ExampleBase::PrintStatus(L"Tab Count:%d, Selected Tab:%d",
92 tabbed_pane_->GetTabCount(),
93 tabbed_pane_->GetSelectedTabIndex());
94 }
95 36
96 void AddButton(const std::wstring& label) { 37 void AddButton(const std::wstring& label);
97 views::TextButton* button = new views::TextButton(NULL, label);
98 tabbed_pane_->AddTab(label, button);
99 }
100 38
101 // The tabbed pane to be tested. 39 // The tabbed pane to be tested.
102 views::TabbedPane* tabbed_pane_; 40 views::TabbedPane* tabbed_pane_;
103 41
104 // Control buttons to add, remove or select tabs. 42 // Control buttons to add, remove or select tabs.
105 views::Button* add_, *add_at_, *remove_at_, *select_at_; 43 views::Button* add_, *add_at_, *remove_at_, *select_at_;
106 44
107 DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample); 45 DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample);
108 }; 46 };
109 47
110 } // namespace examples 48 } // namespace examples
111 49
112 #endif // VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ 50 #endif // VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
OLDNEW
« no previous file with comments | « no previous file | views/examples/tabbed_pane_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698