]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/stattext.mm
Fixed bug: wxPropertyGridInterface::SetPropertyReadOnly() with wxPG_DONT_RECURSE...
[wxWidgets.git] / src / osx / cocoa / stattext.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/stattext.mm
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_STATTEXT
15
16 #include "wx/stattext.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/osx/private.h"
27
28 #include <stdio.h>
29
30 @interface wxNSStaticTextView : NSTextField
31 {
32 wxWidgetCocoaImpl* impl;
33 }
34 @end
35
36 @implementation wxNSStaticTextView
37
38 + (void)initialize
39 {
40 static BOOL initialized = NO;
41 if (!initialized)
42 {
43 initialized = YES;
44 wxOSXCocoaClassAddWXMethods( self );
45 }
46 }
47
48 @end
49
50 class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
51 {
52 public:
53 wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
54 {
55 m_lineBreak = lineBreak;
56 }
57
58 virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
59 {
60 wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
61 wxWindow* wxpeer = GetWXPeer();
62 NSCell* cell = [v cell];
63 wxCFStringRef text( title , encoding );
64
65 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
66 [paragraphStyle setLineBreakMode:m_lineBreak];
67 int style = wxpeer->GetWindowStyleFlag();
68 if (style & wxALIGN_CENTER)
69 [paragraphStyle setAlignment: NSCenterTextAlignment];
70 else if (style & wxALIGN_RIGHT)
71 [paragraphStyle setAlignment: NSRightTextAlignment];
72
73 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
74 NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
75 [cell setAttributedStringValue:attrstring];
76 [attrstring release];
77 [paragraphStyle release];
78 }
79 private :
80 NSLineBreakMode m_lineBreak;
81 };
82
83 wxSize wxStaticText::DoGetBestSize() const
84 {
85 return wxWindowMac::DoGetBestSize() ;
86 }
87
88 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
89 wxWindowMac* WXUNUSED(parent),
90 wxWindowID WXUNUSED(id),
91 const wxString& WXUNUSED(label),
92 const wxPoint& pos,
93 const wxSize& size,
94 long style,
95 long WXUNUSED(extraStyle))
96 {
97 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
98 wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
99
100 [v setEditable:NO];
101 [v setDrawsBackground:NO];
102 [v setSelectable: NO];
103 [v setBezeled:NO];
104 [v setBordered:NO];
105
106 NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
107 if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
108 {
109 if ( style & wxST_ELLIPSIZE_MIDDLE )
110 linebreak = NSLineBreakByTruncatingMiddle;
111 else if (style & wxST_ELLIPSIZE_END )
112 linebreak = NSLineBreakByTruncatingTail;
113 else if (style & wxST_ELLIPSIZE_START )
114 linebreak = NSLineBreakByTruncatingHead;
115 }
116 else
117 {
118 [[v cell] setWraps:YES];
119 }
120
121 wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
122 return c;
123 }
124
125 #endif //if wxUSE_STATTEXT