From a4e3249255361245b5a4bc746e40374f2186439e Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Wed, 11 Mar 2009 04:50:51 +0000 Subject: [PATCH] Get SetLabel working again for wxStaticText by overriding SetLabel so that we can respect alignment. Also add a couple more sizing tweaks. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 2 +- src/osx/cocoa/stattext.mm | 45 ++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index d8ab539438..3fa6846c61 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -98,7 +98,7 @@ public : void SetDefaultButton( bool isDefault ); void PerformClick(); - void SetLabel(const wxString& title, wxFontEncoding encoding); + virtual void SetLabel(const wxString& title, wxFontEncoding encoding); void SetCursor( const wxCursor & cursor ); void CaptureMouse(); diff --git a/src/osx/cocoa/stattext.mm b/src/osx/cocoa/stattext.mm index 41840bcc08..d37673bc8c 100644 --- a/src/osx/cocoa/stattext.mm +++ b/src/osx/cocoa/stattext.mm @@ -58,11 +58,32 @@ } @end +class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl +{ +public: + wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w) + { + } + + virtual void SetLabel(const wxString& title, wxFontEncoding encoding) + { + wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); + wxWindow* wxpeer = GetWXPeer(); + [v setString: wxCFStringRef( title , wxpeer->GetFont().GetEncoding() ).AsNSString()]; + + int style = wxpeer->GetWindowStyleFlag(); + NSRange allText = NSMakeRange(0, title.length()); + if (style & wxALIGN_CENTER) + [v setAlignment: NSCenterTextAlignment range: allText]; + else if (style & wxALIGN_RIGHT) + [v setAlignment: NSRightTextAlignment range: allText]; + } +}; wxSize wxStaticText::DoGetBestSize() const { -Point bounds; - + Point bounds; + #if wxOSX_USE_ATSU_TEXT OSStatus err = noErr; wxCFStringRef str( m_label, GetFont().GetEncoding() ); @@ -81,13 +102,12 @@ Point bounds; wxClientDC dc(const_cast(this)); wxCoord width, height ; dc.GetMultiLineTextExtent( m_label , &width, &height); - // FIXME: Some labels seem to have their last characters - // stripped out. Adding 12 pixels seems to be enough to fix this. - // Perhaps m_label is not being synced properly... + // FIXME: The calculations returned by this function are too small + // for some strings, so we adjust manually. bounds.h = width+12; - bounds.v = height; + bounds.v = height+4; } - + if ( m_label.empty() ) bounds.h = 0; @@ -119,15 +139,8 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, [v setEditable:NO]; [v setDrawsBackground:NO]; [v setSelectable: NO]; - [v setString: wxCFStringRef( label , wxpeer->GetFont().GetEncoding() ).AsNSString()]; - - NSRange allText = NSMakeRange(0, label.length()); - if (style & wxALIGN_CENTER) - [v setAlignment: NSCenterTextAlignment range: allText]; - else if (style & wxALIGN_RIGHT) - [v setAlignment: NSRightTextAlignment range: allText]; - - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); + + wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v ); return c; /* Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); -- 2.45.2