OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "views/controls/listbox/listbox.h" |
| 6 |
| 7 #include "views/controls/listbox/native_listbox_wrapper.h" |
| 8 #include "views/controls/native/native_view_host.h" |
| 9 #include "views/fill_layout.h" |
| 10 |
| 11 namespace views { |
| 12 |
| 13 // Listbox ------------------------------------------------------------------ |
| 14 |
| 15 Listbox::Listbox( |
| 16 const std::vector<string16>& strings, Listbox::Listener* listener) |
| 17 : strings_(strings), |
| 18 listener_(listener), |
| 19 native_wrapper_(NULL) { |
| 20 SetLayoutManager(new FillLayout()); |
| 21 } |
| 22 |
| 23 Listbox::~Listbox() { |
| 24 } |
| 25 |
| 26 int Listbox::GetRowCount() const { |
| 27 return static_cast<int>(strings_.size()); |
| 28 } |
| 29 |
| 30 int Listbox::SelectedRow() const { |
| 31 if (!native_wrapper_) |
| 32 return -1; |
| 33 return native_wrapper_->SelectedRow(); |
| 34 } |
| 35 |
| 36 void Listbox::SelectRow(int model_row) { |
| 37 if (!native_wrapper_) |
| 38 return; |
| 39 native_wrapper_->SelectRow(model_row); |
| 40 } |
| 41 |
| 42 void Listbox::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 43 if (is_add && !native_wrapper_ && GetWidget()) { |
| 44 // The native wrapper's lifetime will be managed by the view hierarchy after |
| 45 // we call AddChildView. |
| 46 native_wrapper_ = CreateWrapper(); |
| 47 AddChildView(native_wrapper_->GetView()); |
| 48 } |
| 49 } |
| 50 |
| 51 //////////////////////////////////////////////////////////////////////////////// |
| 52 // Listbox, protected: |
| 53 |
| 54 NativeListboxWrapper* Listbox::CreateWrapper() { |
| 55 return NativeListboxWrapper::CreateNativeWrapper(this, strings_, listener_); |
| 56 } |
| 57 |
| 58 } // namespace views |
OLD | NEW |