From e1f448eeefd90163fedd9134f35203afe51200c6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Jul 2003 22:32:52 +0000 Subject: [PATCH] corrected bug with alignment of static labels with GTK 2 (replaces patch 760066; closes bug 759375) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21883 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/gtk/stattext.cpp | 22 ++++++++++++++++++++++ src/gtk/window.cpp | 19 +++++++++++++------ src/gtk1/stattext.cpp | 22 ++++++++++++++++++++++ src/gtk1/window.cpp | 19 +++++++++++++------ 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index a60e724bbf..acf810873e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -149,6 +149,7 @@ wxGTK: be appended to filenames with no extension - added wxTextCtrl::SetSelection implementation for GTK+ 2 - fixed wxTextCtrl::IsEditable() for GTK+ 2 +- fixed wxStaticText alignment for GTK+ 2 (Kevin Hock) - don't consume 100% CPU when showing a poup menu wxMac: diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 255ecb25f8..53fe9f98e5 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -22,6 +22,11 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +extern "C" +void wxgtk_window_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxWindow *win); + //----------------------------------------------------------------------------- // wxStaticText //----------------------------------------------------------------------------- @@ -87,6 +92,23 @@ bool wxStaticText::Create(wxWindow *parent, PostCreation(); + // the bug below only happens with GTK 2 +#ifdef __WXGTK20__ + if ( justify != GTK_JUSTIFY_LEFT ) + { + // if we let GTK call wxgtk_window_size_request_callback the label + // always shrinks to its minimal size for some reason and so no + // alignment except the default left doesn't work (in fact it does, + // but you don't see it) + gtk_signal_disconnect_by_func + ( + GTK_OBJECT(m_widget), + GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), + (gpointer) this + ); + } +#endif // __WXGTK20__ + ApplyWidgetStyle(); wxControl::SetFont( parent->GetFont() ); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 9f1d174de7..ee418a7c17 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -477,12 +477,18 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU // "size_request" of m_widget //----------------------------------------------------------------------------- -static void gtk_window_size_request_callback( GtkWidget *widget, GtkRequisition *requisition, wxWindow *win ) +// make it extern because wxStatitText needs to disconnect this one +extern "C" +void wxgtk_window_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxWindow *win) { - int w,h; + int w, h; win->GetSize( &w, &h ); - if (w < 2) w = 2; - if (h < 2) h = 2; + if (w < 2) + w = 2; + if (h < 2) + h = 2; requisition->height = h; requisition->width = w; @@ -2797,7 +2803,7 @@ void wxWindowGTK::PostCreation() GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } - if (!GTK_IS_COMBO(m_widget)) + if ( !GTK_IS_COMBO(m_widget)) { // This is needed if we want to add our windows into native // GTK control, such as the toolbar. With this callback, the @@ -2805,7 +2811,8 @@ void wxWindowGTK::PostCreation() // programmer). Sadly, it misbehaves for wxComboBox. FIXME // when moving to GTK 2.0. gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", - GTK_SIGNAL_FUNC(gtk_window_size_request_callback), (gpointer) this ); + GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), + (gpointer) this ); } m_hasVMT = TRUE; diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 255ecb25f8..53fe9f98e5 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -22,6 +22,11 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +extern "C" +void wxgtk_window_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxWindow *win); + //----------------------------------------------------------------------------- // wxStaticText //----------------------------------------------------------------------------- @@ -87,6 +92,23 @@ bool wxStaticText::Create(wxWindow *parent, PostCreation(); + // the bug below only happens with GTK 2 +#ifdef __WXGTK20__ + if ( justify != GTK_JUSTIFY_LEFT ) + { + // if we let GTK call wxgtk_window_size_request_callback the label + // always shrinks to its minimal size for some reason and so no + // alignment except the default left doesn't work (in fact it does, + // but you don't see it) + gtk_signal_disconnect_by_func + ( + GTK_OBJECT(m_widget), + GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), + (gpointer) this + ); + } +#endif // __WXGTK20__ + ApplyWidgetStyle(); wxControl::SetFont( parent->GetFont() ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 9f1d174de7..ee418a7c17 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -477,12 +477,18 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU // "size_request" of m_widget //----------------------------------------------------------------------------- -static void gtk_window_size_request_callback( GtkWidget *widget, GtkRequisition *requisition, wxWindow *win ) +// make it extern because wxStatitText needs to disconnect this one +extern "C" +void wxgtk_window_size_request_callback(GtkWidget *widget, + GtkRequisition *requisition, + wxWindow *win) { - int w,h; + int w, h; win->GetSize( &w, &h ); - if (w < 2) w = 2; - if (h < 2) h = 2; + if (w < 2) + w = 2; + if (h < 2) + h = 2; requisition->height = h; requisition->width = w; @@ -2797,7 +2803,7 @@ void wxWindowGTK::PostCreation() GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } - if (!GTK_IS_COMBO(m_widget)) + if ( !GTK_IS_COMBO(m_widget)) { // This is needed if we want to add our windows into native // GTK control, such as the toolbar. With this callback, the @@ -2805,7 +2811,8 @@ void wxWindowGTK::PostCreation() // programmer). Sadly, it misbehaves for wxComboBox. FIXME // when moving to GTK 2.0. gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", - GTK_SIGNAL_FUNC(gtk_window_size_request_callback), (gpointer) this ); + GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback), + (gpointer) this ); } m_hasVMT = TRUE; -- 2.45.2