tags:

views:

251

answers:

1

Hi All,

I have few views aligned in grids in parent view (All being NSView's )

I am overriding -(void)mouseDown:(NSEvent *)event - (void)mouseDragged:(NSEvent *)theEvent for some custom drawing in child view subclass

To be specific, I draw some rectangle boxes during mouse drag in child view's.

Problem: when cursor moves out of the child view( during mouse drag ) , obviously, I am not able to track the event and hence I cannot resize the rectangle. I want to track the mouse movements even outside the application window... (for now just the drag event )

Is there any obvious or complex way to achieve this.....

Thanks in Advance

Rajesh

A: 
- (void)mouseDown:(NSEvent *)theEvent
{
    NSPoint point;
    while (1) {
        theEvent = [[self window] nextEventMatchingMask: (NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
        point = [self convertPoint: [theEvent locationInWindow] fromView: nil];

        // do something with point

        if ([theEvent type] == NSLeftMouseUp)
            break;
    }
}
cocoafan
thanks 'cocoafan', works like a charm.