Custom NSViews not highlighting
Custom NSViews not highlighting
- Subject: Custom NSViews not highlighting
- From: Development <email@hidden>
- Date: Sat, 13 Oct 2007 16:33:13 -0700
I have a custom NSView subclass in side of a scroll view. This
subclass contains a bunch of NSViews which act as buttons with in. I
want to be able to select an area of these buttons and have them all
highlight (to show they are selected) I have no trouble getting the
selection to draw, and according to my NSLog tracking the view's
within the selection rectangle are being recognized correctly. The
problem is I cannot get any form of a rectangle to appear around the
edges of the button. Now originally the subviews acting as buttons
had the following code:
-(void)highlight
{
[self lockFocus];
[[NSColor yellowColor]set];
NSFrameRect([self bounds]);
[self unlockFocus];
}
this code would not highlight the button during mousedrag, nor when
called after the mouse up. However if I called it from within the
subview it would highlight correctly so this leads me to assume the
code should have worked..
Now still having no success, I added the following code to the master
view. (the subclass that contains the buttons.)
-(NSArray*)subviewsInSelection
{
NSEnumerator * iter = [[self subviews]objectEnumerator];
NSMutableArray * subviews = [[NSMutableArray alloc]init];
id item = NULL;
while(item = [iter nextObject]){
NSRect intersection = NSIntersectionRect([selectionMarker
selectedRect],[item bounds]);
NSRect selection = [selectionMarker selectedRect];
NSLog(@"looping");
BOOL inside = NSContainsRect([selectionMarker selectedRect],[item
frame]);
if(inside || !NSIsEmptyRect(intersection)){
[item lockFocus];
[[NSColor yellowColor]set];
NSFrameRect([item bounds]);
[item unlockFocus];
[subviews addObject:item];
}
else{
[item lockFocus];
[[NSColor yellowColor]set];
NSFrameRect([item bounds]);
[item unlockFocus];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.0001]];
}
[self setNeedsDisplay:YES];
return subviews;
}
I can use NSLog to track that infact the 'buttons' are being
correctly detected, and asked to highlight however no highlight ever
appears. (I know a yellow box is ugly. I'll use the proper highlight
in the end but before I worry about it I'd like to at least get it
working.)
Now the button items all have the first responder methods and
drawRect overriden, I don't know if this is causing the problem. If
so, do I need to add a contingency for when the button has been
selected?
April.
_______________________________________________
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