drag and drop sample is incorrect: it does not use the pasteboard contents
drag and drop sample is incorrect: it does not use the pasteboard contents
- Subject: drag and drop sample is incorrect: it does not use the pasteboard contents
- From: Baback Nemazie <email@hidden>
- Date: Thu, 6 Feb 2003 10:11:56 -0800
I looked at the drag and drop sample in cocoa application samples
(DragNDropOutlineView sample under Developer/Examples/AppKit). The
sample does not read the dragged items off the pasteboard, rather it
calls the outline view's data source method draggedNodes to get the
dragged nodes. Here is a code snippet from AppController.m (see the
lines highlighted in red starting with AppController* dragDataSource):
- (void)_performDropOperation:(id <NSDraggingInfo>)info
onNode:(TreeNode*)parentNode atIndex:(int)childIndex {
// Helper method to insert dropped data into the model.
NSPasteboard * pboard = [info draggingPasteboard];
NSMutableArray * itemsToSelect = nil;
// Do the appropriate thing depending on wether the data is
DragDropSimplePboardType or NSStringPboardType.
if ([pboard availableTypeFromArray:[NSArray
arrayWithObjects:DragDropSimplePboardType, nil]] != nil) {
AppController *dragDataSource = [[info draggingSource]
dataSource];
NSArray *_draggedNodes = [TreeNode
minimumNodeCoverFromNodesInArray: [dragDataSource draggedNodes]];
Also the right items are not placed on the pasteboard. Here is the code
snippet:
- (BOOL)outlineView:(NSOutlineView *)olv writeItems:(NSArray*)items
toPasteboard:(NSPasteboard*)pboard {
draggedNodes = items; // Don't retain since this is just holding
temporaral drag information, and it is only used during a drag! We
could put this in the pboard actually.
// Provide data for our custom type, and simple NSStrings.
[pboard declareTypes:[NSArray arrayWithObjects:
DragDropSimplePboardType, NSStringPboardType, nil] owner:self];
// the actual data doesn't matter since DragDropSimplePboardType
drags aren't recognized by anyone but us!.
[pboard set
Data:[NSData data] forType:DragDropSimplePboardType];
// Put string data on the pboard... notice you candrag into
TextEdit!
[pboard setString: [draggedNodes description] forType:
NSStringPboardType];
return YES;
}
where a string rather than the dragged nodes are posted to the
pasteboard.
So My question is what is the correct way to post dragged items to the
pasteboard in the drag source, and read them off the pasteboard in the
drop source.
Thanks
_______________________________________________
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.