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