]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/stattext.mm
Fix harmless unused parameter warnings in wxDEBUG_LEVEL==0 build.
[wxWidgets.git] / src / osx / cocoa / stattext.mm
index d37673bc8c38e15beadf8884e1bf502bc3acc657..42e5c85254923bb0df5e216ade0ae36beeec29e0 100644 (file)
 
 #include <stdio.h>
 
-@interface wxNSStaticTextView : NSTextView
+@interface wxNSStaticTextView : NSTextField
 {
-    wxWidgetCocoaImpl* impl;
 }
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item;
-- (wxWidgetCocoaImpl*) implementation;
 @end
+
 @implementation wxNSStaticTextView
 
 + (void)initialize
 {
     static BOOL initialized = NO;
-    if (!initialized) 
-    {    
+    if (!initialized)
+    {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (void) setImplementation:(wxWidgetCocoaImpl*) item
-{
-    impl = item;
-}
 @end
 
 class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
 {
 public:
-    wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
+    wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
     {
+        m_lineBreak = lineBreak;
     }
-    
-    virtual void SetLabel(const wxString& title, wxFontEncoding encoding) 
-    { 
+
+    virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
+    {
         wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
         wxWindow* wxpeer = GetWXPeer();
-        [v setString: wxCFStringRef( title , wxpeer->GetFont().GetEncoding() ).AsNSString()];
-    
+        NSCell* cell = [v cell];
+        wxCFStringRef text( title , encoding );
+
+        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
+        [paragraphStyle setLineBreakMode:m_lineBreak];
         int style = wxpeer->GetWindowStyleFlag();
-        NSRange allText = NSMakeRange(0, title.length());
         if (style & wxALIGN_CENTER)
-            [v setAlignment: NSCenterTextAlignment range: allText];
+            [paragraphStyle setAlignment: NSCenterTextAlignment];
         else if (style & wxALIGN_RIGHT)
-            [v setAlignment: NSRightTextAlignment range: allText];
+            [paragraphStyle setAlignment: NSRightTextAlignment];
+
+        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
+        NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
+        [cell setAttributedStringValue:attrstring];
+        [attrstring release];
+        [paragraphStyle release];
     }
+private :
+    NSLineBreakMode m_lineBreak;
 };
 
 wxSize wxStaticText::DoGetBestSize() const
 {
-    Point bounds;
-    
-#if wxOSX_USE_ATSU_TEXT
-    OSStatus err = noErr;
-    wxCFStringRef str( m_label,  GetFont().GetEncoding() );
-
-    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
-    {
-        wxClientDC dc(const_cast<wxStaticText*>(this));
-        wxCoord width, height ;
-        dc.GetMultiLineTextExtent( m_label , &width, &height);
-        // FIXME: The calculations returned by this function are too small
-        // for some strings, so we adjust manually.
-        bounds.h = width+12;
-        bounds.v = height+4;
-    }
-    
-    if ( m_label.empty() )
-        bounds.h = 0;
-
-    bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
-    bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
-
-    return wxSize( bounds.h, bounds.v );
+    return wxWindowMac::DoGetBestSize() ;
 }
 
-// for wxST_ELLIPSIZE_* support:
-
-/*
-   FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
-          to allow correct dynamic ellipsizing of the label
-*/
-
 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
-                                    wxWindowMac* parent,
-                                    wxWindowID id,
-                                    const wxString& label,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
+                                    const wxString& WXUNUSED(label),
                                     const wxPoint& pos,
                                     const wxSize& size,
                                     long style,
-                                    long extraStyle)
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
@@ -139,29 +99,26 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
     [v setEditable:NO];
     [v setDrawsBackground:NO];
     [v setSelectable: NO];
-            
-    wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v );
-    return c;
-/*
-    Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
+    [v setBezeled:NO];
+    [v setBordered:NO];
 
-    wxMacControl* peer = new wxMacControl( wxpeer );
-    OSStatus err = CreateStaticTextControl(
-        MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
-        &bounds, NULL, NULL, peer->GetControlRefAddr() );
-    verify_noerr( err );
-
-    if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
+    NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
+    if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
     {
-        TruncCode tCode = truncEnd;
         if ( style & wxST_ELLIPSIZE_MIDDLE )
-            tCode = truncMiddle;
-
-        err = peer->SetData( kControlStaticTextTruncTag, tCode );
-        err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
+            linebreak = NSLineBreakByTruncatingMiddle;
+        else if (style & wxST_ELLIPSIZE_END )
+            linebreak = NSLineBreakByTruncatingTail;
+        else if (style & wxST_ELLIPSIZE_START )
+            linebreak = NSLineBreakByTruncatingHead;
     }
-    return peer;
-    */
+    else
+    {
+        [[v cell] setWraps:YES];
+    }
+
+    wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
+    return c;
 }
 
 #endif //if wxUSE_STATTEXT