summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 17:22:48 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 17:22:48 +0000
commite557d64b1d89a5acbe4b185e63c029c428bd217b (patch)
treeadc254b279329bfae6f1a53cc19a03a3cade7a41 /views
parentdd92c8dc5191650d37501f74bf017e4ad4f664a4 (diff)
downloadchromium_src-e557d64b1d89a5acbe4b185e63c029c428bd217b.zip
chromium_src-e557d64b1d89a5acbe4b185e63c029c428bd217b.tar.gz
chromium_src-e557d64b1d89a5acbe4b185e63c029c428bd217b.tar.bz2
Porting the view examples to Windows.
Some refactoring done to the tests also. See original review at: http://codereview.chromium.org/295013/show BUG=None TEST=Make sure the view examples build and run on Windows and Linux. Review URL: http://codereview.chromium.org/294026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/examples/button_example.h19
-rw-r--r--views/examples/combobox_example.h22
-rw-r--r--views/examples/example_base.cc15
-rw-r--r--views/examples/example_base.h25
-rw-r--r--views/examples/examples_main.cc128
-rw-r--r--views/examples/examples_main.h46
-rw-r--r--views/examples/examples_main_base.cc88
-rw-r--r--views/examples/examples_main_base.h41
-rw-r--r--views/examples/examples_main_gtk.cc36
-rw-r--r--views/examples/message_box_example.h37
-rw-r--r--views/examples/radio_button_example.h30
-rw-r--r--views/examples/scroll_view_example.h37
-rw-r--r--views/examples/tabbed_pane_example.h50
-rw-r--r--views/examples/textfield_example.h31
-rw-r--r--views/views.gyp82
15 files changed, 372 insertions, 315 deletions
diff --git a/views/examples/button_example.h b/views/examples/button_example.h
index ef93376..dacbc8c 100644
--- a/views/examples/button_example.h
+++ b/views/examples/button_example.h
@@ -7,7 +7,6 @@
#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 {
@@ -15,21 +14,29 @@ namespace examples {
// ButtonExample simply counts the number of clicks.
class ButtonExample : protected ExampleBase, private views::ButtonListener {
public:
- ButtonExample(views::TabbedPane* tabbed_pane, views::Label* message)
- : ExampleBase(message),
- count_(0) {
- views::TextButton* button = new views::TextButton(this, L"Button");
- tabbed_pane->AddTab(L"Text Button", button);
+ explicit ButtonExample(ExamplesMain* main) : ExampleBase(main), count_(0) {
+ button_ = new views::TextButton(this, L"Button");
}
virtual ~ButtonExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Text Button";
+ }
+
+ virtual views::View* GetExampleView() {
+ return button_;
+ }
+
private:
// ButtonListner implementation.
virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
PrintStatus(L"Pressed! count:%d", ++count_);
}
+ // The only control in this test.
+ views::TextButton* button_;
+
// The number of times the button is pressed.
int count_;
diff --git a/views/examples/combobox_example.h b/views/examples/combobox_example.h
index 28c8cc3..f65508f 100644
--- a/views/examples/combobox_example.h
+++ b/views/examples/combobox_example.h
@@ -13,17 +13,22 @@
namespace examples {
// ComboboxExample
-class ComboboxExample : protected ExampleBase,
- private views::Combobox::Listener {
+class ComboboxExample : public ExampleBase, public views::Combobox::Listener {
public:
- ComboboxExample(views::TabbedPane* tabbed_pane, views::Label* message)
- : ExampleBase(message) {
- views::Combobox* cb = new views::Combobox(new ComboboxModelExample());
- cb->set_listener(this);
- tabbed_pane->AddTab(L"Combo Box", cb);
+ explicit ComboboxExample(ExamplesMain* main) : ExampleBase(main) {
+ combobox_ = new views::Combobox(new ComboboxModelExample());
+ combobox_->set_listener(this);
}
virtual ~ComboboxExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Combo Box";
+ }
+
+ virtual views::View* GetExampleView() {
+ return combobox_;
+ }
+
private:
// An sample combobox model that generates list of "Item <index>".
class ComboboxModelExample : public ComboboxModel {
@@ -51,6 +56,9 @@ class ComboboxExample : protected ExampleBase,
new_index, combo_box->model()->GetItemAt(new_index).c_str());
}
+ // This test only control.
+ views::Combobox* combobox_;
+
DISALLOW_COPY_AND_ASSIGN(ComboboxExample);
};
diff --git a/views/examples/example_base.cc b/views/examples/example_base.cc
index 09231dd..70185b5 100644
--- a/views/examples/example_base.cc
+++ b/views/examples/example_base.cc
@@ -9,30 +9,17 @@
#include "base/string_util.h"
#include "views/controls/button/text_button.h"
-#include "views/controls/label.h"
#include "views/controls/tabbed_pane/tabbed_pane.h"
namespace examples {
-using views::Label;
-using views::TabbedPane;
-using views::TextButton;
-
// Prints a message in the status area, at the bottom of the window.
void ExampleBase::PrintStatus(const wchar_t* format, ...) {
va_list ap;
va_start(ap, format);
std::wstring msg;
StringAppendV(&msg, format, ap);
- status_->SetText(msg);
-}
-
-// static
-void ExampleBase::AddButton(TabbedPane* tabbed_pane,
- const std::wstring& label) {
- TextButton* button = new TextButton(NULL, label);
- tabbed_pane->AddTab(label, button);
+ main_->SetStatus(msg);
}
} // namespace examples
-
diff --git a/views/examples/example_base.h b/views/examples/example_base.h
index b17065c..35898eb 100644
--- a/views/examples/example_base.h
+++ b/views/examples/example_base.h
@@ -8,21 +8,28 @@
#include <string>
#include "base/basictypes.h"
+#include "views/examples/examples_main.h"
+#include "views/window/window_delegate.h"
namespace views {
-class Label;
-class TabbedPane;
+class View;
} // namespace views
namespace examples {
-// ExampleBase defines utility functions for examples.
class ExampleBase {
protected:
- explicit ExampleBase(views::Label* status) : status_(status) {}
-
+ explicit ExampleBase(ExamplesMain* main) : main_(main) {}
virtual ~ExampleBase() {}
+ // Sub-classes should return the name of this test.
+ // It is used as the title of the tab displaying this test's controls.
+ virtual std::wstring GetExampleTitle() = 0;
+
+ // Sub-classes should return the view containing this example controls.
+ // This view is added as a tab to the example application.
+ virtual views::View* GetExampleView() = 0;
+
// Prints a message in the status area, at the bottom of the window.
void PrintStatus(const wchar_t* format, ...);
@@ -31,13 +38,9 @@ class ExampleBase {
return value ? L"on" : L"off";
}
- // Adds a new tab with the button with given label to the tabbed pane.
- static void AddButton(views::TabbedPane* tabbed_pane,
- const std::wstring& label);
-
private:
- // A label to show a message at the bottom of example app.
- views::Label* status_;
+ // The runner actually running this test.
+ ExamplesMain* main_;
DISALLOW_COPY_AND_ASSIGN(ExampleBase);
};
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
new file mode 100644
index 0000000..6d65e8a
--- /dev/null
+++ b/views/examples/examples_main.cc
@@ -0,0 +1,128 @@
+// 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.
+
+#include "views/examples/examples_main.h"
+
+#include "app/app_paths.h"
+#include "app/resource_bundle.h"
+#include "base/at_exit.h"
+#include "base/i18n/icu_util.h"
+#include "base/process_util.h"
+#include "views/controls/label.h"
+#include "views/controls/button/text_button.h"
+#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/scroll_view_example.h"
+#include "views/examples/tabbed_pane_example.h"
+#include "views/examples/textfield_example.h"
+#include "views/focus/accelerator_handler.h"
+#include "views/grid_layout.h"
+#include "views/window/window.h"
+
+namespace examples {
+
+views::View* ExamplesMain::GetContentsView() {
+ return contents_;
+}
+
+void ExamplesMain::SetStatus(const std::wstring& status) {
+ status_label_->SetText(status);
+}
+
+void ExamplesMain::Run() {
+ base::EnableTerminationOnHeapCorruption();
+
+ // The exit manager is in charge of calling the dtors of singleton objects.
+ base::AtExitManager exit_manager;
+
+ app::RegisterPathProvider();
+
+ icu_util::Initialize();
+
+ // This requires chrome to be built first right now.
+ // TODO(oshima): fix build to include resource file.
+ ResourceBundle::InitSharedInstance(L"en-US");
+ ResourceBundle::GetSharedInstance().LoadThemeResources();
+
+ MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+
+ // Creates a window with the tabbed pane for each examples, and
+ // a label to print messages from each examples.
+ DCHECK(contents_ == NULL) << "Run called more than once.";
+ contents_ = new views::View();
+ contents_->set_background(views::Background::CreateStandardPanelBackground());
+ views::GridLayout* layout = new views::GridLayout(contents_);
+ contents_->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+
+ views::TabbedPane* tabbed_pane = new views::TabbedPane();
+ status_label_ = new views::Label();
+
+ layout->StartRow(1, 0);
+ layout->AddView(tabbed_pane);
+ layout->StartRow(0 /* no expand */, 0);
+ layout->AddView(status_label_);
+
+ examples::TextfieldExample textfield_example(this);
+ tabbed_pane->AddTab(textfield_example.GetExampleTitle(),
+ textfield_example.GetExampleView());
+
+ examples::ButtonExample button_example(this);
+ tabbed_pane->AddTab(button_example.GetExampleTitle(),
+ button_example.GetExampleView());
+
+ examples::ComboboxExample combobox_example(this);
+ tabbed_pane->AddTab(combobox_example.GetExampleTitle(),
+ combobox_example.GetExampleView());
+
+ examples::TabbedPaneExample tabbed_pane_example(this);
+ tabbed_pane->AddTab(tabbed_pane_example.GetExampleTitle(),
+ tabbed_pane_example.GetExampleView());
+
+ examples::MessageBoxExample message_box_example(this);
+ tabbed_pane->AddTab(message_box_example.GetExampleTitle(),
+ message_box_example.GetExampleView());
+
+ examples::RadioButtonExample radio_button_example(this);
+ tabbed_pane->AddTab(radio_button_example.GetExampleTitle(),
+ radio_button_example.GetExampleView());
+
+ examples::ScrollViewExample scroll_view_example(this);
+ tabbed_pane->AddTab(scroll_view_example.GetExampleTitle(),
+ scroll_view_example.GetExampleView());
+
+ views::Window* window =
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 600, 300), this);
+ window->Show();
+
+ views::AcceleratorHandler accelerator_handler;
+ MessageLoopForUI::current()->Run(&accelerator_handler);
+}
+
+} // examples namespace
+
+int main(int argc, char** argv) {
+#if defined(OS_WIN)
+ OleInitialize(NULL);
+#elif defined(OS_LINUX)
+ // Initializes gtk stuff.
+ g_thread_init(NULL);
+ g_type_init();
+ gtk_init(&argc, &argv);
+#endif
+
+ CommandLine::Init(argc, argv);
+ examples::ExamplesMain main;
+ main.Run();
+
+#if defined(OS_WIN)
+ OleUninitialize();
+#endif
+ return 0;
+}
diff --git a/views/examples/examples_main.h b/views/examples/examples_main.h
new file mode 100644
index 0000000..c1d4a2b7
--- /dev/null
+++ b/views/examples/examples_main.h
@@ -0,0 +1,46 @@
+// 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_EXAMPLE_MAIN_H_
+#define VIEWS_EXAMPLES_EXAMPLE_MAIN_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "views/window/window_delegate.h"
+
+namespace views {
+class Label;
+class View;
+} // namespace views
+
+namespace examples {
+
+// ExamplesMainBase creates all view examples and start event loop.
+class ExamplesMain : public views::WindowDelegate {
+ public:
+ ExamplesMain() : contents_(NULL), status_label_(NULL) {}
+ virtual ~ExamplesMain() {}
+
+ // views::WindowDelegate implementation:
+ virtual views::View* GetContentsView();
+
+ // Prints a message in the status area, at the bottom of the window.
+ void SetStatus(const std::wstring& status);
+
+ // Creates all examples and runs the UI event loop.
+ void Run();
+
+ private:
+ views::View* contents_;
+
+ views::Label* status_label_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExamplesMain);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_EXAMPLE_MAIN_H_
+
diff --git a/views/examples/examples_main_base.cc b/views/examples/examples_main_base.cc
deleted file mode 100644
index 9a1644b..0000000
--- a/views/examples/examples_main_base.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// 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.
-
-#include "views/examples/examples_main_base.h"
-
-#include "app/app_paths.h"
-#include "app/resource_bundle.h"
-#include "base/at_exit.h"
-#include "base/process_util.h"
-#include "views/controls/label.h"
-#include "views/focus/accelerator_handler.h"
-#include "views/grid_layout.h"
-#include "views/widget/widget.h"
-
-// 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/scroll_view_example.h"
-#include "views/examples/tabbed_pane_example.h"
-#include "views/examples/textfield_example.h"
-
-namespace examples {
-
-using views::Background;
-using views::ColumnSet;
-using views::GridLayout;
-using views::Label;
-using views::TabbedPane;
-using views::View;
-using views::Widget;
-
-void ExamplesMainBase::Run() {
- base::EnableTerminationOnHeapCorruption();
-
- // The exit manager is in charge of calling the dtors of singleton objects.
- base::AtExitManager exit_manager;
-
- app::RegisterPathProvider();
-
- // This requires chrome to be built first right now.
- // TODO(oshima): fix build to include resource file.
- ResourceBundle::InitSharedInstance(L"en-US");
- ResourceBundle::GetSharedInstance().LoadThemeResources();
-
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
-
- Widget* widget = CreateTopLevelWidget();
- widget->Init(NULL, gfx::Rect(0, 0, 500, 300));
-
- // Creates a window with the tabbed pane for each examples, and
- // a label to print messages from each examples.
- View* container = new View();
- container->set_background(Background::CreateStandardPanelBackground());
- GridLayout* layout = new GridLayout(container);
- container->SetLayoutManager(layout);
-
- widget->SetContentsView(container);
-
- ColumnSet* column_set = layout->AddColumnSet(0);
- column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
- GridLayout::USE_PREF, 0, 0);
-
- TabbedPane* tabbed_pane = new TabbedPane();
- Label* message = new Label();
-
- layout->StartRow(1, 0);
- layout->AddView(tabbed_pane);
- layout->StartRow(0 /* no expand */, 0);
- layout->AddView(message);
-
- TextfieldExample textfield_example(tabbed_pane, message);
- 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);
- ScrollViewExample scroll_view_example(tabbed_pane, message);
-
- widget->Show();
-
- views::AcceleratorHandler accelerator_handler;
- MessageLoopForUI::current()->Run(&accelerator_handler);
-}
-
-} // namespace examples
diff --git a/views/examples/examples_main_base.h b/views/examples/examples_main_base.h
deleted file mode 100644
index 2645408..0000000
--- a/views/examples/examples_main_base.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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_EXAMPLE_MAIN_BASE_H_
-#define VIEWS_EXAMPLES_EXAMPLE_MAIN_BASE_H_
-
-#include "base/basictypes.h"
-
-namespace views {
-class Widget;
-} // namespace views
-
-namespace examples {
-
-// ExamplesMainBase creates all view examples and start event loop.
-// Each platform specific main class should extend this base class and
-// provide the implementation of CreateTopLevelWidget. The main program
-// has to perform platform specific initializations before calling Run().
-class ExamplesMainBase {
- public:
- ExamplesMainBase() {}
- virtual ~ExamplesMainBase() {}
-
- // Creates all examples and start UI event loop.
- void Run();
-
- protected:
- // Returns a widget for a top level, decorated window.
- // Each platform must implement this method and return platform specific
- // widget.
- virtual views::Widget* CreateTopLevelWidget() = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ExamplesMainBase);
-};
-
-} // namespace examples
-
-#endif // VIEWS_EXAMPLES_EXAMPLE_MAIN_BASE_H_
-
diff --git a/views/examples/examples_main_gtk.cc b/views/examples/examples_main_gtk.cc
deleted file mode 100644
index 041c8d4..0000000
--- a/views/examples/examples_main_gtk.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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.
-
-#include "views/widget/widget_gtk.h"
-#include "views/examples/examples_main_base.h"
-
-namespace {
-
-class ExamplesMainGtk : public examples::ExamplesMainBase {
- public:
- ExamplesMainGtk() {}
- virtual ~ExamplesMainGtk() {}
-
- // Overrides ExamplesMainBase.
- virtual views::Widget* CreateTopLevelWidget() {
- return new views::WidgetGtk(views::WidgetGtk::TYPE_DECORATED_WINDOW);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ExamplesMainGtk);
-};
-
-} // namespace
-
-int main(int argc, char** argv) {
- // Initializes gtk stuff.
- g_thread_init(NULL);
- g_type_init();
- gtk_init(&argc, &argv);
-
- ExamplesMainGtk main;
- main.Run();
- return 0;
-}
-
diff --git a/views/examples/message_box_example.h b/views/examples/message_box_example.h
index d586d58..3edd210 100644
--- a/views/examples/message_box_example.h
+++ b/views/examples/message_box_example.h
@@ -11,26 +11,22 @@
#include "views/controls/message_box_view.h"
#include "views/controls/tabbed_pane/tabbed_pane.h"
#include "views/examples/example_base.h"
+#include "views/grid_layout.h"
namespace examples {
-// A MessageBoxView example. This tests some of checkbox features
-// as well.
+// 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")),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- status_(new views::TextButton(this, L"Show Status"))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- 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);
+ explicit MessageBoxExample(ExamplesMain* main) : ExampleBase(main) {
+ 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");
+
+ container_ = new views::View();
+ views::GridLayout* layout = new views::GridLayout(container_);
+ container_->SetLayoutManager(layout);
message_box_view_->SetCheckBoxLabel(L"Check Box");
@@ -56,6 +52,14 @@ class MessageBoxExample : protected ExampleBase, private views::ButtonListener {
virtual ~MessageBoxExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Message Box View";
+ }
+
+ virtual views::View* GetExampleView() {
+ return container_;
+ }
+
private:
// ButtonListener overrides.
virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
@@ -70,6 +74,9 @@ class MessageBoxExample : protected ExampleBase, private views::ButtonListener {
}
}
+ // The view containing this test's controls.
+ views::View* container_;
+
// The MessageBoxView to be tested.
MessageBoxView* message_box_view_;
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h
index db0e762..abe5a4c 100644
--- a/views/examples/radio_button_example.h
+++ b/views/examples/radio_button_example.h
@@ -9,7 +9,6 @@
#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 {
@@ -17,12 +16,10 @@ namespace examples {
class RadioButtonExample : protected ExampleBase,
private views::ButtonListener {
public:
- RadioButtonExample(views::TabbedPane* tabbed_pane, views::Label* message)
- : ExampleBase(message),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- select_(new views::TextButton(this, L"Select"))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- status_(new views::TextButton(this, L"Show Status"))) {
+ explicit RadioButtonExample(ExamplesMain* main) : ExampleBase(main) {
+ 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
@@ -34,11 +31,9 @@ class RadioButtonExample : protected ExampleBase,
group);
}
- views::View* container = new views::View();
- tabbed_pane->AddTab(L"Radio Button", container);
-
- views::GridLayout* layout = new views::GridLayout(container);
- container->SetLayoutManager(layout);
+ container_ = new views::View();
+ 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,
@@ -55,6 +50,14 @@ class RadioButtonExample : protected ExampleBase,
virtual ~RadioButtonExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Radio Button";
+ }
+
+ virtual views::View* GetExampleView() {
+ return container_;
+ }
+
private:
// Override from ButtonListener
virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
@@ -73,6 +76,9 @@ class RadioButtonExample : protected ExampleBase,
}
}
+ // The view containing this test's controls.
+ views::View* container_;
+
// 6 radio buttons, 0-2 consists 1st group, and 3-5 consists
// 2nd group.
views::RadioButton* radio_buttons_[6];
diff --git a/views/examples/scroll_view_example.h b/views/examples/scroll_view_example.h
index b032224..2fd2d2f 100644
--- a/views/examples/scroll_view_example.h
+++ b/views/examples/scroll_view_example.h
@@ -5,6 +5,7 @@
#ifndef VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_
#define VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_
+#include "base/compiler_specific.h"
#include "base/string_util.h"
#include "views/controls/button/text_button.h"
#include "views/controls/scroll_view.h"
@@ -14,24 +15,21 @@ namespace examples {
class ScrollViewExample : protected ExampleBase, private views::ButtonListener {
public:
- ScrollViewExample(views::TabbedPane* tabbed_pane, views::Label* message)
- : ExampleBase(message),
- wide_(new views::TextButton(this, L"Wide")),
- tall_(new views::TextButton(this, L"Tall")),
- big_square_(new views::TextButton(this, L"Big Square")),
- small_square_(new views::TextButton(this, L"Small Square")),
- scroll_to_(new views::TextButton(this, L"Scroll to")),
- scrollable_(new ScrollableView()),
- scroll_view_(new views::ScrollView()) {
+ explicit ScrollViewExample(ExamplesMain* main) : ExampleBase(main) {
+ wide_ = new views::TextButton(this, L"Wide");
+ tall_ = new views::TextButton(this, L"Tall");
+ big_square_ = new views::TextButton(this, L"Big Square");
+ small_square_ = new views::TextButton(this, L"Small Square");
+ scroll_to_ = new views::TextButton(this, L"Scroll to");
+ scrollable_ = new ScrollableView();
+ scroll_view_ = new views::ScrollView();
scroll_view_->SetContents(scrollable_);
scrollable_->SetBounds(0, 0, 1000, 100);
scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
- views::View* container = new views::View();
- tabbed_pane->AddTab(L"Scroll View", container);
-
- views::GridLayout* layout = new views::GridLayout(container);
- container->SetLayoutManager(layout);
+ container_ = new views::View();
+ views::GridLayout* layout = new views::GridLayout(container_);
+ container_->SetLayoutManager(layout);
// Add scroll view.
views::ColumnSet* column_set = layout->AddColumnSet(0);
@@ -56,6 +54,14 @@ class ScrollViewExample : protected ExampleBase, private views::ButtonListener {
virtual ~ScrollViewExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Scroll View";
+ }
+
+ virtual views::View* GetExampleView() {
+ return container_;
+ }
+
private:
// ScrollView's content, which draws gradient color on background.
// TODO(oshima): add child views as well.
@@ -102,6 +108,9 @@ class ScrollViewExample : protected ExampleBase, private views::ButtonListener {
scroll_view_->Layout();
}
+ // The view containing this test's controls.
+ views::View* container_;
+
// Control buttons to change the size of scrollable and jump to
// predefined position.
views::TextButton* wide_, *tall_, *big_square_, *small_square_, *scroll_to_;
diff --git a/views/examples/tabbed_pane_example.h b/views/examples/tabbed_pane_example.h
index 283e355..fe622e9 100644
--- a/views/examples/tabbed_pane_example.h
+++ b/views/examples/tabbed_pane_example.h
@@ -5,10 +5,8 @@
#ifndef VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
#define VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
-#include "base/compiler_specific.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 {
@@ -18,22 +16,16 @@ 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()),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- add_(new views::TextButton(this, L"Add"))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- add_at_(new views::TextButton(this, L"Add At 1"))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- remove_at_(new views::TextButton(this, L"Remove At 1"))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- 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);
+ explicit TabbedPaneExample(ExamplesMain* main) : ExampleBase(main) {
+ 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");
+
+ container_ = new views::View();
+ 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);
@@ -43,8 +35,8 @@ class TabbedPaneExample : protected ExampleBase,
layout->AddView(tabbed_pane_);
// Create a few tabs with a button first.
- AddButton(tabbed_pane_, L"Tab 1");
- AddButton(tabbed_pane_, L"Tab 2");
+ AddButton(L"Tab 1");
+ AddButton(L"Tab 2");
// Add control buttons horizontally.
const int button_column = 1;
@@ -63,11 +55,19 @@ class TabbedPaneExample : protected ExampleBase,
virtual ~TabbedPaneExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Tabbed Pane";
+ }
+
+ virtual views::View* GetExampleView() {
+ return container_;
+ }
+
private:
// ButtonListener overrides.
virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
if (sender == add_) {
- AddButton(tabbed_pane_, L"Added");
+ AddButton(L"Added");
} else if (sender == add_at_) {
const std::wstring label = L"Added at 1";
tabbed_pane_->AddTabAtIndex(1, label,
@@ -95,6 +95,14 @@ class TabbedPaneExample : protected ExampleBase,
tabbed_pane_->GetSelectedTabIndex());
}
+ void AddButton(const std::wstring& label) {
+ views::TextButton* button = new views::TextButton(NULL, label);
+ tabbed_pane_->AddTab(label, button);
+ }
+
+ // The view containing this test's controls.
+ views::View* container_;
+
// The tabbed pane to be tested.
views::TabbedPane* tabbed_pane_;
diff --git a/views/examples/textfield_example.h b/views/examples/textfield_example.h
index 2feed4f..e30f3f9 100644
--- a/views/examples/textfield_example.h
+++ b/views/examples/textfield_example.h
@@ -21,20 +21,18 @@ class TextfieldExample : protected ExampleBase,
private Textfield::Controller,
private views::ButtonListener {
public:
- TextfieldExample(views::TabbedPane* tabbed_pane, views::Label* message)
- : ExampleBase(message),
- name_(new Textfield()),
- password_(new Textfield(Textfield::STYLE_PASSWORD)),
- show_password_(new views::TextButton(this, L"Show password")),
- clear_all_(new views::TextButton(this, L"Clear All")),
- append_(new views::TextButton(this, L"Append")) {
+ explicit TextfieldExample(ExamplesMain* main) : ExampleBase(main) {
+ name_ = new Textfield();
+ password_ = new Textfield(Textfield::STYLE_PASSWORD);
+ show_password_ = new views::TextButton(this, L"Show password");
+ clear_all_ = new views::TextButton(this, L"Clear All");
+ append_ = new views::TextButton(this, L"Append");
name_->SetController(this);
password_->SetController(this);
- views::View* container = new views::View();
- tabbed_pane->AddTab(L"Textfield", container);
- views::GridLayout* layout = new views::GridLayout(container);
- container->SetLayoutManager(layout);
+ container_ = new views::View();
+ views::GridLayout* layout = new views::GridLayout(container_);
+ container_->SetLayoutManager(layout);
views::ColumnSet* column_set = layout->AddColumnSet(0);
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
@@ -57,6 +55,14 @@ class TextfieldExample : protected ExampleBase,
virtual ~TextfieldExample() {}
+ virtual std::wstring GetExampleTitle() {
+ return L"Textfield";
+ }
+
+ virtual views::View* GetExampleView() {
+ return container_;
+ }
+
private:
// Textfield::Controller implementations:
// This method is called whenever the text in the field changes.
@@ -89,6 +95,9 @@ class TextfieldExample : protected ExampleBase,
}
}
+ // The view containing this test's controls.
+ views::View* container_;
+
// Textfields for name and password.
views::Textfield* name_;
views::Textfield* password_;
diff --git a/views/views.gyp b/views/views.gyp
index 655c57d..7074cf9 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -338,51 +338,55 @@
}],
],
},
- ],
- 'conditions': [
- # TODO(oshima): support win
- ['OS!="win"', {
- 'targets': [
- {
- 'target_name': 'view_examples',
- 'type': 'executable',
+ {
+ 'target_name': 'view_examples',
+ 'type': 'executable',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../skia/skia.gyp:skia',
+ 'views',
+ ],
+ 'include_dirs': [
+ '..',
+ ],
+ 'sources': [
+ 'examples/button_example.h',
+ 'examples/combobox_example.h',
+ 'examples/example_base.cc',
+ 'examples/example_base.h',
+ 'examples/examples_main.cc',
+ 'examples/examples_main.h',
+ 'examples/message_box_example.h',
+ 'examples/radio_button_example.h',
+ 'examples/scroll_view_example.h',
+ 'examples/tabbed_pane_example.h',
+ 'examples/textfield_example.h',
+ ],
+ 'conditions': [
+ ['OS=="linux"', {
+ 'dependencies': [
+ '../build/linux/system.gyp:gtk',
+ ],
+ },
+ ],
+ ['OS=="linux" and toolkit_views==1', {
'dependencies': [
- '../base/base.gyp:base',
- '../skia/skia.gyp:skia',
'views',
],
+ }],
+ ['OS=="win"', {
+ 'link_settings': {
+ 'libraries': [
+ '-limm32.lib',
+ '-loleacc.lib',
+ ]
+ },
'include_dirs': [
- '..',
- ],
- 'sources': [
- 'examples/button_example.h',
- 'examples/combobox_example.h',
- 'examples/example_base.cc',
- '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',
- 'examples/textfield_example.h',
- ],
- 'conditions': [
- ['OS=="linux"', {
- 'dependencies': [
- '../build/linux/system.gyp:gtk',
- ],
- },
- ],
- ['OS=="linux" and toolkit_views==1', {
- 'dependencies': [
- 'views',
- ],
- }],
+ '../chrome/third_party/wtl/include',
],
- },
+ }],
],
- }],
+ },
],
}