Skip to content

Commit

Permalink
Using OS to determine DRAG_DONE operation
Browse files Browse the repository at this point in the history
  • Loading branch information
beldenfox committed Feb 16, 2024
1 parent 1fb56e3 commit 4f088cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@protocol GlassDragSourceDelegate <NSObject>

- (void)startDrag:(NSDragOperation)operation withItems:(NSArray<NSDraggingItem*>*)items;
- (void)draggingEnded;
- (void)draggingEnded:(NSDragOperation)operation;

@end

Expand All @@ -41,7 +41,7 @@

+ (NSDragOperation)mapJavaMaskToNsOperation:(jint)mask;
+ (jint)mapNsOperationToJavaMaskExternal:(NSDragOperation)operation;
+ (jint)mapNSOperationToJavaMaskInternal:(NSDragOperation)operation;
+ (jint)mapNsOperationToJavaMaskInternal:(NSDragOperation)operation;
+ (jint)getRecommendedActionForMaskExternal:(NSDragOperation)operation;
+ (jint)getRecommendedActionForMaskInternal:(NSDragOperation)operation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@


#import <Cocoa/Cocoa.h>
#import "GlassDragSource.h"

@interface GlassDraggingSource : NSObject <NSDraggingSource>
{
@public
NSDragOperation dragOperation;

id<GlassDragSourceDelegate> dragDelegate;
}

- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation;
- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation delegate:(id<GlassDragSourceDelegate>)delegate;

- (void)draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint;
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationM
return self->dragOperation;
}

- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation
- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation delegate:(id<GlassDragSourceDelegate>)delegate
{
dragOperation = operation;
// The delegate retains this object
dragDelegate = delegate;
return self;
}

Expand All @@ -69,6 +71,8 @@ - (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)scree

- (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation
{
LOG("Dragging session ended");
[dragDelegate draggingEnded: operation];
}

- (BOOL)ignoreModifierKeysForDraggingSession:(NSDraggingSession *)session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
- (void)draggingEnded:(id <NSDraggingInfo>)sender
{
DNDLOG("draggingEnded");
[self->_delegate draggingEnded];
}

- (void)draggingExited:(id <NSDraggingInfo>)sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ - (void)startDrag:(NSDragOperation)operation withItems:(NSArray<NSDraggingItem*>
[image release];
}

self->draggingSource = [[GlassDraggingSource alloc] initWithOperation:operation];
self->draggingSource = [[GlassDraggingSource alloc] initWithOperation:operation delegate:self];

NSDraggingSession *session = [self->nsView beginDraggingSessionWithItems:items event:self->lastEvent source:self->draggingSource];
}
Expand All @@ -1097,7 +1097,7 @@ - (void)synthesizeMouseUp:(NSEventType)type
[self sendJavaMouseEvent:theEvent];
}

- (void)draggingEnded
- (void)draggingEnded:(NSDragOperation)operation
{
DNDLOG("draggingEnded");

Expand All @@ -1109,8 +1109,23 @@ - (void)draggingEnded

[GlassDragSource setDelegate:nil];

// At the end of dragging we're handed a single definitive
// drag operation (no Generic or Any).
jint mask = com_sun_glass_ui_Clipboard_ACTION_NONE;
if (operation == NSDragOperationNone) {
mask = com_sun_glass_ui_Clipboard_ACTION_NONE;
} else if (operation == NSDragOperationCopy) {
mask = com_sun_glass_ui_Clipboard_ACTION_COPY;
} else if (operation == NSDragOperationMove) {
mask = com_sun_glass_ui_Clipboard_ACTION_MOVE;
} else if (operation == NSDragOperationLink) {
mask = com_sun_glass_ui_Clipboard_ACTION_REFERENCE;
} else {
DNDLOG("Invalid drag operation");
}

GET_MAIN_JENV;
(*env)->CallVoidMethod(env, self->jView, jViewNotifyDragEnd, [GlassDragSource getMask]);
(*env)->CallVoidMethod(env, self->jView, jViewNotifyDragEnd, mask);
GLASS_CHECK_EXCEPTION(env);

// RT-36038: OS X won't send mouseUp after DnD is complete, so we synthesize them
Expand Down

0 comments on commit 4f088cc

Please sign in to comment.