1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-29 02:40:05 +00:00

Fixed a bug in an Objective-C drag and drop helper class

This commit is contained in:
tpoole 2017-02-23 18:12:10 +00:00
parent 95085c1fa2
commit f5dafc4a3c
2 changed files with 24 additions and 17 deletions

View file

@ -130,8 +130,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);

View file

@ -24,20 +24,7 @@
} // namespace juce
@interface NSDraggingSourceHelper : NSObject <NSDraggingSource>
{
}
@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 <NSObject <NSDraggingSource>>
{
public:
NSDraggingSourceHelper()
: ObjCClass <NSObject <NSDraggingSource>> ("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