PDA

View Full Version : Storing color in NSColorPboardType




MacRumoron
Nov 1, 2006, 08:13 PM
SOLUTION FOUND, read edit 3

I have an nsview, and I want to be able to drag this nsview into a colorwell and make the colorwell change its color. How can I do this?

Or another question would be: how is data stored in NSColorWell for the NSColorPboardType? Because it isn't just an archived NSColor.

Hope this makes any sense :o

EDIT: This is a code snippet from mouseDragged in my NSView.

pb = [NSPasteboard pasteboardWithName:NSDragPboard];
[pb declareTypes:[NSArray arrayWithObjects:NSColorPboardType, NSStringPboardType, nil] owner:self];

[pb setString:@"test" forType:NSStringPboardType];
[pb setData:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forType:NSColorPboardType];

NSLog(@"%@", [NSColor colorFromPasteboard:pb]);


Then when I drag I get this message

-[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x4, 0xb, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d)

What am I doing wrong?

Thanks.

EDIT2: ok i found out it is supposed to be NSKeyedArchiver not NSArchiver, but NSColorWell's still don't do anything when I drag to it

EDIT3: the problem was that I had this in my NSView
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return NSDragOperationCopy;
}

once i commented that out everything worked perfectly :)



HiRez
Nov 1, 2006, 11:09 PM
I have an nsview, and I want to be able to drag this nsview into a colorwell and make the colorwell change its color. How can I do this?You want to drag an NSView into a color well? That's an odd way of doing things, I think the way they're meant to be used is to select an object you want to affect first, then the well changes the color of that object (or objects). Not saying there's not a way to do that, just that I don't think they're intended to be used that way.

MacRumoron
Nov 1, 2006, 11:55 PM
Sorry, I meant that I have this NSView, and when I drag it, a colored square box appears (just like when you drag from NSColorWell). I want to be able to make it so when you drop that square box in an NSColorWell, it will change the colorwell into a certain color.