From d9307d006e88025e28457290c9997f7c0f7c4fdc Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 10 May 2013 18:31:51 +0000 Subject: [PATCH] applying editor part of patch, see #15003 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 12 ++++++++++++ src/osx/cocoa/combobox.mm | 33 +++++++++++++++++++++++++++------ src/osx/cocoa/nonownedwnd.mm | 13 +++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 949558c335..aae5939607 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -341,6 +341,18 @@ public: @end + @interface wxNSComboBox : NSComboBox + { + wxNSTextFieldEditor* fieldEditor; + } + + - (wxNSTextFieldEditor*) fieldEditor; + - (void) setFieldEditor:(wxNSTextFieldEditor*) fieldEditor; + + @end + + + @interface wxNSMenu : NSMenu { wxMenuImpl* impl; diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index f001957006..c410bd23c4 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -36,12 +36,6 @@ @end -@interface wxNSComboBox : NSComboBox -{ -} - -@end - @implementation wxNSComboBox + (void)initialize @@ -54,6 +48,33 @@ } } +- (void) dealloc +{ + [fieldEditor release]; + [super dealloc]; +} + +// Over-riding NSComboBox onKeyDown method doesn't work for key events. +// Ensure that we can use our own wxNSTextFieldEditor to catch key events. +// See windowWillReturnFieldEditor in nonownedwnd.mm. +// Key events will be caught and handled via wxNSTextFieldEditor onkey... +// methods in textctrl.mm. + +- (void) setFieldEditor:(wxNSTextFieldEditor*) editor +{ + if ( editor != fieldEditor ) + { + [editor retain]; + [fieldEditor release]; + fieldEditor = editor; + } +} + +- (wxNSTextFieldEditor*) fieldEditor +{ + return fieldEditor; +} + - (void)controlTextDidChange:(NSNotification *)aNotification { wxUnusedVar(aNotification); diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 751dc10f73..bbba049d28 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -484,6 +484,19 @@ extern int wxOSXGetIdFromSelector(SEL action ); } return editor; } + else if ([anObject isKindOfClass:[wxNSComboBox class]]) + { + wxNSComboBox * cb = (wxNSComboBox*) anObject; + wxNSTextFieldEditor* editor = [cb fieldEditor]; + if ( editor == nil ) + { + editor = [[wxNSTextFieldEditor alloc] init]; + [editor setFieldEditor:YES]; + [cb setFieldEditor:editor]; + [editor release]; + } + return editor; + } return nil; } -- 2.45.2