| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.6 and later. |
| Companion guide | |
| Declared in | NSWindow.h |
| Related sample code |
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.
– windowWillUseStandardFrame:defaultFrame:
– windowShouldZoom:toFrame:
– windowWillResize:toSize:
– windowDidResize:
– windowWillStartLiveResize:
– windowDidEndLiveResize:
Asks the delegate whether a user can drag the document icon from the window’s title bar.
- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard
The window containing the document icon the user wants to drag.
The left-mouse down event that triggered the dragging operation.
The location at which the user started the dragging operation.
The pasteboard containing the contents of the document, which the delegate can modify.
YES to allow the drag to proceed; NO to prevent it.
To implement its own dragging process, the delegate can perform the dragging operation and return NO.
NSWindow.hAsks the delegate whether the window displays the title pop-up menu in response to a Command-click or Control-click on its title.
- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
The window whose title the user Command-clicked or Control-clicked.
The menu the window will display, if allowed. By default, its items are the path components of the file represented by window.
YES to allow the display of the title pop-up menu; NO to prevent it.
NSWindow.hTells 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.
- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect
The window containing the sheet to be animated.
The sheet to be shown.
The default sheet location, just under the title bar of the window, aligned with the left and right edges of the window.
The custom location specified.
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.
NSWindow.hInforms the delegate that the window has become the key window.
- (void)windowDidBecomeKey:(NSNotification *)notification
A notification named NSWindowDidBecomeKeyNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hInforms the delegate that the window has become main.
- (void)windowDidBecomeMain:(NSNotification *)notification
A notification named NSWindowDidBecomeMainNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window has changed screens.
- (void)windowDidChangeScreen:(NSNotification *)notification
A notification named NSWindowDidChangeScreenNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window has changed screen display profiles.
- (void)windowDidChangeScreenProfile:(NSNotification *)notification
A notification named NSWindowDidChangeScreenProfileNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window has been deminimized.
- (void)windowDidDeminiaturize:(NSNotification *)notification
A notification named NSWindowDidDeminiaturizeNotification
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hInforms the delegate that a live resize operation on the window has ended.
- (void)windowDidEndLiveResize:(NSNotification *)notification
A notification named NSWindowDidEndLiveResizeNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window has closed a sheet.
- (void)windowDidEndSheet:(NSNotification *)notification
A notification named NSWindowDidEndSheetNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window has been exposed.
- (void)windowDidExpose:(NSNotification *)notification
A notification named NSWindowDidExposeNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window has been minimized.
- (void)windowDidMiniaturize:(NSNotification *)notification
A notification named NSWindowDidMiniaturizeNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window has moved.
- (void)windowDidMove:(NSNotification *)window
A notification named NSWindowDidMoveNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hInforms the delegate that the window has resigned key window status.
- (void)windowDidResignKey:(NSNotification *)notification
A notification named NSWindowDidResignKeyNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hInforms the delegate that the window has resigned main window status.
- (void)windowDidResignMain:(NSNotification *)notification
A notification named NSWindowDidResignMainNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hInforms the delegate that the window has been resized.
- (void)windowDidResize:(NSNotification *)notification
A notification named NSWindowDidResizeNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window received an update message.
- (void)windowDidUpdate:(NSNotification *)notification
A notification named NSWindowDidUpdateNotification
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the user has attempted to close a window or the window has received a performClose: message.
- (BOOL)windowShouldClose:(id)sender
The window being closed.
YES to allow sender to be closed; otherwise, NO.
This method may not always be called during window closing. Specifically, this method is not called when a user quits an application. You can find additional information on application termination in Graceful Application Termination.
NSWindow.hAsks the delegate whether the specified window should zoom to the specified frame.
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
The window being zoomed.
The rectangle to which the specified window is being zoomed.
YES to allow window’s frame to become newFrame; otherwise, NO.
NSWindow.hNotifies the delegate that the window is about to open a sheet.
- (void)windowWillBeginSheet:(NSNotification *)notification
A notification named NSWindowWillBeginSheetNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hTells the delegate that the window is about to close.
- (void)windowWillClose:(NSNotification *)notification
A notification named NSWindowWillCloseNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window is about to be minimized.
- (void)windowWillMiniaturize:(NSNotification *)notification
A notification named NSWindowWillMiniaturizeNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window is about to move.
- (void)windowWillMove:(NSNotification *)notification
A notification named NSWindowWillMoveNotification.
You can retrieve the NSWindow object in question by sending object to notification.
NSWindow.hTells the delegate that the window is being resized (whether by the user or through one of the setFrame... methods other than setFrame:display:).
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
The window being resized.
The size to which the specified window is being resized.
A custom size to which the specified window will be resized.
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.
NSWindow.hTells the delegate that the field editor for a text-displaying object has been requested.
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client
The window requesting the field editor from the delegate.
A text-displaying object to be associated with the field editor. If nil, the requested field editor is the default.
The field editor for client; returns nil when the delegate has no field editor to assign.
NSWindow.hTells the delegate that the window’s undo manager has been requested. Returns the appropriate undo manager for the window.
- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window
The window whose undo manager is being requested.
The appropriate undo manager for the specified window.
If this method is not implemented by the delegate, the window creates anNSUndoManager for window.
NSWindow.hInforms the delegate that the window is about to be live resized.
- (void)windowWillStartLiveResize:(NSNotification *)notification
A notification named NSWindowWillStartLiveResizeNotification.
You can retrieve the window object in question by sending object to notification.
NSWindow.hInvoked by NSWindow’s zoom: method while determining the frame a window may be zoomed to.
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame
The window whose frame size is being determined.
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.
The specified window’s standard frame.
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.
NSWindow.hLast updated: 2009-04-25