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:
committed by
Dimitri Schoolwerth
parent
6749ca7405
commit
7dc6d1876e
@@ -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;
|
||||
|
@@ -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
|
||||
{
|
||||
wxUnusedVar(notification);
|
||||
|
@@ -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<wxNSTextFieldControl*>(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
|
||||
|
||||
|
Reference in New Issue
Block a user