I have a pop-down status bar application that contains an NSTableView
. When a row is dragged outside the table (drag-drop works here completely, this is not the focus of the question) I change the cursor to be the poofy-pointer, otherwise known as [NSCursor disappearingItemCursor]
like so:
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
if (self.draggedRowCanBeDeleted) {
BOOL outside = !NSPointInRect(screenPoint, window.frame);
if (outside) {
[[NSCursor disappearingItemCursor] set];
} else {
[[NSCursor arrowCursor] set];
}
}
}
This is pretty unreliable in that it sometimes works sometimes not. It often works on the first attempt, but quits working after that. I can't seem to find a pattern with what I am dragging over, or how far the drag travels etc..., just that it seems pretty unstable. Am I doing something wrong here? If not, is there something I can do to help diagnose the problem?
UPDATE
I have also tried the push
/pop
route and the problem persists.
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
if (self.draggedRowCanBeDeleted) {
BOOL outside = !NSPointInRect(screenPoint, window.frame);
if (outside) {
if (!_showingPoof) {
_showingPoof = YES;
[[NSCursor disappearingItemCursor] push];
}
} else {
if (_showingPoof) {
_showingPoof = NO;
[[NSCursor disappearingItemCursor] pop];
// I have also tried: [NSCursor pop];
}
}
}
}
UPDATE
I have also tried using the sourceOperationMaskForDraggingContext
method to set it. I can confirm that the correct sections are being called at the correct times, yet the cursor never changes when going this route.
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
if (self.draggedRowCanBeDeleted) {
switch(context) {
case NSDraggingContextOutsideApplication:
[[NSCursor disappearingItemCursor] set];
return NSDragOperationDelete;
break;
case NSDraggingContextWithinApplication:
[[NSCursor closedHandCursor] set];
return NSDragOperationMove;
default:
[[NSCursor arrowCursor] set];
return NSDragOperationNone;
}
}
return NSDragOperationNone;
}