]> git.saurik.com Git - wxWidgets.git/blame - src/osx/stattext_osx.cpp
Applied #15375 to stop event-sending in generic wxSpinCtrl ctor (eco)
[wxWidgets.git] / src / osx / stattext_osx.cpp
CommitLineData
e53b3d16 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/stattext_osx.cpp
e53b3d16
SC
3// Purpose: wxStaticText
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
e53b3d16
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_STATTEXT
14
15#include "wx/stattext.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/dc.h"
21 #include "wx/dcclient.h"
22 #include "wx/settings.h"
23#endif // WX_PRECOMP
24
e53b3d16
SC
25#include "wx/osx/private.h"
26
27#include <stdio.h>
28
e53b3d16
SC
29
30bool wxStaticText::Create( wxWindow *parent,
31 wxWindowID id,
32 const wxString& label,
33 const wxPoint& pos,
34 const wxSize& size,
35 long style,
36 const wxString& name )
d15694e8
SC
37{
38 DontCreatePeer();
39
e53b3d16
SC
40 if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
41 return false;
42
22756322 43 SetPeer(wxWidgetImpl::CreateStaticText( this, parent, id, label, pos, size, style, GetExtraStyle() ));
e53b3d16
SC
44
45 MacPostControlCreate( pos, size );
46
47 SetLabel(label);
e465e648
VZ
48 if ( HasFlag(wxST_NO_AUTORESIZE) )
49 {
50 // Normally this is done in SetLabel() below but we avoid doing it when
51 // this style is used, so we need to explicitly do it in the ctor in
52 // this case or otherwise the control would retain its initial tiny size.
53 InvalidateBestSize();
54 SetInitialSize(size);
55 }
e53b3d16
SC
56
57 return true;
58}
59
60void wxStaticText::SetLabel(const wxString& label)
61{
62 m_labelOrig = label;
63
64 // middle/end ellipsization is handled by the OS:
03647350 65 if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE)
f1c40652 66#if wxOSX_USE_COCOA // Cocoa has all three modes
03647350 67 || HasFlag(wxST_ELLIPSIZE_START)
f1c40652
SC
68#endif
69 )
e53b3d16 70 {
2318a5d7 71 // leave ellipsization to the OS
3da9cffc 72 DoSetLabel(GetLabel());
e53b3d16
SC
73 }
74 else // not supported natively
75 {
3da9cffc 76 DoSetLabel(GetEllipsizedLabel());
e53b3d16
SC
77 }
78
79 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
80 !IsEllipsized() ) // don't resize if we adjust to current size
81 {
82 InvalidateBestSize();
83 SetSize( GetBestSize() );
84 }
85
86 Refresh();
87
88 // we shouldn't need forced updates
89 // Update();
90}
91
92bool wxStaticText::SetFont(const wxFont& font)
93{
94 bool ret = wxControl::SetFont( font );
95
96 if ( ret )
97 {
98 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
99 {
100 InvalidateBestSize();
101 SetSize( GetBestSize() );
102 }
103 }
104
105 return ret;
106}
107
108void wxStaticText::DoSetLabel(const wxString& label)
109{
e53b3d16 110 m_label = RemoveMnemonics(label);
22756322 111 GetPeer()->SetLabel(m_label , GetFont().GetEncoding() );
e53b3d16
SC
112}
113
f672c969
VZ
114#if wxUSE_MARKUP && wxOSX_USE_COCOA
115
116bool wxStaticText::DoSetLabelMarkup(const wxString& markup)
117{
118 if ( !wxStaticTextBase::DoSetLabelMarkup(markup) )
119 return false;
120
22756322 121 GetPeer()->SetLabelMarkup(markup);
f672c969
VZ
122
123 return true;
124}
125
126#endif // wxUSE_MARKUP && wxOSX_USE_COCOA
127
e53b3d16
SC
128wxString wxStaticText::DoGetLabel() const
129{
130 return m_label;
131}
132
133/*
134 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
135 to allow correct dynamic ellipsizing of the label
136*/
137
138#endif //if wxUSE_STATTEXT