NSWindowDelegate Protocol Reference
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.6 and later. |
| Companion guide | |
| Declared in | NSWindow.h |
Overview
The NSWindowDelegate protocol defines the methods that a delegate of NSWindow should implement. All methods in this protocol are optional.
By implementing these methods, the delegate may respond to window resizing, moving, exposing, minimizing, and a number of other window events.
Tasks
Managing Sheets
Sizing Windows
-
– windowWillResize:toSize: -
– windowDidResize: -
– windowWillStartLiveResize: -
– windowDidEndLiveResize:
Minimizing Windows
Zooming Window
Managing Full-Screen Presentation
-
– window:willUseFullScreenContentSize: -
– window:willUseFullScreenPresentationOptions: -
– windowWillEnterFullScreen: -
– windowDidEnterFullScreen: -
– windowWillExitFullScreen: -
– windowDidExitFullScreen:
Custom Full-Screen Presentation Animations
-
– customWindowsToEnterFullScreenForWindow: -
– window:startCustomAnimationToEnterFullScreenWithDuration: -
– windowDidFailToEnterFullScreen: -
– customWindowsToExitFullScreenForWindow: -
– window:startCustomAnimationToExitFullScreenWithDuration: -
– windowDidFailToExitFullScreen:
Moving Windows
-
– windowWillMove: -
– windowDidMove: -
– windowDidChangeScreen: -
– windowDidChangeScreenProfile: -
– windowDidChangeBackingProperties:
Closing Windows
Managing Key Status
Managing Main Status
Managing Field Editors
Updating Windows
Exposing Windows
Dragging Windows
Getting the Undo Manager
Managing Titles
Managing Restorable State
-
– window:willEncodeRestorableState:required method -
– window:didDecodeRestorableState:required method
Managing Presentation in Version Browsers
-
– window:willResizeForVersionBrowserWithMaxPreferredSize:maxAllowedSize:required method -
– windowWillEnterVersionBrowser:required method -
– windowDidEnterVersionBrowser:required method -
– windowWillExitVersionBrowser:required method -
– windowDidExitVersionBrowser:required method
Instance Methods
customWindowsToEnterFullScreenForWindow:
Invoked when the window is about to enter full-screen mode.
Parameters
- window
The window to enter to full-screen mode.
Return Value
An array of windows to use for the animation to full-screen mode for window; otherwise nil.
Discussion
This method lets a window delegate customize the animation when the window is about to enter full-screen mode by providing a custom window or windows containing layers or other effects. If you do not want to perform custom animation, you can omit the implementation of this method, or it can return nil.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hcustomWindowsToExitFullScreenForWindow:
Invoked when the window is about to exit full-screen mode.
Parameters
- window
The window to exit full-screen mode.
Return Value
An array of windows involved in the animation out of full-screen mode for window; otherwise nil.
Discussion
This method lets the window delegate customize the animation when the window is about to exit full-screen mode by providing a custom window or windows containing layers or other effects. If an you do not want to perform custom animation, you can omit the implementation of this method, or it can return nil.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hwindow:didDecodeRestorableState:
Tells the delegate the window is has extracted its restorable state from a given archiver. (required)
Parameters
- window
The window extracting its restorable state from an archive.
- state
The coder extracting the archive.
Discussion
This method is invoked during the window’s restoreStateWithCoder: method.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hwindow:shouldDragDocumentWithEvent:from:withPasteboard:
Asks the delegate whether a user can drag the document icon from the window’s title bar.
Parameters
- window
The window containing the document icon the user wants to drag.
- event
The left-mouse down event that triggered the dragging operation.
- dragImageLocation
The location at which the user started the dragging operation.
- pasteboard
The pasteboard containing the contents of the document, which the delegate can modify.
Return Value
YES to allow the drag to proceed; NO to prevent it. Before turning no the delegate can implement its own dragging behavior as described below.
Discussion
Implementing this method allows an application to customize the process of dragging the window’s document icon.implement its own dragging process, the delegate can perform the dragging operation and return NO.
The delegate can prohibit the drag by returning NO. Before returning NO, the delegate may implement its own dragging behavior using dragImage:at:offset:event:pasteboard:source:slideBack:.
Availability
- Available in OS X v10.5 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindow:shouldPopUpDocumentPathMenu:
Asks the delegate whether the window displays the title pop-up menu in response to a Command-click or Control-click on its title.
Parameters
- window
The window whose title the user Command-clicked or Control-clicked.
- menu
The menu the window will display, if allowed. By default, its items are the path components of the file represented by window.
Return Value
YES to allow the display of the title pop-up menu; NO to prevent it.
Availability
- Available in OS X v10.5 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindow:startCustomAnimationToEnterFullScreenWithDuration:
This method is called to start the window animation into full-screen mode, including transitioning to a new space.
Parameters
- window
The window to enter full-screen mode.
- duration
The duration of the presentation change.
Discussion
You can implement this method to perform custom animation with the given duration to be in sync with the system animation.
Special Considerations
This method is called only if customWindowsToEnterFullScreenForWindow: returns non-nil.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hwindow:startCustomAnimationToExitFullScreenWithDuration:
This method is called to start the window animation out of full-screen mode, including transitioning back to the desktop space.
Parameters
- window
The window to exit to full-screen mode.
- duration
The duration of the presentation change.
Discussion
You can implement this method to perform custom animation with the given duration to be in sync with the system animation.
Special Considerations
This method is called only if customWindowsToExitFullScreenForWindow: returns non-nil.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hwindow:willEncodeRestorableState:
Tells the delegate the window is about to add its restorable state to a given archiver. (required)
Parameters
- window
The window adding its restorable state to an archive.
- state
The coder creating the archive.
Discussion
This method is invoked during the window’s encodeRestorableStateWithCoder: method.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSWindow.hwindow:willPositionSheet:usingRect:
Tells the delegate that the window is about to show a sheet at the specified location, giving it the opportunity to return a custom location for the attachment of the sheet to the window.
Parameters
- window
The window containing the sheet to be animated.
- sheet
The sheet to be shown.
- rect
The default sheet location, just under the title bar of the window, aligned with the left and right edges of the window.
Return Value
The custom location specified.
Discussion
This method is also invoked whenever the user resizes window while sheet is attached.
This method is useful in many situations. If your window has a toolbar, for example, you can specify a location for the sheet that is just below it. If you want the sheet associated with a certain control or view, you could position the sheet so that it appears to originate from the object (through animation) or is positioned next to it.
Neither the rect parameter nor the returned NSRect value define the boundary of the sheet. They indicate where the top-left edge of the sheet is attached to the window. The origin is expressed in window coordinates; the default origin.y value is the height of the content view and the default origin.x value is 0. The size.width value indicates the width and behavior of the initial animation; if size.width is narrower than the sheet, the sheet genies out from the specified location, and if size.width is wider than the sheet, the sheet slides out. You cannot affect the size of the sheet through the size.width and size.height fields. It is recommended that you specify zero for the size.height value as this field may have additional meaning in a future release.
Availability
- Available in OS X v10.3 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindow:willResizeForVersionBrowserWithMaxPreferredSize:maxAllowedSize:
Tells the delegate the the window will resize for presentation during version browsing. (required)
Parameters
- window
The window being presented in a version browser.
- maxPreferredSize
The maximum size the version browser would prefer the window to be.
- maxAllowedSize
The maximum allowed size for the window (the full-screen frame minus the margins required to ensure the Versions controls are still visible).
Return Value
The size that the window should be.
Discussion
Windows entering the version browser will be resized to the size returned by this method. If either dimension of the returned size is larger than the maxPreferredFrameSize, the window will also be scaled down to ensure it fits properly in the version browser.
If this method is not implemented, the version browser will use windowWillUseStandardFrame:defaultFrame: to determine the resulting window frame size.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindow:willUseFullScreenContentSize:
Invoked to allow the delegate to modify the full-screen content size.
Parameters
- window
The window to enter to full-screen mode.
- proposedSize
The proposed window size.
Return Value
The window size to use when displaying content size.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindow:willUseFullScreenPresentationOptions:
Returns the presentation options the window uses when transitioning to full-screen mode.
Parameters
- window
The window to enter to full-screen mode.
- proposedOptions
The proposed options. See
NSApplicationPresentationOptionsfor the possible values.
Return Value
The options the window should use when transitioning to full-screen mode. These may be the same as the proposedOptions or may be modified.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidBecomeKey:
Informs the delegate that the window has become the key window.
Parameters
- notification
A notification named
NSWindowDidBecomeKeyNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidBecomeMain:
Informs the delegate that the window has become main.
Parameters
- notification
A notification named
NSWindowDidBecomeMainNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidChangeBackingProperties:
Tells the delegate that the window backing properties changed.
Parameters
- notification
A notification named
NSWindowDidChangeBackingPropertiesNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
The notification NSWindowDidChangeBackingPropertiesNotification is posted on OS X v10.7.3 or later when a window’s backing scale factor or its color space changes. You should watch for this notification instead of NSWindowDidChangeScreenProfileNotification if your app runs on a system version on which the backing properties notification is available.
Many apps won’t have the need to watch for this notification, but those that perform sophisticated color handling or manually manage their own cache of window-resolution or color-space-appropriate bitmapped images will find this notification useful as a prompt to invalidate caches or schedule other reassessment for the new resolution or color space. The notification’s userInfo dictionary specifies the window’s previous backing scale factor (retrieved with the keyNSBackingPropertyOldScaleFactorKey) and color space (retrieved with the key NSBackingPropertyOldColorSpaceKey). You can compare these with the window’s new previous backing scale factor and color space at the time of the notification to determine which properties changed.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidChangeScreen:
Tells the delegate that the window has changed screens.
Parameters
- notification
A notification named
NSWindowDidChangeScreenNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidChangeScreenProfile:
Tells the delegate that the window has changed screen display profiles.
Parameters
- notification
A notification named
NSWindowDidChangeScreenProfileNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
If your app runs on OS X v10.7.3 or later, you should instead watch for the notification NSWindowDidChangeBackingPropertiesNotification.
Availability
- Available in OS X v10.4 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidDeminiaturize:
Tells the delegate that the window has been deminimized.
Parameters
- notification
A notification named
NSWindowDidDeminiaturizeNotification
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidEndLiveResize:
Informs the delegate that a live resize operation on the window has ended.
Parameters
- notification
A notification named
NSWindowDidEndLiveResizeNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.6 and later.
Declared In
NSWindow.hwindowDidEndSheet:
Tells the delegate that the window has closed a sheet.
Parameters
- notification
A notification named
NSWindowDidEndSheetNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.1 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidEnterFullScreen:
The window just entered full-screen mode.
Parameters
- notification
A notification named
NSWindowDidEnterFullScreenNotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidEnterVersionBrowser:
Tells the delegate the the window just entered version browsing. (required)
Parameters
- notification
An
NSWindowDidEnterVersionBrowserNotificationnotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidExitFullScreen:
The window is about to enter full-screen mode.
Parameters
- notification
A notification named
NSWindowDidExitFullScreenNotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidExitVersionBrowser:
Tells the delegate the the window is about to leave version browsing. (required)
Parameters
- notification
An
NSWindowDidExitVersionBrowserNotificationnotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidExpose:
Tells the delegate that the window has been exposed.
Parameters
- notification
A notification named
NSWindowDidExposeNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidFailToEnterFullScreen:
Invoked if the window failed to enter full-screen mode.
Parameters
- window
The window that failed to enter to full-screen mode.
Discussion
In some cases, the transition to enter full-screen mode can fail, due to being in the midst of handling some other animation or user gesture. This method indicates that there was an error, and you should clean up any work you may have done to prepare to enter full-screen mode.
This message is sent whether or not the delegate indicated a custom animation by returning non-nil from customWindowsToEnterFullScreenForWindow:.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidFailToExitFullScreen:
Invoked if the window failed to exit full-screen mode.
Parameters
- window
The window that failed to exit to full-screen mode.
Discussion
In some cases, the transition to exit full-screen mode can fail, due to being in the midst of handling some other animation or user gesture. This method indicates that there was an error, and you should clean up any work you may have done to prepare to exit full-screen mode.
This message is sent whether or not the delegate indicated a custom animation by returning non-nil from customWindowsToExitFullScreenForWindow:.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowDidMiniaturize:
Tells the delegate that the window has been minimized.
Parameters
- notification
A notification named
NSWindowDidMiniaturizeNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidMove:
Tells the delegate that the window has moved.
Parameters
- notification
A notification named
NSWindowDidMoveNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidResignKey:
Informs the delegate that the window has resigned key window status.
Parameters
- notification
A notification named
NSWindowDidResignKeyNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidResignMain:
Informs the delegate that the window has resigned main window status.
Parameters
- notification
A notification named
NSWindowDidResignMainNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowDidResize:
Informs the delegate that the window has been resized.
Parameters
- notification
A notification named
NSWindowDidResizeNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowDidUpdate:
Tells the delegate that the window received an update message.
Parameters
- notification
A notification named
NSWindowDidUpdateNotification
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowShouldClose:
Tells the delegate that the user has attempted to close a window or the window has received a performClose: message.
Parameters
- sender
The window being closed.
Return Value
YES to allow sender to be closed; otherwise, NO.
Discussion
This method may not always be called during window closing. Specifically, this method is not called when a user quits an application.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowShouldZoom:toFrame:
Asks the delegate whether the specified window should zoom to the specified frame.
Parameters
- window
The window being zoomed.
- newFrame
The rectangle to which the specified window is being zoomed.
Return Value
YES to allow window’s frame to become newFrame; otherwise, NO.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowWillBeginSheet:
Notifies the delegate that the window is about to open a sheet.
Parameters
- notification
A notification named
NSWindowWillBeginSheetNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.1 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowWillClose:
Tells the delegate that the window is about to close.
Parameters
- notification
A notification named
NSWindowWillCloseNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowWillEnterFullScreen:
The window is about to enter full-screen mode.
Parameters
- notification
A notification named
NSWindowWillEnterFullScreenNotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowWillEnterVersionBrowser:
Tells the delegate the the window is about to enter version browsing. (required)
Parameters
- notification
An
NSWindowWillEnterVersionBrowserNotificationnotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowWillExitFullScreen:
The window is about to exit full-screen mode.
Parameters
- notification
A notification named
NSWindowWillExitFullScreenNotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowWillExitVersionBrowser:
Tells the delegate the the window just left version browsing. (required)
Parameters
- notification
An
NSWindowWillExitVersionBrowserNotificationnotification.
Availability
- Available in OS X v10.7 and later.
Declared In
NSWindow.hwindowWillMiniaturize:
Tells the delegate that the window is about to be minimized.
Parameters
- notification
A notification named
NSWindowWillMiniaturizeNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowWillMove:
Tells the delegate that the window is about to move.
Parameters
- notification
A notification named
NSWindowWillMoveNotification.
Discussion
You can retrieve the NSWindow object in question by sending object to notification.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowWillResize:toSize:
Tells the delegate that the window is being resized (whether by the user or through one of the setFrame... methods other than setFrame:display:).
Parameters
- sender
The window being resized.
- frameSize
The size to which the specified window is being resized.
Return Value
A custom size to which the specified window will be resized.
Discussion
The frameSize contains the size (in screen coordinates) sender will be resized to. To resize to a different size, simply return the desired size from this method; to avoid resizing, return the current size. sender’s minimum and maximum size constraints have already been applied when this method is invoked.
While the user is resizing a window, the delegate is sent a series of windowWillResize:toSize: messages as the window’s outline is dragged. The window’s outline is displayed at the constrained size as set by this method.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowWillReturnFieldEditor:toObject:
Tells the delegate that the field editor for a text-displaying object has been requested.
Parameters
- sender
The window requesting the field editor from the delegate.
- client
A text-displaying object to be associated with the field editor. If
nil, the requested field editor is the default.
Return Value
The field editor for client; returns nil when the delegate has no field editor to assign.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.hwindowWillReturnUndoManager:
Tells the delegate that the window’s undo manager has been requested. Returns the appropriate undo manager for the window.
Parameters
- window
The window whose undo manager is being requested.
Return Value
The appropriate undo manager for the specified window.
Discussion
If this method is not implemented by the delegate, the window creates anNSUndoManager for window.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSWindow.hwindowWillStartLiveResize:
Informs the delegate that the window is about to be live resized.
Parameters
- notification
A notification named
NSWindowWillStartLiveResizeNotification.
Discussion
You can retrieve the window object in question by sending object to notification.
Availability
- Available in OS X v10.6 and later.
Declared In
NSWindow.hwindowWillUseStandardFrame:defaultFrame:
Invoked by NSWindow’s zoom: method while determining the frame a window may be zoomed to.
Parameters
- window
The window whose frame size is being determined.
- newFrame
The size of the current screen, which is the screen containing the largest part of the window’s current frame, possibly reduced on the top, bottom, left, or right, depending on the current interface style. The frame is reduced on the top to leave room for the menu bar.
Return Value
The specified window’s standard frame.
Discussion
The standard frame for a window should supply the size and location that are “best” for the type of information shown in the window, taking into account the available display or displays. For example, the best width for a window that displays a word-processing document is the width of a page or the width of the display, whichever is smaller. The best height can be determined similarly. On return from this method, the zoom: method modifies the returned standard frame, if necessary, to fit on the current screen.
Availability
- Available in OS X v10.0 and later.
- Available as part of an informal protocol prior to OS X v10.6.
See Also
Declared In
NSWindow.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)