ftp.nice.ch/peanuts/GeneralData/Documents/openstep/OpenStepSpec_rtf.tar.gz#/OpenStepSpec_rtf/ApplicationKit/Classes/NSWindow.rtf

This is NSWindow.rtf in view mode; [Download] [Up]

Copyright ©1994 by NeXT Computer, Inc.  All Rights Reserved.


NSWindow 

Inherits From:tab NSResponder : NSObject

Conforms To:tab NSCoding (NSResponder)
NSObject (NSObject)

Declared In:tab AppKit/NSWindow.h 


Class Description


The NSWindow class defines objects that manage and coordinate the windows that an application displays on the screen. A single NSWindow object corresponds to, at most, one window. The two principle functions of an NSWindow are to provide an area in which views can be placed, and to accept and distribute, to the appropriate NSViews, events that the user instigates by manipulating the mouse and keyboard.


Rectangles, Views, and the View Hierarchy

An NSWindow is defined by a frame rectangle that encloses the entire window, including its title bar, resize bar, and border, and by a content rectangle that encloses just its content area. Both rectangles are specified in the screen coordinate system. The frame rectangle establishes the NSWindow's base coordinate system. This coordinate system is always aligned with and is measured in the same increments as the screen coordinate system (in other words, the base coordinate system can't be rotated or scaled). The origin of a base coordinate system is the bottom left corner of the window's frame rectangle. 

You create an NSWindow (through one of the init:... methods) by specifying, among other attributes, the size and location of its content rectangle. The frame rectangle is derived from the dimensions of the content rectangle.

When it's created, an NSWindow automatically creates two NSViews: an opaque frame view and a transparent content view that fills the content area. The frame view is a private object that your application can't access directly. The content view is the ªhighestº accessible view in the window; you can replace the content view with an NSView of your own creation through NSWindow's setContentView: method. 

You add other views to the window by declaring each to be a subview of the content view, or a subview of one of the content view's subviews, and so on, through NSView's addSubview: method. This tree of views is called the window's view hierarchy. When an NSWindow is told to display itself, it does so by sending view-displaying messages to each object in its view hierarchy. Because displaying is carried out in a determined order, the content view (which is drawn first) may be wholly or partially obscured by its subviews, and these subviews may be obscured by their subviews (and so on). 


Event Handling

The window system and the NSApplication object forward mouse and keyboard events to the appropriate NSWindow object. The NSWindow that's currently designated to receive keyboard events is known as the key window. If the mouse or keyboard event affects the window directlyÐresizing or moving it, for exampleÐthe NSWindow performs the appropriate operation itself and sends messages to its delegate informing it of its intentions, thus allowing your application to intercede. Events that are directed at specific views within the window are forwarded by the NSWindow to the NSView. 

The NSWindow keeps track of the object that was last selected to handle keyboard events as its first responder. The first responder is typically the NSView that displays the current selection. In addition to keyboard events, the first responder is sent action messages that have a user-selected target (a nil target in program code). The NSWindow continually updates the first responder in response to the user's mouse actions.

Each NSWindow provides a field editor, an NSText object that handles small-scale text-editing chores. The field editor can be used by the NSWindow's first responder to edit the text that it displays. The fieldEditor:forObject: method returns the NSWindow's field editor. (You can make this method instead return an alternative NSText object, appropriate for the object specified the second argument, by implementing the delegate method windowWillReturnFieldEditor:toObject:.)


Initializing and Getting a New NSWindow Object 


- (id)initWithContentRect:(NSRect)contentRecttab Initializes the new window object with a location and 
styleMask:(unsigned int)aStyletab  tab size for content of contentRect, a window style and
backing:(NSBackingStoreType)bufferingTypetab buttons as indicated in the bitmap mask aStyle, drawing 
defer:(BOOL)flagtab  tab buffering as indicated by bufferingType. If flag is YES, 
tab  tab the window system defers creating the window until it's needed.

- (id)initWithContentRect:(NSRect)contentRecttab Initializes the new window object for a screen as specified 
styleMask:(unsigned int)aStyletab  tab by aScreen, with a location and size for content of 
backing:(NSBackingStoreType)bufferingTypetab contentRect, a window style and buttons as indicated in
defer:(BOOL)flagtab tab the bitmap mask aStyle, drawing buffering as indicated 
screen:(NSScreen *)aScreentab tab by bufferingType. If flag is YES,the window system defers creating the window until it's needed.

Computing Frame and Content Rectangles 


+ (NSRect)contentRectForFrameRect:(NSRect)aRect
styleMask:(unsigned int)aStyletab Gets the content rectangle for frame rectangle aRect in a window of type aStyle.

+ (NSRect)frameRectForContentRect:(NSRect)aRect
styleMask:(unsigned int)aStyletab Gets the frame rectangle for content rectangle aRect in a window of type aStyle.

+ (float)minFrameWidthWithTitle:(NSString *)aTitle
styleMask:(unsigned int)aStyletab Returns the minimum frame width needed for aTitle in a window of type aStyle.

Accessing the Content View 


- (id)contentViewtab Returns the NSWindow's content view. 

- (void)setContentView:(NSView *)aViewtab Makes aView the NSWindow's content view. 

Window Graphics 


- (NSColor *)backgroundColortab Returns the window's background color. 

- (NSString *)representedFilenametab Returns the filename associated with this window (regardless of the title string).

- (void)setBackgroundColor:(NSColor *)colortab Sets the window's background color to color. 

- (void)setRepresentedFilename:(NSString *)aString
tab  Alters aString by formatting it as a path and filename, then sets the filename associated with this window to the result.  If filename doesn't include a path to the file, the current working directory is used. This method doesn't affect the title string.

- (void)setTitle:(NSString *)aStringtab Makes aString the window's title. 

- (void)setTitleWithRepresentedFilename:(NSString *)aString
tab Invokes setRepresentedFilename: and makes the resultant string the window's title.

- (unsigned int)styleMasktab Returns the window's border and title-bar style. 

- (NSString *)titletab Returns the window's title string. 

Window Device Attributes 


- (NSBackingStoreType)backingTypetab Returns the type of the window device's backing store. 

- (NSDictionary *)deviceDescriptiontab Returns the window device's attributes as key/value pairs.

- (int)gStatetab Returns the graphics-state object for the window object.

- (BOOL)isOneShottab Returns whether backing-store memory for the window is freed when the window is ordered off-screen.

- (void)setBackingType:(NSBackingStoreType)typetab Sets the type of window-device backing store. 

- (void)setOneShot:(BOOL)flagtab Sets whether backing-store memory for the window should be freed when the window is ordered off-screen.

- (int)windowNumbertab Returns the window number. 

The Miniwindow 


- (NSImage *)miniwindowImagetab Returns the image that's displayed in the miniwindow. 

- (NSString *)miniwindowTitletab Returns the title that's displayed in the miniwindow. 

- (void)setMiniwindowImage:(NSImage *)imagetab Sets the image that's displayed in the miniwindow. 

- (void)setMiniwindowTitle:(NSString *)titletab Sets the title that's displayed in the miniwindow. 

The Field Editor 


- (void)endEditingFor:(id)anObjecttab Ends the field editor's editing assignment for anObject. 

- (NSText *)fieldEditor:(BOOL)createFlagtab Returns the window object's field editor for anObject.
forObject:(id)anObjecttab  tab If the field editor does not exist and createFlag is YES, creates a field editor. 

Window Status and Ordering


- (void)becomeKeyWindowtab Records the window's new status as the key window. This method posts the notification NSWindowDidBecomeKeyNotification with the receiving object to the default notification center.

- (void)becomeMainWindowtab Records the window's new status as the main window. This method posts the notification NSWindowDidBecomeMainNotification with the receiving object to the default notification center.

- (BOOL)canBecomeKeyWindowtab Returns whether the receiving window object can be the key window. 

- (BOOL)canBecomeMainWindowtab Returns whether the receiving window object can be the main window. 

- (BOOL)hidesOnDeactivatetab Returns whether deactivation hides the window. 

- (BOOL)isKeyWindowtab Returns whether the receiving window object is the key window. 

- (BOOL)isMainWindowtab Returns whether the receiving window object is the main window. 

- (BOOL)isMiniaturizedtab Returns whether the window is hidden (and the miniwindow displayed). 

- (BOOL)isVisibletab Returns whether the window object is in the screen list (and thus visible). 

- (int)leveltab Returns the current window level.

- (void)makeKeyAndOrderFront:(id)sendertab Makes the receiving window object the key window and brings it forward. 

- (void)makeKeyWindowtab Makes the receiving window object the key window. 

- (void)makeMainWindowtab Makes the receiving window object the main window. 

- (void)orderBack:(id)sendertab Puts the window object at the back of its tier. 

- (void)orderFront:(id)sendertab Puts the window object at the front of its tier. 

- (void)orderFrontRegardlesstab Puts the window object at the front even if the application is inactive. If the window is currently miniaturized, this method posts the notification NSWindowDidDeminiaturizeNotification with the window object to the default notification center.

- (void)orderOut:(id)sendertab Removes the window object from the screen list. 

- (void)orderWindow:(NSWindowOrderingMode)place
relativeTo:(int)otherWintab  Repositions the window object in the screen list in position place relative to another window. If the window is currently miniaturized, this method posts the NSWindowDidDeminiaturizeNotification notification with that window object to the default notification center.

- (void)resignKeyWindowtab Records that the window object is no longer the key window. This method posts the notification NSWindowDidResignKeyNotification with the receiving object to the default notification center. 

- (void)resignMainWindowtab Records that the window object is no longer the main window. This method posts the notification NSWindowDidResignMainNotification with the receiving object to the default notification center. 

- (void)setHidesOnDeactivate:(BOOL)flagtab Sets whether deactivation hides the window. 

- (void)setLevel:(int)newLeveltab Resets the window level to newLevel.

Moving and Resizing the Window 


- (NSPoint)cascadeTopLeftFromPoint:(NSPoint)topLeftPoint
tab When successively invoked, tiles windows by offsetting them slightly to the right and down from the previous window. Returns the top left point of the placed window, which is typically used for topLeftPoint in the next invocation. If you specify (0,0), places the window as is, and returns its top left point.

- (void)centertab Centers the window on the screen. 

- (NSRect)constrainFrameRect:(NSRect)frameRect
toScreen:(NSScreen *)screentab Constrains the window's frame rectangle frameRect to screen. Returns the frame rectangle.

- (NSRect)frametab Returns the window's frame rectangle 

- (NSSize)minSizetab Returns the window's minimum size. 

- (NSSize)maxSizetab Returns the window's maximum size 

- (void)setContentSize:(NSSize)aSizetab Resizes the window's content area to aSize.

- (void)setFrame:(NSRect)frameRect tab Moves and/or resizes the window frame to frameRect. flag
display:(BOOL)flagtab tab determines whether the window is displayed. This method posts the NSWindowDidResizeNotification notification with the receiving object to the default notification center.

- (void)setFrameOrigin:(NSPoint)aPointtab Moves the window by changing its frame origin to aPoint.

- (void)setFrameTopLeftPoint:(NSPoint)aPointtab Moves the window by changing its top-left corner to aPoint.

- (void)setMinSize:(NSSize)aSizetab Sets the window's minimum size. 

- (void)setMaxSize:(NSSize)aSizetab Sets the window's maximum size. 

Converting Coordinates 


- (NSPoint)convertBaseToScreen:(NSPoint)aPoint
tab Converts aPoint from base to screen coordinates. 

- (NSPoint)convertScreenToBase:(NSPoint)aPoint
tab Converts aPoint from screen to base coordinates. 

Managing the Display 


- (void)displaytab Displays all the window's views.

- (void)disableFlushWindowtab Disables flushing for a buffered window. 

- (void)displayIfNeededtab Displays all the window's views that need to be redrawn. 

- (void)enableFlushWindowtab Enables flushing for a buffered window.

- (void)flushWindowtab Flushes the window's buffer to the screen. 

- (void)flushWindowIfNeededtab Conditionally flushes the window's buffer to the screen. 

- (BOOL)isAutodisplaytab Returns whether the window displays all views requiring redrawing when update is invoked.

- (BOOL)isFlushWindowDisabledtab Returns whether flushing is disabled. 

- (void)setAutodisplay:(BOOL)flagtab Sets whether the window displays all views requiring redrawing when update is invoked.

- (void)setViewsNeedDisplay:(BOOL)flagtab Sets whether some views of the receiving window object should be redrawn.

- (void)updatetab Update's the window's display and cursor rectangles. This method is invoked after every event. When it successfully completes, it posts the NSWindowDidUpdateNotification notification.

- (void)useOptimizedDrawing:(BOOL)flagtab Sets whether the window's views should optimize drawing.

- (BOOL)viewsNeedDisplaytab Returns whether some views of the receiving NSWindow object should be redrawn.

Screens and Window Depths 


+ (NSWindowDepth)defaultDepthLimittab Returns the default depth limit for all windows. 

- (BOOL)canStoreColortab Returns whether the window is deep enough to store colors. 

- (NSScreen *)deepestScreentab Returns the deepest screen that the window is on. 

- (NSWindowDepth)depthLimittab Returns the window's depth limit. 

- (BOOL)hasDynamicDepthLimittab Returns whether the depth limit depends on the screen. 

- (NSScreen *)screentab Returns the screen that (most of) the window is on.

- (void)setDepthLimit:(NSWindowDepth)limittab Sets the window's depth limit to limit 

- (void)setDynamicDepthLimit:(BOOL)flagtab Sets whether the depth limit will depend on the screen. 

Cursor Management 


- (BOOL)areCursorRectsEnabledtab Returns whether cursor rectangles are enabled.

- (void)disableCursorRectstab Disables all cursor rectangles in the window object.

- (void)discardCursorRectstab Removes all cursor rectangles in the window object. 

- (void)enableCursorRectstab Enables cursor rectangles in the window object. 

- (void)invalidateCursorRectsForView:(NSView *)aView
tab Marks cursor rectangles invalid for aView. 

- (void)resetCursorRectstab Resets cursor rectangles for the window object. 

Handling User Actions and Events 


- (void)closetab Closes the window. When this method begins, it posts the notification NSWindowWillCloseNotification with the receiving object to the default notification center. 

- (void)deminiaturize:(id)sendertab Hides the miniwindow and redisplays the window. 

- (BOOL)isDocumentEditedtab Returns whether the window's document has been edited. 

- (BOOL)isReleasedWhenClosedtab Returns whether the window object is released when it is closed.

- (void)miniaturize:(id)sendertab Hides the window and displays its miniwindow. When this method begins, it posts the notification NSWindowWillMiniaturizeNotification with the receiving object to the default notification center. When it completes successfully, it posts NSWindowDidMiniaturizeNotification.

- (void)performClose:(id)sendertab Simulates user clicking the close button. 

- (void)performMiniaturize:(id)sendertab Simulates user clicking the miniaturize button. 

- (int)resizeFlagstab Returns the event modifier flags during resizing. 

- (void)setDocumentEdited:(BOOL)flagtab Sets whether the window's document has been edited. 

- (void)setReleasedWhenClosed:(BOOL)flagtab Sets whether closing the window object also releases it. 

Aiding Event Handling 


- (BOOL)acceptsMouseMovedEventstab Returns whether the NSWindow accepts mouse-moved events.

- (NSEvent *)currentEventtab Returns the current event object for the application.

- (void)discardEventsMatchingMask:(unsigned int)mask 
beforeEvent:(NSEvent *)lastEventtab Discards any events in the event queue that have a type indicated by bitmap mask until the method encounters the event lastEvent.

- (NSResponder *)firstRespondertab Returns the first responder to user events. 

- (void)keyDown:(NSEvent *)theEventtab Handles key-down events.

- (BOOL)makeFirstResponder:(NSResponder *)aResponder
tab Makes aResponder the first responder to user events. 

- (NSPoint)mouseLocationOutsideOfEventStreamtab Provides current location of the cursor. 

- (NSEvent *)nextEventMatchingMask:(unsigned int)mask
tab Returns the next event object for the application that matches the events indicated by event mask mask.

- (NSEvent *)nextEventMatchingMask:(unsigned int)mask 
untilDate:(NSDate *)expiration tab Returns the next event object for the application that
inMode:(NSString *)mode tab tab matches the events indicated by event mask mask, and 
dequeue:(BOOL)deqFlagtab  tab that occurs before time expiration; until expiration, the run loop runs in mode.

- (void)postEvent:(NSEvent *)event 
atStart:(BOOL)flagtab Post an event for the application; if atStart is YES, the event goes to the beginning of the event queue.

- (void)setAcceptsMouseMovedEvents:(BOOL)flag
tab Sets whether the NSWindow accepts mouse-moved events.

- (void)sendEvent:(NSEvent *)theEventtab Dispatches mouse and keyboard events. If this method is dispatching a window exposed event, it posts the NSWindowDidExposeNotification notification with the receiving object and, in the notification's dictionary, a rectangle describing the exposed area (with the key NSExposedRect) to the default notification center. If it is dispatching a screen changed event, it posts NSWindowDidChangeScreenNotification with the receiving object. If it is dispatching a window moved event, it posts NSWindowDidMoveNotification.

- (BOOL)tryToPerform:(SEL)anActiontab  Aids in dispatching action messages (anAction) to
with:(id)anObjecttab  tab anObject.

- (BOOL)worksWhenModaltab Override to return whether the window object accepts events when a modal panel is being run. Default is NO.

Dragging 


- (void)dragImage:(NSImage *)anImagetab  Initiates an image-dragging session. NSView invokes this
at:(NSPoint)baseLocationtab  tab method inside its implementation of mouseDown:. 
offset:(NSSize)initialOffset
event:(NSEvent *)event
pasteboard:(NSPasteboard *)pboard
source:(id)sourceObject
slideBack:(BOOL)slideFlag

- (void)registerForDraggedTypes:(NSArray *)newTypes
tab Registers the NSPasteboard types (newTypes) that the window object accepts in an image-dragging session. 

- (void)unregisterDraggedTypestab Unregisters the window object as a recipient of dragged images. 

Services and Windows Menu Support 


- (BOOL)isExcludedFromWindowsMenutab Returns whether the receiving window object is omitted from the Windows menu. 

- (void)setExcludedFromWindowsMenu:(BOOL)flag
tab Sets whether the receiving window object is omitted from the Windows menu. 

- (id)validRequestorForSendType:(NSString *)sendType
returnType:(NSString *)returnTypetab Returns whether the window can respond to a service with send and receive types sendType and returnType. 

Saving and Restoring the Frame 


+ (void)removeFrameUsingName:(NSString *)name
tab Removes the named frame rectangle from the system defaults. 

- (NSString *)frameAutosaveNametab Returns the name that's used to autosave the frame rectangle as a system default. 

- (void)saveFrameUsingName:(NSString *)nametab Saves the frame rectangle as a system default. 

- (BOOL)setFrameAutosaveName:(NSString *)name
tab Sets the name that's used to autosave the frame rectangle as a system default. 

- (void)setFrameFromString:(NSString *)stringtab Sets the frame rectangle from string, which encodes the position and dimensions of the frame rectangle and the position and dimensions of the screen. 

- (BOOL)setFrameUsingName:(NSString *)nametab Sets the frame rectangle from the named default.

- (NSString *)stringWithSavedFrametab Returns a string encoding the position and dimensions of the frame rectangle and the position and dimensions of the screen.

Printing and PostScript


- (NSData *)dataWithEPSInsideRect:(NSRect)rect tab 
tab Returns the encapsulated PostScript inside rect as a data object.

- (void)fax:(id)sendertab Faxes all the window's views. 

- (void)print:(id)sendertab Prints all the window's views. 

Assigning a Delegate 


- (id)delegatetab Returns the window object's delegate. 

- (void)setDelegate:(id)anObjecttab Makes anObject the window object's delegate.

Implemented by the Delegate 


- (BOOL)windowShouldClose:(id)sendertab Notifies delegate that the window is about to close. 

- (NSSize)windowWillResize:(NSWindow *)sender 
toSize:(NSSize)frameSizetab Lets delegate constrain resizing to frameSize.

- (id)windowWillReturnFieldEditor:(NSWindow *)sender 
toObject:(id)clienttab Lets delegate provide another text object for field editor. 

- (void)windowDidBecomeKey:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window is the key window. aNotification is always NSWindowDidBecomeKeyNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidBecomeMain:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window is the main window. aNotification is always NSWindowDidBecomeMainNotification. If the delegate implements this method, it's automatically registered to receive this notification. 

- (void)windowDidChangeScreen:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window changed screens. aNotification is always NSWindowDidChangeScreenNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidDeminiaturize:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window was restored to screen. aNotification is always NSWindowDidDeminiaturizeNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidExpose:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window was exposed. aNotification is always NSWindowDidExposeNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidMiniaturize:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window was miniaturized. aNotification is always NSWindowDidMiniaturizeNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidMove:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window did move. aNotification is always NSWindowDidMoveNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidResignKey:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window isn't the key window. aNotification is always NSWindowDidResignKeyNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidResignMain:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window isn't the main window. aNotification is always NSWindowDidResignMainNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidResize:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window was resized. aNotification is always NSWindowDidResizeNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowDidUpdate:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window was updated. aNotification is always NSWindowDidUpdateNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowWillClose:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window will close. aNotification is always NSWindowWillCloseNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowWillMiniaturize:(NSNotification *)aNotification 
tab Sent by the default notification center to notify the delegate that the window will be miniaturized. aNotification is always NSWindowWillMiniaturizeNotification. If the delegate implements this method, it's automatically registered to receive this notification.

- (void)windowWillMove:(NSNotification *)aNotification
tab Sent by the default notification center to notify the delegate that the window will move. aNotification is always NSWindowWillMoveNotification. If the delegate implements this method, it's automatically registered to receive this notification.

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.