Avoid sending wxEVT_CHAR events when text is inserted by the program in wxOSX.

This should fix crashes due to infinite recursion in the code that calls
wxTextCtrl::WriteText() from wxEVT_CHAR handler.

Closes #15345.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-10-18 18:15:29 +00:00
parent 8750905b8b
commit dcc9f9c1e4

View File

@@ -96,6 +96,12 @@ public :
return v == ms_viewCurrentlyEdited;
}
// Returns true if this editor is the one currently being modified.
static bool IsCurrentEditor(wxNSTextFieldEditor* e)
{
return e == [(NSTextField*)ms_viewCurrentlyEdited currentEditor];
}
protected :
BOOL m_formerEditable ;
BOOL m_formerSelectable;
@@ -286,11 +292,16 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
- (void) insertText:(id) str
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
if ( impl == NULL || lastKeyDownEvent==nil || !impl->DoHandleCharEvent(lastKeyDownEvent, str) )
// We should never generate char events for the text being inserted
// programmatically.
if ( !wxMacEditHelper::IsCurrentEditor(self) )
{
[super insertText:str];
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) [self delegate] );
if ( impl && lastKeyDownEvent && impl->DoHandleCharEvent(lastKeyDownEvent, str) )
return;
}
[super insertText:str];
}
@end