Talk:NSView

From GNUstepWiki
Revision as of 11:27, 1 September 2005 by Cbv (talk | contribs) (Suggested alternativ -mouseDown: implementation for dragging)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.