]>
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 | ||
8f5bce64 SC |
47 | - (void) setEnabled:(BOOL) flag |
48 | { | |
49 | [super setEnabled: flag]; | |
50 | ||
51 | if (![self drawsBackground]) { | |
52 | // Static text is drawn incorrectly when disabled. | |
53 | // For an explanation, see | |
54 | // http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168028 | |
55 | if (flag) | |
56 | { | |
57 | [self setTextColor: [NSColor controlTextColor]]; | |
58 | } | |
59 | else | |
60 | { | |
61 | [self setTextColor: [NSColor secondarySelectedControlColor]]; | |
62 | } | |
63 | } | |
64 | } | |
65 | ||
c2a4d428 KO |
66 | @end |
67 | ||
a4e32492 KO |
68 | class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl |
69 | { | |
70 | public: | |
f1c40652 | 71 | wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w) |
a4e32492 | 72 | { |
f1c40652 | 73 | m_lineBreak = lineBreak; |
a4e32492 | 74 | } |
03647350 VZ |
75 | |
76 | virtual void SetLabel(const wxString& title, wxFontEncoding encoding) | |
77 | { | |
a4e32492 KO |
78 | wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); |
79 | wxWindow* wxpeer = GetWXPeer(); | |
f1c40652 | 80 | NSCell* cell = [v cell]; |
d8207702 | 81 | wxCFStringRef text( title , encoding ); |
f1c40652 SC |
82 | |
83 | NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
84 | [paragraphStyle setLineBreakMode:m_lineBreak]; | |
a4e32492 | 85 | int style = wxpeer->GetWindowStyleFlag(); |
a4e32492 | 86 | if (style & wxALIGN_CENTER) |
f1c40652 | 87 | [paragraphStyle setAlignment: NSCenterTextAlignment]; |
a4e32492 | 88 | else if (style & wxALIGN_RIGHT) |
f1c40652 | 89 | [paragraphStyle setAlignment: NSRightTextAlignment]; |
03647350 | 90 | |
f1c40652 SC |
91 | NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil]; |
92 | NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict]; | |
93 | [cell setAttributedStringValue:attrstring]; | |
94 | [attrstring release]; | |
95 | [paragraphStyle release]; | |
a4e32492 | 96 | } |
f1c40652 SC |
97 | private : |
98 | NSLineBreakMode m_lineBreak; | |
a4e32492 | 99 | }; |
c2a4d428 | 100 | |
f033830e SC |
101 | wxSize wxStaticText::DoGetBestSize() const |
102 | { | |
f1c40652 | 103 | return wxWindowMac::DoGetBestSize() ; |
f033830e SC |
104 | } |
105 | ||
6e7a89af | 106 | wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, |
d8207702 SC |
107 | wxWindowMac* WXUNUSED(parent), |
108 | wxWindowID WXUNUSED(id), | |
109 | const wxString& WXUNUSED(label), | |
6e7a89af | 110 | const wxPoint& pos, |
f033830e | 111 | const wxSize& size, |
6e7a89af | 112 | long style, |
d8207702 | 113 | long WXUNUSED(extraStyle)) |
f033830e | 114 | { |
dbeddfb9 | 115 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
c2a4d428 | 116 | wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r]; |
f033830e | 117 | |
f033830e SC |
118 | [v setEditable:NO]; |
119 | [v setDrawsBackground:NO]; | |
44ca06dd | 120 | [v setSelectable: NO]; |
f1c40652 SC |
121 | [v setBezeled:NO]; |
122 | [v setBordered:NO]; | |
03647350 | 123 | |
f1c40652 SC |
124 | NSLineBreakMode linebreak = NSLineBreakByWordWrapping; |
125 | if ( ((wxStaticText*)wxpeer)->IsEllipsized() ) | |
f033830e | 126 | { |
f033830e | 127 | if ( style & wxST_ELLIPSIZE_MIDDLE ) |
f1c40652 SC |
128 | linebreak = NSLineBreakByTruncatingMiddle; |
129 | else if (style & wxST_ELLIPSIZE_END ) | |
130 | linebreak = NSLineBreakByTruncatingTail; | |
131 | else if (style & wxST_ELLIPSIZE_START ) | |
132 | linebreak = NSLineBreakByTruncatingHead; | |
f033830e | 133 | } |
03647350 | 134 | else |
f1c40652 SC |
135 | { |
136 | [[v cell] setWraps:YES]; | |
137 | } | |
03647350 | 138 | |
f1c40652 SC |
139 | wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak ); |
140 | return c; | |
f033830e SC |
141 | } |
142 | ||
143 | #endif //if wxUSE_STATTEXT |