+void wxNSTextFieldControl::SetInternalSelection( long from , long to )
+{
+ m_selStart = from;
+ m_selEnd = to;
+}
+
+// as becoming first responder on a window - triggers a resign on the same control, we have to avoid
+// the resign notification writing back native selection values before we can set our own
+
+static WXWidget s_widgetBecomingFirstResponder = nil;
+
+bool wxNSTextFieldControl::becomeFirstResponder(WXWidget slf, void *_cmd)
+{
+ s_widgetBecomingFirstResponder = slf;
+ bool retval = wxWidgetCocoaImpl::becomeFirstResponder(slf, _cmd);
+ s_widgetBecomingFirstResponder = nil;
+ if ( retval )
+ {
+ NSText* editor = [m_textField currentEditor];
+ if ( editor )
+ {
+ long textLength = [[m_textField stringValue] length];
+ m_selStart = wxMin(textLength,wxMax(m_selStart,0)) ;
+ m_selEnd = wxMax(0,wxMin(textLength,m_selEnd)) ;
+
+ [editor setSelectedRange:NSMakeRange(m_selStart, m_selEnd-m_selStart)];
+ }
+ }
+ return retval;
+}
+
+bool wxNSTextFieldControl::resignFirstResponder(WXWidget slf, void *_cmd)
+{
+ if ( slf != s_widgetBecomingFirstResponder )
+ {
+ NSText* editor = [m_textField currentEditor];
+ if ( editor )
+ {
+ NSRange range = [editor selectedRange];
+ m_selStart = range.location;
+ m_selEnd = range.location + range.length;
+ }
+ }
+ return wxWidgetCocoaImpl::resignFirstResponder(slf, _cmd);
+}
+
+bool wxNSTextFieldControl::SetHint(const wxString& hint)
+{
+ wxCFStringRef hintstring(hint);
+ [[m_textField cell] setPlaceholderString:hintstring.AsNSString()];
+ return true;
+}
+