Events and the NSApplication Object
After an event is translated into an NSResponder method, your program’s NSApplication object sends the corresponding message to the appropriate NSWindow (or other) object within your application. The particular object in your application that receives the message is determined by the type of message, as shown in Table 8-2.
Table 8-2. Important NSResponder methods
|
NSResponder method |
Sent to |
|---|---|
|
mouseDown:,rightMouseDown: |
The window where the mouse-down event occurred |
|
mouseUp:,rightMouseUp: |
The window where the original mouse-down event occurred |
|
mouseDragged:,rightMouseDragged: |
The window where the mouse-dragged event occurred |
|
mouseEntered:, mouseExited: |
The object that was specified when the tracking rectangle was created (see Chapter 18) |
|
keyDown: |
The key window |
|
keyUp: |
The same window that received the key-down event |
|
performKeyEquivalent: |
The key window |
As we saw earlier, each one of these NSResponder methods has an NSEvent object as its only argument. This NSEvent object contains essentially the same information that the Mac OS X Window Server passes to the NSApplication object, but it’s in a form that Cocoa programmers can handle.
Responders and the NSResponder Chain
As we mentioned earlier, the NSView, NSWindow, and NSApplication classes are all subclasses of the NSResponder class. NSResponder is the main class for handling events. It’s called an abstract superclass because its functionality is used via instances ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access