From 9e9e75f3314426b47bc77cbaa0cdac75565a74e1 Mon Sep 17 00:00:00 2001 From: arturo Date: Thu, 11 Jul 2013 22:50:46 +0200 Subject: [PATCH] cocoa_window: fix mouse dissapearing after drop and on resize --- src/cocoa_window.m | 75 ++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 29ae743d..3925b107 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -390,6 +390,8 @@ static int translateKey(unsigned int key) @interface GLFWContentView : NSView { _GLFWwindow* window; + char * fileNamesForDrag; + int fileNamesSize; NSTrackingArea* trackingArea; } @@ -420,11 +422,14 @@ static int translateKey(unsigned int key) { window = initWindow; trackingArea = nil; - + + fileNamesForDrag = (char*)malloc(1024); + fileNamesSize = 1024; + [self updateTrackingAreas]; - [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, + [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; } @@ -434,6 +439,7 @@ static int translateKey(unsigned int key) -(void)dealloc { [trackingArea release]; + free(fileNamesForDrag); [super dealloc]; } @@ -617,80 +623,71 @@ static int translateKey(unsigned int key) _glfwInputScroll(window, deltaX, deltaY); } -- (void)resetCursorRects + +// arturoc: this makes the cursor dissapear when the window is +// resized or received a drag operation +/*- (void)resetCursorRects { [self discardCursorRects]; [self addCursorRect:[self bounds] cursor:_glfw.ns.cursor]; -} +}*/ - (NSDragOperation)draggingEntered:(id )sender { if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) { - + + [self setNeedsDisplay:YES]; + return NSDragOperationGeneric; - } // end if - - // not a drag we can use + } + return NSDragOperationNone; - -} // end draggingEntered +} - (BOOL)prepareForDragOperation:(id )sender { [self setNeedsDisplay:YES]; return YES; -} // end prepareForDragOperation - - - +} - (BOOL)performDragOperation:(id )sender { - - //int i; - int count; NSPasteboard *zPasteboard = [sender draggingPasteboard]; NSArray *files = [zPasteboard propertyListForType:NSFilenamesPboardType]; - - // define the images types we accept - // NSPasteboardTypeTIFF: (used to be NSTIFFPboardType). - // NSFilenamesPboardType:An array of NSString filenames - char fileNames[100*1000]; - memset(fileNames, 0, 100*1000); + // set the first char to 0 so strcat + // starts to add from the beginning + fileNamesForDrag[0] = 0; int dragX = [sender draggingLocation].x; int dragY = [sender draggingLocation].y; - count = 0; + int dragSize = 1; if ([files count]) { NSEnumerator *filenameEnum = [files objectEnumerator]; NSString *name; while (name = [filenameEnum nextObject]) { - if (count < 100){ - if (strlen([name UTF8String]) < MAXPATHLEN){ - strcat(fileNames, [name UTF8String]); - strcat(fileNames, "\n"); - count++; - } - } - + dragSize += [name length]+1; + if (dragSize > fileNamesSize){ + fileNamesSize *= 2; + fileNamesForDrag = realloc(fileNamesForDrag, fileNamesSize); + } + strcat(fileNamesForDrag, [name UTF8String]); + strcat(fileNamesForDrag, "\n"); } } int height; _glfwPlatformGetWindowSize(window, NULL, &height); _glfwInputCursorMotion(window, dragX, height-dragY); - _glfwInputDrop(window, fileNames); - - //NSLog(@"Got a drag!"); + _glfwInputDrop(window, fileNamesForDrag); + return YES; - -} // end performDragOperation - +} - (void)concludeDragOperation:(id )sender { -} // end concludeDragOperation + [self setNeedsDisplay:YES]; +} @end