]> git.saurik.com Git - wxWidgets.git/blame - src/osx/textentry_osx.cpp
Disable some wxWebView tests that fail on the buildbot but not locally.
[wxWidgets.git] / src / osx / textentry_osx.cpp
CommitLineData
c84030e0
KO
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
b5b208a1 7// RCS-ID: $Id$
c84030e0
KO
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"
c729f16f 48#include "wx/textcompleter.h"
c84030e0
KO
49
50#include "wx/osx/private.h"
51
c729f16f
VZ
52wxTextEntry::wxTextEntry()
53{
54 m_completer = NULL;
55 m_editable = true;
56 m_maxLength = 0;
57}
58
59wxTextEntry::~wxTextEntry()
60{
61 delete m_completer;
62}
63
c84030e0
KO
64wxString wxTextEntry::DoGetValue() const
65{
da8eb5f5
VZ
66 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
67
c84030e0
KO
68 return GetTextPeer()->GetStringValue() ;
69}
70
71void wxTextEntry::GetSelection(long* from, long* to) const
72{
da8eb5f5
VZ
73 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
74
c84030e0
KO
75 GetTextPeer()->GetSelection( from , to ) ;
76}
77
78void wxTextEntry::SetMaxLength(unsigned long len)
79{
80 m_maxLength = len ;
81}
82
83// Clipboard operations
84
85void wxTextEntry::Copy()
86{
da8eb5f5
VZ
87 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
88
c84030e0
KO
89 if (CanCopy())
90 GetTextPeer()->Copy() ;
91}
92
93void wxTextEntry::Cut()
94{
da8eb5f5
VZ
95 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
96
c84030e0
KO
97 if (CanCut())
98 GetTextPeer()->Cut() ;
99}
100
101void wxTextEntry::Paste()
102{
da8eb5f5
VZ
103 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
104
c84030e0
KO
105 if (CanPaste())
106 GetTextPeer()->Paste() ;
107}
108
109bool 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
118bool 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
130bool wxTextEntry::CanPaste() const
131{
132 if (!IsEditable())
133 return false;
134
da8eb5f5
VZ
135 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
136
c84030e0
KO
137 return GetTextPeer()->CanPaste() ;
138}
139
140void wxTextEntry::SetEditable(bool editable)
141{
da8eb5f5
VZ
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 ) ;
c84030e0
KO
149}
150
151void wxTextEntry::SetInsertionPoint(long pos)
152{
153 SetSelection( pos , pos ) ;
154}
155
156void wxTextEntry::SetInsertionPointEnd()
157{
158 long pos = GetLastPosition();
159 SetInsertionPoint( pos );
160}
161
162long wxTextEntry::GetInsertionPoint() const
163{
164 long begin, end ;
165 GetSelection( &begin , &end ) ;
166
167 return begin ;
168}
169
170wxTextPos wxTextEntry::GetLastPosition() const
171{
da8eb5f5
VZ
172 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
173
c84030e0
KO
174 return GetTextPeer()->GetLastPosition() ;
175}
176
177void wxTextEntry::Remove(long from, long to)
178{
da8eb5f5
VZ
179 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
180
4275201b
SC
181 {
182 EventsSuppressor noevents(this);
183 GetTextPeer()->Remove( from , to );
184 }
ce00f59b 185
e567904a 186 SendTextUpdatedEventIfAllowed();
c84030e0
KO
187}
188
189void wxTextEntry::SetSelection(long from, long to)
190{
da8eb5f5
VZ
191 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
192
c84030e0
KO
193 GetTextPeer()->SetSelection( from , to ) ;
194}
195
196void wxTextEntry::WriteText(const wxString& str)
197{
da8eb5f5
VZ
198 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
199
4275201b
SC
200 {
201 EventsSuppressor noevents(this);
202 GetTextPeer()->WriteText( str );
203 }
e567904a
VZ
204
205 SendTextUpdatedEventIfAllowed();
c84030e0
KO
206}
207
208void wxTextEntry::Clear()
209{
da8eb5f5
VZ
210 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
211
4275201b
SC
212 {
213 EventsSuppressor noevents(this);
214 GetTextPeer()->Clear();
215 }
e567904a
VZ
216
217 SendTextUpdatedEventIfAllowed();
c84030e0
KO
218}
219
220bool wxTextEntry::IsEditable() const
221{
222 return m_editable ;
223}
224
225// ----------------------------------------------------------------------------
226// Undo/redo
227// ----------------------------------------------------------------------------
228
229void wxTextEntry::Undo()
230{
da8eb5f5
VZ
231 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
232
c84030e0
KO
233 if (CanUndo())
234 GetTextPeer()->Undo() ;
235}
236
237void wxTextEntry::Redo()
238{
da8eb5f5
VZ
239 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
240
c84030e0
KO
241 if (CanRedo())
242 GetTextPeer()->Redo() ;
243}
244
245bool wxTextEntry::CanUndo() const
246{
247 if ( !IsEditable() )
248 return false ;
249
da8eb5f5
VZ
250 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
251
c84030e0
KO
252 return GetTextPeer()->CanUndo() ;
253}
254
255bool wxTextEntry::CanRedo() const
256{
257 if ( !IsEditable() )
258 return false ;
259
da8eb5f5
VZ
260 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
261
c84030e0
KO
262 return GetTextPeer()->CanRedo() ;
263}
264
265wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
266{
005ac806
VZ
267 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
268
269 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
c84030e0 270}
005ac806 271
c729f16f
VZ
272// ----------------------------------------------------------------------------
273// Auto-completion
274// ----------------------------------------------------------------------------
275
276bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
277{
278 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
279 completer->SetCompletions(choices);
280
281 return DoAutoCompleteCustom(completer);
282}
283
284bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
285{
286 m_completer = completer;
287
288 return true;
289}
290
c84030e0 291#endif // wxUSE_TEXTCTRL