]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
mouse-capture fix
[wxWidgets.git] / src / mac / carbon / stattext.cpp
CommitLineData
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
c545950d
RN
18#if wxUSE_STATTEXT
19
e9576ca5
SC
20#include "wx/app.h"
21#include "wx/stattext.h"
bedaf53e
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
03e11df5
GD
24#include "wx/dc.h"
25#include "wx/dcclient.h"
00500f40 26#include "wx/utils.h"
f7035880 27#include "wx/settings.h"
e9576ca5
SC
28
29#include <stdio.h>
30
90b959ae 31IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
e9576ca5 32
d497dca4 33#include "wx/mac/uma.h"
519cb848 34
8208e181
SC
35bool 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() ) ;
b905d6cc 54 m_peer = new wxMacControl(this) ;
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 63wxSize 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 89void 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
107bool 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}
c545950d
RN
122
123#endif //if wxUSE_STATTEXT
124