6

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;
}
coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • Have you tried using `[[NSCursor disappearingItemCursor] push]` when the pointer is outside and `[NSCursor pop]` if pointer cursor was outside and it’s not anymore? I.e., you would push the disappearing item cursor the first time the pointer moves outside of the window, and pop back to the original cursor if the pointer moves back to the window or dragging is cancelled, to make sure every push is balanced with a pop. –  Oct 07 '13 at 10:27
  • unfortunately, the same behavior is exhibited when using push/pop vs set/set – coneybeare Oct 09 '13 at 20:12
  • That wasn't an alternative, it is a way to make it work which, as I specified previously, indeed does work. The question here is in regards to the unreliable cursor poof. – coneybeare Oct 16 '13 at 16:44
  • I have updated some piece of code – Hussain Shabbir Oct 17 '13 at 00:55

0 Answers0