Re: Drag & Drop
Re: Drag & Drop
- Subject: Re: Drag & Drop
- From: Michael Becker <email@hidden>
- Date: Tue, 2 Mar 2004 16:31:57 +0100
I have an NSTabView that contains an NSScrollView [...] will the
TableView catch all drags and not pass them on to the scrollview?
Where is the table view? is it inside the scroll view? is it setup to
receive dragged items? if yes, then it will most likely swallow the
events -- but then in reality, isn't it the table view you want to
setup to receive the drops?
Sorry, typo. There's no TableView. It's just an NSTabView containing an
NSScrollView (which again contains an NSMatrix). I would like the user
to drop files on the ScrollView.
I registered correctly (i think) for dragging types and am honestly a
little lost here. Any suggestions?
If you are not 100% sure that you did it correct, then you should post
the code so that we may inspect it! Asking us to guess what you did
wrong without showing us what you did, is really just wasting our
time...
Sorry again. My code is attached below the mail text.
You may also search the net for the hundreds of examples of doing
drag'n'drop.
I actually did, and they're all pretty clear about what to do, but
still I can't get it to work. Here's the important code. To avoid the
problem of swallowed events, here I try to let NSTabView accept the
drops.
in my AppController's -awakeFromNib:
[ oTabView registerForDraggedTypes:[NSArray
arrayWithObjects:NSTIFFPboardType, nil]];
in my DTabView.m:
@implementation DTabView
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
== NSDragOperationGeneric)
{
return NSDragOperationGeneric;
}
else {
return NSDragOperationNone;
}
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {}
- (void)draggingEnded:(id <NSDraggingInfo>)sender {}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *paste = [ sender draggingPasteboard];
NSArray *types = [ NSArray arrayWithObjects:NSTIFFPboardType, nil];
NSString *desiredType = [ paste availableTypeFromArray:types];
NSData *carriedData = [ paste dataForType:desiredType];
if (nil == carriedData)
{
// no data
return NO;
}
else
{
// incoming data
if ([desiredType isEqualToString:NSTIFFPboardType])
{
NSLog(@"Drop worked!");
}
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
}
-
@end
_______________________________________________
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.