Browse Source

Handle paste, copy, cut events which come from plug-in hosts

tags/2021-05-28
hogliux 10 years ago
parent
commit
9510c16665
3 changed files with 25 additions and 4 deletions
  1. +11
    -0
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  2. +9
    -4
      modules/juce_gui_basics/windows/juce_ComponentPeer.cpp
  3. +5
    -0
      modules/juce_gui_basics/windows/juce_ComponentPeer.h

+ 11
- 0
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -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 <NSView>
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; }


+ 9
- 4
modules/juce_gui_basics/windows/juce_ComponentPeer.cpp View File

@@ -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())
{


+ 5
- 0
modules/juce_gui_basics/windows/juce_ComponentPeer.h View File

@@ -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.
*/


Loading…
Cancel
Save