]> git.saurik.com Git - wxWidgets.git/commitdiff
Add alignment support, and more tweaks for label size issues, though I hope to find...
authorKevin Ollivier <kevino@theolliviers.com>
Sat, 7 Mar 2009 04:19:26 +0000 (04:19 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Sat, 7 Mar 2009 04:19:26 +0000 (04:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59399 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/stattext.mm

index 9134d2ef7960f8a9bc9846e72d93a53bad679744..74e3aad2f6806e92ac2608b04fae3108b9b74aaa 100644 (file)
 
 #include <stdio.h>
 
+@interface wxNSStaticTextView : NSTextView
+{
+    wxWidgetCocoaImpl* impl;
+}
+
+- (void) setImplementation:(wxWidgetCocoaImpl*) item;
+- (wxWidgetCocoaImpl*) implementation;
+@end
+@implementation wxNSStaticTextView
+
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {    
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
+
+- (wxWidgetCocoaImpl*) implementation
+{
+    return impl;
+}
+
+- (void) setImplementation:(wxWidgetCocoaImpl*) item
+{
+    impl = item;
+}
+@end
+
+
 wxSize wxStaticText::DoGetBestSize() const
 {
 Point bounds;
@@ -49,9 +81,10 @@ Point bounds;
         wxClientDC dc(const_cast<wxStaticText*>(this));
         wxCoord width, height ;
         dc.GetMultiLineTextExtent( m_label , &width, &height);
-        // Some labels seem to have their last characters
-        // stripped out.  Adding 4 pixels seems to be enough to fix this.
-        bounds.h = width+4;
+        // 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...
+        bounds.h = width+12;
         bounds.v = height;
     }
 
@@ -81,11 +114,17 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
                                     long extraStyle)
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
-    wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
+    wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
 
-    [v setBezeled:NO];
     [v setEditable:NO];
     [v setDrawsBackground: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 );
     return c;