Browse Source

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

tags/2021-05-28
tpoole 8 years ago
parent
commit
f5dafc4a3c
2 changed files with 24 additions and 17 deletions
  1. +2
    -2
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h
  2. +22
    -15
      modules/juce_gui_basics/native/juce_mac_Windowing.mm

+ 2
- 2
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.h 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);


+ 22
- 15
modules/juce_gui_basics/native/juce_mac_Windowing.mm 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


Loading…
Cancel
Save