drag and drop images to NSWindow doesn't work

  • Dear all,

    I m trying the drag n drop behavior of NSWindow using the following excerpt:

    - (void)awakeFromNib {

    NSArray *myAy = [NSImage imagePasteboardTypes];

    [window registerForDraggedTypes:myAy];

    //[window registerForDraggedTypes:[NSArray
    arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
    }

    - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
    NSLog(@"Hello");
    }

    - (void)draggingExited:(id < NSDraggingInfo >)sender {
    NSLog(@"dragging exit");
    }

    - (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender {
    //check to see if we can accept the data
        return [NSImage canInitWithPasteboard: [sender draggingPasteboard]];
    }

    - (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
    // add the image to the source image array
    // render layout
    NSLog(@"Performing drag operation");
    return YES;
    }

    However, if I use the image pasteboard types, the sample app doesn't
    respond to any image dragging into the window.

    If I use the commented code in "awakeFromNib" instead, it prints those
    debug message.

    What's wrong?

    Please kindly help.

    Best Regards,
    Bill
  • Different types i'd guess.With myAny youonly accept images.
    With the commented code URLs and paths.

    Often an app may not directly put a lot of data on the pasteboard
    (although there is a protocol to provide data lazily) but merely a
    reference to it.

    On 24.09.2007, at 19:43, Bill So wrote:

    > Dear all,
    >
    > I m trying the drag n drop behavior of NSWindow using the following
    > excerpt:
    >
    > - (void)awakeFromNib {
    >
    > NSArray *myAy = [NSImage imagePasteboardTypes];
    >
    > [window registerForDraggedTypes:myAy];
    >
    > //[window registerForDraggedTypes:[NSArray
    > arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
    > }
    >
    > - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
    > NSLog(@"Hello");
    > }
    >
    > - (void)draggingExited:(id < NSDraggingInfo >)sender {
    > NSLog(@"dragging exit");
    > }
    >
    > - (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender {
    > //check to see if we can accept the data
    > return [NSImage canInitWithPasteboard: [sender
    > draggingPasteboard]];
    > }
    >
    > - (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
    > // add the image to the source image array
    > // render layout
    > NSLog(@"Performing drag operation");
    > return YES;
    > }
    >
    > However, if I use the image pasteboard types, the sample app doesn't
    > respond to any image dragging into the window.
    >
    > If I use the commented code in "awakeFromNib" instead, it prints those
    > debug message.
    >
    > What's wrong?
    >
    > Please kindly help.
    >
    > Best Regards,
    > Bill
  • On 24 Sep 2007, at 12:43 PM, Bill So wrote:

    > - (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
    > NSLog(@"Hello");
    > }

    I'd clear this up before going further. You don't return anything from
    this method. I'm surprised you didn't get a compiler warning.

    -- F
  • --- Bill So <headnixlist...> wrote:

    > Dear all,
    >
    > I m trying the drag n drop behavior of NSWindow
    > using the following excerpt:
    >
    > - (void)awakeFromNib {
    >
    > NSArray *myAy = [NSImage imagePasteboardTypes];
    >
    > [window registerForDraggedTypes:myAy];
    >
    > //[window registerForDraggedTypes:[NSArray
    > arrayWithObjects:NSFilenamesPboardType,
    > NSURLPboardType, nil]];
    > }
    > [SNIP]
    > However, if I use the image pasteboard types, the
    > sample app doesn't
    > respond to any image dragging into the window.
    >
    > If I use the commented code in "awakeFromNib"
    > instead, it prints those
    > debug message.

    It sounds like you're dragging an image file, which is
    a file rather than an image, so you need that
    pasteboard type to recognize the drag.

    Cheers,
    Chuck


    ____________________________________________________________________________________
    Yahoo! oneSearch: Finally, mobile search
    that gives answers, not web links.
    http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
  • Yeah, I m dragging a file from Finder to my app.  (though the file is an image)

    I'll change my code to recognize that then.

    Thanks,
    Bill

    On 9/25/07, Charles Steinman <acharlieblue...> wrote:
    >
    > --- Bill So <headnixlist...> wrote:
    >
    >> Dear all,
    >>
    >> I m trying the drag n drop behavior of NSWindow
    >> using the following excerpt:
    >>
    >> - (void)awakeFromNib {
    >>
    >> NSArray *myAy = [NSImage imagePasteboardTypes];
    >>
    >> [window registerForDraggedTypes:myAy];
    >>
    >> //[window registerForDraggedTypes:[NSArray
    >> arrayWithObjects:NSFilenamesPboardType,
    >> NSURLPboardType, nil]];
    >> }
    >> [SNIP]
    >> However, if I use the image pasteboard types, the
    >> sample app doesn't
    >> respond to any image dragging into the window.
    >>
    >> If I use the commented code in "awakeFromNib"
    >> instead, it prints those
    >> debug message.
    >
    > It sounds like you're dragging an image file, which is
    > a file rather than an image, so you need that
    > pasteboard type to recognize the drag.
    >
    > Cheers,
    > Chuck
    >
    >
    >
    > ____________________________________________________________________________________
    > Yahoo! oneSearch: Finally, mobile search
    > that gives answers, not web links.
    > http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
    >
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today