]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/stattext.cpp
added native alignement support
[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
00500f40 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 28IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
2f1ae414 29#endif
e9576ca5 30
d497dca4 31#include "wx/mac/uma.h"
519cb848 32
8208e181
SC
33bool 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() ) ;
52 verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str ,
53 NULL , (ControlRef*)&m_macControl ) ) ;
b8c140b8 54
facd6764 55 MacPostControlCreate(pos,size) ;
7595f381 56
facd6764 57 return true;
9714ffa0
SC
58}
59
facd6764 60wxSize wxStaticText::DoGetBestSize() const
8208e181 61{
facd6764
SC
62 ControlFontStyleRec controlFont ;
63 Size outSize ;
64 verify_noerr( GetControlData( (ControlRef) m_macControl , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ;
e40298d5 65
facd6764
SC
66 Point bounds ;
67 SInt16 baseline ;
68 wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ;
69 verify_noerr( GetThemeTextDimensions( str , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ;
8208e181 70
facd6764 71 return wxSize(bounds.h, bounds.v);
8208e181
SC
72}
73
facd6764 74void wxStaticText::SetLabel(const wxString& st )
e9576ca5 75{
2f1ae414 76
facd6764
SC
77 m_label = wxStripMenuCodes(st) ;
78
79 wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ;
80 CFStringRef ref = str ;
81 SetControlData( (ControlRef) m_macControl, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ),
82 &ref );
e9576ca5 83
bb751cf9
RD
84 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
85 SetSize( GetBestSize() ) ;
facd6764 86
bb751cf9
RD
87 Update() ;
88}
89
90bool wxStaticText::SetFont(const wxFont& font)
91{
92 bool ret = wxControl::SetFont(font);
607f6d2b 93
55094d8b
SC
94 if ( ret )
95 {
55094d8b 96 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
55094d8b 97 SetSize( GetBestSize() );
55094d8b 98 }
bb751cf9
RD
99
100 return ret;
e9576ca5 101}