]> git.saurik.com Git - wxWidgets.git/commitdiff
Get SetLabel working again for wxStaticText by overriding SetLabel so that we can...
authorKevin Ollivier <kevino@theolliviers.com>
Wed, 11 Mar 2009 04:50:51 +0000 (04:50 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Wed, 11 Mar 2009 04:50:51 +0000 (04:50 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/private.h
src/osx/cocoa/stattext.mm

index d8ab5394384d7daf311b2d712100b272f08bbeb0..3fa6846c6165b16ed687f3ec6c7a90de206139b5 100644 (file)
@@ -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();
index 41840bcc08900f52a3f04c60fdcc1d2f9159771c..d37673bc8c38e15beadf8884e1bf502bc3acc657 100644 (file)
 }
 @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<wxStaticText*>(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 );