From fe00335bb1d7dab7143a3f77cac9526d53f08c7a Mon Sep 17 00:00:00 2001 From: "oshima@chromium.org" Date: Tue, 22 Sep 2009 01:15:18 +0000 Subject: 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 --- views/examples/combobox_example.h | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 views/examples/combobox_example.h (limited to 'views/examples/combobox_example.h') 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 ". + 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_ + + -- cgit v1.1