Re: Respond to Click in TextView
Re: Respond to Click in TextView
- Subject: Re: Respond to Click in TextView
- From: "Michael Ash" <email@hidden>
- Date: Sun, 27 Aug 2006 08:46:19 -0400
On 8/27/06, Michael Terry <email@hidden> wrote:
Hello,
I'd like to respond to mouseDown events in a TextView, but just how
is eluding me. In case some configuration error in my application was
the culprit, I set up a fresh one.
In Interface Builder, I noticed that MyDocument is listed as the
delegate for the NSWindow instance. That being the case, this is what
I expected to happen when clicking on the running program's TextView:
click event sent to TextView, forwarded to ScrollView, forwarded to
NSWindow, and finally forwarded to the window's delegate MyDocument
where it had been prepared to receive it with:
- (void)mouseDown:(NSEvent *)event
{
NSLog(@"mouseDown: %d", [event clickCount]);
}
... in MyDocument.m. However, clicking in the TextView (or window)
doesn't register anything in the log. What don't I understand?
There are two problems here.
1) The window's delegate only gets consulted for action messages, not
event messages. So if you have a button hooked up to First Responder,
it will get consulted. But it will never get a mouseDown:.
2) NSTextView surely implements mouseDown:, therefore the event does
not go farther up the responder chain. Responder chain messages only
get sent to one object, therefore they stop at the first object that
can handle them.
Now, solutions:
1) If what you care about is moving the insertion point around or
changing the selection, look at
NSTextViewDidChangeSelectionNotification. The insertion point is
counted as a zero-size selection, so this gets fired for moving the
insertion point too.
2) If you really need all mouse down events, even the ones that don't
move the insertion point, subclass NSView and override mouseDown:.
Don't forget to call super in the cases where you need the default
behavior.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden