]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/textentry_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/textentry_osx.cpp
3 // Purpose: wxTextEntry
4 // Author: Stefan Csomor
5 // Modified by: Kevin Ollivier
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/textctrl.h"
23 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
31 #include <sys/types.h>
37 #if wxUSE_STD_IOSTREAM
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
48 #include "wx/textcompleter.h"
50 #include "wx/osx/private.h"
52 wxTextEntry::wxTextEntry()
59 wxTextEntry::~wxTextEntry()
64 wxString
wxTextEntry::DoGetValue() const
66 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
68 return GetTextPeer()->GetStringValue() ;
71 void wxTextEntry::GetSelection(long* from
, long* to
) const
73 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
75 GetTextPeer()->GetSelection( from
, to
) ;
78 void wxTextEntry::SetMaxLength(unsigned long len
)
80 if ( GetTextPeer()->CanClipMaxLength() )
81 GetTextPeer()->SetMaxLength(len
);
85 // Clipboard operations
87 void wxTextEntry::Copy()
89 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
92 GetTextPeer()->Copy() ;
95 void wxTextEntry::Cut()
97 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
100 GetTextPeer()->Cut() ;
103 void wxTextEntry::Paste()
105 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
108 GetTextPeer()->Paste() ;
111 bool wxTextEntry::CanCopy() const
113 // Can copy if there's a selection
115 GetSelection( &from
, &to
);
120 bool wxTextEntry::CanCut() const
125 // Can cut if there's a selection
127 GetSelection( &from
, &to
);
132 bool wxTextEntry::CanPaste() const
137 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
139 return GetTextPeer()->CanPaste() ;
142 void wxTextEntry::SetEditable(bool editable
)
144 if ( editable
== m_editable
)
147 m_editable
= editable
;
149 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
150 GetTextPeer()->SetEditable( editable
) ;
153 void wxTextEntry::SetInsertionPoint(long pos
)
155 SetSelection( pos
, pos
) ;
158 void wxTextEntry::SetInsertionPointEnd()
160 long pos
= GetLastPosition();
161 SetInsertionPoint( pos
);
164 long wxTextEntry::GetInsertionPoint() const
167 GetSelection( &begin
, &end
) ;
172 wxTextPos
wxTextEntry::GetLastPosition() const
174 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
176 return GetTextPeer()->GetLastPosition() ;
179 void wxTextEntry::Remove(long from
, long to
)
181 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
184 EventsSuppressor
noevents(this);
185 GetTextPeer()->Remove( from
, to
);
188 SendTextUpdatedEventIfAllowed();
191 void wxTextEntry::SetSelection(long from
, long to
)
193 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
195 GetTextPeer()->SetSelection( from
, to
) ;
198 void wxTextEntry::WriteText(const wxString
& str
)
200 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
203 EventsSuppressor
noevents(this);
204 GetTextPeer()->WriteText( str
);
207 SendTextUpdatedEventIfAllowed();
210 void wxTextEntry::Clear()
212 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
215 EventsSuppressor
noevents(this);
216 GetTextPeer()->Clear();
219 SendTextUpdatedEventIfAllowed();
222 bool wxTextEntry::IsEditable() const
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
231 void wxTextEntry::Undo()
233 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
236 GetTextPeer()->Undo() ;
239 void wxTextEntry::Redo()
241 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
244 GetTextPeer()->Redo() ;
247 bool wxTextEntry::CanUndo() const
252 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
254 return GetTextPeer()->CanUndo() ;
257 bool wxTextEntry::CanRedo() const
262 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
264 return GetTextPeer()->CanRedo() ;
267 wxTextWidgetImpl
* wxTextEntry::GetTextPeer() const
269 wxWindow
* const win
= const_cast<wxTextEntry
*>(this)->GetEditableWindow();
271 return win
? dynamic_cast<wxTextWidgetImpl
*>(win
->GetPeer()) : NULL
;
274 // ----------------------------------------------------------------------------
276 // ----------------------------------------------------------------------------
278 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString
& choices
)
280 wxTextCompleterFixed
* const completer
= new wxTextCompleterFixed
;
281 completer
->SetCompletions(choices
);
283 return DoAutoCompleteCustom(completer
);
286 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
*completer
)
288 m_completer
= completer
;
293 #endif // wxUSE_TEXTCTRL