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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to