mirror of
https://github.com/gnustep/libs-back.git
synced 2025-02-23 11:51:27 +00:00
Make XGDragView a subclass of GSDragView
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@20999 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4e5fe7c3ac
commit
d7737164ec
3 changed files with 68 additions and 511 deletions
|
@ -1,3 +1,10 @@
|
|||
2005-03-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/x11/XGDragView.h: Make this a subclass of GSDragView
|
||||
* Source/x11/XGDragView.m: Rewrite to be a subclass of GSDragView
|
||||
so that bugfixes from it are in XGDragView. Remove lots of
|
||||
redundant code. Still quite a bit to do.
|
||||
|
||||
2005-03-29 Adrian Robert <arobert@cogsci.ucsd.edu>
|
||||
|
||||
* Source/art/ftfont.h, Source/art/ftfont.m, Source/art/ftfont-old.m:
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <AppKit/NSCell.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
#include <GNUstepGUI/GSDragView.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include "x11/xdnd.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
|
@ -39,14 +40,6 @@ Atom GSActionForDragOperation(unsigned int op);
|
|||
NSDragOperation GSDragOperationForAction(Atom xaction);
|
||||
|
||||
|
||||
/*
|
||||
used in the operation mask to indicate that the
|
||||
user can not change the drag action by
|
||||
pressing modifiers.
|
||||
*/
|
||||
|
||||
#define NSDragOperationIgnoresModifiers 0xffff
|
||||
|
||||
/*"
|
||||
WRO (notes made 18 Nov 2001)
|
||||
|
||||
|
@ -54,43 +47,12 @@ NSDragOperation GSDragOperationForAction(Atom xaction);
|
|||
It hijacks the event loop and manages the complete
|
||||
drag and drop sequence.
|
||||
"*/
|
||||
@interface XGDragView : NSView <NSDraggingInfo>
|
||||
@interface XGDragView : GSDragView
|
||||
{
|
||||
|
||||
NSCell *dragCell; /*" the graphics that is dragged"*/
|
||||
NSPasteboard *dragPasteboard;
|
||||
NSPoint dragPoint; /*" in base coordinates, only valid when dragWindow != nil "*/
|
||||
gswindow_device_t *dragWindev;
|
||||
|
||||
/* 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 "*/
|
||||
|
||||
int dragSequence;
|
||||
id dragSource;
|
||||
|
||||
unsigned int dragMask; /*" Operations supported by the source "*/
|
||||
unsigned int operationMask; /*" user specified operation mask (key modifiers).
|
||||
this is either a mask of type _NSDragOperation,
|
||||
or NSDragOperationIgnoresModifiers, which
|
||||
is defined as 0xffff "*/
|
||||
unsigned int targetMask; /*" Operations supported by the target, only valid if
|
||||
targetIsDndAware is true "*/
|
||||
|
||||
id dragWindow; /*" NSWindow in this application that is the current target "*/
|
||||
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;
|
||||
}
|
||||
|
||||
+ (XGDragView*) sharedDragView;
|
||||
|
||||
- (BOOL) isDragging;
|
||||
+ (id) sharedDragView;
|
||||
|
||||
- (void) setupDragInfoFromXEvent: (XEvent *)xEvent;
|
||||
- (void) updateDragInfoFromEvent: (NSEvent *)event;
|
||||
|
|
|
@ -48,6 +48,10 @@
|
|||
#define SLIDE_TIME_STEP .02 /* in seconds */
|
||||
#define SLIDE_NR_OF_STEPS 20
|
||||
|
||||
#define dragWindev [XGServer _windowWithTag: [_window windowNumber]]
|
||||
#define XX(P) (P.x)
|
||||
#define XY(P) (DisplayHeight(XDPY, dragWindev->screen) - P.y)
|
||||
|
||||
@interface XGRawWindow : NSWindow
|
||||
@end
|
||||
|
||||
|
@ -161,48 +165,11 @@ static XGDragView *sharedDragView = nil;
|
|||
return sharedDragView;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
+ (Class) windowClass
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
NSRect winRect = {{0, 0}, {DWZ, DWZ}};
|
||||
XGRawWindow *sharedDragWindow = [XGRawWindow alloc];
|
||||
|
||||
dragCell = [[NSCell alloc] initImageCell: nil];
|
||||
[dragCell setBordered: NO];
|
||||
|
||||
[sharedDragWindow initWithContentRect: winRect
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreNonretained
|
||||
defer: NO];
|
||||
[sharedDragWindow setContentView: self];
|
||||
RELEASE(self);
|
||||
|
||||
// Cache the X structure of our window
|
||||
dragWindev = [XGServer _windowWithTag: [sharedDragWindow windowNumber]];
|
||||
}
|
||||
|
||||
return self;
|
||||
return [XGRawWindow class];
|
||||
}
|
||||
|
||||
- (BOOL) isDragging
|
||||
{
|
||||
return isDragging;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
RELEASE(cursors);
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
[dragCell drawWithFrame: [self frame] inView: self];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* External drag operation
|
||||
*/
|
||||
|
@ -210,7 +177,7 @@ static XGDragView *sharedDragView = nil;
|
|||
{
|
||||
// Start a dragging session from another application
|
||||
dragSource = nil;
|
||||
dragExternal = YES;
|
||||
destExternal = YES;
|
||||
operationMask = NSDragOperationAll;
|
||||
|
||||
ASSIGN(dragPasteboard, [NSPasteboard pasteboardWithName: NSDragPboard]);
|
||||
|
@ -219,7 +186,7 @@ static XGDragView *sharedDragView = nil;
|
|||
- (void) updateDragInfoFromEvent: (NSEvent*)event
|
||||
{
|
||||
// Store the drag info, so that we can send status messages as response
|
||||
dragWindow = [event window];
|
||||
destWindow = [event window];
|
||||
dragPoint = [event locationInWindow];
|
||||
dragSequence = [event timestamp];
|
||||
dragMask = [event data2];
|
||||
|
@ -234,11 +201,6 @@ static XGDragView *sharedDragView = nil;
|
|||
* Local drag operation
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - use initialOffset
|
||||
* - use screenLocation
|
||||
*/
|
||||
- (void) dragImage: (NSImage*)anImage
|
||||
at: (NSPoint)screenLocation
|
||||
offset: (NSSize)initialOffset
|
||||
|
@ -247,52 +209,16 @@ static XGDragView *sharedDragView = nil;
|
|||
source: (id)sourceObject
|
||||
slideBack: (BOOL)slideFlag
|
||||
{
|
||||
if (anImage == nil)
|
||||
{
|
||||
anImage = [NSImage imageNamed: @"common_Close"];
|
||||
}
|
||||
|
||||
[dragCell setImage: anImage];
|
||||
|
||||
ASSIGN(dragPasteboard, pboard);
|
||||
dragSource = RETAIN(sourceObject);
|
||||
dragSequence = [event timestamp];
|
||||
dragExternal = NO;
|
||||
slideBack = slideFlag;
|
||||
|
||||
NSDebugLLog(@"NSDragging", @"Start drag with %@", [pboard types]);
|
||||
typelist = mimeTypeForPasteboardType (XDPY, [self zone], [pboard types]);
|
||||
[self _handleDrag: event];
|
||||
[super dragImage: anImage
|
||||
at: screenLocation
|
||||
offset: initialOffset
|
||||
event: event
|
||||
pasteboard: pboard
|
||||
source: sourceObject
|
||||
slideBack: slideFlag];
|
||||
NSZoneFree([self zone], typelist);
|
||||
typelist = NULL;
|
||||
RELEASE(dragSource);
|
||||
}
|
||||
|
||||
- (void) _sendLocalEvent: (GSAppKitSubtype)subtype
|
||||
action: (NSDragOperation)action
|
||||
position: (NSPoint)eventLocation
|
||||
timestamp: (NSTimeInterval)time
|
||||
toWindow: (NSWindow*)dWindow
|
||||
{
|
||||
NSEvent *e;
|
||||
NSGraphicsContext *context = GSCurrentContext();
|
||||
gswindow_device_t *windev;
|
||||
|
||||
windev = [XGServer _windowWithTag: [dWindow windowNumber]];
|
||||
eventLocation = NSMakePoint(eventLocation.x - NSMinX(windev->xframe),
|
||||
eventLocation.y - NSMinY(windev->xframe));
|
||||
eventLocation.y = NSHeight(windev->xframe) - eventLocation.y;
|
||||
|
||||
e = [NSEvent otherEventWithType: NSAppKitDefined
|
||||
location: eventLocation
|
||||
modifierFlags: 0
|
||||
timestamp: time
|
||||
windowNumber: windev->number
|
||||
context: context
|
||||
subtype: subtype
|
||||
data1: dragWindev->ident
|
||||
data2: action];
|
||||
[dWindow sendEvent: e];
|
||||
}
|
||||
|
||||
- (void) postDragEvent: (NSEvent *)theEvent
|
||||
|
@ -304,7 +230,7 @@ static XGDragView *sharedDragView = nil;
|
|||
{
|
||||
NSDragOperation action = [theEvent data2];
|
||||
|
||||
if (dragExternal)
|
||||
if (destExternal)
|
||||
{
|
||||
Atom xaction;
|
||||
|
||||
|
@ -328,7 +254,7 @@ static XGDragView *sharedDragView = nil;
|
|||
}
|
||||
else if ([theEvent subtype] == GSAppKitDraggingFinished)
|
||||
{
|
||||
if (dragExternal)
|
||||
if (destExternal)
|
||||
{
|
||||
xdnd_send_finished(&dnd,
|
||||
[theEvent data1],
|
||||
|
@ -342,199 +268,6 @@ static XGDragView *sharedDragView = nil;
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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.
|
||||
|
||||
Pre coniditions:
|
||||
- dragCell is initialized with the image to drag.
|
||||
- typelist is initialized with the dragging types
|
||||
Post conditions:
|
||||
- all instance variables pertaining to moving the window are initialized
|
||||
- all instance variables pertaining to X-Windows are initialized
|
||||
|
||||
*/
|
||||
- (void) _setupWindow: (NSPoint) dragStart
|
||||
{
|
||||
NSSize imageSize = [[dragCell image] size];
|
||||
|
||||
offset = NSMakePoint (imageSize.width / 2.0, imageSize.height / 2.0);
|
||||
|
||||
[_window setFrame: NSMakeRect (dragStart.x - offset.x,
|
||||
dragStart.y - offset.y,
|
||||
imageSize.width, imageSize.height)
|
||||
display: NO];
|
||||
|
||||
NSDebugLLog (@"NSDragging", @"---dragWindow: %x <- %x",
|
||||
dragWindev->parent, dragWindev->ident);
|
||||
|
||||
/* setup the wx and wy coordinates, used for moving the view around */
|
||||
wx = dragWindev->siz_hints.x;
|
||||
wy = dragWindev->siz_hints.y;
|
||||
|
||||
dragPosition = dragStart;
|
||||
newPosition = dragStart;
|
||||
|
||||
// Only display the image
|
||||
[GSServerForWindow(_window) restrictWindow: dragWindev->number
|
||||
toImage: [dragCell image]];
|
||||
|
||||
[_window orderFront: nil];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
updates the operationMask by examining modifier keys
|
||||
pressed during -theEvent-.
|
||||
|
||||
If the current value of operationMask == NSDragOperationIgnoresModifiers
|
||||
it will return immediately without updating the operationMask
|
||||
|
||||
This method will return YES if the operationMask
|
||||
is changed, NO if it is still the same.
|
||||
*/
|
||||
- (BOOL) _updateOperationMask: (NSEvent*) theEvent
|
||||
{
|
||||
unsigned int mod = [theEvent modifierFlags];
|
||||
unsigned int oldOperationMask = operationMask;
|
||||
|
||||
if (operationMask == NSDragOperationIgnoresModifiers)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (mod & NSControlKeyMask)
|
||||
{
|
||||
operationMask = NSDragOperationLink;
|
||||
}
|
||||
else if (mod & NSAlternateKeyMask)
|
||||
{
|
||||
operationMask = NSDragOperationCopy;
|
||||
}
|
||||
else if (mod & NSCommandKeyMask)
|
||||
{
|
||||
operationMask = NSDragOperationGeneric;
|
||||
}
|
||||
else
|
||||
{
|
||||
operationMask = NSDragOperationAll;
|
||||
}
|
||||
|
||||
return (operationMask != oldOperationMask);
|
||||
}
|
||||
|
||||
/**
|
||||
_setCursor examines the state of the dragging and update
|
||||
the cursor accordingly. It will not save the current cursor,
|
||||
if you want to keep the original you have to save it yourself.
|
||||
|
||||
The code recogines 4 cursors:
|
||||
|
||||
- NONE - when the source does not allow dragging
|
||||
- COPY - when the current operation is ONLY Copy
|
||||
- LINK - when the current operation is ONLY Link
|
||||
- GENERIC - all other cases
|
||||
|
||||
And two colors
|
||||
|
||||
- GREEN - when the target accepts the drop
|
||||
- BLACK - when the target does not accept the drop
|
||||
|
||||
Note that the code to figure out which of the 4 cursor to use
|
||||
depends on the fact that
|
||||
|
||||
{NSDragOperationNone, NSDragOperationCopy, NSDragOperationLink} = {0, 1, 2}
|
||||
*/
|
||||
- (void) _setCursor
|
||||
{
|
||||
NSCursor *newCursor;
|
||||
NSString *name;
|
||||
NSString *iname;
|
||||
int mask;
|
||||
|
||||
mask = dragMask & operationMask;
|
||||
|
||||
if (targetWindow)
|
||||
mask &= targetMask;
|
||||
|
||||
NSDebugLLog (@"NSDragging",
|
||||
@"drag, operation, target mask = (%x, %x, %x), dnd aware = %d\n",
|
||||
dragMask, operationMask, targetMask,
|
||||
(targetWindow != (Window) None));
|
||||
|
||||
if (cursors == nil)
|
||||
cursors = RETAIN([NSMutableDictionary dictionary]);
|
||||
|
||||
name = iname = nil;
|
||||
newCursor = nil;
|
||||
switch (mask)
|
||||
{
|
||||
case NSDragOperationNone:
|
||||
name = @"NoCursor";
|
||||
iname = @"common_noCursor";
|
||||
break;
|
||||
case NSDragOperationCopy:
|
||||
name = @"CopyCursor";
|
||||
iname = @"common_copyCursor";
|
||||
break;
|
||||
case NSDragOperationLink:
|
||||
name = @"LinkCursor";
|
||||
iname = @"common_linkCursor";
|
||||
break;
|
||||
case NSDragOperationGeneric:
|
||||
break;
|
||||
default:
|
||||
// FIXME: Should not happen, add warning?
|
||||
break;
|
||||
}
|
||||
|
||||
if (name != nil)
|
||||
{
|
||||
newCursor = [cursors objectForKey: name];
|
||||
if (newCursor == nil)
|
||||
{
|
||||
NSImage *image = [NSImage imageNamed: iname];
|
||||
newCursor = [[NSCursor alloc] initWithImage: image];
|
||||
[cursors setObject: newCursor forKey: name];
|
||||
RELEASE(newCursor);
|
||||
}
|
||||
}
|
||||
if (newCursor == nil)
|
||||
{
|
||||
name = @"ArrowCursor";
|
||||
newCursor = [cursors objectForKey: name];
|
||||
if (newCursor == nil)
|
||||
{
|
||||
/* Make our own arrow cursor, since we want to color it */
|
||||
void *c;
|
||||
|
||||
newCursor = [[NSCursor alloc] initWithImage: nil];
|
||||
[GSCurrentServer() standardcursor: GSArrowCursor : &c];
|
||||
[newCursor _setCid: c];
|
||||
[cursors setObject: newCursor forKey: name];
|
||||
RELEASE(newCursor);
|
||||
}
|
||||
}
|
||||
|
||||
[newCursor set];
|
||||
|
||||
if ((targetWindow != (Window) None) && mask != NSDragOperationNone)
|
||||
{
|
||||
[GSCurrentServer() setcursorcolor: [NSColor greenColor]
|
||||
: [NSColor blackColor]
|
||||
: [newCursor _cid]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[GSCurrentServer() setcursorcolor: [NSColor blackColor]
|
||||
: [NSColor whiteColor]
|
||||
: [newCursor _cid]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The dragging support works by hijacking the NSApp event loop.
|
||||
|
@ -571,14 +304,12 @@ static XGDragView *sharedDragView = nil;
|
|||
BOOL refreshedView = NO;
|
||||
|
||||
// Unset the target window
|
||||
targetWindow = 0;
|
||||
targetWindowRef = 0;
|
||||
targetMask = NSDragOperationAll;
|
||||
|
||||
isDragging = YES;
|
||||
startPoint = [eWindow convertBaseToScreen: [theEvent locationInWindow]];
|
||||
|
||||
[self _setupWindow: startPoint];
|
||||
|
||||
// Notify the source that dragging has started
|
||||
if ([dragSource respondsToSelector:
|
||||
@selector(draggedImage:beganAt:)])
|
||||
|
@ -587,8 +318,6 @@ static XGDragView *sharedDragView = nil;
|
|||
beganAt: startPoint];
|
||||
}
|
||||
|
||||
NSDebugLLog(@"NSDragging", @"Drag window X origin %d %d\n", wx, wy);
|
||||
|
||||
// --- Setup up the masks for the drag operation ---------------------
|
||||
if ([dragSource respondsToSelector:
|
||||
@selector(ignoreModifierKeysWhileDragging)]
|
||||
|
@ -602,7 +331,7 @@ static XGDragView *sharedDragView = nil;
|
|||
[self _updateOperationMask: theEvent];
|
||||
}
|
||||
|
||||
dragMask = [dragSource draggingSourceOperationMaskForLocal: !dragExternal];
|
||||
dragMask = [dragSource draggingSourceOperationMaskForLocal: !destExternal];
|
||||
|
||||
// --- Setup the event loop ------------------------------------------
|
||||
[self _updateAndMoveImageToCorrectPosition];
|
||||
|
@ -631,10 +360,10 @@ static XGDragView *sharedDragView = nil;
|
|||
[NSEvent stopPeriodicEvents];
|
||||
[self _updateAndMoveImageToCorrectPosition];
|
||||
|
||||
NSDebugLLog(@"NSDragging", @"dnd ending %x\n", targetWindow);
|
||||
NSDebugLLog(@"NSDragging", @"dnd ending %x\n", targetWindowRef);
|
||||
|
||||
// --- Deposit the drop ----------------------------------------------
|
||||
if ((targetWindow != (Window) None)
|
||||
if ((targetWindowRef != (int) None)
|
||||
&& ((targetMask & dragMask & operationMask) != NSDragOperationNone))
|
||||
{
|
||||
// FIXME: (22 Jan 2002)
|
||||
|
@ -653,21 +382,21 @@ static XGDragView *sharedDragView = nil;
|
|||
[_window orderOut: nil];
|
||||
[cursorBeforeDrag set];
|
||||
NSDebugLLog(@"NSDragging", @"sending dnd drop\n");
|
||||
if (!dragExternal)
|
||||
if (!destExternal)
|
||||
{
|
||||
[self _sendLocalEvent: GSAppKitDraggingDrop
|
||||
action: 0
|
||||
position: NSZeroPoint
|
||||
timestamp: CurrentTime
|
||||
toWindow: dragWindow];
|
||||
toWindow: destWindow];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetWindow == dragWindev->root)
|
||||
if (targetWindowRef == dragWindev->root)
|
||||
{
|
||||
// FIXME There is an xdnd extension for root drop
|
||||
}
|
||||
xdnd_send_drop(&dnd, targetWindow, dragWindev->ident, CurrentTime);
|
||||
xdnd_send_drop(&dnd, targetWindowRef, dragWindev->ident, CurrentTime);
|
||||
}
|
||||
|
||||
//CHECKME: Why XSync here?
|
||||
|
@ -723,6 +452,7 @@ static XGDragView *sharedDragView = nil;
|
|||
switch (sub)
|
||||
{
|
||||
case GSAppKitWindowMoved:
|
||||
case GSAppKitWindowResized:
|
||||
/*
|
||||
* Keep window up-to-date with its current position.
|
||||
*/
|
||||
|
@ -731,7 +461,7 @@ static XGDragView *sharedDragView = nil;
|
|||
|
||||
case GSAppKitDraggingStatus:
|
||||
NSDebugLLog(@"NSDragging", @"got GSAppKitDraggingStatus\n");
|
||||
if ((Window)[theEvent data1] == targetWindow)
|
||||
if ((Window)[theEvent data1] == targetWindowRef)
|
||||
{
|
||||
unsigned int newTargetMask = [theEvent data2];
|
||||
|
||||
|
@ -772,19 +502,19 @@ static XGDragView *sharedDragView = nil;
|
|||
{
|
||||
// If flags change, send update to allow
|
||||
// destination to take note.
|
||||
if (dragWindow)
|
||||
if (destWindow)
|
||||
{
|
||||
[self _sendLocalEvent: GSAppKitDraggingUpdate
|
||||
action: dragMask & operationMask
|
||||
position: NSMakePoint(wx + offset.x, wy + offset.y)
|
||||
position: newPosition
|
||||
timestamp: CurrentTime
|
||||
toWindow: dragWindow];
|
||||
toWindow: destWindow];
|
||||
}
|
||||
else
|
||||
{
|
||||
xdnd_send_position(&dnd, targetWindow, dragWindev->ident,
|
||||
xdnd_send_position(&dnd, targetWindowRef, dragWindev->ident,
|
||||
GSActionForDragOperation(dragMask & operationMask),
|
||||
wx + offset.x, wy + offset.y, CurrentTime);
|
||||
XX(newPosition), XY(newPosition), CurrentTime);
|
||||
}
|
||||
[self _setCursor];
|
||||
}
|
||||
|
@ -817,14 +547,13 @@ static XGDragView *sharedDragView = nil;
|
|||
|
||||
//--- Store old values -----------------------------------------------------
|
||||
|
||||
oldDragWindow = dragWindow;
|
||||
oldDragExternal = dragExternal;
|
||||
oldDragWindow = destWindow;
|
||||
oldDragExternal = destExternal;
|
||||
|
||||
|
||||
//--- Determine target XWindow ---------------------------------------------
|
||||
|
||||
mouseWindow = [self _xWindowAcceptingDnDunderX: wx + offset.x
|
||||
Y: wy + offset.y];
|
||||
|
||||
mouseWindow = [self _xWindowAcceptingDnDunderX: XX(dragPosition) Y: XY(dragPosition)];
|
||||
|
||||
//--- Determine target NSWindow --------------------------------------------
|
||||
|
||||
|
@ -832,21 +561,21 @@ static XGDragView *sharedDragView = nil;
|
|||
|
||||
if (dwindev != 0)
|
||||
{
|
||||
dragWindow = GSWindowWithNumber(dwindev->number);
|
||||
destWindow = GSWindowWithNumber(dwindev->number);
|
||||
}
|
||||
else
|
||||
{
|
||||
dragWindow = nil;
|
||||
destWindow = nil;
|
||||
}
|
||||
|
||||
// If we have are not hovering above a window that we own
|
||||
// we are dragging to an external application.
|
||||
|
||||
dragExternal = (mouseWindow != (Window) None) && (dragWindow == nil);
|
||||
destExternal = (mouseWindow != (Window) None) && (destWindow == nil);
|
||||
|
||||
if (dragWindow)
|
||||
if (destWindow)
|
||||
{
|
||||
dragPoint = [dragWindow convertScreenToBase: dragPosition];
|
||||
dragPoint = [destWindow convertScreenToBase: dragPosition];
|
||||
}
|
||||
|
||||
NSDebugLLog(@"NSDragging", @"mouse window %x\n", mouseWindow);
|
||||
|
@ -855,7 +584,7 @@ static XGDragView *sharedDragView = nil;
|
|||
|
||||
//--- send exit message if necessary -------------------------------------
|
||||
|
||||
if ((mouseWindow != targetWindow) && targetWindow)
|
||||
if ((mouseWindow != targetWindowRef) && targetWindowRef)
|
||||
{
|
||||
/* If we change windows and the old window is dnd aware, we send an
|
||||
dnd exit */
|
||||
|
@ -872,17 +601,17 @@ static XGDragView *sharedDragView = nil;
|
|||
}
|
||||
else
|
||||
{
|
||||
xdnd_send_leave(&dnd, targetWindow, dragWindev->ident);
|
||||
xdnd_send_leave(&dnd, targetWindowRef, dragWindev->ident);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset drag mask when we switch from external to internal or back
|
||||
//
|
||||
if (oldDragExternal != dragExternal)
|
||||
if (oldDragExternal != destExternal)
|
||||
{
|
||||
unsigned int newMask;
|
||||
|
||||
newMask = [dragSource draggingSourceOperationMaskForLocal: dragExternal];
|
||||
newMask = [dragSource draggingSourceOperationMaskForLocal: destExternal];
|
||||
if (newMask != dragMask)
|
||||
{
|
||||
dragMask = newMask;
|
||||
|
@ -891,22 +620,22 @@ static XGDragView *sharedDragView = nil;
|
|||
}
|
||||
|
||||
|
||||
if (mouseWindow == targetWindow && targetWindow)
|
||||
if (mouseWindow == targetWindowRef && targetWindowRef)
|
||||
{ // same window, sending update
|
||||
NSDebugLLog(@"NSDragging", @"sending dnd pos\n");
|
||||
if (dragWindow)
|
||||
if (destWindow)
|
||||
{
|
||||
[self _sendLocalEvent: GSAppKitDraggingUpdate
|
||||
action: dragMask & operationMask
|
||||
position: NSMakePoint (wx + offset.x, wy + offset.y)
|
||||
position: dragPosition
|
||||
timestamp: CurrentTime
|
||||
toWindow: dragWindow];
|
||||
toWindow: destWindow];
|
||||
}
|
||||
else
|
||||
{
|
||||
xdnd_send_position(&dnd, targetWindow, dragWindev->ident,
|
||||
GSActionForDragOperation (dragMask & operationMask), wx + offset.x,
|
||||
wy + offset.y, CurrentTime);
|
||||
xdnd_send_position(&dnd, targetWindowRef, dragWindev->ident,
|
||||
GSActionForDragOperation (dragMask & operationMask),
|
||||
XX(dragPosition), XY(dragPosition), CurrentTime);
|
||||
}
|
||||
}
|
||||
else if (mouseWindow != (Window) None)
|
||||
|
@ -917,26 +646,26 @@ static XGDragView *sharedDragView = nil;
|
|||
NSDebugLLog(@"NSDragging",
|
||||
@"sending dnd enter/pos\n");
|
||||
|
||||
if (dragWindow)
|
||||
if (destWindow)
|
||||
{
|
||||
[self _sendLocalEvent: GSAppKitDraggingEnter
|
||||
action: dragMask
|
||||
position: NSMakePoint (wx + offset.x, wy + offset.y)
|
||||
position:dragPosition
|
||||
timestamp: CurrentTime
|
||||
toWindow: dragWindow];
|
||||
toWindow: destWindow];
|
||||
}
|
||||
else
|
||||
{
|
||||
xdnd_send_enter(&dnd, mouseWindow, dragWindev->ident, typelist);
|
||||
xdnd_send_position(&dnd, mouseWindow, dragWindev->ident,
|
||||
GSActionForDragOperation (dragMask & operationMask),
|
||||
wx + offset.x, wy + offset.y, CurrentTime);
|
||||
XX(dragPosition), XY(dragPosition), CurrentTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetWindow != mouseWindow)
|
||||
if (targetWindowRef != mouseWindow)
|
||||
{
|
||||
targetWindow = mouseWindow;
|
||||
targetWindowRef = mouseWindow;
|
||||
changeCursor = YES;
|
||||
}
|
||||
|
||||
|
@ -946,147 +675,6 @@ static XGDragView *sharedDragView = nil;
|
|||
}
|
||||
}
|
||||
|
||||
/* NSDraggingInfo protocol */
|
||||
- (NSWindow*) draggingDestinationWindow
|
||||
{
|
||||
return dragWindow;
|
||||
}
|
||||
|
||||
- (NSPoint) draggingLocation
|
||||
{
|
||||
return dragPoint;
|
||||
}
|
||||
|
||||
- (NSPasteboard*) draggingPasteboard
|
||||
{
|
||||
return dragPasteboard;
|
||||
}
|
||||
|
||||
- (int) draggingSequenceNumber
|
||||
{
|
||||
return dragSequence;
|
||||
}
|
||||
|
||||
- (id) draggingSource
|
||||
{
|
||||
return dragSource;
|
||||
}
|
||||
|
||||
- (unsigned int) draggingSourceOperationMask
|
||||
{
|
||||
// Mix in possible modifiers
|
||||
return dragMask & operationMask;
|
||||
}
|
||||
|
||||
- (NSImage*) draggedImage
|
||||
{
|
||||
if (dragSource)
|
||||
return [dragCell image];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSPoint) draggedImageLocation
|
||||
{
|
||||
NSPoint loc;
|
||||
|
||||
if (dragSource)
|
||||
{
|
||||
NSSize size;
|
||||
|
||||
size = [[dragCell image] size];
|
||||
loc = NSMakePoint(dragPoint.x-size.width/2, dragPoint.y - size.height/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
loc = dragPoint;
|
||||
}
|
||||
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);
|
||||
*/
|
||||
[GSServerForWindow(_window) movewindow: NSMakePoint(newPosition.x - offset.x,
|
||||
newPosition.y - offset.y)
|
||||
: dragWindev->number];
|
||||
}
|
||||
|
||||
|
||||
- (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
|
||||
|
|
Loading…
Reference in a new issue