]> git.saurik.com Git - wxWidgets.git/blame - src/osx/textentry_osx.cpp
Rename CreateWindow() to CreateDialog() in generic wxPreferencesEditor code.
[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{
a39815bd
SC
80 if ( GetTextPeer()->CanClipMaxLength() )
81 GetTextPeer()->SetMaxLength(len);
c84030e0
KO
82 m_maxLength = len ;
83}
84
85// Clipboard operations
86
87void wxTextEntry::Copy()
88{
da8eb5f5
VZ
89 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
90
c84030e0
KO
91 if (CanCopy())
92 GetTextPeer()->Copy() ;
93}
94
95void wxTextEntry::Cut()
96{
da8eb5f5
VZ
97 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
98
c84030e0
KO
99 if (CanCut())
100 GetTextPeer()->Cut() ;
101}
102
103void wxTextEntry::Paste()
104{
da8eb5f5
VZ
105 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
106
c84030e0
KO
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
da8eb5f5
VZ
137 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
138
c84030e0
KO
139 return GetTextPeer()->CanPaste() ;
140}
141
142void wxTextEntry::SetEditable(bool editable)
143{
da8eb5f5
VZ
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 ) ;
c84030e0
KO
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{
da8eb5f5
VZ
174 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
175
c84030e0
KO
176 return GetTextPeer()->GetLastPosition() ;
177}
178
179void wxTextEntry::Remove(long from, long to)
180{
da8eb5f5
VZ
181 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
182
4275201b
SC
183 {
184 EventsSuppressor noevents(this);
185 GetTextPeer()->Remove( from , to );
186 }
ce00f59b 187
e567904a 188 SendTextUpdatedEventIfAllowed();
c84030e0
KO
189}
190
191void wxTextEntry::SetSelection(long from, long to)
192{
da8eb5f5
VZ
193 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
194
c84030e0
KO
195 GetTextPeer()->SetSelection( from , to ) ;
196}
197
198void wxTextEntry::WriteText(const wxString& str)
199{
da8eb5f5
VZ
200 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
201
4275201b
SC
202 {
203 EventsSuppressor noevents(this);
204 GetTextPeer()->WriteText( str );
205 }
e567904a
VZ
206
207 SendTextUpdatedEventIfAllowed();
c84030e0
KO
208}
209
210void wxTextEntry::Clear()
211{
da8eb5f5
VZ
212 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
213
4275201b
SC
214 {
215 EventsSuppressor noevents(this);
216 GetTextPeer()->Clear();
217 }
e567904a
VZ
218
219 SendTextUpdatedEventIfAllowed();
c84030e0
KO
220}
221
222bool wxTextEntry::IsEditable() const
223{
224 return m_editable ;
225}
226
227// ----------------------------------------------------------------------------
228// Undo/redo
229// ----------------------------------------------------------------------------
230
231void wxTextEntry::Undo()
232{
da8eb5f5
VZ
233 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
234
c84030e0
KO
235 if (CanUndo())
236 GetTextPeer()->Undo() ;
237}
238
239void wxTextEntry::Redo()
240{
da8eb5f5
VZ
241 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
242
c84030e0
KO
243 if (CanRedo())
244 GetTextPeer()->Redo() ;
245}
246
247bool wxTextEntry::CanUndo() const
248{
249 if ( !IsEditable() )
250 return false ;
251
da8eb5f5
VZ
252 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
253
c84030e0
KO
254 return GetTextPeer()->CanUndo() ;
255}
256
257bool wxTextEntry::CanRedo() const
258{
259 if ( !IsEditable() )
260 return false ;
261
da8eb5f5
VZ
262 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
263
c84030e0
KO
264 return GetTextPeer()->CanRedo() ;
265}
266
267wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
268{
005ac806
VZ
269 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
270
271 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
c84030e0 272}
005ac806 273
c729f16f
VZ
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
c84030e0 293#endif // wxUSE_TEXTCTRL