Re: Window moving during drag and drop operation, (newbiew question)
Re: Window moving during drag and drop operation, (newbiew question)
- Subject: Re: Window moving during drag and drop operation, (newbiew question)
- From: Jesper Storm Bache <email@hidden>
- Date: Sun, 7 Dec 2008 10:48:38 -0800
Are you using a "metal" style window (NSTexturedBackgroundWindowMask).
If so, then you will want to look into how [NSView
mouseDownCanMoveWindow] works (try overriding it and return NO)
Jesper Storm Bache
On Dec 6, 2008, at 6:39 AM, Gustavo Pizano wrote:
On 6.12.2008, at 12:20, Gustavo Pizano wrote:
Hi all, its me again. well Im implementing the drag-n-drop op for my
app. in the Soruce view I have different layers, im checking which one
of those was clicked and then commence the drag and drop, but the
funny part is that ithe main window ts moving. Any clues why is this
happening..
thsi is my code Im using
-(void)mouseDragged:(NSEvent *)event
{
NSPoint down = [mouseDownEvent locationInWindow];
NSPoint drag = [event locationInWindow];
float distance = hypot(down.x - drag.x , down.y - drag.y);
if(distance < 3){
return;
}
//NSEnumerator * e = [shipsLayers objectEnumerator];
NSPoint auxPoint;
auxPoint = [self convertPoint:[mouseDownEvent locationInWindow]
fromView:nil];
CGRect r;
CALayer * actualLayer = [CALayer layer];
BOOL inRect = NO;
int i;
for (i =0;i < [shipsLayers count]; i++){
actualLayer = [shipsLayers objectAtIndex:i];
r = [actualLayer frame];
if(NSPointInRect(auxPoint,NSRectFromCGRect(r))){
inRect= YES;
break;
}
}
if(!inRect)
return; //if the drag wasn't made on any of the
layers containning
ships
//Create the image that will be dragged
NSSize s;
s = NSSizeFromCGSize(actualLayer.frame.size);
//Create a rect in which the image will be drawn
NSRect imageBounds;
imageBounds.origin=NSZeroPoint;
imageBounds.size = s;
//try out
CGImageRef cgImage = (CGImageRef)actualLayer.contents;
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc]
initWithCGImage:cgImage];
// Create an NSImage and add the bitmap rep to it...
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
[bitmapRep release];
// to here
//draw the image
[image lockFocus];
NSRect drawingRect = imageBounds;
[image drawInRect:drawingRect fromRect:imageBounds
operation:NSCompositeSourceOver fraction:0.8];
[image unlockFocus];
//get the location of the mouse
auxPoint.x = auxPoint.x - s.width/2;
auxPoint.y = auxPoint.y - s.height/2;
//Get the Pasteboard
NSPasteboard * pb = [NSPasteboard
pasteboardWithName:NSDragPboard];
//put the image on the pb, first delcare the types then copy
the
image into the pb
[pb declareTypes:[NSArray
arrayWithObjects:NSTIFFPboardType,NSPostScriptPboardType,nil]
owner:self];
//put the image into the pasteboard
[pb setData:[NSKeyedArchiver archivedDataWithRootObject:image]
forType:NSTIFFPboardType];
//start the drag
[self dragImage:image at:auxPoint offset:NSMakeSize(0, 0)
event:mouseDownEvent pasteboard:pb source:self slideBack:YES];
[image release];
}
Thanks a lot guys for your help
Gustavo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden