Re: -draggingEntered: never gets called [SOLVED]
It turns out that this was caused by manipulating the GUI outside the main thread. Once I realized that and refactored accordingly, the issue went away. No wonder I was having trouble duplicating the symptoms! Thanks to everybody who helped me figure this out. -Michael On May 5, 2008, at 4:02 PM, Michael Gardner wrote: I'm trying to implement drag & drop in an NSView subclass. I made sure that the source returns NSDragOperationMove in - draggingSourceOperationMaskForLocal:, and that the destination calls -registerForDraggedTypes: with the same (custom) type that the source uses for the drag operation. The drag operation starts properly, but the destination's - draggingEntered: method never gets called, no matter what I do. What could cause this? Does it matter if the source and destination are the same object? -Michael ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
If so, it should be documented. As soon as I can get together a working test case, I'll submit a bug report. It would be nice to get some confirmation from an Apple engineer, though, since I'm having trouble duplicating the issue. -Michael On May 6, 2008, at 6:30 PM, Graham Cox wrote: I'm not sure if it's documented as such, but I *think* this is expected behaviour. The reality is that the dragging is really implemented by the underlying window (ultimately using Carbon) so if the view has no reference to its window when the drag types are registered, they probably just "get lost". A nib-instantiated window won't have this problem as it's most likely built top down. Generally it's probably wise to build structures completely (in this case window+views) before trying to set up high-level behaviours on them which probably do assume that things are fully constructed. G. On 7 May 2008, at 1:34 am, Michael Gardner wrote: Upon further investigation, I've found that if I call - registerForDraggedTypes: before adding the view to its parent window with -setContentView:, I never get the -draggingEntered: messages. If I do so afterwards, everything works properly. Is this expected behavior? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
Which is irrelevant, since I'm constructing my views programatically. Anyway, I've long since verified that my methods are all getting called as expected (except for -draggingEntered:, of course). -Michael On May 6, 2008, at 6:24 PM, Kyle Sluder wrote: On Tue, May 6, 2008 at 10:44 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: My actual init method has a different signature, and calls - initWithFrame: on its superclass. I was trying to abstract away extra details, but I shouldn't have made it look like an actual method signature. Sorry about that. IB will never call this method. It will always call -initWithFrame:, as it has no way of knowing that you have designated a different initializer. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
I'm not sure if it's documented as such, but I *think* this is expected behaviour. The reality is that the dragging is really implemented by the underlying window (ultimately using Carbon) so if the view has no reference to its window when the drag types are registered, they probably just "get lost". A nib-instantiated window won't have this problem as it's most likely built top down. Generally it's probably wise to build structures completely (in this case window+views) before trying to set up high-level behaviours on them which probably do assume that things are fully constructed. G. On 7 May 2008, at 1:34 am, Michael Gardner wrote: Upon further investigation, I've found that if I call - registerForDraggedTypes: before adding the view to its parent window with -setContentView:, I never get the -draggingEntered: messages. If I do so afterwards, everything works properly. Is this expected behavior? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
On Tue, May 6, 2008 at 10:44 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: > My actual init method has a different signature, and calls -initWithFrame: > on its superclass. I was trying to abstract away extra details, but I > shouldn't have made it look like an actual method signature. Sorry about > that. IB will never call this method. It will always call -initWithFrame:, as it has no way of knowing that you have designated a different initializer. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
On May 6, 2008, at 10:47 AM, I. Savant wrote: On Tue, May 6, 2008 at 11:34 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: Upon further investigation, I've found that if I call -registerForDraggedTypes: before adding the view to its parent window with -setContentView:, I never get the -draggingEntered: messages. If I do so afterwards, everything works properly. Is this expected behavior? Interesting ... have you placed the call in the view's -viewDidMoveToSuperview to get this to work? The first thing I tried was putting the call in the source's - mouseDown: method, right before the drag operation. Then on a hunch, I put the call outside the class, with the code that creates the view and adds it to the window: NSWindow * window = [[[NSWindow alloc] initWithContentRect: NSMakeRect(100, 100, 500, 500) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing: NSBackingStoreBuffered defer: NO] autorelease]; [windows addObject: window]; [window setTitle: @"MyWindow"]; MyView * view = [[[MyView alloc] initWithFoo: foo bar: bar frame: NSMakeRect(0, 0, 500, 500)] autorelease]; [view registerMyDraggedTypes]; [window setContentView: view]; [window makeKeyAndOrderFront: self]; [view registerMyDraggedTypes] just does the actual - registerForDraggedTypes: call with the right argument. Moving that statement one line down, after [window setContentView], fixes the issue. As for posting the code, I'm trying to put together a minimal test case, but so far I haven't been able to duplicate the problem. There must be some relevant difference between the test case and my actual code, but I haven't been able to figure out what that is yet. One thing that occurs to me is to check where you're defining your custom type. Does it exist before you're registering it or vice-versa? :-) It's just a #define statement (#define MyPasteboardType @"application/ x-foo"), so it should get taken care of during preprocessing... as long as the compiler can see the definition from wherever I'm using it, that should be enough, right? -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
On Tue, May 6, 2008 at 11:34 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: > Upon further investigation, I've found that if I call > -registerForDraggedTypes: before adding the view to its parent window with > -setContentView:, I never get the -draggingEntered: messages. If I do so > afterwards, everything works properly. Is this expected behavior? Interesting ... have you placed the call in the view's -viewDidMoveToSuperview to get this to work? > As for posting the code, I'm trying to put together a minimal test case, > but so far I haven't been able to duplicate the problem. There must be some > relevant difference between the test case and my actual code, but I haven't > been able to figure out what that is yet. One thing that occurs to me is to check where you're defining your custom type. Does it exist before you're registering it or vice-versa? :-) -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
Upon further investigation, I've found that if I call - registerForDraggedTypes: before adding the view to its parent window with -setContentView:, I never get the -draggingEntered: messages. If I do so afterwards, everything works properly. Is this expected behavior? As for posting the code, I'm trying to put together a minimal test case, but so far I haven't been able to duplicate the problem. There must be some relevant difference between the test case and my actual code, but I haven't been able to figure out what that is yet. -Michael On May 6, 2008, at 10:14 AM, I. Savant wrote: On Tue, May 6, 2008 at 10:44 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: My actual init method has a different signature, and calls - initWithFrame: on its superclass. I was trying to abstract away extra details, but I shouldn't have made it look like an actual method signature. Sorry about that. At this point, I think it's time to post your relevant code. Again, I have never run across the problem you've described -- it should work as far as I know. I'll assume you've verified that your own init method (and the associated call to is -registerForDraggedTypes:) is actually called as expected (ie, you've stepped through it with the debugger and it is in fact called). -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
On Tue, May 6, 2008 at 10:44 AM, Michael Gardner <[EMAIL PROTECTED]> wrote: > My actual init method has a different signature, and calls -initWithFrame: > on its superclass. I was trying to abstract away extra details, but I > shouldn't have made it look like an actual method signature. Sorry about > that. At this point, I think it's time to post your relevant code. Again, I have never run across the problem you've described -- it should work as far as I know. I'll assume you've verified that your own init method (and the associated call to is -registerForDraggedTypes:) is actually called as expected (ie, you've stepped through it with the debugger and it is in fact called). -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
My actual init method has a different signature, and calls - initWithFrame: on its superclass. I was trying to abstract away extra details, but I shouldn't have made it look like an actual method signature. Sorry about that. -Michael On May 6, 2008, at 9:34 AM, I. Savant wrote: With help from Stéphane Sudre, I found that calling -registerForDraggedTypes: somewhere outside the destination's - init: method solves the issue. Can anyone shed light on why this would be? I've never personally experienced the problem you're describing, but if you're literally calling this from an init method with this signature: - (id)init ... then "You're Doing It Wrong". Views and their subclasses use -initWithFrame: as their designated initializer. If your call to -registerForDraggedTypes: is in an -init method, it won't get called unless you're creating your view with that method ... which you shouldn't do because it's a view and "strange things will happen". -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
I haven't been following this thread and I'm not sure this would make a difference, but do you really mean -init:, or -initWithFrame:? --Andy On May 6, 2008, at 10:27 AM, Michael Gardner wrote: With help from Stéphane Sudre, I found that calling - registerForDraggedTypes: somewhere outside the destination's -init: method solves the issue. Can anyone shed light on why this would be? My views are created programatically rather than loaded from a .nib, so there shouldn't be any interference from that side of things. As far as I can tell, this looks to be a bug in Cocoa's DnD code, or at least a caveat that should be mentioned in the documentation... -Michael On May 5, 2008, at 4:02 PM, Michael Gardner wrote: I'm trying to implement drag & drop in an NSView subclass. I made sure that the source returns NSDragOperationMove in - draggingSourceOperationMaskForLocal:, and that the destination calls -registerForDraggedTypes: with the same (custom) type that the source uses for the drag operation. The drag operation starts properly, but the destination's - draggingEntered: method never gets called, no matter what I do. What could cause this? Does it matter if the source and destination are the same object? -Michael ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
> With help from Stéphane Sudre, I found that calling > -registerForDraggedTypes: somewhere outside the destination's -init: method > solves the issue. Can anyone shed light on why this would be? I've never personally experienced the problem you're describing, but if you're literally calling this from an init method with this signature: - (id)init ... then "You're Doing It Wrong". Views and their subclasses use -initWithFrame: as their designated initializer. If your call to -registerForDraggedTypes: is in an -init method, it won't get called unless you're creating your view with that method ... which you shouldn't do because it's a view and "strange things will happen". -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: -draggingEntered: never gets called [solved?]
With help from Stéphane Sudre, I found that calling - registerForDraggedTypes: somewhere outside the destination's -init: method solves the issue. Can anyone shed light on why this would be? My views are created programatically rather than loaded from a .nib, so there shouldn't be any interference from that side of things. As far as I can tell, this looks to be a bug in Cocoa's DnD code, or at least a caveat that should be mentioned in the documentation... -Michael On May 5, 2008, at 4:02 PM, Michael Gardner wrote: I'm trying to implement drag & drop in an NSView subclass. I made sure that the source returns NSDragOperationMove in - draggingSourceOperationMaskForLocal:, and that the destination calls -registerForDraggedTypes: with the same (custom) type that the source uses for the drag operation. The drag operation starts properly, but the destination's - draggingEntered: method never gets called, no matter what I do. What could cause this? Does it matter if the source and destination are the same object? -Michael ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]