Skip navigation.
 
mlRe: Dragging to table view without indicator
FROM : Shaun Wexler
DATE : Mon Jan 27 03:28:46 2003

On Sunday, January 26, 2003, at 02:37  PM, Andrew Merenbach wrote:

> I would like to accept various drops on my table view, but would
> rather that the entire table view become outlined, rather than an
> indicator bar be drawn, to signal that a drop can occur, as the
> dropped data would not be inserted at the particular location
> indicated by the bar.  What will I need to do to make this happen?
>
> Take care,
>     Andrew


Easy.  You'll need to implement these three methods in your NSTableView
delegate/datasource:

- (BOOL) tableView:(NSTableView *)tableview writeRows:(NSArray *)rows
toPasteboard:(NSPasteboard *)pboard;
- (unsigned int) tableView:(NSTableView *)tableview validateDrop:(id
<NSDraggingInfo>)info proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)operation;
- (BOOL) tableView:(NSTableView *)tableview acceptDrop:(id
<NSDraggingInfo>)info row:(int)row
dropOperation:(NSTableViewDropOperation)operation;

Then, in your NSTableView subclass (you must subclass), add some code
to the methods:

BOOL _shouldDrawFocusRing = NO;

- (NSDragOperation) draggingEntered:(id <NSDraggingInfo>)sender
{
   NSDragOperation operation = [super draggingEntered:sender];
   // code here to decide how to handle the drag, and modify operation if
needed
   _shouldDrawFocusRing = YES;  // NO, if drag will not be accepted
   [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
   return operation;
}

- (void) draggingExited:(id <NSDraggingInfo>)sender
{
   _shouldDrawFocusRing = NO;
   [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
   [super draggingExited:sender];
}

- (void) concludeDragOperation:(id <NSDraggingInfo>)sender
{
   _shouldDrawFocusRing = NO;
   [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
   [super concludeDragOperation:sender];
}

- (void) drawRect:(NSRect)rect
{
   [super drawRect: rect];
   if (_shouldDrawFocusRing) {
        NSSetFocusRingStyle(NSFocusRingOnly);
        NSRectFill([self bounds]);
    }
}

Hope that makes it work for you.
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlDragging to table view without indicator Andrew Merenbach Jan 26, 23:37
mlRe: Dragging to table view without indicator Scott Anguish Jan 27, 00:32
mlRe: Dragging to table view without indicator Shaun Wexler Jan 27, 03:28
mlRe: Dragging to table view without indicator Shaun Wexler Jan 27, 03:36
mlRe: Dragging to table view without indicator Stéphane Sudre Jan 27, 13:10