From 715b3df02f73174c67c05d29708a578ad60e64fd Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 10 Aug 2007 18:40:56 +0000 Subject: [PATCH] Tell NSTextField to send us its action message and respond to it so we can generate wxEVT_COMMAND_TEXT_ENTER. Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48007 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/textctrl.h | 1 + src/cocoa/textctrl.mm | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/wx/cocoa/textctrl.h b/include/wx/cocoa/textctrl.h index 4adacb0..290ac2a 100644 --- a/include/wx/cocoa/textctrl.h +++ b/include/wx/cocoa/textctrl.h @@ -50,6 +50,7 @@ public: // ------------------------------------------------------------------------ protected: virtual void Cocoa_didChangeText(void); + virtual void CocoaTarget_action(void); // ------------------------------------------------------------------------ // Implementation // ------------------------------------------------------------------------ diff --git a/src/cocoa/textctrl.mm b/src/cocoa/textctrl.mm index d755334..cbab8ea 100644 --- a/src/cocoa/textctrl.mm +++ b/src/cocoa/textctrl.mm @@ -59,6 +59,10 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid, if(m_parent) m_parent->CocoaAddChild(this); SetInitialFrameRect(pos,size); + + [(NSTextField*)m_cocoaNSView setTarget: sm_cocoaTarget]; + [(NSTextField*)m_cocoaNSView setAction:@selector(wxNSControlAction:)]; + return true; } @@ -71,6 +75,19 @@ void wxTextCtrl::Cocoa_didChangeText(void) { } +void wxTextCtrl::CocoaTarget_action(void) +{ + // NSTextField only sends the action message on enter key press and thus + // we send the appropriate event type. + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId()); + + // See wxTextCtrlBase::SendTextUpdatedEvent for why we don't set the string. + //event.SetString(GetValue()); + + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); +} + void wxTextCtrl::AppendText(wxString const&) { } -- 2.7.4