bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch informal NSDraggingDestination protocol handling


From: Willem Rein Oudshoorn
Subject: Patch informal NSDraggingDestination protocol handling
Date: 09 Dec 2001 15:10:26 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

The implementation of the NSDraggingDestination protocol is not correct.
The Apple documentation specifies that if the method NSDraggingUpdate:
is not implemented it should use the value returned by NSDraggingEntered:

This is the reason that the NSColorWell did not communicate it's status
to the DnD code correctly.  It implemented only NSDraggingEntered:

The following patch fixes this.   I removed the NSObjectProtocols that
provided default implementation of the NSDraggingDestination protocol.
The code in the eventhandling that uses the NSDraggingDestination protocol
checks if a method is implemented before using it.  
(I do not like to burden NSObject with this protocol)
If this is liable to break anything, do not apply this patch 
but please explain to my why it is going to break other code.  
Although I tested it on a few programs and it did not break them.
Also from the specs I do not see how such an change should break anything.

Wim Oudshoorn.



2001-12-09  Willem Rein Oudshoorn  <woudshoo@xs4all.nl>

        * Source/NSWindow.m (GSPerformVoidDragSelector): rewritten to not rely 
on category on NSObject
        (GSPerformDragSelector): rewritten to not rely on category on NSObject
        ([NSWindow -sendEvent:]): fixed bug in handling of informal 
draggingDestination protocol

        * Headers/AppKit/NSWindow.h (NSCoding>): added instance variable 
_lastDragOperationMask

        * Source/GNUmakefile (libgnustep-gui_OBJC_FILES): Removed obsolete 
NSObjectProtocols.m file




Index: Headers/gnustep/gui/NSWindow.h
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/gnustep/gui/NSWindow.h,v
retrieving revision 1.57
diff -c -r1.57 NSWindow.h
*** Headers/gnustep/gui/NSWindow.h      2001/11/26 20:25:15     1.57
--- Headers/gnustep/gui/NSWindow.h      2001/12/09 13:49:25
***************
*** 116,121 ****
--- 116,122 ----
    id            _delegate;
    id            _fieldEditor;
    id            _lastDragView;
+   int           _lastDragOperationMask;
    int           _windowNum;
    int           _gstate;
    NSColor       *_backgroundColor;
Index: Source/GNUmakefile
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/GNUmakefile,v
retrieving revision 1.84
diff -c -r1.84 GNUmakefile
*** Source/GNUmakefile  2001/10/25 21:41:03     1.84
--- Source/GNUmakefile  2001/12/09 13:49:27
***************
*** 100,106 ****
  NSMenuItemCell.m \
  NSOpenPanel.m \
  NSOutlineView.m \
- NSObjectProtocols.m \
  NSPageLayout.m \
  NSPanel.m \
  NSParagraphStyle.m \
--- 100,105 ----
Index: Source/NSWindow.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWindow.m,v
retrieving revision 1.203
diff -c -r1.203 NSWindow.m
*** Source/NSWindow.m   2001/11/26 20:25:50     1.203
--- Source/NSWindow.m   2001/12/09 13:49:45
***************
*** 2742,2759 ****
              break;
  
  
! #define     GSPerformDragSelector(view, sel, info, action)                 \
!               if (view == _contentView && _delegate)                       \
!                   action = (int)[_delegate performSelector: sel withObject:   
\
!                                           info];                           \
!               else                                                         \
!                 action = (int)[view performSelector: sel withObject: info]
! #define     GSPerformVoidDragSelector(view, sel, info)                        
\
!               if (view == _contentView && _delegate)                  \
!                   [_delegate performSelector: sel withObject: info];  \
!               else                                                    \
!                 [view performSelector: sel withObject: info]
  
            case GSAppKitDraggingEnter:
            case GSAppKitDraggingUpdate:
              v = [_contentView hitTest: [theEvent locationInWindow]];
--- 2742,2783 ----
              break;
  
  
! #define     GSPerformDragSelector(view, sel, info, action) \
!                 do {  \
!                     id target;  \
!               if (view == _contentView && _delegate) \
!                   { \
!                     target = _delegate; \
!                   } \
!                 else \
!                   { \
!                     target= view; \
!                   } \
!                 \
!                 if ([target respondsToSelector: sel]) \
!                   { \
!                     action = (int)[target performSelector: sel withObject: 
info];   \
!                   } \
!                 } while (0)
  
+ #define     GSPerformVoidDragSelector(view, sel, info) \
+                 do {  \
+                     id target;  \
+               if (view == _contentView && _delegate) \
+                   { \
+                     target = _delegate; \
+                   } \
+                 else \
+                   { \
+                     target= view; \
+                   } \
+                 \
+                 if ([target respondsToSelector: sel]) \
+                   { \
+                     [target performSelector: sel withObject: info];   \
+                   } \
+                 } while (0)
+ 
            case GSAppKitDraggingEnter:
            case GSAppKitDraggingUpdate:
              v = [_contentView hitTest: [theEvent locationInWindow]];
***************
*** 2766,2792 ****
                                      @selector(draggingExited:), dragInfo);
                }
              _f.accepts_drag = GSViewAcceptsDrag(v, dragInfo);
!             if (_lastDragView != v && _f.accepts_drag)
!               {
!                 GSPerformDragSelector(v, @selector(draggingEntered:),
!                                     dragInfo, action);
!               }
!             else
!               {
!                 GSPerformDragSelector(v, @selector(draggingUpdated:),
!                                     dragInfo, action);
!               }
!             e = [NSEvent otherEventWithType: NSAppKitDefined
!                          location: [theEvent locationInWindow]
!                          modifierFlags: 0
!                          timestamp: 0
!                          windowNumber: _windowNum
!                          context: GSCurrentContext()
!                          subtype: GSAppKitDraggingStatus
!                          data1: [theEvent data1]
!                          data2: action];
!             [GSCurrentContext() _postExternalEvent: e];
!             _lastDragView = v;
              break;
  
            case GSAppKitDraggingStatus:
--- 2790,2828 ----
                                      @selector(draggingExited:), dragInfo);
                }
              _f.accepts_drag = GSViewAcceptsDrag(v, dragInfo);
!               if (_f.accepts_drag)
!                 {
!                   if (_lastDragView != v)
!                     {
!                       action = NSDragOperationNone;
!                       GSPerformDragSelector(v, @selector(draggingEntered:),
!                                             dragInfo, action);
!                     }
!                   else  
!                     {
!                       action = _lastDragOperationMask;
!                       GSPerformDragSelector(v, @selector(draggingUpdated:),
!                                             dragInfo, action);
!                     }
!                 }
!               else
!                 {
!                   action = NSDragOperationNone;
!                 }
! 
!               e = [NSEvent otherEventWithType: NSAppKitDefined
!                            location: [theEvent locationInWindow]
!                            modifierFlags: 0
!                            timestamp: 0
!                            windowNumber: _windowNum
!                            context: GSCurrentContext()
!                            subtype: GSAppKitDraggingStatus
!                            data1: [theEvent data1]
!                            data2: action];
! 
!               _lastDragOperationMask = action;
!               [GSCurrentContext() _postExternalEvent: e];
!               _lastDragView = v;
              break;
  
            case GSAppKitDraggingStatus:
***************
*** 2798,2807 ****
              dragInfo = [GSCurrentContext() _dragInfo];
              if (_lastDragView && _f.accepts_drag)
                {
!                 GSPerformDragSelector(_lastDragView,
!                                     @selector(draggingExited:), dragInfo,
!                                     action);
                }
              _lastDragView = nil;
              break;
  
--- 2834,2843 ----
              dragInfo = [GSCurrentContext() _dragInfo];
              if (_lastDragView && _f.accepts_drag)
                {
!                 GSPerformVoidDragSelector(_lastDragView,
!                                             @selector(draggingExited:), 
dragInfo);
                }
+               _lastDragOperationMask = NSDragOperationNone;
              _lastDragView = nil;
              break;
  
***************
*** 2809,2819 ****
              if (_lastDragView && _f.accepts_drag)
                {
                  dragInfo = [GSCurrentContext() _dragInfo];
!                 GSPerformDragSelector(_lastDragView,
                                        @selector(prepareForDragOperation:),
                                        dragInfo, action);
                  if (action)
                    {
                      GSPerformDragSelector(_lastDragView,
                                          @selector(performDragOperation:),
                                          dragInfo, action);
--- 2845,2858 ----
              if (_lastDragView && _f.accepts_drag)
                {
                  dragInfo = [GSCurrentContext() _dragInfo];
! 
!                   action = NO;
!                   GSPerformDragSelector(_lastDragView,
                                        @selector(prepareForDragOperation:),
                                        dragInfo, action);
                  if (action)
                    {
+                       action = NO;
                      GSPerformDragSelector(_lastDragView,
                                          @selector(performDragOperation:),
                                          dragInfo, action);
***************
*** 2825,2830 ****
--- 2864,2870 ----
                                          dragInfo);
                    }
                }
+               _lastDragOperationMask = NSDragOperationNone;
              _lastDragView = nil;
              e = [NSEvent otherEventWithType: NSAppKitDefined
                           location: [theEvent locationInWindow]
***************
*** 2839,2844 ****
--- 2879,2885 ----
              break;
  
            case GSAppKitDraggingFinished:
+               _lastDragOperationMask = NSDragOperationNone;
              _lastDragView = nil;
              NSDebugLLog(@"NSDragging",
                @"Internal: dropped GSAppKitDraggingFinished event");






reply via email to

[Prev in Thread] Current Thread [Next in Thread]