]> git.saurik.com Git - wxWidgets.git/blame - src/osx/textentry_osx.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[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
c84030e0
KO
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_TEXTCTRL
14
15#include "wx/textctrl.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/button.h"
23 #include "wx/menu.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/toplevel.h"
27#endif
28
29#ifdef __DARWIN__
30 #include <sys/types.h>
31 #include <sys/stat.h>
32#else
33 #include <stat.h>
34#endif
35
36#if wxUSE_STD_IOSTREAM
37 #if wxUSE_IOSTREAMH
38 #include <fstream.h>
39 #else
40 #include <fstream>
41 #endif
42#endif
43
44#include "wx/filefn.h"
45#include "wx/sysopt.h"
46#include "wx/thread.h"
c729f16f 47#include "wx/textcompleter.h"
c84030e0
KO
48
49#include "wx/osx/private.h"
50
c729f16f
VZ
51wxTextEntry::wxTextEntry()
52{
53 m_completer = NULL;
54 m_editable = true;
55 m_maxLength = 0;
56}
57
58wxTextEntry::~wxTextEntry()
59{
60 delete m_completer;
61}
62
c84030e0
KO
63wxString wxTextEntry::DoGetValue() const
64{
da8eb5f5
VZ
65 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
66
c84030e0
KO
67 return GetTextPeer()->GetStringValue() ;
68}
69
70void wxTextEntry::GetSelection(long* from, long* to) const
71{
da8eb5f5
VZ
72 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
73
c84030e0
KO
74 GetTextPeer()->GetSelection( from , to ) ;
75}
76
77void wxTextEntry::SetMaxLength(unsigned long len)
78{
a39815bd
SC
79 if ( GetTextPeer()->CanClipMaxLength() )
80 GetTextPeer()->SetMaxLength(len);
c84030e0
KO
81 m_maxLength = len ;
82}
83
84// Clipboard operations
85
86void wxTextEntry::Copy()
87{
da8eb5f5
VZ
88 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
89
c84030e0
KO
90 if (CanCopy())
91 GetTextPeer()->Copy() ;
92}
93
94void wxTextEntry::Cut()
95{
da8eb5f5
VZ
96 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
97
c84030e0
KO
98 if (CanCut())
99 GetTextPeer()->Cut() ;
100}
101
102void wxTextEntry::Paste()
103{
da8eb5f5
VZ
104 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
105
c84030e0
KO
106 if (CanPaste())
107 GetTextPeer()->Paste() ;
108}
109
110bool wxTextEntry::CanCopy() const
111{
112 // Can copy if there's a selection
113 long from, to;
114 GetSelection( &from, &to );
115
116 return (from != to);
117}
118
119bool wxTextEntry::CanCut() const
120{
121 if ( !IsEditable() )
122 return false;
123
124 // Can cut if there's a selection
125 long from, to;
126 GetSelection( &from, &to );
127
128 return (from != to);
129}
130
131bool wxTextEntry::CanPaste() const
132{
133 if (!IsEditable())
134 return false;
135
da8eb5f5
VZ
136 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
137
c84030e0
KO
138 return GetTextPeer()->CanPaste() ;
139}
140
141void wxTextEntry::SetEditable(bool editable)
142{
da8eb5f5
VZ
143 if ( editable == m_editable )
144 return;
145
146 m_editable = editable ;
147
148 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
149 GetTextPeer()->SetEditable( editable ) ;
c84030e0
KO
150}
151
152void wxTextEntry::SetInsertionPoint(long pos)
153{
154 SetSelection( pos , pos ) ;
155}
156
157void wxTextEntry::SetInsertionPointEnd()
158{
159 long pos = GetLastPosition();
160 SetInsertionPoint( pos );
161}
162
163long wxTextEntry::GetInsertionPoint() const
164{
165 long begin, end ;
166 GetSelection( &begin , &end ) ;
167
168 return begin ;
169}
170
171wxTextPos wxTextEntry::GetLastPosition() const
172{
da8eb5f5
VZ
173 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
174
c84030e0
KO
175 return GetTextPeer()->GetLastPosition() ;
176}
177
178void wxTextEntry::Remove(long from, long to)
179{
da8eb5f5
VZ
180 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
181
4275201b
SC
182 {
183 EventsSuppressor noevents(this);
184 GetTextPeer()->Remove( from , to );
185 }
ce00f59b 186
e567904a 187 SendTextUpdatedEventIfAllowed();
c84030e0
KO
188}
189
190void wxTextEntry::SetSelection(long from, long to)
191{
da8eb5f5
VZ
192 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
193
c84030e0
KO
194 GetTextPeer()->SetSelection( from , to ) ;
195}
196
197void wxTextEntry::WriteText(const wxString& str)
198{
da8eb5f5
VZ
199 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
200
4275201b
SC
201 {
202 EventsSuppressor noevents(this);
203 GetTextPeer()->WriteText( str );
204 }
e567904a
VZ
205
206 SendTextUpdatedEventIfAllowed();
c84030e0
KO
207}
208
209void wxTextEntry::Clear()
210{
da8eb5f5
VZ
211 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
212
4275201b
SC
213 {
214 EventsSuppressor noevents(this);
215 GetTextPeer()->Clear();
216 }
e567904a
VZ
217
218 SendTextUpdatedEventIfAllowed();
c84030e0
KO
219}
220
221bool wxTextEntry::IsEditable() const
222{
223 return m_editable ;
224}
225
053f5a55
SC
226bool wxTextEntry::SendMaxLenEvent()
227{
228 wxWindow *win = GetEditableWindow();
229 wxCHECK_MSG( win, false, "can't send an event without a window" );
230
231 wxCommandEvent event(wxEVT_TEXT_MAXLEN, win->GetId());
232
233 // do not do this as it could be very inefficient if the text control
234 // contains a lot of text and we're not using ref-counted wxString
235 // implementation -- instead, event.GetString() will query the control for
236 // its current text if needed
237 //event.SetString(win->GetValue());
238
239 event.SetEventObject(win);
240 return win->HandleWindowEvent(event);
241}
242
c84030e0
KO
243// ----------------------------------------------------------------------------
244// Undo/redo
245// ----------------------------------------------------------------------------
246
247void wxTextEntry::Undo()
248{
da8eb5f5
VZ
249 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
250
c84030e0
KO
251 if (CanUndo())
252 GetTextPeer()->Undo() ;
253}
254
255void wxTextEntry::Redo()
256{
da8eb5f5
VZ
257 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
258
c84030e0
KO
259 if (CanRedo())
260 GetTextPeer()->Redo() ;
261}
262
263bool wxTextEntry::CanUndo() const
264{
265 if ( !IsEditable() )
266 return false ;
267
da8eb5f5
VZ
268 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
269
c84030e0
KO
270 return GetTextPeer()->CanUndo() ;
271}
272
273bool wxTextEntry::CanRedo() const
274{
275 if ( !IsEditable() )
276 return false ;
277
da8eb5f5
VZ
278 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
279
c84030e0
KO
280 return GetTextPeer()->CanRedo() ;
281}
282
283wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
284{
005ac806
VZ
285 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
286
287 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
c84030e0 288}
005ac806 289
c729f16f
VZ
290// ----------------------------------------------------------------------------
291// Auto-completion
292// ----------------------------------------------------------------------------
293
294bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
295{
296 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
297 completer->SetCompletions(choices);
298
299 return DoAutoCompleteCustom(completer);
300}
301
302bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
303{
304 m_completer = completer;
305
306 return true;
307}
308
c84030e0 309#endif // wxUSE_TEXTCTRL