Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.application |
Companion guide |
An NSTextContainer defines a region where text is laid out. An NSLayoutManager uses NSTextContainers to determine where to break lines, lay out portions of text, and so on. NSTextContainer defines rectangular regions, but you can create subclasses that define regions of other shapes, such as circular regions, regions with holes in them, or regions that flow alongside graphics.
setContainerSize
containerSize
setWidthTracksTextView
widthTracksTextView
setHeightTracksTextView
heightTracksTextView
Creates an NSTextContainer with a zero-sized bounding rectangle.
public NSTextContainer
()
Creates an NSTextContainer, with aSize as the size of its bounding rectangle.
public NSTextContainer
(NSSize aSize)
For both constructors, the new NSTextContainer must be added to an NSLayoutManager before it can be used; it must also have an NSTextView set for text to be displayed.
addTextContainer
(NSLayoutManager)setTextView
Returns the size of the receiver’s bounding rectangle, regardless of the size of its region.
public NSSize containerSize
()
textContainerInset
(NSTextView)setContainerSize
Overridden by subclasses to return true
if aPoint lies within the receiver’s region or on the region’s edge—not simply within its bounding rectangle—false
otherwise.
public boolean containsPoint
(NSPoint aPoint)
For example, if the receiver defines a donut shape and aPoint lies in the hole, this method returns false
. This method can be used for hit testing of mouse events.
NSTextContainer’s implementation merely checks that aPoint lies within its bounding rectangle.
Returns true
if the receiver adjusts the height of its bounding rectangle when its NSTextView is resized, false
otherwise.
public boolean heightTracksTextView
()
The height is adjusted to the height of the NSTextView minus twice the inset height (as given by NSTextView’s textContainerInset
method).
See Text System Storage Layer Overview for more information on size tracking.
Overridden by subclasses to return true
if the receiver’s region is a rectangle with no holes or gaps and whose edges are parallel to the NSTextView’s coordinate system axes; returns false
otherwise.
public boolean isSimpleRectangularTextContainer
()
An NSTextContainer whose shape changes can return true
if its region is currently a simple rectangle, but when its shape does change it must send textContainerChangedGeometry
to its NSLayoutManager so the layout can be recalculated.
NSTextContainer’s implementation of this method returns true
.
Returns the receiver’s NSLayoutManager.
public NSLayoutManager layoutManager
()
Returns the amount (in points) by which text is inset within line fragment rectangles.
public float lineFragmentPadding
()
Overridden by subclasses to calculate and return the longest rectangle available for proposedRect for displaying text, or NSRect.ZeroRect
if there is none according to the receiver’s region definition.
public NSRect lineFragmentRectForProposedRect
(NSRect proposedRect, int sweepDirection, int movementDirection, NSMutableRect remainingRect)
There is no guarantee as to the width of the proposed rectangle or to its location. For example, the proposed rectangle is likely to be much wider than the width of the receiver. The receiver should examine proposedRect to see that it intersects its bounding rectangle and should return a modified rectangle based on sweepDirection and movementDirection, whose possible values are listed in the class description. If sweepDirection is LineSweepRight
, for example, the receiver uses this information to trim the right end of proposedRect as needed rather than the left end.
If proposedRect doesn’t completely overlap the region along the axis of movementDirection and movementDirection isn’t LineDoesntMove
, this method can either shift the rectangle in that direction as much as needed so that it does completely overlap, or return NSRect.ZeroRect
to indicate that the proposed rectangle simply doesn’t fit.
Upon returning, remainingRect contains the unused, possibly shifted, portion of proposedRect that’s available for further text, or NSRect.ZeroRect
if there is no remainder.
See the class description for more information on overriding this method.
Replaces the NSLayoutManager for the group of text system objects containing the receiver with aLayoutManager.
public void replaceLayoutManager
(NSLayoutManager aLayoutManager)
All NSTextContainers and NSTextViews sharing the original NSLayoutManager then share the new one. This method makes all the adjustments necessary to keep these relationships intact, unlike setLayoutManager
.
Sets the size of the receiver’s bounding rectangle to aSize and sends textContainerChangedGeometry
to the NSLayoutManager.
public void setContainerSize
(NSSize aSize)
setTextContainerInset
(NSTextView)containerSize
Controls whether the receiver adjusts the height of its bounding rectangle when its NSTextView is resized.
public void setHeightTracksTextView
(boolean flag)
If flag is true
, the receiver follows changes to the height of its text view; if flag is false
, it doesn’t.
See Text System Storage Layer Overview for more information on size tracking.
Sets the receiver’s NSLayoutManager to aLayoutManager.
public void setLayoutManager
(NSLayoutManager aLayoutManager)
This method is invoked automatically when you add an NSTextContainer to an NSLayoutManager; you should never need to invoke it directly, but might want to override it. If you want to replace the NSLayoutManager for an established group of text system objects, use replaceLayoutManager
.
addTextContainer
(NSLayoutManager)layoutManager
Sets the amount (in points) by which text is inset within line fragment rectangles to aFloat.
public void setLineFragmentPadding
(float aFloat)
Also sends textContainerChangedGeometry
to the receiver’s NSLayoutManager to inform it of the change.
Line fragment padding is not designed to express text margins. Instead, use the NSTextView method setTextContainerInset
, paragraph margin attributes, or the position of the text view within a superview.
Sets the receiver’s NSTextView to aTextView and sends setTextContainer
to aTextView to complete the association of the text container and text view.
public void setTextView
(NSTextView aTextView)
Because you usually specify an NSTextContainer when you create an NSTextView, you should rarely need to invoke this method. An NSTextContainer doesn’t need an NSTextView to calculate line fragment rectangles, but must have one to display text.
You can use this method to disconnect an NSTextView from a group of text system objects by sending this message to its text container and passing null
as aTextView.
replaceTextContainer
(NSTextView)Controls whether the receiver adjusts the width of its bounding rectangle when its NSTextView is resized.
public void setWidthTracksTextView
(boolean flag)
If flag is true
, the receiver follows changes to the width of its text view; if flag is false
, it doesn’t.
See Text System Storage Layer Overview for more information on size tracking.
Returns the receiver’s NSTextView, or null
if it has none.
public NSTextView textView
()
Returns true
if the receiver adjusts the width of its bounding rectangle when its NSTextView is resized, false
otherwise.
public boolean widthTracksTextView
()
The width is adjusted to the width of the NSTextView minus twice the inset width (as given by NSTextView’s textContainerInset
method).
See Text System Storage Layer Overview for more information on size tracking.
These constants describe the progression of text on a page. The typesetter decides which way text is supposed to flow and passes these values as arguments to the text container, which uses them to calculate the next line rectangle.
The only values currently used by the supplied typesetters are LineSweepRight
and LineMovesDown
. An NSTextContainer subclass should be prepared to deal with any value, and an NSTypesetter subclass should be able to use any of them.
Line sweep is the direction text progresses within a line. See Text System Storage Layer Overview.
Line movement is the direction in which lines move. See Text System Storage Layer Overview.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)