DnD cleanups and fixes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21028 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-04-01 14:10:39 +00:00
parent f3f0b8b94d
commit d2bb38a102
6 changed files with 125 additions and 61 deletions

View file

@ -1,3 +1,23 @@
2005-04-01 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <fedor@gnu.org>
* Version 0.9.5

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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;
}