]> git.saurik.com Git - wxWidgets.git/blob - src/osx/stattext_osx.cpp
precomp header fixes
[wxWidgets.git] / src / osx / stattext_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/osx/private.h"
27
28 #include <stdio.h>
29
30
31 bool wxStaticText::Create( wxWindow *parent,
32 wxWindowID id,
33 const wxString& label,
34 const wxPoint& pos,
35 const wxSize& size,
36 long style,
37 const wxString& name )
38 {
39 m_macIsUserPane = false;
40
41 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
42 return false;
43
44 m_peer = wxWidgetImpl::CreateStaticText( this, parent, id, label, pos, size, style, GetExtraStyle() );
45
46 MacPostControlCreate( pos, size );
47
48 SetLabel(label);
49
50 return true;
51 }
52
53 void wxStaticText::SetLabel(const wxString& label)
54 {
55 m_labelOrig = label;
56
57 // middle/end ellipsization is handled by the OS:
58 if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE)
59 #if wxOSX_USE_COCOA // Cocoa has all three modes
60 || HasFlag(wxST_ELLIPSIZE_START)
61 #endif
62 )
63 {
64 // leave ellipsization to the OS
65 DoSetLabel(GetLabelWithoutMarkup());
66 }
67 else // not supported natively
68 {
69 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
70 }
71
72 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
73 !IsEllipsized() ) // don't resize if we adjust to current size
74 {
75 InvalidateBestSize();
76 SetSize( GetBestSize() );
77 }
78
79 Refresh();
80
81 // we shouldn't need forced updates
82 // Update();
83 }
84
85 bool wxStaticText::SetFont(const wxFont& font)
86 {
87 bool ret = wxControl::SetFont( font );
88
89 if ( ret )
90 {
91 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
92 {
93 InvalidateBestSize();
94 SetSize( GetBestSize() );
95 }
96 }
97
98 return ret;
99 }
100
101 void wxStaticText::DoSetLabel(const wxString& label)
102 {
103 m_label = RemoveMnemonics(label);
104 m_peer->SetLabel(m_label , GetFont().GetEncoding() );
105 }
106
107 wxString wxStaticText::DoGetLabel() const
108 {
109 return m_label;
110 }
111
112 /*
113 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
114 to allow correct dynamic ellipsizing of the label
115 */
116
117 #endif //if wxUSE_STATTEXT