From b67dea6fc0602296ce5af6ea0012c2f6fdecd09e Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 18 May 2014 16:33:57 +0000 Subject: [PATCH] In order to get all focus set events, store field in editor and catch becomeFirstResponder there See #14269. (this is a backport of cea11b5 from master) --- include/wx/osx/cocoa/private.h | 2 ++ src/osx/cocoa/nonownedwnd.mm | 2 ++ src/osx/cocoa/textctrl.mm | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 94cca7d4df..0e263970fe 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -324,8 +324,10 @@ public: @interface wxNSTextFieldEditor : NSTextView { NSEvent* lastKeyDownEvent; + NSTextField* textField; } + - (void) setTextField:(NSTextField*) field; @end @interface wxNSTextField : NSTextField wxOSX_10_6_AND_LATER() diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 10ce0d23cf..666c63c6a7 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -507,6 +507,7 @@ extern int wxOSXGetIdFromSelector(SEL action ); { editor = [[wxNSTextFieldEditor alloc] init]; [editor setFieldEditor:YES]; + [editor setTextField:tf]; [tf setFieldEditor:editor]; [editor release]; } @@ -520,6 +521,7 @@ extern int wxOSXGetIdFromSelector(SEL action ); { editor = [[wxNSTextFieldEditor alloc] init]; [editor setFieldEditor:YES]; + [editor setTextField:cb]; [cb setFieldEditor:editor]; [editor release]; } diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index c8a968ec2e..a16023b024 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -298,6 +298,29 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; [super insertText:str]; } +- (BOOL) resignFirstResponder +{ + return [super resignFirstResponder]; +} + +- (BOOL) becomeFirstResponder +{ + // we need the stored text field, as at this point the delegate is not yet set + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( (WXWidget) textField ); + + BOOL r = [super becomeFirstResponder]; + if ( impl != NULL && r ) + impl->DoNotifyFocusSet(); + + return r; +} + +- (void) setTextField:(NSTextField*) field +{ + textField = field; +} + + @end @implementation wxNSTextView