diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-24 13:04:55 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-24 13:04:55 +0000 |
commit | 4975080fbd3b2b032fb005e36c07f5254ca3e34a (patch) | |
tree | 40670f02fcf88564c0115cf9c61d67a746f6cc72 /views | |
parent | 16feffcde410248e08396f1307243f2b5cc3a46e (diff) | |
download | chromium_src-4975080fbd3b2b032fb005e36c07f5254ca3e34a.zip chromium_src-4975080fbd3b2b032fb005e36c07f5254ca3e34a.tar.gz chromium_src-4975080fbd3b2b032fb005e36c07f5254ca3e34a.tar.bz2 |
views: Move implementations of ComboboxExample and SliderExample to source file.
BUG=None
TEST=run out/Debug/views_examples, everything should works as before.
Review URL: http://codereview.chromium.org/6366008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72328 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/examples/combobox_example.cc | 63 | ||||
-rw-r--r-- | views/examples/combobox_example.h | 57 | ||||
-rw-r--r-- | views/examples/slider_example.cc | 39 | ||||
-rw-r--r-- | views/examples/slider_example.h | 39 | ||||
-rw-r--r-- | views/views.gyp | 2 |
5 files changed, 128 insertions, 72 deletions
diff --git a/views/examples/combobox_example.cc b/views/examples/combobox_example.cc new file mode 100644 index 0000000..16c84c7 --- /dev/null +++ b/views/examples/combobox_example.cc @@ -0,0 +1,63 @@ +// 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/combobox_example.h" + +#include "base/stringprintf.h" +#include "base/utf_string_conversions.h" +#include "ui/base/models/combobox_model.h" +#include "views/fill_layout.h" + +namespace { + +// An sample combobox model that generates list of "Item <index>". +class ComboboxModelExample : public ui::ComboboxModel { + public: + ComboboxModelExample() {} + virtual ~ComboboxModelExample() {} + + // Overridden from ui::ComboboxModel: + virtual int GetItemCount() OVERRIDE { return 10; } + + // Overridden from ui::ComboboxModel: + virtual string16 GetItemAt(int index) OVERRIDE { + return WideToUTF16Hack(base::StringPrintf(L"Item %d", index)); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); +}; + +} // namespace + +namespace examples { + +ComboboxExample::ComboboxExample(ExamplesMain* main) : ExampleBase(main) { +} + +ComboboxExample::~ComboboxExample() { +} + +std::wstring ComboboxExample::GetExampleTitle() { + return L"Combo Box"; +} + +void ComboboxExample::CreateExampleView(views::View* container) { + combobox_ = new views::Combobox(new ComboboxModelExample()); + combobox_->set_listener(this); + combobox_->SetSelectedItem(3); + + container->SetLayoutManager(new views::FillLayout); + container->AddChildView(combobox_); +} + +void ComboboxExample::ItemChanged(views::Combobox* combo_box, + int prev_index, + int new_index) { + PrintStatus(L"Selected: index=%d, label=%ls", + new_index, UTF16ToWideHack( + combo_box->model()->GetItemAt(new_index)).c_str()); +} + +} // namespace examples diff --git a/views/examples/combobox_example.h b/views/examples/combobox_example.h index 35e85c0..127c507 100644 --- a/views/examples/combobox_example.h +++ b/views/examples/combobox_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,63 +6,28 @@ #define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ #pragma once -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "ui/base/models/combobox_model.h" +#include "base/compiler_specific.h" #include "views/controls/combobox/combobox.h" #include "views/examples/example_base.h" #include "views/fill_layout.h" -using ui::ComboboxModel; // TODO(beng): remove - namespace examples { -// ComboboxExample -class ComboboxExample : public ExampleBase, public views::Combobox::Listener { +class ComboboxExample : public ExampleBase, + public views::Combobox::Listener { public: - explicit ComboboxExample(ExamplesMain* main) : ExampleBase(main) { - combobox_ = new views::Combobox(new ComboboxModelExample()); - combobox_->set_listener(this); - combobox_->SetSelectedItem(3); - } - virtual ~ComboboxExample() {} - - virtual std::wstring GetExampleTitle() { - return L"Combo Box"; - } + explicit ComboboxExample(ExamplesMain* main); + virtual ~ComboboxExample(); - virtual void CreateExampleView(views::View* container) { - container->SetLayoutManager(new views::FillLayout); - container->AddChildView(combobox_); - } + // Overridden from ExampleBase: + virtual std::wstring GetExampleTitle() OVERRIDE; + virtual void CreateExampleView(views::View* container) OVERRIDE; private: - // An sample combobox model that generates list of "Item <index>". - class ComboboxModelExample : public ComboboxModel { - public: - ComboboxModelExample() {} - virtual ~ComboboxModelExample() {} - - virtual int GetItemCount() { - return 10; - } - - virtual string16 GetItemAt(int index) { - return WideToUTF16Hack(StringPrintf(L"Item %d", index)); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); - }; - - // Lister implementation. + // Overridden from views::Combobox::Listener: virtual void ItemChanged(views::Combobox* combo_box, int prev_index, - int new_index) { - PrintStatus(L"Selected: index=%d, label=%ls", - new_index, UTF16ToWideHack( - combo_box->model()->GetItemAt(new_index)).c_str()); - } + int new_index) OVERRIDE; // This test only control. views::Combobox* combobox_; diff --git a/views/examples/slider_example.cc b/views/examples/slider_example.cc new file mode 100644 index 0000000..1ae8c73 --- /dev/null +++ b/views/examples/slider_example.cc @@ -0,0 +1,39 @@ +// 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/slider_example.h" + +#include "build/build_config.h" +#include "views/fill_layout.h" + +namespace examples { + +SliderExample::SliderExample(ExamplesMain* main) : ExampleBase(main) { +} + +SliderExample::~SliderExample() { +} + +std::wstring SliderExample::GetExampleTitle() { + return L"Slider"; +} + +void SliderExample::CreateExampleView(views::View* container) { +#if !defined(OS_WIN) && !defined(OS_MACOSX) + const double min = 0.0; + const double max = 100.0; + const double step = 1.0; + slider_ = new views::Slider(min, max, step, + views::Slider::STYLE_DRAW_VALUE, this); + + container->SetLayoutManager(new views::FillLayout); + container->AddChildView(slider_); +#endif +} + +void SliderExample::SliderValueChanged(views::Slider* sender) { + PrintStatus(L"Value: %.1f", sender->value()); +} + +} // namespace examples diff --git a/views/examples/slider_example.h b/views/examples/slider_example.h index f70c6bd..c69cac6 100644 --- a/views/examples/slider_example.h +++ b/views/examples/slider_example.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 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,40 +6,28 @@ #define VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_ #pragma once +#include <string> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" #include "views/controls/slider/slider.h" #include "views/examples/example_base.h" -#include "views/fill_layout.h" namespace examples { // SliderExample demonstrates how to use the Slider class. -class SliderExample : public ExampleBase, views::SliderListener { +class SliderExample : public ExampleBase, public views::SliderListener { public: - explicit SliderExample(ExamplesMain* main) : ExampleBase(main) { - } - - virtual ~SliderExample() {} - - virtual std::wstring GetExampleTitle() { - return L"Slider"; - } + explicit SliderExample(ExamplesMain* main); + virtual ~SliderExample(); - virtual void CreateExampleView(views::View* container) { - const double min = 0.0; - const double max = 100.0; - const double step = 1.0; - const views::Slider::StyleFlags style = - views::Slider::STYLE_DRAW_VALUE; - slider_ = new views::Slider(min, max, step, style, this); - - container->SetLayoutManager(new views::FillLayout); - container->AddChildView(slider_); - } + // Overridden from ExampleBase: + virtual std::wstring GetExampleTitle() OVERRIDE; + virtual void CreateExampleView(views::View* container) OVERRIDE; private: - virtual void SliderValueChanged(views::Slider* sender) { - PrintStatus(L"Value: %.1f", sender->value()); - } + // Overridden from views::SliderListener: + virtual void SliderValueChanged(views::Slider* sender) OVERRIDE; views::Slider* slider_; @@ -49,4 +37,3 @@ class SliderExample : public ExampleBase, views::SliderListener { } // namespace examples #endif // VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_ - diff --git a/views/views.gyp b/views/views.gyp index 26c5a34..cc17b09 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -520,6 +520,7 @@ ], 'sources': [ 'examples/button_example.h', + 'examples/combobox_example.cc', 'examples/combobox_example.h', 'examples/example_base.cc', 'examples/example_base.h', @@ -531,6 +532,7 @@ 'examples/scroll_view_example.h', 'examples/single_split_view_example.cc', 'examples/single_split_view_example.h', + 'examples/slider_example.cc', 'examples/slider_example.h', 'examples/tabbed_pane_example.cc', 'examples/tabbed_pane_example.h', |