diff --git a/ChangeLog b/ChangeLog index 2dd0a192f..dc0c98524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-04-01 Richard Frith-Macdonald + + * Source/GSDragView.m: when dragging, use the mouse offset to adjust + the initial position of the dragged image. + Modified internally to pass the original position of the image so + that slideback can slide to that position rather than the position + the mouse started from. This makes no difference if the initial + mouse offset was zero, but does have an effect if the drag was + initiated by a mouse move at a location offset from the original + mouse down. + Exposed a couple of methods for subclasses. + * Source/NSColorPanel.m: Set image position for DnD so that color + swatch is centered on the mouse position. + * Source/NSImageView.m: ditto + * Source/NSTableView.m: ([-mouseDown:]) after calling the + ([-dragImageForRows:event:dragImageOffset:]) method, use the + returned offset to position the center of the image relative + to the mouse pointer .. I *think* that's what the apple documentation + of the method means. + 2005-03-30 Adam Fedor * Version 0.9.5 diff --git a/Headers/Additions/GNUstepGUI/GSDragView.h b/Headers/Additions/GNUstepGUI/GSDragView.h index 4969045bb..7bfbc0ef2 100644 --- a/Headers/Additions/GNUstepGUI/GSDragView.h +++ b/Headers/Additions/GNUstepGUI/GSDragView.h @@ -113,5 +113,12 @@ source: (id)sourceObject slideBack: (BOOL)slideFlag; - (void) postDragEvent: (NSEvent*)theEvent; +- (void) sendExternalEvent: (GSAppKitSubtype)subtype + action: (NSDragOperation)action + position: (NSPoint)eventLocation + timestamp: (NSTimeInterval)time + toWindow: (int)dWindowNumber; +- (NSWindow*) windowAcceptingDnDunder: (NSPoint)mouseLocation + windowRef: (int*)mouseWindowRef; @end diff --git a/Source/GSDragView.m b/Source/GSDragView.m index c4f0e6cce..b55872945 100644 --- a/Source/GSDragView.m +++ b/Source/GSDragView.m @@ -69,12 +69,6 @@ position: (NSPoint)eventLocation timestamp: (NSTimeInterval)time toWindow: (NSWindow*)dWindow; -- (void) _sendExternalEvent: (GSAppKitSubtype)subtype - action: (NSDragOperation)action - position: (NSPoint)eventLocation - timestamp: (NSTimeInterval)time - toWindow: (int)dWindowNumber; -- (void) _handleDrag: (NSEvent*)theEvent; - (void) _handleEventDuringDragging: (NSEvent *)theEvent; - (void) _updateAndMoveImageToCorrectPosition; - (void) _moveDraggedImageToNewPosition; @@ -82,8 +76,6 @@ numberOfSteps: (int) steps delay: (float) delay waitAfterSlide: (BOOL) waitFlag; -- (NSWindow*) _windowAcceptingDnDunder: (NSPoint) mouseLocation - windowRef: (int*)mouseWindowRef; @end @implementation GSRawWindow @@ -234,6 +226,7 @@ static GSDragView *sharedDragView = nil; slideBack: (BOOL)slideFlag { NSPoint eventPoint; + NSPoint imagePoint; ASSIGN(dragPasteboard, pboard); ASSIGN(dragSource, sourceObject); @@ -250,20 +243,26 @@ static GSDragView *sharedDragView = nil; /* * The position of the mouse is the event location plus any offset * provided. We convert this from window coordinates to screen - * coordinates, then determine the screen offset between the mouse - * pointer and the dragged image. + * coordinates. */ eventPoint = [event locationInWindow]; + eventPoint = [[event window] convertBaseToScreen: eventPoint]; eventPoint.x += initialOffset.width; eventPoint.y += initialOffset.height; - eventPoint = [[event window] convertBaseToScreen: eventPoint]; + + /* + * Adjust image location to match the mose adjustment. + */ + imagePoint = screenLocation; + imagePoint.x += initialOffset.width; + imagePoint.y += initialOffset.height; [self _setupWindowFor: anImage mousePosition: eventPoint - imagePosition: screenLocation]; + imagePosition: imagePoint]; isDragging = YES; - [self _handleDrag: event]; + [self _handleDrag: event slidePoint: screenLocation]; isDragging = NO; DESTROY(dragSource); DESTROY(dragPasteboard); @@ -532,11 +531,11 @@ static GSDragView *sharedDragView = nil; [dWindow sendEvent: e]; } -- (void) _sendExternalEvent: (GSAppKitSubtype)subtype - action: (NSDragOperation)action - position: (NSPoint)eventLocation - timestamp: (NSTimeInterval)time - toWindow: (int)dWindowNumber +- (void) sendExternalEvent: (GSAppKitSubtype)subtype + action: (NSDragOperation)action + position: (NSPoint)eventLocation + timestamp: (NSTimeInterval)time + toWindow: (int)dWindowNumber { } @@ -561,7 +560,7 @@ static GSDragView *sharedDragView = nil; - It seems that sometimes a periodic event get lost. */ -- (void) _handleDrag: (NSEvent*)theEvent +- (void) _handleDrag: (NSEvent*)theEvent slidePoint: (NSPoint)slidePoint { // Caching some often used values. These values do not // change in this method. @@ -656,11 +655,11 @@ static GSDragView *sharedDragView = nil; } else { - [self _sendExternalEvent: GSAppKitDraggingDrop - action: 0 - position: NSZeroPoint - timestamp: [theEvent timestamp] - toWindow: targetWindowRef]; + [self sendExternalEvent: GSAppKitDraggingDrop + action: 0 + position: NSZeroPoint + timestamp: [theEvent timestamp] + toWindow: targetWindowRef]; } deposited = YES; } @@ -668,7 +667,7 @@ static GSDragView *sharedDragView = nil; { if (slideBack) { - [self slideDraggedImageTo: startPoint]; + [self slideDraggedImageTo: slidePoint]; } [self _clearupWindow]; [cursorBeforeDrag set]; @@ -765,11 +764,11 @@ static GSDragView *sharedDragView = nil; } else { - [self _sendExternalEvent: GSAppKitDraggingUpdate - action: dragMask & operationMask - position: newPosition - timestamp: [theEvent timestamp] - toWindow: targetWindowRef]; + [self sendExternalEvent: GSAppKitDraggingUpdate + action: dragMask & operationMask + position: newPosition + timestamp: [theEvent timestamp] + toWindow: targetWindowRef]; } [self _setCursor]; } @@ -801,8 +800,8 @@ static GSDragView *sharedDragView = nil; [self _moveDraggedImageToNewPosition]; //--- Determine target window --------------------------------------------- - destWindow = [self _windowAcceptingDnDunder: dragPosition - windowRef: &mouseWindowRef]; + destWindow = [self windowAcceptingDnDunder: dragPosition + windowRef: &mouseWindowRef]; // If we have are not hovering above a window that we own // we are dragging to an external application. @@ -833,11 +832,11 @@ static GSDragView *sharedDragView = nil; } else { - [self _sendExternalEvent: GSAppKitDraggingExit - action: dragMask & operationMask - position: NSZeroPoint - timestamp: dragSequence - toWindow: targetWindowRef]; + [self sendExternalEvent: GSAppKitDraggingExit + action: dragMask & operationMask + position: NSZeroPoint + timestamp: dragSequence + toWindow: targetWindowRef]; } } @@ -869,11 +868,11 @@ static GSDragView *sharedDragView = nil; } else { - [self _sendExternalEvent: GSAppKitDraggingUpdate - action: dragMask & operationMask - position: dragPosition - timestamp: dragSequence - toWindow: targetWindowRef]; + [self sendExternalEvent: GSAppKitDraggingUpdate + action: dragMask & operationMask + position: dragPosition + timestamp: dragSequence + toWindow: targetWindowRef]; } } else if (mouseWindowRef != 0) @@ -892,11 +891,11 @@ static GSDragView *sharedDragView = nil; } else { - [self _sendExternalEvent: GSAppKitDraggingEnter - action: dragMask - position: dragPosition - timestamp: dragSequence - toWindow: mouseWindowRef]; + [self sendExternalEvent: GSAppKitDraggingEnter + action: dragMask + position: dragPosition + timestamp: dragSequence + toWindow: mouseWindowRef]; } } @@ -986,8 +985,8 @@ static GSDragView *sharedDragView = nil; In mouseWindowRef the OS reference for this window is returned, this is even set, if there is a native window, but no GNUstep window at this location. */ -- (NSWindow*) _windowAcceptingDnDunder: (NSPoint)mouseLocation - windowRef: (int*)mouseWindowRef +- (NSWindow*) windowAcceptingDnDunder: (NSPoint)mouseLocation + windowRef: (int*)mouseWindowRef { int win; diff --git a/Source/NSColorPanel.m b/Source/NSColorPanel.m index 078a31df7..6078b572c 100644 --- a/Source/NSColorPanel.m +++ b/Source/NSColorPanel.m @@ -416,14 +416,21 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel; { NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard]; NSImage *image = [NSImage imageNamed: @"common_ColorSwatch"]; + NSSize s; + NSPoint p; [pb declareTypes: [NSArray arrayWithObjects: NSColorPboardType, nil] owner: aColor]; [aColor writeToPasteboard: pb]; [image setBackgroundColor: aColor]; + s = [image size]; + p = [sourceView convertPoint: [anEvent locationInWindow] fromView: nil]; + p.x -= s.width/2; + p.y -= s.width/2; + [sourceView dragImage: image - at: [sourceView bounds].origin + at: p offset: NSMakeSize(0,0) event: anEvent pasteboard: pb diff --git a/Source/NSImageView.m b/Source/NSImageView.m index 2760c4ec7..8d5fe477c 100644 --- a/Source/NSImageView.m +++ b/Source/NSImageView.m @@ -220,8 +220,17 @@ static Class imageCellClass; if ([pboard setData: [anImage TIFFRepresentation] forType: NSTIFFPboardType]) { + NSSize s; + NSPoint p; + + // Center the image on the mouse position ... is this right? + s = [anImage size]; + p = [theEvent locationInWindow]; + p = [self convertPoint: p fromView: nil]; + p.x -= s.width/2; + p.y -= s.width/2; [_window dragImage: anImage - at: [theEvent locationInWindow] + at: p offset: NSMakeSize(0, 0) event: theEvent pasteboard: pboard diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 49812e5ae..ad7cc15ec 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -3613,18 +3613,40 @@ static inline float computePeriod(NSPoint mouseLocationWin, if ([self _writeRows: rows toPasteboard: pboard] == YES) { - NSPoint p = NSZeroPoint; - NSImage *dragImage = - [self dragImageForRows: rows - event: theEvent - dragImageOffset: &p]; + NSPoint p = NSZeroPoint; + NSImage *dragImage; + NSSize s; + + dragImage = [self dragImageForRows: rows + event: theEvent + dragImageOffset: &p]; + /* + * Store image offset in s ... the returned + * value is the position of the center of + * the image, so we adjust to the bottom left + * corner. + */ + s = [dragImage size]; + s.width = p.x - s.width/2; + s.height = p.y - s.height/2; + + /* + * Find the current mouse location and adjust + * it to determine the location of the bottom + * left corner of the image in this view's + * coordinate system. + */ + p = [self convertPoint: + [theEvent locationInWindow] fromView: nil]; + p.x += s.width; + p.y += s.height; [self dragImage: dragImage - at: NSZeroPoint - offset: NSMakeSize(0, 0) - event: theEvent - pasteboard: pboard - source: self + at: p + offset: NSMakeSize(0, 0) + event: theEvent + pasteboard: pboard + source: self slideBack: YES]; return; }