Added SDL_DROPBEGIN and SDL_DROPCOMPLETE events, plus window IDs for drops.

This allows an app to know when a set of drops are coming in a grouping of
some sort (for example, a user selected multiple files and dropped them all
on the window with a single drag), and when that set is complete.

This also adds a window ID to the drop events, so the app can determine to
which window a given drop was delivered. For application-level drops (for
example, you launched an app by dropping a file on its icon), the window ID
will be zero.
This commit is contained in:
Ryan C. Gordon
2016-01-05 01:42:00 -05:00
parent f2defe5e11
commit 8e855f2fbc
9 changed files with 79 additions and 20 deletions

View File

@@ -95,6 +95,7 @@ struct SDL_Window
SDL_bool is_hiding;
SDL_bool is_destroying;
SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
SDL_WindowShaper *shaper;

View File

@@ -176,7 +176,7 @@
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
return (BOOL)SDL_SendDropFile([filename UTF8String]);
return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
}
@end

View File

@@ -116,9 +116,12 @@
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ @autoreleasepool
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
NSPasteboard *pasteboard = [sender draggingPasteboard];
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
NSString *desiredType = [pasteboard availableTypeFromArray:types];
SDL_Window *sdlwindow = nil;
if (desiredType == nil) {
return NO; /* can't accept anything that's being dropped here. */
}
@@ -157,11 +160,22 @@
}
}
if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
/* !!! FIXME: is there a better way to do this? */
if (_this) {
for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow;
if (nswindow == self) {
break;
}
}
}
if (!SDL_SendDropFile(sdlwindow, [[fileURL path] UTF8String])) {
return NO;
}
}
SDL_SendDropComplete(sdlwindow);
return YES;
}}

View File

@@ -907,12 +907,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (buffer) {
if (DragQueryFile(drop, i, buffer, size)) {
char *file = WIN_StringToUTF8(buffer);
SDL_SendDropFile(file);
SDL_SendDropFile(data->window, file);
SDL_free(file);
}
SDL_stack_free(buffer);
}
}
SDL_SendDropComplete(data->window);
DragFinish(drop);
return 0;
}

View File

@@ -1230,17 +1230,17 @@ X11_DispatchEvent(_THIS)
char *token = strtok((char *) p.data, "\r\n");
while (token != NULL) {
if (SDL_strcmp("text/plain", name)==0) {
SDL_SendDropText(token);
SDL_SendDropText(data->window, token);
} else if (SDL_strcmp("text/uri-list", name)==0) {
char *fn = X11_URIToLocal(token);
if (fn) {
SDL_SendDropFile(fn);
SDL_SendDropFile(data->window, fn);
}
}
token = strtok(NULL, "\r\n");
}
SDL_SendDropComplete(data->window);
}
X11_XFree(p.data);
/* send reply */