]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/stattext.mm
Correct format specifiers used to show wxIPV4address.
[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 }
33 @end
34
35 @implementation wxNSStaticTextView
36
37 + (void)initialize
38 {
39 static BOOL initialized = NO;
40 if (!initialized)
41 {
42 initialized = YES;
43 wxOSXCocoaClassAddWXMethods( self );
44 }
45 }
46
47 @end
48
49 class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
50 {
51 public:
52 wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
53 {
54 m_lineBreak = lineBreak;
55 }
56
57 virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
58 {
59 wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
60 wxWindow* wxpeer = GetWXPeer();
61 NSCell* cell = [v cell];
62 wxCFStringRef text( title , encoding );
63
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];
71
72 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
73 NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
74 [cell setAttributedStringValue:attrstring];
75 [attrstring release];
76 [paragraphStyle release];
77 }
78 private :
79 NSLineBreakMode m_lineBreak;
80 };
81
82 wxSize wxStaticText::DoGetBestSize() const
83 {
84 return wxWindowMac::DoGetBestSize() ;
85 }
86
87 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
88 wxWindowMac* WXUNUSED(parent),
89 wxWindowID WXUNUSED(id),
90 const wxString& WXUNUSED(label),
91 const wxPoint& pos,
92 const wxSize& size,
93 long style,
94 long WXUNUSED(extraStyle))
95 {
96 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
97 wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
98
99 [v setEditable:NO];
100 [v setDrawsBackground:NO];
101 [v setSelectable: NO];
102 [v setBezeled:NO];
103 [v setBordered:NO];
104
105 NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
106 if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
107 {
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;
114 }
115 else
116 {
117 [[v cell] setWraps:YES];
118 }
119
120 wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
121 return c;
122 }
123
124 #endif //if wxUSE_STATTEXT