]>
Commit | Line | Data |
---|---|---|
f033830e SC |
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 | ||
f033830e SC |
26 | #include "wx/osx/private.h" |
27 | ||
28 | #include <stdio.h> | |
29 | ||
f1c40652 | 30 | @interface wxNSStaticTextView : NSTextField |
c2a4d428 | 31 | { |
c2a4d428 | 32 | } |
c2a4d428 | 33 | @end |
f1c40652 | 34 | |
c2a4d428 KO |
35 | @implementation wxNSStaticTextView |
36 | ||
37 | + (void)initialize | |
38 | { | |
39 | static BOOL initialized = NO; | |
03647350 VZ |
40 | if (!initialized) |
41 | { | |
c2a4d428 KO |
42 | initialized = YES; |
43 | wxOSXCocoaClassAddWXMethods( self ); | |
44 | } | |
45 | } | |
46 | ||
c2a4d428 KO |
47 | @end |
48 | ||
a4e32492 KO |
49 | class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl |
50 | { | |
51 | public: | |
f1c40652 | 52 | wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w) |
a4e32492 | 53 | { |
f1c40652 | 54 | m_lineBreak = lineBreak; |
a4e32492 | 55 | } |
03647350 VZ |
56 | |
57 | virtual void SetLabel(const wxString& title, wxFontEncoding encoding) | |
58 | { | |
a4e32492 KO |
59 | wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); |
60 | wxWindow* wxpeer = GetWXPeer(); | |
f1c40652 | 61 | NSCell* cell = [v cell]; |
d8207702 | 62 | wxCFStringRef text( title , encoding ); |
f1c40652 SC |
63 | |
64 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
65 | [paragraphStyle setLineBreakMode:m_lineBreak]; | |
a4e32492 | 66 | int style = wxpeer->GetWindowStyleFlag(); |
a4e32492 | 67 | if (style & wxALIGN_CENTER) |
f1c40652 | 68 | [paragraphStyle setAlignment: NSCenterTextAlignment]; |
a4e32492 | 69 | else if (style & wxALIGN_RIGHT) |
f1c40652 | 70 | [paragraphStyle setAlignment: NSRightTextAlignment]; |
03647350 | 71 | |
f1c40652 SC |
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]; | |
a4e32492 | 77 | } |
f1c40652 SC |
78 | private : |
79 | NSLineBreakMode m_lineBreak; | |
a4e32492 | 80 | }; |
c2a4d428 | 81 | |
f033830e SC |
82 | wxSize wxStaticText::DoGetBestSize() const |
83 | { | |
f1c40652 | 84 | return wxWindowMac::DoGetBestSize() ; |
f033830e SC |
85 | } |
86 | ||
6e7a89af | 87 | wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, |
d8207702 SC |
88 | wxWindowMac* WXUNUSED(parent), |
89 | wxWindowID WXUNUSED(id), | |
90 | const wxString& WXUNUSED(label), | |
6e7a89af | 91 | const wxPoint& pos, |
f033830e | 92 | const wxSize& size, |
6e7a89af | 93 | long style, |
d8207702 | 94 | long WXUNUSED(extraStyle)) |
f033830e | 95 | { |
dbeddfb9 | 96 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
c2a4d428 | 97 | wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r]; |
f033830e | 98 | |
f033830e SC |
99 | [v setEditable:NO]; |
100 | [v setDrawsBackground:NO]; | |
44ca06dd | 101 | [v setSelectable: NO]; |
f1c40652 SC |
102 | [v setBezeled:NO]; |
103 | [v setBordered:NO]; | |
03647350 | 104 | |
f1c40652 SC |
105 | NSLineBreakMode linebreak = NSLineBreakByWordWrapping; |
106 | if ( ((wxStaticText*)wxpeer)->IsEllipsized() ) | |
f033830e | 107 | { |
f033830e | 108 | if ( style & wxST_ELLIPSIZE_MIDDLE ) |
f1c40652 SC |
109 | linebreak = NSLineBreakByTruncatingMiddle; |
110 | else if (style & wxST_ELLIPSIZE_END ) | |
111 | linebreak = NSLineBreakByTruncatingTail; | |
112 | else if (style & wxST_ELLIPSIZE_START ) | |
113 | linebreak = NSLineBreakByTruncatingHead; | |
f033830e | 114 | } |
03647350 | 115 | else |
f1c40652 SC |
116 | { |
117 | [[v cell] setWraps:YES]; | |
118 | } | |
03647350 | 119 | |
f1c40652 SC |
120 | wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak ); |
121 | return c; | |
f033830e SC |
122 | } |
123 | ||
124 | #endif //if wxUSE_STATTEXT |