• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Drag an drop in a custom NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drag an drop in a custom NSView


  • Subject: Re: Drag an drop in a custom NSView
  • From: Brian Stern <email@hidden>
  • Date: Tue, 9 Oct 2007 16:21:33 -0400


On Oct 9, 2007, at 3:05 PM, Development wrote:

Ok,
I have constructed a subclass of NSView so that I can set the delegate.
Anyway. The NSView Subclass contains a bunch of subviews which are NSButtons. I am having two problems though with drag and drop. I registered for drag types, both file names and a custom internal type like I normally do with outline views. However i get no focus ring nor does it seem I get any reaction at all when I drag a file to the view. I've tried registering the enclosing scroll view for drag types, but still nothing. So basically its obvious I don't know how to tell the view to detect the drag, or if I have, I don't know how to gain the data from the drag.



Your NSView subclass has to draw the focus ring itself. It also has to override these methods:


- (BOOL)acceptsFirstResponder
{
	return YES;
}
- (BOOL)becomeFirstResponder
{
	[self setNeedsDisplay:YES];
	return YES;
}
- (BOOL)resignFirstResponder
{
	[self setNeedsDisplay:YES];
	return YES;
}

- (void)drawRect:(NSRect)rect
{
if (mDragInside || self == [[self window] firstResponder])
{
// showsFirstResponder is set for us by the NSControl that is drawing us.
NSRect focusRingFrame = [self frame];
focusRingFrame.origin = NSZeroPoint;
focusRingFrame.size.height -= 2.0;
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect: NSInsetRect(focusRingFrame, 4, 4)] fill];
[NSGraphicsContext restoreGraphicsState];
}
}


You need to implement draggingEntered and draggingExited and set mDragInside and then call [self display] along with perhaps calling your delegate.




-- Brian Stern email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Drag an drop in a custom NSView (From: Development <email@hidden>)

  • Prev by Date: Re: Where/when to #import
  • Next by Date: Re: Drag an drop in a custom NSView
  • Previous by thread: Re: Drag an drop in a custom NSView
  • Next by thread: Re: Drag an drop in a custom NSView
  • Index(es):
    • Date
    • Thread