Drag button within bounds of superview.
Drag button within bounds of superview.
- Subject: Drag button within bounds of superview.
- From: "Eloy Duran" <email@hidden>
- Date: Thu, 5 Jul 2007 18:21:19 +0200
Hello,
First off all a heads up: I'm new to custom view and drag & drop
programming, so sorry for any duh kind of questions :)
Also I'm doing this in rubycocoa so there are bound to be some errors
in my translation back to objective-c, but this code works and is only
meant as a context reference.
I have a custom view, which is a bar, with multiple buttons aligned
horizontally and I would like a user to be able to reorder them.
I was able to start a drag operation of a button by implementing this
in the button class:
- (void)mouseDown:(NSEvent *)theEvent
{
// other code...
draggingPasteBoard = [NSPasteboard pasteboardWithName:NSDragPboard];
[self lockFocus];
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]];
[self unlockFocus];
image = [[NSImage alloc] initWithSize:[self bounds].size];
[image addRepresentation:bitmap];
[self dragImage:image,
at:NSMakePoint(NSMinX([self frame]), NSMaxY([self frame])),
offset:NSZeroSize,
event:theEvent,
pasteboard:draggingPasteBoard,
source: self,
slideBack:YES];
}
But here's the catch, I want the image to only move horizontally
within the bounds of the superview of the button.
Just like the bookmark buttons in the bookmark bar of Safari do.
Does anybody know of some code or opensource app that implements this
kind of behaviour?
Or could somebody explain me which class I need to subclass to add
this drawing behaviour to? Is it NSImage, or is there some sort of
drag & drop controller object?
Thanks in advance!
Cheers,
Eloy
_______________________________________________
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