- Inherits from:
- NSText : NSView : NSResponder : NSObject
- Implements:
- NSTextInput
- Package:
- com.apple.yellow.application
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.
Instances of this class can be created using Interface Builder or using one of its constructors.
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. |
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:
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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. |
NSTextInput
- - conversationIdentifier
- - doCommandBySelector:
- - getMarkedText:selectedRange:
- - hasMarkedText
- - insertText:
- - setMarkedText:selectedRange:
- - unmarkText
- 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
public NSTextView()
public NSTextView(NSRect frameRect)
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)
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.
public static void registerForServices()
public NSArray acceptableDragTypes()
See Also: updateDragTypeRegistration
public void alignJustified(Object sender)
See Also: alignCenter (NSText), alignLeft (NSText), alignRight (NSText), alignment (NSText), setAlignment (NSText)
public boolean allowsUndo()
public NSAttributedString attributedSubstringWithRange(NSRange aRange)
public NSColor backgroundColor()
See Also: drawsBackground, setBackgroundColor
public boolean becomeFirstResponder()
true
.Use NSWindow's makeFirstResponder, not this method, to make an NSTextView the first responder. Never invoke this method directly.
See Also: resignFirstResponder
public void changeColor(Object sender)
public int characterIndexForPoint(NSPoint aPoint)
public void cleanUpAfterDragOperation()
super
's
implementation.public void clickedOnLinkAtIndex(
Object link,
int charIndex)
See Also: textViewClickedOnLinkAtIndex (delegate method)
public int conversationIdentifier()
public Object delegate()
null
if there is none.See Also: setDelegate
public void didChangeText()
See Also: shouldChangeTextInRange
public void doCommandBySelector(NSSelector aSelector)
public int dragOperationForDraggingInfo(
NSDraggingInfo dragInfo,
String type)
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)
public void drawInsertionPointInRect(
NSRect aRect,
NSColor aColor,
boolean flag)
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)
public boolean drawsBackground()
true
if
the receiver draws its background, false
if
it doesn't.See Also: backgroundColor, setDrawsBackground
public NSRect firstRectForCharacterRange(NSRange aRange)
public boolean hasMarkedText()
public boolean importsGraphics()
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
public void insertText(Object aString)
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
public NSColor insertionPointColor()
See Also: drawInsertionPointInRect, shouldDrawInsertionPoint, setInsertionPointColor
public void invalidateTextContainerOrigin()
See Also: textContainer, textContainerOrigin
public boolean isEditable()
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
public boolean isFieldEditor()
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
public boolean isRichText()
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
public boolean isRulerVisible()
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)
public boolean isSelectable()
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
public NSLayoutManager layoutManager()
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)
public void loosenKerning(Object sender)
See Also: tightenKerning, turnOffKerning, useStandardKerning
public void lowerBaseline(Object sender)
See Also: raiseBaseline, subscript (NSText), unscript (NSText)
public NSRange markedRange()
NotFound
.See Also: setMarkedTextAttributes
public NSDictionary markedTextAttributes()
See Also: setMarkedTextAttributes
public void pasteAsPlainText(Object sender)
See Also: pasteAsRichText, insertText
public void pasteAsRichText(Object sender)
See Also: pasteAsRichText, insertText
public String preferredPasteboardTypeFromArray(
NSArray availableTypes,
NSArray allowedTypes)
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
public void raiseBaseline(Object sender)
See Also: lowerBaseline, superscript (NSText), unscript (NSText)
public NSRange rangeForUserCharacterAttributeChange()
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
public NSRange rangeForUserParagraphAttributeChange()
If the receiver isn't editable
the range returned has a location of NotFound
.
See Also: rangeForUserParagraphAttributeChange, rangeForUserTextChange, isEditable, usesRuler
public NSRange rangeForUserTextChange()
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
public NSArray readablePasteboardTypes()
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
public boolean readSelectionFromPasteboard(NSPasteboard pboard)
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
public boolean readSelectionFromPasteboardOfType(
NSPasteboard pboard,
String type)
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
public void replaceTextContainer(NSTextContainer aTextContainer)
null
.See Also: setTextContainer
public boolean resignFirstResponder()
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
public void rulerViewDidAddMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
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
public void rulerViewDidMoveMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
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
public void rulerViewDidRemoveMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
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
public void rulerViewHandleMouseDown(
NSRulerView aRulerView,
NSEvent theEvent)
public boolean rulerViewShouldAddMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
See Also: rulerViewShouldMoveMarker, rulerViewShouldRemoveMarker
public boolean rulerViewShouldMoveMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
See Also: rulerViewShouldAddMarker, rulerViewShouldRemoveMarker
public boolean rulerViewShouldRemoveMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker)
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
public float rulerViewWillAddMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker,
float location)
See Also: rulerViewDidAddMarker
public float rulerViewWillMoveMarker(
NSRulerView aRulerView,
NSRulerMarker aMarker,
float location)
See Also: rulerViewDidMoveMarker
public NSRange selectedRange()
See Also: selectedTextAttributes, selectionRangeForProposedRange, setSelectedRange:
public NSDictionary selectedTextAttributes()
See Also: selectedRange, setSelectedTextAttributes
public int selectionAffinity()
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.public int selectionGranularity()
SelectByCharacter
SelectByWord
SelectByParagraph
See Also: selectionRangeForProposedRange, setSelectionGranularity
public NSRange selectionRangeForProposedRange(
NSRange proposedSelRange,
int granularity)
SelectByCharacter
SelectByWord
SelectByParagraph
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
public void setAlignmentInRange(
int alignment,
NSRange aRange)
NSText.LeftTextAlignment
NSText.RightTextAlignment
NSText.CenterTextAlignment
NSText.JustifiedTextAlignment
NSText.NaturalTextAlignment
See Also: rangeForUserParagraphAttributeChange
public void setAllowsUndo(boolean flag)
public void setBackgroundColor(NSColor aColor)
See Also: setDrawsBackground, backgroundColor
public void setConstrainedFrameSize(NSSize desiredSize)
See Also: minSize (NSText), maxSize (NSText), isHorizontallyResizable (NSText), isVerticallyResizable (NSText)
public void setDelegate(Object anObject)
See Also: delegate
public void setDrawsBackground(boolean flag)
true
,
the receiver fills its background with the background color; if flag is false
,
it doesn't.See Also: setBackgroundColor, drawsBackground
public void setEditable(boolean flag)
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
public void setFieldEditor(boolean flag)
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
public void setImportsGraphics(boolean flag)
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
public void setInsertionPointColor(NSColor aColor)
See Also: drawInsertionPointInRect, shouldDrawInsertionPoint, insertionPointColor
public void setMarkedTextAndSelectedRange(
Object anObject,
NSRange aRange)
public void setMarkedTextAttributes(NSDictionary attributes)
See Also: markedTextAttributes, markedRange
public void setNeedsDisplay(
NSRect aRect,
boolean flag)
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
.
public void setRichText(boolean flag)
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
public void setRulerVisible(boolean flag)
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)
public void setSelectable(boolean flag)
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
public void setSelectedRange(
NSRange charRange,
int affinity,
boolean flag)
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)
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
public void setSelectedTextAttributes(NSDictionary attributes)
See Also: selectedRange, selectedTextAttributes
public void setSelectionGranularity(int granularity)
SelectByCharacter
SelectByWord
SelectByParagraph
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:
public void setSmartInsertDeleteEnabled(boolean flag)
true
it
does; if flag is false
it
inserts and deletes exactly what's selected.See Also: smartDeleteRangeForProposedRange, smartInsertDeleteEnabled
- (void)setTextContainer:(NSTextContainer
*)aTextContainer
See Also: textContainer
public void setTextContainerInset(NSSize inset)
See Also: textContainerOrigin, invalidateTextContainerOrigin, textContainerInset
public void setTypingAttributes(NSDictionary attributes)
See Also: typingAttributes
public void setUsesFontPanel(boolean flag)
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
public void setUsesRuler(boolean flag)
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
public boolean shouldChangeTextInRange(
NSRange affectedCharRange,
String replacementString)
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
public boolean shouldDrawInsertionPoint()
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
public NSRange smartDeleteRangeForProposedRange(NSRange proposedCharRange)
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
public String smartInsertAfterStringForString(
String aString,
NSRange charRange)
null
or if
smart insertion and deletion is disabled, this method returns null
.When inserting text, insert the following over charRange:
public String smartInsertBeforeStringForString(
String aString,
NSRange charRange)
null
or if
smart insertion and deletion is disabled, this method returns null
.When inserting text, insert the following over charRange:
public boolean smartInsertDeleteEnabled()
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
public int spellCheckerDocumentTag()
public NSTextContainer textContainer()
See Also: setTextContainer
public NSSize textContainerInset()
See Also: textContainerOrigin, invalidateTextContainerOrigin, setTextContainerInset
public NSPoint textContainerOrigin()
See Also: invalidateTextContainerOrigin, textContainerInset, usedRectForTextContainer (NSLayoutManager)
public NSTextStorage textStorage()
public void tightenKerning(Object sender)
See Also: loosenKerning, useStandardKerning, turnOffKerning
public void turnOffKerning(Object sender)
See Also: useStandardKerning, loosenKerning, tightenKerning, isRichText
public void turnOffLigatures(Object sender)
See Also: useAllLigatures, isRichText, useStandardLigatures
public NSDictionary typingAttributes()
See Also: setTypingAttributes
public void unmarkText()
public void updateDragTypeRegistration()
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
public void updateFontPanel()
See Also: usesFontPanel
public void updateInsertionPointStateAndRestartTimer(boolean flag)
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
public void updateRuler()
See Also: usesRuler
public void useAllLigatures(Object sender)
See Also: turnOffLigatures, useStandardLigatures
public void useStandardKerning(Object sender)
See Also: isRichText, loosenKerning, tightenKerning, turnOffKerning
public void useStandardLigatures(Object sender)
See Also: turnOffLigatures, useAllLigatures
public boolean usesFontPanel()
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.public boolean usesRuler()
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 behaviorSee Also: setUsesRuler
public NSArray validAttributesForMarkedText()
public Object validRequestorForTypes(
String sendType,
String returnType)
null
.See Also: validRequestorForTypes (NSResponder)
public NSArray writablePasteboardTypes()
See Also: readablePasteboardTypes
public boolean writeSelectionToPasteboardOfType(
NSPasteboard pboard,
String type)
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
public boolean writeSelectionToPasteboardOfTypes(
NSPasteboard pboard,
NSArray types)
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
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.
public abstract void textViewClickedCell(
NSTextView aTextView,
NSCellForTextAttachment attachmentCell,
NSRect cellFrame)
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)
public abstract void textViewClickedCellAtIndex(
NSTextView textView,
NSCellForTextAttachment cell,
NSRect cellFrame,
int charIndex)
The delegate may subsequently receive a textViewDoubleClickedCellAtIndex message if the user continues to perform a double click.
See Also: textViewDoubleClickedCellAtIndex
public abstract boolean textViewClickedOnLink(
NSTextView textView,
Object link)
This method is being deprecated in favor of textViewClickedOnLinkAtIndex.
See Also: clickedOnLinkAtIndex (NSTextView), textViewClickedOnLinkAtIndex
public abstract boolean textViewClickedOnLinkAtIndex(
NSTextView textView,
Object link,
int charIndex)
true
to
indicate that the click was handled, otherwise return false
to
allow the next responder to handle it.See Also: clickedOnLinkAtIndex (NSTextView)
public abstract void textViewDidChangeSelection(NSNotification aNotification)
See Also: TextViewDidChangeSelectionNotification (notification)
public abstract boolean textViewDoCommandBySelector(
NSTextView aTextView,
NSSelector aSelector)
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.public abstract void textViewDoubleClickedCell(
NSTextView aTextView,
CellForTextAttachment attachmentCell,
NSRect cellFrame)
This method is being deprecated in favor of textViewDoubleClickedCellAtIndex.
See Also: wantsToTrackMouse (NSTextAttachmentCell), textViewDoubleClickedCellAtIndex
public abstract void textViewDoubleClickedCellAtIndex(
NSTextView textView,
NSCellForTextAttachment cell,
NSRect cellFrame,
int charIndex)
See Also: wantsToTrackMouse (NSTextAttachmentCell)
public abstract void textViewDraggedCell(
NSTextView aTextView,
NSCellForTextAttachment attachmentCell,
NSRect aRect,
NSEvent theEvent)
This method is being deprecated in favor of textViewDraggedCellAtIndex.
See Also: wantsToTrackMouse (NSTextAttachmentCell), dragImage (NSView), dragFile (NSView)
public abstract void textViewDraggedCellAtIndex(
NSTextView view,
NSCellForTextAttachment cell,
NSRect rect,
NSEvent event,
int charIndex)
See Also: wantsToTrackMouse (NSTextAttachmentCell), dragImage (NSView), dragFile (NSView)
public abstract boolean textViewShouldChangeTextInRange(
NSTextView aTextView,
NSRange affectedCharRange,
String replacementString)
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.
public abstract NSRange textViewWillChangeSelection(
NSTextView aTextView,
NSRange oldSelectedCharRange,
NSRange newSelectedCharRange)
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.
public abstract NSUndoManager undoManagerForTextView(NSTextView view)
NSTextView posts the following notifications as well as those declared by its superclasses, particularly NSText. See the NSText class specification for those other notifications.
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 |
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)