Re: How to get NSColorPanel's target?
Re: How to get NSColorPanel's target?
- Subject: Re: How to get NSColorPanel's target?
- From: Keith Renz <email@hidden>
- Date: Thu, 21 Aug 2003 19:02:12 -0400
- Resent-date: Thu, 21 Aug 2003 19:02:49 -0400
- Resent-from: Keith Renz <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: Cocoa-Dev List <email@hidden>
Neil,
Unfortunately, that won't work. I have multiple (up to 32) very small
identical views which are all sibling views of a parent view. Their
individual colors can be changed. To change their colors, you
double-click on them, which opens the color panel. Also, these views
can be removed and added by dragging them, etc., which doesn't
guarantee any particular order. So, if I change the color of one of
them and then subsequently delete it, with the color panel remaining
open, the color panel now has the wrong (deallocated) target. If I
change the color in the color panel, the app crashes. If the color
panel doesn't have a target, i.e. a nil target and a valid selector, I
won't know which view to color, and the layering isn't guaranteed in
any particular order for sibling views. Since the color panel knows its
target, I should be able to query it as to its target, but you can't
(at least not with any documented method). I could manually keep track
of the color panel's target, but that seems like such a waste since the
color panel already has a private _target instance variable.
Keith
-----
On Thursday, August 21, 2003, at 09:21 AM, Neil Earnshaw wrote:
The color panel can work without a target. If its target hasn't been
set then it checks to see if the first responder implements
changeColor:
I've got an app delegate method that opens it in response to a
MainMenu->Window->Show Color Panel menu item:
-(IBAction)showColorPanel:(id)sender
{
[[NSColorPanel sharedColorPanel] orderFront:self];
}
and a window controller that implements changeColor:
-(IBAction)changeColor:(id)sender
{
if ( 0 < [_selectedDKNodes count] ) {
int i;
for ( i = 0 ; i < [_selectedDKNodes count] ; i++ ) {
[[_selectedDKNodes objectAtIndex:i] setColor:[sender color]];
}
}
if ( ! ([_selectedDKNodes count] || _selectedDKPath) ) {
[_dkModel setColor:[sender color]];
}
}
As long as its window is the active one, the window controller will
get the message. There's no need to set target or release anything.
Its all automatic.
Hope this helps,
-Neil
On Tuesday, August 19, 2003, at 04:37 AM, Keith Renz wrote:
I'm setting NSColorPanel's shared instance's target to a custom view
(no color well is being used). When I deallocate the view, I would
like to decouple it from the color panel if it is the color panel's
target by resetting the color panel's target and action to nil. I
would like to ask the color panel what its target is, but there's no
method to do so. I can get at the color panel's private _target
instance variable with key value coding ([colorPanel
valueForKey:@"target"]), but this isn't really kosher. Is there a
better way to do this without manually keeping track of the color
panel's target?
Thanks,
Keith
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
Neil Earnshaw
Consultant Software Engineer
Object Software Engineers Ltd
email@hidden
Tel : 01747 854 852
Mbl : 07870 209 102
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.