Talk:NSView

From GNUstepWiki
Jump to navigation Jump to search

Why not use something like

  - (void) mouseDown: (NSEvent *) theEvent
  {   
    BOOL isInside;
    unsigned int mask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
    
    if( nil == target ) return;
    
    while( [theEvent type] != NSLeftMouseUp )
    {
      theEvent = [[self window] nextEventMatchingMask: mask];
      isInside = [self mouse: [self convertPoint: [theEvent locationInWindow]
                                        fromView: nil]
                      inRect: [self bounds]];
      
      switch( [theEvent type] )
      {
        case NSLeftMouseDragged: // drag
          //
          // whatever needs to be done while dragging
          //
          break;
        
        case NSLeftMouseUp: // drop
          if( isInside )
          {
            //
            // whatever needs to be done when button is released
            //
          }
          break;
        
        default:
          break;
      } /*switch */
    } /* while */
  } /* -mouseDown: */

Looks much cleaner and should be faster.