NSTextAttachmentCell Protocol Reference
| Adopted by | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.0 and later. |
| Declared in | NSTextAttachment.h |
| Companion guides |
Overview
The NSTextAttachmentCell protocol declares the interface for objects that draw text attachment icons and handle mouse events on their icons. With the exceptions of cellBaselineOffset, setAttachment:, and attachment, all of these methods are implemented by the NSCell class and described in that class specification.
See the NSAttributedString and NSTextView class specifications for general information on text attachments.
Tasks
Drawing
-
– drawWithFrame:inView:required method -
– drawWithFrame:inView:characterIndex:required method -
– drawWithFrame:inView:characterIndex:layoutManager:required method -
– highlight:withFrame:inView:required method
Cell Size and Position
-
– cellSizerequired method -
– cellBaselineOffsetrequired method -
– cellFrameForTextContainer:proposedLineFragment:glyphPosition:characterIndex:required method
Event Handling
-
– wantsToTrackMouserequired method -
– wantsToTrackMouseForEvent:inRect:ofView:atCharacterIndex:required method -
– trackMouse:inRect:ofView:untilMouseUp:required method -
– trackMouse:inRect:ofView:atCharacterIndex:untilMouseUp:required method
Setting the Attachment
-
– setAttachment:required method -
– attachmentrequired method
Instance Methods
attachment
Returns the text attachment object that owns the receiver. (required)
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextAttachment.hcellBaselineOffset
Returns the position where the attachment cell’s image should be drawn in text, relative to the current point established in the glyph layout. (required)
Discussion
The image should be drawn so its lower-left corner lies on this point.
Availability
- Available in OS X v10.0 and later.
See Also
-
– icon(NSFileWrapper)
Declared In
NSTextAttachment.hcellFrameForTextContainer:proposedLineFragment:glyphPosition:characterIndex:
Returns the frame of the cell as it would be drawn as the character at the given glyph position, and character index, charIndex, in textContainer. (required)
Discussion
The proposed line fragment is specified by lineFrag.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.hcellSize
Returns the size of the attachment’s icon. (required)
Availability
- Available in OS X v10.0 and later.
See Also
-
– icon(NSFileWrapper) -
– fileWrapper(NSTextAttachment)
Declared In
NSTextAttachment.hdrawWithFrame:inView:
Draws the receiver’s image within cellFrame in aView, which is the view currently focused. (required)
Availability
- Available in OS X v10.0 and later.
See Also
-
– drawWithFrame:inView:(NSCell) -
– lockFocus(NSView)
Declared In
NSTextAttachment.hdrawWithFrame:inView:characterIndex:
Draws the receiver’s image within cellFrame in aView, which is the view currently focused. charIndex is the index of the attachment character within the text. (required)
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.hdrawWithFrame:inView:characterIndex:layoutManager:
Draws the receiver’s image within cellFrame in controlView, which is the view currently focused. charIndex is the index of the attachment character within the text. layoutManager is the layout manager for the text. (required)
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.hhighlight:withFrame:inView:
Draws the receiver’s image—with highlighting if flag is YES—within cellFrame in aView, which should be the focus view. (required)
Availability
- Available in OS X v10.0 and later.
See Also
-
– highlight:withFrame:inView:(NSCell) -
– lockFocus(NSView)
Declared In
NSTextAttachment.hsetAttachment:
Sets the text attachment object that owns the receiver to anAttachment, without retaining it (the text attachment, as the owner, retains the cell). (required)
Availability
- Available in OS X v10.0 and later.
See Also
-
– attachment -
– setAttachmentCell:(NSTextAttachment)
Declared In
NSTextAttachment.htrackMouse:inRect:ofView:atCharacterIndex:untilMouseUp:
Handles a mouse-down event on the receiver’s image. (required)
Discussion
theEvent is the mouse-down event. cellFrame is the region of aTextView in which you should track further mouse events. charIndex is the position in the text at which this attachment appears. aTextView is the view that received the event. It’s assumed to be an NSTextView, and should be the focus view. If flag is YES, the receiver tracks the mouse until a mouse-up event occurs; if flag is NO, it stops tracking when a mouse-dragged event occurs outside of cellFrame. Returns YES if the receiver successfully finished tracking the mouse (typically through a mouse-up event), NO otherwise (such as when the mouse is dragged outside cellFrame).
NSTextAttachmentCell’s implementation of this method calls upon aTextView’s delegate to handle the event. If theEvent is a mouse-up event for a double click, the text attachment cell sends the delegate a textView:doubleClickedOnCell:inRect: message and returns YES. Otherwise, depending on whether the user clicks or drags the cell, it sends the delegate a textView:clickedOnCell:inRect: or a textView:draggedCell:inRect:event: message and returns YES. NSTextAttachmentCell’s implementation returns NO only if flag is NO and the mouse is dragged outside of cellFrame. The delegate methods are invoked only if the delegate responds.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.htrackMouse:inRect:ofView:untilMouseUp:
Handles a mouse-down event on the receiver’s image. (required)
Discussion
theEvent is the mouse-down event. cellFrame is the region of aTextView in which further mouse events should be tracked. aTextView is the view that received the event. It’s assumed to be an NSTextView and should be the focus view. If flag is YES, the receiver tracks the mouse until a mouse-up event occurs; if flag is NO, it stops tracking when a mouse-dragged event occurs outside of cellFrame. Returns YES if the receiver successfully finished tracking the mouse (typically through a mouse-up event), NO otherwise (such as when the cursor is dragged outside cellFrame).
NSTextAttachmentCell’s implementation of this method calls upon the delegate of aTextView to handle the event. If theEvent is a mouse-up event for a double click, the text attachment cell sends the delegate a textView:doubleClickedOnCell:inRect: message and returns YES. Otherwise, depending on whether the user clicks or drags the cell, it sends the delegate a textView:clickedOnCell:inRect: or a textView:draggedCell:inRect:event: message and returns YES. NSTextAttachmentCell’s implementation returns NO only if flag is NO and the cursor is dragged outside of cellFrame. The delegate methods are invoked only if the delegate responds.
Availability
- Available in OS X v10.0 and later.
See Also
-
– wantsToTrackMouse -
– trackMouse:inRect:ofView:untilMouseUp:(NSCell) -
– lockFocus(NSView)
Declared In
NSTextAttachment.hwantsToTrackMouse
Returns YES if the receiver will handle a mouse event occurring over its image (to support dragging, for example), NO otherwise. (required)
Discussion
NSTextAttachmentCell’s implementation of this method returns YES. The NSView containing the cell should invoke this method before sending a trackMouse:inRect:ofView:untilMouseUp: message.
For an attachment in an attributed string, if the attachment cell returns NO its attachment character should be selected rather than the cell being asked to track the mouse. This results in the attachment icon behaving as any regular glyph in text.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.hwantsToTrackMouseForEvent:inRect:ofView:atCharacterIndex:
Allows an attachment to specify what events it would want to track the mouse for. (required)
Discussion
theEvent is the event in question that occurred in cellFrame inside controlView. charIndex is the index of the attachment character within the text. If wantsToTrackMouse returns YES, this method allows the attachment to decide whether it wishes to do so for particular events.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextAttachment.h© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)