| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.6 and later. |
| Declared in | NSTextView.h |
| Companion guides | |
| Related sample code |
The NSTextViewDelegate protocol defines the optional methods implemented by delegates of NSTextView objects.
– textView:willChangeSelectionFromCharacterRange:toCharacterRange:
– textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:
– textViewDidChangeSelection:
– textView:shouldChangeTextInRange:replacementString:
– textView:shouldChangeTextInRanges:replacementStrings:
– textView:shouldChangeTypingAttributes:toAttributes:
– textViewDidChangeTypingAttributes:
– textView:clickedOnCell:inRect:atIndex:
– textView:doubleClickedOnCell:inRect:atIndex:
– textView:clickedOnLink:atIndex:
– textView:shouldSetSpellingState:range:
– textView:willCheckTextInRange:options:types:
– textView:didCheckTextInRange:types:options:results:orthography:wordCount:
Sent when the user clicks a cell. (Deprecated. Use textView:clickedOnCell:inRect:atIndex: instead.)
- (void)textView:(NSTextView *)aTextView clickedOnCell:(id < NSTextAttachmentCell >)attachmentCell inRect:(NSRect)cellFrame
The text view sending the message.
The cell clicked by the user.
The frame of the clicked cell.
This message is only sent if textView:clickedOnCell:inRect:atIndex: is not implemented. Implement this method in order to track the mouse after a mouse click on a cell.
NSTextView.hSent when the user clicks a cell.
- (void)textView:(NSTextView *)aTextView clickedOnCell:(id < NSTextAttachmentCell >)cell inRect:(NSRect)cellFrame atIndex:(NSUInteger)charIndex
The text view sending the message.
The cell clicked by the user.
The frame of the clicked cell.
The character index of the clicked cell.
The delegate can use this message as its cue to perform an action or select the attachment cell’s character. aTextView is the first text view in a series shared by a layout manager, not necessarily the one that draws cell.
The delegate may subsequently receive a textView:doubleClickedOnCell:inRect:atIndex: message if the user continues to perform a double click.
NSTextView.hSent after the user clicks on a link. (Deprecated. Use textView:clickedOnLink:atIndex: instead.)
- (BOOL)textView:(NSTextView *)aTextView clickedOnLink:(id)link
The text view sending the message.
The link that was clicked.
This message is only sent if textView:clickedOnLink:atIndex: is not implemented.
NSTextView.hSent after the user clicks a link.
- (BOOL)textView:(NSTextView *)aTextView clickedOnLink:(id)link atIndex:(NSUInteger)charIndex
The text view sending the message.
The link that was clicked; the value of NSLinkAttributeName.
The character index where the click occurred, indexed within the text storage.
The delegate can use this method to handle the click on the link. It is invoked by clickedOnLink:atIndex:.
The charIndex parameter is a character index somewhere in the range of the link attribute. If the user actually physically clicked the link, then it should be the character that was originally clicked. In some cases a link may be opened indirectly or programmatically, in which case a character index somewhere in the range of the link attribute is supplied.
– clickedOnLink:atIndex: (NSTextView)NSTextView.hReturns the actual completions for a partial word.
- (NSArray *)textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index
The text view sending the message.
The proposed array of completions.
The range of characters to be completed.
On return, the index of the initially selected completion. The default is 0, and –1 indicates no selection.
The actual array of completions that will be presented for the partial word at the given range. Returning nil or a zero-length array suppresses completion.
NSTextView.hInvoked to allow the delegate to modify the text checking results after checking has occurred.
- (NSArray *)textView:(NSTextView *)view didCheckTextInRange:(NSRange)range types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options results:(NSArray *)results orthography:(NSOrthography *)orthography wordCount:(NSInteger)wordCount
The text view sending the message.
The range that was checked.
The type of checking that was performed. The possible constants are listed in NSTextCheckingTypes and can be combined using the C bit-wise OR operator to perform multiple checks at the same time.
A dictionary of values used during the checking process to perform. See Spell Checking Option Dictionary Keys for the supported values.
An array of NSTextCheckingResult instances.
The orthography of the text.
The number of words checked.
An array of NSTextCheckingResult instances. You can return the results array as is, or an altered array of NSTextCheckingResult objects.
Invoked by handleTextCheckingResults:forRange:types:options:orthography:wordCount:, this method allows observation of text checking, or modification of the results
NSTextView.hSent to allow the delegate to perform the command for the text view.
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
The text view sending the message. This is the first text view in a series shared by a layout manager.
The selector.
YES indicates that the delegate handled the command and the text view will not attempt to perform it; NO indicates that the delegate did not handle the command the text view will attempt to perform it.
This method is invoked by NSTextView's doCommandBySelector: method.
NSTextView.hSent when the user double-clicks a cell. (Deprecated. Use textView:doubleClickedOnCell:inRect:atIndex: instead.)
- (void)textView:(NSTextView *)aTextView doubleClickedOnCell:(id < NSTextAttachmentCell >)attachmentCell inRect:(NSRect)cellFrame
The text view sending the message.
The cell double-clicked by the user.
The frame of the double-clicked cell.
This message is only sent if textView:doubleClickedOnCell:inRect:atIndex: is not implemented. Implement this method in order to track the mouse after a mouse double-click on a cell.
NSTextView.hSent when the user double-clicks a cell.
- (void)textView:(NSTextView *)aTextView doubleClickedOnCell:(id < NSTextAttachmentCell >)cell inRect:(NSRect)cellFrame atIndex:(NSUInteger)charIndex
The text view sending the message.
The cell double-clicked by the user.
The frame of the double-clicked cell.
The character index of the double-clicked cell.
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 text view in a series shared by a layout manager, not necessarily the one that draws cell.
NSTextView.hSent when the user attempts to drag a cell. (Deprecated. Use textView:draggedCell:inRect:event:atIndex: instead.)
- (void)textView:(NSTextView *)aTextView draggedCell:(id < NSTextAttachmentCell >)cell inRect:(NSRect)aRect event:(NSEvent *)theEvent
The text view sending the message.
The cell being dragged.
The rectangle from which the cell was dragged.
The mouse-down event that preceded the mouse-dragged event.
This method has been deprecated in favor of textView:draggedCell:inRect:event:atIndex:.
– dragImage:at:offset:event:pasteboard:source:slideBack: (NSView)– dragFile:fromRect:slideBack:event: (NSView)NSTextView.hSent when the user attempts to drag a cell.
- (void)textView:(NSTextView *)aTextView draggedCell:(id < NSTextAttachmentCell >)cell inRect:(NSRect)rect event:(NSEvent *)event atIndex:(NSUInteger)charIndex
The text view sending the message.
The cell being dragged.
The rectangle from which the cell was dragged.
The mouse-down event that preceded the mouse-dragged event.
The character position where the mouse button was clicked.
The delegate can use this message as its cue to initiate a dragging operation.
– dragImage:at:offset:event:pasteboard:source:slideBack: (NSView)– dragFile:fromRect:slideBack:event: (NSView)NSTextView.hAllows delegate to control the context menu returned by the text view.
- (NSMenu *)textView:(NSTextView *)view menu:(NSMenu *)menu forEvent:(NSEvent *)event atIndex:(NSUInteger)charIndex
The text view sending the message.
The proposed contextual menu.
The mouse-down event that initiated the contextual menu’s display.
The character position where the mouse button was clicked.
A menu to use as the contextual menu. You can return menu unaltered, or you can return a customized menu.
This method allows the delegate to control the context menu returned by menuForEvent:.
NSTextView.hSent when a text view needs to determine if text in a specified range should be changed.
- (BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString
The text view sending the message. This is the first text view in a series shared by a layout manager, not necessarily the text view displaying the selected text.
The range of characters to be replaced.
The characters that will replace the characters in affectedCharRange; nil if only text attributes are being changed.
If a delegate implements this method and not its multiple-selection replacement, textView:shouldChangeTextInRanges:replacementStrings:, it is called with an appropriate range and string. If a delegate implements the new method, then this one is ignored.
NSTextView.hSent when a text view needs to determine if text in an array of specified ranges should be changed.
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRanges:(NSArray *)affectedRanges replacementStrings:(NSArray *)replacementStrings
The text view sending the message. This is the first text view in a series shared by a layout manager, not necessarily the text view displaying the selected text.
The array of ranges of characters to be replaced. This array must be a non-nil, non-empty array of objects responding to the NSValue rangeValue method, and in addition its elements must be sorted, non-overlapping, non-contiguous, and (except for the case of a single range) have non-zero-length.
The array of strings that will replace the characters in affectedRanges, one string for each range; nil if only text attributes are being changed.
NSTextView.hSent when the typing attributes are changed.
- (NSDictionary *)textView:(NSTextView *)textView shouldChangeTypingAttributes:(NSDictionary *)oldTypingAttributes toAttributes:(NSDictionary *)newTypingAttributes
The text view sending the message.
The old typing attributes.
The proposed typing attributes.
The actual new typing attributes.
NSTextView.hSent when the spelling state is changed.
- (NSInteger)textView:(NSTextView *)textView shouldSetSpellingState:(NSInteger)value range:(NSRange)affectedCharRange
The text view sending the message.
The proposed spelling state value to set. Possible values, for the temporary attribute on the layout manager using the key NSSpellingStateAttributeName, are:
NSSpellingStateSpellingFlag to highlight spelling issues.
NSSpellingStateGrammarFlag to highlight grammar issues.
The character range over which to set the given spelling state.
The actual spelling state to set.
Delegate only. Allows delegate to control the setting of spelling and grammar indicators.
– setSpellingState:range: (NSTextView)NSTextView.hReturns the actual range to select.
- (NSRange)textView:(NSTextView *)aTextView willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange
The text view sending the message. This is the first text view in a series shared by a layout manager, not necessarily the text view displaying the selected text.
The original range of the selection.
The proposed character range for the new selection.
The actual character range for the new selection.
This method is invoked before a text view finishes changing the selection—that is, when the last argument to a setSelectedRange:affinity:stillSelecting: message is NO.
In Mac OS X version 10.4 and later, if a delegate implements this delegate method and not its multiple-selection replacement, textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:, then multiple selection is effectively disallowed; attempts to set the selected ranges call the old delegate method with the first subrange, and afterwards only a single selected range is set.
NSTextView.hReturns the actual character ranges to select.
- (NSArray *)textView:(NSTextView *)aTextView willChangeSelectionFromCharacterRanges:(NSArray *)oldSelectedCharRanges toCharacterRanges:(NSArray *)newSelectedCharRanges
The text view sending the message. This is the first text view in a series shared by a layout manager, not necessarily the text view displaying the selected text.
An array containing the original ranges of the selection. This must be a non-nil, non-empty array of objects responding to the NSValue rangeValue method, and in addition its elements must be sorted, non-overlapping, non-contiguous, and (except for the case of a single range) have non-zero-length.
An array containing the proposed character ranges for the new selection. This must be a non-nil, non-empty array of objects responding to the NSValue rangeValue method, and in addition its elements must be sorted, non-overlapping, non-contiguous, and (except for the case of a single range) have non-zero-length.
An array containing the actual character ranges for the new selection.
Invoked before an NSTextView finishes changing the selection—that is, when the last argument to a setSelectedRange:affinity:stillSelecting: or setSelectedRanges:affinity:stillSelecting: message is NO.
If a delegate implements both this method and textView:willChangeSelectionFromCharacterRange:toCharacterRange:, then the latter is ignored.
NSTextView.hInvoked to allow the delegate to modify the text checking process before it occurs.
- (NSDictionary *)textView:(NSTextView *)view willCheckTextInRange:(NSRange)range options:(NSDictionary *)options types:(NSTextCheckingTypes *)checkingTypes
The text view sending the message.
The range to be checked.
A dictionary of values used during the checking process to perform. See Spell Checking Option Dictionary Keys for the supported values.
The type of checking to be performed, passed by-reference. The possible constants are listed in NSTextCheckingTypes and can be combined using the C bit-wise OR operator to perform multiple checks at the same time.
You can change this parameter to alter the types of checking to be performed.
A dictionary containing an alternative to the options dictionary.
Invoked by checkTextInRange:types:options:, this method allows control over text checking optionss (via the return value) or types (by modifying the flags pointed to by the inout parameter checkingTypes)
NSTextView.hReturns the actual tooltip to display.
- (NSString *)textView:(NSTextView *)textView willDisplayToolTip:(NSString *)tooltip forCharacterAtIndex:(NSUInteger)characterIndex
The text view sending the message.
The proposed tooltip to display.
The location in textView.
The actual tooltip to display, or nil to suppress display of the tooltip.
The tooltip string is the value of the NSToolTipAttributeName attribute at characterIndex.
NSTextView.hReturns the writable pasteboard types for a given cell.
- (NSArray *)textView:(NSTextView *)aTextView writablePasteboardTypesForCell:(id < NSTextAttachmentCell >)cell atIndex:(NSUInteger)charIndex
The text view sending the message.
The cell in question.
The character index in the text view that was clicked.
An array of types that can be written to the pasteboard for cell.
This method is invoked after the user clicks cell at the specified charIndex location in aTextView. If the textView:draggedCell:inRect:event:atIndex: is not used, this method and textView:writeCell:atIndex:toPasteboard:type: allow aTextView to take care of attachment dragging and pasting, with the delegate responsible only for writing the attachment to the pasteboard.
NSTextView.hReturns whether data of the specified type for the given cell could be written to the specified pasteboard.
- (BOOL)textView:(NSTextView *)aTextView writeCell:(id < NSTextAttachmentCell >)cell atIndex:(NSUInteger)charIndex toPasteboard:(NSPasteboard *)pboard type:(NSString *)type
The text view sending the message.
The cell whose contents should be written to the pasteboard.
The index at which the cell was accessed.
The pasteboard to which the cell's contents should be written.
The type of data that should be written.
YES if the write succeeded, NO otherwise.
The receiver should attempt to write the cell to pboard with the given type, and return success or failure.
NSTextView.hSent when the selection changes in the text view.
- (void)textViewDidChangeSelection:(NSNotification *)aNotification
A notification named NSTextViewDidChangeSelectionNotification.
NSTextView.hSent when a text view’s typing attributes change.
- (void)textViewDidChangeTypingAttributes:(NSNotification *)aNotification
A notification named NSTextViewDidChangeTypingAttributesNotification.
NSTextView.hReturns the undo manager for the specified text view.
- (NSUndoManager *)undoManagerForTextView:(NSTextView *)aTextView
The text view whose undo manager should be returned.
The undo manager for aTextView.
This method provides the flexibility to return a custom undo manager for the text view. Although NSTextView implements undo and redo for changes to text, applications may need a custom undo manager to handle interactions between changes to text and changes to other items in the application.
NSTextView.hLast updated: 2009-08-26