Mac Developer Library

Developer

AppKit Framework Reference NSWindowDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSWindowDelegate

The NSWindowDelegate protocol defines the methods that a delegate of NSWindow should implement. All methods in this protocol are optional. More...

Inheritance


Not Applicable

Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.6 and later.
  • 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.

    Declaration

    Swift

    optional func window(_ window: NSWindow, willPositionSheet sheet: NSWindow, usingRect rect: NSRect) -> NSRect

    Objective-C

    - (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 called 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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowWillBeginSheet(_ notification: NSNotification)

    Objective-C

    - (void)windowWillBeginSheet:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowWillBeginSheetNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.1 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has closed a sheet.

    Declaration

    Swift

    optional func windowDidEndSheet(_ notification: NSNotification)

    Objective-C

    - (void)windowDidEndSheet:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidEndSheetNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.1 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowWillMiniaturize(_ notification: NSNotification)

    Objective-C

    - (void)windowWillMiniaturize:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowWillMiniaturizeNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has been minimized.

    Declaration

    Swift

    optional func windowDidMiniaturize(_ notification: NSNotification)

    Objective-C

    - (void)windowDidMiniaturize:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidMiniaturizeNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has been deminimized.

    Declaration

    Swift

    optional func windowDidDeminiaturize(_ notification: NSNotification)

    Objective-C

    - (void)windowDidDeminiaturize:(NSNotification *)notification

    Parameters

    notification

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowWillUseStandardFrame(_ window: NSWindow, defaultFrame newFrame: NSRect) -> NSRect

    Objective-C

    - (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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowShouldZoom(_ window: NSWindow, toFrame newFrame: NSRect) -> Bool

    Objective-C

    - (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

    YEStrue to allow window’s frame to become newFrame; otherwise, NOfalse.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window is about to move.

    Declaration

    Swift

    optional func windowWillMove(_ notification: NSNotification)

    Objective-C

    - (void)windowWillMove:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowWillMoveNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has moved.

    Declaration

    Swift

    optional func windowDidMove(_ notification: NSNotification)

    Objective-C

    - (void)windowDidMove:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidMoveNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has changed screens.

    Declaration

    Swift

    optional func windowDidChangeScreen(_ notification: NSNotification)

    Objective-C

    - (void)windowDidChangeScreen:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidChangeScreenNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowDidChangeScreenProfile(_ notification: NSNotification)

    Objective-C

    - (void)windowDidChangeScreenProfile:(NSNotification *)notification

    Parameters

    notification

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window backing properties changed.

    Declaration

    Swift

    optional func windowDidChangeBackingProperties(_ notification: NSNotification)

    Objective-C

    - (void)windowDidChangeBackingProperties:(NSNotification *)notification

    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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    optional func windowShouldClose(_ sender: AnyObject) -> Bool

    Objective-C

    - (BOOL)windowShouldClose:(id)sender

    Parameters

    sender

    The window being closed.

    Return Value

    YEStrue to allow sender to be closed; otherwise, NOfalse.

    Discussion

    This method may not always be called during window closing. Specifically, this method is not called when a user quits an application.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window is about to close.

    Declaration

    Swift

    optional func windowWillClose(_ notification: NSNotification)

    Objective-C

    - (void)windowWillClose:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowWillCloseNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func windowWillReturnFieldEditor(_ sender: NSWindow, toObject client: AnyObject?) -> AnyObject?

    Objective-C

    - (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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window received an update message.

    Declaration

    Swift

    optional func windowDidUpdate(_ notification: NSNotification)

    Objective-C

    - (void)windowDidUpdate:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidUpdateNotification

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Tells the delegate that the window has been exposed.

    Declaration

    Swift

    optional func windowDidExpose(_ notification: NSNotification)

    Objective-C

    - (void)windowDidExpose:(NSNotification *)notification

    Parameters

    notification

    A notification named NSWindowDidExposeNotification.

    Discussion

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

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Asks the delegate whether a user can drag the document icon from the window’s title bar.

    Declaration

    Swift

    optional func window(_ window: NSWindow, shouldDragDocumentWithEvent event: NSEvent, from dragImageLocation: NSPoint, withPasteboard pasteboard: NSPasteboard) -> Bool

    Objective-C

    - (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 of the origin of the document icon, in window coordinates, when the user started the dragging operation.

    pasteboard

    The pasteboard containing the contents of the document, which the delegate can modify.

    Return Value

    YEStrue to allow the drag to proceed; NOfalse to prevent it. Before turning no the delegate can implement its own dragging behavior as described below.

    Discussion

    Implementing this method enables an application to customize the process of dragging the window’s document icon. The delegate can prohibit the drag by returning NOfalse. Before returning NOfalse, the delegate can implement its own dragging behavior using dragImage:at:offset:event:pasteboard:source:slideBack:.

    Alternatively, the delegate can enable a drag by returning YEStrue, for example, to override the default NSWindow behavior of prohibiting the drag of an edited document. In addition, the delegate can customize the pasteboard contents before returning YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    representedURL

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

    Declaration

    Swift

    optional func windowWillReturnUndoManager(_ window: NSWindow) -> NSUndoManager?

    Objective-C

    - (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.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Asks the delegate whether the window displays the title pop-up menu in response to a Command-click or Control-click on its title.

    Declaration

    Swift

    optional func window(_ window: NSWindow, shouldPopUpDocumentPathMenu menu: NSMenu) -> Bool

    Objective-C

    - (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

    YEStrue to allow the display of the title pop-up menu; NOfalse to prevent it.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    representedURL