From 024e9a4cea08387daf5c2027cdc7e098eb563503 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 15 Feb 2005 23:19:32 +0000 Subject: [PATCH] Better resizing code fro wxComboBox. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32090 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/combobox.cpp | 4 ++-- src/gtk/window.cpp | 44 +++++++++++++++++++++++++++++++++++++++---- src/gtk1/combobox.cpp | 4 ++-- src/gtk1/window.cpp | 44 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 0e16d9ae26..3217adb803 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -273,8 +273,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, SetBestSize(size); // need this too because this is a wxControlWithItems // This is required for tool bar support - wxSize setsize = GetSize(); - gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); +// wxSize setsize = GetSize(); +// gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); return true; } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 4e92f5a423..2ffbc1a024 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -28,6 +28,7 @@ #include "wx/dialog.h" #include "wx/msgdlg.h" #include "wx/module.h" +#include "wx/combobox.h" #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -476,6 +477,34 @@ void wxgtk_window_size_request_callback(GtkWidget *widget, requisition->width = w; } + +extern "C" +void wxgtk_combo_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxComboBox *win) +{ + // This callback is actually hooked into the text entry + // of the combo box, not the GtkHBox. + + int w, h; + win->GetSize( &w, &h ); + if (w < 2) + w = 2; + if (h < 2) + h = 2; + + GtkCombo *gcombo = GTK_COMBO(win->m_widget); + + GtkRequisition entry_req; + entry_req.width = 2; + entry_req.height = 2; + (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo->button) )->size_request ) + (gcombo->button, &entry_req ); + + requisition->width = w - entry_req.width; + requisition->height = entry_req.height+4; // TODO: why +4? +} + //----------------------------------------------------------------------------- // "expose_event" of m_wxwindow //----------------------------------------------------------------------------- @@ -2929,13 +2958,20 @@ void wxWindowGTK::PostCreation() GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } - if ( !GTK_IS_COMBO(m_widget)) + if (GTK_IS_COMBO(m_widget)) + { + GtkCombo *gcombo = GTK_COMBO(m_widget); + + gtk_signal_connect( GTK_OBJECT(gcombo->entry), "size_request", + GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback), + (gpointer) this ); + } + else { // This is needed if we want to add our windows into native - // GTK control, such as the toolbar. With this callback, the + // GTK controls, such as the toolbar. With this callback, the // toolbar gets to know the correct size (the one set by the - // programmer). Sadly, it misbehaves for wxComboBox. FIXME - // when moving to GTK 2.0. + // programmer). Sadly, it misbehaves for wxComboBox. gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), (gpointer) this ); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 0e16d9ae26..3217adb803 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -273,8 +273,8 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, SetBestSize(size); // need this too because this is a wxControlWithItems // This is required for tool bar support - wxSize setsize = GetSize(); - gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); +// wxSize setsize = GetSize(); +// gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); return true; } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 4e92f5a423..2ffbc1a024 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -28,6 +28,7 @@ #include "wx/dialog.h" #include "wx/msgdlg.h" #include "wx/module.h" +#include "wx/combobox.h" #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -476,6 +477,34 @@ void wxgtk_window_size_request_callback(GtkWidget *widget, requisition->width = w; } + +extern "C" +void wxgtk_combo_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxComboBox *win) +{ + // This callback is actually hooked into the text entry + // of the combo box, not the GtkHBox. + + int w, h; + win->GetSize( &w, &h ); + if (w < 2) + w = 2; + if (h < 2) + h = 2; + + GtkCombo *gcombo = GTK_COMBO(win->m_widget); + + GtkRequisition entry_req; + entry_req.width = 2; + entry_req.height = 2; + (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo->button) )->size_request ) + (gcombo->button, &entry_req ); + + requisition->width = w - entry_req.width; + requisition->height = entry_req.height+4; // TODO: why +4? +} + //----------------------------------------------------------------------------- // "expose_event" of m_wxwindow //----------------------------------------------------------------------------- @@ -2929,13 +2958,20 @@ void wxWindowGTK::PostCreation() GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } - if ( !GTK_IS_COMBO(m_widget)) + if (GTK_IS_COMBO(m_widget)) + { + GtkCombo *gcombo = GTK_COMBO(m_widget); + + gtk_signal_connect( GTK_OBJECT(gcombo->entry), "size_request", + GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback), + (gpointer) this ); + } + else { // This is needed if we want to add our windows into native - // GTK control, such as the toolbar. With this callback, the + // GTK controls, such as the toolbar. With this callback, the // toolbar gets to know the correct size (the one set by the - // programmer). Sadly, it misbehaves for wxComboBox. FIXME - // when moving to GTK 2.0. + // programmer). Sadly, it misbehaves for wxComboBox. gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), (gpointer) this ); -- 2.45.2