]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/stattext.cpp |
489468fe SC |
3 | // Purpose: wxStaticText |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
489468fe SC |
7 | // Copyright: (c) Stefan Csomor |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if wxUSE_STATTEXT | |
14 | ||
15 | #include "wx/stattext.h" | |
16 | ||
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/app.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/dc.h" | |
21 | #include "wx/dcclient.h" | |
22 | #include "wx/settings.h" | |
23 | #endif // WX_PRECOMP | |
24 | ||
524c47aa | 25 | #include "wx/osx/private.h" |
489468fe SC |
26 | |
27 | #include <stdio.h> | |
28 | ||
524c47aa | 29 | class wxMacStaticText : public wxMacControl |
489468fe | 30 | { |
524c47aa SC |
31 | public: |
32 | wxMacStaticText( wxWindowMac* peer ) : wxMacControl(peer) | |
489468fe | 33 | { |
489468fe | 34 | } |
524c47aa SC |
35 | void SetLabel(const wxString& title, wxFontEncoding encoding) |
36 | { | |
37 | wxCFStringRef str( title, encoding ); | |
38 | OSStatus err = SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str); | |
39 | verify_noerr( err ); | |
40 | } | |
41 | }; | |
489468fe SC |
42 | |
43 | wxSize wxStaticText::DoGetBestSize() const | |
44 | { | |
489468fe | 45 | Point bounds; |
524c47aa SC |
46 | #if wxOSX_USE_CARBON |
47 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
489468fe SC |
48 | |
49 | // try the built-in best size if available | |
22756322 SC |
50 | Boolean former = GetPeer()->GetData<Boolean>( kControlStaticTextIsMultilineTag); |
51 | GetPeer()->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
52 | GetPeer()->GetBestRect( &bestsize ) ; | |
53 | GetPeer()->SetData( kControlStaticTextIsMultilineTag, former ); | |
d15694e8 | 54 | |
489468fe SC |
55 | if ( !EmptyRect( &bestsize ) ) |
56 | { | |
57 | bounds.h = bestsize.right - bestsize.left ; | |
58 | bounds.v = bestsize.bottom - bestsize.top ; | |
59 | } | |
60 | else | |
524c47aa | 61 | #endif |
489468fe | 62 | { |
524c47aa | 63 | #if wxOSX_USE_CARBON |
489468fe | 64 | ControlFontStyleRec controlFont; |
22756322 | 65 | OSStatus err = GetPeer()->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); |
489468fe SC |
66 | verify_noerr( err ); |
67 | ||
292e5e1f | 68 | #if wxOSX_USE_ATSU_TEXT |
489468fe SC |
69 | SInt16 baseline; |
70 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
71 | { | |
03647350 VZ |
72 | // GetThemeTextDimensions will cache strings and the documentation |
73 | // says not to use the NoCopy string creation calls. | |
74 | // This also means that we can't use CFSTR without | |
75 | // -fno-constant-cfstrings if the library might be unloaded, | |
76 | // as GetThemeTextDimensions may cache a pointer to our | |
77 | // unloaded segment. | |
78 | wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "), | |
6fd21e16 | 79 | GetFont().GetEncoding() ); |
03647350 | 80 | |
489468fe | 81 | err = GetThemeTextDimensions( |
6fd21e16 | 82 | (CFStringRef)str, |
489468fe SC |
83 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); |
84 | verify_noerr( err ); | |
85 | } | |
86 | else | |
524c47aa | 87 | #endif |
489468fe SC |
88 | #endif |
89 | { | |
90 | wxClientDC dc(const_cast<wxStaticText*>(this)); | |
91 | wxCoord width, height ; | |
92 | dc.GetTextExtent( m_label , &width, &height); | |
93 | bounds.h = width; | |
94 | bounds.v = height; | |
95 | } | |
96 | ||
97 | if ( m_label.empty() ) | |
98 | bounds.h = 0; | |
99 | } | |
100 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
101 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
102 | ||
103 | return wxSize( bounds.h, bounds.v ); | |
104 | } | |
105 | ||
524c47aa SC |
106 | /* |
107 | FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set | |
108 | to allow correct dynamic ellipsizing of the label | |
109 | */ | |
489468fe | 110 | |
6e7a89af FM |
111 | wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, |
112 | wxWindowMac* parent, | |
a4fec5b4 SC |
113 | wxWindowID WXUNUSED(id), |
114 | const wxString& WXUNUSED(label), | |
6e7a89af | 115 | const wxPoint& pos, |
524c47aa | 116 | const wxSize& size, |
6e7a89af | 117 | long style, |
a4fec5b4 | 118 | long WXUNUSED(extraStyle)) |
524c47aa SC |
119 | { |
120 | Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); | |
489468fe | 121 | |
524c47aa SC |
122 | wxMacControl* peer = new wxMacStaticText( wxpeer ); |
123 | OSStatus err = CreateStaticTextControl( | |
124 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
125 | &bounds, NULL, NULL, peer->GetControlRefAddr() ); | |
126 | verify_noerr( err ); | |
489468fe | 127 | |
524c47aa | 128 | if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) |
489468fe | 129 | { |
524c47aa SC |
130 | TruncCode tCode = truncEnd; |
131 | if ( style & wxST_ELLIPSIZE_MIDDLE ) | |
132 | tCode = truncMiddle; | |
489468fe | 133 | |
524c47aa SC |
134 | err = peer->SetData( kControlStaticTextTruncTag, tCode ); |
135 | err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
489468fe | 136 | } |
524c47aa | 137 | return peer; |
489468fe SC |
138 | } |
139 | ||
489468fe | 140 | #endif //if wxUSE_STATTEXT |