mirror of
https://github.com/glfw/glfw.git
synced 2025-07-29 11:00:04 +00:00
cocoa_window: fix mouse dissapearing after drop and on resize
This commit is contained in:
parent
7aed0ad35c
commit
9e9e75f331
@ -390,6 +390,8 @@ static int translateKey(unsigned int key)
|
||||
@interface GLFWContentView : NSView
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
char * fileNamesForDrag;
|
||||
int fileNamesSize;
|
||||
NSTrackingArea* trackingArea;
|
||||
}
|
||||
|
||||
@ -421,10 +423,13 @@ 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 <NSDraggingInfo>)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 <NSDraggingInfo>)sender {
|
||||
[self setNeedsDisplay:YES];
|
||||
return YES;
|
||||
} // end prepareForDragOperation
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)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);
|
||||
_glfwInputDrop(window, fileNamesForDrag);
|
||||
|
||||
//NSLog(@"Got a drag!");
|
||||
return YES;
|
||||
|
||||
} // end performDragOperation
|
||||
|
||||
}
|
||||
|
||||
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
|
||||
} // end concludeDragOperation
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user