]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
a074f61e | 2 | // Name: src/mac/carbon/stattext.cpp |
e9576ca5 | 3 | // Purpose: wxStaticText |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
c545950d RN |
14 | #if wxUSE_STATTEXT |
15 | ||
e9576ca5 | 16 | #include "wx/stattext.h" |
670f9935 WS |
17 | |
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/app.h" | |
de6185e2 | 20 | #include "wx/utils.h" |
da80ae71 | 21 | #include "wx/dc.h" |
ed4b0fdc | 22 | #include "wx/dcclient.h" |
9eddec69 | 23 | #include "wx/settings.h" |
670f9935 WS |
24 | #endif // WX_PRECOMP |
25 | ||
bedaf53e SC |
26 | #include "wx/notebook.h" |
27 | #include "wx/tabctrl.h" | |
e9576ca5 | 28 | |
43524b15 DS |
29 | #include "wx/mac/uma.h" |
30 | ||
e9576ca5 SC |
31 | #include <stdio.h> |
32 | ||
90b959ae | 33 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
e9576ca5 | 34 | |
519cb848 | 35 | |
43524b15 DS |
36 | bool wxStaticText::Create( wxWindow *parent, |
37 | wxWindowID id, | |
38 | const wxString& label, | |
39 | const wxPoint& pos, | |
40 | const wxSize& size, | |
41 | long style, | |
42 | const wxString& name ) | |
8208e181 | 43 | { |
43524b15 | 44 | m_macIsUserPane = false; |
8208e181 | 45 | |
32cd189d | 46 | m_label = GetLabelText( label ); |
43524b15 DS |
47 | |
48 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) | |
b45ed7a2 | 49 | return false; |
b45ed7a2 | 50 | |
43524b15 DS |
51 | Rect bounds = wxMacGetBoundsForControl( this, pos, size ); |
52 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
53 | ||
54 | m_peer = new wxMacControl( this ); | |
55 | OSStatus err = CreateStaticTextControl( | |
56 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
57 | &bounds, str, NULL, m_peer->GetControlRefAddr() ); | |
58 | verify_noerr( err ); | |
b8c140b8 | 59 | |
a074f61e | 60 | if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) ) |
14132857 | 61 | { |
a074f61e | 62 | TruncCode tCode = truncEnd; |
14132857 | 63 | if ( style & wxST_DOTS_MIDDLE ) |
a074f61e DS |
64 | tCode = truncMiddle; |
65 | ||
66 | err = m_peer->SetData( kControlStaticTextTruncTag, tCode ); | |
67 | err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); | |
14132857 | 68 | } |
a074f61e | 69 | |
43524b15 | 70 | MacPostControlCreate( pos, size ); |
7595f381 | 71 | |
facd6764 | 72 | return true; |
9714ffa0 SC |
73 | } |
74 | ||
facd6764 | 75 | wxSize wxStaticText::DoGetBestSize() const |
8208e181 | 76 | { |
4d7e2cda | 77 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
43524b15 | 78 | Point bounds; |
4d7e2cda SC |
79 | |
80 | // try the built-in best size if available | |
81 | m_peer->GetBestRect( &bestsize ) ; | |
82 | if ( !EmptyRect( &bestsize ) ) | |
43524b15 | 83 | { |
4d7e2cda SC |
84 | bounds.h = bestsize.right - bestsize.left ; |
85 | bounds.v = bestsize.bottom - bestsize.top ; | |
43524b15 | 86 | } |
943b730f SC |
87 | else |
88 | { | |
4d7e2cda SC |
89 | ControlFontStyleRec controlFont; |
90 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
43524b15 | 91 | verify_noerr( err ); |
43524b15 | 92 | |
4d7e2cda SC |
93 | SInt16 baseline; |
94 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
43524b15 | 95 | |
4d7e2cda SC |
96 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) |
97 | { | |
98 | err = GetThemeTextDimensions( | |
99 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
100 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
101 | verify_noerr( err ); | |
102 | } | |
103 | else | |
104 | { | |
105 | #if wxMAC_USE_CORE_GRAPHICS | |
106 | wxClientDC dc(const_cast<wxStaticText*>(this)); | |
107 | wxCoord width, height ; | |
108 | dc.GetTextExtent( m_label , &width, &height); | |
109 | bounds.h = width; | |
110 | bounds.v = height; | |
111 | #else | |
112 | wxMacWindowStateSaver sv( this ); | |
113 | ::TextFont( m_font.MacGetFontNum() ); | |
114 | ::TextSize( (short)(m_font.MacGetFontSize()) ); | |
115 | ::TextFace( m_font.MacGetFontStyle() ); | |
116 | ||
117 | err = GetThemeTextDimensions( | |
118 | (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), | |
119 | kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); | |
120 | verify_noerr( err ); | |
121 | #endif | |
122 | } | |
123 | ||
124 | if ( m_label.empty() ) | |
125 | bounds.h = 0; | |
126 | } | |
43524b15 DS |
127 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); |
128 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
129 | ||
130 | return wxSize( bounds.h, bounds.v ); | |
8208e181 SC |
131 | } |
132 | ||
43524b15 | 133 | void wxStaticText::SetLabel( const wxString& st ) |
e9576ca5 | 134 | { |
32cd189d | 135 | m_label = GetLabelText( st ); |
2f1ae414 | 136 | |
43524b15 DS |
137 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); |
138 | CFStringRef ref = str; | |
139 | OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref ); | |
140 | verify_noerr( err ); | |
e9576ca5 | 141 | |
c0e6c051 RD |
142 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) |
143 | { | |
9f884528 | 144 | InvalidateBestSize(); |
43524b15 | 145 | SetSize( GetBestSize() ); |
c0e6c051 | 146 | } |
43524b15 DS |
147 | |
148 | Refresh(); | |
149 | ||
3a0ec6eb | 150 | // we shouldn't need forced updates |
a074f61e | 151 | // Update(); |
bb751cf9 RD |
152 | } |
153 | ||
c0e6c051 RD |
154 | bool wxStaticText::SetFont(const wxFont& font) |
155 | { | |
43524b15 | 156 | bool ret = wxControl::SetFont( font ); |
c0e6c051 | 157 | |
43524b15 DS |
158 | if ( ret ) |
159 | { | |
160 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
441b46ac SC |
161 | { |
162 | InvalidateBestSize(); | |
163 | SetSize( GetBestSize() ); | |
164 | } | |
43524b15 | 165 | } |
c0e6c051 RD |
166 | |
167 | return ret; | |
168 | } | |
c545950d RN |
169 | |
170 | #endif //if wxUSE_STATTEXT |