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
|
@interface GLFWContentView : NSView
|
||||||
{
|
{
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
char * fileNamesForDrag;
|
||||||
|
int fileNamesSize;
|
||||||
NSTrackingArea* trackingArea;
|
NSTrackingArea* trackingArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,11 +422,14 @@ static int translateKey(unsigned int key)
|
|||||||
{
|
{
|
||||||
window = initWindow;
|
window = initWindow;
|
||||||
trackingArea = nil;
|
trackingArea = nil;
|
||||||
|
|
||||||
|
fileNamesForDrag = (char*)malloc(1024);
|
||||||
|
fileNamesSize = 1024;
|
||||||
|
|
||||||
[self updateTrackingAreas];
|
[self updateTrackingAreas];
|
||||||
|
|
||||||
|
|
||||||
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
|
[self registerForDraggedTypes:[NSArray arrayWithObjects:
|
||||||
NSFilenamesPboardType, nil]];
|
NSFilenamesPboardType, nil]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,6 +439,7 @@ static int translateKey(unsigned int key)
|
|||||||
-(void)dealloc
|
-(void)dealloc
|
||||||
{
|
{
|
||||||
[trackingArea release];
|
[trackingArea release];
|
||||||
|
free(fileNamesForDrag);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,80 +623,71 @@ static int translateKey(unsigned int key)
|
|||||||
_glfwInputScroll(window, deltaX, deltaY);
|
_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 discardCursorRects];
|
||||||
[self addCursorRect:[self bounds] cursor:_glfw.ns.cursor];
|
[self addCursorRect:[self bounds] cursor:_glfw.ns.cursor];
|
||||||
}
|
}*/
|
||||||
|
|
||||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
||||||
{
|
{
|
||||||
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
|
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
|
||||||
== NSDragOperationGeneric) {
|
== NSDragOperationGeneric) {
|
||||||
|
|
||||||
|
[self setNeedsDisplay:YES];
|
||||||
|
|
||||||
return NSDragOperationGeneric;
|
return NSDragOperationGeneric;
|
||||||
|
|
||||||
} // end if
|
}
|
||||||
|
|
||||||
// not a drag we can use
|
|
||||||
return NSDragOperationNone;
|
return NSDragOperationNone;
|
||||||
|
}
|
||||||
} // end draggingEntered
|
|
||||||
|
|
||||||
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
|
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
|
||||||
[self setNeedsDisplay:YES];
|
[self setNeedsDisplay:YES];
|
||||||
return YES;
|
return YES;
|
||||||
} // end prepareForDragOperation
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
||||||
|
|
||||||
//int i;
|
|
||||||
int count;
|
|
||||||
NSPasteboard *zPasteboard = [sender draggingPasteboard];
|
NSPasteboard *zPasteboard = [sender draggingPasteboard];
|
||||||
NSArray *files = [zPasteboard propertyListForType:NSFilenamesPboardType];
|
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];
|
// set the first char to 0 so strcat
|
||||||
memset(fileNames, 0, 100*1000);
|
// starts to add from the beginning
|
||||||
|
fileNamesForDrag[0] = 0;
|
||||||
|
|
||||||
int dragX = [sender draggingLocation].x;
|
int dragX = [sender draggingLocation].x;
|
||||||
int dragY = [sender draggingLocation].y;
|
int dragY = [sender draggingLocation].y;
|
||||||
|
|
||||||
count = 0;
|
int dragSize = 1;
|
||||||
if ([files count]) {
|
if ([files count]) {
|
||||||
NSEnumerator *filenameEnum = [files objectEnumerator];
|
NSEnumerator *filenameEnum = [files objectEnumerator];
|
||||||
NSString *name;
|
NSString *name;
|
||||||
while (name = [filenameEnum nextObject]) {
|
while (name = [filenameEnum nextObject]) {
|
||||||
if (count < 100){
|
dragSize += [name length]+1;
|
||||||
if (strlen([name UTF8String]) < MAXPATHLEN){
|
if (dragSize > fileNamesSize){
|
||||||
strcat(fileNames, [name UTF8String]);
|
fileNamesSize *= 2;
|
||||||
strcat(fileNames, "\n");
|
fileNamesForDrag = realloc(fileNamesForDrag, fileNamesSize);
|
||||||
count++;
|
}
|
||||||
}
|
strcat(fileNamesForDrag, [name UTF8String]);
|
||||||
}
|
strcat(fileNamesForDrag, "\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int height;
|
int height;
|
||||||
_glfwPlatformGetWindowSize(window, NULL, &height);
|
_glfwPlatformGetWindowSize(window, NULL, &height);
|
||||||
_glfwInputCursorMotion(window, dragX, height-dragY);
|
_glfwInputCursorMotion(window, dragX, height-dragY);
|
||||||
_glfwInputDrop(window, fileNames);
|
_glfwInputDrop(window, fileNamesForDrag);
|
||||||
|
|
||||||
//NSLog(@"Got a drag!");
|
|
||||||
return YES;
|
return YES;
|
||||||
|
}
|
||||||
} // end performDragOperation
|
|
||||||
|
|
||||||
|
|
||||||
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
|
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
|
||||||
} // end concludeDragOperation
|
[self setNeedsDisplay:YES];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user