Commit 4975080f authored by tfarina@chromium.org's avatar tfarina@chromium.org

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
parent 16feffcd
// 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
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -6,63 +6,28 @@ ...@@ -6,63 +6,28 @@
#define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_ #define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
#pragma once #pragma once
#include "base/string_util.h" #include "base/compiler_specific.h"
#include "base/utf_string_conversions.h"
#include "ui/base/models/combobox_model.h"
#include "views/controls/combobox/combobox.h" #include "views/controls/combobox/combobox.h"
#include "views/examples/example_base.h" #include "views/examples/example_base.h"
#include "views/fill_layout.h" #include "views/fill_layout.h"
using ui::ComboboxModel; // TODO(beng): remove
namespace examples { namespace examples {
// ComboboxExample class ComboboxExample : public ExampleBase,
class ComboboxExample : public ExampleBase, public views::Combobox::Listener { 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";
}
virtual void CreateExampleView(views::View* container) {
container->SetLayoutManager(new views::FillLayout);
container->AddChildView(combobox_);
}
private:
// An sample combobox model that generates list of "Item <index>".
class ComboboxModelExample : public ComboboxModel {
public: public:
ComboboxModelExample() {} explicit ComboboxExample(ExamplesMain* main);
virtual ~ComboboxModelExample() {} virtual ~ComboboxExample();
virtual int GetItemCount() { // Overridden from ExampleBase:
return 10; virtual std::wstring GetExampleTitle() OVERRIDE;
} virtual void CreateExampleView(views::View* container) OVERRIDE;
virtual string16 GetItemAt(int index) {
return WideToUTF16Hack(StringPrintf(L"Item %d", index));
}
private: private:
DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample); // Overridden from views::Combobox::Listener:
};
// Lister implementation.
virtual void ItemChanged(views::Combobox* combo_box, virtual void ItemChanged(views::Combobox* combo_box,
int prev_index, int prev_index,
int new_index) { int new_index) OVERRIDE;
PrintStatus(L"Selected: index=%d, label=%ls",
new_index, UTF16ToWideHack(
combo_box->model()->GetItemAt(new_index)).c_str());
}
// This test only control. // This test only control.
views::Combobox* combobox_; views::Combobox* combobox_;
......
// 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
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -6,40 +6,28 @@ ...@@ -6,40 +6,28 @@
#define VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_ #define VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_
#pragma once #pragma once
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "views/controls/slider/slider.h" #include "views/controls/slider/slider.h"
#include "views/examples/example_base.h" #include "views/examples/example_base.h"
#include "views/fill_layout.h"
namespace examples { namespace examples {
// SliderExample demonstrates how to use the Slider class. // SliderExample demonstrates how to use the Slider class.
class SliderExample : public ExampleBase, views::SliderListener { class SliderExample : public ExampleBase, public views::SliderListener {
public: public:
explicit SliderExample(ExamplesMain* main) : ExampleBase(main) { explicit SliderExample(ExamplesMain* main);
} virtual ~SliderExample();
virtual ~SliderExample() {}
virtual std::wstring GetExampleTitle() {
return L"Slider";
}
virtual void CreateExampleView(views::View* container) { // Overridden from ExampleBase:
const double min = 0.0; virtual std::wstring GetExampleTitle() OVERRIDE;
const double max = 100.0; virtual void CreateExampleView(views::View* container) OVERRIDE;
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_);
}
private: private:
virtual void SliderValueChanged(views::Slider* sender) { // Overridden from views::SliderListener:
PrintStatus(L"Value: %.1f", sender->value()); virtual void SliderValueChanged(views::Slider* sender) OVERRIDE;
}
views::Slider* slider_; views::Slider* slider_;
...@@ -49,4 +37,3 @@ class SliderExample : public ExampleBase, views::SliderListener { ...@@ -49,4 +37,3 @@ class SliderExample : public ExampleBase, views::SliderListener {
} // namespace examples } // namespace examples
#endif // VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_ #endif // VIEWS_EXAMPLES_SLIDER_EXAMPLE_H_
...@@ -520,6 +520,7 @@ ...@@ -520,6 +520,7 @@
], ],
'sources': [ 'sources': [
'examples/button_example.h', 'examples/button_example.h',
'examples/combobox_example.cc',
'examples/combobox_example.h', 'examples/combobox_example.h',
'examples/example_base.cc', 'examples/example_base.cc',
'examples/example_base.h', 'examples/example_base.h',
...@@ -531,6 +532,7 @@ ...@@ -531,6 +532,7 @@
'examples/scroll_view_example.h', 'examples/scroll_view_example.h',
'examples/single_split_view_example.cc', 'examples/single_split_view_example.cc',
'examples/single_split_view_example.h', 'examples/single_split_view_example.h',
'examples/slider_example.cc',
'examples/slider_example.h', 'examples/slider_example.h',
'examples/tabbed_pane_example.cc', 'examples/tabbed_pane_example.cc',
'examples/tabbed_pane_example.h', 'examples/tabbed_pane_example.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment