| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "views/controls/combobox/native_combobox_gtk.h" | 5 #include "views/controls/combobox/native_combobox_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "ui/base/models/combobox_model.h" | 13 #include "ui/base/models/combobox_model.h" |
| 14 #include "views/controls/combobox/combobox.h" | 14 #include "views/controls/combobox/combobox.h" |
| 15 #include "views/controls/combobox/native_combobox_views.h" | 15 #include "views/controls/combobox/native_combobox_views.h" |
| 16 #include "views/views_delegate.h" | 16 #include "views/views_delegate.h" |
| 17 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
| 18 | 18 |
| 19 using ui::ComboboxModel; // TODO(beng): remove | |
| 20 | |
| 21 namespace views { | 19 namespace views { |
| 22 | 20 |
| 23 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 24 // NativeComboboxGtk, public: | 22 // NativeComboboxGtk, public: |
| 25 | 23 |
| 26 NativeComboboxGtk::NativeComboboxGtk(Combobox* combobox) | 24 NativeComboboxGtk::NativeComboboxGtk(Combobox* combobox) |
| 27 : combobox_(combobox), | 25 : combobox_(combobox), |
| 28 menu_(NULL) { | 26 menu_(NULL) { |
| 29 set_focus_view(combobox); | 27 set_focus_view(combobox); |
| 30 } | 28 } |
| 31 | 29 |
| 32 NativeComboboxGtk::~NativeComboboxGtk() { | 30 NativeComboboxGtk::~NativeComboboxGtk() { |
| 33 } | 31 } |
| 34 | 32 |
| 35 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 36 // NativeComboboxGtk, NativeComboboxWrapper implementation: | 34 // NativeComboboxGtk, NativeComboboxWrapper implementation: |
| 37 | 35 |
| 38 void NativeComboboxGtk::UpdateFromModel() { | 36 void NativeComboboxGtk::UpdateFromModel() { |
| 39 if (!native_view()) | 37 if (!native_view()) |
| 40 return; | 38 return; |
| 41 | 39 |
| 42 preferred_size_ = gfx::Size(); | 40 preferred_size_ = gfx::Size(); |
| 43 | 41 |
| 44 GtkListStore* store = | 42 GtkListStore* store = |
| 45 GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(native_view()))); | 43 GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(native_view()))); |
| 46 ComboboxModel* model = combobox_->model(); | 44 ui::ComboboxModel* model = combobox_->model(); |
| 47 int count = model->GetItemCount(); | 45 int count = model->GetItemCount(); |
| 48 gtk_list_store_clear(store); | 46 gtk_list_store_clear(store); |
| 49 GtkTreeIter iter; | 47 GtkTreeIter iter; |
| 50 while (count-- > 0) { | 48 while (count-- > 0) { |
| 51 gtk_list_store_prepend(store, &iter); | 49 gtk_list_store_prepend(store, &iter); |
| 52 gtk_list_store_set(store, &iter, | 50 gtk_list_store_set(store, &iter, |
| 53 0, UTF16ToUTF8(model->GetItemAt(count)).c_str(), | 51 0, UTF16ToUTF8(model->GetItemAt(count)).c_str(), |
| 54 -1); | 52 -1); |
| 55 } | 53 } |
| 56 } | 54 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 224 |
| 227 // static | 225 // static |
| 228 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 226 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
| 229 Combobox* combobox) { | 227 Combobox* combobox) { |
| 230 if (Widget::IsPureViews()) | 228 if (Widget::IsPureViews()) |
| 231 return new NativeComboboxViews(combobox); | 229 return new NativeComboboxViews(combobox); |
| 232 return new NativeComboboxGtk(combobox); | 230 return new NativeComboboxGtk(combobox); |
| 233 } | 231 } |
| 234 | 232 |
| 235 } // namespace views | 233 } // namespace views |
| OLD | NEW |