]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: stattext.cpp | |
3 | // Purpose: wxStaticText | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "stattext.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/app.h" | |
17 | #include "wx/stattext.h" | |
18 | #include "wx/notebook.h" | |
19 | #include "wx/tabctrl.h" | |
20 | #include "wx/dc.h" | |
21 | #include "wx/dcclient.h" | |
22 | #include "wx/utils.h" | |
23 | #include "wx/settings.h" | |
24 | ||
25 | #include <stdio.h> | |
26 | ||
27 | #if !USE_SHARED_LIBRARY | |
28 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) | |
29 | #endif | |
30 | ||
31 | #include "wx/mac/uma.h" | |
32 | ||
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 | { | |
40 | m_macIsUserPane = FALSE ; | |
41 | ||
42 | m_label = wxStripMenuCodes(label) ; | |
43 | ||
44 | if ( !wxControl::Create( parent, id, pos, size, style, | |
45 | wxDefaultValidator , name ) ) | |
46 | { | |
47 | return false; | |
48 | } | |
49 | ||
50 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
51 | wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; | |
52 | verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str , | |
53 | NULL , (ControlRef*)&m_macControl ) ) ; | |
54 | ||
55 | MacPostControlCreate(pos,size) ; | |
56 | ||
57 | return true; | |
58 | } | |
59 | ||
60 | wxSize wxStaticText::DoGetBestSize() const | |
61 | { | |
62 | ControlFontStyleRec controlFont ; | |
63 | Size outSize ; | |
64 | verify_noerr( GetControlData( (ControlRef) m_macControl , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ; | |
65 | ||
66 | Point bounds ; | |
67 | SInt16 baseline ; | |
68 | wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ; | |
69 | verify_noerr( GetThemeTextDimensions( (m_label.Length() > 0 ? ((CFStringRef) str ) : CFSTR(" ") ) , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ; | |
70 | if ( m_label.Length() == 0 ) | |
71 | bounds.h = 0 ; | |
72 | return wxSize(bounds.h, bounds.v); | |
73 | } | |
74 | ||
75 | void wxStaticText::SetLabel(const wxString& st ) | |
76 | { | |
77 | ||
78 | m_label = wxStripMenuCodes(st) ; | |
79 | ||
80 | wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; | |
81 | CFStringRef ref = str ; | |
82 | SetControlData( (ControlRef) m_macControl, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ), | |
83 | &ref ); | |
84 | ||
85 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
86 | SetSize( GetBestSize() ) ; | |
87 | ||
88 | Update() ; | |
89 | } | |
90 | ||
91 | bool wxStaticText::SetFont(const wxFont& font) | |
92 | { | |
93 | bool ret = wxControl::SetFont(font); | |
94 | ||
95 | if ( ret ) | |
96 | { | |
97 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
98 | SetSize( GetBestSize() ); | |
99 | } | |
100 | ||
101 | return ret; | |
102 | } |