]>
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
)
83 // Clipboard operations
85 void wxTextEntry::Copy()
87 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
90 GetTextPeer()->Copy() ;
93 void wxTextEntry::Cut()
95 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
98 GetTextPeer()->Cut() ;
101 void wxTextEntry::Paste()
103 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
106 GetTextPeer()->Paste() ;
109 bool wxTextEntry::CanCopy() const
111 // Can copy if there's a selection
113 GetSelection( &from
, &to
);
118 bool wxTextEntry::CanCut() const
123 // Can cut if there's a selection
125 GetSelection( &from
, &to
);
130 bool wxTextEntry::CanPaste() const
135 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
137 return GetTextPeer()->CanPaste() ;
140 void wxTextEntry::SetEditable(bool editable
)
142 if ( editable
== m_editable
)
145 m_editable
= editable
;
147 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
148 GetTextPeer()->SetEditable( editable
) ;
151 void wxTextEntry::SetInsertionPoint(long pos
)
153 SetSelection( pos
, pos
) ;
156 void wxTextEntry::SetInsertionPointEnd()
158 long pos
= GetLastPosition();
159 SetInsertionPoint( pos
);
162 long wxTextEntry::GetInsertionPoint() const
165 GetSelection( &begin
, &end
) ;
170 wxTextPos
wxTextEntry::GetLastPosition() const
172 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
174 return GetTextPeer()->GetLastPosition() ;
177 void wxTextEntry::Remove(long from
, long to
)
179 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
182 EventsSuppressor
noevents(this);
183 GetTextPeer()->Remove( from
, to
);
186 SendTextUpdatedEventIfAllowed();
189 void wxTextEntry::SetSelection(long from
, long to
)
191 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
193 GetTextPeer()->SetSelection( from
, to
) ;
196 void wxTextEntry::WriteText(const wxString
& str
)
198 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
201 EventsSuppressor
noevents(this);
202 GetTextPeer()->WriteText( str
);
205 SendTextUpdatedEventIfAllowed();
208 void wxTextEntry::Clear()
210 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
213 EventsSuppressor
noevents(this);
214 GetTextPeer()->Clear();
217 SendTextUpdatedEventIfAllowed();
220 bool wxTextEntry::IsEditable() const
225 // ----------------------------------------------------------------------------
227 // ----------------------------------------------------------------------------
229 void wxTextEntry::Undo()
231 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
234 GetTextPeer()->Undo() ;
237 void wxTextEntry::Redo()
239 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
242 GetTextPeer()->Redo() ;
245 bool wxTextEntry::CanUndo() const
250 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
252 return GetTextPeer()->CanUndo() ;
255 bool wxTextEntry::CanRedo() const
260 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
262 return GetTextPeer()->CanRedo() ;
265 wxTextWidgetImpl
* wxTextEntry::GetTextPeer() const
267 wxWindow
* const win
= const_cast<wxTextEntry
*>(this)->GetEditableWindow();
269 return win
? dynamic_cast<wxTextWidgetImpl
*>(win
->GetPeer()) : NULL
;
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
276 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString
& choices
)
278 wxTextCompleterFixed
* const completer
= new wxTextCompleterFixed
;
279 completer
->SetCompletions(choices
);
281 return DoAutoCompleteCustom(completer
);
284 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
*completer
)
286 m_completer
= completer
;
291 #endif // wxUSE_TEXTCTRL