diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index b9b9a2b692..8bfee01d02 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -661,6 +661,10 @@ public: (void) ev; } + void redirectCopy (NSObject*) { handleKeyPress (KeyPress ('c', ModifierKeys (ModifierKeys::commandModifier), 'c')); } + void redirectPaste (NSObject*) { handleKeyPress (KeyPress ('v', ModifierKeys (ModifierKeys::commandModifier), 'v')); } + void redirectCut (NSObject*) { handleKeyPress (KeyPress ('x', ModifierKeys (ModifierKeys::commandModifier), 'x')); } + void sendMouseEvent (NSEvent* ev) { updateModifiers (ev); @@ -1458,6 +1462,10 @@ struct JuceNSViewClass : public ObjCClass addMethod (@selector (performDragOperation:), performDragOperation, "c@:@"); addMethod (@selector (concludeDragOperation:), concludeDragOperation, "v@:@"); + addMethod (@selector (paste:), paste, "v@:@"); + addMethod (@selector (copy:), copy, "v@:@"); + addMethod (@selector (cut:), cut, "v@:@"); + addProtocol (@protocol (NSTextInput)); registerClass(); @@ -1503,6 +1511,9 @@ private: static void mouseExited (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseExit (ev); } static void scrollWheel (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMouseWheel (ev); } static void magnify (id self, SEL, NSEvent* ev) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectMagnify (ev); } + static void copy (id self, SEL, NSObject* s) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectCopy (s); } + static void paste (id self, SEL, NSObject* s) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectPaste (s); } + static void cut (id self, SEL, NSObject* s) { if (NSViewComponentPeer* const p = getOwner (self)) p->redirectCut (s); } static BOOL acceptsFirstMouse (id, SEL, NSEvent*) { return YES; } diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp index cb71b21985..70b3d9662d 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp @@ -177,11 +177,16 @@ Component* ComponentPeer::getTargetForKeyPress() bool ComponentPeer::handleKeyPress (const int keyCode, const juce_wchar textCharacter) { ModifierKeys::updateCurrentModifiers(); - bool keyWasUsed = false; - const KeyPress keyInfo (keyCode, - ModifierKeys::getCurrentModifiers().withoutMouseButtons(), - textCharacter); + return handleKeyPress (KeyPress (keyCode, + ModifierKeys::getCurrentModifiers().withoutMouseButtons(), + textCharacter)); +} + + +bool ComponentPeer::handleKeyPress (const KeyPress& keyInfo) +{ + bool keyWasUsed = false; for (Component* target = getTargetForKeyPress(); target != nullptr; target = target->getParentComponent()) { diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.h b/modules/juce_gui_basics/windows/juce_ComponentPeer.h index a79a1fbd06..4277618991 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.h +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.h @@ -269,6 +269,11 @@ public: */ bool handleKeyPress (int keyCode, juce_wchar textCharacter); + /** Called when a key is pressed. + Returns true if the keystroke was used. + */ + bool handleKeyPress (const KeyPress& key); + /** Called whenever a key is pressed or released. Returns true if the keystroke was used. */