Mac OS X Reference Library Apple Developer Connection spyglass button

NSWindowDelegate Protocol Reference

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

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

Managing Key Status

Managing Main Status

Managing Field Editors

Updating Windows

Exposing Windows

Dragging Windows

Getting the Undo Manager

Managing Titles

Moving Windows

Closing Windows

Minimizing Windows

Instance Methods

window:shouldDragDocumentWithEvent:from:withPasteboard:

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

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.

Discussion

To implement its own dragging process, the delegate can perform the dragging operation and return NO.

Availability
  • Available in Mac OS X v10.5 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
See Also
Declared In
NSWindow.h

window: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.

- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu

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 Mac OS X v10.5 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
See Also
Declared In
NSWindow.h

window: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.

- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect

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 Mac OS X v10.3 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidBecomeKey:

Informs the delegate that the window has become the key window.

- (void)windowDidBecomeKey:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidBecomeKeyNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidBecomeMain:

Informs the delegate that the window has become main.

- (void)windowDidBecomeMain:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidBecomeMainNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidChangeScreen:

Tells the delegate that the window has changed screens.

- (void)windowDidChangeScreen:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidChangeScreenNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidChangeScreenProfile:

Tells the delegate that the window has changed screen display profiles.

- (void)windowDidChangeScreenProfile:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidChangeScreenProfileNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.4 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidDeminiaturize:

Tells the delegate that the window has been deminimized.

- (void)windowDidDeminiaturize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidDeminiaturizeNotification

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidEndLiveResize:

Informs the delegate that a live resize operation on the window has ended.

- (void)windowDidEndLiveResize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidEndLiveResizeNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.6 and later.
Declared In
NSWindow.h

windowDidEndSheet:

Tells the delegate that the window has closed a sheet.

- (void)windowDidEndSheet:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidEndSheetNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.1 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidExpose:

Tells the delegate that the window has been exposed.

- (void)windowDidExpose:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidExposeNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidMiniaturize:

Tells the delegate that the window has been minimized.

- (void)windowDidMiniaturize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidMiniaturizeNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidMove:

Tells the delegate that the window has moved.

- (void)windowDidMove:(NSNotification *)window

Parameters
window

A notification named NSWindowDidMoveNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidResignKey:

Informs the delegate that the window has resigned key window status.

- (void)windowDidResignKey:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidResignKeyNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidResignMain:

Informs the delegate that the window has resigned main window status.

- (void)windowDidResignMain:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidResignMainNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidResize:

Informs the delegate that the window has been resized.

- (void)windowDidResize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidResizeNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowDidUpdate:

Tells the delegate that the window received an update message.

- (void)windowDidUpdate:(NSNotification *)notification

Parameters
notification

A notification named NSWindowDidUpdateNotification

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowShouldClose:

Tells the delegate that the user has attempted to close a window or the window has received a performClose: message.

- (BOOL)windowShouldClose:(id)sender

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. You can find additional information on application termination in Graceful Application Termination.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowShouldZoom:toFrame:

Asks the delegate whether the specified window should zoom to the specified frame.

- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame

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 Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
See Also
Declared In
NSWindow.h

windowWillBeginSheet:

Notifies the delegate that the window is about to open a sheet.

- (void)windowWillBeginSheet:(NSNotification *)notification

Parameters
notification

A notification named NSWindowWillBeginSheetNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.1 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillClose:

Tells the delegate that the window is about to close.

- (void)windowWillClose:(NSNotification *)notification

Parameters
notification

A notification named NSWindowWillCloseNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillMiniaturize:

Tells the delegate that the window is about to be minimized.

- (void)windowWillMiniaturize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowWillMiniaturizeNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillMove:

Tells the delegate that the window is about to move.

- (void)windowWillMove:(NSNotification *)notification

Parameters
notification

A notification named NSWindowWillMoveNotification.

Discussion

You can retrieve the NSWindow object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillResize: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:).

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize

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 Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillReturnFieldEditor:toObject:

Tells the delegate that the field editor for a text-displaying object has been requested.

- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)client

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 Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
See Also
Declared In
NSWindow.h

windowWillReturnUndoManager:

Tells the delegate that the window’s undo manager has been requested. Returns the appropriate undo manager for the window.

- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)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 Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
Declared In
NSWindow.h

windowWillStartLiveResize:

Informs the delegate that the window is about to be live resized.

- (void)windowWillStartLiveResize:(NSNotification *)notification

Parameters
notification

A notification named NSWindowWillStartLiveResizeNotification.

Discussion

You can retrieve the window object in question by sending object to notification.

Availability
  • Available in Mac OS X v10.6 and later.
Declared In
NSWindow.h

windowWillUseStandardFrame:defaultFrame:

Invoked by NSWindow’s zoom: method while determining the frame a window may be zoomed to.

- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame

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 Mac OS X v10.0 and later.
  • Available as part of an informal protocol prior to Mac OS X v10.6.
See Also
Declared In
NSWindow.h


Last updated: 2009-04-25

Did this document help you? Yes It's good, but... Not helpful...