From a5040b80be64f5a5eea4066c5535ff4b4f018a83 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 7 Apr 2005 22:52:32 +0000 Subject: [PATCH] Implemented text wrapping for GTK (1.2 and 2.X). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33420 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/stattext.h | 4 ++++ include/wx/gtk1/stattext.h | 4 ++++ src/gtk/stattext.cpp | 32 +++++++++++++++++++++----------- src/gtk1/stattext.cpp | 32 +++++++++++++++++++++----------- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/include/wx/gtk/stattext.h b/include/wx/gtk/stattext.h index 6686c96982..fc7098928b 100644 --- a/include/wx/gtk/stattext.h +++ b/include/wx/gtk/stattext.h @@ -67,6 +67,10 @@ public: // -------------- protected: + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize() const; DECLARE_DYNAMIC_CLASS(wxStaticText) diff --git a/include/wx/gtk1/stattext.h b/include/wx/gtk1/stattext.h index 6686c96982..fc7098928b 100644 --- a/include/wx/gtk1/stattext.h +++ b/include/wx/gtk1/stattext.h @@ -67,6 +67,10 @@ public: // -------------- protected: + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize() const; DECLARE_DYNAMIC_CLASS(wxStaticText) diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 9b5aa5cb2f..da7039c8ed 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -85,8 +85,10 @@ bool wxStaticText::Create(wxWindow *parent, static const float labelAlignments[] = { 0.0, 1.0, 0.5 }; gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0); - // do not move this call elsewhere - gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); + if (size.x == -1) + gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); + else + gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); m_parent->DoAddChild( this ); @@ -168,24 +170,32 @@ bool wxStaticText::SetFont( const wxFont &font ) return ret; } +void wxStaticText::DoSetSize(int x, int y, + int width, int height, + int sizeFlags ) +{ + wxControl::DoSetSize( x, y, width, height, sizeFlags ); +} + wxSize wxStaticText::DoGetBestSize() const { // Do not return any arbitrary default value... wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") ); - // this invalidates the size request - gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); - gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); - + int width = m_width; +#ifndef __WXGTK20__ + gtk_label_set_pattern( GTK_LABEL(m_widget), NULL ); + if (width < 3) width = -1; +#endif + gtk_widget_set_usize( m_widget, width, -1 ); + GtkRequisition req; - req.width = 2; - req.height = 2; + req.width = -1; + req.height = -1; (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req ); - wxSize best(req.width, req.height); - CacheBestSize(best); - return best; + return wxSize (req.width, req.height); } bool wxStaticText::SetForegroundColour(const wxColour& colour) diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 9b5aa5cb2f..da7039c8ed 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -85,8 +85,10 @@ bool wxStaticText::Create(wxWindow *parent, static const float labelAlignments[] = { 0.0, 1.0, 0.5 }; gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0); - // do not move this call elsewhere - gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); + if (size.x == -1) + gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); + else + gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); m_parent->DoAddChild( this ); @@ -168,24 +170,32 @@ bool wxStaticText::SetFont( const wxFont &font ) return ret; } +void wxStaticText::DoSetSize(int x, int y, + int width, int height, + int sizeFlags ) +{ + wxControl::DoSetSize( x, y, width, height, sizeFlags ); +} + wxSize wxStaticText::DoGetBestSize() const { // Do not return any arbitrary default value... wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") ); - // this invalidates the size request - gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); - gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); - + int width = m_width; +#ifndef __WXGTK20__ + gtk_label_set_pattern( GTK_LABEL(m_widget), NULL ); + if (width < 3) width = -1; +#endif + gtk_widget_set_usize( m_widget, width, -1 ); + GtkRequisition req; - req.width = 2; - req.height = 2; + req.width = -1; + req.height = -1; (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req ); - wxSize best(req.width, req.height); - CacheBestSize(best); - return best; + return wxSize (req.width, req.height); } bool wxStaticText::SetForegroundColour(const wxColour& colour) -- 2.47.2