]> git.saurik.com Git - wxWidgets.git/blame - src/osx/textentry_osx.cpp
Fixed wxMessageBox with only an OK button returning wxCANCEL under MSW.
[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{
66 return GetTextPeer()->GetStringValue() ;
67}
68
69void wxTextEntry::GetSelection(long* from, long* to) const
70{
71 GetTextPeer()->GetSelection( from , to ) ;
72}
73
74void wxTextEntry::SetMaxLength(unsigned long len)
75{
76 m_maxLength = len ;
77}
78
79// Clipboard operations
80
81void wxTextEntry::Copy()
82{
83 if (CanCopy())
84 GetTextPeer()->Copy() ;
85}
86
87void wxTextEntry::Cut()
88{
89 if (CanCut())
90 GetTextPeer()->Cut() ;
91}
92
93void wxTextEntry::Paste()
94{
95 if (CanPaste())
96 GetTextPeer()->Paste() ;
97}
98
99bool wxTextEntry::CanCopy() const
100{
101 // Can copy if there's a selection
102 long from, to;
103 GetSelection( &from, &to );
104
105 return (from != to);
106}
107
108bool wxTextEntry::CanCut() const
109{
110 if ( !IsEditable() )
111 return false;
112
113 // Can cut if there's a selection
114 long from, to;
115 GetSelection( &from, &to );
116
117 return (from != to);
118}
119
120bool wxTextEntry::CanPaste() const
121{
122 if (!IsEditable())
123 return false;
124
125 return GetTextPeer()->CanPaste() ;
126}
127
128void wxTextEntry::SetEditable(bool editable)
129{
130 if ( editable != m_editable )
131 {
132 m_editable = editable ;
133 GetTextPeer()->SetEditable( editable ) ;
134 }
135}
136
137void wxTextEntry::SetInsertionPoint(long pos)
138{
139 SetSelection( pos , pos ) ;
140}
141
142void wxTextEntry::SetInsertionPointEnd()
143{
144 long pos = GetLastPosition();
145 SetInsertionPoint( pos );
146}
147
148long wxTextEntry::GetInsertionPoint() const
149{
150 long begin, end ;
151 GetSelection( &begin , &end ) ;
152
153 return begin ;
154}
155
156wxTextPos wxTextEntry::GetLastPosition() const
157{
158 return GetTextPeer()->GetLastPosition() ;
159}
160
161void wxTextEntry::Remove(long from, long to)
162{
4275201b
SC
163 {
164 EventsSuppressor noevents(this);
165 GetTextPeer()->Remove( from , to );
166 }
ce00f59b 167
e567904a 168 SendTextUpdatedEventIfAllowed();
c84030e0
KO
169}
170
171void wxTextEntry::SetSelection(long from, long to)
172{
173 GetTextPeer()->SetSelection( from , to ) ;
174}
175
176void wxTextEntry::WriteText(const wxString& str)
177{
4275201b
SC
178 {
179 EventsSuppressor noevents(this);
180 GetTextPeer()->WriteText( str );
181 }
e567904a
VZ
182
183 SendTextUpdatedEventIfAllowed();
c84030e0
KO
184}
185
186void wxTextEntry::Clear()
187{
4275201b
SC
188 {
189 EventsSuppressor noevents(this);
190 GetTextPeer()->Clear();
191 }
e567904a
VZ
192
193 SendTextUpdatedEventIfAllowed();
c84030e0
KO
194}
195
196bool wxTextEntry::IsEditable() const
197{
198 return m_editable ;
199}
200
201// ----------------------------------------------------------------------------
202// Undo/redo
203// ----------------------------------------------------------------------------
204
205void wxTextEntry::Undo()
206{
207 if (CanUndo())
208 GetTextPeer()->Undo() ;
209}
210
211void wxTextEntry::Redo()
212{
213 if (CanRedo())
214 GetTextPeer()->Redo() ;
215}
216
217bool wxTextEntry::CanUndo() const
218{
219 if ( !IsEditable() )
220 return false ;
221
222 return GetTextPeer()->CanUndo() ;
223}
224
225bool wxTextEntry::CanRedo() const
226{
227 if ( !IsEditable() )
228 return false ;
229
230 return GetTextPeer()->CanRedo() ;
231}
232
233wxTextWidgetImpl * wxTextEntry::GetTextPeer() const
234{
005ac806
VZ
235 wxWindow * const win = const_cast<wxTextEntry *>(this)->GetEditableWindow();
236
237 return win ? dynamic_cast<wxTextWidgetImpl *>(win->GetPeer()) : NULL;
c84030e0 238}
005ac806 239
c729f16f
VZ
240// ----------------------------------------------------------------------------
241// Auto-completion
242// ----------------------------------------------------------------------------
243
244bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices)
245{
246 wxTextCompleterFixed * const completer = new wxTextCompleterFixed;
247 completer->SetCompletions(choices);
248
249 return DoAutoCompleteCustom(completer);
250}
251
252bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer)
253{
254 m_completer = completer;
255
256 return true;
257}
258
c84030e0 259#endif // wxUSE_TEXTCTRL