summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 18:02:59 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 18:02:59 +0000
commitad7f5dd1a9f700d1fda062f7b541ab1fb9ecfdd3 (patch)
tree2ef13720daf6be8b2356db9501a2c2a634f03c6c /views
parenta1cbcc403c92a24a44d369fb6af29a6529cb44dd (diff)
downloadchromium_src-ad7f5dd1a9f700d1fda062f7b541ab1fb9ecfdd3.zip
chromium_src-ad7f5dd1a9f700d1fda062f7b541ab1fb9ecfdd3.tar.gz
chromium_src-ad7f5dd1a9f700d1fda062f7b541ab1fb9ecfdd3.tar.bz2
Lands 176025 from Oshima:
Combobox implemenation for GTK Removed const from GetPreferredSize, as GTK implementation has cache to update. TEST=none BUG=none Review URL: http://codereview.chromium.org/183015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/combobox/native_combobox_gtk.cc85
-rw-r--r--views/controls/combobox/native_combobox_gtk.h10
-rw-r--r--views/controls/combobox/native_combobox_win.cc2
-rw-r--r--views/controls/combobox/native_combobox_win.h2
-rw-r--r--views/controls/combobox/native_combobox_wrapper.h2
5 files changed, 86 insertions, 15 deletions
diff --git a/views/controls/combobox/native_combobox_gtk.cc b/views/controls/combobox/native_combobox_gtk.cc
index e1a2917..6e44fa701 100644
--- a/views/controls/combobox/native_combobox_gtk.cc
+++ b/views/controls/combobox/native_combobox_gtk.cc
@@ -2,9 +2,13 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
+#include <gtk/gtk.h>
+
#include "views/controls/combobox/native_combobox_gtk.h"
+#include "app/combobox_model.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "views/controls/combobox/combobox.h"
namespace views {
@@ -14,6 +18,7 @@ namespace views {
NativeComboboxGtk::NativeComboboxGtk(Combobox* combobox)
: combobox_(combobox) {
+ set_focus_view(combobox);
}
NativeComboboxGtk::~NativeComboboxGtk() {
@@ -23,30 +28,62 @@ NativeComboboxGtk::~NativeComboboxGtk() {
// NativeComboboxGtk, NativeComboboxWrapper implementation:
void NativeComboboxGtk::UpdateFromModel() {
- NOTIMPLEMENTED();
+ if (!native_view())
+ return;
+
+ preferred_size_ = gfx::Size();
+
+ GtkListStore* store =
+ GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(native_view())));
+ ComboboxModel* model = combobox_->model();
+ int count = model->GetItemCount();
+ gtk_list_store_clear(store);
+ GtkTreeIter iter;
+ while (count-- > 0) {
+ gtk_list_store_prepend(store, &iter);
+ gtk_list_store_set(store, &iter,
+ 0, WideToUTF8(model->GetItemAt(count)).c_str(),
+ -1);
+ }
}
void NativeComboboxGtk::UpdateSelectedItem() {
- NOTIMPLEMENTED();
+ if (!native_view())
+ return;
+ gtk_combo_box_set_active(
+ GTK_COMBO_BOX(native_view()), combobox_->selected_item());
}
void NativeComboboxGtk::UpdateEnabled() {
- NOTIMPLEMENTED();
+ SetEnabled(combobox_->IsEnabled());
}
int NativeComboboxGtk::GetSelectedItem() const {
- NOTIMPLEMENTED();
- return 0;
+ if (!native_view())
+ return 0;
+ return gtk_combo_box_get_active(GTK_COMBO_BOX(native_view()));
}
bool NativeComboboxGtk::IsDropdownOpen() const {
- NOTIMPLEMENTED();
- return false;
+ if (!native_view())
+ return false;
+ gboolean popup_shown;
+ g_object_get(G_OBJECT(native_view()), "popup-shown", &popup_shown, NULL);
+ return popup_shown;
}
-gfx::Size NativeComboboxGtk::GetPreferredSize() const {
- NOTIMPLEMENTED();
- return gfx::Size();
+gfx::Size NativeComboboxGtk::GetPreferredSize() {
+ if (!native_view())
+ return gfx::Size();
+
+ if (preferred_size_.IsEmpty()) {
+ GtkRequisition size_request = { 0, 0 };
+ gtk_widget_size_request(native_view(), &size_request);
+ // TODO(oshima|scott): we may not need ::max to 29. revisit this.
+ preferred_size_.SetSize(size_request.width,
+ std::max(size_request.height, 29));
+ }
+ return preferred_size_;
}
View* NativeComboboxGtk::GetView() {
@@ -61,16 +98,42 @@ gfx::NativeView NativeComboboxGtk::GetTestingHandle() const {
return native_view();
}
+void NativeComboboxGtk::SelectionChanged() {
+ combobox_->SelectionChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeComboboxGtk, NativeControlGtk overrides:
-
void NativeComboboxGtk::CreateNativeControl() {
+ GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);
+ GtkWidget* widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
+ g_object_unref(G_OBJECT(store));
+
+ GtkCellRenderer* cell = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), cell, TRUE);
+ gtk_cell_layout_set_attributes(
+ GTK_CELL_LAYOUT(widget), cell, "text", 0, NULL);
+ g_signal_connect(G_OBJECT(widget), "changed",
+ G_CALLBACK(CallChanged), this);
+
+ NativeControlCreated(widget);
+
+ // Set the data from combobox
+ UpdateFromModel();
+ // and show the 1st item by default.
+ gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 0);
}
void NativeComboboxGtk::NativeControlCreated(GtkWidget* native_control) {
NativeControlGtk::NativeControlCreated(native_control);
}
+// static
+void NativeComboboxGtk::CallChanged(GtkWidget* widget,
+ NativeComboboxGtk* combo) {
+ combo->SelectionChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeComboboxWrapper, public:
diff --git a/views/controls/combobox/native_combobox_gtk.h b/views/controls/combobox/native_combobox_gtk.h
index e1034d0..c854367 100644
--- a/views/controls/combobox/native_combobox_gtk.h
+++ b/views/controls/combobox/native_combobox_gtk.h
@@ -22,7 +22,7 @@ class NativeComboboxGtk : public NativeControlGtk,
virtual void UpdateEnabled();
virtual int GetSelectedItem() const;
virtual bool IsDropdownOpen() const;
- virtual gfx::Size GetPreferredSize() const;
+ virtual gfx::Size GetPreferredSize();
virtual View* GetView();
virtual void SetFocus();
virtual gfx::NativeView GetTestingHandle() const;
@@ -33,9 +33,17 @@ class NativeComboboxGtk : public NativeControlGtk,
virtual void NativeControlCreated(GtkWidget* widget);
private:
+ static void CallChanged(GtkWidget* widget, NativeComboboxGtk* combo);
+
+ void SelectionChanged();
+
// The combobox we are bound to.
Combobox* combobox_;
+ // The preferred size from the last size_request. See
+ // NativeButtonGtk::preferred_size_ for more detail why we need this.
+ gfx::Size preferred_size_;
+
DISALLOW_COPY_AND_ASSIGN(NativeComboboxGtk);
};
diff --git a/views/controls/combobox/native_combobox_win.cc b/views/controls/combobox/native_combobox_win.cc
index bc6102b..31f47fc 100644
--- a/views/controls/combobox/native_combobox_win.cc
+++ b/views/controls/combobox/native_combobox_win.cc
@@ -98,7 +98,7 @@ bool NativeComboboxWin::IsDropdownOpen() const {
return SendMessage(native_view(), CB_GETDROPPEDSTATE, 0, 0) != 0;
}
-gfx::Size NativeComboboxWin::GetPreferredSize() const {
+gfx::Size NativeComboboxWin::GetPreferredSize() {
COMBOBOXINFO cbi = { 0 };
cbi.cbSize = sizeof(cbi);
// Note: Don't use CB_GETCOMBOBOXINFO since that crashes on WOW64 systems
diff --git a/views/controls/combobox/native_combobox_win.h b/views/controls/combobox/native_combobox_win.h
index 46c25a6..5b7d241 100644
--- a/views/controls/combobox/native_combobox_win.h
+++ b/views/controls/combobox/native_combobox_win.h
@@ -22,7 +22,7 @@ class NativeComboboxWin : public NativeControlWin,
virtual void UpdateEnabled();
virtual int GetSelectedItem() const;
virtual bool IsDropdownOpen() const;
- virtual gfx::Size GetPreferredSize() const;
+ virtual gfx::Size GetPreferredSize();
virtual View* GetView();
virtual void SetFocus();
virtual gfx::NativeView GetTestingHandle() const;
diff --git a/views/controls/combobox/native_combobox_wrapper.h b/views/controls/combobox/native_combobox_wrapper.h
index 3cecde0..76f7855 100644
--- a/views/controls/combobox/native_combobox_wrapper.h
+++ b/views/controls/combobox/native_combobox_wrapper.h
@@ -34,7 +34,7 @@ class NativeComboboxWrapper {
virtual bool IsDropdownOpen() const = 0;
// Returns the preferred size of the combobox.
- virtual gfx::Size GetPreferredSize() const = 0;
+ virtual gfx::Size GetPreferredSize() = 0;
// Retrieves the views::View that hosts the native control.
virtual View* GetView() = 0;