]>
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
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/textctrl.h"
22 #include "wx/button.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/toplevel.h"
30 #include <sys/types.h>
36 #if wxUSE_STD_IOSTREAM
44 #include "wx/filefn.h"
45 #include "wx/sysopt.h"
46 #include "wx/thread.h"
47 #include "wx/textcompleter.h"
49 #include "wx/osx/private.h"
51 wxTextEntry::wxTextEntry()
58 wxTextEntry::~wxTextEntry()
63 wxString
wxTextEntry::DoGetValue() const
65 wxCHECK_MSG( GetTextPeer(), wxString(), "Must create the control first" );
67 return GetTextPeer()->GetStringValue() ;
70 void wxTextEntry::GetSelection(long* from
, long* to
) const
72 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
74 GetTextPeer()->GetSelection( from
, to
) ;
77 void wxTextEntry::SetMaxLength(unsigned long len
)
79 if ( GetTextPeer()->CanClipMaxLength() )
80 GetTextPeer()->SetMaxLength(len
);
84 // Clipboard operations
86 void wxTextEntry::Copy()
88 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
91 GetTextPeer()->Copy() ;
94 void wxTextEntry::Cut()
96 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
99 GetTextPeer()->Cut() ;
102 void wxTextEntry::Paste()
104 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
107 GetTextPeer()->Paste() ;
110 bool wxTextEntry::CanCopy() const
112 // Can copy if there's a selection
114 GetSelection( &from
, &to
);
119 bool wxTextEntry::CanCut() const
124 // Can cut if there's a selection
126 GetSelection( &from
, &to
);
131 bool wxTextEntry::CanPaste() const
136 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
138 return GetTextPeer()->CanPaste() ;
141 void wxTextEntry::SetEditable(bool editable
)
143 if ( editable
== m_editable
)
146 m_editable
= editable
;
148 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
149 GetTextPeer()->SetEditable( editable
) ;
152 void wxTextEntry::SetInsertionPoint(long pos
)
154 SetSelection( pos
, pos
) ;
157 void wxTextEntry::SetInsertionPointEnd()
159 long pos
= GetLastPosition();
160 SetInsertionPoint( pos
);
163 long wxTextEntry::GetInsertionPoint() const
166 GetSelection( &begin
, &end
) ;
171 wxTextPos
wxTextEntry::GetLastPosition() const
173 wxCHECK_MSG( GetTextPeer(), -1, "Must create the control first" );
175 return GetTextPeer()->GetLastPosition() ;
178 void wxTextEntry::Remove(long from
, long to
)
180 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
183 EventsSuppressor
noevents(this);
184 GetTextPeer()->Remove( from
, to
);
187 SendTextUpdatedEventIfAllowed();
190 void wxTextEntry::SetSelection(long from
, long to
)
192 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
194 GetTextPeer()->SetSelection( from
, to
) ;
197 void wxTextEntry::WriteText(const wxString
& str
)
199 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
202 EventsSuppressor
noevents(this);
203 GetTextPeer()->WriteText( str
);
206 SendTextUpdatedEventIfAllowed();
209 void wxTextEntry::Clear()
211 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
214 EventsSuppressor
noevents(this);
215 GetTextPeer()->Clear();
218 SendTextUpdatedEventIfAllowed();
221 bool wxTextEntry::IsEditable() const
226 bool wxTextEntry::SendMaxLenEvent()
228 wxWindow
*win
= GetEditableWindow();
229 wxCHECK_MSG( win
, false, "can't send an event without a window" );
231 wxCommandEvent
event(wxEVT_TEXT_MAXLEN
, win
->GetId());
233 // do not do this as it could be very inefficient if the text control
234 // contains a lot of text and we're not using ref-counted wxString
235 // implementation -- instead, event.GetString() will query the control for
236 // its current text if needed
237 //event.SetString(win->GetValue());
239 event
.SetEventObject(win
);
240 return win
->HandleWindowEvent(event
);
243 // ----------------------------------------------------------------------------
245 // ----------------------------------------------------------------------------
247 void wxTextEntry::Undo()
249 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
252 GetTextPeer()->Undo() ;
255 void wxTextEntry::Redo()
257 wxCHECK_RET( GetTextPeer(), "Must create the control first" );
260 GetTextPeer()->Redo() ;
263 bool wxTextEntry::CanUndo() const
268 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
270 return GetTextPeer()->CanUndo() ;
273 bool wxTextEntry::CanRedo() const
278 wxCHECK_MSG( GetTextPeer(), false, "Must create the control first" );
280 return GetTextPeer()->CanRedo() ;
283 wxTextWidgetImpl
* wxTextEntry::GetTextPeer() const
285 wxWindow
* const win
= const_cast<wxTextEntry
*>(this)->GetEditableWindow();
287 return win
? dynamic_cast<wxTextWidgetImpl
*>(win
->GetPeer()) : NULL
;
290 // ----------------------------------------------------------------------------
292 // ----------------------------------------------------------------------------
294 bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString
& choices
)
296 wxTextCompleterFixed
* const completer
= new wxTextCompleterFixed
;
297 completer
->SetCompletions(choices
);
299 return DoAutoCompleteCustom(completer
);
302 bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter
*completer
)
304 m_completer
= completer
;
309 #endif // wxUSE_TEXTCTRL