Refactoring to common code for updating selections, using common focus

code

See #14269.

(this is a backport of e65104f from master)
This commit is contained in:
Stefan Csomor
2014-05-18 10:46:12 +00:00
committed by Dimitri Schoolwerth
parent 6749ca7405
commit 7dc6d1876e
3 changed files with 28 additions and 26 deletions

View File

@@ -48,7 +48,7 @@ public :
virtual bool resignFirstResponder(WXWidget slf, void *_cmd); virtual bool resignFirstResponder(WXWidget slf, void *_cmd);
virtual void SetInternalSelection( long from , long to ); virtual void SetInternalSelection( long from , long to );
virtual void UpdateInternalSelectionFromEditor( wxNSTextFieldEditor* editor);
protected : protected :
NSTextField* m_textField; NSTextField* m_textField;
long m_selStart; long m_selStart;

View File

@@ -90,6 +90,19 @@
} }
} }
- (void)controlTextDidEndEditing:(NSNotification *) aNotification
{
wxUnusedVar(aNotification);
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( impl )
{
wxNSTextFieldControl* timpl = dynamic_cast<wxNSTextFieldControl*>(impl);
if ( timpl )
timpl->UpdateInternalSelectionFromEditor(fieldEditor);
impl->DoNotifyFocusLost();
}
}
- (void)comboBoxWillPopUp:(NSNotification *)notification - (void)comboBoxWillPopUp:(NSNotification *)notification
{ {
wxUnusedVar(notification); wxUnusedVar(notification);

View File

@@ -196,13 +196,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
wxUnusedVar(aNotification); wxUnusedVar(aNotification);
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( impl ) if ( impl )
{ impl->DoNotifyFocusLost();
NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder();
NSView* otherView = wxOSXGetViewFromResponder(responder);
wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView);
impl->DoNotifyFocusEvent( false, otherWindow );
}
} }
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector - (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 ); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( impl ) if ( impl )
{ impl->DoNotifyFocusLost();
NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder();
NSView* otherView = wxOSXGetViewFromResponder(responder);
wxWidgetImpl* otherWindow = impl->FindBestFromWXWidget(otherView);
impl->DoNotifyFocusEvent( false, otherWindow );
}
} }
@end @end
@@ -528,17 +516,9 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
if ( impl ) if ( impl )
{ {
wxNSTextFieldControl* timpl = dynamic_cast<wxNSTextFieldControl*>(impl); wxNSTextFieldControl* timpl = dynamic_cast<wxNSTextFieldControl*>(impl);
if ( fieldEditor ) if ( timpl )
{ timpl->UpdateInternalSelectionFromEditor(fieldEditor);
NSRange range = [fieldEditor selectedRange]; impl->DoNotifyFocusLost();
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 );
} }
} }
@end @end
@@ -958,6 +938,15 @@ void wxNSTextFieldControl::SetInternalSelection( long from , long to )
m_selEnd = 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 // 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 // the resign notification writing back native selection values before we can set our own