From 7dc6d1876eb0db68d85655a8049995f74f7a251a Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 18 May 2014 10:46:12 +0000 Subject: [PATCH] Refactoring to common code for updating selections, using common focus code See #14269. (this is a backport of e65104f from master) --- include/wx/osx/cocoa/private/textimpl.h | 2 +- src/osx/cocoa/combobox.mm | 13 +++++++++ src/osx/cocoa/textctrl.mm | 39 +++++++++---------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 767f31cddb..47d2565119 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -48,7 +48,7 @@ public : virtual bool resignFirstResponder(WXWidget slf, void *_cmd); virtual void SetInternalSelection( long from , long to ); - + virtual void UpdateInternalSelectionFromEditor( wxNSTextFieldEditor* editor); protected : NSTextField* m_textField; long m_selStart; diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index 37e9c5d9fe..fbaec3fb74 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -90,6 +90,19 @@ } } +- (void)controlTextDidEndEditing:(NSNotification *) aNotification +{ + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if ( impl ) + { + wxNSTextFieldControl* timpl = dynamic_cast(impl); + if ( timpl ) + timpl->UpdateInternalSelectionFromEditor(fieldEditor); + impl->DoNotifyFocusLost(); + } +} + - (void)comboBoxWillPopUp:(NSNotification *)notification { wxUnusedVar(notification); diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index bec0c44431..c8a968ec2e 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -196,13 +196,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; wxUnusedVar(aNotification); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) - { - NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = wxOSXGetViewFromResponder(responder); - - wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); - impl->DoNotifyFocusEvent( false, otherWindow ); - } + impl->DoNotifyFocusLost(); } - (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector @@ -359,13 +353,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) - { - NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = wxOSXGetViewFromResponder(responder); - - wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); - impl->DoNotifyFocusEvent( false, otherWindow ); - } + impl->DoNotifyFocusLost(); } @end @@ -528,17 +516,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; if ( impl ) { wxNSTextFieldControl* timpl = dynamic_cast(impl); - if ( fieldEditor ) - { - NSRange range = [fieldEditor selectedRange]; - timpl->SetInternalSelection(range.location, range.location + range.length); - } - - NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder(); - NSView* otherView = wxOSXGetViewFromResponder(responder); - - wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView); - impl->DoNotifyFocusEvent( false, otherWindow ); + if ( timpl ) + timpl->UpdateInternalSelectionFromEditor(fieldEditor); + impl->DoNotifyFocusLost(); } } @end @@ -958,6 +938,15 @@ void wxNSTextFieldControl::SetInternalSelection( long from , long to ) m_selEnd = to; } +void wxNSTextFieldControl::UpdateInternalSelectionFromEditor( wxNSTextFieldEditor* fieldEditor ) +{ + if ( fieldEditor ) + { + NSRange range = [fieldEditor selectedRange]; + SetInternalSelection(range.location, range.location + range.length); + } +} + // 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