From 059ce355597c349712a2e1a23a051e84c02aabe0 Mon Sep 17 00:00:00 2001 From: tpoole Date: Thu, 23 Feb 2017 18:09:26 +0000 Subject: [PATCH] Fixed a bug in an Objective-C drag and drop helper class --- .../mouse/juce_DragAndDropContainer.h | 4 +- .../native/juce_mac_Windowing.mm | 37 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h index 69bc5ca22f..8358776334 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h @@ -129,8 +129,8 @@ public: @param files a list of filenames to drag @param canMoveFiles if true, the app that receives the files is allowed to move the files to a new location (if this is appropriate). If false, the receiver is expected to make a copy of them. - @returns true if the files were successfully dropped somewhere, or false if it - was interrupted + @returns true if the files were successfully dropped somewhere, or false if it + was interrupted @see performExternalDragDropOfText */ static bool performExternalDragDropOfFiles (const StringArray& files, bool canMoveFiles); diff --git a/modules/juce_gui_basics/native/juce_mac_Windowing.mm b/modules/juce_gui_basics/native/juce_mac_Windowing.mm index ee976540e2..802c5572b1 100644 --- a/modules/juce_gui_basics/native/juce_mac_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_mac_Windowing.mm @@ -24,20 +24,7 @@ } // namespace juce -@interface NSDraggingSourceHelper : NSObject -{ -} -@end - -@implementation NSDraggingSourceHelper - --(NSDragOperation) draggingSession: (NSDraggingSession *)session sourceOperationMaskForDraggingContext: (NSDraggingContext)context -{ - juce::ignoreUnused (session, context); - return NSDragOperationCopy; -} - -@end +#include "../../juce_core/native/juce_osx_ObjCHelpers.h" namespace juce { @@ -250,6 +237,26 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text) return false; } +class NSDraggingSourceHelper : public ObjCClass > +{ +public: + NSDraggingSourceHelper() + : ObjCClass > ("JUCENSDraggingSourceHelper_") + { + addMethod (@selector (draggingSession:sourceOperationMaskForDraggingContext:), sourceOperationMaskForDraggingContext, "c@:@@"); + + registerClass(); + } + +private: + static NSDragOperation sourceOperationMaskForDraggingContext (id, SEL, NSDraggingSession*, NSDraggingContext) + { + return NSDragOperationCopy; + } +}; + +static NSDraggingSourceHelper draggingSourceHelper; + bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, bool /*canMoveFiles*/) { if (files.isEmpty()) @@ -279,7 +286,7 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi [dragItem release]; } - auto* helper = [[NSDraggingSourceHelper alloc] autorelease]; + auto* helper = [draggingSourceHelper.createInstance() autorelease]; if (! [view beginDraggingSessionWithItems: dragItems event: event