]>
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 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "stattext.h" | |
14 | #endif | |
15 | ||
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 SC |
24 | |
25 | #include <stdio.h> | |
26 | ||
2f1ae414 | 27 | #if !USE_SHARED_LIBRARY |
90b959ae | 28 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
2f1ae414 | 29 | #endif |
e9576ca5 | 30 | |
d497dca4 | 31 | #include "wx/mac/uma.h" |
519cb848 | 32 | |
8208e181 SC |
33 | bool wxStaticText::Create(wxWindow *parent, wxWindowID id, |
34 | const wxString& label, | |
35 | const wxPoint& pos, | |
36 | const wxSize& size, | |
37 | long style, | |
38 | const wxString& name) | |
39 | { | |
facd6764 SC |
40 | m_macIsUserPane = FALSE ; |
41 | ||
28c98a77 | 42 | m_label = wxStripMenuCodes(label) ; |
8208e181 | 43 | |
b45ed7a2 VZ |
44 | if ( !wxControl::Create( parent, id, pos, size, style, |
45 | wxDefaultValidator , name ) ) | |
46 | { | |
47 | return false; | |
48 | } | |
49 | ||
facd6764 SC |
50 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
51 | wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; | |
21fd5529 | 52 | m_peer = new wxMacControl() ; |
facd6764 | 53 | verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str , |
21fd5529 | 54 | NULL , *m_peer ) ) ; |
b8c140b8 | 55 | |
facd6764 | 56 | MacPostControlCreate(pos,size) ; |
7595f381 | 57 | |
facd6764 | 58 | return true; |
9714ffa0 SC |
59 | } |
60 | ||
facd6764 | 61 | wxSize wxStaticText::DoGetBestSize() const |
8208e181 | 62 | { |
facd6764 SC |
63 | ControlFontStyleRec controlFont ; |
64 | Size outSize ; | |
21fd5529 | 65 | verify_noerr( GetControlData( *m_peer , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ; |
e40298d5 | 66 | |
facd6764 SC |
67 | Point bounds ; |
68 | SInt16 baseline ; | |
69 | wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ; | |
943b730f SC |
70 | if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) |
71 | verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ; | |
72 | else | |
73 | { | |
74 | wxMacWindowStateSaver sv( this ) ; | |
75 | ::TextFont( m_font.MacGetFontNum() ) ; | |
76 | ::TextSize( (short)( m_font.MacGetFontSize()) ) ; | |
77 | ::TextFace( m_font.MacGetFontStyle() ) ; | |
78 | verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , kThemeCurrentPortFont , kThemeStateActive , false , &bounds , &baseline ) ) ; | |
79 | } | |
b1d7de5a SC |
80 | if ( m_label.Length() == 0 ) |
81 | bounds.h = 0 ; | |
facd6764 | 82 | return wxSize(bounds.h, bounds.v); |
8208e181 SC |
83 | } |
84 | ||
facd6764 | 85 | void wxStaticText::SetLabel(const wxString& st ) |
e9576ca5 | 86 | { |
2f1ae414 | 87 | |
facd6764 SC |
88 | m_label = wxStripMenuCodes(st) ; |
89 | ||
90 | wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; | |
91 | CFStringRef ref = str ; | |
21fd5529 | 92 | SetControlData( *m_peer, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ), |
facd6764 | 93 | &ref ); |
e9576ca5 | 94 | |
bb751cf9 | 95 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) |
d3b5db4b | 96 | { |
bb751cf9 | 97 | SetSize( GetBestSize() ) ; |
d3b5db4b RD |
98 | SetSizeHints(GetSize()); |
99 | } | |
facd6764 | 100 | |
bb751cf9 RD |
101 | Update() ; |
102 | } | |
103 | ||
104 | bool wxStaticText::SetFont(const wxFont& font) | |
105 | { | |
106 | bool ret = wxControl::SetFont(font); | |
607f6d2b | 107 | |
55094d8b SC |
108 | if ( ret ) |
109 | { | |
55094d8b | 110 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) |
d3b5db4b | 111 | { |
55094d8b | 112 | SetSize( GetBestSize() ); |
d3b5db4b RD |
113 | SetSizeHints(GetSize()); |
114 | } | |
55094d8b | 115 | } |
bb751cf9 RD |
116 | |
117 | return ret; | |
e9576ca5 | 118 | } |