From 75a2c6a1ee034a5d866b4a121a97351603bce98b Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Sat, 6 Feb 2010 17:00:38 +0000 Subject: [PATCH] Get wxSearchCtrl text events working, and share the text event handler code among all the various wxTextCtrl-based classes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63415 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 4 ++++ src/osx/cocoa/srchctrl.mm | 8 ++++++++ src/osx/cocoa/textctrl.mm | 33 +++++---------------------------- src/osx/cocoa/window.mm | 13 +++++++++++++ 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index f7ee0900a4..6255662319 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -173,6 +173,10 @@ public : virtual void controlAction(WXWidget slf, void* _cmd, void* sender); virtual void controlDoubleAction(WXWidget slf, void* _cmd, void *sender); + + // for wxTextCtrl-derived classes, put here since they don't all derive + // from the same pimpl class. + virtual void controlTextDidChange(); protected: WXWidget m_osxView; diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index 399729c183..e98a3cf7f3 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -77,6 +77,14 @@ } } +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); + if ( impl ) + impl->controlTextDidChange(); +} + @end // ============================================================================ diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index c288d78703..1f10089116 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -96,15 +96,7 @@ protected : wxUnusedVar(aNotification); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) - { - wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); - if ( wxpeer ) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); - event.SetEventObject( wxpeer ); - event.SetString( static_cast(wxpeer)->GetValue() ); - wxpeer->HandleWindowEvent( event ); - } - } + impl->controlTextDidChange(); } - (void)controlTextDidEndEditing:(NSNotification *)aNotification @@ -194,17 +186,10 @@ protected : - (void)textDidChange:(NSNotification *)aNotification { - wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( [aNotification object] ); + wxUnusedVar(aNotification); + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) - { - wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); - if ( wxpeer ) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); - event.SetEventObject( wxpeer ); - event.SetString( static_cast(wxpeer)->GetValue() ); - wxpeer->HandleWindowEvent( event ); - } - } + impl->controlTextDidChange(); } @end @@ -266,15 +251,7 @@ protected : wxUnusedVar(aNotification); wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); if ( impl ) - { - wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); - if ( wxpeer ) { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); - event.SetEventObject( wxpeer ); - event.SetString( static_cast(wxpeer)->GetValue() ); - wxpeer->HandleWindowEvent( event ); - } - } + impl->controlTextDidChange(); } typedef BOOL (*wxOSX_insertNewlineHandlerPtr)(NSView* self, SEL _cmd, NSControl *control, NSTextView* textView, SEL commandSelector); diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 3154e3fe2c..8ab72ea342 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -15,6 +15,7 @@ #include "wx/dcclient.h" #include "wx/nonownedwnd.h" #include "wx/log.h" + #include "wx/textctrl.h" #endif #ifdef __WXMAC__ @@ -1123,6 +1124,18 @@ void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNU { } +void wxWidgetCocoaImpl::controlTextDidChange() +{ + wxWindow* wxpeer = (wxWindow*)GetWXPeer(); + if ( wxpeer ) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( static_cast(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } +} + // #if OBJC_API_VERSION >= 2