]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/stattext.mm
fixing class
[wxWidgets.git] / src / osx / cocoa / stattext.mm
index 0ec3ff70c3bddf75676bc776f0a15d2d3b110aae..591a97a4764a1e9fb6475d751d498891409745dd 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     04/01/98
-// RCS-ID:      $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/osx/private.h"
 
+#if wxUSE_MARKUP
+    #include "wx/osx/cocoa/private/markuptoattr.h"
+#endif // wxUSE_MARKUP
+
 #include <stdio.h>
 
 @interface wxNSStaticTextView : NSTextField
 {
-    wxWidgetCocoaImpl* impl;
 }
 @end
 
 + (void)initialize
 {
     static BOOL initialized = NO;
-    if (!initialized) 
-    {    
+    if (!initialized)
+    {
         initialized = YES;
         wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
+- (void) setEnabled:(BOOL) flag 
+{ 
+    [super setEnabled: flag]; 
+    
+    if (![self drawsBackground]) { 
+        // Static text is drawn incorrectly when disabled. 
+        // For an explanation, see 
+        // http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168028 
+        if (flag)
+        { 
+            [self setTextColor: [NSColor controlTextColor]]; 
+        }
+        else 
+        { 
+            [self setTextColor: [NSColor secondarySelectedControlColor]]; 
+        } 
+    } 
+} 
+
 @end
 
 class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
@@ -54,29 +76,45 @@ public:
     {
         m_lineBreak = lineBreak;
     }
-    
-    virtual void SetLabel(const wxString& title, wxFontEncoding encoding) 
-    { 
-        wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
-        wxWindow* wxpeer = GetWXPeer();
-        NSCell* cell = [v cell];
-        wxCFStringRef text( title , wxpeer->GetFont().GetEncoding() );
 
+    virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
+    {
+        wxCFStringRef text( title , encoding );
+
+        NSMutableAttributedString *
+            attrstring = [[NSMutableAttributedString alloc] initWithString:text.AsNSString()];
+        DoSetAttrString(attrstring);
+        [attrstring release];
+    }
+
+#if wxUSE_MARKUP
+    virtual void SetLabelMarkup( const wxString& markup)
+    {
+        wxMarkupToAttrString toAttr(GetWXPeer(), markup);
+
+        DoSetAttrString(toAttr.GetNSAttributedString());
+    }
+#endif // wxUSE_MARKUP
+
+private:
+    void DoSetAttrString(NSMutableAttributedString *attrstring)
+    {
         NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
         [paragraphStyle setLineBreakMode:m_lineBreak];
-        int style = wxpeer->GetWindowStyleFlag();
-        if (style & wxALIGN_CENTER)
+        int style = GetWXPeer()->GetWindowStyleFlag();
+        if (style & wxALIGN_CENTER_HORIZONTAL)
             [paragraphStyle setAlignment: NSCenterTextAlignment];
         else if (style & wxALIGN_RIGHT)
             [paragraphStyle setAlignment: NSRightTextAlignment];
-    
-        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
-        NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
+
+        [attrstring addAttribute:NSParagraphStyleAttributeName
+                    value:paragraphStyle
+                    range:NSMakeRange(0, [attrstring length])];
+        NSCell* cell = [(wxNSStaticTextView *)GetWXWidget() cell];
         [cell setAttributedStringValue:attrstring];
-        [attrstring release];
         [paragraphStyle release];
     }
-private :
+
     NSLineBreakMode m_lineBreak;
 };
 
@@ -86,13 +124,13 @@ wxSize wxStaticText::DoGetBestSize() const
 }
 
 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];
@@ -102,7 +140,7 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
     [v setSelectable: NO];
     [v setBezeled:NO];
     [v setBordered:NO];
-    
+
     NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
     if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
     {
@@ -113,11 +151,11 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
         else if (style & wxST_ELLIPSIZE_START )
             linebreak = NSLineBreakByTruncatingHead;
     }
-    else 
+    else
     {
         [[v cell] setWraps:YES];
     }
-            
+
     wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
     return c;
 }