src/video/cocoa/SDL_cocoawindow.m
changeset 8953 dc80dc0bd22e
parent 8926 38e89ab78465
parent 8935 9d2f0236322b
child 8978 7753e4fd3d1d
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Wed Jun 25 02:08:37 2014 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Wed Jun 25 17:06:12 2014 -0400
     1.3 @@ -192,6 +192,7 @@
     1.4      inFullscreenTransition = NO;
     1.5      pendingWindowOperation = PENDING_OPERATION_NONE;
     1.6      isMoving = NO;
     1.7 +    isDragAreaRunning = NO;
     1.8  
     1.9      center = [NSNotificationCenter defaultCenter];
    1.10  
    1.11 @@ -663,10 +664,48 @@
    1.12      /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
    1.13  }
    1.14  
    1.15 +/* We'll respond to selectors by doing nothing so we don't beep.
    1.16 + * The escape key gets converted to a "cancel" selector, etc.
    1.17 + */
    1.18 +- (void)doCommandBySelector:(SEL)aSelector
    1.19 +{
    1.20 +    /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
    1.21 +}
    1.22 +
    1.23 +- (BOOL)processHitTest:(NSEvent *)theEvent
    1.24 +{
    1.25 +    SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
    1.26 +
    1.27 +    if (_data->window->hit_test) {  /* if no hit-test, skip this. */
    1.28 +        const NSPoint location = [theEvent locationInWindow];
    1.29 +        const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
    1.30 +        const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
    1.31 +        if (rc == SDL_HITTEST_DRAGGABLE) {
    1.32 +            if (!isDragAreaRunning) {
    1.33 +                isDragAreaRunning = YES;
    1.34 +                [_data->nswindow setMovableByWindowBackground:YES];
    1.35 +            }
    1.36 +            return YES;  /* dragging! */
    1.37 +        }
    1.38 +    }
    1.39 +
    1.40 +    if (isDragAreaRunning) {
    1.41 +        isDragAreaRunning = NO;
    1.42 +        [_data->nswindow setMovableByWindowBackground:NO];
    1.43 +        return YES;  /* was dragging, drop event. */
    1.44 +    }
    1.45 +
    1.46 +    return NO;  /* not a special area, carry on. */
    1.47 +}
    1.48 +
    1.49  - (void)mouseDown:(NSEvent *)theEvent
    1.50  {
    1.51      int button;
    1.52  
    1.53 +    if ([self processHitTest:theEvent]) {
    1.54 +        return;  /* dragging, drop event. */
    1.55 +    }
    1.56 +
    1.57      switch ([theEvent buttonNumber]) {
    1.58      case 0:
    1.59          if (([theEvent modifierFlags] & NSControlKeyMask) &&
    1.60 @@ -705,6 +744,10 @@
    1.61  {
    1.62      int button;
    1.63  
    1.64 +    if ([self processHitTest:theEvent]) {
    1.65 +        return;  /* stopped dragging, drop event. */
    1.66 +    }
    1.67 +
    1.68      switch ([theEvent buttonNumber]) {
    1.69      case 0:
    1.70          if (wasCtrlLeft) {
    1.71 @@ -744,6 +787,10 @@
    1.72      NSPoint point;
    1.73      int x, y;
    1.74  
    1.75 +    if ([self processHitTest:theEvent]) {
    1.76 +        return;  /* dragging, drop event. */
    1.77 +    }
    1.78 +
    1.79      if (mouse->relative_mode) {
    1.80          return;
    1.81      }
    1.82 @@ -752,8 +799,8 @@
    1.83      x = (int)point.x;
    1.84      y = (int)(window->h - point.y);
    1.85  
    1.86 -    if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
    1.87 -        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
    1.88 +    if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
    1.89 +        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
    1.90              if (x < 0) {
    1.91                  x = 0;
    1.92              } else if (x >= window->w) {
    1.93 @@ -890,6 +937,7 @@
    1.94  
    1.95  /* The default implementation doesn't pass rightMouseDown to responder chain */
    1.96  - (void)rightMouseDown:(NSEvent *)theEvent;
    1.97 +- (BOOL)mouseDownCanMoveWindow;
    1.98  @end
    1.99  
   1.100  @implementation SDLView
   1.101 @@ -898,6 +946,14 @@
   1.102      [[self nextResponder] rightMouseDown:theEvent];
   1.103  }
   1.104  
   1.105 +- (BOOL)mouseDownCanMoveWindow
   1.106 +{
   1.107 +    /* Always say YES, but this doesn't do anything until we call
   1.108 +       -[NSWindow setMovableByWindowBackground:YES], which we ninja-toggle
   1.109 +       during mouse events when we're using a drag area. */
   1.110 +    return YES;
   1.111 +}
   1.112 +
   1.113  - (void)resetCursorRects
   1.114  {
   1.115      [super resetCursorRects];
   1.116 @@ -995,6 +1051,7 @@
   1.117  
   1.118      /* All done! */
   1.119      [pool release];
   1.120 +    window->driverdata = data;
   1.121      return 0;
   1.122  }
   1.123  
   1.124 @@ -1566,6 +1623,12 @@
   1.125      return succeeded;
   1.126  }
   1.127  
   1.128 +int
   1.129 +Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
   1.130 +{
   1.131 +    return 0;  /* just succeed, the real work is done elsewhere. */
   1.132 +}
   1.133 +
   1.134  #endif /* SDL_VIDEO_DRIVER_COCOA */
   1.135  
   1.136  /* vi: set ts=4 sw=4 expandtab: */