Next Page > Hide TOC

Legacy Documentclose button

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

NSTextContainer

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

Overview

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.

Tasks

Constructors

Managing Text Components

Controlling Size

Setting Line Fragment Padding

Calculating Text Layout

Mouse Hit Testing

Constructors

NSTextContainer

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)

Discussion

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.

See Also

Instance Methods

containerSize

Returns the size of the receiver’s bounding rectangle, regardless of the size of its region.

public NSSize containerSize()

See Also

containsPoint

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)

Discussion

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.

heightTracksTextView

Returns true if the receiver adjusts the height of its bounding rectangle when its NSTextView is resized, false otherwise.

public boolean heightTracksTextView()

Discussion

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.

See Also

isSimpleRectangularTextContainer

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

Discussion

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.

layoutManager

Returns the receiver’s NSLayoutManager.

public NSLayoutManager layoutManager()

See Also

lineFragmentPadding

Returns the amount (in points) by which text is inset within line fragment rectangles.

public float lineFragmentPadding()

See Also

lineFragmentRectForProposedRect

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)

Discussion

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.

replaceLayoutManager

Replaces the NSLayoutManager for the group of text system objects containing the receiver with aLayoutManager.

public void replaceLayoutManager(NSLayoutManager aLayoutManager)

Discussion

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.

See Also

setContainerSize

Sets the size of the receiver’s bounding rectangle to aSize and sends textContainerChangedGeometry to the NSLayoutManager.

public void setContainerSize(NSSize aSize)

See Also

setHeightTracksTextView

Controls whether the receiver adjusts the height of its bounding rectangle when its NSTextView is resized.

public void setHeightTracksTextView(boolean flag)

Discussion

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.

See Also

setLayoutManager

Sets the receiver’s NSLayoutManager to aLayoutManager.

public void setLayoutManager(NSLayoutManager aLayoutManager)

Discussion

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.

See Also

setLineFragmentPadding

Sets the amount (in points) by which text is inset within line fragment rectangles to aFloat.

public void setLineFragmentPadding(float aFloat)

Discussion

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.

See Also

setTextView

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)

Discussion

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.

See Also

setWidthTracksTextView

Controls whether the receiver adjusts the width of its bounding rectangle when its NSTextView is resized.

public void setWidthTracksTextView(boolean flag)

Discussion

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.

See Also

textView

Returns the receiver’s NSTextView, or null if it has none.

public NSTextView textView()

See Also

widthTracksTextView

Returns true if the receiver adjusts the width of its bounding rectangle when its NSTextView is resized, false otherwise.

public boolean widthTracksTextView()

Discussion

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.

See Also

Constants

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.

Constant

Description

LineSweepLeft

Characters move from right to left.

LineSweepRight

Characters move from left to right.

LineSweepDown

Characters move from top to bottom.

LineSweepUp

Characters move from bottom to top.

Line movement is the direction in which lines move. See Text System Storage Layer Overview.

Constant

Description

LineMovesLeft

Lines move from right to left.

LineMovesRight

Lines move from left to right.

LineMovesDown

Lines move from top to bottom.

LineMovesUp

Lines move from bottom to top.

LineDoesntMove

Line has no movement.



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.