Re: Getting hitTest of Subview
Re: Getting hitTest of Subview
- Subject: Re: Getting hitTest of Subview
- From: Craig Bakalian <email@hidden>
- Date: Sat, 2 Nov 2002 17:42:03 -0500
On Saturday, November 2, 2002, at 07:42 AM, j o a r wrote:
>
How do you mean "get a hitTest"? As soon as it is inserted in the
>
superview it should get mouse click events automatically. If your
>
CBNote class implements "mouseDown:" it should get called when you
>
click it - is this not working?
>
>
j o a r
>
Well, hold on here,
I was doing the hitTest in the wrong subclass. The hitTest needed to
be in the superview so the mouseDown would not create an instance on
top of another instance. So this is what I did-
-(void)mouseDown: (NSEvent *) event
{
NSPoint loc = [event locationInWindow];
NSPoint vLoc = [self convertPoint: loc fromView: nil];
NSView *Note;
Note = [self hitTest: vLoc];
if(Note == self){
NSRect myRect = NSMakeRect(vLoc.x, vLoc.y, 100.0, 24.0);
CBNote *myNote = [[CBNote alloc] initWithFrame: myRect];
[self addSubview: myNote];
[myNote release];
}
}
No big thrill here, I just couldn't figure out what hitTest was
returning. But, I think, on the CBNote.m I had to do the below code to
make certain it's mouseDown would change it's string property.
-(void)mouseDown: (NSEvent *) event
{
[self setString: @"Good Bye"];
[self setNeedsDisplay: YES];
}
-(BOOL)acceptsFirstResponder
{
return YES;
}
I think I need to set the acceptsFirstResponder to get the mouseDown
before the superview does, because this is a subview?
Craig Bakalian
_______________________________________________
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.