]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stattext.cpp | |
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 SC |
16 | #include "wx/app.h" |
17 | #include "wx/stattext.h" | |
bedaf53e SC |
18 | #include "wx/notebook.h" |
19 | #include "wx/tabctrl.h" | |
03e11df5 GD |
20 | #include "wx/dc.h" |
21 | #include "wx/dcclient.h" | |
00500f40 | 22 | #include "wx/utils.h" |
f7035880 | 23 | #include "wx/settings.h" |
e9576ca5 | 24 | |
43524b15 DS |
25 | #include "wx/mac/uma.h" |
26 | ||
e9576ca5 SC |
27 | #include <stdio.h> |
28 | ||
90b959ae | 29 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
e9576ca5 | 30 | |
519cb848 | 31 | |
43524b15 DS |
32 | bool wxStaticText::Create( wxWindow *parent, |
33 | wxWindowID id, | |
34 | const wxString& label, | |
35 | const wxPoint& pos, | |
36 | const wxSize& size, | |
37 | long style, | |
38 | const wxString& name ) | |
8208e181 | 39 | { |
43524b15 | 40 | m_macIsUserPane = false; |
8208e181 | 41 | |
43524b15 DS |
42 | m_label = wxStripMenuCodes( label ); |
43 | ||
44 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) | |
b45ed7a2 | 45 | return false; |
b45ed7a2 | 46 | |
43524b15 DS |
47 | Rect bounds = wxMacGetBoundsForControl( this, pos, size ); |
48 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
49 | ||
50 | m_peer = new wxMacControl( this ); | |
51 | OSStatus err = CreateStaticTextControl( | |
52 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), | |
53 | &bounds, str, NULL, m_peer->GetControlRefAddr() ); | |
54 | verify_noerr( err ); | |
b8c140b8 | 55 | |
43524b15 | 56 | MacPostControlCreate( pos, size ); |
7595f381 | 57 | |
facd6764 | 58 | return true; |
9714ffa0 SC |
59 | } |
60 | ||
facd6764 | 61 | wxSize wxStaticText::DoGetBestSize() const |
8208e181 | 62 | { |
43524b15 DS |
63 | ControlFontStyleRec controlFont; |
64 | OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); | |
65 | verify_noerr( err ); | |
66 | ||
67 | Point bounds; | |
68 | SInt16 baseline; | |
69 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); | |
70 | ||
943b730f | 71 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) |
43524b15 DS |
72 | { |
73 | err = GetThemeTextDimensions( | |
74 | (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")), | |
75 | m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); | |
76 | verify_noerr( err ); | |
77 | } | |
943b730f SC |
78 | else |
79 | { | |
43524b15 DS |
80 | wxMacWindowStateSaver sv( this ); |
81 | ::TextFont( m_font.MacGetFontNum() ); | |
82 | ::TextSize( (short)(m_font.MacGetFontSize()) ); | |
83 | ::TextFace( m_font.MacGetFontStyle() ); | |
84 | ||
85 | err = GetThemeTextDimensions( | |
86 | (m_label.Length() > 0 ? (CFStringRef)str : CFSTR(" ")), | |
87 | kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); | |
88 | verify_noerr( err ); | |
943b730f | 89 | } |
43524b15 | 90 | |
b1d7de5a SC |
91 | if ( m_label.Length() == 0 ) |
92 | bounds.h = 0 ; | |
43524b15 DS |
93 | |
94 | bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
95 | bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
96 | ||
97 | return wxSize( bounds.h, bounds.v ); | |
8208e181 SC |
98 | } |
99 | ||
43524b15 | 100 | void wxStaticText::SetLabel( const wxString& st ) |
e9576ca5 | 101 | { |
43524b15 | 102 | m_label = wxStripMenuCodes( st ); |
2f1ae414 | 103 | |
43524b15 DS |
104 | wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); |
105 | CFStringRef ref = str; | |
106 | OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref ); | |
107 | verify_noerr( err ); | |
e9576ca5 | 108 | |
c0e6c051 RD |
109 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) |
110 | { | |
9f884528 | 111 | InvalidateBestSize(); |
43524b15 | 112 | SetSize( GetBestSize() ); |
c0e6c051 | 113 | } |
43524b15 DS |
114 | |
115 | Refresh(); | |
116 | ||
3a0ec6eb SC |
117 | // we shouldn't need forced updates |
118 | // Update() ; | |
bb751cf9 RD |
119 | } |
120 | ||
c0e6c051 RD |
121 | bool wxStaticText::SetFont(const wxFont& font) |
122 | { | |
43524b15 | 123 | bool ret = wxControl::SetFont( font ); |
c0e6c051 | 124 | |
43524b15 DS |
125 | if ( ret ) |
126 | { | |
127 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
441b46ac SC |
128 | { |
129 | InvalidateBestSize(); | |
130 | SetSize( GetBestSize() ); | |
131 | } | |
43524b15 | 132 | } |
c0e6c051 RD |
133 | |
134 | return ret; | |
135 | } | |
c545950d RN |
136 | |
137 | #endif //if wxUSE_STATTEXT | |
138 |