NSTextInputClient Protocol Reference
| Adopted by | |
| Framework |
/System/Library/Frameworks/AppKit.framework
|
| Availability |
Available in Mac OS X v10.5 and later.
|
| Declared in |
NSTextInputClient.h
|
Overview
The
NSTextInputClient protocol defines the methods that Cocoa text views must implement in order to interact properly with the text input management system. To create another text view class, you can either subclass NSTextView (and not NSText, for historical reasons), or subclass NSView and implement the NSTextInputClient protocolsetMarkedText:selectedRange:replacementRange:
Replaces a specified range in the receiver’s text storage with the given string and sets the selection. (required)
- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
Parameters
- aString
- The string to insert. Can be either an
NSStringorNSAttributedStringinstance. - selectedRange
- The range to set as the selection, computed from the beginning of the inserted string.
- replacementRange
- The range to replace, computed from the beginning of the marked text.
Discussion
If there is no marked text, the current selection is replaced. If there is no selection, the string is inserted at the insertion point.
When aString is an
NSString object, the receiver is expected to render the marked text with distinguishing appearance (for example,NSTextView renders with markedTextAttributes).Availability
- Available in Mac OS X v10.5 and later.
See Also
Declared In
NSTextInputClient.h
Binding Keystrokes
doCommandBySelector:
Invokes the action specified by the given selector. (required)
- (void)doCommandBySelector:(SEL)aSelector
Parameters
- aSelector
-
The selector to invoke.
Discussion
If aSelector cannot be invoked, then doCommandBySelector: should not pass this message up the responder chain. NSResponder also implements this method, and it does forward uninvokable commands up the responder chain, but a text view should not. A text view implementing the NSTextInputClient protocol inherits from NSView, which inherits from NSResponder, so your implementation of this method will override the one in NSResponder. It should not call super.
Availability
- Available in Mac OS X v10.5 and later.
See Also
interpretKeyEvents: (NSResponder)
doCommandBySelector: (NSResponder)
Declared In
NSTextInputClient.h
NSTextInput Protocol Reference
Adopted by
NSInputManager
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in Mac OS X v10.0 and later.
Declared in
NSInputManager.h
Companion guides
Overview
The NSTextInput protocol defines the methods that Cocoa text views must implement in order to interact properly with the text input management system.
NSTextView and its abstract superclass NSText are the only classes included in Cocoa that implement NSTextInput. To create another text view class, you can either subclass NSTextView (and not NSText, for historical reasons), or subclass NSView and implement theNSTextInput protocol.
insertText:
Inserts the given string into the receiver’s text storage. (required)
- (void)insertText:(id)aString
Parameters
- aString
-
Either an
NSString or an NSAttributedString object.
Discussion
This method is the entry point for inserting text typed by the user and is generally not suitable for other purposes. Programmatic modification of the text is best done by operating on the text storage directly. Because this method pertains to the actions of the user, the text view must be editable for the insertion to work.
Availability
- Available in Mac OS X v10.0 and later.
Declared In
NSInputManager.h
Key Bindings
doCommandBySelector:
Invokes the given selector if possible. (required)
- (void)doCommandBySelector:(SEL)aSelector
Parameters
- aSelector
-
The selector to be invoked.
Discussion
If aSelector cannot be invoked, then doCommandBySelector: should not pass this message up the responder chain. NSResponder also implements this method, and it does forward uninvokable commands up the responder chain, but a text view should not. A text view implementing the NSTextInput protocol inherits from NSView, which inherits from NSResponder, so your implementation of this method will override the one in NSResponder. It should not call super.
Availability
- Available in Mac OS X v10.0 and later.
See Also
– interpretKeyEvents: (NSResponder)
– doCommandBySelector: (NSResponder)
Declared In
NSInputManager.h
沒有留言:
張貼留言