1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/stattext.mm
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/stattext.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
26 #include "wx/osx/private.h"
30 @interface wxNSStaticTextView : NSTextField
35 @implementation wxNSStaticTextView
39 static BOOL initialized = NO;
43 wxOSXCocoaClassAddWXMethods( self );
49 class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
52 wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
54 m_lineBreak = lineBreak;
57 virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
59 wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
60 wxWindow* wxpeer = GetWXPeer();
61 NSCell* cell = [v cell];
62 wxCFStringRef text( title , encoding );
64 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
65 [paragraphStyle setLineBreakMode:m_lineBreak];
66 int style = wxpeer->GetWindowStyleFlag();
67 if (style & wxALIGN_CENTER)
68 [paragraphStyle setAlignment: NSCenterTextAlignment];
69 else if (style & wxALIGN_RIGHT)
70 [paragraphStyle setAlignment: NSRightTextAlignment];
72 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
73 NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
74 [cell setAttributedStringValue:attrstring];
76 [paragraphStyle release];
79 NSLineBreakMode m_lineBreak;
82 wxSize wxStaticText::DoGetBestSize() const
84 return wxWindowMac::DoGetBestSize() ;
87 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
88 wxWindowMac* WXUNUSED(parent),
89 wxWindowID WXUNUSED(id),
90 const wxString& WXUNUSED(label),
94 long WXUNUSED(extraStyle))
96 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
97 wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
100 [v setDrawsBackground:NO];
101 [v setSelectable: NO];
105 NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
106 if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
108 if ( style & wxST_ELLIPSIZE_MIDDLE )
109 linebreak = NSLineBreakByTruncatingMiddle;
110 else if (style & wxST_ELLIPSIZE_END )
111 linebreak = NSLineBreakByTruncatingTail;
112 else if (style & wxST_ELLIPSIZE_START )
113 linebreak = NSLineBreakByTruncatingHead;
117 [[v cell] setWraps:YES];
120 wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
124 #endif //if wxUSE_STATTEXT