summaryrefslogtreecommitdiffstats
path: root/views/examples/combobox_example.h
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 01:15:18 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-22 01:15:18 +0000
commitfe00335bb1d7dab7143a3f77cac9526d53f08c7a (patch)
tree02f9a379a10865c2b8762f663552588ab3816979 /views/examples/combobox_example.h
parent5b69e884ffd49dd64835a87d95b282377d6ad1c3 (diff)
downloadchromium_src-fe00335bb1d7dab7143a3f77cac9526d53f08c7a.zip
chromium_src-fe00335bb1d7dab7143a3f77cac9526d53f08c7a.tar.gz
chromium_src-fe00335bb1d7dab7143a3f77cac9526d53f08c7a.tar.bz2
View examples:
I'm planning to move these to unit_test using Jay's testing framework, but let's check in it first, and then I will refactor and move them to unittest. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples/combobox_example.h')
-rw-r--r--views/examples/combobox_example.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/views/examples/combobox_example.h b/views/examples/combobox_example.h
new file mode 100644
index 0000000..28c8cc3
--- /dev/null
+++ b/views/examples/combobox_example.h
@@ -0,0 +1,61 @@
+// 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_COMBOBOX_EXAMPLE_H_
+#define VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
+
+#include "app/combobox_model.h"
+#include "base/string_util.h"
+#include "views/controls/combobox/combobox.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+// ComboboxExample
+class ComboboxExample : protected ExampleBase,
+ private 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);
+ }
+ virtual ~ComboboxExample() {}
+
+ 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 std::wstring GetItemAt(int index) {
+ return StringPrintf(L"Item %d", index);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample);
+ };
+
+ // Lister implementation.
+ virtual void ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) {
+ PrintStatus(L"Selected: index=%d, label=%ls",
+ new_index, combo_box->model()->GetItemAt(new_index).c_str());
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ComboboxExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
+
+