summaryrefslogtreecommitdiffstats
path: root/views
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
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')
-rw-r--r--views/examples/examples_main_base.cc7
-rw-r--r--views/examples/message_box_example.h83
-rw-r--r--views/examples/radio_button_example.h86
-rw-r--r--views/examples/tabbed_pane_example.h105
-rw-r--r--views/views.gyp10
5 files changed, 287 insertions, 4 deletions
diff --git a/views/examples/examples_main_base.cc b/views/examples/examples_main_base.cc
index 917f96e..cd65c2c 100644
--- a/views/examples/examples_main_base.cc
+++ b/views/examples/examples_main_base.cc
@@ -16,6 +16,9 @@
// Examples
#include "views/examples/button_example.h"
#include "views/examples/combobox_example.h"
+#include "views/examples/message_box_example.h"
+#include "views/examples/radio_button_example.h"
+#include "views/examples/tabbed_pane_example.h"
namespace examples {
@@ -68,6 +71,9 @@ void ExamplesMainBase::Run() {
ButtonExample button_example(tabbed_pane, message);
ComboboxExample combobox_example(tabbed_pane, message);
+ TabbedPaneExample tabbed_pane_example(tabbed_pane, message);
+ MessageBoxExample message_box_example(tabbed_pane, message);
+ RadioButtonExample radio_button_example(tabbed_pane, message);
widget->Show();
@@ -76,4 +82,3 @@ void ExamplesMainBase::Run() {
}
} // namespace examples
-
diff --git a/views/examples/message_box_example.h b/views/examples/message_box_example.h
new file mode 100644
index 0000000..e92425f
--- /dev/null
+++ b/views/examples/message_box_example.h
@@ -0,0 +1,83 @@
+// 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_MESSAGE_BOX_EXAMPLE_H_
+#define VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
+
+#include "base/string_util.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/message_box_view.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+// A MessageBoxView example. This tests some of checkbox features
+// as well.
+class MessageBoxExample : protected ExampleBase, private views::ButtonListener {
+ public:
+ MessageBoxExample(views::TabbedPane* tabbed_pane, views::Label* message)
+ : ExampleBase(message),
+ message_box_view_(
+ new MessageBoxView(0, L"Message Box Message", L"Default Prompt")),
+ status_(new views::TextButton(this, L"Show Status")),
+ toggle_(new views::TextButton(this, L"Toggle Checkbox")) {
+ views::View* container = new views::View();
+ tabbed_pane->AddTab(L"Message Box View", container);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ message_box_view_->SetCheckBoxLabel(L"Check Box");
+
+ const int message_box_column = 0;
+ views::ColumnSet* column_set = layout->AddColumnSet(message_box_column);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, message_box_column);
+ layout->AddView(message_box_view_);
+
+ const int button_column = 1;
+ column_set = layout->AddColumnSet(button_column);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0 /* no expand */, button_column);
+
+ layout->AddView(status_);
+ layout->AddView(toggle_);
+ }
+
+ virtual ~MessageBoxExample() {}
+
+ private:
+ // ButtonListener overrides.
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
+ if (sender == status_) {
+ message_box_view_->SetCheckBoxLabel(
+ IntToOnOff(message_box_view_->IsCheckBoxSelected()));
+ PrintStatus(message_box_view_->IsCheckBoxSelected() ?
+ L"Check Box Selected" : L"Check Box Not Selected");
+ } else if (sender == toggle_) {
+ message_box_view_->SetCheckBoxSelected(
+ !message_box_view_->IsCheckBoxSelected());
+ }
+ }
+
+ // The MessageBoxView to be tested.
+ MessageBoxView* message_box_view_;
+
+ // Control buttons to show the status and toggle checkbox in the
+ // message box.
+ views::Button* status_, *toggle_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageBoxExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
+
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h
new file mode 100644
index 0000000..732fa3d
--- /dev/null
+++ b/views/examples/radio_button_example.h
@@ -0,0 +1,86 @@
+// 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_RADIO_BUTTON_EXAMPLE_H_
+#define VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
+
+#include "base/string_util.h"
+#include "views/controls/button/radio_button.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+class RadioButtonExample : protected ExampleBase,
+ private views::ButtonListener {
+ public:
+ RadioButtonExample(views::TabbedPane* tabbed_pane, views::Label* message)
+ : ExampleBase(message),
+ select_(new views::TextButton(this, L"Select")),
+ status_(new views::TextButton(this, L"Show Status")) {
+ int all = arraysize(radio_buttons_);
+
+ // divide buttons into 2 groups
+ int group_count = all / 2;
+ for (int i = 0; i < all; i++) {
+ int group = i / group_count;
+ radio_buttons_[i] = new views::RadioButton(
+ StringPrintf(L"Radio %d in group %d", (i % group_count + 1), group),
+ group);
+ }
+
+ views::View* container = new views::View();
+ tabbed_pane->AddTab(L"Radio Button", container);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1.0f, views::GridLayout::USE_PREF, 0, 0);
+ for (int i = 0; i < all; i++) {
+ layout->StartRow(0, 0);
+ layout->AddView(radio_buttons_[i]);
+ }
+ layout->StartRow(0, 0);
+ layout->AddView(select_);
+ layout->StartRow(0, 0);
+ layout->AddView(status_);
+ }
+
+ virtual ~RadioButtonExample() {}
+
+ private:
+ // Override from ButtonListener
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
+ if (sender == select_) {
+ radio_buttons_[0]->SetChecked(true);
+ radio_buttons_[5]->SetChecked(true);
+ } else if (sender == status_) {
+ // Show the state of radio buttons.
+ PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls",
+ IntToOnOff(radio_buttons_[0]->checked()),
+ IntToOnOff(radio_buttons_[1]->checked()),
+ IntToOnOff(radio_buttons_[2]->checked()),
+ IntToOnOff(radio_buttons_[3]->checked()),
+ IntToOnOff(radio_buttons_[4]->checked()),
+ IntToOnOff(radio_buttons_[5]->checked()));
+ }
+ }
+
+ // 6 radio buttons, 0-2 consists 1st group, and 3-5 consists
+ // 2nd group.
+ views::RadioButton* radio_buttons_[6];
+
+ // Control button to select radio buttons, and show the status of buttons.
+ views::TextButton* select_, *status_;
+
+ DISALLOW_COPY_AND_ASSIGN(RadioButtonExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
+
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_
+
diff --git a/views/views.gyp b/views/views.gyp
index 1b2c89a..e9456e6 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -346,12 +346,16 @@
'..',
],
'sources': [
- 'examples/button_example-inl.h',
- 'examples/example_base.h',
+ 'examples/button_example.h',
+ 'examples/combobox_example.h',
'examples/example_base.cc',
- 'examples/examples_main_base.h',
+ 'examples/example_base.h',
'examples/examples_main_base.cc',
+ 'examples/examples_main_base.h',
'examples/examples_main_gtk.cc',
+ 'examples/message_box_example.h',
+ 'examples/radio_button_example.h',
+ 'examples/tabbed_pane_example.h',
],
'conditions': [
['OS=="linux"', {