PATH  Documentation > Mac OS X > Application Kit Reference: Java

Table of Contents

NSTextView


Inherits from:
NSText : NSView : NSResponder : NSObject
Implements:
NSTextInput
Package:
com.apple.yellow.application

Class at a Glance


NSTextView is the front-end component of the Application Kit's text system. It displays and manipulates text laid out in an area defined by an NSTextContainer, and adds many features to those defined by its superclass, NSText. Many of the methods that you'll use most frequently are declared by the superclass; see the NSText class specification for details.

Principal Attributes


Creation


Instances of this class can be created using Interface Builder or using one of its constructors.

Commonly Used Methods


The methods most commonly used with NSTextView objects are declared in NSText, the superclass. These methods provide access to the other major components of the text system:


textStorage Returns the associated NSTextStorage object.
textContainer Returns the associated NSTextContainer object.
layoutManager Returns the associated NSLayoutManager object.


Class Description


NSTextView is the front-end class to the Application Kit's extended text-handling system. It draws the text managed by the back-end components and handles user events to select and modify its text. NSTextView is the principal means to obtain a text object that caters to almost all needs for displaying and managing text at the user interface level. While NSTextView is a subclass of NSText-which declares the most general Cocoa interface to the text system-NSTextView adds several major features over and above the capabilities of NSText.

One of the design goals of NSTextView is to provide a comprehensive set of text-handling features so that you should rarely need to create a subclass. In its standard incarnation, NSTextView creates the requisite group of objects that support the text handling system-NSTextContainer, NSLayoutManager, and NSTextStorage objects. Here are the major features that NSTextView adds to those of NSText:


Creating NSTextView Objects


The easiest way to add an NSTextView to your application is through Interface Builder. Interface Builder's Data Views palette supplies a specially configured NSScrollView object that contains an NSTextView object as its document view. This NSTextView is configured to work with the NSScrollView and other user-interface controls such as a ruler, the Font menu, the Edit menu, and so on.

Interface Builder also offers other objects-of the NSTextField and NSForm classes-that make use of NSTextView objects for their text-editing facilities. In fact, all NSTextFields and NSForms within the same window share the same NSTextView object (known as the field editor), thus reducing the memory demands of an application. If your application requires stand-alone or grouped text fields that support editing (and all the other facilities provided by the NSTextView class), these are the classes to use.

You can also create NSTextView objects programmatically, using one of its constructors. The constructor that takes one argument is the simplest way to obtain an NSTextView object-it creates all the other components of the text-handling system for you and releases them when you're done. If you use the constructor that takes two arguments, you must construct (and release) the other components yourself.


Configuring Editing Behavior


Like NSText, NSTextView allows you to grant or deny the user the ability to select or edit its text, using the setSelectable and setEditable methods. These methods only affect what the user can do; you can still make changes to the NSTextView programmatically. An editable text view can behave as a normal text editor, accepting Tab and Return characters, or as a field editor, interpreting tabs and returns as cues to end editing. The setFieldEditor method controls this behavior. NSTextView also implements the distinction between plain and rich text defined by NSText with its setRichText and setImportsGraphics methods. See the NSText class specification for more information on these various distinctions.


Attachments


While NSText leaves open the nature of imported graphics and other attachments, NSTextView explicitly uses NSTextAttachment objects, which contain NSFileWrappers to represent the attached files. NSTextView declares several delegate methods that let you handle user actions on an attachment's image or icon. textViewClickedCellAtIndex and textViewDoubleClickedCellAtIndex let the delegate take action on mouse clicks, textViewDraggedCellAtIndex lets the delegate initiate a dragging session for the attachment, and textViewClickedOnLinkAtIndex lets the delegate act on mouse clicks in a link. See the NSTextAttachment, NSTextAttachmentCell, and NSFileWrapper class and protocol specifications for more information on working with attachments.


Input Management


NSTextView uses an input manager to turn basic character information into text and commands. It passes uninterpreted keyboard input to the input manager, which examines the characters generated and sends messages to the NSTextView based on those characters. If the typed characters are interpreted as text to input, the input manager sends the text view an insertText message. If they're interpreted as commands to perform, such as moving the insertion point or deleting text, the input manager sends the text view a doCommandBySelector message. Many of the standard commands are described in the NSResponder class specification. NSTextView also gives its delegate a chance to handle a command by sending it a textViewDoCommandBySelector message. If the delegate implements this method and returns true, the text view does nothing further; otherwise it tries to perform the command itself.

See the NSInputManager class and NSTextInput protocol specifications for more information.


Using the Font Panel and Ruler


NSTextView is designed to work with the Application Kit's font conversion system, defined by the NSFontPanel and NSFontManager classes. By default, an NSTextView keeps the Font Panel updated with the first font in its selection, or of its typing attributes (defined below). It also changes the font in response to messages from the Font Panel and Font menu. Such changes apply to the selected text or typing attributes for a rich text view, or to all the text in a plain text view. You can turn this behavior off using the setUsesFontPanel method. Doing so is recommended for a text view that serves as a field editor, for example. Making an NSTextView not use the font conversion system renders some of its other methods unusable, as these methods require access to font information to work. See the description of setUsesFontPanel for these side effects.

NSTextView also defines a comprehensive interface for manipulating paragraph attributes, using the NSRulerView class. If an NSTextView is enclosed in an NSScrollView, it can display a ruler view, which displays margin and tab markers that the user can manipulate to adjust their settings, as well as other controls for setting alignment, paragraph spacing, and so on. setRulerVisible and the inherited toggleRuler control whether the ruler view is displayed. The NSTextView serves as the ruler view's client, as described in the NSRulerView class specification. Similar to the Font Panel, NSTextView can be set not to use a ruler with the setUsesRuler method. This has side effects similar to those of setUsesFontPanel.


Examining and Setting the Selection


Most of the time the selection is determined by the user through mouse or keyboard operations. You can get the range of characters currently selected using the selectedRange method. This is the single most commonly used method for examining the selection. You can also set the selection programmatically using setSelectedRange. NSTextView indicates its selection by applying a special set of attributes to it. selectedTextAttributes returns these attributes, and setSelectedTextAttributes sets them.

While changing the selection in response to user input, an NSTextView invokes its setSelectedRange:affinity:stillSelecting: method. The first argument is of course the range to select. The second, called the selection affinity, determines which glyph the insertion point displays near when the two glyphs aren't adjacent. It's typically used where lines wrap to place the insertion point at the end of one line or the beginning of the following line. You can get the selection affinity in effect using the selectionAffinity method. The last argument indicates whether the selection is still in the process of changing; the delegate and any observers aren't notified of the change in the selection until the method is invoked with false for this argument. An additional factor affecting selection behavior is the selection granularity: whether characters, words, or whole paragraphs are being selected. This is usually determined by number of initial clicks; for example, a double-click initiates word-level selection. NSTextView decides how much to change the selection during input tracking using its selectionRangeForProposedRange method, as described under "Subclass Responsibilities" below.

An additional aspect of selection, actually related to input management, is the range of marked text. As the input manager interprets keyboard input, it can mark incomplete input in a special way. markedRange returns the range of any marked text, and markedTextAttributes returns the attributes used to highlight the marked text. You can change these attributes using setMarkedTextAttributes


Setting Text Attributes


NSTextView allows you to change the attributes of its text programmatically through various methods, most inherited from the superclass, NSText. NSTextView adds its own methods for setting the attributes of text that the user types, for setting the baseline offset of text as an absolute value, and for adjusting kerning and use of ligatures. Most of the methods for changing attributes are defined as action methods, and apply to the selected text or typing attributes for a rich text view, or to all of the text in a plain text view.

An NSTextView maintains a set of typing attributes (font, size, color, and so on) that it applies to newly entered text, whether typed by the user or pasted as plain text. It automatically sets the typing attributes to the attributes of the first character immediately preceding the insertion point, of the first character of a paragraph if the insertion point is at the beginning of a paragraph, or of the first character of a selection. The user can change the typing attributes by choosing menu commands and using utilities such as the Font Panel. You can also set the typing attributes programmatically using setTypingAttributes, though you should rarely find need to do so unless creating a subclass.

NSText defines the action methods superscript, subscript, and unscript, which raise and lower the baseline of text by predefined increments. NSTextView gives you much finer control over the baseline offset of text by defining the raiseBaseline and lowerBaseline action methods, which raise or lower text by one point each time they're invoked.


Kerning


NSTextView provides convenient action methods for adjusting the spacing between characters. By default, an NSTextView object uses standard kerning (as provided by the data in a font's AFM file). A turnOffKerning message causes this kerning information to be ignored and the selected text to be displayed using nominal widths. The loosenKerning and tightenKerning methods adjust kerning values over the selected text and useStandardKerning reestablishes the default kerning values.

Kerning information is a character attribute that's stored in the text view's NSTextStorage object. If your application needs finer control over kerning than the methods of this class provide, you should operate on the NSTextStorage object directly through methods defined by its superclass, NSMutableAttributedString.


Ligatures


NSTextView's support for ligatures provides the minimum required ligatures for a given font and script. The required ligatures for a specific font and script are determined by the mechanisms that generate glyphs for a specific language. Some scripts may well have no ligatures at all-English text, as an example, doesn't require ligatures, although certain ligatures such as "fi" and "fl" are desirable and are used if they're available. Other scripts, such as Arabic, demand that certain ligatures must be available even if a turnOffLigatures message is sent to the NSTextView. Other scripts and fonts have standard ligatures that are used if they're available. The useAllLigatures method extends ligature support to include all possible ligatures available in each font for a given script.

Ligature information is a character attribute that's stored in the text view's NSTextStorage object. If your application needs finer control over ligature use than the methods of this class provide, you should operate on the NSTextStorage object directly through methods defined by its superclass, NSMutableAttributedString.


Using Multiple NSTextViews


A single NSLayoutManager can be assigned any number of NSTextContainers, in whose NSTextViews it lays out text sequentially. In such a configuration, many of the attributes accessed through the NSTextView interface are actually shared by all of these text views. Among these attributes are:

Setting any of these attributes causes all associated NSTextView's to share the new value.

With multiple NSTextViews, only one is the first responder at any time. NSLayoutManager defines these methods for determining and appropriately setting the first responder:

See their descriptions in the NSLayoutManager class specification for more information.


Other Delegate Messages and Notifications


An NSTextView object can have a delegate that it informs of certain actions or pending changes to the state of the text. Several of the delegate methods have already been mentioned; here are all the messages a delegate can receive:

Those whose names begin with "text" rather than "textView" are declared by NSText and described in the NSText class specification. See "Methods Implemented By the Delegate" at the end of this class description for more details. The delegate can be any object you choose, and one delegate can control multiple NSTextView objects (or multiple series of connected NSTextView objects).

All NSTextView objects attached to the same NSLayoutManager share the same delegate: Setting the delegate of one such NSTextView sets the delegate for all the others. Delegate messages pass the sender as an argument. For multiple NSTextViews attached to the same NSLayoutManager, the argument isthe notifying text view, the first NSTextView for the shared NSLayoutManager. As the name implies, this NSTextView is also responsible for posting notifications at the appropriate times.

The notifications posted by NSTextView are:

Of these, the last is important for observers to register for. If a new NSTextView is added at the beginning of a series of connected NSTextViews, it becomes the new notifying text view. It doesn't have access to which objects are observing its group of text objects, so it posts a TextViewWillChangeNotifyingTextViewNotification, which allows all those observers to unregister themselves from the old notifying text view and reregister themselves with the new one. See the description for this notification at the end of this specification for more information.


Subclass Responsibilities


NSTextView expects subclasses to abide by certain rules of behavior, and provides many methods to help subclasses do so. Some of these methods are meant to be overridden to add information and behavior into the basic infrastructure. Some are meant to be invoked as part of that infrastructure when the subclass defines its own behavior. The following sections describe the major areas where a subclass has obligations or where it can expect help in implementing its new features.


Updating State


NSTextView automatically updates the Font Panel and ruler as its selection changes. If you add any new font or paragraph attributes to your subclass of NSTextView, you'll need to override the methods that perform this updating to account for the added information. updateFontPanel makes the Font Panel display the font of the first character in the selection; you might override it to update the display of an accessory view in the Font Panel. Similarly, updateRuler causes the ruler to display the paragraph attributes for the first paragraph in the selection. You can also override this to customize display of items in the ruler. Be sure to invoke super's implementation to have the basic updating performed as well.


Custom Import Types


NSTextView supports pasteboard operations and the dragging of files and colors into its text. If you customize the ability of your subclass to handle pasteboard operations for new data types, you should override the readablePasteboardTypes and writablePasteboardTypes methods to reflect those types. Similarly, for to support new types of data for dragging operations, you should override the acceptableDragTypes method. Your implementation of these methods should invoke the superclass' implementation, add the new data types to the array returned from super, and then return the modified array.

For dragging operations, if your subclass's ability to accept your custom dragging types varies over time, you can override updateDragTypeRegistration to register or unregister the custom types according to the text view's current status. By default this method enables dragging of all acceptable types if the receiver is editable and a rich text view.

To read and write custom pasteboard types, you must override the readSelectionFromPasteboardOfType and writeSelectionToPasteboardOfType methods. In your implementation of these methods, you should read the new data types your subclass supports and let the superclass handle any other types.


Altering Selection Behavior


Your subclass of NSTextView can customize the way selections are made for the various granularities described in "Examining and Setting the Selection" . While tracking user changes to the selection, whether by the mouse or keyboard, an NSTextView repeatedly invokes selectionRangeForProposedRange to determine what range to actually select. When finished tracking changes, it sends the delegate a textViewWillChangeSelection message. By overriding the NSTextView method or implementing the delegate method, you can alter the way the selection is extended or reduced. For example, in a code editor you can provide a delegate that extends a double click on a brace or parenthesis character to its matching delimiter.

These mechanisms aren't meant for changing language word definitions (such as what's selected on a double click). This detail of selection is handled at a lower (and currently private) level of the text system.


Preparing to Change Text


If you create a subclass of NSTextView to add new capabilities that will modify the text in response to user actions, you may need to modify the range selected by the user before actually applying the change. For example, if the user is making a change to the ruler, the change must apply to whole paragraphs, so the selection may have to be extended to paragraph boundaries. Three methods calculate the range to which certain kinds of change should apply. rangeForUserTextChange returns the range to which any change to characters themselves-insertions and deletions-should apply. rangeForUserCharacterAttributeChange returns the range to which a character attribute change, such as a new font or color, should apply. Finally, rangeForUserParagraphAttributeChange returns the range for a paragraph-level change, such as a new or moved tab stop, or indent. These methods all return a range whose location is NSArray.NotFound if a change isn't possible; you should check the returned range and abandon the change in this case.


Notifying About Changes to the Text


In actually making changes to the text, you must ensure that the changes are properly performed and recorded by different parts of the text system. You do this by bracketing each batch of potential changes with shouldChangeTextInRange and didChangeText messages. These methods ensure that the appropriate delegate messages are sent and notifications posted. The first method asks the delegate for permission to begin editing with a textShouldBeginEditing message. If the delegate returns false, shouldChangeTextInRange in turn returns false, in which case your subclass should disallow the change. If the delegate returns true, the text view posts a TextDidBeginEditingNotification, and shouldChangeTextInRange in turn returns true. In this case you can make your changes to the text, and follow up by invoking didChangeText. This method concludes the changes by posting a TextDidChangeNotification, which results in the delegate receiving a textDidChange message.

The textShouldBeginEditing and textDidBeginEditing messages are sent only once during an editing session. More precisely, they're sent upon the first user input since the NSTextView became the first responder. Thereafter, these messages-and the TextDidBeginEditingNotification-are skipped in the sequence. textViewShouldChangeTextInRange, however, must be invoked for each individual change.


Smart Insert and Delete


NSTextView defines several methods to aid in "smart" insertion and deletion of text, so that spacing and punctuation is preserved after a change. Smart insertion and deletion typically applies when the user has selected whole words or other significant units of text. A smart deletion of a word before a comma, for example, also deletes the space that would otherwise be left before the comma (though not placing it on the pasteboard in a Cut operation). A smart insertion of a word between another word and a comma adds a space between the two words to protect that boundary. NSTextView automatically uses smart insertion and deletion by default; you can turn this behavior off using setSmartInsertDeleteEnabled. Doing so causes only the selected text to be deleted, and inserted text to be added with no addition of white space.

If your subclass of NSTextView defines any methods that insert or delete text, you can make them smart by taking advantage of two NSTextView methods. smartDeleteRangeForProposedRange expands a proposed deletion range to include any whitespace that should also be deleted. If you need to save the text deleted, though, it's typically best to save only the text from the original range. For smart insertion, smartInsertBeforeStringForString and smartInsertAfterStringForString return strings that you can insert before and after a given string to preserve spacing and punctuation. See the method descriptions for more information.




Constants


These constants specify how much the text view extends the selection when the user drags the mouse. They're used by selectionGranularity and setSelectionGranularity


Constant Description
SelectByCharacter Extend the selection character by character
SelectByWord Extend the selection word by word
SelectByParagraph Extend the selection paragraph by paragraph

These constants specify the preferred direction of selection. They're used by selectionAffinity.


Constant Description
SelectionAffinityUpstream Description forthcoming.
SelectionAffinityDownstream Description forthcoming.



Interfaces Implemented


NSTextInput
- conversationIdentifier
- doCommandBySelector:
- getMarkedText:selectedRange:
- hasMarkedText
- insertText:
- setMarkedText:selectedRange:
- unmarkText


Method Types


Constructors
NSTextView
Registering Services information
registerForServices
Accessing related text-system objects
characterIndexForPoint
conversationIdentifier
firstRectForCharacterRange
setTextContainer
replaceTextContainer
textContainer
setTextContainerInset
textContainerInset
textContainerOrigin
invalidateTextContainerOrigin
layoutManager
textStorage
Setting graphic attributes
setBackgroundColor
backgroundColor
setDrawsBackground
drawsBackground
Controlling display
setNeedsDisplay
shouldDrawInsertionPoint
drawInsertionPointInRect
setConstrainedFrameSize
cleanUpAfterDragOperation
Setting behavioral attributes
allowsUndo
setAllowsUndo
setEditable
isEditable
setSelectable
isSelectable
setFieldEditor
isFieldEditor
setRichText
isRichText
setImportsGraphics
importsGraphics
Using the Font Panel and menu
setUsesFontPanel
usesFontPanel
Using the ruler
setUsesRuler
usesRuler
setRulerVisible
isRulerVisible
Managing the selection
attributedSubstringWithRange
selectedRange
setSelectedRange
selectionAffinity
setMarkedTextAndSelectedRange
setSelectionGranularity
selectionGranularity
setInsertionPointColor
insertionPointColor
updateInsertionPointStateAndRestartTimer
hasMarkedText
setSelectedTextAttributes
selectedTextAttributes
markedRange
setMarkedTextAttributes
markedTextAttributes
unmarkText
validAttributesForMarkedText
Managing the pasteboard
preferredPasteboardTypeFromArray
readSelectionFromPasteboard
readSelectionFromPasteboardOfType
readablePasteboardTypes
writablePasteboardTypes
writeSelectionToPasteboardOfType
writeSelectionToPasteboardOfTypes
Setting text attributes
alignJustified
changeColor
setAlignmentInRange
setTypingAttributes
typingAttributes
useStandardKerning
lowerBaseline
raiseBaseline
turnOffKerning
loosenKerning
tightenKerning
useStandardLigatures
turnOffLigatures
useAllLigatures
Other action methods
allowsUndo
clickedOnLinkAtIndex
doCommandBySelector
pasteAsPlainText
pasteAsRichText
Methods that subclasses should use or override
updateFontPanel
updateRuler
acceptableDragTypes
updateDragTypeRegistration
selectionRangeForProposedRange
rangeForUserCharacterAttributeChange
rangeForUserParagraphAttributeChange
rangeForUserTextChange
shouldChangeTextInRange
didChangeText
setSmartInsertDeleteEnabled
smartInsertDeleteEnabled
smartDeleteRangeForProposedRange
Changing first responder status
resignFirstResponder
becomeFirstResponder
validRequestorForTypes
Working with the spelling checker
spellCheckerDocumentTag
NSRulerView client methods
rulerViewDidMoveMarker
rulerViewDidRemoveMarker
rulerViewDidAddMarker
rulerViewShouldMoveMarker
rulerViewShouldAddMarker
rulerViewWillMoveMarker
rulerViewShouldRemoveMarker
rulerViewWillAddMarker
rulerViewHandleMouseDown
Assigning a delegate
setDelegate
delegate


Constructors



NSTextView

public NSTextView()

Description forthcoming.

public NSTextView(NSRect frameRect)

Creates an NSTextView object with frameRect as its frame rectangle. This method creates the entire collection of objects associated with an NSTextView-its NSTextContainer, NSLayoutManager, and NSTextStorage-and invokes the constructor that takes a frameRect and aTextContainer.

This method creates the text web in such a manner that the NSTextView object is the principal owner of the objects in the web.

public NSTextView( NSRect frameRect, NSTextContainer aTextContainer)

Creates an NSTextView object with frameRect as its frame rectangle and aTextContainer as its text container. This method is the designated initializer for NSTextView objects.

Unlike the constructor that takes only a frameRect, which builds up an entire group of text-handling objects, you use this constructor after you've created the other components of the text handling system-an NSTextStorage object, an NSLayoutManager object, and an NSTextContainer object. Assembling the components in this fashion means that the NSTextStorage, not the NSTextView, is the principal owner of the component objects.




Static Methods



registerForServices

public static void registerForServices()

Registers send and return types for the Services facility. This method is invoked automatically; you should never need to invoke it directly.


Instance Methods



acceptableDragTypes

public NSArray acceptableDragTypes()

Returns the data types that the receiver accepts as the destination view of a dragging operation. These types are automatically registered as necessary by the NSTextView. Subclasses should override this method as necessary to add their own types to those returned by NSTextView's implementation. They must then also override the appropriate methods of the NSDraggingDestination interface to support import of those types. See that interface's specification for more information.

See Also: updateDragTypeRegistration



alignJustified

public void alignJustified(Object sender)

This action method applies full justification to selected paragraphs (or all text, if the receiver is a plain text object).

See Also: alignCenter (NSText), alignLeft (NSText), alignRight (NSText), alignment (NSText), setAlignment (NSText)



allowsUndo

public boolean allowsUndo()

Description forthcoming.

attributedSubstringWithRange

public NSAttributedString attributedSubstringWithRange(NSRange aRange)

Description forthcoming.

backgroundColor

public NSColor backgroundColor()

Returns the receiver's background color.

See Also: drawsBackground, setBackgroundColor



becomeFirstResponder

public boolean becomeFirstResponder()

Informs the receiver that it's becoming the first responder. If the previous first responder was not an NSTextView on the same NSLayoutManager as the receiving NSTextView, this method draws the selection and updates the insertion point if necessary. Returns true.

Use NSWindow's makeFirstResponder, not this method, to make an NSTextView the first responder. Never invoke this method directly.

See Also: resignFirstResponder



changeColor

public void changeColor(Object sender)

Invoked by the NSColorPanel (sender) to set the color of the selected text. NSTextView's implementation queries sender for the color by sending it a color message.

characterIndexForPoint

public int characterIndexForPoint(NSPoint aPoint)

Description forthcoming.

cleanUpAfterDragOperation

public void cleanUpAfterDragOperation()

Releases the drag information still existing after the dragging session has completed. Subclasses may override this method to clean up any additional data structures used for dragging. In your overridden method, be sure to invoke super's implementation.

clickedOnLinkAtIndex

public void clickedOnLinkAtIndex( Object link, int charIndex)

Notifies the delegate that the user clicked in a link at the specified charIndex. The delegate may take any appropriate actions to handle the click in its textViewClickedOnLinkAtIndex method.

See Also: textViewClickedOnLinkAtIndex (delegate method)



conversationIdentifier

public int conversationIdentifier()

Description forthcoming.

delegate

public Object delegate()

Returns the delegate used by the receiver (and by all other NSTextViews sharing the receiver's NSLayoutManager), or null if there is none.

See Also: setDelegate



didChangeText

public void didChangeText()

Invoked automatically at the end of a series of changes, this method posts a TextDidChangeNotification to the default notification center, which also results in the delegate receiving an NSText-delegate textDidChange message. Subclasses implementing methods that change their text should invoke this method at the end of those methods. See the class description for more information.

See Also: shouldChangeTextInRange



doCommandBySelector

public void doCommandBySelector(NSSelector aSelector)

Description forthcoming.

dragOperationForDraggingInfo

public int dragOperationForDraggingInfo( NSDraggingInfo dragInfo, String type)

Returns the type of drag operation that should be performed if the image were released now. type is the pasteboard type that will be read from the dragging pasteboard , and dragInfo is an object the Application Kit creates that holds information about the dragging session. 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.

If none of the operations is appropriate, this method should return NSDraggingInfo.DragOperationNone.

This method is called repeatedly from draggingEntered and draggingUpdated as the user drags the image.

See Also: draggingEntered (NSDraggingDestination), draggingUpdated (NSDraggingDestination)



drawInsertionPointInRect

public void drawInsertionPointInRect( NSRect aRect, NSColor aColor, boolean flag)

If flag is true, draws the insertion point in aRect using aColor. If flag is false, this method erases the insertion point. The focus must be locked on the receiver when this method is invoked.

See Also: insertionPointColor, shouldDrawInsertionPoint, backgroundColor, lockFocus (NSView)



drawsBackground

public boolean drawsBackground()

Returns true if the receiver draws its background, false if it doesn't.

See Also: backgroundColor, setDrawsBackground



firstRectForCharacterRange

public NSRect firstRectForCharacterRange(NSRange aRange)

Description forthcoming.

hasMarkedText

public boolean hasMarkedText()

Description forthcoming.

importsGraphics

public boolean importsGraphics()

Returns true if the text views sharing the receiver's NSLayoutManager allow the user to import files by dragging, false if they don't.

A text view that accepts dragged files is also a rich text view.

See Also: isRichText, textStorage, - insertAttributedString:atIndex: (NSMutableAttributedString), setImportsGraphics



insertText

public void insertText(Object aString)

Inserts aString into the receiver's text at the insertion point if there is one, otherwise replacing the selection. The inserted text is assigned the current typing attributes, as explained in the class description under "Setting Text Attributes" .

This method is the means by which typed text enters an NSTextView. See the NSInputManager class and NSTextInput protocol specifications for more information.

See Also: typingAttributes



insertionPointColor

public NSColor insertionPointColor()

Returns the color used to draw the insertion point.

See Also: drawInsertionPointInRect, shouldDrawInsertionPoint, setInsertionPointColor



invalidateTextContainerOrigin

public void invalidateTextContainerOrigin()

Informs the receiver that it needs to recalculate the origin of its text container, usually because it's been resized or the contents of the text container have changed. This method is invoked automatically; you should never need to invoke it directly.

See Also: textContainer, textContainerOrigin



isEditable

public boolean isEditable()

Returns true if the text views sharing the receiver's NSLayoutManager allow the user to edit text, false if they don't. If a text view is editable, it's also selectable.

See Also: isSelectable, setEditable



isFieldEditor

public boolean isFieldEditor()

Returns true if the text views sharing the receiver's NSLayoutManager interpret Tab, Shift-Tab, and Return (Enter) as cues to end editing, and possibly to change the first responder; no if they accept them as text input. See the NSWindow class specification for more information on field editors. By default, NSTextViews don't behave as field editors.

See Also: setFieldEditor



isRichText

public boolean isRichText()

Returns true if the text views sharing the receiver's NSLayoutManager allow the user to apply attributes to specific ranges of the text, false if they don't.

See Also: importsGraphics, textStorage, setRichText



isRulerVisible

public boolean isRulerVisible()

Returns true if the scroll view enclosing the text views sharing the receiver's NSLayoutManager shows its ruler, false otherwise.

See Also: usesRuler, setRulerVisible, toggleRuler (NSText)



isSelectable

public boolean isSelectable()

Returns true if the text views sharing the receiver's NSLayoutManager allow the user to select text, false if they don't.

See Also: isEditable, setSelectable



layoutManager

public NSLayoutManager layoutManager()

Returns the NSLayoutManager that lays out text for the receiver's text container, or null if there's no such object (which is the case when a text view isn't linked into a group of text objects).

See Also: textContainer, setLayoutManager (NSTextContainer), replaceLayoutManager (NSTextContainer)



loosenKerning

public void loosenKerning(Object sender)

This action method increases the space between glyphs in the receiver's selection, or in all text if the receiver is a plain text view. Kerning values are determined by the point size of the fonts in the selection.

See Also: tightenKerning, turnOffKerning, useStandardKerning



lowerBaseline

public void lowerBaseline(Object sender)

This action method lowers the baseline offset of selected text by one point, or of all text if the receiver is a plain text view. As such, this method defines a more primitive operation than subscripting.

See Also: raiseBaseline, subscript (NSText), unscript (NSText)



markedRange

public NSRange markedRange()

Returns the range of marked text. If there's no marked text, returns a range whose location is NotFound.

See Also: setMarkedTextAttributes



markedTextAttributes

public NSDictionary markedTextAttributes()

Returns the attributes used to draw marked text.

See Also: setMarkedTextAttributes



pasteAsPlainText

public void pasteAsPlainText(Object sender)

This action method inserts the contents of the pasteboard into the receiver's text as plain text, in the manner of insertText.

See Also: pasteAsRichText, insertText



pasteAsRichText

public void pasteAsRichText(Object sender)

This action method inserts the contents of the pasteboard into the receiver's text as rich text, maintaining its attributes. The text is inserted at the insertion point if there is one, otherwise replacing the selection.

See Also: pasteAsRichText, insertText



preferredPasteboardTypeFromArray

public String preferredPasteboardTypeFromArray( NSArray availableTypes, NSArray allowedTypes)

Returns whatever type on the pasteboard would be most preferred for copying data. The availableTypes parameter lists the types that are currently available on the pasteboard. If the allowedTypes parameter is not null then only types in that array may be returned; otherwise, if allowedTypes is null, any of the available pasteboard types may be returned.

You should not need to override this method. You should also not need to invoke it unless you were implementing a new type of pasteboard to handle services other than copy/paste or dragging.

See Also: pasteAsPlainText, pasteAsRichText



raiseBaseline

public void raiseBaseline(Object sender)

This action method raises the baseline offset of selected text by one point, or of all text if the receiver is a plain text view. As such, this method defines a more primitive operation than superscripting.

See Also: lowerBaseline, superscript (NSText), unscript (NSText)



rangeForUserCharacterAttributeChange

public NSRange rangeForUserCharacterAttributeChange()

Returns the range of characters affected by an action method that changes character (not paragraph) attributes, such as the NSText action method changeFont. For rich text this is typically the range of the selection. For plain text this is the entire contents of the receiver.

If the receiver isn't editable or doesn't use the Font Panel, the range returned has a location of NotFound.

See Also: rangeForUserParagraphAttributeChange, rangeForUserTextChange, isEditable, usesFontPanel



rangeForUserParagraphAttributeChange

public NSRange rangeForUserParagraphAttributeChange()

Returns the range of characters affected by a method that changes paragraph (not character) attributes, such as the NSText action method alignLeft. For rich text this is typically calculated by extending the range of the selection to paragraph boundaries. For plain text this is the entire contents of the receiver.

If the receiver isn't editable the range returned has a location of NotFound.

See Also: rangeForUserParagraphAttributeChange, rangeForUserTextChange, isEditable, usesRuler



rangeForUserTextChange

public NSRange rangeForUserTextChange()

Returns the range of characters affected by a method that changes characters (as opposed to attributes), such as insertText. This is typically the range of the selection.

If the receiver isn't editable or doesn't use a ruler, the range returned has a location of NotFound.

See Also: rangeForUserParagraphAttributeChange, rangeForUserTextChange, isEditable, usesRuler



readablePasteboardTypes

public NSArray readablePasteboardTypes()

Returns an array of strings describing the types this text view can read immediately from the pasteboard. The strings are ordered by the default preferences.

You can override this method to provide support for new types of data. If you want to add support for the default types, you can invoke the superclass version of this method or add the types directly in your overridden version.

See Also: preferredPasteboardTypeFromArray, writablePasteboardTypes



readSelectionFromPasteboard

public boolean readSelectionFromPasteboard(NSPasteboard pboard)

Reads the text view's preferred type of data from the pasteboard specified by the pboard parameter. This method invokes the preferredPasteboardTypeFromArray method to determine the text view's preferred type of data and then reads the data using the readSelectionFromPasteboardOfType method. Returns true if the data was successfully read.

You should not need to override this method. You might need to invoke this method if you are implementing a new type of pasteboard to handle services other than copy/paste or dragging.

See Also: preferredPasteboardTypeFromArray, readSelectionFromPasteboardOfType



readSelectionFromPasteboardOfType

public boolean readSelectionFromPasteboardOfType( NSPasteboard pboard, String type)

Reads data of the given type from pboard. The new data is placed at the current insertion point, replacing the current selection if one exists. Returns true if the data was successfully read.

You should override this method to read pasteboard types other than the default types. Use the rangeForUserTextChange method to obtain the range of characters (if any) to be replaced by the new data.

See Also: rangeForUserTextChange



replaceTextContainer

public void replaceTextContainer(NSTextContainer aTextContainer)

Replaces the NSTextContainer for the group of text-system objects containing the receiver with aTextContainer, keeping the association between the receiver and its layout manager intact, unlike setTextContainer. Throws InvalidArgumentException if aTextContainer is null.

See Also: setTextContainer



resignFirstResponder

public boolean resignFirstResponder()

Notifies the receiver that it's been asked to relinquish its status as first responder in its NSWindow. If the object that will become the new first responder is an NSTextView attached to the same NSLayoutManager as the receiver, this method returns true with no further action. Otherwise, this method sends a textShouldEndEditing message to its delegate (if any). If the delegate returns false, this method returns false. If the delegate returns true this method hides the selection highlighting and posts a TextDidEndEditingNotification to the default notification center.

Use NSWindow's makeFirstResponder, not this method, to make an NSTextView the first responder. Never invoke this method directly.

See Also: becomeFirstResponder



rulerViewDidAddMarker

public void rulerViewDidAddMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method modifies the paragraph style of the paragraphs containing the selection to accommodate a new NSTextTab represented by aMarker. It then records the change by invoking didChangeText.

NSTextView checks for permission to make the change in its rulerViewShouldAddMarker method, which invokes shouldChangeTextInRange to send out the proper request and notifications, and only invokes this method if permission is granted.

See Also: representedObject (NSRulerMarker), rulerViewDidMoveMarker, rulerViewDidRemoveMarker



rulerViewDidMoveMarker

public void rulerViewDidMoveMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method modifies the paragraph style of the paragraphs containing the selection to record the new location of the NSTextTab represented by aMarker. It then records the change by invoking didChangeText.

NSTextView checks for permission to make the change in its rulerViewShouldMoveMarker method, which invokes shouldChangeTextInRange to send out the proper request and notifications, and only invokes this method if permission is granted.

See Also: representedObject (NSRulerMarker), rulerViewDidAddMarker, rulerViewDidRemoveMarker



rulerViewDidRemoveMarker

public void rulerViewDidRemoveMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method modifies the paragraph style of the paragraphs containing the selection-if possible-by removing the NSTextTab represented by aMarker. It then records the change by invoking didChangeText.

NSTextView checks for permission to move or remove a tab stop in its rulerViewShouldMoveMarker method, which invokes shouldChangeTextInRange to send out the proper request and notifications, and only invokes this method if permission is granted.

See Also: representedObject (NSRulerMarker), shouldChangeTextInRange, rulerViewDidAddMarker, rulerViewDidMoveMarker



rulerViewHandleMouseDown

public void rulerViewHandleMouseDown( NSRulerView aRulerView, NSEvent theEvent)

This NSRulerView client method adds a left tab marker to the ruler, but a subclass can override this method to provide other behavior, such as creating guidelines. This method is invoked once with theEvent when the user first clicks in the aRulerView's ruler area, as described in the NSRulerView class specification.

rulerViewShouldAddMarker

public boolean rulerViewShouldAddMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method controls whether a new tab stop can be added. The receiver checks for permission to make the change by invoking shouldChangeTextInRange and returning the return value of that message. If the change is allowed, the receiver is then sent a rulerViewDidAddMarker message.

See Also: rulerViewShouldMoveMarker, rulerViewShouldRemoveMarker



rulerViewShouldMoveMarker

public boolean rulerViewShouldMoveMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method controls whether an existing tab stop can be moved. The receiver checks for permission to make the change by invoking shouldChangeTextInRange and returning the return value of that message. If the change is allowed, the receiver is then sent a rulerViewDidAddMarker message.

See Also: rulerViewShouldAddMarker, rulerViewShouldRemoveMarker



rulerViewShouldRemoveMarker

public boolean rulerViewShouldRemoveMarker( NSRulerView aRulerView, NSRulerMarker aMarker)

This NSRulerView client method controls whether an existing tab stop can be removed. Returns true if aMarker represents an NSTextTab, false otherwise. Because this method can be invoked repeatedly as the user drags a ruler marker, it returns that value immediately. If the change is allows and the user actually removes the marker, the receiver is also sent a rulerViewDidRemoveMarker message.

See Also: rulerViewShouldAddMarker, rulerViewShouldMoveMarker



rulerViewWillAddMarker

public float rulerViewWillAddMarker( NSRulerView aRulerView, NSRulerMarker aMarker, float location)

This NSRulerView client method ensures that the proposed location of aMarker lies within the appropriate bounds for the receiver's text container, returning the modified location.

See Also: rulerViewDidAddMarker



rulerViewWillMoveMarker

public float rulerViewWillMoveMarker( NSRulerView aRulerView, NSRulerMarker aMarker, float location)

This NSRulerView client method ensures that the proposed location of aMarker lies within the appropriate bounds for the receiver's text container, returning the modified location.

See Also: rulerViewDidMoveMarker



selectedRange

public NSRange selectedRange()

Returns the range of characters selected in the receiver's layout manager.

See Also: selectedTextAttributes, selectionRangeForProposedRange, setSelectedRange:



selectedTextAttributes

public NSDictionary selectedTextAttributes()

Returns the attributes used to indicate the selection. This is typically just the text background color.

See Also: selectedRange, setSelectedTextAttributes



selectionAffinity

public int selectionAffinity()

Returns the preferred direction of selection, either SelectionAffinityUpstream or SelectionAffinityDownstream. Selection affinity determines whether, for example, the insertion point appears after the last character on a line or before the first character on the following line in cases where text wraps across line boundaries.

selectionGranularity

public int selectionGranularity()

Returns the current selection granularity, used during mouse tracking to modify the range of the selection. This is one of:

See Also: selectionRangeForProposedRange, setSelectionGranularity



selectionRangeForProposedRange

public NSRange selectionRangeForProposedRange( NSRange proposedSelRange, int granularity)

Adjusts the proposedSelRange if necessary, based on granularity. granularity is one of:

Returns the adjusted range. This method is invoked repeatedly during mouse tracking to modify the range of the selection. Override this method to specialize selection behavior.

See Also: setSelectionGranularity



setAlignmentInRange

public void setAlignmentInRange( int alignment, NSRange aRange)

Sets the alignment of the paragraphs containing characters in aRange to alignment. alignment is one of:

See Also: rangeForUserParagraphAttributeChange



setAllowsUndo

public void setAllowsUndo(boolean flag)

Description forthcoming.

setBackgroundColor

public void setBackgroundColor(NSColor aColor)

Sets the receiver's background color to aColor.

See Also: setDrawsBackground, backgroundColor



setConstrainedFrameSize

public void setConstrainedFrameSize(NSSize desiredSize)

Attempts to set the frame size for the NSTextView to desiredSize, constrained by the receiver's existing minimum and maximum sizes and by whether resizing is permitted.

See Also: minSize (NSText), maxSize (NSText), isHorizontallyResizable (NSText), isVerticallyResizable (NSText)



setDelegate

public void setDelegate(Object anObject)

Sets the delegate for all NSTextViews sharing the receiver's NSLayoutManager to anObject, without retaining it.

See Also: delegate



setDrawsBackground

public void setDrawsBackground(boolean flag)

Controls whether the receiver draws its background. If flag is true, the receiver fills its background with the background color; if flag is false, it doesn't.

See Also: setBackgroundColor, drawsBackground



setEditable

public void setEditable(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager allow the user to edit text. If flag is true, they allow the user to edit text and attributes; if flag is false, they don't. If an NSTextView is made editable, it's also made selectable. NSTextViews are by default editable.

See Also: setSelectable, isEditable



setFieldEditor

public void setFieldEditor(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager interpret Tab, Shift-Tab, and Return (Enter) as cues to end editing, and possibly to change the first responder. If flag is true, they do; if flag is false, they don't, instead accepting these characters as text input. See the NSWindow class specification for more information on field editors. By default, NSTextViews don't behave as field editors.

See Also: isFieldEditor



setImportsGraphics

public void setImportsGraphics(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager allow the user to import files by dragging. If flag is true, they do; if flag is false, they don't. If an NSTextView is set to accept dragged files, it's also set for rich text. By default, NSTextViews don't accept dragged files.

See Also: textStorage, setRichText, importsGraphics



setInsertionPointColor

public void setInsertionPointColor(NSColor aColor)

Sets the color of the insertion point to aColor.

See Also: drawInsertionPointInRect, shouldDrawInsertionPoint, insertionPointColor



setMarkedTextAndSelectedRange

public void setMarkedTextAndSelectedRange( Object anObject, NSRange aRange)

Description forthcoming.

setMarkedTextAttributes

public void setMarkedTextAttributes(NSDictionary attributes)

Sets the attributes used to draw marked text to attributes. Text color, background color, and underline are the only supported attributes for marked text.

See Also: markedTextAttributes, markedRange



setNeedsDisplay

public void setNeedsDisplay( NSRect aRect, boolean flag)

Marks the receiver as requiring display within aRect. If flag is true, the receiver won't perform any layout that might be required to complete the display, even if this means that portions of the NSTextView remain empty. If flag is false, the receiver performs at least as much layout as needed to display aRect.

NSTextView overrides the NSView setNeedsDisplay method such that it invokes this method with a flag argument of false.



setRichText

public void setRichText(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager allow the user to apply attributes to specific ranges of the text. If flag is true they do; if flag is false they don't. If flag is false, they're also set not to accept dragged files. By default, NSTextViews let the user apply multiple attributes to text, but don't accept dragged files.

See Also: textStorage, isRichText, setImportsGraphics



setRulerVisible

public void setRulerVisible(boolean flag)

Controls whether the scroll view enclosing text views sharing the receiver's NSLayoutManager displays the ruler. If flag is true it shows the ruler; if flag is false it hides the ruler. By default, the ruler is not visible.

See Also: setUsesRuler, isRulerVisible, toggleRuler (NSText)



setSelectable

public void setSelectable(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager allow the user to select text. If flag is false, they do; if flag is false, they don't. If an NSTextView is made not selectable, it's also made not editable. NSTextViews are by default both editable and selectable.

See Also: setEditable, isSelectable



setSelectedRange

public void setSelectedRange( NSRange charRange, int affinity, boolean flag)

Sets the selection to the characters in charRange, using affinity if needed to determine how to display the selection or insertion point (see the description for selectionAffinity for more information). flag indicates whether this method is being invoked during mouse-dragging or after the user releases the mouse. If flag is true the receiver doesn't send notifications or remove the marking from its marked text; if flag is false it does as appropriate. This method also resets the selection granularity to SelectByCharacter.

charRange must begin and end on glyph boundaries and not split base glyphs and their non-spacing marks.

public void setSelectedRange(NSRange charRange)

Sets the selection to the characters in charRange, resets the selection granularity to SelectByCharacter, posts a TextViewDidChangeSelectionNotification to the default notification center. Also removes the marking from marked text if the new selection is greater than the marked region.

charRange must begin and end on glyph boundaries and not split base glyphs and their non-spacing marks.

See Also: selectionAffinity, selectionGranularity, selectedRange



setSelectedTextAttributes

public void setSelectedTextAttributes(NSDictionary attributes)

Sets the attributes used to indicate the selection to attributes. Text color, background color, and underline are the only supported attributes for selected text.

See Also: selectedRange, selectedTextAttributes



setSelectionGranularity

public void setSelectionGranularity(int granularity)

Sets the selection granularity for subsequent extension of a selection to granularity. granularity may be one of:

Selection granularity is used to determine how the selection is modified when the user Shift-clicks or drags the mouse after a double- or triple-click. For example, if the user selects a word by double-clicking, the selection granularity is set to SelectByWord. Subsequent shift-clicks then extend the selection by words.

Selection granularity is reset to SelectByCharacter whenever the selection is set. You should always set the selection granularity after setting the selection.

See Also: selectionGranularity, setSelectedRange:



setSmartInsertDeleteEnabled

public void setSmartInsertDeleteEnabled(boolean flag)

Controls whether the receiver inserts or deletes space around selected words so as to preserve proper spacing and punctuation. If flag is true it does; if flag is false it inserts and deletes exactly what's selected.

See Also: smartDeleteRangeForProposedRange, smartInsertDeleteEnabled



setTextContainer

- (void)setTextContainer:(NSTextContainer *)aTextContainer

Sets the receiver's text container to aTextContainer. The receiver then uses the layout manager and text storage of aTextContainer. This method is invoked automatically when you create an NSTextView; you should never invoke it directly, but might want to override it. To change the text view for an established group of text-system objects, send setTextView: to the text container. To replace the text container for a text view and maintain the view's association with the existing layout manager and text storage, use replaceTextContainer.

See Also: textContainer



setTextContainerInset

public void setTextContainerInset(NSSize inset)

Sets the empty space the NSTextView leaves around its associated text container to inset.

See Also: textContainerOrigin, invalidateTextContainerOrigin, textContainerInset



setTypingAttributes

public void setTypingAttributes(NSDictionary attributes)

Sets the receiver's typing attributes to attributes. Typing attributes are reset automatically whenever the selection changes. If you add any user actions that change text attributes, you should use this method to apply those attributes to a zero-length selection.

See Also: typingAttributes



setUsesFontPanel

public void setUsesFontPanel(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager use the Font Panel and Font menu. If flag is true, they respond to messages from the Font Panel and from the Font menu, and update the Font Panel with the selection font whenever it changes. If flag is false they disallow character attribute changes. By default, NSTextView objects use the Font Panel and menu.

See Also: rangeForUserCharacterAttributeChange, usesFontPanel



setUsesRuler

public void setUsesRuler(boolean flag)

Controls whether the text views sharing the receiver's NSLayoutManager use an NSRulerView and respond to Format menu commands. If flag is true, they respond to NSRulerView client messages and to paragraph-related menu actions, and update the ruler (when visible) as the selection changes with its paragraph and tab attributes. If flag is false, the ruler is hidden and the text views disallow paragraph attribute changes. By default, NSTextView objects use the ruler.

See Also: setRulerVisible, rangeForUserParagraphAttributeChange, usesRuler



shouldChangeTextInRange

public boolean shouldChangeTextInRange( NSRange affectedCharRange, String replacementString)

Initiates a series of delegate messages (and general notifications) to determine whether modifications can be made to the receiver's text. If characters in the text string are being changed, replacementString contains the characters that will replace the characters in affectedCharRange. If only text attributes are being changed, replacementString is null. This method checks with the delegate as needed using textShouldBeginEditing and textViewShouldChangeTextInRange, returning true to allow the change, and false to prohibit it.

This method must be invoked at the start of any sequence of user-initiated editing changes. If your subclass of NSTextView implements new methods that modify the text, make sure to invoke this method to determine whether the change should be made. If the change is allowed, complete the change by invoking the didChangeText method. See "Notifying About Changes to the Text" in the class description for more information. If you can't determine the affected range or replacement string before beginning changes, pass (NSArray.NotFound, 0) and null for these values.

See Also: isEditable



shouldDrawInsertionPoint

public boolean shouldDrawInsertionPoint()

Returns true if the receiver should draw its insertion point, false if the insertion point can't or shouldn't be drawn. For example, you might not want to draw the insertion point if the receiver's window isn't key).

See Also: drawInsertionPointInRect



smartDeleteRangeForProposedRange

public NSRange smartDeleteRangeForProposedRange(NSRange proposedCharRange)

Given proposedCharRange, returns an extended range that includes adjacent whitespace that should be deleted along with the proposed range in order to preserve proper spacing and punctuation of the text surrounding the deletion.

NSTextView uses this method as necessary; you can also use it in implementing your own methods that delete text, typically when the selection granularity is SelectByWord. To do so, invoke this method with the proposed range to delete, then actually delete the range returned. If placing text on the pasteboard, however, you should put only the characters from the proposed range onto the pasteboard.

See Also: selectionGranularity, smartInsertDeleteEnabled



smartInsertAfterStringForString

public String smartInsertAfterStringForString( String aString, NSRange charRange)

Returns any whitespace that needs to be added after aString to preserve proper spacing and punctuation when aString is inserted into the receiver's text over charRange. If aString is null or if smart insertion and deletion is disabled, this method returns null.

When inserting text, insert the following over charRange:



smartInsertBeforeStringForString

public String smartInsertBeforeStringForString( String aString, NSRange charRange)

Returns any whitespace that needs to be added before aString to preserve proper spacing and punctuation when aString is inserted into the receiver's text over charRange. If aString is null or if smart insertion and deletion is disabled, this method returns null.

When inserting text, insert the following over charRange:



smartInsertDeleteEnabled

public boolean smartInsertDeleteEnabled()

Returns true if the receiver inserts or deletes space around selected words so as to preserve proper spacing and punctuation, false if it inserts and deletes exactly what's selected.

See Also: smartDeleteRangeForProposedRange, setSmartInsertDeleteEnabled



spellCheckerDocumentTag

public int spellCheckerDocumentTag()

Returns a tag identifying the NSTextView text as a document for the spell checker server. The document tag is obtained by sending a uniqueSpellDocumentTag message to the spell server the first time this method is invoked for a particular group of NSTextViews. See the NSSpellChecking and NSSpellServer class specifications for more information on how this tag is used.

textContainer

public NSTextContainer textContainer()

Returns the receiver's text container.

See Also: setTextContainer



textContainerInset

public NSSize textContainerInset()

Returns the empty space the NSTextView leaves around its text container.

See Also: textContainerOrigin, invalidateTextContainerOrigin, setTextContainerInset



textContainerOrigin

public NSPoint textContainerOrigin()

Returns the origin of the receiver's text container, which is calculated from the receiver's bounds rectangle, container inset, and the container's used rect.

See Also: invalidateTextContainerOrigin, textContainerInset, usedRectForTextContainer (NSLayoutManager)



textStorage

public NSTextStorage textStorage()

Returns the receiver's text storage object.

tightenKerning

public void tightenKerning(Object sender)

This action method decreases the space between glyphs in the receiver's selection, or for all glyphs if the receiver is a plain text view. Kerning values are determined by the point size of the fonts in the selection.

See Also: loosenKerning, useStandardKerning, turnOffKerning



turnOffKerning

public void turnOffKerning(Object sender)

This action method causes the receiver to use nominal glyph spacing for the glyphs in its selection, or for all glyphs if the receiver is a plain text view.

See Also: useStandardKerning, loosenKerning, tightenKerning, isRichText



turnOffLigatures

public void turnOffLigatures(Object sender)

This action method causes the receiver to use only required ligatures when setting text, for the glyphs in the selection if the receiver is a rich text view, or for all glyphs if it's a plain text view.

See Also: useAllLigatures, isRichText, useStandardLigatures



typingAttributes

public NSDictionary typingAttributes()

Returns the current typing attributes.

See Also: setTypingAttributes



unmarkText

public void unmarkText()

Description forthcoming.

updateDragTypeRegistration

public void updateDragTypeRegistration()

If the receiver is editable and is a rich text view, causes all NSTextViews associated with the receiver's NSLayoutManager to register their acceptable drag types. If the NSTextView isn't editable or isn't rich text, causes those NSTextViews to unregister their dragged types.

Subclasses can override this method to change the conditions for registering and unregistering drag types, whether as a group or individually based on the current state of the NSTextView. They can then invoke this method when that state changes to perform that reregistration.

See Also: acceptableDragTypes, registerForDraggedTypes (NSView), unregisterDraggedTypes (NSView), isEditable, importsGraphics, isRichText



updateFontPanel

public void updateFontPanel()

Updates the Font Panel to contain the font attributes of the selection. Does nothing if the receiver doesn't use the Font Panel. You should never need to invoke this method directly, but you can override it if needed to handle additional font attributes.

See Also: usesFontPanel



updateInsertionPointStateAndRestartTimer

public void updateInsertionPointStateAndRestartTimer(boolean flag)

Updates the insertion point's location and, if flag is true, restarts the blinking cursor timer. This method is invoked automatically whenever the insertion point needs to be moved; you should never need to invoke it directly, but you can override it to add different insertion point behavior.

See Also: shouldDrawInsertionPoint, drawInsertionPointInRect



updateRuler

public void updateRuler()

Updates the NSRulerView in the receiver's enclosing scroll view to reflect the selection's paragraph and marker attributes. Does nothing if the ruler isn't visible or if the receiver doesn't use the ruler. You should never need to invoke this method directly, but you can override this method if needed to handle additional ruler attributes.

See Also: usesRuler



useAllLigatures

public void useAllLigatures(Object sender)

This action method causes the receiver to use all ligatures available for the fonts and languages used when setting text, for the glyphs in the selection if the receiver is a rich text view, or for all glyphs if it's a plain text view.

See Also: turnOffLigatures, useStandardLigatures



useStandardKerning

public void useStandardKerning(Object sender)

This action method causes the receiver to use pair kerning data for the glyphs in its selection, or for all glyphs if the receiver is a plain text view. This data is taken from a font's AFM file

See Also: isRichText, loosenKerning, tightenKerning, turnOffKerning



useStandardLigatures

public void useStandardLigatures(Object sender)

This action method causes the receiver to use the standard ligatures available for the fonts and languages used when setting text, for the glyphs in the selection if the receiver is a rich text view, or for all glyphs if it's a plain text view.

See Also: turnOffLigatures, useAllLigatures



usesFontPanel

public boolean usesFontPanel()

Returns true if the text views sharing the receiver's NSLayoutManager use the Font Panel, false otherwise. See setUsesFontPanel and rangeForUserCharacterAttributeChange for the effect this has on an NSTextView's behavior.

usesRuler

public boolean usesRuler()

Returns true if the text views sharing the receiver's NSLayoutManager use a ruler view, false otherwise. See setUsesRuler and rangeForUserParagraphAttributeChange for the effect this has on an NSTextView's behavior

See Also: setUsesRuler



validAttributesForMarkedText

public NSArray validAttributesForMarkedText()

Description forthcoming.

validRequestorForTypes

public Object validRequestorForTypes( String sendType, String returnType)

Returns this if sendType specifies a type of data the text view can put on the pasteboard and returnType contains a type of data the text view can read from the pasteboard; otherwise returns null.

See Also: validRequestorForTypes (NSResponder)



writablePasteboardTypes

public NSArray writablePasteboardTypes()

If the text view contains some selected data, this method returns an array of strings describing the types that can be written to the pasteboard immediately. You can override this method to add new supported types to the array of strings.

See Also: readablePasteboardTypes



writeSelectionToPasteboardOfType

public boolean writeSelectionToPasteboardOfType( NSPasteboard pboard, String type)

Writes the current selection to pboard using the given type. Returns true if the data was successfully written. You can override this method to add support for writing new types of data to the pasteboard. You should invoke super's implementation of the method to handle any types of data your overridden version does not.

See Also: readSelectionFromPasteboardOfType



writeSelectionToPasteboardOfTypes

public boolean writeSelectionToPasteboardOfTypes( NSPasteboard pboard, NSArray types)

Writes the current selection to pboard under each type in the types array. Returns true if the data for any single type was written successfully.

You should not need to override this method. You might need to invoke this method if you are implementing a new type of pasteboard to handle services other than copy/paste or dragging.

See Also: writeSelectionToPasteboardOfType




Methods Implemented By the Delegate


NSTextView communicates with its delegate through methods declared both by NSTextView and by its superclass, NSText. See the NSText class specification for those other delegate methods.



textViewClickedCell

public abstract void textViewClickedCell( NSTextView aTextView, NSCellForTextAttachment attachmentCell, NSRect cellFrame)

Invoked after the user clicks on attachmentCell within cellFrame in an NSTextView and the cell wants to track the mouse. The delegate can use this message as its cue to perform an action or select the attachment cell's character. aTextView is the first NSTextView in a series shared by an NSLayoutManager, not necessarily the one that draws attachmentCell.

The delegate may subsequently receive a textViewDoubleClickedCell message if the user continues to perform a double click.

This method is being deprecated in favor of textViewClickedCellAtIndex.

See Also: wantsToTrackMouse (NSTextAttachmentCell)



textViewClickedCellAtIndex

public abstract void textViewClickedCellAtIndex( NSTextView textView, NSCellForTextAttachment cell, NSRect cellFrame, int charIndex)

Invoked after the user clicks on cell within cellFrame at the specified charIndex in an NSTextView and the cell wants to track the mouse. The delegate can use this message as its cue to perform an action or select the attachment cell's character. textView is the first NSTextView in a series shared by an NSLayoutManager, not necessarily the one that draws cell.

The delegate may subsequently receive a textViewDoubleClickedCellAtIndex message if the user continues to perform a double click.

See Also: textViewDoubleClickedCellAtIndex



textViewClickedOnLink

public abstract boolean textViewClickedOnLink( NSTextView textView, Object link)

Invoked after the user clicks on link in an NSTextView if the delegate does not respond to the textViewClickedOnLinkAtIndex message. The delegate can use this method to handle the click on the link.

This method is being deprecated in favor of textViewClickedOnLinkAtIndex.

See Also: clickedOnLinkAtIndex (NSTextView), textViewClickedOnLinkAtIndex



textViewClickedOnLinkAtIndex

public abstract boolean textViewClickedOnLinkAtIndex( NSTextView textView, Object link, int charIndex)

Invoked after the user clicks on link at the specified charIndex in an NSTextView. The delegate can use this method to handle the click on the link. Return true to indicate that the click was handled, otherwise return false to allow the next responder to handle it.

See Also: clickedOnLinkAtIndex (NSTextView)



textViewDidChangeSelection

public abstract void textViewDidChangeSelection(NSNotification aNotification)

Invoked when the selection changes in the NSTextView. The name of aNotification is TextViewDidChangeSelectionNotification.

See Also: TextViewDidChangeSelectionNotification (notification)



textViewDoCommandBySelector

public abstract boolean textViewDoCommandBySelector( NSTextView aTextView, NSSelector aSelector)

Sent from NSTextView's doCommandBySelector, this method allows the delegate to perform the command for the text view. If the delegate returns true, the text view doesn't perform aSelector; if the delegate returns false, the text view attempts to perform it. aTextView is the first NSTextView in a series shared by an NSLayoutManager.

textViewDoubleClickedCell

public abstract void textViewDoubleClickedCell( NSTextView aTextView, CellForTextAttachment attachmentCell, NSRect cellFrame)

Invoked when the user double-clicks on attachmentCell within cellFrame in an NSTextView and the cell wants to track the mouse. The delegate can use this message as its cue to perform an action, such as opening the file represented by the attachment. aTextView is the first NSTextView in a series shared by an NSLayoutManager, not necessarily the one that draws attachmentCell.

This method is being deprecated in favor of textViewDoubleClickedCellAtIndex.

See Also: wantsToTrackMouse (NSTextAttachmentCell), textViewDoubleClickedCellAtIndex



textViewDoubleClickedCellAtIndex

public abstract void textViewDoubleClickedCellAtIndex( NSTextView textView, NSCellForTextAttachment cell, NSRect cellFrame, int charIndex)

Invoked when the user double-clicks on attachmentCell within cellFrame at the specified charIndex in an NSTextView and the cell wants to track the mouse. The delegate can use this message as its cue to perform an action, such as opening the file represented by the attachment. aTextView is the first NSTextView in a series shared by an NSLayoutManager, not necessarily the one that draws attachmentCell.

See Also: wantsToTrackMouse (NSTextAttachmentCell)



textViewDraggedCell

public abstract void textViewDraggedCell( NSTextView aTextView, NSCellForTextAttachment attachmentCell, NSRect aRect, NSEvent theEvent)

Invoked when the user attempts to drag attachmentCell from aRect within an NSTextView and the cell wants to track the mouse. theEvent is the mouse-down event that preceded the mouse-dragged event. The delegate can use this message as its cue to initiate a dragging operation.

This method is being deprecated in favor of textViewDraggedCellAtIndex.

See Also: wantsToTrackMouse (NSTextAttachmentCell), dragImage (NSView), dragFile (NSView)



textViewDraggedCellAtIndex

public abstract void textViewDraggedCellAtIndex( NSTextView view, NSCellForTextAttachment cell, NSRect rect, NSEvent event, int charIndex)

Invoked when the user attempts to drag attachmentCell from aRect within an NSTextView and the cell wants to track the mouse. The event parameter is the mouse-down event that preceded the mouse-dragged event. The charIndex parameter indicates the character position where the mouse was clicked. The delegate can use this message as its cue to initiate a dragging operation.

See Also: wantsToTrackMouse (NSTextAttachmentCell), dragImage (NSView), dragFile (NSView)



textViewShouldChangeTextInRange

public abstract boolean textViewShouldChangeTextInRange( NSTextView aTextView, NSRange affectedCharRange, String replacementString)

Invoked when an NSTextView needs to determine if text in the range affectedCharRange should be changed. If characters in the text string are being changed, replacementString contains the characters that will replace the characters in affectedCharRange. If only text attributes are being changed, replacementString is null. The delegate can return true to allow the replacement, or false to reject the change.

aTextView is the first NSTextView in a series shared by an NSLayoutManager.



textViewWillChangeSelection

public abstract NSRange textViewWillChangeSelection( NSTextView aTextView, NSRange oldSelectedCharRange, NSRange newSelectedCharRange)

Invoked before an NSTextView finishes changing the selection-that is, when the last argument to a setSelectedRange:affinity:stillSelecting: message is false. oldSelectedCharRange is the original range of the selection. newSelectedCharRange is the proposed character range for the new selection. The delegate can return an adjusted range or return newSelectedCharRange unmodified.

aTextView is the first NSTextView in a series shared by an NSLayoutManager.



undoManagerForTextView

public abstract NSUndoManager undoManagerForTextView(NSTextView view)

Description forthcoming.


Notifications


NSTextView posts the following notifications as well as those declared by its superclasses, particularly NSText. See the NSText class specification for those other notifications.

TextViewDidChangeSelectionNotification

Posted when the selected range of characters changes. NSTextView posts this notification whenever setSelectedRangeis invoked either directly, or through the many methods ( mouseDown, selectAll:, and so on) that invoke it indirectly. When the user is selecting text, this notification is posted only once, at the end of the selection operation. The NSTextView's delegate receives a textViewDidChangeSelection message when this notification is posted.

This notification contains a notification object and a userInfo dictionary. The notification object is the notifying NSTextView. The userInfo dictionary contains these keys and values:


Key Value
OldSelectedCharacterRange An NSValue object containing an NSRange

TextViewWillChangeNotifyingTextViewNotification

Posted when a new NSTextView is established as the NSTextView that sends notifications. This allows observers to reregister themselves for the new NSTextView. Methods such as removeTextContainerAtIndex, textContainerChangedTextView:, and insertTextContainerAtIndex cause this notification to be posted.

This notification contains a notification object and a userInfo dictionary. The notification object is the old notifying NSTextView, or null. The userInfo dictionary contains these keys and values:


Key Value
OldNotifyingTextView The old NSTextView, if one exists
NewNotifyingTextView The new NSTextView, if one exists

There's no delegate method associated with this notification. The text-handling system ensures that when a new NSTextView replaces an old one as the notifying NSTextView, the existing delegate becomes the delegate of the new NSTextView and the delegate is registered to receive NSTextView notifications from the new notifying NSTextView. All other observers are responsible for registering themselves on receiving this notification.

See Also: - removeObserver: (NSNotificationCenter), - addObserver:selector:name:object: (NSNotificationCenter)



Table of Contents