]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/stattext.cpp
don't reset the selection after event was vetoed if there is no old selection
[wxWidgets.git] / src / mac / carbon / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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 #include "wx/wxprec.h"
13
14 #if wxUSE_STATTEXT
15
16 #include "wx/stattext.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/notebook.h"
27 #include "wx/tabctrl.h"
28
29 #include "wx/mac/uma.h"
30
31 #include <stdio.h>
32
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
34
35
36 bool wxStaticText::Create( wxWindow *parent,
37 wxWindowID id,
38 const wxString& label,
39 const wxPoint& pos,
40 const wxSize& size,
41 long style,
42 const wxString& name )
43 {
44 m_macIsUserPane = false;
45
46 m_label = GetLabelText( label );
47
48 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
49 return false;
50
51 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
52 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
53
54 m_peer = new wxMacControl( this );
55 OSStatus err = CreateStaticTextControl(
56 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
57 &bounds, str, NULL, m_peer->GetControlRefAddr() );
58 verify_noerr( err );
59
60 if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
61 {
62 TruncCode tCode = truncEnd;
63 if ( style & wxST_DOTS_MIDDLE )
64 tCode = truncMiddle;
65
66 err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
67 err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
68 }
69
70 MacPostControlCreate( pos, size );
71
72 return true;
73 }
74
75 wxSize wxStaticText::DoGetBestSize() const
76 {
77 ControlFontStyleRec controlFont;
78 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
79 verify_noerr( err );
80
81 Point bounds;
82 SInt16 baseline;
83 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
84
85 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
86 {
87 err = GetThemeTextDimensions(
88 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
89 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
90 verify_noerr( err );
91 }
92 else
93 {
94 wxMacWindowStateSaver sv( this );
95 ::TextFont( m_font.MacGetFontNum() );
96 ::TextSize( (short)(m_font.MacGetFontSize()) );
97 ::TextFace( m_font.MacGetFontStyle() );
98
99 err = GetThemeTextDimensions(
100 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
101 kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
102 verify_noerr( err );
103 }
104
105 if ( m_label.empty() )
106 bounds.h = 0;
107
108 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
109 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
110
111 return wxSize( bounds.h, bounds.v );
112 }
113
114 void wxStaticText::SetLabel( const wxString& st )
115 {
116 m_label = GetLabelText( st );
117
118 wxMacCFStringHolder str( m_label, m_font.GetEncoding() );
119 CFStringRef ref = str;
120 OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
121 verify_noerr( err );
122
123 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
124 {
125 InvalidateBestSize();
126 SetSize( GetBestSize() );
127 }
128
129 Refresh();
130
131 // we shouldn't need forced updates
132 // Update();
133 }
134
135 bool wxStaticText::SetFont(const wxFont& font)
136 {
137 bool ret = wxControl::SetFont( font );
138
139 if ( ret )
140 {
141 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
142 {
143 InvalidateBestSize();
144 SetSize( GetBestSize() );
145 }
146 }
147
148 return ret;
149 }
150
151 #endif //if wxUSE_STATTEXT