]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/stattext.mm
Border styles create a double-border on native search ctrl, just use the one Apple...
[wxWidgets.git] / src / osx / cocoa / stattext.mm
index f35aebba813be85b83d37de2aef2b9fe50df97f9..41840bcc08900f52a3f04c60fdcc1d2f9159771c 100644 (file)
     #include "wx/settings.h"
 #endif // WX_PRECOMP
 
-#include "wx/notebook.h"
-#include "wx/tabctrl.h"
-
 #include "wx/osx/private.h"
 
 #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;
-#if wxOSX_USE_CARBON
-    Rect bestsize = { 0 , 0 , 0 , 0 } ;
-
-    // try the built-in best size if available
-    Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
-    m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
-    m_peer->GetBestRect( &bestsize ) ;
-    m_peer->SetData( kControlStaticTextIsMultilineTag, former );
-    if ( !EmptyRect( &bestsize ) )
+Point bounds;
+
+#if wxOSX_USE_ATSU_TEXT
+    OSStatus err = noErr;
+    wxCFStringRef str( m_label,  GetFont().GetEncoding() );
+
+    SInt16 baseline;
+    if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
     {
-        bounds.h = bestsize.right - bestsize.left ;
-        bounds.v = bestsize.bottom - bestsize.top ;
+        err = GetThemeTextDimensions(
+            (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
+            m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
+        verify_noerr( err );
     }
     else
 #endif
     {
-#if wxOSX_USE_CARBON
-        ControlFontStyleRec controlFont;
-        OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
-        verify_noerr( err );
+        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...
+        bounds.h = width+12;
+        bounds.v = height;
+    }
 
-        wxCFStringRef str( m_label,  GetFont().GetEncoding() );
+    if ( m_label.empty() )
+        bounds.h = 0;
 
-#if wxOSX_USE_ATSU_TEXT
-        SInt16 baseline;
-        if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
-        {
-            err = GetThemeTextDimensions(
-                (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
-                m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
-            verify_noerr( err );
-        }
-        else
-#endif
-#endif
-        {
-            wxClientDC dc(const_cast<wxStaticText*>(this));
-            wxCoord width, height ;
-            dc.GetTextExtent( m_label , &width, &height);
-            bounds.h = width;
-            bounds.v = height;
-        }
-
-        if ( m_label.empty() )
-            bounds.h = 0;
-    }
     bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
     bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
 
@@ -92,65 +104,30 @@ wxSize wxStaticText::DoGetBestSize() const
           to allow correct dynamic ellipsizing of the label
 */
 
-@interface wxNSTextField : NSTextField
-{
-    wxWidgetImpl* m_impl;
-}
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
-
-@end
-
-@implementation wxNSTextField
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
-{
-    m_impl = theImplementation;
-}
-
-- (wxWidgetImpl*) implementation
-{
-    return m_impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
-
-// use our common calls
-- (void) setTitle:(NSString *) title
-{
-    [self setStringValue: title];
-}
-
-@end
-
-
-wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, 
-                                    wxWindowMac* parent, 
-                                    wxWindowID id, 
+wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
+                                    wxWindowMac* parent,
+                                    wxWindowID id,
                                     const wxString& label,
-                                    const wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStyle) 
+                                    long style,
+                                    long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
-    NSRect r = wxToNSRect( sv, wxRect( pos, size) );
-    // Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
-    wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
-    [sv addSubview:v];
+    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
+    wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
 
-    [v setBezeled:NO];
     [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 );
-    [v setImplementation:c];
     return c;
 /*
     Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );