Capturing window events in NSDocument

I have a Cocoa application based on a document with TextView, and I would like to capture clicks on it, so I'm trying to intercept Window events such as mouseDown, mouseUp, etc., then link them to my TextView.

I tried two things:

1.) I made TextView the initial first responder for the window of my document and redefined the mouseDown event in my document class, but didn't hit.

2.) I subclassed NSWindow and redefined mouseDown and set this subclass to my Window class in my xib document. This event also did not hit.

I noticed that the Window delegate is already set up for my file owner, which is my subclass of NSDocument. Why in my NSDocument events do not fire if my subclass of documents is a delegate for my window?

+3
source share
1 answer

It's unclear why you expect NSDocument to handle -mouseDown: events for presentation in a window. NSDocument is not responding to -mouseDown :. NSTextView (as the name implies) is a subclass of NSView, which is a subclass of NSResponder that responds to -mouseDown :.

You have to give Cocoa Event Handbook a good read.

, . Cocoa , , . (, " ?" ) - (, , ) .

+2

Source: https://habr.com/ru/post/1772585/


All Articles