diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 22:16:55 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 22:16:55 +0000 |
commit | 5aa233385b156d2ff13645384fc34b0d3b74e2c4 (patch) | |
tree | e223c9cd959b8684236c3f4fb9008f08056ab9f8 | |
parent | eee8e1f58619869fc8a87dfcaebdbfe7f4d6b5f8 (diff) | |
download | chromium_src-5aa233385b156d2ff13645384fc34b0d3b74e2c4.zip chromium_src-5aa233385b156d2ff13645384fc34b0d3b74e2c4.tar.gz chromium_src-5aa233385b156d2ff13645384fc34b0d3b74e2c4.tar.bz2 |
views: Move the implementation of TabbedPaneExample from the header file to the source file.
BUG=None
TEST=run out/Debug/views_examples, it should work as before.
Review URL: http://codereview.chromium.org/6283008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72211 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/examples/tabbed_pane_example.cc | 92 | ||||
-rw-r--r-- | views/examples/tabbed_pane_example.h | 90 | ||||
-rw-r--r-- | views/views.gyp | 1 |
3 files changed, 107 insertions, 76 deletions
diff --git a/views/examples/tabbed_pane_example.cc b/views/examples/tabbed_pane_example.cc new file mode 100644 index 0000000..94d77d2 --- /dev/null +++ b/views/examples/tabbed_pane_example.cc @@ -0,0 +1,92 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/examples/tabbed_pane_example.h" + +#include "views/grid_layout.h" + +namespace examples { + +TabbedPaneExample::TabbedPaneExample(ExamplesMain* main) + : ExampleBase(main) { +} + +TabbedPaneExample::~TabbedPaneExample() { +} + +std::wstring TabbedPaneExample::GetExampleTitle() { + return L"Tabbed Pane"; +} + +void TabbedPaneExample::CreateExampleView(views::View* container) { + tabbed_pane_ = new views::TabbedPane(); + add_ = new views::TextButton(this, L"Add"); + add_at_ = new views::TextButton(this, L"Add At 1"); + remove_at_ = new views::TextButton(this, L"Remove At 1"); + select_at_ = new views::TextButton(this, L"Select At 1"); + + views::GridLayout* layout = new views::GridLayout(container); + container->SetLayoutManager(layout); + + const int tabbed_pane_column = 0; + views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, + 1.0f, views::GridLayout::USE_PREF, 0, 0); + layout->StartRow(1 /* expand */, tabbed_pane_column); + layout->AddView(tabbed_pane_); + + // Create a few tabs with a button first. + AddButton(L"Tab 1"); + AddButton(L"Tab 2"); + + // Add control buttons horizontally. + const int button_column = 1; + column_set = layout->AddColumnSet(button_column); + for (int i = 0; i < 4; i++) { + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, + 1.0f, views::GridLayout::USE_PREF, 0, 0); + } + + layout->StartRow(0 /* no expand */, button_column); + layout->AddView(add_); + layout->AddView(add_at_); + layout->AddView(remove_at_); + layout->AddView(select_at_); +} + +void TabbedPaneExample::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == add_) { + AddButton(L"Added"); + } else if (sender == add_at_) { + const std::wstring label = L"Added at 1"; + tabbed_pane_->AddTabAtIndex(1, label, + new views::TextButton(NULL, label), true); + } else if (sender == remove_at_) { + if (tabbed_pane_->GetTabCount() > 1) + delete tabbed_pane_->RemoveTabAtIndex(1); + } else if (sender == select_at_) { + if (tabbed_pane_->GetTabCount() > 1) + tabbed_pane_->SelectTabAt(1); + } + PrintStatus(); +} + +void TabbedPaneExample::TabSelectedAt(int index) { + // Just print the status when selection changes. + PrintStatus(); +} + +void TabbedPaneExample::PrintStatus() { + ExampleBase::PrintStatus(L"Tab Count:%d, Selected Tab:%d", + tabbed_pane_->GetTabCount(), + tabbed_pane_->GetSelectedTabIndex()); +} + +void TabbedPaneExample::AddButton(const std::wstring& label) { + views::TextButton* button = new views::TextButton(NULL, label); + tabbed_pane_->AddTab(label, button); +} + +} // namespace examples diff --git a/views/examples/tabbed_pane_example.h b/views/examples/tabbed_pane_example.h index f49d15c..649c2b72 100644 --- a/views/examples/tabbed_pane_example.h +++ b/views/examples/tabbed_pane_example.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,97 +6,35 @@ #define VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_ #pragma once -#include "base/string_util.h" #include "views/controls/button/text_button.h" #include "views/examples/example_base.h" +#include "views/controls/tabbed_pane/tabbed_pane.h" namespace examples { // A TabbedPane example tests adding/removing/selecting tabs. class TabbedPaneExample : public ExampleBase, public views::ButtonListener, - views::TabbedPane::Listener { + public views::TabbedPane::Listener { public: - explicit TabbedPaneExample(ExamplesMain* main) : ExampleBase(main) {} + explicit TabbedPaneExample(ExamplesMain* main); + virtual ~TabbedPaneExample(); - virtual ~TabbedPaneExample() {} - - virtual std::wstring GetExampleTitle() { - return L"Tabbed Pane"; - } - - virtual void CreateExampleView(views::View* container) { - tabbed_pane_ = new views::TabbedPane(); - add_ = new views::TextButton(this, L"Add"); - add_at_ = new views::TextButton(this, L"Add At 1"); - remove_at_ = new views::TextButton(this, L"Remove At 1"); - select_at_ = new views::TextButton(this, L"Select At 1"); - - views::GridLayout* layout = new views::GridLayout(container); - container->SetLayoutManager(layout); - - const int tabbed_pane_column = 0; - views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column); - column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, - 1.0f, views::GridLayout::USE_PREF, 0, 0); - layout->StartRow(1 /* expand */, tabbed_pane_column); - layout->AddView(tabbed_pane_); - - // Create a few tabs with a button first. - AddButton(L"Tab 1"); - AddButton(L"Tab 2"); - - // Add control buttons horizontally. - const int button_column = 1; - column_set = layout->AddColumnSet(button_column); - for (int i = 0; i < 4; i++) { - column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, - 1.0f, views::GridLayout::USE_PREF, 0, 0); - } - - layout->StartRow(0 /* no expand */, button_column); - layout->AddView(add_); - layout->AddView(add_at_); - layout->AddView(remove_at_); - layout->AddView(select_at_); - } + // Overridden from ExampleBase: + virtual std::wstring GetExampleTitle(); + virtual void CreateExampleView(views::View* container); private: - // ButtonListener overrides. - virtual void ButtonPressed(views::Button* sender, const views::Event& event) { - if (sender == add_) { - AddButton(L"Added"); - } else if (sender == add_at_) { - const std::wstring label = L"Added at 1"; - tabbed_pane_->AddTabAtIndex(1, label, - new views::TextButton(NULL, label), true); - } else if (sender == remove_at_) { - if (tabbed_pane_->GetTabCount() > 1) - delete tabbed_pane_->RemoveTabAtIndex(1); - } else if (sender == select_at_) { - if (tabbed_pane_->GetTabCount() > 1) - tabbed_pane_->SelectTabAt(1); - } - PrintStatus(); - } + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); - // TabbedPane::Listener overrides. - virtual void TabSelectedAt(int index) { - // Just print the status when selection changes. - PrintStatus(); - } + // Overridden from views::TabbedPane::Listener: + virtual void TabSelectedAt(int index); // Print the status of the tab in the status area. - void PrintStatus() { - ExampleBase::PrintStatus(L"Tab Count:%d, Selected Tab:%d", - tabbed_pane_->GetTabCount(), - tabbed_pane_->GetSelectedTabIndex()); - } + void PrintStatus(); - void AddButton(const std::wstring& label) { - views::TextButton* button = new views::TextButton(NULL, label); - tabbed_pane_->AddTab(label, button); - } + void AddButton(const std::wstring& label); // The tabbed pane to be tested. views::TabbedPane* tabbed_pane_; diff --git a/views/views.gyp b/views/views.gyp index 34013a6..2cbdbf6 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -532,6 +532,7 @@ 'examples/single_split_view_example.cc', 'examples/single_split_view_example.h', 'examples/slider_example.h', + 'examples/tabbed_pane_example.cc', 'examples/tabbed_pane_example.h', 'examples/textfield_example.h', 'examples/throbber_example.cc', |