Storing color in NSColorPboardType

Discussion in 'Mac Programming' started by MacRumoron, Nov 1, 2006.

  1. MacRumoron macrumors 6502

    Sep 6, 2005
    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 :eek:

    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?


    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 :)
  2. HiRez macrumors 603


    Jan 6, 2004
    Western US
    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.
  3. MacRumoron thread starter macrumors 6502

    Sep 6, 2005
    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.

Share This Page