Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: views/examples/combobox_example.cc

Issue 6366008: views: Move implementations of ComboboxExample and SliderExample to source file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Slider is only implemented in gtk Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/examples/combobox_example.cc
diff --git a/views/examples/combobox_example.cc b/views/examples/combobox_example.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16c84c7ba804bd95d8e297ade55dc12b4cc324b6
--- /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

Powered by Google App Engine
This is Rietveld 408576698