The following patch implement the slideback functionality.
Also a operator precedence bug is fixed (SR # 100253).
Slideback numbers are now hardcoded. Also Apples docs.
say that slideback is disabled when icon animation is disabled.
This is not implemented, it will always do a slideback when asked.
2002-01-13 Willem Rein Oudshoorn <[EMAIL PROTECTED]>
* Source/SharedX/XGDragView.m: changed and added comments in a few
places.
(SLIDE_TIME_STEP, SLIDE_NR_OF_STEPS): #define numbers controlling
slide (back).
([XGDragView
-dragImage:at:offset:event:pasteboard:source:slideBack:]): use
slideBack: argument
([XGDragView -_handleDrag:]): renamed a local var, and use
slideback.
([XGDragView -_handleDrag:]): fixed bug in determining if we do a
DnD drop SR#100253. (operator precedence was wrong).
([XGDragView -_updateAndMoveImageToCorrectPosition]): use new
method to display drag image.
([XGDragView -_moveDraggedImageToNewPosition]): new method that
will do the drawing and moving of the DnD image.
([XGDragView
-_slideDraggedImageTo:numberOfSteps:stepswaitAfterSlide:waitFlag]):
new method that implements sliding the DnD image.
([XGDragView -slideDraggedImageTo:point]): is implemented with the
use of the method above
* Source/SharedX/XGDragView.h: added instance variable, slideBack.
changed comments, added prototypes for new methods. (See XGDragView.m)
? Source/SharedX/Untitled.igsdoc
Index: Source/SharedX/XGDragView.h
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/xgps/Source/SharedX/XGDragView.h,v
retrieving revision 1.2
diff -c -r1.2 XGDragView.h
*** Source/SharedX/XGDragView.h 21 Dec 2001 00:43:18 -0000 1.2
--- Source/SharedX/XGDragView.h 13 Jan 2002 15:46:35 -0000
***************
*** 73,79 ****
/* information used in the drag and drop event loop */
NSPoint offset; /*" offset of image w.r.t. cursor "*/
NSPoint dragPosition; /*" in screen coordinates "*/
! NSPoint newPosition; /*" position not yet processes "*/
int wx, wy; /*" position of image in X-coordinates "*/
Window targetWindow; /*" XWindow that is the current drag target "*/
--- 73,79 ----
/* information used in the drag and drop event loop */
NSPoint offset; /*" offset of image w.r.t. cursor "*/
NSPoint dragPosition; /*" in screen coordinates "*/
! NSPoint newPosition; /*" position, not yet processed "*/
int wx, wy; /*" position of image in X-coordinates "*/
Window targetWindow; /*" XWindow that is the current drag target "*/
***************
*** 92,97 ****
--- 92,98 ----
Atom *typelist;
BOOL dragExternal; /*" YES if target and source are in a different application "*/
BOOL isDragging; /*" Yes if we are currently dragging "*/
+ BOOL slideBack; /*" slide back when drag fails? "*/
NSMutableDictionary *cursors;
}
***************
*** 119,123 ****
--- 120,128 ----
- (void) _handleDrag: (NSEvent*)theEvent;
- (void) _handleEventDuringDragging: (NSEvent*) theEvent;
- (void) _updateAndMoveImageToCorrectPosition;
+ - (void) _moveDraggedImageToNewPosition;
+ - (void) _slideDraggedImageTo: (NSPoint)screenPoint
+ numberOfSteps: (int) steps
+ waitAfterSlide: (BOOL) waitFlag;
- (Window) _xWindowAcceptingDnDunderX: (int) x Y: (int) y;
@end
Index: Source/SharedX/XGDragView.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/xgps/Source/SharedX/XGDragView.m,v
retrieving revision 1.5
diff -c -r1.5 XGDragView.m
*** Source/SharedX/XGDragView.m 24 Dec 2001 15:04:37 -0000 1.5
--- Source/SharedX/XGDragView.m 13 Jan 2002 15:46:39 -0000
***************
*** 51,56 ****
--- 51,59 ----
#define XDPY [XGContext currentXDisplay]
+ #define SLIDE_TIME_STEP .02 /* in seconds */
+ #define SLIDE_NR_OF_STEPS 20
+
@interface XGRawWindow : NSWindow
@end
***************
*** 240,245 ****
--- 243,255 ----
/*
* Local drag operation
*/
+
+ /*
+ * TODO:
+ * - use initialOffset
+ * - use screenLocation
+ * - implement slideBack
+ */
- (void) dragImage: (NSImage*)anImage
at: (NSPoint)screenLocation
offset: (NSSize)initialOffset
***************
*** 259,264 ****
--- 269,275 ----
dragSource = sourceObject;
dragSequence = [event timestamp];
dragExternal = NO;
+ slideBack = slideFlag;
NSDebugLLog(@"NSDragging", @"Start drag with %@", [pboard types]);
typelist = mimeTypeForPasteboardType (XDPY, [self zone], [pboard types]);
***************
*** 345,351 ****
Method to initialize the dragview before it is put on the screen.
It only initializes the instance variables that have to do with
moving the image over the screen and variables that are used
! to keep track where we.
So it is typically used just before the dragview is actually displayed.
--- 356,362 ----
Method to initialize the dragview before it is put on the screen.
It only initializes the instance variables that have to do with
moving the image over the screen and variables that are used
! to keep track where we are.
So it is typically used just before the dragview is actually displayed.
***************
*** 588,609 ****
| NSLeftMouseDraggedMask | NSMouseMovedMask
| NSPeriodicMask | NSAppKitDefinedMask | NSFlagsChangedMask;
! NSPoint point;
// Storing values, to restore after we have finished.
NSCursor *cursorBeforeDrag = [NSCursor currentCursor];
isDragging = YES;
! point = [eWindow convertBaseToScreen: [theEvent locationInWindow]];
! [self _setupWindow: point];
// Notify the source that dragging has started
if ([dragSource respondsToSelector:
@selector(draggedImage:beganAt:)])
{
[dragSource draggedImage: dragImage
! beganAt: point];
}
NSDebugLLog(@"NSDragging", @"Drag window X origin %d %d\n", wx, wy);
--- 599,620 ----
| NSLeftMouseDraggedMask | NSMouseMovedMask
| NSPeriodicMask | NSAppKitDefinedMask | NSFlagsChangedMask;
! NSPoint startPoint;
// Storing values, to restore after we have finished.
NSCursor *cursorBeforeDrag = [NSCursor currentCursor];
isDragging = YES;
! startPoint = [eWindow convertBaseToScreen: [theEvent locationInWindow]];
! [self _setupWindow: startPoint];
// Notify the source that dragging has started
if ([dragSource respondsToSelector:
@selector(draggedImage:beganAt:)])
{
[dragSource draggedImage: dragImage
! beganAt: startPoint];
}
NSDebugLLog(@"NSDragging", @"Drag window X origin %d %d\n", wx, wy);
***************
*** 643,661 ****
}
! // --- Event loop for drag opeeration stopped ------------------------
[NSEvent stopPeriodicEvents];
[self _updateAndMoveImageToCorrectPosition];
- [_window orderOut: nil];
-
NSDebugLLog(@"NSDragging", @"dnd ending %x\n", targetWindow);
-
// --- Deposit the drop ----------------------------------------------
if ((targetWindow != (Window) None) &&
! (targetMask & dragMask & operationMask != NSDragOperationNone))
{
NSDebugLLog(@"NSDragging", @"sending dnd drop\n");
if (!dragExternal)
--- 654,669 ----
}
! // --- Event loop for drag operation stopped ------------------------
[NSEvent stopPeriodicEvents];
[self _updateAndMoveImageToCorrectPosition];
NSDebugLLog(@"NSDragging", @"dnd ending %x\n", targetWindow);
// --- Deposit the drop ----------------------------------------------
if ((targetWindow != (Window) None) &&
! ((targetMask & dragMask & operationMask) != NSDragOperationNone))
{
NSDebugLLog(@"NSDragging", @"sending dnd drop\n");
if (!dragExternal)
***************
*** 680,685 ****
--- 688,695 ----
if ([dragSource respondsToSelector:
@selector(draggedImage:endedAt:deposited:)])
{
+ NSPoint point;
+
point = [theEvent locationInWindow];
point = [[theEvent window] convertBaseToScreen: point];
[dragSource draggedImage: dragImage
***************
*** 689,697 ****
--- 699,714 ----
}
else
{
+ if (slideBack)
+ {
+ [self slideDraggedImageTo: startPoint];
+ }
+
if ([dragSource respondsToSelector:
@selector(draggedImage:endedAt:deposited:)])
{
+ NSPoint point;
+
point = [theEvent locationInWindow];
point = [[theEvent window] convertBaseToScreen: point];
[dragSource draggedImage: dragImage
***************
*** 699,704 ****
--- 716,723 ----
deposited: NO];
}
}
+
+ [_window orderOut: nil];
[cursorBeforeDrag set];
isDragging = NO;
}
***************
*** 796,802 ****
}
/*
! * This method will move the drag image, update and update all associated data
*/
- (void) _updateAndMoveImageToCorrectPosition
{
--- 815,821 ----
}
/*
! * This method will move the drag image and update all associated data
*/
- (void) _updateAndMoveImageToCorrectPosition
{
***************
*** 807,823 ****
BOOL changeCursor = NO;
//--- Move drag image to the new position -----------------------------------
!
! // Move drag window, because X coordinates are flipped the wy and wx
! // calculations are different
! wx += (int) (newPosition.x - dragPosition.x);
! wy += (int) (dragPosition.y - newPosition.y);
!
! XMoveWindow (XDPY, dragWindev->ident, wx, wy);
!
//--- Store old values -----------------------------------------------------
- dragPosition = newPosition;
oldDragWindow = dragWindow;
oldDragExternal = dragExternal;
--- 826,836 ----
BOOL changeCursor = NO;
//--- Move drag image to the new position -----------------------------------
!
! [self _moveDraggedImageToNewPosition];
!
//--- Store old values -----------------------------------------------------
oldDragWindow = dragWindow;
oldDragExternal = dragExternal;
***************
*** 1005,1021 ****
return loc;
}
! - (void) slideDraggedImageTo: (NSPoint)screenPoint
{
! // FIXME
}
/*
! return search all descendents of parent and return
! window under mouse that accepts drag and drop.
! -1 if we can only find the window we are dragging under the mouse.
! None if there is no window under the mouse that accepts drag and drop.
*/
- (Window) _xWindowAcceptingDnDDescendentOf: (Window) parent underX: (int) x Y: (int) y
{
--- 1018,1102 ----
return loc;
}
!
! /*
! * Move the dragged image immediately to the position indicated by
! * the instance variable newPosition.
! *
! * In doing so it will update the (wx, wy) and dragPosition instance variables.
! */
! - (void) _moveDraggedImageToNewPosition
! {
! wx += (int) (newPosition.x - dragPosition.x);
! wy += (int) (dragPosition.y - newPosition.y);
!
! // We use this instead of the simpler `dragPosition = newPosition'
! // because we want to keep the dragPosition in sync with (wx, wy)
! // and (wx, wy) are integers.
! dragPosition.x += (float) ((int) newPosition.x - dragPosition.x);
! dragPosition.y += (float) ((int) newPosition.y - dragPosition.y);
!
! XMoveWindow (XDPY, dragWindev->ident, wx, wy);
! }
!
!
! - (void) _slideDraggedImageTo: (NSPoint)screenPoint
! numberOfSteps: (int) steps
! waitAfterSlide: (BOOL) waitFlag
! {
! // --- If we do not need multiple redrawing, just move the image immediately
! // to its desired spot.
!
! if (steps < 2)
! {
! newPosition = screenPoint;
! [self _moveDraggedImageToNewPosition];
! }
! else
! {
! [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: SLIDE_TIME_STEP];
!
! // Use the event loop to redraw the image repeatedly.
! // Using the event loop to allow the application to process
! // expose events.
! while (steps)
! {
! NSEvent *theEvent = [NSApp nextEventMatchingMask: NSPeriodicMask
! untilDate: [NSDate distantFuture]
! inMode: NSEventTrackingRunLoopMode
! dequeue: YES];
!
! if ([theEvent type] != NSPeriodic)
! {
! NSDebugLLog (@"NSDragging: Unexpected event type: %d during slide",
! [theEvent type]);
! }
! newPosition.x = (screenPoint.x + ((float) steps - 1.0) * dragPosition.x) / ((float) steps);
! newPosition.y = (screenPoint.y + ((float) steps - 1.0) * dragPosition.y) / ((float) steps);
!
! [self _moveDraggedImageToNewPosition];
! steps --;
! }
! [NSEvent stopPeriodicEvents];
! }
! if (waitFlag)
! {
! [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: SLIDE_TIME_STEP * 2.0]];
! }
! }
!
!
! - (void) slideDraggedImageTo: (NSPoint) point
{
! [self _slideDraggedImageTo: point numberOfSteps: SLIDE_NR_OF_STEPS waitAfterSlide: YES];
}
/*
! Search all descendents of parent and return
! X window containing screen coordinates (x,y) that accepts drag and drop.
! -1 if we can only find the X window that we are dragging
! None if there is no X window that accepts drag and drop.
*/
- (Window) _xWindowAcceptingDnDDescendentOf: (Window) parent underX: (int) x Y: (int) y
{