Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSWindow

Inherits from
Implements
Package
com.apple.cocoa.application
Companion guide

Class at a Glance

An NSWindow manages an onscreen window, coordinating the display and event handling for its NSViews. Interface Builder allows you to create and set up NSWindows, but there are many things you may wish to do programmatically as well.

Principal Attributes

Creation

Interface Builder
Constructor

"NSWindow"

Commonly Used Methods

makeKeyAndOrderFront

Moves the NSWindow to the front and makes it the key window.

makeFirstResponder

Sets the first responder in the NSWindow.

fieldEditorForObject

Returns the shared text object for the NSWindow.

setContentView

Sets the root-level NSView in the NSWindow.

representedFilename

Returns the filename whose contents the NSWindow presents.

setDocumentEdited

Sets whether the NSWindow’s represented file needs to be saved.

setTitle

Sets the title of the NSWindow.

setTitleWithRepresentedFilename

Sets the title of the NSWindow in a readable format for filenames.

Overview

The NSWindow class defines objects 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 NSWindow are to provide an area in which NSViews can be placed and to accept and distribute, to the appropriate NSViews, events the user instigates through actions with the mouse and keyboard.

Note: Although NSWindow inherits the NSCoding protocol from NSResponder, NSWindow 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 using a keyed coding object throws an InvalidArgumentException.

Tasks

Constructors

Calculating Layout

Converting Coordinates

Moving and Resizing

Constraining Window Size

Managing Content Size

Saving the Frame to User Defaults

Ordering Windows

Attached Windows

Making Key and Main Windows

Working with the Default Button

Display and Drawing

Flushing Graphics

Bracketing Temporary Drawing

Window Server Information

Screen Information

Working with the Responder Chain

Event Handling

Working with the Field Editor

Keyboard Interface Control

Setting the Title and Filename

Marking a Window Edited

Closing the Window

Miniaturizing and Miniaturized Windows

Working with Menus

Working with the Windows Menu

Working with Cursor Rectangles

Dragging

Controlling Behavior

Working with Display Characteristics

Working with Services

Printing

Setting the Delegate

Getting Associated Information

Working with Sheets

Working with Toolbars

Working with Title Bar Widgets

Managing Tool Tips

Working with window status

Moving and resizing windows

Miniaturizing and closing windows

Exposing and updating windows

Displaying sheets

Obtaining information about a window

Constructors

NSWindow

Creates a new NSWindow object, whose content rectangle is specified relative to the lower-left corner of the main screen.

public NSWindow()

Discussion

This constructor calls the following constructor with contentRect of (100.0, 100.0, 100.0, 100.0), styleMask of TitledWindowMask, backingType of BackingStoreBuffered, and defer set to false.

Creates a new NSWindow object, whose content rectangle is specified relative to the lower-left corner of the main screen.

public NSWindow(NSRect contentRect, int styleMask, int backingType, boolean defer)

Discussion

The contentRect argument specifies the location and size of the NSWindow’s content area in screen coordinates. Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.

The styleMask argument specifies the receiver’s style. Either it can be BorderlessWindowMask, or it can contain any of the options described in the constants section, 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 an NSWindow’s style mask should include TitledWindowMask if it includes any of the others.

The backingType argument specifies how the drawing done in the receiver is buffered by the object’s window device, and possible values are described in the constants section.

The defer argument determines whether the window server creates a window device for the new object immediately. If defer is true, it defers creating the window until the receiver is moved onscreen. All display messages sent to the NSWindow or its NSViews are postponed until the window is created, just before it’s moved onscreen. Deferring the creation of the window improves launch time and minimizes the virtual memory load on the window server.

The new NSWindow creates an instance of NSView to be its default content view. You can replace it with your own object by using the setContentView method.

Creates an NSWindow object, whose content rectangle is specified relative to the lower-left corner of aScreen.

public NSWindow(NSRect contentRect, int styleMask, int bufferingType, boolean defer, NSScreen aScreen)

Discussion

Otherwise this method is equivalent to the preceding constructor.

If aScreen is null, the content rectangle is interpreted relative to the lower-left corner of the main screen. 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.

See Also

Static Methods

contentRectForFrameRect

Returns the content rectangle used by an NSWindow with a frame rectangle of frameRect and a style mask of aStyle.

public static NSRect contentRectForFrameRect(NSRect frameRect, int aStyle)

Discussion

Both frameRect and the returned content rectangle are expressed in screen coordinates. See the constants section for a list of style mask values.

See Also

defaultDepthLimit

Returns the default depth limit for instances of NSWindow.

public static int defaultDepthLimit()

Discussion

This limit is determined by the depth of the deepest screen level available to the window server.

See Also

frameRectForContentRect

Returns the frame rectangle used by an NSWindow with a content rectangle of contentRect and a style mask of aStyle.

public static NSRect frameRectForContentRect(NSRect contentRect, int aStyle)

Discussion

Both contentRect and the returned frame rectangle are expressed in screen coordinates. See the constants section for a list of style mask values.

See Also

menuChanged

This method does nothing; it is here for backward compatibility.

public static void menuChanged(NSMenu aMenu)

See Also

minFrameWidthWithTitle

Returns the minimum width an NSWindow’s frame rectangle must have for it to display all of aTitle, given aStyle as its style mask.

public static float minFrameWidthWithTitle(String aTitle, int aStyle)

Discussion

See the constants section for a list of acceptable style mask values.

removeFrameUsingName

Removes the frame data stored under name from the application’s user defaults.

public static void removeFrameUsingName(String name)

See Also

standardWindowButtonForStyleMask

Returns a new instance of the given standard button, sized appropriately for the styleMask.

public static NSButton standardWindowButtonForStyleMask(int button, int styleMask)

Discussion

The caller is responsible for adding the button to the view hierarchy and for setting the target to be the window.

Availability
See Also

Instance Methods

acceptsMouseMovedEvents

Returns true if the receiver accepts and distributes mouse-moved events, false if it doesn’t.

public boolean acceptsMouseMovedEvents()

Discussion

NSWindows by default don’t accept mouse-moved events.

See Also

addChildWindow

childWin is ordered either above (Above) or below (Below) the receiver, and maintained in that relative place for subsequent ordering operations involving either window.

public void addChildWindow(NSWindow childWin, int place)

Discussion

While this attachment is active, moving childWin will not cause the receiver to move (as in sliding a drawer in or out), but moving the receiver will cause childWin 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.

Availability
See Also

allowsToolTipsWhenApplicationIsInactive

Returns whether the receiver can display tool tips even when the application is in the background.

public boolean allowsToolTipsWhenApplicationIsInactive()

Discussion

Default is false.

Availability
See Also

alphaValue

Returns the receiver’s alpha value.

public float alphaValue()

See Also

animationResizeTime

Subclasses can override this method to control the total time for the frame change.

public double animationResizeTime(NSRect newFrame)

Discussion

newFrame is the rect passed into setFrame.

The default 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).

areCursorRectsEnabled

Returns true if the receiver’s cursor rectangles are enabled, false if they’re not.

public boolean areCursorRectsEnabled()

See Also

aspectRatio

Returns the receiver’s size aspect ratio.

public NSSize aspectRatio()

Discussion

The size of the receiver’s frame rectangle is constrained to integral multiples of this ratio when the user resizes it. You can set an NSWindow’s size to any ratio programmatically.

See Also

attachedSheet

Returns the sheet attached to the receiver.

public NSWindow attachedSheet()

Discussion

If the receiver does not have a sheet attached, this method returns null.

autorecalculatesKeyViewLoop

Returns true if the window automatically recalculates the key view loop when views are added; otherwise returns false.

public boolean autorecalculatesKeyViewLoop()

Availability
See Also

backgroundColor

Returns the color of the receiver’s background.

public NSColor backgroundColor()

See Also

backingType

Returns the receiver’s backing store type.

public int backingType()

Discussion

The possible return values are described in the constants section.

See Also

becomeKeyWindow

Invoked automatically to inform the receiver that it has become the key window; never invoke this method directly.

public void becomeKeyWindow()

Discussion

This method reestablishes the receiver’s first responder, sends the becomeKeyWindow message to that object if it responds, and posts a WindowDidBecomeKeyNotification to the default notification center.

See Also

becomeMainWindow

Invoked automatically to inform the receiver that it has become the main window; never invoke this method directly.

public void becomeMainWindow()

Discussion

This method posts a WindowDidBecomeMainNotification to the default notification center.

See Also

cacheImageInRect

Stores the receiver’s raster image from aRect, which is expressed in the receiver’s base coordinate system.

public void cacheImageInRect(NSRect aRect)

Discussion

This method allows the receiver 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.

See Also

canBecomeKeyWindow

Returns true if the receiver can become the key window, false if it can’t.

public boolean canBecomeKeyWindow()

Discussion

Attempts to make the receiver the key window are abandoned if this method returns false. NSWindow’s implementation returns true if the receiver has a title bar or a resize bar, false otherwise.

See Also

canBecomeMainWindow

Returns true if the receiver can become the main window, false if it can’t.

public boolean canBecomeMainWindow()

Discussion

Attempts to make the receiver the main window are abandoned if this method returns false. NSWindow’s implementation returns true if the receiver is visible, is not an NSPanel, and has a title bar or a resize mechanism. Otherwise it returns false.

See Also

canHide

Returns whether the receiver can be hidden during NSApplication’s hide.

public boolean canHide()

Discussion

The default is true.

See Also

canStoreColor

Returns true if the receiver has a depth limit that allows it to store color values, false if it doesn’t.

public boolean canStoreColor()

See Also

cascadeTopLeftFromPoint

Positions the receiver's top left at topLeftPoint, unless topLeftPoint is NSPoint.ZeroPoint in which case the receiver is not moved except as needed to constrain to the visible screen.

public NSPoint cascadeTopLeftFromPoint(NSPoint topLeftPoint)

Discussion

Returns a point shifted from top left of the receiver that can be passed to a subsequent invocation of cascadeTopLeftFromPoint to position the next NSWindow so the title bars of both NSWindows are fully visible.

Both topLeftPoint and the return value are expressed in screen coordinates.

See Also

center

Sets the receiver’s location to the center of the screen.

public void center()

Discussion

The receiver 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 receiver onscreen, however; use makeKeyAndOrderFront to do that.

You typically use this method to place an NSWindow—most likely an alert dialog—where the user can’t miss it. This method is invoked automatically when an NSPanel is placed on the screen by NSApplication’s runModalForWindow method.

childWindows

Returns an array of the receiver’s attached child windows.

public NSArray childWindows()

Availability
See Also

close

Removes the receiver from the screen.

public void close()

Discussion

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 a WindowWillCloseNotification to the default notification center.

The close method differs in two important ways from the performClose method:

Use performClose if you need these features.

See Also

concludeDragOperation

public void concludeDragOperation(NSDraggingInfo draggingInfo)

Discussion

Invoked when the dragging operation is complete and the previous performDragOperation returned true. draggingInfo contains details about the dragging operation. This method allows you to perform any tidying up that is needed, such as updating the visual representation now the dragged data has been incorporated. This is the last message sent during a dragging session.

constrainFrameRectToScreen

Modifies and returns frameRect so that its top edge lies on aScreen.

public NSRect constrainFrameRectToScreen(NSRect frameRect, NSScreen aScreen)

Discussion

If the receiver is resizable and the receiver’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 receiver) whenever a titled NSWindow 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.

contentAspectRatio

Returns the aspect ratio (height in relation to width) of the receiver’s content view.

public NSSize contentAspectRatio()

Availability
See Also

contentMaxSize

Returns the maximum size of the receiver’s content view.

public NSSize contentMaxSize()

Availability
See Also

contentMinSize

Returns the minimum size of the receiver’s content view.

public NSSize contentMinSize()

Availability
See Also

contentRectForFrameRect

Returns the rectangle bounding the receiver’s content view given the frame rectangle frameRect.

public NSRect contentRectForFrameRect(NSRect frameRect)

Discussion

Both frameRect and the returned content rectangle are expressed in screen coordinates. The receiver uses its current style mask in computing the content rectangle. See the constants sectionfor a list of style mask values. The main advantage of this instance-method counterpart to contentRectForFrameRect 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.)

Availability
See Also

contentResizeIncrements

Returns the size of increments used during resizing of the receiver’s content rectangle.

public NSSize contentResizeIncrements()

Discussion

Resizing of the content rectangle is constrained to integral multiples of the returned height and width.

Availability
See Also

contentView

Returns the receivers’s content view, the highest accessible NSView object in the receiver’s view hierarchy.

public NSView contentView()

See Also

convertBaseToScreen

Returns aPoint converted from the receiver’s base coordinate system to the screen coordinate system.

public NSPoint convertBaseToScreen(NSPoint aPoint)

See Also

convertScreenToBase

Returns aPoint converted from the screen coordinate system to the receiver’s base coordinate system.

public NSPoint convertScreenToBase(NSPoint aPoint)

See Also

currentEvent

Returns the event currently being processed by the application, by invoking NSApplication’s currentEvent method.

public NSEvent currentEvent()

dataWithEPSInsideRect

Returns EPS data that draws the region of the receiver within aRect (expressed in the receiver’s base coordinate system).

public NSData dataWithEPSInsideRect(NSRect aRect)

Discussion

This data can be placed on a pasteboard, written to a file, or used to create an NSImage object.

See Also

dataWithPDFInsideRect

Returns PDF data that draws the region of the receiver within aRect (expressed in the receiver’s base coordinate system).

public NSData dataWithPDFInsideRect(NSRect aRect)

Discussion

This data can be placed on a pasteboard, written to a file, or used to create an NSImage object.

See Also

deepestScreen

Returns the deepest screen the receiver is on (it may be split over several screens), or null if the receiver is offscreen.

public NSScreen deepestScreen()

See Also

defaultButtonCell

Returns the button cell that performs as if clicked when the NSWindow receives a Return (or Enter) key event.

public NSButtonCell defaultButtonCell()

Discussion

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.

See Also

delegate

Returns the receiver’s delegate, or null if it doesn’t have a delegate.

public Object delegate()

See Also

deminiaturize

This action method deminiaturizes the receiver.

public void deminiaturize(Object sender)

Discussion

Invoke this method to programmatically deminiaturize a miniaturized window in the dock.

See Also

depthLimit

Returns the depth limit of the receiver.

public int depthLimit()

See Also

deviceDescription

Returns a dictionary containing information about the receiver’s resolution, color depth, and so on.

public NSDictionary deviceDescription()

Discussion

This information is useful for tuning images and colors to the window’s display capabilities. The contents of the dictionary are:

Dictionary Key

Value

NSGraphics.DeviceResolution

An NSSize that describes the receiver’s raster resolution in dots per inch (dpi).

NSGraphics.DeviceColorSpaceName

A String giving the name of the receiver’s color space. See the constants section in NSGraphics for a list of possible values.

NSGraphics.DeviceBitsPerSample

A Number containing an integer that gives the bit depth of the receiver’s raster image (2-bit, 8-bit, and so forth).

NSGraphics.DeviceIsScreen

A result of true, indicating that the receiver displays on the screen.

NSGraphics.DeviceSize

An NSSize that gives the size of the receiver’s frame rectangle.

See Also

disableCursorRects

Disables all cursor rectangle management within the receiver.

public void disableCursorRects()

Discussion

Use this method when you need to do some special cursor manipulation and you don’t want the Application Kit interfering.

See Also

disableFlushWindow

Disables the flushWindow method for the receiver.

public void disableFlushWindow()

Discussion

If the receiver is buffered, disabling flushWindow prevents drawing from being automatically flushed by NSView’s display... methods from the receiver’s backing store to the screen. This method permits several NSViews to be drawn before the results are shown to the user.

Flushing should be disabled only temporarily, while the NSWindow’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.

disableKeyEquivalentForDefaultButtonCell

Disables the default button cell’s key equivalent, so it doesn’t perform a click when the user presses Return (or Enter).

public void disableKeyEquivalentForDefaultButtonCell()

Discussion

See the method description for defaultButtonCell for more information.

See Also

disableScreenUpdatesUntilFlush

Disables the receiver’s screen updates until the window is flushed.

public void disableScreenUpdatesUntilFlush()

Discussion

This method can be invoked to synchronize hardware surface flushes with the window’s flushes. The receiver immediately disables screen updates using the function NSDisableScreenUpdates and re-enables screen updates when the window flushes. Sending this message multiple times during a window update cycle has no effect.

Availability

discardCachedImage

Discards all of the receiver’s cached image rectangles.

public void discardCachedImage()

Discussion

An NSWindow automatically discards its cached image rectangles when it displays.

See Also

discardCursorRects

Invalidates all cursor rectangles in the receiver.

public void discardCursorRects()

Discussion

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 might want to override it to change its behavior.

discardEventsMatchingMask

Forwards the message to the NSApplication object, which handles it as described in the NSApplication class specification.

public void discardEventsMatchingMask(int mask, NSEvent lastEvent)

display

Passes a display message down the receiver’s view hierarchy, thus redrawing all NSViews within the receiver, including the frame view that draws the border, title bar, and other peripheral elements.

public void display()

Discussion

You rarely need to invoke this method. NSWindows normally record which of their NSViews need display and display them automatically on each pass through the event loop.

See Also

displayIfNeeded

Passes a displayIfNeeded message down the receiver’s view hierarchy, thus redrawing all NSViews that need to be displayed, including the frame view that draws the border, title bar, and other peripheral elements.

public void displayIfNeeded()

Discussion

This method is useful when you want to modify some number of NSViews and then display only the ones that were modified.

You rarely need to invoke this method. NSWindows normally record which of their NSViews need display and display them automatically on each pass through the event loop.

See Also

displaysWhenScreenProfileChanges

Returns true if the window context should be updated when the screen profile changes or when the window moves to a different screen.

public boolean displaysWhenScreenProfileChanges()

Discussion

Returns false (the default value) if the window context should stay the same despite profile changes.

Availability
See Also

draggingEntered

public int draggingEntered(NSDraggingInfo draggingInfo)

Discussion

Invoked when a dragged image enters the receiver. Specifically, this method is invoked when the mouse pointer enters the receiver’s frame rectangle. draggingInfo contains details about the dragging operation.

Returns a value indicating which dragging operation will be performed when the image is released. In deciding which dragging operation to return, you should evaluate the overlap between both the dragging operations allowed by the source and the dragging operations and pasteboard data types the receiver supports. The returned value should be one of the following:

Option

Meaning

NSDraggingInfo.DragOperationCopy

The data represented by the image will be copied.

NSDraggingInfo.DragOperationLink

The data will be shared.

NSDraggingInfo.DragOperationGeneric

The operation will be defined by the destination.

NSDraggingInfo.DragOperationPrivate

The operation is negotiated privately between the source and the destination.

NSDraggingInfo.DragOperationEvery

Combines all the above.

If none of the operations is appropriate, returns NSDraggingInfo.DragOperationNone.

See Also

draggingExited

Invoked when the dragged image exits the receiver’s frame rectangle.

public void draggingExited(NSDraggingInfo draggingInfo)

Discussion

draggingInfo contains details about the dragging operation.

draggingUpdated

public int draggingUpdated(NSDraggingInfo draggingInfo)

Discussion

Invoked periodically as the dragged image is held within the receiver. The messages continue until the image is either released or dragged out of the receiver. draggingInfo contains details about the dragging operation. Returns one of the dragging operation options listed under draggingEntered.

This method provides you with an opportunity to modify the dragging operation depending on the position of the mouse pointer inside of the receiver. For example, you may have several graphics or areas of text contained within the same view and wish to tailor the dragging operation or to ignore the drag event completely, depending upon which object is underneath the mouse pointer at the time when the user releases the dragged image and performDragOperation is invoked.

You typically examine the contents of the pasteboard in draggingEntered, as this method is invoked only once, rather than in this method, which is invoked multiple times.

Only one window at a time receives a sequence of draggingUpdated messages. If the mouse pointer is within the bounds of two overlapping windows that are both valid destinations, the uppermost window receives these messages until the image is either released or dragged out.

See Also

dragImage

Begins a dragging session.

public void dragImage(NSImage anImage, NSPoint aPoint, NSSize initialOffset, NSEvent theEvent, NSPasteboard pboard, Object sourceObject, boolean slideBack)

Discussion

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). Essentially the same as NSView’s method of the same name, except that aPoint is given in the NSWindow’s base coordinate system. See the description of NSView’s dragImage for more information.

drawers

Returns the collection of drawers associated with the receiver.

public NSArray drawers()

enableCursorRects

Reenables cursor rectangle management within the receiver after a disableCursorRects message.

public void enableCursorRects()

enableFlushWindow

Reenables the flushWindow method for the receiver after it was disabled through a previous disableFlushWindow message.

public void enableFlushWindow()

enableKeyEquivalentForDefaultButtonCell

Reenables the default button cell’s key equivalent, so it performs a click when the user presses Return (or Enter).

public void enableKeyEquivalentForDefaultButtonCell()

Discussion

See the method description for defaultButtonCell for more information.

See Also

endEditingForObject

Forces the field editor, which anObject is assumed to be using, to give up its first responder status and prepares it for its next assignment.

public void endEditingForObject(Object anObject)

Discussion

If the field editor is the first responder, it’s made to resign that status even if its resignFirstResponder method returns false. 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 null, 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 endEditingForObject 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 the first responder.

See Also

fieldEditorForObject

Returns the receiver’s field editor, creating it if needed if createFlag is true.

public NSText fieldEditorForObject(boolean createFlag, Object anObject)

Discussion

Returns null if createFlag is false and the field editor doesn’t exist. anObject is used to allow the receiver’s delegate to substitute another object in place of the field editor, as described below. 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 endEditingForObject). 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 endEditingForObject.

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

A freshly created NSWindow doesn’t have a field editor. After a field editor has been created for an NSWindow, the createFlag argument is ignored. By passing false for createFlag and testing the return value, however, you can predicate an action on the existence of the field editor.

The receiver’s delegate can substitute a custom editor in place of the NSWindow’s field editor by implementing windowWillReturnFieldEditor. The receiver sends this message to its delegate with itself and anObject as the arguments, and if the return value is not null the NSWindow returns that object instead of its field editor. However, note the following:

firstResponder

Returns the receiver’s first responder.

public NSResponder firstResponder()

See Also

flushWindow

Flushes the receiver’s offscreen buffer to the screen if the receiver is buffered and flushing is enabled.

public void flushWindow()

Discussion

Does nothing for other display devices, such as a printer. This method is automatically invoked by NSWindow’s and NSView’s display and displayIfNeeded methods.

See Also

flushWindowIfNeeded

Flushes the receiver’s offscreen buffer to the screen if flushing is enabled and if the last flushWindow message had no effect because flushing was disabled.

public void flushWindowIfNeeded()

Discussion

To avoid unnecessary flushing, use this method rather than flushWindow to flush an NSWindow after flushing has been reenabled.

See Also

frame

Returns the receiver’s frame rectangle.

public NSRect frame()

Discussion

The frame rectangle is always reckoned in the screen coordinate system.

See Also

frameAutosaveName

Returns the name used to automatically save the receiver’s frame rectangle data in the defaults system, as set through setFrameAutosaveName.

public String frameAutosaveName()

Discussion

If the receiver has an autosave name, its frame data is written whenever the frame rectangle changes.

See Also

frameRectForContentRect

Returns the receiver’s frame rectangle given the rectangle bounding the content view contentRect.

public NSRect frameRectForContentRect(NSRect contentRect)

Discussion

Both contentRect and the returned frame rectangle are expressed in screen coordinates. The receiver uses its current style mask in computing the frame rectangle. See the constants section for a list of style mask values. The major advantage of this instance-method counterpart to frameRectForContentRect 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.)

Availability
See Also

graphicsContext

Returns the graphics context associated with the receiver for the current thread.

public NSGraphicsContext graphicsContext()

Availability

gState

Returns the graphics state object associated with the receiver.

public int gState()

Discussion

This graphics state is used by default for all NSViews in the receiver’s view hierarchy, but individual NSViews can be made to use their own with the NSView method allocateGState.

hasDynamicDepthLimit

Returns true if the receiver’s depth limit can change to match the depth of the screen it’s on, false if it can’t.

public boolean hasDynamicDepthLimit()

See Also

hasShadow

Returns true if the window has a shadow; otherwise returns false.

public boolean hasShadow()

See Also

hidesOnDeactivate

Returns true if the receiver is removed from the screen when its application is deactivated, false if it remains onscreen.

public boolean hidesOnDeactivate()

See Also

ignoresMouseEvents

Return whether the receiver is transparent to mouse events.

public boolean ignoresMouseEvents()

Availability
See Also

initialFirstResponder

Returns the NSView that’s made first responder the first time the receiver is placed onscreen.

public NSView initialFirstResponder()

See Also

invalidateCursorRectsForView

Marks as invalid the cursor rectangles of aView, an NSView in the receiver’s view hierarchy, so they’ll be set up again when the receiver becomes key (or immediately if the receiver is key).

public void invalidateCursorRectsForView(NSView aView)

See Also

invalidateShadow

Invalidates the window shadow so that it is recomputed based on the current window shape.

public void invalidateShadow()

Availability
See Also

isAutodisplay

Returns true if the receiver automatically displays its views that are marked as needing it, false if it doesn’t.

public boolean isAutodisplay()

Discussion

Automatic display typically occurs on each pass through the event loop.

See Also

isDocumentEdited

Returns true or false according to the argument supplied with the last setDocumentEdited message.

public boolean isDocumentEdited()

isExcludedFromWindowsMenu

Returns true if the receiver’s title is omitted from the application’s Windows menu, false if it is listed.

public boolean isExcludedFromWindowsMenu()

See Also

isFlushWindowDisabled

Returns true if the receiver’s flushing ability has been disabled; otherwise returns false.

public boolean isFlushWindowDisabled()

See Also

isKeyWindow

Returns true if the receiver is the key window for the application, false if it isn’t.

public boolean isKeyWindow()

See Also

isMainWindow

Returns true if the receiver is the main window for the application, false if it isn’t.

public boolean isMainWindow()

See Also

isMiniaturized

Returns true if the receiver has been miniaturized, false if it hasn’t.

public boolean isMiniaturized()

Discussion

A miniaturized window is removed from the screen and replaced by a image, icon, or button that represents it, called the counterpart.

See Also

isMovableByWindowBackground

Returns true if the receiver is movable by clicking and dragging anywhere in its background, false if not.

public boolean isMovableByWindowBackground()

Discussion

A window with a style mask of NSTexturedBackgroundWindowMask returns true by default. Sheets and drawers cannot be movable by window background.

Availability
See Also

isOneShot

Returns true if the window device the receiver manages is freed when it’s removed from the screen list, false if not.

public boolean isOneShot()

Discussion

The default is false.

See Also

isOpaque

Returns whether the receiver is opaque.

public boolean isOpaque()

Discussion

The default is true.

See Also

isReleasedWhenClosed

Returns true if the receiver is automatically released after being closed, false if it’s simply removed from the screen.

public boolean isReleasedWhenClosed()

Discussion

The default for NSWindow is true; the default for NSPanel is false. Release when closed, however, is ignored for windows owned by window controllers.

See Also

isSheet

Returns true if the receiver has ever run as a modal sheet.

public boolean isSheet()

Discussion

Sheets are created using the NSPanel subclass.

isVisible

Returns true if the receiver is onscreen (even if it’s obscured by other windows).

public boolean isVisible()

See Also

isZoomed

Returns whether the receiver is in a zoomed state.

public boolean isZoomed()

See Also

keyDown

Handles theEvent keyboard event that may need to be interpreted as changing the key view or triggering a keyboard equivalent.

public void keyDown(NSEvent theEvent)

See Also

keyViewSelectionDirection

Returns the direction the receiver is currently using to change the key view.

public int keyViewSelectionDirection()

Discussion

This direction can be one of the values described in the constants section

See Also

level

Returns the level of the receiver as set using setLevel.

public int level()

makeFirstResponder

Attempts to make aResponder the first responder for the receiver.

public boolean makeFirstResponder(NSResponder aResponder)

Discussion

If aResponder isn’t already the first responder, this method first sends a resignFirstResponder message to the object that is. If that object refuses to resign, it remains the first responder, and this method immediately returns false. If it returns true, this method sends a becomeFirstResponder message to aResponder. If aResponder accepts first responder status, this method returns true. If it refuses, this method returns false, and the NSWindow becomes first responder.

If aResponder is null, 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 false. If the current first responder returns true from resignFirstResponder, the receiver is made its own first responder and this method returns true.

The Application Kit 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. aResponder is typically an NSView in the receiver’s view hierarchy. If this method is called explicitly, first send acceptsFirstResponder to aResponder, and do not call makeFirstResponder if acceptsFirstResponder returns false.

Use setInitialFirstResponder to the set the first responder to be used when the window is brought onscreen for the first time.

See Also

makeKeyAndOrderFront

This action method moves the receiver to the front of the screen list, within its level, and makes it the key window.

public void makeKeyAndOrderFront(Object sender)

See Also

makeKeyWindow

Makes the receiver the key window.

public void makeKeyWindow()

See Also

makeMainWindow

public void makeMainWindow()

Discussion

Makes the receiver the main window.

See Also

maxSize

Returns the maximum size to which the receiver’s frame (including its title bar) can be sized either by the user or by the setFrame... methods other than setFrame.

public NSSize maxSize()

See Also

miniaturize

This action method removes the receiver from the screen list and displays the miniaturized window in the dock.

public void miniaturize(Object sender)

See Also

miniwindowImage

Returns the custom miniaturized window image of the receiver.

public NSImage miniwindowImage()

Discussion

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

See Also

miniwindowTitle

Returns the title displayed in the receiver’s miniaturized window.

public String miniwindowTitle()

See Also

minSize

Returns the minimum size to which the receiver’s frame (including its title bar) can be sized either by the user or by the setFrame... methods other than setFrame.

public NSSize minSize()

See Also

mouseLocationOutsideOfEventStream

Returns the current location of the mouse reckoned in the receiver’s base coordinate system, regardless of the current event being handled or of any events pending.

public NSPoint mouseLocationOutsideOfEventStream()

Discussion

For the same information in screen coordinates, use NSEvent's "mouseLocation".

See Also

nextEventMatchingMask

Invokes NSApplication’s nextEventMatchingMask method, using mask as the first argument, with an unlimited expiration, a mode of NSApplication.EventTrackingRunLoopMode, and a dequeue flag of true.

public NSEvent nextEventMatchingMask(int mask)

Discussion

See the method description in the NSApplication class specification for more information.

Forwards the message to the global NSApplication object, NSApplication.sharedApplication().

public NSEvent nextEventMatchingMask(int mask, NSDate expirationDate, String mode, boolean dequeue)

Discussion

See the method description in the NSApplication class specification for more information.

orderBack

This action method moves the receiver to the back of its level in the screen list, without changing either the key window or the main window.

public void orderBack(Object sender)

See Also

orderFront

This action method moves the receiver to the front of its level in the screen list, without changing either the key window or the main window.

public void orderFront(Object sender)

See Also

orderFrontRegardless

Moves the receiver to the front of its level, even if its application isn’t active, but without changing either the key window or the main window.

public void orderFrontRegardless()

Discussion

Normally an NSWindow can’t be moved in front of the key window unless the NSWindow 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.

See Also

orderOut

This action method takes the receiver out of the screen list.

public void orderOut(Object sender)

Discussion

If the receiver is the key or main window, the NSWindow immediately behind it is made key or main in its place. Calling the orderOut method causes the receiver to be removed from the screen, but does not cause it to be released.

See Also

orderWindow

Repositions the receiver’s window device in the window server’s screen list.

public void orderWindow(int place, int otherWindowNumber)

Discussion

If place is Out, the receiver is removed from the screen list and otherWindowNumber is ignored. If it’s Above, the receiver is ordered immediately in front of the window whose window number is otherWindowNumber. Similarly, if place is Below, the receiver is placed immediately behind the window represented by otherWindowNumber. If otherWindowNumber is 0, the receiver is placed in front of or behind all other windows in its level.

See Also

parentWindow

Returns the parent window to which the receiver is attached as a child.

public NSWindow parentWindow()

Availability
See Also

performClose

This action method simulates the user clicking the close button by momentarily highlighting the button and then closing the window.

public void performClose(Object sender)

Discussion

If the receiver’s delegate or the receiver itself implements windowShouldClose, then that message is sent with the receiver as the argument. (Only one such message is sent; if both the delegate and the NSWindow implement the method, only the delegate receives the message.) If the windowShouldClose method returns false, the window isn’t closed. If it returns true, or if it isn’t implemented, performClose invokes the close method to close the window.

If the receiver doesn’t have a close button or can’t be closed (for example, if the delegate replies false to a windowShouldClose message), the system beeps.

See Also

performDragOperation

public boolean performDragOperation(NSDraggingInfo aDraggingInfo)

Discussion

Invoked after the released image has been removed from the screen and the previous prepareForDragOperation message has returned true. aDraggingInfo contains details about the dragging operation. This method should do the real work of importing the pasteboard data represented by the image. If the receiver accepts the data, return true, otherwise return false.

See Also

performMiniaturize

This action method simulates the user clicking the miniaturize button by momentarily highlighting the button, then miniaturizing the window.

public void performMiniaturize(Object sender)

Discussion

If the receiver doesn’t have a miniaturize button or can’t be miniaturized for some reason, the system beeps.

See Also

performZoom

This action method simulates the user clicking the zoom box by momentarily highlighting the button and then zooming the window.

public void performZoom(Object sender)

Discussion

If the receiver doesn’t have a zoom box or can’t be zoomed for some reason, the system beeps.

See Also

postEvent

Forwards the message to the global NSApplication object, NSApplication.sharedApplication().

public void postEvent(NSEvent anEvent, boolean flag)

Discussion

See “NSApplication” for details.

prepareForDragOperation

public boolean prepareForDragOperation(NSDraggingInfo aDraggingInfo)

Discussion

Invoked when the image is released, if the most recent draggingEntered or draggingUpdated message returned an acceptable drag-operation value. aDraggingInfo contains details about the dragging operation. Returns true if the receiver agrees to perform the drag operation and false if not.

See Also

preservesContentDuringLiveResize

Returns true if the window tries to optimize live resize operations by preserving the content of views that have not moved; otherwise, returns false.

public boolean preservesContentDuringLiveResize()

Discussion

When enabled, 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.

Availability
See Also

print

This action method runs the Print panel, and if the user chooses an option other than canceling, prints the receiver (its frame view and all subviews).

public void print(Object sender)

recalculateKeyViewLoop

Marks the key view loop as dirty and in need of recalculation.

public void recalculateKeyViewLoop()

Discussion

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 from your code to update the window’s key view loop. You can also call setAutorecalculatesKeyViewLoop to have the window recalculate the loop automatically.

Availability
See Also

registerForDraggedTypes

Registers pboardTypes as the pasteboard types the receiver will accept as the destination of an image-dragging session.

public void registerForDraggedTypes(NSArray pboardTypes)

Discussion

Registering an NSWindow for dragged types automatically makes it a candidate destination object for a dragging session. As such, it must properly implement some or all of the NSDraggingDestination interface methods. As a convenience, NSWindow provides default implementations of these methods. See the “NSDraggingDestination” interface specification for details.

See Also

removeChildWindow

Detaches childWin from the receiver.

public void removeChildWindow(NSWindow childWin)

Availability
See Also

representedFilename

Returns the name of the file the receiver represents.

public String representedFilename()

See Also

resetCursorRects

Invokes discardCursorRects to clear the receiver’s cursor rectangles, then sends resetCursorRects to every NSView in the receiver’s view hierarchy.

public void resetCursorRects()

Discussion

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.

resignKeyWindow

Never invoke this method; it’s invoked automatically when the NSWindow resigns key window status.

public void resignKeyWindow()

Discussion

This method sends resignKeyWindow to the receiver’s first responder, sends windowDidResignKey to the receiver’s delegate, and posts a WindowDidResignKeyNotification to the default notification center.

See Also

resignMainWindow

Never invoke this method; it’s invoked automatically when the NSWindow resigns main window status.

public void resignMainWindow()

Discussion

This method sends windowDidResignMain to the receiver’s delegate and posts a WindowDidResignMainNotification to the default notification center.

See Also

resizeFlags

Valid only while the receiver is being resized, this method returns the flags field of the event record for the mouse-down event that initiated the resizing session.

public int resizeFlags()

Discussion

The integer encodes, as a mask, which of the modifier keys was held down when the event occurred. The flags are listed in NSEvent’s modifierFlags method description. 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.

resizeIncrements

Returns the receiver’s resizing increments, which restrict the user’s ability to resize it so that its width and height alter by integral multiples of increments.width and increments.height when the user resizes it.

public NSSize resizeIncrements()

Discussion

These amounts are whole number values, 1.0 or greater. You can set an NSWindow’s size to any value programmatically.

See Also

restoreCachedImage

Splices the receiver’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.

public void restoreCachedImage()

Discussion

You must invoke flushWindow after this method to guarantee proper redisplay. An NSWindow automatically discards its cached image rectangles when it displays.

See Also

runToolbarCustomizationPalette

The action method for the “Customize Toolbar…” menu item.

public void runToolbarCustomizationPalette(Object sender)

Discussion

See the NSToolbar class description for additional information.

saveFrameUsingName

Saves the receiver’s frame rectangle in the user defaults system.

public void saveFrameUsingName(String name)

Discussion

With the companion method setFrameUsingName, you can save and reset an NSWindow’s frame over various launchings of an application. The default is owned by the application and stored under the name “NSWindow Frame name.” See the NSUserDefaults class specification for more information.

See Also

screen

Returns the screen the receiver is on.

public NSScreen screen()

Discussion

If the receiver is partly on one screen and partly on another, the screen where most of it lies is returned. Returns null if the receiver is completely offscreen.

See Also

selectKeyViewFollowingView

Sends the NSView message nextValidKeyView to aView, and if that message returns an NSView, invokes makeFirstResponder with the returned NSView.

public void selectKeyViewFollowingView(NSView aView)

See Also

selectKeyViewPrecedingView

Sends the NSView message previousValidKeyView to aView, and if that message returns an NSView, invokes makeFirstResponder with the returned NSView.

public void selectKeyViewPrecedingView(NSView aView)

See Also

selectNextKeyView

This action method searches for a candidate key view and, if it finds one, invokes makeFirstResponder to establish it as the first responder.

public void selectNextKeyView(Object sender)

Discussion

The candidate is one of the following (searched for in this order):

See Also

selectPreviousKeyView

This action method searches for a candidate key view and, if it finds one, invokes makeFirstResponder to establish it as the first responder.

public void selectPreviousKeyView(Object sender)

Discussion

The candidate is one of the following (searched for in this order):

See Also

sendEvent

This action method dispatches mouse and keyboard events, specified by theEvent, sent to the receiver by the NSApplication object.

public void sendEvent(NSEvent theEvent)

Discussion

Never invoke this method directly. A right mouse-down event in a window of an inactive application is not delivered to NSWindow. It is instead delivered to NSApplications’s sendEvent with a window number of 0.

setAcceptsMouseMovedEvents

Sets whether the receiver accepts mouse-moved events and distributes them to its responders.

public void setAcceptsMouseMovedEvents(boolean flag)

Discussion

If flag is true it does accept them; if flag is false it doesn’t. NSWindows don’t accept mouse-moved events by default.

See Also

setAllowsToolTipsWhenApplicationIsInactive

Sets whether the receiver can display tool tips even when the application is in the background.

public void setAllowsToolTipsWhenApplicationIsInactive(boolean allowWhenInactive)

Discussion

Default is false. The message does not take effect until the receiver changes to an active state. Note that enabling tool tips in an inactive application will cause the application to do work any time the mouse passes over the window, thus degrading system performance.

Availability
See Also

setAlphaValue

Applies windowAlpha to the entire window.

public void setAlphaValue(float windowAlpha)

See Also

setAspectRatio

Sets the receiver’s size aspect ratio to ratio, constraining the size of its frame rectangle to integral multiples of this size when the user resizes it.

public void setAspectRatio(NSSize ratio)

Discussion

An NSWindow’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, you send the NSWindow object a setResizeIncrements message with the width and height set to 1.0.

The setContentAspectRatio method takes precedence over this method.

See Also

setAutodisplay

Sets whether the receiver automatically displays its views that are marked as needing it.

public void setAutodisplay(boolean flag)

Discussion

If flag is true, views are automatically displayed as needed, typically on each pass through the event loop. If flag is false, the receiver or its views must be explicitly displayed.

See Also

setAutorecalculatesKeyViewLoop

If flag is true, the window recalculates the key view loop automatically when views are added or removed.

public void setAutorecalculatesKeyViewLoop(boolean flag)

Discussion

If flag is false, the client code must update the key view loop manually or call recalculateKeyViewLoop to have the window recalculate it.

Availability
See Also

setBackgroundColor

Sets the receiver’s background color to aColor.

public void setBackgroundColor(NSColor aColor)

See Also

setBackingType

Sets the receiver’s backing store type to backingType.

public void setBackingType(int backingType)

Discussion

The valid backing store types are described in the constants section.

This method can only be used to switch a buffered NSWindow to retained or vice versa; you can’t change the backing type to or from nonretained after initializing an NSWindow (an error is generated if you attempt to do so).

See Also

setCanHide

Sets whether the receiver can be hidden during NSApplication’s hide to flag.

public void setCanHide(boolean flag)

See Also

setContentAspectRatio

Sets the aspect ratio of the receiver’s content view to ratio, constraining the dimensions of its content rectangle to integral multiples of that ratio when the user resizes it.

public void setContentAspectRatio(NSSize ratio)

Discussion

You can set a window’s content view to any size programmatically, regardless of its aspect ratio. This method takes precedence over setAspectRatio.

Availability
See Also

setContentMaxSize

Sets the maximum size of the receiver’s content view to size, which is expressed in the receiver’s base coordinate system.

public void setContentMaxSize(NSSize size)

Discussion

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. This method takes precedence over setMaxSize.

Availability
See Also

setContentMinSize

Sets the minimum size of the receiver’s content view to size, which is expressed in the receiver’s base coordinate system.

public void setContentMinSize(NSSize size)

Discussion

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. This method takes precedence over setMinSize.

Availability
See Also

setContentResizeIncrements

Sets the increments for both height and width by which the receiver’s content view can be resized to increments.

public void setContentResizeIncrements(NSSize increments)

Discussion

The increments value constrains the width and height of the content rectangle to change by multiples of increments.width and increments.height when the user resizes the window. You can set a window’s size to any width and height programmatically. This method takes precedence over setResizeIncrements.

Availability
See Also

setContentSize

Sets the size of the receiver’s content view to aSize, which is expressed in the receiver’s base coordinate system.

public void setContentSize(NSSize aSize)

Discussion

This size in turn alters the size of the NSWindow itself. Note that the window server limits window sizes to 10,000; if necessary, be sure to limit aSize relative to the frame rectangle.

See Also

setContentView

Makes aView the receiver’s content view; the previous content view is removed from the receiver’s view hierarchy.

public void setContentView(NSView aView)

Discussion

The receiver retains the new content view and owns it thereafter. aView is resized to fit precisely within the content area of the NSWindow. 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.

See Also

setDefaultButtonCell

Makes the key equivalent of aButtonCell the Return (or Enter) key, so when the user presses Return that button performs as if clicked.

public void setDefaultButtonCell(NSButtonCell aButtonCell)

Discussion

See the method description for defaultButtonCell for more information.

See Also

setDelegate

Makes anObject the receiver’s delegate, without retaining it.

public void setDelegate(Object anObject)

Discussion

An NSWindow’s delegate is inserted in the responder chain after the NSWindow itself and is informed of various actions by the NSWindow through delegation messages.

See Also

setDepthLimit

Sets the depth limit of the receiver to limit.

public void setDepthLimit(int limit)

Discussion

Passing a value of 0 for limit sets the depth limit to the receiver’s default depth limit; using a value of 0 can be useful for reverting an NSWindow to its initial depth.

See Also

setDisplaysWhenScreenProfileChanges

Sets whether the window context should be updated when the screen profile changes.

public void setDisplaysWhenScreenProfileChanges(boolean flag)

Discussion

If flag is false, the screen profile information for the window context never changes. This is the default setting. If flag is true, the window context may be changed in the following situations:

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

Availability
See Also

setDocumentEdited

Sets whether the receiver’s document has been edited and not saved to flag.

public void setDocumentEdited(boolean flag)

Discussion

NSWindows are in the “not edited” state by default.

You should invoke this method with an argument of true every time the NSWindow’s document changes in such a way that it needs to be saved and with an argument of false every time it gets saved. Then, before closing the NSWindow you can use isDocumentEdited to determine whether to allow the user a chance to save the document.

setDynamicDepthLimit

Sets whether the receiver 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.

public void setDynamicDepthLimit(boolean flag)

Discussion

If flag is true, the depth limit depends on which screen the receiver is on. If flag is false, the receiver uses either its preset depth limit or the default depth limit. A different, and nondynamic, depth limit can be set with the setDepthLimit method.

See Also

setExcludedFromWindowsMenu

Sets whether the receiver’s title is omitted from the application’s Windows menu.

public void setExcludedFromWindowsMenu(boolean flag)

Discussion

If flag is true it’s omitted; if flag is false, it’s listed when it or its miniaturized window is onscreen. The default is false.

See Also

setFrame

Sets the origin and size of the receiver’s frame rectangle according to frameRect, thereby setting its position and size onscreen, and passes a displayIfNeeded message down the receiver’s view hierarchy, thus redrawing all NSViews that need to be displayed, if flag is true.

public void setFrame(NSRect frameRect, boolean flag)

Discussion

Note that the window server limits window position coordinates to ±16,000 and sizes to 10,000.

See Also

If animationFlag is false, equivalent to the preceding version of this method. Otherwise, if animationFlag is true, this method performs a smooth resize of the window, where the total time for the resize is specified by animationResizeTime.

public void setFrame(NSRect frameRect, boolean displayFlag, boolean animationFlag)

setFrameAutosaveName

Sets the name used to automatically save the receiver’s frame rectangle in the defaults system to name.

public boolean setFrameAutosaveName(String name)

Discussion

If name isn’t the empty string (“”), the receiver’s frame is saved as a user default (as described in saveFrameUsingName) each time the frame changes. Returns true if the name is set successfully, false if it’s being used as an autosave name by another NSWindow in the application (in which case the receiver’s old name remains in effect).

If there is a frame rectangle previously stored for name in the user defaults, the receiver’s frame is set to this frame rectangle. That is, when you call setFrameAutosaveName with a previously used name, the window picks up the previously saved setting.

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.

See Also

setFrameFromString

Sets the receiver’s frame rectangle from the string representation aString, a representation previously creating using stringWithSavedFrame.

public void setFrameFromString(String aString)

Discussion

The frame is constrained according to the receiver’s minimum and maximum size settings. This method causes a windowWillResize message to be sent to the delegate.

setFrameOrigin

Positions the lower-left corner of the receiver’s frame rectangle at aPoint in screen coordinates.

public void setFrameOrigin(NSPoint aPoint)

Discussion

Note that the window server limits window position coordinates to ±16,000.

See Also

setFrameTopLeftPoint

Positions the top-left corner of the receiver’s frame rectangle at aPoint in screen coordinates.

public void setFrameTopLeftPoint(NSPoint aPoint)

Discussion

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.

See Also

setFrameUsingName

Sets the receiver’s frame rectangle by reading the rectangle data stored in name from the defaults system.

public boolean setFrameUsingName(String name)

Discussion

The frame is constrained according to the receiver’s minimum and maximum size settings. This method causes a windowWillResize message to be sent to the delegate. Returns true if name is read and the frame is set successfully; otherwise returns false.

See Also

Sets the receiver’s frame rectangle by reading the rectangle data stored in name from the defaults system. Send this method with force set to true to use the preceding version of this method on a nonresizable window.

public boolean setFrameUsingName(String name, boolean force)

setHasShadow

Sets whether the receiver has a shadow to hasShadow.

public void setHasShadow(boolean hasShadow)

Discussion

If the shadow setting changes, the window shadow is invalidated, forcing the window shadow to be recomputed.

See Also

setHidesOnDeactivate

Sets whether the receiver is removed from the screen when the application is inactive.

public void setHidesOnDeactivate(boolean flag)

Discussion

If flag is true, the receiver is hidden (taken out of the screen list) when the application stops being the active application. If flag is false, the receiver stays onscreen. The default for NSWindow is false; the default for NSPanel is true.

See Also

setIgnoresMouseEvents

Specifies whether the receiver is transparent to mouse clicks and other mouse events, allowing overlay windows.

public void setIgnoresMouseEvents(boolean flag)

Availability
See Also

setInitialFirstResponder

Sets aView as the NSView that’s made first responder (also called the key view) the first time the receiver is placed onscreen.

public void setInitialFirstResponder(NSView aView)

See Also

setLevel

Sets the receiver’s window level to newLevel.

public void setLevel(int newLevel)

Discussion

Some useful predefined values, ordered from lowest to highest, are described in the constants section.

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 TornOffMenuWindowLevel is preferable to its synonym, SubmenuWindowLevel.

See Also

setMaxSize

Sets the maximum size to which the receiver’s frame (including its title bar) can be sized to aSize.

public void setMaxSize(NSSize aSize)

Discussion

The maximum size constraint is enforced for resizing by the user as well as for the setFrame... methods other than setFrame. Note that the window server limits window sizes to 10,000.

The default maximum size of a window is {FLT_MAX, FLT_MAX}. 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.

See Also

setMiniwindowImage

Sets the receiver’s custom miniaturized window image to anImage.

public void setMiniwindowImage(NSImage anImage)

Discussion

When the user minimizes the window, the dock displays anImage 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 miniaturized window image. Typically, you would specify a custom image immediately prior to a window being minimized—when the system posts an WindowWillMiniaturizeNotification. 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 true 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.

See Also

setMiniwindowTitle

Sets the title of the receiver’s miniaturized counterpart to aString and redisplays it.

public void setMiniwindowTitle(String aString)

Discussion

A miniaturized window’s title normally reflects that of its full-size counterpart, abbreviated to fit if necessary. Although this method allows you to set the miniaturized window’s title explicitly, changing the full-size NSWindow’s title (through setTitle or setTitleWithRepresentedFilename) automatically changes the miniaturized window’s title as well.

See Also

setMinSize

Sets the minimum size to which the receiver’s frame (including its title bar) can be sized to aSize.

public void setMinSize(NSSize aSize)

Discussion

The minimum size constraint is enforced for resizing by the user as well as for the setFrame... methods other than setFrame.

The setContentMinSize takes precedence over this method.

See Also

setMovableByWindowBackground

Sets whether the receiver is movable by clicking and dragging anywhere in its background.

public void setMovableByWindowBackground(boolean flag)

Discussion

A window with a style mask of TexturedBackgroundWindowMask get set to true by default. Sheets and drawers cannot be movable by window background.

Availability
See Also

setOneShot

Sets whether the window device that the receiver manages should be freed when it’s removed from the screen list (and another one created if it’s returned to the screen) to flag.

public void setOneShot(boolean flag)

Discussion

Freeing the window device when it’s removed from the screen list can result in memory savings and performance improvement for NSWindows that don’t take long to display. It’s particularly appropriate for NSWindows the user might use once or twice but not display continually. The default is false.

See Also

setOpaque

Sets whether the receiver is opaque to isOpaque.

public void setOpaque(boolean isOpaque)

See Also

setParentWindow

For use by subclasses when setting the parent window in the receiver.

public void setParentWindow(NSWindow window)

Discussion

You should call super if overriding.

Availability
See Also

setPreservesContentDuringLiveResize

If flag is true, the window optimizes live resize operations by invalidating only the view contents that changed; this is the default setting.

public void setPreservesContentDuringLiveResize(boolean flag)

Discussion

If flag is false, this optimization is disabled for the window and all of its contained views.

You might consider disabling this optimization for the window if none of the window’s contained views can take advantage of it. Disabling the optimization for the window prevents it from checking each view to see if the optimization is supported.

Availability
See Also

setReleasedWhenClosed

Sets whether the receiver is merely hidden (false) or hidden and then released (true) when it receives a close message.

public void setReleasedWhenClosed(boolean flag)

Discussion

The default for NSWindow is true; the default for NSPanel is false. Release when closed, however, is ignored for windows owned by window controllers.

See Also

setRepresentedFilename

Sets the name of the file the receiver represents to path.

public void setRepresentedFilename(String path)

See Also

setResizeIncrements

Restricts the user’s ability to resize the receiver so the width and height change by multiples of increments.width and increments.height as the user resizes the window.

public void setResizeIncrements(NSSize increments)

Discussion

The width and height increments should be whole numbers, 1.0 or greater. Whatever the current resize increments, you can set an NSWindow’s size to any height and width programmatically.

Resize increments and aspect ratio are mutually exclusive attributes. For more information, see setAspectRatio.

The setContentResizeIncrements method takes precedence over this method.

See Also

setShowsResizeIndicator

Sets whether the receiver’s resize indicator is visible to show.

public void setShowsResizeIndicator(boolean show)

Discussion

This method does not affect whether the receiver is resizable.

See Also

setShowsToolbarButton

If flag is true, the window title bar is updated to display the standard toolbar button.

public void setShowsToolbarButton(boolean flag)

Discussion

If flag is false, the button is not displayed. If the window does not have a toolbar, this method has no effect.

Availability
See Also

setTitle

Sets the string that appears in the receiver’s title bar (if it has one) to aString and displays the title.

public void setTitle(String aString)

Discussion

Also sets the title of the receiver’s miniaturized window.

See Also

setTitleWithRepresentedFilename

Sets path as the receiver’s title, formatting it as a file-system path, and records path as the receiver’s associated filename using setRepresentedFilename.

public void setTitleWithRepresentedFilename(String path)

Discussion

The filename—not the pathname—is displayed in the receiver’s title bar.

This method also sets the title bar of the receiver’s minimized window.

See Also

setToolbar

Sets the receiver’s toolbar to toolbar.

public void setToolbar(NSToolbar toolbar)

Discussion

See the NSToolbar class description for additional information.

See Also

setViewsNeedDisplay

Sets whether the receiver’s views need display (true) or do not need display (false) to flag.

public void setViewsNeedDisplay(boolean flag)

Discussion

You should rarely need to invoke this method; NSView’s setNeedsDisplay and similar methods invoke it automatically.

See Also

setWindowController

Set’s the receiver’s window controller to be windowController.

public void setWindowController(NSWindowController windowController)

See Also

showsResizeIndicator

Returns whether the receiver’s resize indicator is visible.

public boolean showsResizeIndicator()

See Also

showsToolbarButton

Returns true if the standard toolbar button is currently displayed; otherwise, returns false.

public boolean showsToolbarButton()

Availability
See Also

standardWindowButton

Return the given standard button if it is in the window view hierarchy.

public NSButton standardWindowButton(int button)

Availability
See Also

stringWithSavedFrame

Returns a string that represents the receiver’s frame rectangle in a format that can be used with a later setFrameFromString message.

public String stringWithSavedFrame()

styleMask

Returns the receiver’s style mask, indicating what kinds of control items it displays.

public int styleMask()

Discussion

See the information about the style mask in the constants section. An NSWindow’s style is set when the object is initialized. Once set, it can’t be changed.

title

Returns either the string that appears in the title bar of the receiver, or the path to the represented file.

public String title()

Discussion

If the title has been set using setTitleWithRepresentedFilename, then this method returns the file’s path, as described in setTitleWithRepresentedFilename.

See Also

toggleToolbarShown

The action method for the “Hide Toolbar” menu item (which alternates with “Show Toolbar”).

public void toggleToolbarShown(Object sender)

Discussion

See the NSToolbar class description for additional information.

toolbar

Returns the receiver’s toolbar.

public NSToolbar toolbar()

Discussion

See the NSToolbar class description for additional information.

See Also

tryToPerform

Dispatches action messages with anObject as the argument.

public boolean tryToPerform(NSSelector anAction, Object anObject)

Discussion

The receiver tries to perform the method anAction using its inherited NSResponder method tryToPerform. If the receiver doesn’t perform anAction, the delegate is given the opportunity to perform it. If either the receiver or its delegate accepts anAction, this method returns true; otherwise it returns false.

unregisterDraggedTypes

Unregisters the receiver as a possible destination for dragging operations.

public void unregisterDraggedTypes()

See Also

update

Updates the window.

public void update()

Discussion

The default implementation of this method does nothing more than post a WindowDidUpdateNotification to the default notification center. A subclass can override this method to perform specialized operations, but should send an update message to super just before returning. For example, the NSMenu class implements this method to disable and enable menu commands.

An NSWindow is automatically sent an update message on every pass through the event loop and before it’s displayed onscreen. You can manually cause an update message to be sent to all visible NSWindows through NSApplication’s updateWindows method.

See Also

useOptimizedDrawing

Informs the receiver whether to optimize focusing and drawing when displaying its NSViews.

public void useOptimizedDrawing(boolean flag)

Discussion

The optimizations may prevent sibling subviews from being displayed in the correct order—which matters only if the subviews overlap. You should always set flag to true if there are no overlapping subviews within the NSWindow. The default is false.

userSpaceScaleFactor

Returns the scale factor applied to the window.

public float userSpaceScaleFactor()

Discussion

Clients can multiply view coordinates by the returned scale factor to get a set of new coordinates that are scaled to the resolution of the target screen. For example, if the scale factor is 1.25 and the view frame size is 80 x 80, the actual size of the view frame is 100 x 100 pixels on the target screen.

Availability

validRequestorForTypes

Searches for an object that responds to a Services request by providing input of sendType and accepting output of returnType.

public Object validRequestorForTypes(String sendType, String returnType)

Discussion

Returns that object, or null if none is found.

Messages to perform this method are initiated by the Services menu. It’s part of the mechanism that passes validRequestorForTypes messages up the responder chain.

This method works by forwarding the message to the receiver’s delegate if it responds (and provided it isn’t an NSResponder with its own next responder). If the delegate doesn’t respond to the message or returns null when sent it, this method forwards the message to the NSApplication object. If the NSApplication object returns null, this method also returns null. Otherwise this method returns the object returned by the delegate or the NSApplication object.

See Also

viewsNeedDisplay

Returns true if any of the receiver’s NSView’s need to be displayed, false otherwise.

public boolean viewsNeedDisplay()

See Also

windowController

Returns the receiver’s window controller.

public Object windowController()

See Also

windowNumber

Returns the window number of the receiver’s window device.

public int windowNumber()

Discussion

Each window device in an application is given a unique window number—note that this isn’t the same as the global window number assigned by the window server. This number can be used to identify the window device with the orderWindow method.

If the receiver doesn’t have a window device, the value returned will be equal to or less than 0.

See Also

worksWhenModal

Returns true if the receiver is able to receive keyboard and mouse events even when some other window is being run modally, false otherwise.

public boolean worksWhenModal()

Discussion

NSWindow’s implementation of this method returns false. Only subclasses of NSPanel should override this default.

See Also

zoom

This action method toggles the size and location of the window between its standard state (provided by the application as the “best” size to display the window’s data) and its user state (a new size and location the user may have set by moving or resizing the window).

public void zoom(Object sender)

Discussion

For more information on the standard and user states, see windowWillUseStandardFrame.

The zoom method is typically invoked after a user clicks the window’s zoom box but may also be invoked programmatically from the performZoom method. It performs the following steps:

  1. Invokes the windowWillUseStandardFrame method, if the delegate or the window class implements it, to obtain a “best fit” frame for the window. If neither the delegate nor the window class implements the method, uses a default frame that nearly fills the current screen, which is defined to be the screen containing the largest part of the window’s current frame.

  2. Adjusts the resulting frame, if necessary, to fit on the current screen.

  3. Compares the resulting frame to the current frame to determine whether the window’s standard frame is currently displayed. If the current frame is within a few pixels of the standard frame in size and location, it is considered a match.

  4. Determines a new frame. If the window is currently in the standard state, the new frame represents the user state, saved during a previous zoom. If the window is currently in the user state, the new frame represents the standard state, computed in step 1 above. If there is no saved user state because there has been no previous zoom, the size and location of the window do not change.

  5. Determines whether the window currently allows zooming. By default, zooming is allowed. If the window’s delegate implements the windowShouldZoom method, zoom invokes that method. If the delegate doesn’t implement the method but the window does, zoom invokes the window’s version. windowShouldZoom returns false if zooming is not currently allowed.

  6. If the window currently allows zooming, sets the new frame.

See Also

Constants

These constants specify the presence of a title and various buttons in an NSWindow’s border. Either it can be BorderlessWindowMask, or it can contain any of the following options, combined using the C bitwise OR operator:

Constant

Description

BorderlessWindowMask

The NSWindow displays none of the usual peripheral elements. Useful only for display or caching purposes.

TitledWindowMask

The NSWindow displays a title bar.

ClosableWindowMask

The NSWindow displays a close button.

MiniaturizableWindowMask

The NSWindow displays a miniaturize button.

ResizableWindowMask

The NSWindow displays a resize control.

TexturedBackgroundWindowMask

The NSWindow displays with a metal-textured background. Additionally, the NSWindow may be moved by clicking and dragging anywhere in the window background. A bordered window with this mask gets rounded bottom corners.

These constants specify how the drawing done in a window is buffered by the window device:

Constant

Description

Buffered

The NSWindow renders all drawing into a display buffer and then flushes it to the screen.

Retained

The NSWindow uses a buffer, but draws directly to the screen where possible and to the buffer for obscured portions.

NonRetained

The NSWindow draws directly to the screen without using any buffer.

These constants specify the window’s level. The stacking of levels takes precedence over the stacking of windows within each level. That is, even the bottom window in a level will obscure even the top window of the next level down. Levels are listed in order from lowest to highest. These constants are mapped (using #define) to corresponding elements in the window level enum in Core Graphics.

Constant

Description

NormalWindowLevel

The default level for NSWindow objects.

FloatingWindowLevel

Useful for floating palettes.

SubmenuWindowLevel

Reserved for submenus. Synonymous with TornOffMenuWindowLevel, which is preferred.

TornOffMenuWindowLevel

The level for a torn-off menu. Synonymous with SubmenuWindowLevel.

ModalPanelWindowLevel

The level for a modal panel.

MainMenuWindowLevel

Reserved for the application’s main menu.

StatusWindowLevel

The level for a status window.

PopUpMenuWindowLevel

The level for a pop-up menu.

ScreenSaverWindowLevel

The level for a screen saver.

These constants let you specify how a window is ordered relative to another window. For more information, see orderWindow.

Constant

Description

Above

Moves the window above the indicated window.

Below

Moves the window below the indicated window.

Out

Moves the window off the screen.

These constants specify the direction a window is currently using to change the key view. They’re used by keyViewSelectionDirection.

Constant

Description

DirectSelection

The receiver isn’t traversing the key view loop.

SelectingNext

The receiver is proceeding to the next valid key view.

SelectingPrevious

The receiver is proceeding to the previous valid key view.

These constants provide a way to access standard title bar widgets:

Constant

Description

WindowCloseButton

The close button.

WindowMiniaturizeButton

The miniaturize button.

WindowZoomButton

The zoom button.

WindowToolbarButton

The toolbar button.

WindowDocumentIconButton

The document icon button.

This constant provides a way to manage scaling factors:

Constant

Description

UnscaledWindowMask

Specifies that the window is created without any scaling factors applied. The client is responsible for all scaling operations in the window. Such a window returns 1.0 from its userSpaceScaleFactor method.

Available in Mac OS X v10.4 and later.

This constant controls the look of a window and its toolbar:

Constant

Description

UnifiedTitleAndToolbarWindowMask

Specifies a window whose toolbar and titlebar are rendered on a single continuous background.

Available in Mac OS X v10.4 and later.

Delegate Methods

windowDidBecomeKey

Sent by the default notification center immediately after an NSWindow has become key.

public abstract void windowDidBecomeKey(NSNotification aNotification)

Discussion

aNotification is always WindowDidBecomeKeyNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidBecomeMain

Sent by the default notification center immediately after an NSWindow has become main.

public abstract void windowDidBecomeMain(NSNotification aNotification)

Discussion

aNotification is always WindowDidBecomeMainNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidChangeScreen

Sent by the default notification center immediately after an NSWindow has changed screens.

public abstract void windowDidChangeScreen(NSNotification aNotification)

Discussion

aNotification is always WindowDidChangeScreenNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidChangeScreenProfile

Sent by the default notification center immediately after an NSWindow has changed screen display profiles.

public abstract void windowDidChangeScreenProfile(NSNotification aNotification)

Discussion

aNotification is always WindowDidChangeScreenProfileNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidDeminiaturize

Sent by the default notification center immediately after an NSWindow has been deminiaturized.

public abstract void windowDidDeminiaturize(NSNotification aNotification)

Discussion

aNotification is always WindowDidDeminiaturizeNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidEndSheet

Sent by the default notification center immediately after an NSWindow closes a sheet.

public abstract void windowDidEndSheet(NSNotification aNotification)

Discussion

aNotification is always WindowDidEndSheetNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidExpose

Sent by the default notification center immediately after an NSWindow has been exposed.

public abstract void windowDidExpose(NSNotification aNotification)

Discussion

aNotification is always WindowDidExposeNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidMiniaturize

Sent by the default notification center immediately after an NSWindow has been miniaturized.

public abstract void windowDidMiniaturize(NSNotification aNotification)

Discussion

aNotification is always WindowDidMiniaturizeNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidMove

Sent by the default notification center immediately after an NSWindow has been moved.

public abstract void windowDidMove(NSNotification aNotification)

Discussion

aNotification is always WindowDidMoveNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidResignKey

Sent by the default notification center immediately after an NSWindow has resigned its status as key window.

public abstract void windowDidResignKey(NSNotification)

Discussion

aNotification is always WindowDidResignKeyNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidResignMain

Sent by the default notification center immediately after an NSWindow has resigned its status as main window.

public abstract void windowDidResignMain(NSNotification aNotification)

Discussion

aNotification is always WindowDidResignMainNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidResize

Sent by the default notification center immediately after an NSWindow has been resized.

public abstract void windowDidResize(NSNotification aNotification)

Discussion

aNotification is always WindowDidResizeNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowDidUpdate

Sent by the default notification center immediately after an NSWindow receives an update message.

public abstract void windowDidUpdate(NSNotification aNotification)

Discussion

aNotification is always WindowDidUpdateNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowShouldClose

Invoked when the user attempts to close the window or when the NSWindow receives a performClose message.

public abstract boolean windowShouldClose(Object sender)

Discussion

The delegate can return false to prevent sender from closing.

This method may not always be called. Specifically, this method is not called when a user quits an application. Additional information on application termination can be found in Graceful Application Termination.

windowShouldZoom

Invoked just before sender is zoomed.

public abstract boolean windowShouldZoom(NSWindow sender, NSRect newFrame)

Discussion

Zooming will change the frame of sender to newFrame. The delegate can return false to prevent sender from zooming.

See Also

windowWillBeginSheet

Sent by the default notification center immediately before an NSWindow opens a sheet.

public abstract void windowWillBeginSheet(NSNotification aNotification)

Discussion

aNotification is always WindowWillBeginSheetNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowWillClose

Sent by the default notification center immediately before an NSWindow closes.

public abstract void windowWillClose(NSNotification aNotification)

Discussion

aNotification is always WindowWillCloseNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowWillMiniaturize

Sent by the default notification center immediately before an NSWindow is miniaturized.

public abstract void windowWillMiniaturize(NSNotification aNotification)

Discussion

aNotification is always WindowWillMiniaturizeNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowWillMove

Sent by the default notification center immediately before an NSWindow is moved.

public abstract void windowWillMove(NSNotification aNotification)

Discussion

aNotification is always WindowWillMoveNotification. You can retrieve the NSWindow object in question by sending object to aNotification.

windowWillPositionSheet

Sent to the delegate just before the animation of a sheet, giving it the opportunity to return a custom location for the attachment of the sheet (sheet) to the window (window).

public abstract NSRect windowWillPositionSheet(NSWindow window, NSWindow sheet, NSRect rect)

Discussion

This method is also invoked whenever the user resizes window while sheet is attached. The default sheet location, passed in rect, is just under the title bar of the window, aligned with the left and right edges of the window.

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 (though genie animation) or is positioned next to it.

Neither the rect parameter nor the returned NSRect 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 zero. The size.width value indicates the width and behavior of the initial animation; if size.width is narrower than the sheet, the sheet genies out from the specified location, and if size.width is wider than the sheet, the sheet slides out. You cannot affect the size of the sheet through the size.width and size.height fields. It is recommended that you specify zero for the size.height value as this field may have additional meaning in a future release.

Availability

windowWillResize

Invoked when sender is being resized (whether by the user or through one of the setFrame... methods other than setFrame).

public abstract NSSize windowWillResize(NSWindow sender, NSSize proposedFrameSize)

Discussion

proposedFrameSize contains the size (in screen coordinates) the sender will be resized to. To resize to a different size, simply return the desired size from this method; to avoid resizing, return the current size. The NSWindow’s minimum and maximum size constraints have already been applied when this method is invoked.

While the user is resizing an NSWindow, the delegate is sent a series of windowWillResize messages as the NSWindow’s outline is dragged. The NSWindow’s outline is displayed at the constrained size as set by this method.

windowWillReturnFieldEditor

Invoked when the field editor of sender is requested by anObject.

public abstract Object windowWillReturnFieldEditor(NSWindow sender, Object anObject)

Discussion

If the delegate’s implementation of this method returns an object other than null, the NSWindow substitutes it for the field editor and returns it to anObject.

This method may be called multiple times while a control is first responder. Therefore, you must return the same field editor object for the control while the control is being edited.

See Also

windowWillReturnUndoManager

Invoked when the undo manager for sender is requested.

public abstract NSUndoManager windowWillReturnUndoManager(NSWindow sender)

Discussion

Returns the appropriate undo manager. If this method is not implemented, the NSWindow creates an NSUndoManager for the window.

windowWillUseStandardFrame

Invoked by the zoom method while determining a frame the sender may be zoomed to.

public abstract NSRect windowWillUseStandardFrame(NSWindow sender, NSRect defaultFrame)

Discussion

Returns the standard frame (described below) for a window. The defaultFrame parameter passed in is the size of the current screen, which is the screen containing the largest part of the window’s current frame, possibly reduced on the top, bottom, left, or right, depending on the current interface style. The frame is reduced on the top to leave room for the menu bar.

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

To customize the standard state, you implement windowWillUseStandardFrame in the class of the window’s delegate or, if necessary, in a window subclass. Your version should return a suitable standard frame, based on the currently displayed data or other factors.

See Also

Notifications

WindowDidBecomeKeyNotification

Posted whenever an NSWindow becomes the key window.

The notification object is the NSWindow that has become key. This notification does not contain a userInfo dictionary.

WindowDidBecomeMainNotification

Posted whenever an NSWindow becomes the main window.

The notification object is the NSWindow that has become main. This notification does not contain a userInfo dictionary.

WindowDidChangeScreenNotification

Posted whenever a portion of an NSWindow’s frame moves onto or off of a screen.

The notification object is the NSWindow that has changed screens. This notification does not contain a userInfo dictionary.

This notification is not sent in Mac OS X versions earlier than 10.4.

WindowDidChangeScreenProfileNotification

Posted whenever the display profile for the screen containing the window changes.

This notification is sent only if the window returns true from displaysWhenScreenProfileChanges. This notification may be sent when a majority of the window is moved to a different screen (whose profile is also different from the previous screen) or when the ColorSync profile for the current screen changes.

The notification object is the NSWindow whose profile changed. This notification does not contain a userInfo dictionary.

Availability

WindowDidDeminiaturizeNotification

Posted whenever an NSWindow is deminiaturized.

The notification object is the NSWindow that has been deminiaturized. This notification does not contain a userInfo dictionary.

WindowDidEndSheetNotification

Posted whenever an NSWindow closes an attached sheet.

The notification object is the NSWindow that contained the sheet. This notification does not contain a userInfo dictionary.

WindowDidExposeNotification

Posted whenever a portion of a nonretained NSWindow is exposed, whether by being ordered in front of other windows or by other windows being removed from in front of it.

The notification object is the NSWindow that has been exposed. The userInfo dictionary contains the following information:

Key

Value

"NSExposedRect"

The rectangle that has been exposed (NSRect).

WindowDidMiniaturizeNotification

Posted whenever an NSWindow is miniaturized.

The notification object is the NSWindow that has been miniaturized. This notification does not contain a userInfo dictionary.

WindowDidMoveNotification

Posted whenever an NSWindow is moved.

The notification object is the NSWindow that has moved. This notification does not contain a userInfo dictionary.

WindowDidResignKeyNotification

Posted whenever an NSWindow resigns its status as key window.

The notification object is the NSWindow that has resigned its key window status. This notification does not contain a userInfo dictionary.

WindowDidResignMainNotification

Posted whenever an NSWindow resigns its status as main window.

The notification object is the NSWindow that has resigned its main window status. This notification does not contain a userInfo dictionary.

WindowDidResizeNotification

Posted whenever an NSWindow’s size changes.

The notification object is the NSWindow whose size has changed. This notification does not contain a userInfo dictionary.

WindowDidUpdateNotification

Posted whenever an NSWindow receives an update message.

The notification object is the NSWindow that received the update message. This notification does not contain a userInfo dictionary.

WindowWillBeginSheetNotification

Posted whenever an NSWindow is about to open a sheet.

The notification object is the NSWindow that is about to open the sheet. This notification does not contain a userInfo dictionary.

WindowWillCloseNotification

Posted whenever an NSWindow is about to close.

The notification object is the NSWindow that is about to close. This notification does not contain a userInfo dictionary.

WindowWillMiniaturizeNotification

Posted whenever an NSWindow is about to be miniaturized.

The notification object is the NSWindow that is about to be miniaturized. This notification does not contain a userInfo dictionary.

WindowWillMoveNotification

Posted whenever an NSWindow is about to move.

The notification object is the NSWindow that is about to move. This notification does not contain a userInfo dictionary.



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.