Port cocoa backend to use new drop API

This commit is contained in:
Kovid Goyal 2020-03-19 13:34:15 +05:30
parent 2458c3a7c6
commit ab9a36f8c1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1159,27 +1159,20 @@ is_ascii_control_char(char x) {
const NSUInteger count = [objs count]; const NSUInteger count = [objs count];
if (count) if (count)
{ {
char** paths = calloc(count, sizeof(char*));
for (NSUInteger i = 0; i < count; i++) for (NSUInteger i = 0; i < count; i++)
{ {
id obj = objs[i]; id obj = objs[i];
if ([obj isKindOfClass:[NSURL class]]) { if ([obj isKindOfClass:[NSURL class]]) {
paths[i] = _glfw_strdup([obj fileSystemRepresentation]); const char *path = [obj fileSystemRepresentation];
_glfwInputDrop(window, "text/uri-list", path, strlen(path));
} else if ([obj isKindOfClass:[NSString class]]) { } else if ([obj isKindOfClass:[NSString class]]) {
paths[i] = _glfw_strdup([obj UTF8String]); const char *text = [obj UTF8String];
_glfwInputDrop(window, "text/plain;charset=utf-8", text, strlen(text));
} else { } else {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Object is neither a URL nor a string"); "Cocoa: Object is neither a URL nor a string");
paths[i] = _glfw_strdup("");
} }
} }
_glfwInputDrop(window, (int) count, (const char**) paths);
for (NSUInteger i = 0; i < count; i++)
free(paths[i]);
free(paths);
} }
return YES; return YES;