Re: When will drag'n'drop to the Finder work? (promiseHFS)
Re: When will drag'n'drop to the Finder work? (promiseHFS)
- Subject: Re: When will drag'n'drop to the Finder work? (promiseHFS)
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 13 May 2002 22:28:17 -0700
It is available RIGHT NOW, but does require the use of one private method
on NSEvent.
What follows is a method that works just fine, but doesn't correctly drag
an actual image-- I couldn't figure out how to generate a draggable Carbon
type image from a Cocoa based NSImage (if someone can, please let me know!
!!).
In any case, if the functionality exists in Carbon it can generally be
used in Cocoa without a problem. Just because something is wrapped with a
nice ObjC API doesn't make it useless, just inconvenient.
There is a necessary evolution that has to happen before an API from
Carbon can be made available in Cocoa. Namely, it needs to be refactored
from the Carbon based functionality into a Core based API. Once the API
has been refined to the point of being stabilized in the Core, it is
eligible to be wrapped.
b.bum
- (void)mouseDown:(NSEvent *)e
{
Point mouseInPoint = { (short) [e locationInWindow].x, (short) [e
locationInWindow].y };
RgnHandle dragRegion, tempRegion;
WindowRef windowRef;
CGrafPtr windowCGrafPtr;
BitMapPtr srcBitMap;
BitMapPtr destBitMap;
Rect srcRect;
Rect dstRect;
NSRect srcNSRect;
Point theLoc = {10,10};
DragRef theDragRef;
EventRecord eventRecord;
int error;
Rect dragBounds;
DragSendDataUPP sendProc;
windowRef = [[self window] windowRef];
windowCGrafPtr = GetWindowStructurePort(windowRef);
srcBitMap = GetPortBitMapForCopyBits(windowCGrafPtr);
destBitMap = malloc(sizeof(BitMap));
srcNSRect = [self frame];
/*
srcRect.top = srcNSRect.origin.y + srcNSRect.size.height;
srcRect.left = srcNSRect.origin.x;
srcRect.bottom = srcNSRect.origin.y;
srcRect.right = srcNSRect.origin.x + srcNSRect.size.width;
dstRect.left = 0;
dstRect.bottom = 0;
dstRect.top = srcNSRect.size.height;
dstRect.right = srcNSRect.size.width;
*/
srcRect.top = 20;
srcRect.left = 20;
srcRect.bottom = 40;
srcRect.right = 40;
dstRect.left = 0;
dstRect.top = 0;
dstRect.bottom = 20;
dstRect.right = 20;
CopyBits(srcBitMap, destBitMap, &srcRect, &dstRect, srcCopy, NULL);
BitMapToRegion(dragRegion = NewRgn(), destBitMap);
LocalToGlobal(&theLoc);
OffsetRgn(dragRegion, theLoc.h, theLoc.v);
if (!WaitMouseMoved(mouseInPoint)) { // mouse released prior to drag?
NSLog(@"%@: Nothing happened.", NSStringFromSelector(_cmd));
return; // return control as if nothing happened (which it didn't)
.
}
NSLog(@"%@: Processing drag.", NSStringFromSelector(_cmd));
NewDrag(&theDragRef);
SetDragItemBounds(theDragRef, 1, GetRegionBounds( dragRegion,
&dragBounds ));
sendProc = NewDragSendDataUPP(HandleDragSendData);
error = SetDragSendProc(theDragRef, sendProc, (void *) self);
if (error)
[NSException raise: NSInternalInconsistencyException
format: @"%s:%d [%@ %@] Failed to SetDragSendProc() -
%d.", __FILE__, __LINE__, NSStringFromClass([self class]),
NSStringFromSelector(_cmd), error];
error = AddDragItemFlavorTypePromiseHFS(theDragRef, 12345);
if (error)
[NSException raise: NSInternalInconsistencyException
format: @"%s:%d [%@ %@] Failed to
AddDragItemFlavorTypePromiseHFS() - %d.", __FILE__, __LINE__,
NSStringFromClass([self class]), NSStringFromSelector(_cmd), error];
tempRegion = NewRgn();
CopyRgn(dragRegion, tempRegion);
InsetRgn(tempRegion, 1, 1);
DiffRgn(dragRegion, tempRegion, dragRegion);
DisposeRgn(tempRegion);
if (![e eventRef]) {
NSLog(@"%@: Event ref is NULL on NSEvent.",
NSStringFromSelector(_cmd));
return;
}
if (!ConvertEventRefToEventRecord([e eventRef], &eventRecord))
NSLog(@"%@: Failed to convert", NSStringFromSelector(_cmd));
error = TrackDrag(theDragRef, &eventRecord, dragRegion);
DisposeDragSendDataUPP(sendProc);
NSLog(@"%@: %d", NSStringFromSelector(_cmd), error);
}
On Monday, May 13, 2002, at 10:04 PM, email@hidden
wrote:
Yes. I need to get the drop location and later create the file. This is
possible in Carbon using the promiseHFS flavor. I need to know when this
will be available in Cocoa.
Jorge Monteiro
JomoSoft LLC
http://www.jomosoft.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.