]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/textentry_osx.cpp
Fix wrong tab order in wxAuiNotebook after dragging.
[wxWidgets.git] / src / osx / textentry_osx.cpp
... / ...
CommitLineData
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
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
64wxString wxTextEntry::DoGetValue() const
65{
66 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
67
68 return GetTextPeer()->GetStringValue() ;
69}
70
71void 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
78void wxTextEntry::SetMaxLength(unsigned long len)
79{
80 if ( GetTextPeer()->CanClipMaxLength() )
81 GetTextPeer()->SetMaxLength(len);
82 m_maxLength = len ;
83}
84
85// Clipboard operations
86
87void wxTextEntry::Copy()
88{
89 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
90
91 if (CanCopy())
92 GetTextPeer()->Copy() ;
93}
94
95void wxTextEntry::Cut()
96{
97 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
98
99 if (CanCut())
100 GetTextPeer()->Cut() ;
101}
102
103void wxTextEntry::Paste()
104{
105 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
106
107 if (CanPaste())
108 GetTextPeer()->Paste() ;
109}
110
111bool wxTextEntry::CanCopy() const
112{
113 // Can copy if there's a selection
114 long from, to;
115 GetSelection( &from, &to );
116
117 return (from != to);
118}
119
120bool wxTextEntry::CanCut() const
121{
122 if ( !IsEditable() )
123 return false;
124
125 // Can cut if there's a selection
126 long from, to;
127 GetSelection( &from, &to );
128
129 return (from != to);
130}
131
132bool wxTextEntry::CanPaste() const
133{
134 if (!IsEditable())
135 return false;
136
137 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
138
139 return GetTextPeer()->CanPaste() ;
140}
141
142void wxTextEntry::SetEditable(bool editable)
143{
144 if ( editable == m_editable )
145 return;
146
147 m_editable = editable ;
148
149 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
150 GetTextPeer()->SetEditable( editable ) ;
151}
152
153void wxTextEntry::SetInsertionPoint(long pos)
154{
155 SetSelection( pos , pos ) ;
156}
157
158void wxTextEntry::SetInsertionPointEnd()
159{
160 long pos = GetLastPosition();
161 SetInsertionPoint( pos );
162}
163
164long wxTextEntry::GetInsertionPoint() const
165{
166 long begin, end ;
167 GetSelection( &begin , &end ) ;
168
169 return begin ;
170}
171
172wxTextPos wxTextEntry::GetLastPosition() const
173{
174 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
175
176 return GetTextPeer()->GetLastPosition() ;
177}
178
179void wxTextEntry::Remove(long from, long to)
180{
181 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
182
183 {
184 EventsSuppressor noevents(this);
185 GetTextPeer()->Remove( from , to );
186 }
187
188 SendTextUpdatedEventIfAllowed();
189}
190
191void wxTextEntry::SetSelection(long from, long to)
192{
193 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
194
195 GetTextPeer()->SetSelection( from , to ) ;
196}
197
198void wxTextEntry::WriteText(const wxString& str)
199{
200 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
201
202 {
203 EventsSuppressor noevents(this);
204 GetTextPeer()->WriteText( str );
205 }
206
207 SendTextUpdatedEventIfAllowed();
208}
209
210void wxTextEntry::Clear()
211{
212 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
213
214 {
215 EventsSuppressor noevents(this);
216 GetTextPeer()->Clear();
217 }
218
219 SendTextUpdatedEventIfAllowed();
220}
221
222bool wxTextEntry::IsEditable() const
223{
224 return m_editable ;
225}
226
227// ----------------------------------------------------------------------------
228// Undo/redo
229// ----------------------------------------------------------------------------
230
231void wxTextEntry::Undo()
232{
233 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
234
235 if (CanUndo())
236 GetTextPeer()->Undo() ;
237}
238
239void wxTextEntry::Redo()
240{
241 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
242
243 if (CanRedo())
244 GetTextPeer()->Redo() ;
245}
246
247bool wxTextEntry::CanUndo() const
248{
249 if ( !IsEditable() )
250 return false ;
251
252 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
253
254 return GetTextPeer()->CanUndo() ;
255}
256
257bool wxTextEntry::CanRedo() const
258{
259 if ( !IsEditable() )
260 return false ;
261
262 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
263
264 return GetTextPeer()->CanRedo() ;
265}
266
267wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
268{
269 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
270
271 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
272}
273
274// ----------------------------------------------------------------------------
275// Auto-completion
276// ----------------------------------------------------------------------------
277
278bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
279{
280 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
281 completer->SetCompletions(choices);
282
283 return DoAutoCompleteCustom(completer);
284}
285
286bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
287{
288 m_completer = completer;
289
290 return true;
291}
292
293#endif // wxUSE_TEXTCTRL