summaryrefslogtreecommitdiffstats
path: root/views/examples/tabbed_pane_example.h
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 17:04:53 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 17:04:53 +0000
commite5709adccae0cfa3856d16cb3a5d908e51cbf346 (patch)
tree27c5b9495f19d2c6f9c754544834c2dfc3daa595 /views/examples/tabbed_pane_example.h
parenta6954d6f9e0a68675767df9d9939a66d6f383924 (diff)
downloadchromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.zip
chromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.tar.gz
chromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.tar.bz2
More examples:
MessageBox, TabbedPane and RadioButton BUG=none TEST=none Review URL: http://codereview.chromium.org/214053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples/tabbed_pane_example.h')
-rw-r--r--views/examples/tabbed_pane_example.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/views/examples/tabbed_pane_example.h b/views/examples/tabbed_pane_example.h
new file mode 100644
index 0000000..9488566
--- /dev/null
+++ b/views/examples/tabbed_pane_example.h
@@ -0,0 +1,105 @@
+// Copyright (c) 2009 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.
+
+#ifndef VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
+#define VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
+
+#include "base/string_util.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+// A TabbedPane example tests adding/removing/selecting tabs.
+class TabbedPaneExample : protected ExampleBase,
+ private views::ButtonListener,
+ views::TabbedPane::Listener {
+ public:
+ TabbedPaneExample(views::TabbedPane* parent, views::Label* message)
+ : ExampleBase(message),
+ 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::View* container = new views::View();
+ parent->AddTab(L"Tabbed Pane", container);
+
+ 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(tabbed_pane_, L"Tab 1");
+ AddButton(tabbed_pane_, 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_);
+ }
+
+ virtual ~TabbedPaneExample() {}
+
+ private:
+ // ButtonListener overrides.
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
+ if (sender == add_) {
+ AddButton(tabbed_pane_, 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();
+ }
+
+ // TabbedPane::Listener overrides.
+ virtual void TabSelectedAt(int index) {
+ // Just print the status when selection changes.
+ PrintStatus();
+ }
+
+ // 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());
+ }
+
+ // The tabbed pane to be tested.
+ views::TabbedPane* tabbed_pane_;
+
+ // Control buttons to add, remove or select tabs.
+ views::Button* add_, *add_at_, *remove_at_, *select_at_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
+