X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03647350fc7cd141953c72e0284e928847d30f44..da6f998486f1070e205f2e0a54f22a1b67cb32a4:/src/osx/cocoa/stattext.mm?ds=inline diff --git a/src/osx/cocoa/stattext.mm b/src/osx/cocoa/stattext.mm index b9f812e308..832b319017 100644 --- a/src/osx/cocoa/stattext.mm +++ b/src/osx/cocoa/stattext.mm @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 04/01/98 -// RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,11 +24,14 @@ #include "wx/osx/private.h" +#if wxUSE_MARKUP + #include "wx/osx/cocoa/private/markuptoattr.h" +#endif // wxUSE_MARKUP + #include @interface wxNSStaticTextView : NSTextField { - wxWidgetCocoaImpl* impl; } @end @@ -45,6 +47,25 @@ } } +- (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 @@ -57,26 +78,42 @@ public: virtual void SetLabel(const wxString& title, wxFontEncoding encoding) { - wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); - wxWindow* wxpeer = GetWXPeer(); - NSCell* cell = [v cell]; 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; };