Re: Subclassing NSColorWell?
Re: Subclassing NSColorWell?
- Subject: Re: Subclassing NSColorWell?
- From: glenn andreas <email@hidden>
- Date: Thu, 14 Jul 2005 16:59:36 -0500
On Jul 14, 2005, at 4:11 PM, Mike McNamara wrote:
Hello!
I'm attempting (without much luck unfortunately) to attach an
NSString to the drag data coming out of an NSColorWell. As an
NSColorWell otherwise does and provides most everything else I
require, I thought that I'd avoid reinventing the wheel and
subclass NSColorWell for my purposes. I've simply attempted to
override both the mouseDown and mouseDragged methods in my subclass
of NSColorWell:
//-----//
- (void) mouseDown:(NSEvent *)event {
BOOL worked;
[super mouseDown: event];
NSPasteboard *pb = [NSPasteboard pasteboardWithName:
NSDragPboard];
[pb declareTypes:[NSArray arrayWithObjects:NSStringPboardType,
nil] owner:self];
x = [pb setString: @"test String" forType: NSStringPboardType];
if (!worked) {
NSLog(@"couldn't setString on pb");
} else {
NSLog(@"%@", [pb stringForType: NSStringPboardType]);
}
}
//-----//
thinking that would suffice. Apparently that thinking is flawed!
=) I can see via NSLog that the string in fact arrives and is
placed on the dragging pasteboard. When I do a drag from the
NSColorWell however, there's no NSString being delivered to the
destination.
Are there some other method(s) that needs to be overridden in this
instance? Perhaps I'm missing some important point entirely? I
could create my own NSView or NSControl and implement the
appropriate dragging stuff, but it just seems silly as NSColorWell
does 95% of what I need.
Advice is much appreciated!
Most likely, NSColorWell, in it's mouse dragged routine, is probably
doing its own declareTypes, which removes yours, or perhaps using +
[NSColorPanel dragColor: color withEvent: theEvent fromView:
sourceView] (which would probably also do this), and so by the time
the super mouseDragged is done, the drag is also done (and so you
can't add anything to the drag pasteboard).
I'd first try to override
dragImage:at:offset:event:pasteboard:source:slideBack in your
NSColorWell subclass (and then append your types & data to the
pasteboard), but if it goes through
dragColor:colorWithEvent:fromView: instead, I'm not sure where to try
to intercept it.
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Widgetarium | the quickest path to widgets
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden