From eecf084d4d22ba7dd923adbc229741538f1ad521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 11 Jan 2017 16:46:32 +0100 Subject: [PATCH] Implement wxClipboardTextEvent support in wxOSX Emit wxEVT_TEXT_{COPY,CUT,PASTE} from NSTextView methods, calling native implementation if not handled. NSTextField-based wxTextCtrl is not supported, because it doesn't have the copy:/cut:/paste: methods. --- src/osx/cocoa/textctrl.mm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 50cca3f039..5b77fcdffe 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -448,6 +448,37 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; return NO; } +- (BOOL)_handleClipboardEvent:(wxEventType)type +{ + wxWidgetImpl *impl = wxWidgetImpl::FindFromWXWidget(self); + wxWindow* wxpeer = impl ? impl->GetWXPeer() : NULL; + if ( wxpeer ) + { + wxClipboardTextEvent evt(type, wxpeer->GetId()); + evt.SetEventObject(wxpeer); + return wxpeer->HandleWindowEvent(evt); + } + return false; +} + +- (void)copy:(id)sender +{ + if ( ![self _handleClipboardEvent:wxEVT_TEXT_COPY] ) + [super copy:sender]; +} + +- (void)cut:(id)sender +{ + if ( ![self _handleClipboardEvent:wxEVT_TEXT_CUT] ) + [super cut:sender]; +} + +- (void)paste:(id)sender +{ + if ( ![self _handleClipboardEvent:wxEVT_TEXT_PASTE] ) + [super paste:sender]; +} + @end @implementation wxNSTextField