From dcc9f9c1e465b45243fe8c7053933f70ff0d7c41 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 Oct 2013 18:15:29 +0000 Subject: [PATCH] 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 --- src/osx/cocoa/textctrl.mm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 16f9291271..bec0c44431 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -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