| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.0 and later. |
| Companion guide | |
| Declared in | NSDrawer.h NSGraphics.h NSWindow.h |
| Related sample code |
The NSWindow class defines objects (known as windows) that manage and coordinate the windows an application displays on the screen. A single NSWindow object corresponds to at most one onscreen window. The two principal functions of a window are to provide an area in which views can be placed and to accept and distribute, to the appropriate views, events the user instigates through actions with the mouse and keyboard.
Note: Although the NSWindow class inherits the NSCoding protocol from NSResponder, the class does not support coding. Legacy support for archivers exists but its use is deprecated and may not work. Any attempt to archive or unarchive an NSWindow object using a keyed coding object raises an NSInvalidArgumentException exception.
– initWithContentRect:styleMask:backing:defer:
– initWithContentRect:styleMask:backing:defer:screen:
– styleMask
– worksWhenModal
– alphaValue
– setAlphaValue:
– backgroundColor
– setBackgroundColor:
– contentView
– setContentView:
– canHide
– setCanHide:
– hidesOnDeactivate
– setHidesOnDeactivate:
– collectionBehavior
– setCollectionBehavior:
– isOpaque
– setOpaque:
– hasShadow
– setHasShadow:
– invalidateShadow
– autorecalculatesContentBorderThicknessForEdge:
– setAutorecalculatesContentBorderThickness:forEdge:
– contentBorderThicknessForEdge:
– setContentBorderThickness:forEdge:
– delegate
– setDelegate:
– canBeVisibleOnAllSpaces Deprecated in Mac OS X v10.5
– setCanBeVisibleOnAllSpaces: Deprecated in Mac OS X v10.5
+ defaultDepthLimit
– windowNumber
– gState
– canStoreColor
– deviceDescription
– canBecomeVisibleWithoutLogin
– setCanBecomeVisibleWithoutLogin:
– sharingType
– setSharingType:
– backingType
– setBackingType:
– backingLocation
– preferredBackingLocation
– setPreferredBackingLocation:
– isOneShot
– setOneShot:
– depthLimit
– setDepthLimit:
– hasDynamicDepthLimit
– setDynamicDepthLimit:
+ contentRectForFrameRect:styleMask:
+ frameRectForContentRect:styleMask:
+ minFrameWidthWithTitle:styleMask:
– contentRectForFrameRect:
– frameRectForContentRect:
– attachedSheet
– isSheet
– window:willPositionSheet:usingRect: delegate method
– windowWillBeginSheet: delegate method
– windowDidEndSheet: delegate method
– frame
– setFrameOrigin:
– setFrameTopLeftPoint:
– constrainFrameRect:toScreen:
– cascadeTopLeftFromPoint:
– setFrame:display:
– setFrame:display:animate:
– animationResizeTime:
– windowWillUseStandardFrame:defaultFrame: delegate method
– aspectRatio
– setAspectRatio:
– minSize
– setMinSize:
– maxSize
– setMaxSize:
– isZoomed
– performZoom:
– zoom:
– windowShouldZoom:toFrame: delegate method
– resizeFlags
– showsResizeIndicator
– setShowsResizeIndicator:
– resizeIncrements
– setResizeIncrements:
– preservesContentDuringLiveResize
– setPreservesContentDuringLiveResize:
– windowWillResize:toSize: delegate method
– windowDidResize: delegate method
– contentAspectRatio
– setContentAspectRatio:
– contentMinSize
– setContentMinSize:
– setContentSize:
– contentMaxSize
– setContentMaxSize:
– contentResizeIncrements
– setContentResizeIncrements:
– isVisible
– orderOut:
– orderBack:
– orderFront:
– orderFrontRegardless
– orderWindow:relativeTo:
– level
– setLevel:
+ removeFrameUsingName:
– setFrameUsingName:
– setFrameUsingName:force:
– saveFrameUsingName:
– frameAutosaveName
– setFrameAutosaveName:
– stringWithSavedFrame
– setFrameFromString:
– isKeyWindow
– canBecomeKeyWindow
– makeKeyWindow
– makeKeyAndOrderFront:
– becomeKeyWindow
– windowDidBecomeKey: delegate method
– resignKeyWindow
– windowDidResignKey: delegate method
– isMainWindow
– canBecomeMainWindow
– makeMainWindow
– becomeMainWindow
– windowDidBecomeMain: delegate method
– resignMainWindow
– windowDidResignMain: delegate method
– isFlushWindowDisabled
– enableFlushWindow
– disableFlushWindow
– flushWindow
– flushWindowIfNeeded
– defaultButtonCell
– setDefaultButtonCell:
– enableKeyEquivalentForDefaultButtonCell
– disableKeyEquivalentForDefaultButtonCell
– areCursorRectsEnabled
– enableCursorRects
– disableCursorRects
– discardCursorRects
– invalidateCursorRectsForView:
– resetCursorRects
+ standardWindowButton:forStyleMask:
– standardWindowButton:
– showsToolbarButton
– setShowsToolbarButton:
+ menuChanged:
– currentEvent
– nextEventMatchingMask:
– nextEventMatchingMask:untilDate:inMode:dequeue:
– discardEventsMatchingMask:beforeEvent:
– postEvent:atStart:
– sendEvent:
– tryToPerform:with:
– selectKeyViewPrecedingView:
– selectKeyViewFollowingView:
– selectPreviousKeyView:
– selectNextKeyView:
– keyViewSelectionDirection
– autorecalculatesKeyViewLoop
– recalculateKeyViewLoop
– setAutorecalculatesKeyViewLoop:
– acceptsMouseMovedEvents
– ignoresMouseEvents
– setIgnoresMouseEvents:
– mouseLocationOutsideOfEventStream
– setAcceptsMouseMovedEvents:
– display
– displayIfNeeded
– viewsNeedDisplay
– setViewsNeedDisplay:
– isAutodisplay
– setAutodisplay:
– useOptimizedDrawing:
– graphicsContext
– disableScreenUpdatesUntilFlush
– update
– windowDidUpdate: delegate method
– windowDidExpose: delegate method
– dragImage:at:offset:event:pasteboard:source:slideBack:
– registerForDraggedTypes:
– unregisterDraggedTypes
– window:shouldDragDocumentWithEvent:from:withPasteboard: delegate method
– windowWillReturnUndoManager: delegate method
– title
– setTitle:
– setTitleWithRepresentedFilename:
– representedFilename
– setRepresentedFilename:
– representedURL
– setRepresentedURL:
– window:shouldPopUpDocumentPathMenu: delegate method
– isMovableByWindowBackground
– setMovableByWindowBackground:
– center
– windowWillMove: delegate method
– windowDidMove: delegate method
– windowDidChangeScreen: delegate method
– windowDidChangeScreenProfile: delegate method
– performClose:
– close
– windowShouldClose: delegate method
– windowWillClose: delegate method
– isReleasedWhenClosed
– setReleasedWhenClosed:
– isMiniaturized
– performMiniaturize:
– miniaturize:
– windowWillMiniaturize: delegate method
– windowDidMiniaturize: delegate method
– deminiaturize:
– windowDidDeminiaturize: delegate method
– miniwindowImage
– setMiniwindowImage:
– miniwindowTitle
– setMiniwindowTitle:
Returns the content rectangle used by a window with a given frame rectangle and window style.
+ (NSRect)contentRectForFrameRect:(NSRect)windowFrame styleMask:(NSUInteger)windowStyle
The frame rectangle for the window expressed in screen coordinates.
The window style for the window. See “Constants” for a list of style mask values.
The content rectangle, expressed in screen coordinates, used by the window with windowFrame and windowStyle.
When a NSWindow instance is available, you should use contentRectForFrameRect: instead of this method.
NSWindow.h
Returns the default depth limit for instances of NSWindow.
+ (NSWindowDepth)defaultDepthLimit
The default depth limit for instances of NSWindow, determined by the depth of the deepest screen level available to the window server.
The value returned can be examined with the Application Kit functions NSPlanarFromDepth, NSColorSpaceFromDepth, NSBitsPerSampleFromDepth, and NSBitsPerPixelFromDepth.
NSWindow.hReturns the frame rectangle used by a window with a given content rectangle and window style.
+ (NSRect)frameRectForContentRect:(NSRect)windowContentRect styleMask:(NSUInteger)windowStyle
The content rectangle for a window expressed in screen coordinates.
The window style for the window. See “Constants” for a list of style mask values.
The frame rectangle, expressed in screen coordinates, used by the window with windowContentRect and windowStyle.
When a NSWindow instance is available, you should use frameRectForContentRect: instead of this method.
NSWindow.h
This method does nothing; it is here for backward compatibility.
+ (void)menuChanged:(NSMenu *)menu
The menu object that changed.
– menu (NSResponder)NSWindow.hReturns the minimum width a window’s frame rectangle must have for it to display a title, with a given window style.
+ (CGFloat)minFrameWidthWithTitle:(NSString *)windowTitle styleMask:(NSUInteger)windowStyle
The title for the window.
The window style for the window. See “Constants” for a list of style mask values.
The minimum width of the window’s frame, using windowStyle, in order to display windowTitle.
NSWindow.h
Removes the frame data stored under a given name from the application’s user defaults.
+ (void)removeFrameUsingName:(NSString *)frameName
The name of the frame to remove.
NSWindow.h
Returns a new instance of a given standard window button, sized appropriately for a given window style.
+ (NSButton *)standardWindowButton:(NSWindowButton)windowButtonKind forStyleMask:(NSUInteger)windowStyle
The kind of standard window button to return.
The window style for which windowButtonKind is to be sized. See “Window Style Masks” for the list of allowable values.
The new window button of the kind identified by windowButtonKind; nil when no such button kind exists.
The caller is responsible for adding the button to the view hierarchy and for setting the target to be the window.
NSWindow.hIndicates whether the window accepts mouse-moved events.
- (BOOL)acceptsMouseMovedEvents
YES when the window accepts (and distributes) mouse-moved events; NO otherwise.
The NSWindow default is NO.
NSWindow.hAdds a given window as a child window of the window.
- (void)addChildWindow:(NSWindow *)childWindow ordered:(NSWindowOrderingMode)orderingMode
The child window to order.
NSWindowAbove: childWindow is ordered immediately in front of the window.
NSWindowBelow: childWindow is ordered immediately behind the window.
After the childWindow is added as a child of the window, it is maintained in relative position indicated by orderingMode for subsequent ordering operations involving either window. While this attachment is active, moving childWindow will not cause the window to move (as in sliding a drawer in or out), but moving the window will cause childWindow to move.
Note that you should not create cycles between parent and child windows. For example, you should not add window B as child of window A, then add window A as a child of window B.
NSWindow.hIndicates whether the window can display tooltips even when the application is in the background.
- (BOOL)allowsToolTipsWhenApplicationIsInactive
YES if the window can display tooltips even when the application is in the background; NO otherwise.
The default is NO.
NSWindow.hReturns the window’s alpha value.
- (CGFloat)alphaValue
The window’s alpha value.
NSWindow.hSpecifies the duration of a smooth frame-size change.
- (NSTimeInterval)animationResizeTime:(NSRect)newWindowFrame
The frame rectangle specified in setFrame:display:animate:.
The duration of the frame size change.
Subclasses can override this method to control the total time for the frame change.
The NSWindow implementation uses the value from the NSWindowResizeTime user default as the time in seconds to resize by 150 pixels. If this value is unspecified, NSWindowResizeTime is 0.20 seconds (this default value may be differ in different releases of Mac OS X).
NSWindow.hIndicates whether the window’s cursor rectangles are enabled.
- (BOOL)areCursorRectsEnabled
YES when cursor rectangles are enabled, NO otherwise.
NSWindow.h
Returns the window’s aspect ratio, which constrains the size of its frame rectangle to integral multiples of this ratio when the user resizes it.
- (NSSize)aspectRatio
The window’s aspect ratio.
The size of the window’s frame rectangle is constrained to integral multiples of this ratio when the user resizes it. You can set an NSWindow object’s size to any ratio programmatically.
NSWindow.hReturns the sheet attached to the window.
- (NSWindow *)attachedSheet
The sheet attached to the window; nil when the window doesn’t have a sheet attached.
NSWindow.hIndicates whether the window calculates the thickness of a given border automatically.
- (BOOL)autorecalculatesContentBorderThicknessForEdge:(NSRectEdge)edge
Border whose thickness autorecalculation status to set:
NSMaxYEdge: Top border.
NSMinYEdge: Bottom border.
YES when the window autorecalculates the given border’s thickness; NO otherwise.
NSWindow.hIndicates whether the window automatically recalculates the key view loop when views are added.
- (BOOL)autorecalculatesKeyViewLoop
YES if the window automatically recalculates the key view loop when views are added; NO otherwise.
NSWindow.h
Returns the color of the window’s background.
- (NSColor *)backgroundColor
The window’s background color.
NSWindow.hIndicates the window’s backing store location.
- (NSWindowBackingLocation)backingLocation
The location of the window’s backing store. See “Constants” for possible values.
NSWindow.h
Returns the window’s backing store type.
- (NSBackingStoreType)backingType
The backing store type.
The possible return values are described in “Constants.”
NSWindow.h
Invoked automatically to inform the window that it has become the key window; never invoke this method directly.
- (void)becomeKeyWindow
This method reestablishes the window’s first responder, sends the becomeKeyWindow message to that object if it responds, and posts an NSWindowDidBecomeKeyNotification to the default notification center.
NSWindow.h
Invoked automatically to inform the window that it has become the main window; never invoke this method directly.
- (void)becomeMainWindow
This method posts an NSWindowDidBecomeMainNotification to the default notification center.
NSWindow.hStores the window’s raster image from a given rectangle expressed in the window’s base coordinate system.
- (void)cacheImageInRect:(NSRect)rectangle
The rectangle representing the image to cache.
This method allows the window to perform temporary drawing, such as a band around the selection as the user drags the mouse, and to quickly restore the previous image by invoking restoreCachedImage and flushWindowIfNeeded. The next time the window displays, it discards its cached image rectangles. You can also explicitly use discardCachedImage to free the memory occupied by cached image rectangles. aRect is made integral before caching the image to avoid antialiasing artifacts.
Only the last cached rectangle is remembered and can be restored.
NSWindow.hIndicates whether the window can become the key window.
- (BOOL)canBecomeKeyWindow
YES if the window can become the key window, NO otherwise.
Attempts to make the window the key window are abandoned if this method returns NO. The NSWindow implementation returns YES if the window has a title bar or a resize bar, NO otherwise.
NSWindow.hIndicates whether the window can become the application’s main window.
- (BOOL)canBecomeMainWindow
YES when the window can become the main window; NO otherwise.
Attempts to make the window the main window are abandoned if this method returns NO. The NSWindow implementation returns YES if the window is visible, is not an NSPanel object, and has a title bar or a resize mechanism. Otherwise it returns NO.
NSWindow.hIndicates whether the window can be displayed at the log-in window. Default: NO.
- (BOOL)canBecomeVisibleWithoutLogin
YES when the window can be displayed at the log-in window; NO otherwise.
NSWindow.hIndicates whether the window can be hidden when its application becomes hidden (during execution of the NSApplication hide: method).
- (BOOL)canHide
YES if the window can be hidden when its application becomes hidden; NO otherwise.
The default is YES.
NSWindow.h
Indicates whether the window has a depth limit that allows it to store color values.
- (BOOL)canStoreColor
YES when the window’s depth limit allows it to store color values; NO otherwise.
– depthLimit– shouldDrawColor (NSView)NSWindow.hPositions the window's top left to a given point.
- (NSPoint)cascadeTopLeftFromPoint:(NSPoint)topLeft
The new top-left point, in screen coordinates, for the window. When NSZeroPoint, the window is not moved, except as needed to constrain to the visible screen
The point shifted from top left of the window in screen coordinates.
The returned point can be passed to a subsequent invocation of cascadeTopLeftFromPoint: to position the next window so the title bars of both windows are fully visible.
NSWindow.hSets the window’s location to the center of the screen.
- (void)center
The window is placed exactly in the center horizontally and somewhat above center vertically. Such a placement carries a certain visual immediacy and importance. This method doesn’t put the window onscreen, however; use makeKeyAndOrderFront: to do that.
You typically use this method to place a window—most likely an alert dialog—where the user can’t miss it. This method is invoked automatically when a panel is placed on the screen by the runModalForWindow: method of the NSApplication class.
NSWindow.hReturns an array of the window’s attached child windows.
- (NSArray *)childWindows
An array containing the window’s child windows.
NSWindow.hRemoves the window from the screen.
- (void)close
If the window is set to be released when closed, a release message is sent to the object after the current event is completed. For an NSWindow object, the default is to be released on closing, while for an NSPanel object, the default is not to be released. You can use the setReleasedWhenClosed: method to change the default behavior.
A window doesn’t have to be visible to receive the close message. For example, when the application terminates, it sends the close message to all windows in its window list, even those that are not currently visible.
The close method posts an NSWindowWillCloseNotification notification to the default notification center.
The close method differs in two important ways from the performClose: method:
It does not attempt to send a windowShouldClose: message to the window or its delegate.
It does not simulate the user clicking the close button by momentarily highlighting the button.
Use performClose: if you need these features.
NSWindow.hIdentifies the window’s behavior in window collections.
- (NSWindowCollectionBehavior)collectionBehavior;
The collection behavior identifier.
NSWindow.hModifies and returns a frame rectangle so that its top edge lies on a specific screen.
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
The proposed frame rectangle to adjust.
The screen on which the top edge of the window’s frame is to lie.
The adjusted frame rectangle.
If the window is resizable and the window’s height is greater than the screen height, the rectangle’s height is adjusted to fit within the screen as well. The rectangle’s width and horizontal location are unaffected. You shouldn’t need to invoke this method yourself; it’s invoked automatically (and the modified frame is used to locate and set the size of the window) whenever a titled NSWindow object is placed onscreen and whenever its size is changed.
Subclasses can override this method to prevent their instances from being constrained or to constrain them differently.
NSWindow.hReturns the window’s content aspect ratio.
- (NSSize)contentAspectRatio
The window’s content aspect ratio.
The default content aspect ratio is (0, 0).
NSWindow.hIndicates the thickness of a given border of the window.
- (CGFloat)contentBorderThicknessForEdge:(NSRectEdge)edge
Border whose thickness to get:
NSMaxYEdge: Top border.
NSMinYEdge: Bottom border.
Thickness of the given border, in points.
NSWindow.hReturns the maximum size of the window’s content view.
- (NSSize)contentMaxSize
The maximum size of the window’s content view.
NSWindow.hReturns the minimum size of the window’s content view.
- (NSSize)contentMinSize
The minimum size of the window’s content view.
NSWindow.hReturns the window’s content rectangle with a given frame rectangle.
- (NSRect)contentRectForFrameRect:(NSRect)windowFrame
The frame rectangle for the window expressed in screen coordinates.
The window’s content rectangle, expressed in screen coordinates, with windowFrame.
The window uses its current style mask in computing the content rectangle. See “Constants” for a list of style mask values. The main advantage of this instance-method counterpart to contentRectForFrameRect:styleMask: is that it allows you to take toolbars into account when converting between content and frame rectangles. (The toolbar is not included in the content rectangle.)
NSWindow.hReturns the window’s content-view resizing increments.
- (NSSize)contentResizeIncrements
The window’s content-view resizing increments.
NSWindow.h
Returns the window’s content view, the highest accessible NSView object in the window’s view hierarchy.
- (id)contentView
The content view.
NSWindow.h
Converts a given point from the window’s base coordinate system to the screen coordinate system.
- (NSPoint)convertBaseToScreen:(NSPoint)point
The point expressed in the window’s base coordinate system.
point expressed in screen coordinates.
NSWindow.h
Converts a given point from the screen coordinate system to the window’s base coordinate system.
- (NSPoint)convertScreenToBase:(NSPoint)aPoint
The point expressed in screen coordinates.
point expressed in the window’s base coordinate system.
NSWindow.h
Returns the event currently being processed by the application, by invoking NSApplication’s currentEvent method.
- (NSEvent *)currentEvent
The event being processed by the application.
NSWindow.hReturns EPS data that draws the region of the window within a given rectangle.
- (NSData *)dataWithEPSInsideRect:(NSRect)rect
A rectangle (expressed in the window’s coordinate system) that identifies the region to be expressed as EPS data.
The region in the window (identified by rect) as EPS data.
This data can be placed on a pasteboard, written to a file, or used to create an NSImage object.
– dataWithEPSInsideRect: (NSView)– writeEPSInsideRect:toPasteboard: (NSView)NSWindow.hReturns PDF data that draws the region of the window within a given rectangle.
- (NSData *)dataWithPDFInsideRect:(NSRect)rect
A rectangle (expressed in the window’s coordinate system) that identifies the region to be expressed as PDF data.
The region in the window (identified by rect) as PDF data.
This data can be placed on a pasteboard, written to a file, or used to create an NSImage object.
– dataWithPDFInsideRect: (NSView)– writePDFInsideRect:toPasteboard: (NSView)NSWindow.h
Returns the deepest screen the window is on (it may be split over several screens).
- (NSScreen *)deepestScreen
The deepest screen the window is on; nil when the window is offscreen.
– screen+ deepestScreen (NSScreen)NSWindow.hReturns the button cell that performs as if clicked when the window receives a Return (or Enter) key event.
- (NSButtonCell *)defaultButtonCell
The button cell.
This cell draws itself as the focal element for keyboard interface control, unless another button cell is focused on, in which case the default button cell temporarily draws itself as normal and disables its key equivalent.
The window receives a Return key event if no responder in its responder chain claims it, or if the user presses the Control key along with the Return key.
– setDefaultButtonCell:– disableKeyEquivalentForDefaultButtonCell– enableKeyEquivalentForDefaultButtonCellNSWindow.hReturns the window’s delegate.
- (id)delegate
The window’s delegate, or nil if it doesn’t have a delegate.
NSWindow.hDeminimizes the window.
- (void)deminiaturize:(id)sender
The message’s sender.
Invoke this method to programmatically deminimize a minimized window in the Dock.
NSWindow.h
Returns the depth limit of the window.
- (NSWindowDepth)depthLimit
Depth limit of the window.
The value returned can be examined with the Application Kit functions NSPlanarFromDepth, NSColorSpaceFromDepth, NSBitsPerSampleFromDepth, and NSBitsPerPixelFromDepth.
NSWindow.h
Returns a dictionary containing information about the window’s resolution.
- (NSDictionary *)deviceDescription
A dictionary containing resolution information about the window, such as color, depth, and so on.
This information is useful for tuning images and colors to the window’s display capabilities. The contents of the dictionary are described in “Display Device—Descriptions”.
– deviceDescription (NSScreen)– bestRepresentationForDevice: (NSImage)– colorUsingColorSpaceName: (NSColor)NSWindow.hDisables all cursor rectangle management within the window.
- (void)disableCursorRects
Use this method when you need to do some special cursor manipulation and you don’t want the Application Kit interfering.
NSWindow.hDisables the flushWindow method for the window.
- (void)disableFlushWindow
If the window is buffered, disabling flushWindow prevents drawing from being automatically flushed by the NSView display... methods from the window’s backing store to the screen. This method permits several views to be drawn before the results are shown to the user.
Flushing should be disabled only temporarily, while the window’s display is being updated. Each disableFlushWindow message must be paired with a subsequent enableFlushWindow message. Invocations of these methods can be nested; flushing isn’t reenabled until the last (unnested) enableFlushWindow message is sent.
NSWindow.h
Disables the default button cell’s key equivalent, so it doesn’t perform a click when the user presses Return (or Enter).
- (void)disableKeyEquivalentForDefaultButtonCell
NSWindow.hDisables the window’s screen updates until the window is flushed.
- (void)disableScreenUpdatesUntilFlush
This method can be invoked to synchronize hardware surface flushes with the window’s flushes. The window immediately disables screen updates using the NSDisableScreenUpdates function and reenables screen updates when the window flushes. Sending this message multiple times during a window update cycle has no effect.
NSWindow.hDiscards all of the window’s cached image rectangles.
- (void)discardCachedImage
An NSWindow object automatically discards its cached image rectangles when it displays.
NSWindow.hInvalidates all cursor rectangles in the window.
- (void)discardCursorRects
This method is invoked by resetCursorRects to clear out existing cursor rectangles before resetting them. You shouldn’t invoke it in the code you write, but you might want to override it to change its behavior.
NSWindow.h
Forwards the message to the NSApplication object, NSApp.
- (void)discardEventsMatchingMask:(NSUInteger)eventMask beforeEvent:(NSEvent *)lastEvent
The mask of the events to discard.
The event up to which queued events are discarded from the queue.
– discardEventsMatchingMask:beforeEvent: (NSApplication)NSWindow.hPasses a display message down the window’s view hierarchy, thus redrawing all views within the window, including the frame view that draws the border, title bar, and other peripheral elements.
- (void)display
You rarely need to invoke this method. NSWindow objects normally record which of their views need display and display them automatically on each pass through the event loop.
– display (NSView)– displayIfNeeded– isAutodisplayNSWindow.hPasses a displayIfNeeded message down the window’s view hierarchy, thus redrawing all views that need to be displayed, including the frame view that draws the border, title bar, and other peripheral elements.
- (void)displayIfNeeded
This method is useful when you want to modify some number of views and then display only the ones that were modified.
You rarely need to invoke this method. NSWindow objects normally record which of their views need display and display them automatically on each pass through the event loop.
– display– displayIfNeeded (NSView)– setNeedsDisplay: (NSView)– isAutodisplayNSWindow.hIndicates whether the window context should be updated when the screen profile changes or when the window moves to a different screen.
- (BOOL)displaysWhenScreenProfileChanges
YES when the window context should be updated when the screen profile changes or when the window moves to a different screen; NO otherwise.
The default value is NO.
NSWindow.hProvides the application’s Dock tile.
- (NSDockTile *)dockTile
The application’s Dock tile.
NSWindow.hBegins a dragging session.
- (void)dragImage:(NSImage *)image at:(NSPoint)imageLocation offset:(NSSize)pointerOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pasteboard source:(id)sourceObject slideBack:(BOOL)slideBack
The object to be dragged.
Location of the image’s bottom-left corner in the window’s coordinate system. It determines the placement of the dragged image under the pointer.
The pointer’s location relative to the mouse-down location. Not used in Mac OS X v10.4 and later.
The left-mouse down event that triggered the dragging operation.
The pasteboard that holds the data to be transfered to the destination.
The object serving as the controller of the dragging operation. It must conform to the NSDraggingSource informal protocol.
Specifies whether the drag image should slide back to imageLocation if it's rejected by the drag destination. Pass YES to specify slideback behavior, NO to specify otherwise.
This method should be invoked only from within a view’s implementation of the mouseDown: or mouseDragged: methods (which overrides the version defined in NSResponder class). Essentially the same as the NSView method of the same name, except that imageLocation is given in the NSWindow object’s base coordinate system.
NSWindow.hReturns the collection of drawers associated with the window.
- (NSArray *)drawers
The collection of drawers associated with the window.
NSDrawer.hReenables cursor rectangle management within the window after a disableCursorRects message.
- (void)enableCursorRects
NSWindow.hReenables the flushWindow method for the window after it was disabled through a previous disableFlushWindow message.
- (void)enableFlushWindow
NSWindow.h
Reenables the default button cell’s key equivalent, so it performs a click when the user presses Return (or Enter).
- (void)enableKeyEquivalentForDefaultButtonCell
NSWindow.hForces the field editor to give up its first responder status and prepares it for its next assignment.
- (void)endEditingFor:(id)object
The object that is using the window’s field editor.
If the field editor is the first responder, it’s made to resign that status even if its resignFirstResponder method returns NO. This registration forces the field editor to send a textDidEndEditing: message to its delegate. The field editor is then removed from the view hierarchy, its delegate is set to nil, and it’s emptied of any text it may contain.
This method is typically invoked by the object using the field editor when it’s finished. Other objects normally change the first responder by simply using makeFirstResponder:, which allows a field editor or other object to retain its first responder status if, for example, the user has entered an invalid value. The endEditingFor: method should be used only as a last resort if the field editor refuses to resign first responder status. Even in this case, you should always allow the field editor a chance to validate its text and take whatever other action it needs first. You can do this by first trying to make the NSWindow object the first responder:
if ([myWindow makeFirstResponder:myWindow]) { |
/* All fields are now valid; it’s safe to use fieldEditor:forObject: |
to claim the field editor. */ |
} |
else { |
/* Force first responder to resign. */ |
[myWindow endEditingFor:nil]; |
} |
NSWindow.hReturns the window’s field editor, creating it if requested.
- (NSText *)fieldEditor:(BOOL)createWhenNeeded forObject:(id)anObject
If YES, creates a field editor if one doesn’t exist; if NO, does not create a field editor.
A freshly created NSWindow object doesn’t have a field editor. After a field editor has been created for a window, the createWhenNeeded argument is ignored. By passing NO for createWhenNeeded and testing the return value, however, you can predicate an action on the existence of the field editor.
A text-displaying object for which the delegate (in windowWillReturnFieldEditor:toObject:) assigns a custom field editor. Pass nil to get the default field editor, which can be the NSWindow field editor or a custom field editor returned by the delegate.
Returns the field editor for the designated object (anObject) or, if anObject is nil, the default field editor. Returns nil if createFlag is NO and if the field editor doesn’t exist.
The field editor is a single NSTextView object that is shared among all the controls in a window for light text-editing needs. It is automatically instantiated when needed, and it can be used however your application sees fit. Typically, the field editor is used by simple text-bearing objects—for example, an NSTextField object uses its window’s field editor to display and manipulate text. The field editor can be shared by any number of objects, and so its state may be constantly changing. Therefore, it shouldn’t be used to display text that demands sophisticated layout (for this you should create a dedicated NSTextView object).
The field editor may be in use by some view object, so be sure to properly dissociate it from that object before actually using it yourself (the appropriate way to do this is illustrated in the description of endEditingFor:). Once you retrieve the field editor, you can insert it in the view hierarchy, set a delegate to interpret text events, and have it perform whatever editing is needed. Then, when it sends a textDidEndEditing: message to the delegate, you can get its text to display or store and remove the field editor using endEditingFor:.
The window’s delegate can substitute a custom field editor in place of the window’s field editor by implementing windowWillReturnFieldEditor:toObject:. The custom field editor can become the default editor (common to all text-displaying objects) or specific to a particular text-displaying object (anObject). The window sends this message to its delegate with itself and anObject as the arguments; if the delegate returns a non-nil value, the window returns that object instead of its field editor in fieldEditor:forObject:. However, note the following:
If the window’s delegate is identical to anObject, windowWillReturnFieldEditor:toObject: isn’t sent to the delegate.
The object returned by the delegate method, though it may become first responder, does not become the window's default field editor. Other objects continue to use the window's default field editor.
NSWindow.h
Returns the window’s first responder.
- (NSResponder *)firstResponder
The first responder.
The first responder is usually the first object in a responder chain to receive an event or action message. In most cases, the first responder is a view object in that the user selects or activates with the mouse or keyboard.
You can use the firstResponder method in custom subclasses of responder classes (NSWindow, NSApplication, NSView, and subclasses) to determine if an instance of the subclass is currently the first responder. You can also use it to help locate a text field that currently has first-responder status. For more on this subject, see “Event Handling Basics.“
– makeFirstResponder:– acceptsFirstResponder (NSResponder)NSWindow.hFlushes the window’s offscreen buffer to the screen if the window is buffered and flushing is enabled.
- (void)flushWindow
Does nothing for other display devices, such as a printer. This method is automatically invoked by the NSWindow display and displayIfNeeded methods and the corresponding NSView display and displayIfNeeded methods.
NSWindow.hFlushes the window’s offscreen buffer to the screen if flushing is enabled and if the last flushWindow message had no effect because flushing was disabled.
- (void)flushWindowIfNeeded
To avoid unnecessary flushing, use this method rather than flushWindow to flush an NSWindow object after flushing has been reenabled.
NSWindow.hReturns the window’s frame rectangle.
- (NSRect)frame
The frame rectangle of the window in screen coordinates.
NSWindow.h
Returns the name used to automatically save the window’s frame rectangle data in the defaults system, as set through setFrameAutosaveName:.
- (NSString *)frameAutosaveName
The name used to save the window’s frame rectangle automatically in the defaults system.
NSWindow.hReturns the window’s frame rectangle with a given content rectangle.
- (NSRect)frameRectForContentRect:(NSRect)windowContent
The content rectangle for the window expressed in screen coordinates.
The window’s frame rectangle, expressed in screen coordinates, with windowContent.
The window uses its current style mask in computing the frame rectangle. See “Constants” for a list of style mask values. The major advantage of this instance-method counterpart to frameRectForContentRect:styleMask: is that it allows you to take toolbars into account when converting between content and frame rectangles. (The toolbar is included in the frame rectangle but not the content rectangle.)
NSWindow.hProvides the graphics context associated with the window for the current thread.
- (NSGraphicsContext *)graphicsContext
The graphics context associated with the window for the current thread.
NSWindow.hReturns the window’s graphics state object.
- (NSInteger)gState
The graphics state object associated with the window.
This graphics state is used by default for all NSView objects in the window’s view hierarchy, but individual views can be made to use their own with the NSView method allocateGState.
NSWindow.h
Indicates whether the window’s depth limit can change to match the depth of the screen it’s on.
- (BOOL)hasDynamicDepthLimit
YES when the window has a dynamic depth limit; NO otherwise.
NSWindow.hIndicates whether the window has a shadow.
- (BOOL)hasShadow
YES when the window has a shadow; NO otherwise.
NSWindow.h
Indicates whether the window is removed from the screen when its application becomes inactive.
- (BOOL)hidesOnDeactivate
YES if the window is removed from the screen when its application is deactivated; NO if it remains onscreen.
The default for NSWindow is NO; the default for NSPanel is YES.
NSWindow.hIndicates whether the window is transparent to mouse events.
- (BOOL)ignoresMouseEvents
YES when the window is transparent to mouse events; NO otherwise.
NSWindow.hReturns view that’s made first responder the first time the window is placed onscreen.
- (NSView *)initialFirstResponder
The view that’s made first responder the first time the window is placed onscreen.
NSWindow.hInitializes the window with the specified values.
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
Location and size of the window’s content area in screen coordinates. Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.
The window’s style. Either it can be NSBorderlessWindowMask, or it can contain any of the options described in “Constants,” combined using the C bitwise OR operator. Borderless windows display none of the usual peripheral elements and are generally useful only for display or caching purposes; you should normally not need to create them. Also, note that a window’s style mask should include NSTitledWindowMask if it includes any of the others.
Specifies how the drawing done in the window is buffered by the window device, and possible values are described in “Constants.”
Specifies whether the window server creates a window device for the window immediately. When YES, the window server defers creating the window device until the window is moved onscreen. All display messages sent to the window or its views are postponed until the window is created, just before it’s moved onscreen.
The initialized window.
This method is the designated initializer for the NSWindow class.
Deferring the creation of the window improves launch time and minimizes the virtual memory load on the window server.
The new window creates a view to be its default content view. You can replace it with your own object by using the setContentView: method.
NSWindow.h
Initializes an allocated window with the specified values.
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
Location and size of the window’s content area in screen coordinates. Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.
The window’s style. It can be either NSBorderlessWindowMask, or it can contain any of the options described in “Constants,” combined using the C bitwise OR operator. Borderless windows display none of the usual peripheral elements and are generally useful only for display or caching purposes; you should normally not need to create them. Also, note that a window’s style mask should include NSTitledWindowMask if it includes any of the others.
Specifies how the drawing done in the window is buffered by the window device; possible values are described in “Constants.”
Specifies whether the window server creates a window device for the window immediately. When YES, the window server defers creating the window device until the window is moved onscreen. All display messages sent to the window or its views are postponed until the window is created, just before it’s moved onscreen.
Specifies where the window’s content rectangle is drawn if the window is to be drawn in a screen other than the main screen. The content rectangle is drawn relative to the bottom-left corner of screen. When nil, the content rectangle is drawn on the main screen.
The initialized window.
The main screen is the one that contains the current key window or, if there is no key window, the one that contains the main menu. If there’s neither a key window nor a main menu (if there’s no active application), the main screen is the one where the origin of the screen coordinate system is located.
NSWindow.hReturns a Cocoa window created from a Carbon window.
- (NSWindow *)initWithWindowRef:(void *)carbonWindowRef
The Carbon WindowRef object to use to create the Cocoa window.
A Cocoa window created from carbonWindowRef.
For more information on Carbon-Cocoa integration, see Using a Carbon User Interface in a Cocoa Application in Carbon-Cocoa Integration Guide.
For historical reasons, contrary to normal memory management policy initWithWindowRef: does not retain windowRef. It is therefore recommended that you make sure you retain windowRef before calling this method. If windowRef is still valid when the Cocoa window is deallocated, the Cocoa window will release it.
NSWindow.hMarks as invalid the cursor rectangles of a given NSView object in the window’s view hierarchy, so they’ll be set up again when the window becomes key (or immediately if the window is key).
- (void)invalidateCursorRectsForView:(NSView *)view
The view in the window’s view hierarchy.
– resetCursorRects– resetCursorRects (NSView)NSWindow.hInvalidates the window shadow so that it is recomputed based on the current window shape.
- (void)invalidateShadow
NSWindow.h
Indicates whether the window automatically displays views that need to be displayed.
- (BOOL)isAutodisplay
YES when the window automatically displays views that need to be displayed; NO otherwise.
Automatic display typically occurs on each pass through the event loop.
NSWindow.hIndicates whether the window’s document has been edited.
- (BOOL)isDocumentEdited
YES when the window’s document has been edited; NO otherwise.
Initially, by default, NSWindow objects are in the “not edited” state.
NSWindow.hIndicates whether the window is excluded from the application’s Windows menu.
- (BOOL)isExcludedFromWindowsMenu
YES when the window is excluded from the Windows menu; NO otherwise.
The default initial setting is NO.
NSWindow.h
Indicates whether the window’s flushing ability is disabled.
- (BOOL)isFlushWindowDisabled
YES when the window’s flushing ability has been disabled; NO otherwise.
NSWindow.hIndicates whether the window is the key window for the application.
- (BOOL)isKeyWindow
YES if the window is the key window for the application; NO otherwise.
NSWindow.hIndicates whether the window is the application’s main window.
- (BOOL)isMainWindow
YES when the window is the main window for the application, NO otherwise.
NSWindow.h
Indicates whether the window is minimized.
- (BOOL)isMiniaturized
YES if the window is minimized, otherwise NO.
A minimized window is removed from the screen and replaced by a image, icon, or button that represents it, called the counterpart.
NSWindow.hIndicates whether the window is movable by clicking and dragging anywhere in its background.
- (BOOL)isMovableByWindowBackground
YES when the window is movable by clicking and dragging anywhere in its background; NO otherwise.
A window with a style mask of NSTexturedBackgroundWindowMask is movable by background by default. Sheets and drawers cannot be movable by window background.
NSWindow.hIndicates whether the window device the window manages is freed when it’s removed from the screen list.
- (BOOL)isOneShot
YES when the window’s window device is freed when it’s removed from the screen list; NO otherwise.
The default is NO.
NSWindow.hIndicates whether the window is opaque.
- (BOOL)isOpaque
YES when the window is opaque; NO otherwise.
The default is YES.
NSWindow.h
Indicates whether the window is released when it receives the close message.
- (BOOL)isReleasedWhenClosed
YES if the window is automatically released after being closed; NO if it’s simply removed from the screen.
The default for NSWindow is YES; the default for NSPanel is NO. Release when closed, however, is ignored for windows owned by window controllers.
NSWindow.hIndicates whether the window has ever run as a modal sheet.
- (BOOL)isSheet
YES if the window has ever run as a modal sheet, otherwise NO.
Sheets are created using the NSPanel subclass.
NSWindow.hIndicates whether the window is visible onscreen (even when It’s obscured by other windows).
- (BOOL)isVisible
YES when the window is onscreen (even if it’s obscured by other windows); NO otherwise.
– visibleRect (NSView)NSWindow.hReturns a Boolean value that indicates whether the window is in a zoomed state.
- (BOOL)isZoomed
YES if the window is in a zoomed state, otherwise NO.
The zoomed state of the window is determined using the following steps:
If the delegate or the window class implements windowWillUseStandardFrame:defaultFrame:, it is invoked to obtain the zoomed frame of the window. The result of isZoomed is then determined by whether or not the current window frame is equal to the zoomed frame.
If the neither the delegate nor the window class implements windowWillUseStandardFrame:defaultFrame:, a default frame that nearly fits the screen is chosen. If the delegate or window class implements windowWillResize:toSize:, it is invoked to validate the proposed zoomed frame. Once the zoomed frame is validated, the result of isZoomed is determined by whether or not the current window frame is equal to the zoomed frame.
NSWindow.hHandles a given keyboard event that may need to be interpreted as changing the key view or triggering a keyboard equivalent.
- (void)keyDown:(NSEvent *)event
The keyboard event to process.
– selectNextKeyView:– nextKeyView (NSView)– performMnemonic: (NSView)NSWindow.hReturns the direction the window is currently using to change the key view.
- (NSSelectionDirection)keyViewSelectionDirection
The direction the window is using to change the key view.
This direction can be one of the values described in “Constants.”
NSWindow.hReturns the window level of the window.
- (NSInteger)level
The window level.
See “Constants” for a list of possible values.
NSWindow.hAttempts to make a given responder the first responder for the window.
- (BOOL)makeFirstResponder:(NSResponder *)responder
The responder to set as the window’s first responder. nil makes the window its first responder.
YES when the operation is successful; NO otherwise.
If responder isn’t already the first responder, this method first sends a resignFirstResponder message to the object that is the first responder. If that object refuses to resign, it remains the first responder, and this method immediately returns NO. If the current first responder resigns, this method sends a becomeFirstResponder message to responder. If responder does not accept first responder status, the NSWindow object becomes first responder; in this case, the method returns YES even if responder refuses first responder status.
If responder is nil, this method still sends resignFirstResponder to the current first responder. If the current first responder refuses to resign, it remains the first responder and this method immediately returns NO. If the current first responder returns YES from resignFirstResponder, the window is made its own first responder and this method returns YES.
The Application Kit framework uses this method to alter the first responder in response to mouse-down events; you can also use it to explicitly set the first responder from within your program. The responder object is typically an NSView object in the window’s view hierarchy. If this method is called explicitly, first send acceptsFirstResponder to responder, and do not call makeFirstResponder: if acceptsFirstResponder returns NO.
Use setInitialFirstResponder: to the set the first responder to be used when the window is brought onscreen for the first time.
– becomeFirstResponder (NSResponder)– resignFirstResponder (NSResponder)NSWindow.hMoves the window to the front of the screen list, within its level, and makes it the key window; that is, it shows the window.
- (void)makeKeyAndOrderFront:(id)sender
The message’s sender.
NSWindow.hMakes the window the key window.
- (void)makeKeyWindow
NSWindow.hMakes the window the main window.
- (void)makeMainWindow
NSWindow.hReturns the maximum size to which the window’s frame (including its title bar) can be sized.
- (NSSize)maxSize
The maximum size to which the window’s frame (including its title bar) can be sized either by the user or by the setFrame... methods other than setFrame:display:.
NSWindow.hRemoves the window from the screen list and displays the minimized window in the Dock.
- (void)miniaturize:(id)sender
The message’s sender.
NSWindow.h
Returns the custom miniaturized window image of the window.
- (NSImage *)miniwindowImage
The custom miniaturized window image.
The miniaturized window image is the image displayed in the Dock when the window is minimized. If you did not assign a custom image to the window, this method returns nil.
NSWindow.h
Returns the title displayed in the window’s minimized window.
- (NSString *)miniwindowTitle
The title displayed in the window’s minimized window.
NSWindow.hReturns the minimum size to which the window’s frame (including its title bar) can be sized.
- (NSSize)minSize
The minimum size to which the window’s frame (including its title bar) can be sized either by the user or by the setFrame... methods other than setFrame:display:.
NSWindow.hReturns the current location of the pointer reckoned in the window’s base coordinate system.
- (NSPoint)mouseLocationOutsideOfEventStream
The current location of the pointer reckoned in the window’s base coordinate system, regardless of the current event being handled or of any events pending.
For the same information in screen coordinates, use NSEvent's mouseLocation.
– currentEvent (NSApplication)NSWindow.h
Returns the next event matching a given mask.
- (NSEvent *)nextEventMatchingMask:(NSUInteger)eventMask
The mask that the event to return must match. Events with nonmatching masks are removed from the queue. See discardEventsMatchingMask:beforeEvent: in NSApplication for the list of mask values.
The next event whose mask matches eventMask; nil when no matching event was found.
This method sends the message nextEventMatchingMask:eventMask untilDate:[NSDate distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:YES to the application (NSApp).
– nextEventMatchingMask:untilDate:inMode:dequeue: (NSApplication)NSWindow.h
Forwards the message to the global NSApplication object, NSApp.
- (NSEvent *)nextEventMatchingMask:(NSUInteger)eventMask untilDate:(NSDate *)expirationDate inMode:(NSString *)runLoopMode dequeue:(BOOL)dequeue
The mask that the event to return must match.
The date until which to wait for events.
The run loop mode to use while waiting for events
YES to remove the returned event from the event queue; NO to leave the returned event in the queue.
The next event whose mask matches eventMask; nil when no matching event was found.
– nextEventMatchingMask:untilDate:inMode:dequeue: (NSApplication)NSWindow.hMoves the window to the back of its level in the screen list, without changing either the key window or the main window.
- (void)orderBack:(id)sender
Message originator.
NSWindow.hMoves the window to the front of its level in the screen list, without changing either the key window or the main window.
- (void)orderFront:(id)sender
The message’s sender.
NSWindow.h
Moves the window to the front of its level, even if its application isn’t active, without changing either the key window or the main window.
- (void)orderFrontRegardless
The message’s sender.
Normally an NSWindow object can’t be moved in front of the key window unless it and the key window are in the same application. You should rarely need to invoke this method; it’s designed to be used when applications are cooperating in such a way that an active application (with the key window) is using another application to display data.
NSWindow.hRemoves the window from the screen list, which hides the window.
- (void)orderOut:(id)sender
The message’s sender.
If the window is the key or main window, the NSWindow object immediately behind it is made key or main in its place. Calling the orderOut: method causes the window to be removed from the screen, but does not cause it to be released. See the close method for information on when a window is released.
NSWindow.hRepositions the window’s window device in the window server’s screen list.
- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber
NSWindowOut: The window is removed from the screen list and otherWindowNumber is ignored.
NSWindowAbove: The window is ordered immediately in front of the window whose window number is otherWindowNumber
NSWindowBelow: The window is placed immediately behind the window represented by otherWindowNumber.
The number of the window the window is to be placed in front of or behind. Pass 0 to place the window in front of (when orderingMode is NSWindowAbove) or behind (when orderingMode is NSWindowBelow) all other windows in its level.
NSWindow.hReturns the parent window to which the window is attached as a child.
- (NSWindow *)parentWindow
The window to which the window is attached as a child.
NSWindow.hThis action method simulates the user clicking the close button by momentarily highlighting the button and then closing the window.
- (void)performClose:(id)sender
The message’s sender.
If the window’s delegate or the window itself implements windowShouldClose:, that message is sent with the window as the argument. (Only one such message is sent; if both the delegate and the NSWindow object implement the method, only the delegate receives the message.) If the windowShouldClose: method returns NO, the window isn’t closed. If it returns YES, or if it isn’t implemented, performClose: invokes the close method to close the window.
If the window doesn’t have a close button or can’t be closed (for example, if the delegate replies NO to a windowShouldClose: message), the system emits the alert sound.
NSWindow.hSimulates the user clicking the minimize button by momentarily highlighting the button, then minimizing the window.
- (void)performMiniaturize:(id)sender
The message’s sender.
If the window doesn’t have a minimize button or can’t be minimized for some reason, the system emits the alert sound.
NSWindow.hThis action method simulates the user clicking the zoom box by momentarily highlighting the button and then zooming the window.
- (void)performZoom:(id)sender
The object sending the message.
If the window doesn’t have a zoom box or can’t be zoomed for some reason, the computer beeps.
NSWindow.h
Forwards the message to the global NSApplication object, NSApp.
- (void)postEvent:(NSEvent *)event atStart:(BOOL)atStart
The event to add to the window’s event queue.
YES to place the event in the front of the queue; NO to place it in the back.
NSWindow.hIndicates the preferred location for the window’s backing store.
- (NSWindowBackingLocation)preferredBackingLocation
The preferred location for the window’s backing store. See “Constants” for possible values.
NSWindow.hReturns a Boolean value that indicates whether the window tries to optimize live resize operations by preserving the content of views that have not changed.
- (BOOL)preservesContentDuringLiveResize
YES if the window tries to optimize live resize operations by preserving the content of views that have not moved; NO otherwise.
When live-resize optimization is active, the window redraws only those views that moved (or do not support this optimization) during a live resize operation.
See preservesContentDuringLiveResize in NSView for additional information on how to support this optimization.
NSWindow.hThis action method runs the Print panel, and if the user chooses an option other than canceling, prints the window (its frame view and all subviews).
- (void)print:(id)sender
The message’s sender.
NSWindow.hMarks the key view loop as dirty and in need of recalculation.
- (void)recalculateKeyViewLoop
The key view loop is actually recalculated the next time someone requests the next or previous key view of the window. The recalculated loop is based on the geometric order of the views in the window.
If you do not want to maintain the key view loop of your window manually, you can use this method to do it for you. When it is first loaded, NSWindow calls this method automatically if your window does not have a key view loop already established. If you add or remove views later, you can call this method manually to update the window’s key view loop. You can also call setAutorecalculatesKeyViewLoop: to have the window recalculate the loop automatically.
NSWindow.hRegisters a give set of pasteboard types as the pasteboard types the window will accept as the destination of an image-dragging session.
- (void)registerForDraggedTypes:(NSArray *)pasteboardTypes
An array of the pasteboard types the window will accept as the destination of an image-dragging session.
Registering an NSWindow object for dragged types automatically makes it a candidate destination object for a dragging session. NSWindow has a default implementation for many of the methods in the NSDraggingDestination informal protocol. The default implementation forwards each message to the delegate if the delegate responds to the selector of the message. The messages forwarded this way are draggingEntered:, draggingUpdated:, draggingExited:, prepareForDragOperation:, performDragOperation:, and concludeDragOperation:.
NSWindow.hDetaches a given child window from the window.
- (void)removeChildWindow:(NSWindow *)childWindow
The child window to detach.
NSWindow.hReturns the pathname of the file the window represents.
- (NSString *)representedFilename
The path to the file of the window’s represented file.
NSWindow.hProvides the URL of the file the window represents.
- (NSURL *)representedURL
The URL for the file the window represents.
When the URL specifies a path, the window shows an icon in its title bar, as described in Table 1.
Filepath | Document icon |
|---|---|
Empty | None. |
Specifies a nonexistent file | Generic. |
Specifies an existent file | Specific for the file’s type. |
You can customize the file icon in the tile bar with the following code:
[[<window> standardWindowButton:NSWindowDocumentIconButton] setImage:<image>] |
When the URL identifies an existing file, the window’s title offers a pop-up menu showing the path components of the URL. (The user displays this menu by Command-clicking the title.) The behavior and contents of this menu can be controlled with window:shouldPopUpDocumentPathMenu:.
NSWindow.hClears the window’s cursor rectangles and the cursor rectangles of the NSView objects in its view hierarchy.
- (void)resetCursorRects
Invokes discardCursorRects to clear the window’s cursor rectangles, then sends resetCursorRects to every NSView object in the window’s view hierarchy.
This method is typically invoked by the NSApplication object when it detects that the key window’s cursor rectangles are invalid. In program code, it’s more efficient to invoke invalidateCursorRectsForView:.
NSWindow.hInvoked automatically when the window resigns key window status; never invoke this method directly.
- (void)resignKeyWindow
This method sends resignKeyWindow to the window’s first responder, sends windowDidResignKey: to the window’s delegate, and posts an NSWindowDidResignKeyNotification to the default notification center.
NSWindow.h
Invoked automatically when the window resigns main window status; never invoke this method directly.
- (void)resignMainWindow
This method sends windowDidResignMain: to the window’s delegate and posts an NSWindowDidResignMainNotification to the default notification center.
NSWindow.h
Returns the flags field of the event record for the mouse-down event that initiated the resizing session.
- (NSInteger)resizeFlags
A mask indicating which of the modifier keys was held down when the mouse-down event occurred. The flags are listed in NSEvent object’s modifierFlags method description.
This method is valid only while the window is being resized
You can use this method to constrain the direction or amount of resizing. Because of its limited validity, this method should only be invoked from within an implementation of the delegate method windowWillResize:toSize:.
NSWindow.h
Returns the window’s resizing increments.
- (NSSize)resizeIncrements
The window’s resizing increments.
NSWindow.hSplices the window’s cached image rectangles, if any, back into its raster image (and buffer if it has one), undoing the effect of any drawing performed within those areas since they were established using cacheImageInRect:.
- (void)restoreCachedImage
You must invoke flushWindow after this method to guarantee proper redisplay. An NSWindow object automatically discards its cached image rectangles when it displays.
NSWindow.hThe action method for the “Customize Toolbar…” menu item.
- (void)runToolbarCustomizationPalette:(id)sender
The message’s sender.
See the NSToolbar class description for additional information.
NSWindow.hSaves the window’s frame rectangle in the user defaults system under a given name.
- (void)saveFrameUsingName:(NSString *)frameName
The name under which the frame is to be saved.
With the companion method setFrameUsingName:, you can save and reset an NSWindow object’s frame over various launches of an application. The default is owned by the application and stored under the name "NSWindow Frame frameName". See NSUserDefaults for more information.
NSWindow.hReturns the screen the window is on.
- (NSScreen *)screen
The screen where most of the window is on; nil when the window is offscreen.
When the window is partly on one screen and partly on another, the screen where most of it lies is returned.
NSWindow.hMakes key the view that follows the given view.
- (void)selectKeyViewFollowingView:(NSView *)referenceView
The view whose following view in the key view loop is sought.
Sends the nextValidKeyView message to referenceView and, if that message returns an NSView object, invokes makeFirstResponder: with the returned object.
NSWindow.hMakes key the view that precedes the given view.
- (void)selectKeyViewPrecedingView:(NSView *)referenceView
The view whose preceding view in the key view loop is sought.
Sends the previousValidKeyView message to referenceView and, if that message returns an NSView object, invokes makeFirstResponder: with the returned object.
NSWindow.h
This action method searches for a candidate next key view and, if it finds one, invokes makeFirstResponder: to establish it as the first responder.
- (void)selectNextKeyView:(id)sender
The message’s sender.
The candidate is one of the following (searched for in this order):
The current first responder’s next valid key view, as returned by the nextValidKeyView method of NSView
The object designated as the window’s initial first responder (using setInitialFirstResponder:) if it returns YES to an acceptsFirstResponder message
Otherwise, the initial first responder’s next valid key view, which may end up being nil
NSWindow.h
This action method searches for a candidate previous key view and, if it finds one, invokes makeFirstResponder: to establish it as the first responder.
- (void)selectPreviousKeyView:(id)sender
The message’s sender.
The candidate is one of the following (searched for in this order):
The current first responder’s previous valid key view, as returned by the previousValidKeyView method of NSView
The object designated as the window’s initial first responder (using setInitialFirstResponder:) if it returns YES to an acceptsFirstResponder message
Otherwise, the initial first responder’s previous valid key view, which may end up being nil
NSWindow.hThis action method dispatches mouse and keyboard events sent to the window by the NSApplication object.
- (void)sendEvent:(NSEvent *)event
The mouse or keyboard event to process.
Never invoke this method directly. A right mouse-down event in a window of an inactive application is not delivered to the corresponding NSWindow object. It is instead delivered to the NSApplication object through a sendEvent: message with a window number of 0.
NSWindow.hSpecifies whether the window is to accept mouse-moved events.
- (void)setAcceptsMouseMovedEvents:(BOOL)acceptMouseMovedEvents
YES to have the window accept mouse-moved events (and to distribute them to its responders); NO to not accept such events.
NSWindow.hSpecifies whether the window can display tooltips even when the application is in the background.
- (void)setAllowsToolTipsWhenApplicationIsInactive:(BOOL)allowTooltipsWhenAppInactive
YES to have the window display tooltips even when its application is inactive; NO to suppress tooltip display when inactive.
The message does not take effect until the window changes to an active state.
Note: Enabling tooltips in an inactive application will cause the application to do work any time the pointer passes over the window, thus degrading system performance.
NSWindow.hApplies a given alpha value to the entire window.
- (void)setAlphaValue:(CGFloat)windowAlpha
The alpha value to apply.
NSWindow.hSets the window’s aspect ratio, which constrains the size of its frame rectangle to integral multiples of this ratio when the user resizes it.
- (void)setAspectRatio:(NSSize)aspectRatio
The aspect ratio to be maintained during resizing actions.
An NSWindow object’s aspect ratio and its resize increments are mutually exclusive attributes. In fact, setting one attribute cancels the setting of the other. For example, to cancel an established aspect ratio setting for an NSWindow object, you send it a setResizeIncrements: message with the width and height set to 1.0:
[myWindow setResizeIncrements:NSMakeSize(1.0,1.0)]; |
The setContentAspectRatio: method takes precedence over this method.
NSWindow.hSpecifies whether the window is to automatically display the views that are marked as needing it.
- (void)setAutodisplay:(BOOL)autodisplay
YES to have the window automatically display views that need to be displayed; NO to specify otherwise.
If autodisplay is NO, the window or its views must be explicitly displayed.
NSWindow.hSpecifies whether the window calculates the thickness of a given border automatically.
- (void)setAutorecalculatesContentBorderThickness:(BOOL)autorecalculateContentBorderThickness forEdge:(NSRectEdge)edge
YES to have the window calculate the thickness of edge automatically; NO otherwise.
Border whose thickness autorecalculation status to set:
NSMaxYEdge: Top border.
NSMinYEdge: Bottom border.
Turning off a border’s autorecalculation status sets its border thickness to 0.0.
NSWindow.hSpecifies whether to recalculate the key view loop automatically when views are added or removed.
- (void)setAutorecalculatesKeyViewLoop:(BOOL)autorecalculateKeyViewLoop
YES to recalculate the key view loop automatically; NO otherwise.
If autorecalculateKeyViewLoop is NO, the client code must update the key view loop manually or call recalculateKeyViewLoop to have the window recalculate it.
NSWindow.h
Sets the window’s background color to the given color.
- (void)setBackgroundColor:(NSColor *)color
Color to set as the window’s background color.
NSWindow.hSets the window’s backing store type to a given type.
- (void)setBackingType:(NSBackingStoreType)backingType
The backing store type to set.
The valid backing store types are described in “Constants.”
This method can be used only to switch a buffered window to retained or vice versa; you can’t change the backing type to or from nonretained after initializing an NSWindow object (an error is generated if you attempt to do so).
– backingType– initWithContentRect:styleMask:backing:defer:– initWithContentRect:styleMask:backing:defer:screen:NSWindow.hSpecifies whether the window can be displayed at the login window.
- (void)setCanBecomeVisibleWithoutLogin:(BOOL)canBecomeVisibleWithoutLogin
YES to allow the window to be displayed at the login window; NO to prevent this behavior.
NSWindow.hSpecifies whether the window can be hidden when its application becomes hidden (during execution of the NSApplication hide: method).
- (void)setCanHide:(BOOL)canHide
YES specifies that the window can be hidden when its application becomes hidden; NO specifies otherwise.
NSWindow.hSpecifies the window’s behavior in window collections.
- (void)setCollectionBehavior:(NSWindowCollectionBehavior)collectionBehavior;
The collection behavior identifier to set.
NSWindow.hSets the aspect ratio (height in relation to width) of the window’s content view, constraining the dimensions of its content rectangle to integral multiples of that ratio when the user resizes it.
- (void)setContentAspectRatio:(NSSize)contentAspectRatio
The aspect ratio of the window’s content view.
You can set a window’s content view to any size programmatically, regardless of its aspect ratio. This method takes precedence over setAspectRatio:.
NSWindow.hSpecifies the thickness of a given border of the window.
- (void)setContentBorderThickness:(CGFloat)borderThickness forEdge:(NSRectEdge)edge
Thickness for edge, in points.
Border whose thickness to set:
NSMaxYEdge: Top border.
NSMinYEdge: Bottom border.
NSWindow.hSets the maximum size of the window’s content view in the window’s base coordinate system.
- (void)setContentMaxSize:(NSSize)contentMaxSize
The maximum size of the window’s content view in the window’s base coordinate system.
The maximum size constraint is enforced for resizing by the user as well as for the setContentSize: method and the setFrame... methods other than setFrame:display:. This method takes precedence over setMaxSize:.
NSWindow.hSets the minimum size of the window’s content view in the window’s base coordinate system.
- (void)setContentMinSize:(NSSize)contentMinSize
The minimum size of the window’s content view in the window’s base coordinate system.
The minimum size constraint is enforced for resizing by the user as well as for the setContentSize: method and the setFrame... methods other than setFrame:display:. This method takes precedence over setMinSize:.
NSWindow.hRestricts the user’s ability to resize the window so the width and height of its content view change by multiples of width and height increments.
- (void)setContentResizeIncrements:(NSSize)contentResizeIncrements
The content-view resizing increments to set.
As the user resizer the window, the size of its content view changes by integral multiples of contentResizeIncrements.width and contentResizeIncrements.height. However, you can set a window’s size to any width and height programmatically. This method takes precedence over setResizeIncrements:.
NSWindow.h
Sets the size of the window’s content view to a given size, which is expressed in the window’s base coordinate system.
- (void)setContentSize:(NSSize)size
The new size of the window’s content view in the window’s base coordinate system.
This size in turn alters the size of the NSWindow object itself. Note that the window server limits window sizes to 10,000; if necessary, be sure to limit aSize relative to the frame rectangle.
NSWindow.hMakes a given view the window’s content view.
- (void)setContentView:(NSView *)view
View that is to become the window’s content view.
The window retains the new content view and owns it thereafter. The view object is resized to fit precisely within the content area of the window. You can modify the content view’s coordinate system through its bounds rectangle, but can’t alter its frame rectangle (that is, its size or location) directly.
This method causes the old content view to be released; if you plan to reuse it, be sure to retain it before sending this message and to release it as appropriate when adding it to another NSWindow object or NSView.
NSWindow.hMakes the key equivalent of button cell the Return (or Enter) key, so when the user presses Return that button performs as if clicked.
- (void)setDefaultButtonCell:(NSButtonCell *)defaultButtonCell
The button cell to perform as if clicked when the window receives a Return (or Enter) key event.
– defaultButtonCell– disableKeyEquivalentForDefaultButtonCell– enableKeyEquivalentForDefaultButtonCellNSWindow.h
Sets the window’s delegate to a given object or removes an existing delegate.
- (void)setDelegate:(id)delegate
The delegate for the window. Pass nil to remove an existing delegate.
An NSWindow object’s delegate is inserted in the responder chain after the window itself and is informed of various actions by the window through delegation messages.
– delegate– tryToPerform:with:– sendAction:to:from: (NSApplication)NSWindow.hSets the depth limit of the window to a given limit.
- (void)setDepthLimit:(NSWindowDepth)depthLimit
The depth limit to set.
The NSBestDepth function provides the best depth limit based on a set of parameters.
Passing a value of 0 for depthLimit sets the depth limit to the window’s default depth limit. A depth limit of 0 can be useful for reverting an NSWindow object to its initial depth.
NSWindow.hSpecifies whether the window context should be updated when the screen profile changes.
- (void)setDisplaysWhenScreenProfileChanges:(BOOL)displaysWhenScreenProfileChanges
YES specifies that the window context should be changed in these situations:
A majority of the window is moved to a different screen whose profile is different than the previous screen.
The ColorSync profile of the current screen changes.
NO specifies that the screen profile information for the window context doesn’t change.
After the window context is updated, the window is told to display itself. If you need to update offscreen caches for the window, you should register to receive the NSWindowDidChangeScreenProfileNotification notification.
NSWindow.hSpecifies whether the window’s document has been edited.
- (void)setDocumentEdited:(BOOL)documentEdited
YES to specify that the window’s document has been edited; NO to specify otherwise.
You should send setDocumentEdited:YES to an NSWindow object every time the window’s document changes in such a way that it needs to be saved. Conversely, when the document is saved, you should send setDocumentEdited:NO. Then, before closing the window you can use isDocumentEdited to determine whether to allow the user a chance to save the document.
NSWindow.hSets whether the window changes its depth to match the depth of the screen it’s on, or the depth of the deepest screen when it spans multiple screens.
- (void)setDynamicDepthLimit:(BOOL)dynamicDepthLimit
YES specifies a dynamic depth limit; NO specifies otherwise.
When dynamicDepthLimit is NO, the window uses either its preset depth limit or the default depth limit. A different, and nondynamic, depth limit can be set with the setDepthLimit: method.
NSWindow.hSpecifies whether the window’s title is omitted from the application’s Windows menu.
- (void)setExcludedFromWindowsMenu:(BOOL)excludedFromWindowsMenu
YES to specify that the window is to be omitted from the application’s Windows menu; NO to specify otherwise.
NSWindow.hSets the origin and size of the window’s frame rectangle according to a given frame rectangle, thereby setting its position and size onscreen.
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews
The frame rectangle for the window.
Specifies whether the window redraws the views that need to be displayed. When YES the window sends a displayIfNeeded message down its view hierarchy, thus redrawing all views.
Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.
NSWindow.hSets the origin and size of the window’s frame rectangle, with optional animation, according to a given frame rectangle, thereby setting its position and size onscreen.
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews animate:(BOOL)performAnimation
The frame rectangle for the window.
Specifies whether the window redraws the views that need to be displayed. When YES the window sends a displayIfNeeded message down its view hierarchy, thus redrawing all views.
Specifies whether the window performs a smooth resize. YES to perform the animation, whose duration is specified by animationResizeTime:.
NSWindow.hSets the name used to automatically save the window’s frame rectangle in the defaults system to a given name.
- (BOOL)setFrameAutosaveName:(NSString *)frameName
The name under which the frame is to be saved.
YES when the frame name is set successfully; NO when frameName is being used as an autosave name by another NSWindow object in the application (in which case the window’s old name remains in effect).
If frameName isn’t the empty string (@""), the window’s frame is saved as a user default (as described in saveFrameUsingName:) each time the frame changes.
When the window has an autosave name, its frame data is written whenever the frame rectangle changes.
If there is a frame rectangle previously stored for frameName in the user defaults, the window’s frame is set to this frame rectangle. That is, when you call this method with a previously used frameName, the window picks up the previously saved setting. For example, if you call setFrameAutosaveName: for a window that is already onscreen, this method could cause the window to move to a different screen location. For this reason, it is generally better to call this method before the window is visible on screen.
Keep in mind that a window controller may change the window’s position when it displays it if window cascading is turned on. To preclude the window controller from changing a window’s position from the one saved in the defaults system, you must send setShouldCascadeWindows:NO to the window controller.
NSWindow.h
Sets the window’s frame rectangle from a given string representation.
- (void)setFrameFromString:(NSString *)frameString
A string representation of a frame rectangle, previously creating using stringWithSavedFrame.
The frame is constrained according to the window’s minimum and maximum size settings. This method causes a windowWillResize:toSize: message to be sent to the delegate.
NSWindow.hPositions the bottom-left corner of the window’s frame rectangle at a given point in screen coordinates.
- (void)setFrameOrigin:(NSPoint)point
The new position of the window’s bottom-left corner in screen coordinates.
Note that the window server limits window position coordinates to ±16,000.
NSWindow.hPositions the top-left corner of the window’s frame rectangle at a given point in screen coordinates.
- (void)setFrameTopLeftPoint:(NSPoint)point
The new position of the window’s top-left corner in screen coordinates.
Note that the window server limits window position coordinates to ±16,000; if necessary, adjust aPoint relative to the window’s lower-left corner to account for this limit.
NSWindow.hSets the window’s frame rectangle by reading the rectangle data stored under a given name from the defaults system.
- (BOOL)setFrameUsingName:(NSString *)frameName
The name of the frame to read.
YES when frameName is read and the frame is set successfully; NO otherwise.
The frame is constrained according to the window’s minimum and maximum size settings. This method causes a windowWillResize:toSize: message to be sent to the delegate.
NSWindow.hSets the window’s frame rectangle by reading the rectangle data stored under a given name from the defaults system. Can operate on nonresizable windows.
- (BOOL)setFrameUsingName:(NSString *)frameName force:(BOOL)force
The name of the frame to read.
YES to use setFrameUsingName: on a nonresizable window; NO to fail on a nonresizable window.
YES when frameName is read and the frame is set successfully; NO otherwise.
NSWindow.hSpecifies whether the window has a shadow.
- (void)setHasShadow:(BOOL)hasShadow
YES specifies that the window has a shadow; NO specifies otherwise.
If the shadow setting changes, the window shadow is invalidated, forcing the window shadow to be recomputed.
NSWindow.h
Specifies whether the window is removed from the screen when the application is inactive.
- (void)setHidesOnDeactivate:(BOOL)hideOnDeactivate
NSWindow.hSpecifies whether the window is transparent to mouse clicks and other mouse events, allowing overlay windows.
- (void)setIgnoresMouseEvents:(BOOL)ignoreMouseEvents
NSWindow.hSets a given view as the one that’s made first responder (also called the key view) the first time the window is placed onscreen.
- (void)setInitialFirstResponder:(NSView *)view
The view to make first responder the first time the window is placed onscreen.
NSWindow.hSets the window’s window level to a given level.
- (void)setLevel:(NSInteger)windowLevel
The window level to set.
Some useful predefined values, ordered from lowest to highest, are described in “Constants.”
Each level in the list groups windows within it in front of those in all preceding groups. Floating windows, for example, appear in front of all normal-level windows. When a window enters a new level, it’s ordered in front of all its peers in that level.
The constant NSTornOffMenuWindowLevel is preferable to its synonym, NSSubmenuWindowLevel.
NSWindow.hSets the maximum size to which the window’s frame (including its title bar) can be sized.
- (void)setMaxSize:(NSSize)maxFrameSize
The maximum size of the window’s frame.
The maximum size constraint is enforced for resizing by the user as well as for the setFrame... methods other than setFrame:display:. Note that the window server limits window sizes to 10,000.
The default maximum size of a window is {FLT_MAX, FLT_MAX} (FLT_MAX is defined in /usr/include/float.h). Once the maximum size of a window has been set, there is no way to reset it other than specifying this default maximum size.
The setContentMaxSize: method takes precedence over this method.
NSWindow.hSets the window’s custom minimized window image to a given image.
- (void)setMiniwindowImage:(NSImage *)miniwindowImage
Image to set as the window’s minimized window image.
When the user minimizes the window, the Dock displays miniwindowImage in the corresponding Dock tile, scaling it as needed to fit in the tile. If you do not specify a custom image using this method, the Dock creates one for you automatically.
You can also call this method as needed to change the minimized window image. Typically, you would specify a custom image immediately prior to a window being minimized—when the system posts an NSWindowWillMiniaturizeNotification. You can call this method while the window is minimized to update the current image in the Dock. However, this method is not recommended for creating complex animations in the Dock.
Support for custom images is disabled by default. To enable support, set the AppleDockIconEnabled key to YES when first registering your application’s user defaults. You must set this key prior to calling the init method of NSApplication, which reads the current value of the key.
NSWindow.hSets the title of the window’s miniaturized counterpart to a given string and redisplays it.
- (void)setMiniwindowTitle:(NSString *)miniwindowTitle
The string to set as the title of the minimized window.
A minimized window’s title normally reflects that of its full-size counterpart, abbreviated to fit if necessary. Although this method allows you to set the minimized window’s title explicitly, changing the full-size NSWindow object’s title (through setTitle: or setTitleWithRepresentedFilename:) automatically changes the minimized window’s title as well.