Re: yearly NSDraggingInfo -draggedImage question (BEWARE!)
Re: yearly NSDraggingInfo -draggedImage question (BEWARE!)
- Subject: Re: yearly NSDraggingInfo -draggedImage question (BEWARE!)
- From: "Sherm Pendley" <email@hidden>
- Date: Fri, 21 Mar 2008 13:47:07 -0400
On Thu, Mar 20, 2008 at 7:09 PM, Nathan Vander Wilt <
email@hidden> wrote:
> On Mar 20, 2008, at 3:31 PM, Dave Hersey wrote:
> > Do you get anything different if you print the object as a pointer
> > (%p)? Printing it as an int value is... weird.
> >
> > Try:
> >
> > printf("Dragged Image: %p\n", (void *)[sender draggedImage]);
>
> That's a useful format I'd either forgotten or never known, thanks! I
> was just casting to an int to get rid of the warning for the hex,
> though. (In C casts are pretty weak.) Now from all three methods I
> always get:
> Dragged Image: 0x0
> ...which is prettier, but still doesn't explain why the return value
> is always nil. Or why Sherm's car wouldn't start.
>
> If this is a bug, it seems to have been around since before 2004. (See
> list of unanswered links in OP.) If it's a documentation omission,
> nobody seems to know what the docs *should* say, also since 2004. If
> it's user error, I'll still blame the docs, but at least I can make my
> bug report better!
>
> Maybe this would be a better way of asking:
>
> What is the NSDraggingInfo protocol's -draggedImage method supposed to
> return, and under what circumstances?
Well, the glib answer is that it returns whatever the dragging source passed
as the first argument to
-dragImage:at:offset:event:pasteboard:source:slideBack:.
Seriously though, I can't explain what you're seeing, but I can duplicate
it. In my tests, I couldn't get anything other than NULL from -draggedImage
for dragged files from either Finder or Xcode. I even tried pasting a custom
icon onto a file, which made no difference. What I suspect is that both apps
are passing NULL to the above method, and so that's what gets passed along
to your app.
As a workaround, you could get the file path from the pasteboard, then call
NSWorkspace's -iconForFile: to get an NSImage of the file's icon. I suspect
you're probably already doing that though. I'd file a bug report - that this
has lasted for so long implies that it's normal behavior, and in that case
the documentation really should mention the possibility of -draggedImage
returning NULL.
Oh, and I apologize for the snarky tone of my first response. Thanks for
being a good sport about it. :-)
sherm--
_______________________________________________
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