]>
Commit | Line | Data |
---|---|---|
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 | |
b5b208a1 | 7 | // RCS-ID: $Id$ |
e53b3d16 SC |
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 | ||
e53b3d16 SC |
26 | #include "wx/osx/private.h" |
27 | ||
28 | #include <stdio.h> | |
29 | ||
e53b3d16 SC |
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 ) | |
d15694e8 SC |
38 | { |
39 | DontCreatePeer(); | |
40 | ||
e53b3d16 SC |
41 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) |
42 | return false; | |
43 | ||
22756322 | 44 | SetPeer(wxWidgetImpl::CreateStaticText( this, parent, id, label, pos, size, style, GetExtraStyle() )); |
e53b3d16 SC |
45 | |
46 | MacPostControlCreate( pos, size ); | |
47 | ||
48 | SetLabel(label); | |
e465e648 VZ |
49 | if ( HasFlag(wxST_NO_AUTORESIZE) ) |
50 | { | |
51 | // Normally this is done in SetLabel() below but we avoid doing it when | |
52 | // this style is used, so we need to explicitly do it in the ctor in | |
53 | // this case or otherwise the control would retain its initial tiny size. | |
54 | InvalidateBestSize(); | |
55 | SetInitialSize(size); | |
56 | } | |
e53b3d16 SC |
57 | |
58 | return true; | |
59 | } | |
60 | ||
61 | void wxStaticText::SetLabel(const wxString& label) | |
62 | { | |
63 | m_labelOrig = label; | |
64 | ||
65 | // middle/end ellipsization is handled by the OS: | |
03647350 | 66 | if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) |
f1c40652 | 67 | #if wxOSX_USE_COCOA // Cocoa has all three modes |
03647350 | 68 | || HasFlag(wxST_ELLIPSIZE_START) |
f1c40652 SC |
69 | #endif |
70 | ) | |
e53b3d16 | 71 | { |
2318a5d7 | 72 | // leave ellipsization to the OS |
3da9cffc | 73 | DoSetLabel(GetLabel()); |
e53b3d16 SC |
74 | } |
75 | else // not supported natively | |
76 | { | |
3da9cffc | 77 | DoSetLabel(GetEllipsizedLabel()); |
e53b3d16 SC |
78 | } |
79 | ||
80 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) && | |
81 | !IsEllipsized() ) // don't resize if we adjust to current size | |
82 | { | |
83 | InvalidateBestSize(); | |
84 | SetSize( GetBestSize() ); | |
85 | } | |
86 | ||
87 | Refresh(); | |
88 | ||
89 | // we shouldn't need forced updates | |
90 | // Update(); | |
91 | } | |
92 | ||
93 | bool wxStaticText::SetFont(const wxFont& font) | |
94 | { | |
95 | bool ret = wxControl::SetFont( font ); | |
96 | ||
97 | if ( ret ) | |
98 | { | |
99 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
100 | { | |
101 | InvalidateBestSize(); | |
102 | SetSize( GetBestSize() ); | |
103 | } | |
104 | } | |
105 | ||
106 | return ret; | |
107 | } | |
108 | ||
109 | void wxStaticText::DoSetLabel(const wxString& label) | |
110 | { | |
e53b3d16 | 111 | m_label = RemoveMnemonics(label); |
22756322 | 112 | GetPeer()->SetLabel(m_label , GetFont().GetEncoding() ); |
e53b3d16 SC |
113 | } |
114 | ||
f672c969 VZ |
115 | #if wxUSE_MARKUP && wxOSX_USE_COCOA |
116 | ||
117 | bool wxStaticText::DoSetLabelMarkup(const wxString& markup) | |
118 | { | |
119 | if ( !wxStaticTextBase::DoSetLabelMarkup(markup) ) | |
120 | return false; | |
121 | ||
22756322 | 122 | GetPeer()->SetLabelMarkup(markup); |
f672c969 VZ |
123 | |
124 | return true; | |
125 | } | |
126 | ||
127 | #endif // wxUSE_MARKUP && wxOSX_USE_COCOA | |
128 | ||
e53b3d16 SC |
129 | wxString wxStaticText::DoGetLabel() const |
130 | { | |
131 | return m_label; | |
132 | } | |
133 | ||
134 | /* | |
135 | FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set | |
136 | to allow correct dynamic ellipsizing of the label | |
137 | */ | |
138 | ||
139 | #endif //if wxUSE_STATTEXT |