]>
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 bool wxTextEntry::SendMaxLenEvent()
229 wxWindow
*win
= GetEditableWindow();
230 wxCHECK_MSG( win
, false, "can't send an event without a window" );
232 wxCommandEvent
event(wxEVT_TEXT_MAXLEN
, win
->GetId());
234 // do not do this as it could be very inefficient if the text control
235 // contains a lot of text and we're not using ref-counted wxString
236 // implementation -- instead, event.GetString() will query the control for
237 // its current text if needed
238 //event.SetString(win->GetValue());
240 event
.SetEventObject(win
);
241 return win
->HandleWindowEvent(event
);
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 void wxTextEntry::Undo()
250 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
253 GetTextPeer()->Undo() ;
256 void wxTextEntry::Redo()
258 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
261 GetTextPeer()->Redo() ;
264 bool wxTextEntry::CanUndo() const
269 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
271 return GetTextPeer()->CanUndo() ;
274 bool wxTextEntry::CanRedo() const
279 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
281 return GetTextPeer()->CanRedo() ;
284 wxTextWidgetImpl
* wxTextEntry::GetTextPeer() const
286 wxWindow
* const win
= const_cast<wxTextEntry
*>(this)->GetEditableWindow();
288 return win
? dynamic_cast<wxTextWidgetImpl
*>(win
->GetPeer()) : NULL
;
291 // ----------------------------------------------------------------------------
293 // ----------------------------------------------------------------------------
295 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString
& choices
)
297 wxTextCompleterFixed
* const completer
= new wxTextCompleterFixed
;
298 completer
->SetCompletions(choices
);
300 return DoAutoCompleteCustom(completer
);
303 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
*completer
)
305 m_completer
= completer
;
310 #endif // wxUSE_TEXTCTRL