]> git.saurik.com Git - wxWidgets.git/blob - src/osx/textentry_osx.cpp
Fix compilation for OSX backend.
[wxWidgets.git] / src / osx / textentry_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/textentry_osx.cpp
3 // Purpose: wxTextEntry
4 // Author: Stefan Csomor
5 // Modified by: Kevin Ollivier
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_TEXTCTRL
15
16 #include "wx/textctrl.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.h"
21 #include "wx/utils.h"
22 #include "wx/dc.h"
23 #include "wx/button.h"
24 #include "wx/menu.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
28 #endif
29
30 #ifdef __DARWIN__
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #else
34 #include <stat.h>
35 #endif
36
37 #if wxUSE_STD_IOSTREAM
38 #if wxUSE_IOSTREAMH
39 #include <fstream.h>
40 #else
41 #include <fstream>
42 #endif
43 #endif
44
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
48 #include "wx/textcompleter.h"
49
50 #include "wx/osx/private.h"
51
52 wxTextEntry::wxTextEntry()
53 {
54 m_completer = NULL;
55 m_editable = true;
56 m_maxLength = 0;
57 }
58
59 wxTextEntry::~wxTextEntry()
60 {
61 delete m_completer;
62 }
63
64 wxString wxTextEntry::DoGetValue() const
65 {
66 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
67
68 return GetTextPeer()->GetStringValue() ;
69 }
70
71 void wxTextEntry::GetSelection(long* from, long* to) const
72 {
73 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
74
75 GetTextPeer()->GetSelection( from , to ) ;
76 }
77
78 void wxTextEntry::SetMaxLength(unsigned long len)
79 {
80 m_maxLength = len ;
81 }
82
83 // Clipboard operations
84
85 void wxTextEntry::Copy()
86 {
87 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
88
89 if (CanCopy())
90 GetTextPeer()->Copy() ;
91 }
92
93 void wxTextEntry::Cut()
94 {
95 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
96
97 if (CanCut())
98 GetTextPeer()->Cut() ;
99 }
100
101 void wxTextEntry::Paste()
102 {
103 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
104
105 if (CanPaste())
106 GetTextPeer()->Paste() ;
107 }
108
109 bool wxTextEntry::CanCopy() const
110 {
111 // Can copy if there's a selection
112 long from, to;
113 GetSelection( &from, &to );
114
115 return (from != to);
116 }
117
118 bool wxTextEntry::CanCut() const
119 {
120 if ( !IsEditable() )
121 return false;
122
123 // Can cut if there's a selection
124 long from, to;
125 GetSelection( &from, &to );
126
127 return (from != to);
128 }
129
130 bool wxTextEntry::CanPaste() const
131 {
132 if (!IsEditable())
133 return false;
134
135 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
136
137 return GetTextPeer()->CanPaste() ;
138 }
139
140 void wxTextEntry::SetEditable(bool editable)
141 {
142 if ( editable == m_editable )
143 return;
144
145 m_editable = editable ;
146
147 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
148 GetTextPeer()->SetEditable( editable ) ;
149 }
150
151 void wxTextEntry::SetInsertionPoint(long pos)
152 {
153 SetSelection( pos , pos ) ;
154 }
155
156 void wxTextEntry::SetInsertionPointEnd()
157 {
158 long pos = GetLastPosition();
159 SetInsertionPoint( pos );
160 }
161
162 long wxTextEntry::GetInsertionPoint() const
163 {
164 long begin, end ;
165 GetSelection( &begin , &end ) ;
166
167 return begin ;
168 }
169
170 wxTextPos wxTextEntry::GetLastPosition() const
171 {
172 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
173
174 return GetTextPeer()->GetLastPosition() ;
175 }
176
177 void wxTextEntry::Remove(long from, long to)
178 {
179 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
180
181 {
182 EventsSuppressor noevents(this);
183 GetTextPeer()->Remove( from , to );
184 }
185
186 SendTextUpdatedEventIfAllowed();
187 }
188
189 void wxTextEntry::SetSelection(long from, long to)
190 {
191 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
192
193 GetTextPeer()->SetSelection( from , to ) ;
194 }
195
196 void wxTextEntry::WriteText(const wxString& str)
197 {
198 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
199
200 {
201 EventsSuppressor noevents(this);
202 GetTextPeer()->WriteText( str );
203 }
204
205 SendTextUpdatedEventIfAllowed();
206 }
207
208 void wxTextEntry::Clear()
209 {
210 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
211
212 {
213 EventsSuppressor noevents(this);
214 GetTextPeer()->Clear();
215 }
216
217 SendTextUpdatedEventIfAllowed();
218 }
219
220 bool wxTextEntry::IsEditable() const
221 {
222 return m_editable ;
223 }
224
225 // ----------------------------------------------------------------------------
226 // Undo/redo
227 // ----------------------------------------------------------------------------
228
229 void wxTextEntry::Undo()
230 {
231 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
232
233 if (CanUndo())
234 GetTextPeer()->Undo() ;
235 }
236
237 void wxTextEntry::Redo()
238 {
239 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
240
241 if (CanRedo())
242 GetTextPeer()->Redo() ;
243 }
244
245 bool wxTextEntry::CanUndo() const
246 {
247 if ( !IsEditable() )
248 return false ;
249
250 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
251
252 return GetTextPeer()->CanUndo() ;
253 }
254
255 bool wxTextEntry::CanRedo() const
256 {
257 if ( !IsEditable() )
258 return false ;
259
260 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
261
262 return GetTextPeer()->CanRedo() ;
263 }
264
265 wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
266 {
267 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
268
269 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
270 }
271
272 // ----------------------------------------------------------------------------
273 // Auto-completion
274 // ----------------------------------------------------------------------------
275
276 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
277 {
278 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
279 completer->SetCompletions(choices);
280
281 return DoAutoCompleteCustom(completer);
282 }
283
284 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
285 {
286 m_completer = completer;
287
288 return true;
289 }
290
291 #endif // wxUSE_TEXTCTRL