]>
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 | ||
c2a4d428 KO |
30 | @interface wxNSStaticTextView : NSTextView |
31 | { | |
32 | wxWidgetCocoaImpl* impl; | |
33 | } | |
34 | ||
35 | - (void) setImplementation:(wxWidgetCocoaImpl*) item; | |
36 | - (wxWidgetCocoaImpl*) implementation; | |
37 | @end | |
38 | @implementation wxNSStaticTextView | |
39 | ||
40 | + (void)initialize | |
41 | { | |
42 | static BOOL initialized = NO; | |
43 | if (!initialized) | |
44 | { | |
45 | initialized = YES; | |
46 | wxOSXCocoaClassAddWXMethods( self ); | |
47 | } | |
48 | } | |
49 | ||
50 | - (wxWidgetCocoaImpl*) implementation | |
51 | { | |
52 | return impl; | |
53 | } | |
54 | ||
55 | - (void) setImplementation:(wxWidgetCocoaImpl*) item | |
56 | { | |
57 | impl = item; | |
58 | } | |
59 | @end | |
60 | ||
a4e32492 KO |
61 | class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl |
62 | { | |
63 | public: | |
64 | wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w) | |
65 | { | |
66 | } | |
67 | ||
68 | virtual void SetLabel(const wxString& title, wxFontEncoding encoding) | |
69 | { | |
70 | wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); | |
71 | wxWindow* wxpeer = GetWXPeer(); | |
72 | [v setString: wxCFStringRef( title , wxpeer->GetFont().GetEncoding() ).AsNSString()]; | |
73 | ||
74 | int style = wxpeer->GetWindowStyleFlag(); | |
75 | NSRange allText = NSMakeRange(0, title.length()); | |
76 | if (style & wxALIGN_CENTER) | |
77 | [v setAlignment: NSCenterTextAlignment range: allText]; | |
78 | else if (style & wxALIGN_RIGHT) | |
79 | [v setAlignment: NSRightTextAlignment range: allText]; | |
80 | } | |
81 | }; | |
c2a4d428 | 82 | |
f033830e SC |
83 | wxSize wxStaticText::DoGetBestSize() const |
84 | { | |
a4e32492 KO |
85 | Point bounds; |
86 | ||
4850cc8b SC |
87 | #if wxOSX_USE_ATSU_TEXT |
88 | OSStatus err = noErr; | |
89 | wxCFStringRef str( m_label, GetFont().GetEncoding() ); | |
90 | ||
91 | SInt16 baseline; | |
92 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
f033830e | 93 | { |
4850cc8b SC |
94 | err = GetThemeTextDimensions( |
95 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
96 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
97 | verify_noerr( err ); | |
f033830e SC |
98 | } |
99 | else | |
100 | #endif | |
101 | { | |
4850cc8b SC |
102 | wxClientDC dc(const_cast<wxStaticText*>(this)); |
103 | wxCoord width, height ; | |
16747764 | 104 | dc.GetMultiLineTextExtent( m_label , &width, &height); |
a4e32492 KO |
105 | // FIXME: The calculations returned by this function are too small |
106 | // for some strings, so we adjust manually. | |
c2a4d428 | 107 | bounds.h = width+12; |
a4e32492 | 108 | bounds.v = height+4; |
4850cc8b | 109 | } |
a4e32492 | 110 | |
4850cc8b SC |
111 | if ( m_label.empty() ) |
112 | bounds.h = 0; | |
f033830e | 113 | |
f033830e SC |
114 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); |
115 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
116 | ||
117 | return wxSize( bounds.h, bounds.v ); | |
118 | } | |
119 | ||
120 | // for wxST_ELLIPSIZE_* support: | |
121 | ||
122 | /* | |
123 | FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set | |
124 | to allow correct dynamic ellipsizing of the label | |
125 | */ | |
126 | ||
6e7a89af FM |
127 | wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, |
128 | wxWindowMac* parent, | |
129 | wxWindowID id, | |
f033830e | 130 | const wxString& label, |
6e7a89af | 131 | const wxPoint& pos, |
f033830e | 132 | const wxSize& size, |
6e7a89af FM |
133 | long style, |
134 | long extraStyle) | |
f033830e | 135 | { |
dbeddfb9 | 136 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; |
c2a4d428 | 137 | wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r]; |
f033830e | 138 | |
f033830e SC |
139 | [v setEditable:NO]; |
140 | [v setDrawsBackground:NO]; | |
44ca06dd | 141 | [v setSelectable: NO]; |
a4e32492 KO |
142 | |
143 | wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v ); | |
f033830e SC |
144 | return c; |
145 | /* | |
146 | Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); | |
147 | ||
148 | wxMacControl* peer = new wxMacControl( wxpeer ); | |
149 | OSStatus err = CreateStaticTextControl( | |
150 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
151 | &bounds, NULL, NULL, peer->GetControlRefAddr() ); | |
152 | verify_noerr( err ); | |
153 | ||
154 | if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) | |
155 | { | |
156 | TruncCode tCode = truncEnd; | |
157 | if ( style & wxST_ELLIPSIZE_MIDDLE ) | |
158 | tCode = truncMiddle; | |
159 | ||
160 | err = peer->SetData( kControlStaticTextTruncTag, tCode ); | |
161 | err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
162 | } | |
163 | return peer; | |
164 | */ | |
165 | } | |
166 | ||
167 | #endif //if wxUSE_STATTEXT |