# NSView

scottc@net-community.com
far@ix.netcom.com
ovidiu@net-community.com
richard@brainstorm.co.uk

The view class which encapsulates all drawing functionality

(C) 1996 Free Software Foundation, Inc.
NSView

NSView is an abstract class which provides facilities for drawing in a window and receiving events. It is the superclass of many of the visual elements of the GUI.

In order to display itself, a view must be placed in a window (represented by an NSWindow object). Within the window is a hierarchy of NSViews, headed by the window's content view. Every other view in a window is a descendant of this view.

Subclasses can override -drawRect: in order to implement their appearance. Other methods of NSView and NSResponder can also be overridden to handle user generated events.

AppKit/NSView.h
Description forthcoming.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.
defaultFocusRingType
Description forthcoming.
defaultMenu

Returns the default menu to be used for instances of the current class; if no menu has been set through setMenu: this default menu will be used.

NSView's implementation returns `nil` . You should override this method if you want all instances of your custom view to use the same menu.

focusView
Return the view at the top of graphics contexts stack or `nil` if none is focused.
acceptsFirstMouse:
theEvent
Returns `YES` if the view object will accept the first click received when in an inactive window, and `NO` otherwise.
addCursorRect:
aRect
cursor:
anObject
Adds a cursor rectangle. This provides for automatic update of the cursor to be anObject while the mouse is in aRect.
The cursor ( anObject) is retained until the cursor rectangle is removed or discarded.
Generally your subviews should call this in their implementation of the -resetCursorRects method.
It is your responsibility to ensure that aRect lies within your veiw's visible rectangle.
addSubview:
aView
Adds aView as a subview of the receiver.
addSubview:
aView
positioned:
place
relativeTo:
otherView
Description forthcoming.
addToPageSetup
Description forthcoming.
addToolTipRect:
aRect
owner:
anObject
userData:
data
Description forthcoming.
addTrackingRect:
aRect
owner:
anObject
userData:
data
assumeInside:
flag
Adds a tracking rectangle to monitor mouse movement and generate mouse-entered and mouse-exited events.
The event messages are sent to anObject, which is not retained and must therefore be sure to remove any tracking rectangles using it before it is deallocated.
The value of data is supplied as the user data in the event objects generated.
If flag is `YES` then the mouse is assumed to be inside the tracking rectangle and the first event generated will therefore be a mouse exit, if it is `NO` then the first event generated will be a mouse entry.
adjustPageHeightNew:
newBottom
top:
oldTop
bottom:
oldBottom
limit:
bottomLimit
Description forthcoming.
adjustPageWidthNew:
newRight
left:
oldLeft
right:
oldRight
limit:
rightLimit
Description forthcoming.
adjustScroll:
newVisible
Description forthcoming.
allocateGState

Tell the view to maintain a private gstate object which encapsulates all the information about drawing, such as coordinate transforms, line widths, etc. If you do not invoke this method, a gstate object is constructed each time the view is lockFocused. Allocating a private gstate may improve the performance of views that are focused a lot and have a lot of customized drawing parameters.

View subclasses should override the setUpGstate method to set these custom parameters.

ancestorSharedWithView:
aView
Returns self if aView is the receiver or aView is a subview of the receiver, the ancestor view shared by aView and the receiver if any, or aView if it is an ancestor of the receiver, otherwise returns `nil`.
autoresizesSubviews
Description forthcoming.
autoresizingMask
Description forthcoming.
autoscroll:
theEvent
Finds the nearest enclosing NSClipView and, if the location of the event is outside it, scrolls the NSClipView in the direction of the event. The amount scrolled is proportional to how far outside the NSClipView the event's location is. This method is suitable for calling periodically from a modal event tracking loop when the mouse is dragged outside the tracking view. The suggested period of the calls is 0.1 seconds.
beginDocument
Writes header and job information for the PostScript document. This includes at a minimum, PostScript header information. It may also include job setup information if the output is intended for a printer (i.e. not an EPS file). Most of the information for writing the header comes from the NSPrintOperation and NSPrintInfo objects associated with the current print operation. There isn't normally anything that the program needs to override at the beginning of a document, although if there is additional setup that needs to be done, you can override the NSView's methods endHeaderComments, endPrologue, beginSetup, and/or endSetup. This method calls the above methods in the listed order before or after writing the required information. For an EPS operation, the beginSetup and endSetup methods aren't used.
beginPage:
ordinalNum
label:
aString
bBox:
pageRect
fonts:
fontNames
Description forthcoming.
beginPageInRect:
aRect
atPlacement:
location
Description forthcoming.
beginPageSetupRect:
aRect
placement:
location
Description forthcoming.
beginPrologueBBox:
boundingBox
creationDate:
dateCreated
createdBy:
anApplication
fonts:
fontNames
forWhom:
user
pages:
numPages
title:
aTitle
Description forthcoming.
beginSetup
Description forthcoming.
beginTrailer
Description forthcoming.
bounds
Description forthcoming.
boundsRotation
Description forthcoming.
canBecomeKeyView
Description forthcoming.
canDraw
Description forthcoming.
centerScanRect:
aRect
Description forthcoming.
convertPoint:
aPoint
fromView:
aView
Description forthcoming.
convertPoint:
aPoint
toView:
aView
Description forthcoming.
convertRect:
aRect
fromView:
aView
Converts aRect from the coordinate system of aView to the coordinate system of the receiver, ie. returns the bounding rectangle in the receiver of aRect in aView.
aView
and the receiver must be in the same window. If aView is `nil`, converts from the receiver's window's coordinate system.
convertRect:
aRect
toView:
aView
Converts aRect from the coordinate system of the receiver to the coordinate system of aView, ie. returns the bounding rectangle in aView of aRect in the receiver.
aView
and the receiver must be in the same window. If aView is `nil`, converts to the receiver's window's coordinate system.
convertSize:
aSize
fromView:
aView
Description forthcoming.
convertSize:
aSize
toView:
aView
Description forthcoming.
dataWithEPSInsideRect:
aRect
Description forthcoming.
dataWithPDFInsideRect:
aRect
Description forthcoming.
didAddSubview:
subview
Description forthcoming.
discardCursorRects
Removes all the cursor rectancles which have been set up for the receiver. This is equivalent to calling -removeCursorRect:cursor: for all cursor rectangles which have been set up.
This is called automatically before the system calls -resetCursorRects so you never need to call it.
display
Description forthcoming.
displayIfNeeded
Description forthcoming.
displayIfNeededIgnoringOpacity
Description forthcoming.
displayIfNeededInRect:
aRect
Description forthcoming.
displayIfNeededInRectIgnoringOpacity:
aRect
Description forthcoming.
displayRect:
aRect
Causes the area of the view specified by aRect to be displayed. This is done by moving up the view hierarchy until an opaque view is found, then asking that view to update the appropriate area.
displayRectIgnoringOpacity:
aRect
Description forthcoming.
dragFile:
filename
fromRect:
rect
slideBack:
slideFlag
event:
event
Description forthcoming.
dragImage:
anImage
at:
viewLocation
offset:
initialOffset
event:
event
pasteboard:
pboard
source:
sourceObject
slideBack:
slideFlag
Description forthcoming.
dragPromisedFilesOfTypes:
typeArray
fromRect:
aRect
source:
sourceObject
slideBack:
slideBack
event:
theEvent
Description forthcoming.
drawPageBorderWithSize:
borderSize
Description forthcoming.
drawRect:
rect
This method is invoked to handle drawing inside the view. The default NSView's implementation does nothing; subclasses might override it to draw something inside the view. Since NSView's implementation is guaranteed to be empty, you should not call super's implementation when you override it in subclasses. drawRect: is invoked when the focus has already been locked on the view; you can use arbitrary postscript functions in drawRect: to draw inside your view; the coordinate system in which you draw is the view's own coordinate system (this means for example that you should refer to the rectangle covered by the view using its bounds, and not its frame). The argument of drawRect: is the rectangle which needs to be redrawn. In a lossy implementation, you can ignore the argument and redraw the whole view; if you are aiming at performance, you may want to redraw only what is inside the rectangle which needs to be redrawn; this usually improves drawing performance considerably.
drawSheetBorderWithSize:
borderSize
Description forthcoming.
enclosingScrollView
Description forthcoming.
endDocument
Description forthcoming.
endHeaderComments
Description forthcoming.
endPage
Description forthcoming.
endPageSetup
Description forthcoming.
endPrologue
Description forthcoming.
endSetup
Description forthcoming.
endTrailer
Description forthcoming.
fax:
sender
Description forthcoming.
focusRingType
Description forthcoming.
frame
Description forthcoming.
frameRotation
Description forthcoming.
gState
Returns an identifier that represents the view's gstate object, which is used to encapsulate drawing information about the view. Most of the time a gstate object is created from scratch when the view is focused, so if the view is not currently focused or allocateGState has not been called, then this method will return 0. FIXME: The above is what the OpenStep and Cocoa specification say, but gState is 0 unless allocateGState has been called.
getRectsBeingDrawn:
rects
count:
count
Description forthcoming.
getRectsExposedDuringLiveResize:
exposedRects
count:
count
Description forthcoming.
heightAdjustLimit
Description forthcoming.
hitTest:
aPoint
Returns the subview, lowest in the receiver's hierarchy, which contains aPoint, or `nil` if there is no such view.
inLiveResize
Description forthcoming.
initWithFrame:
frameRect
Description forthcoming.
isDescendantOf:
aView
Returns `YES` if aView is an ancestor of the receiver.
isFlipped
Description forthcoming.
isHidden
Description forthcoming.
isHiddenOrHasHiddenAncestor
Description forthcoming.
isOpaque
Description forthcoming.
isRotatedFromBase
Description forthcoming.
isRotatedOrScaledFromBase
Description forthcoming.
knowsPageRange:
range
Description forthcoming.
knowsPagesFirst:
firstPageNum
last:
lastPageNum
Description forthcoming.
locationOfPrintRect:
aRect
Description forthcoming.
lockFocus
Description forthcoming.
lockFocusIfCanDraw
Description forthcoming.
lockFocusIfCanDrawInContext:
context
Description forthcoming.
lockFocusInRect:
rect
Description forthcoming.
menuForEvent:
theEvent

Returns the menu that it appropriates for the given event. NSView's implementation returns the default menu of the view.

This methods is intended to be overriden so that it can return a context-sensitive for appropriate mouse's events. ((although it seems it can be used for any kind of event)

This method is used by NSView's rightMouseDown: method, and the returned NSMenu is displayed as a context menu

Use of this method is discouraged in GNUstep as it breaks many user interface guidelines. At the very least, menu items that appear in a context sensitive menu should also always appear in a normal menu. Otherwise, users are faced with an inconsistant interface where the menu items they want are only available in certain (possibly unknown) cases, making it difficult for the user to understand how the application operates

see [NSResponder -menu], [NSResponder -setMenu:], [NSView +defaultMenu] and [NSView -menu].

mouse:
aPoint
inRect:
aRect
Returns whether or not aPoint lies within aRect.
mouseDownCanMoveWindow
Description forthcoming.
needsDisplay
Description forthcoming.
needsPanelToBecomeKey
Description forthcoming.
needsToDrawRect:
aRect
Description forthcoming.
nextKeyView
Returns the next view after the receiver in the key view chain.
Returns `nil` if there is no view after the receiver.
The next view is set up using the -setNextKeyView: method.
The key view chain is used to determine the order in which views become first responder when using keyboard navigation.
nextValidKeyView
Returns the first available view after the receiver which is actually able to become first responder. See -nextKeyView and [NSResponder -acceptsFirstResponder]
opaqueAncestor
Description forthcoming.
pageFooter
Description forthcoming.
pageHeader
Description forthcoming.
performKeyEquivalent:
theEvent
Description forthcoming.
performMnemonic:
aString
Description forthcoming.
postsBoundsChangedNotifications
Description forthcoming.
postsFrameChangedNotifications
Description forthcoming.
preservesContentDuringLiveResize
Description forthcoming.
previousKeyView
Returns the view before the receiver in the key view chain.
Returns `nil` if there is no view before the receiver in the chain.
The previous view of the receiver was set up by passing it as the argument to a call of -setNextKeyView: on that view.
The key view chain is used to determine the order in which views become first responder when using keyboard navigation.
previousValidKeyView
Returns the first available view before the receiver which is actually able to become first responder. See -nextKeyView and [NSResponder -acceptsFirstResponder]
print:
sender
Description forthcoming.
printJobTitle
Description forthcoming.
rectForPage:
page
Description forthcoming.
rectPreservedDuringLiveResize
Description forthcoming.
reflectScrolledClipView:
aClipView
Description forthcoming.
registerForDraggedTypes:
newTypes
Registers the fact that the receiver should accept dragged data of any of the specified types. You need to do this if you want your view to support drag and drop.
releaseGState
Frees the gstate object, if there is one.
removeAllToolTips
Description forthcoming.
removeCursorRect:
aRect
cursor:
anObject
Removes the cursor rectangle which was set up for the specified rectangle and cursor.
removeFromSuperview

Removes the receiver from its superviews list of subviews, by invoking the superviews -removeSubview: method, and marks the rectangle that the reciever occupied in the superview as needing redisplay.

This is dangerous to use during display, since it alters the rectangles needing display. In this case, you can use the -removeFromSuperviewWithoutNeedingDisplay method instead.

removeFromSuperviewWithoutNeedingDisplay
Removes the receiver from its superviews list of subviews, by invoking the superviews [-removeSubview:] method.
removeSubview:
aView

Removes aSubview from the receivers list of subviews and from the responder chain.

Also invokes -viewWillMoveToWindow: on aView with a `nil` argument, to handle removal of aView (and recursively, its children) from its window - performing tidyup by invalidating cursor rects etc.

removeToolTip:
tag
Description forthcoming.
removeTrackingRect:
tag
Removes a tracking rectangle which was previously established using the -addTrackingRect:owner:userData:assumeInside: method.
The value of tag must be the value returned by the method used to add the rectangle.
renewGState
Invalidates the view's gstate object so it will be set up again using setUpGState the next time the view is focused.
replaceSubview:
oldView
with:
newView
Removes oldView, which should be a subview of the receiver, from the receiver and places newView in its place. If newView is `nil`, just removes oldView. If oldView is `nil`, just adds newView.
resetCursorRects
This is called to establish a new set of cursor rectangles whenever the receiver needs to do so (eg the view has been resized). The default implementation does nothing, but subclasses should use it to make calls to -addCursorRect:cursor: to establish their new cursor rectangles.
resizeSubviewsWithOldSize:
oldSize
Description forthcoming.
resizeWithOldSuperviewSize:
oldSize
Description forthcoming.
rotateByAngle:
angle
Description forthcoming.
scaleUnitSquareToSize:
newSize
Description forthcoming.
scrollClipView:
aClipView
toPoint:
aPoint
Description forthcoming.
scrollPoint:
aPoint
Description forthcoming.
scrollRect:
aRect
by:
delta
Copy on scroll method, should be called from [NSClipView setBoundsOrigin].
scrollRectToVisible:
aRect
Scrolls the nearest enclosing clip view the minimum required distance necessary to make aRect (or as much of it possible) in the receiver visible. Returns `YES` iff any scrolling was done.
setAutoresizesSubviews:
flag
Description forthcoming.
setAutoresizingMask:
mask
Description forthcoming.
setBounds:
aRect
Description forthcoming.
setBoundsOrigin:
newOrigin
Description forthcoming.
setBoundsRotation:
angle
Description forthcoming.
setBoundsSize:
newSize
Description forthcoming.
setFocusRingType:
focusRingType
Description forthcoming.
setFrame:
frameRect
Description forthcoming.
setFrameOrigin:
newOrigin
Description forthcoming.
setFrameRotation:
angle
Description forthcoming.
setFrameSize:
newSize
Description forthcoming.
setHidden:
flag
Description forthcoming.
setKeyboardFocusRingNeedsDisplayInRect:
rect
Description forthcoming.
setNeedsDisplay:
flag
As an exception to the general rules for threads and gui, this method is thread-safe and may be called from any thread. Display will always be done in the main thread. (Note that other methods are in general not thread-safe; if you want to access other properties of views from multiple threads, you need to provide the synchronization.)
setNeedsDisplayInRect:
invalidRect
Inform the view system that the specified rectangle is invalid and requires updating. This automatically informs any superviews of any updating they need to do. As an exception to the general rules for threads and gui, this method is thread-safe and may be called from any thread. Display will always be done in the main thread. (Note that other methods are in general not thread-safe; if you want to access other properties of views from multiple threads, you need to provide the synchronization.)
setNextKeyView:
aView

The effect of the -setNextKeyView: method is to set aView to be the value returned by subsequent calls to the receivers -nextKeyView method. This also has the effect of setting the previous key view of aView, so that subsequent calls to its -previousKeyView method will return the receiver.

As a special case, if you pass `nil` as aView then the -previousKeyView of the receivers current -nextKeyView is set to `nil` as well as the receivers -nextKeyView being set to `nil`.
This behavior provides MacOS-X compatibility.

If you pass a non-view object other than `nil`, an NSInternaInconsistencyException is raised.

NB This method does NOT cause aView to be retained, and if aView is deallocated, the [NSView -dealloc] method will automatically remove it from the key view chain it is in.

For keyboard navigation, views are linked together in a chain, so that the current first responder view can be changed by stepping backward and forward in that chain. This is the method for building and modifying that chain.

The MacOS-X documentation refers to this chain as a loop, but the actual implementation is not a loop at all (except as a special case when you make the chain into a loop). In fact, while each view may have only zero or one next view, and zero or one previous view, several views may have their next view set to a single view and/or their previous views set to a single view. So the actual setup is a directed graph rather than a loop.

While a directed graph is a very powerful and flexible way of managing the way views get keyboard focus in response to tabs etc, it can be confusing if misused. It is probably best therefore, to set your views up as a single loop within each window.

[a setNextKeyView: b]; [b setNextKeyView: c]; [c setNextKeyView: d]; [d setNextKeyView: a];
setPostsBoundsChangedNotifications:
flag
Description forthcoming.
setPostsFrameChangedNotifications:
flag
Description forthcoming.
setPreviousKeyView:
aView
GNUstep addition... a conveninece method to insert a view in the key view chain before the receiver, using the -previousKeyView and -setNextKeyView: methods.
setToolTip:
string
Description forthcoming.
setUpGState
Description forthcoming.
shouldDelayWindowOrderingForEvent:
anEvent
Description forthcoming.
shouldDrawColor
Description forthcoming.
sortSubviewsUsingFunction:
compare
context:
context
Description forthcoming.
subviews
Description forthcoming.
superview
Description forthcoming.
tag
Description forthcoming.
toolTip
Description forthcoming.
translateOriginToPoint:
point
Description forthcoming.
unlockFocus
Description forthcoming.
unregisterDraggedTypes
Description forthcoming.
viewDidEndLiveResize
Description forthcoming.
viewDidMoveToSuperview
Description forthcoming.
viewDidMoveToWindow
Description forthcoming.
viewWillMoveToSuperview:
newSuper
Notifies the receiver that its superview is being changed to newSuper.
viewWillMoveToWindow:
newWindow
Notifies the receiver that it will now be a view of newWindow. Note, this method is also used when removing a view from a window (in which case, newWindow is `nil`) to let all the subviews know that they have also been removed from the window.
viewWillStartLiveResize
Description forthcoming.
viewWithTag:
aTag
Description forthcoming.
visibleRect
Description forthcoming.
wantsDefaultClipping
Description forthcoming.
widthAdjustLimit
Description forthcoming.
willRemoveSubview:
subview
Description forthcoming.
window
Returns the window in which the receiver resides.
writeEPSInsideRect:
rect
toPasteboard:
pasteboard
Description forthcoming.
writePDFInsideRect:
aRect
toPasteboard:
pboard
Description forthcoming.
Software documentation for the NSView(PrivateMethods) category
AppKit/NSView.h
Warning this category is private, which means that the methods are for internal use by the package. You should not use them in external code.
_invalidateCoordinates
Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.
_matrixFromWindow
Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.
_matrixToWindow
Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.
_rebuildCoordinates
Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.