How to make NSColorPanel/NSColorWell do what I want...
How to make NSColorPanel/NSColorWell do what I want...
- Subject: How to make NSColorPanel/NSColorWell do what I want...
- From: Graham Cox <email@hidden>
- Date: Sat, 10 Dec 2011 13:27:08 +1100
In my app I use a couple of custom variants of NSColorWell.
In some situations, it is necessary to preserve the user's sanity by deactivating ALL colour wells, so that the color panel, if left open, doesn't remain connected to a hidden colorwell and hence change some colour property when the user can't tell what's going on.
NSColorWell instances are linked together a bit like radio buttons, usually you can only have one active at a time. This behaviour is not exposed directly by Cocoa, it happens in some private code. So in order to deactivate all colorwells, I added the following a category that adds a class method +[NSColorWell deactivateAll];
This works by creating a temporary colorwell instance, activating it exclusively, then discarding it. That achieves the desired aim of deactivating all the wells in the UI. But it has an unwanted side-effect: it shows the color panel if it's not already visible. I don't want that, and there's no API for decoupling a colorwell from the panel. So I'm trying to manipulate the frame of the color panel to move it offscreen, so at least when it's shown the user doesn't see it, and then put its frame back afterwards. Unfortunately it doesn't work, because something somewhere is constraining the frame of the color panel to the monitor edges. This means the panel flashes briefly on screen at one of the screen corners.
Here's my code:
@implementation NSColorWell (GCExtensions)
+ (void) deactivateAll
{
BOOL cpVis = [[NSColorPanel sharedColorPanel] isVisible];
NSRect cpFrame;
if( !cpVis )
{
cpFrame = [[NSColorPanel sharedColorPanel] frame];
[[NSColorPanel sharedColorPanel] setFrame:NSMakeRect(10000,10000,0,0) display:NO];
}
NSColorWell* cw = [[self alloc] initWithFrame:NSZeroRect];
[cw activate:YES];
[cw release];
if( !cpVis )
{
[[NSColorPanel sharedColorPanel] orderOut:nil];
[[NSColorPanel sharedColorPanel] setFrame:cpFrame display:NO];
}
}
@end
Can anyone suggest a solution to this problem? It's a real nuisance that these classes are designed in such a way that their high-level behaviour is so hard to customize.
--Graham
_______________________________________________
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