]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/osx/stattext_osx.cpp | |
3 | // Purpose: wxStaticText | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
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 | ||
25 | #include "wx/osx/private.h" | |
26 | ||
27 | #include <stdio.h> | |
28 | ||
29 | ||
30 | bool 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 ) | |
37 | { | |
38 | DontCreatePeer(); | |
39 | ||
40 | if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) | |
41 | return false; | |
42 | ||
43 | SetPeer(wxWidgetImpl::CreateStaticText( this, parent, id, label, pos, size, style, GetExtraStyle() )); | |
44 | ||
45 | MacPostControlCreate( pos, size ); | |
46 | ||
47 | SetLabel(label); | |
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 | } | |
56 | ||
57 | return true; | |
58 | } | |
59 | ||
60 | void wxStaticText::SetLabel(const wxString& label) | |
61 | { | |
62 | m_labelOrig = label; | |
63 | ||
64 | // middle/end ellipsization is handled by the OS: | |
65 | if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) | |
66 | #if wxOSX_USE_COCOA // Cocoa has all three modes | |
67 | || HasFlag(wxST_ELLIPSIZE_START) | |
68 | #endif | |
69 | ) | |
70 | { | |
71 | // leave ellipsization to the OS | |
72 | DoSetLabel(GetLabel()); | |
73 | } | |
74 | else // not supported natively | |
75 | { | |
76 | DoSetLabel(GetEllipsizedLabel()); | |
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 | ||
92 | bool 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 | ||
108 | void wxStaticText::DoSetLabel(const wxString& label) | |
109 | { | |
110 | m_label = RemoveMnemonics(label); | |
111 | GetPeer()->SetLabel(m_label , GetFont().GetEncoding() ); | |
112 | } | |
113 | ||
114 | #if wxUSE_MARKUP && wxOSX_USE_COCOA | |
115 | ||
116 | bool wxStaticText::DoSetLabelMarkup(const wxString& markup) | |
117 | { | |
118 | if ( !wxStaticTextBase::DoSetLabelMarkup(markup) ) | |
119 | return false; | |
120 | ||
121 | GetPeer()->SetLabelMarkup(markup); | |
122 | ||
123 | return true; | |
124 | } | |
125 | ||
126 | #endif // wxUSE_MARKUP && wxOSX_USE_COCOA | |
127 | ||
128 | wxString 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 |