On 19/02/2013, at 11:09 AM, Chuck Soper <chu...@veladg.com> wrote:

> Does anyone know the steps to allow custom dragging of a table column to
> another table? Is this possible? If I was dealing with an NSView subclass,
> I think this would be straightforward. I want to show the entire column
> (header + row) when dragging. I believe that the dragging implementation
> could go in my NSTableHeaderCell subclass, but I'm not sure how to get
> started.


It's definitely possible, but you'll have to do a bit of subclassing. I suspect 
you're going to need to subclass the overall NSTableView so that you can 
receive a private drag type and do the necessary graphics work as part of 
NSDraggingDestination.

There are two parts to a drag - the drag source and the drag destination. The 
source can be your custom table header cell, but the destination is probably 
going to have to be a subclass of the table view itself. The two parts can be 
programmed fairly independently, once you've settled on how they are going to 
communicate in terms of the column data you pass from to the other.

Having subclassed your table header cell, kicking off the drag shouldn't be too 
hard - just handle the mouseDown or mouseDragged and capture an image of the 
column as the drag image. NSView's method for capturing part of a view to a 
bitmap rep is invaluable here. Declare a private drag type and use whatever 
data makes sense to pass the column content through the drag pasteboard 
mechanism - you might not need to actually transfer any data, you could just 
store enough info in shared variables (e.g. just make a note of the source 
column somewhere) that your custom table class can access - as it's all private 
there's no need to consider dragging to other apps or supporting standard data 
formats.

The hardest part as I see it is in receiving the drag. Your custom table class 
will register for the private drag type, and implement NSDraggingDestination 
methods to do whatever is needed to provide feedback and validation of the 
drag. You will need for example to highlight the place where the column can be 
dropped, and maybe animate moving other columns apart to "make room". You'll 
want to pass anything else up to super's implementation to continue supporting 
all the standard dragging that the table can handle.

On a drop, you just need to remove the column from the source, use the private 
data to recreate it at the destination and insert it into the table view.

--Graham


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to