Mac Developer Library

Developer

AppKit Framework Reference NSTextAttachmentCell Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSTextAttachmentCell

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

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.

  • Draws the receiver’s image within cellFrame in aView, which is the view currently focused. (required)

    Declaration

    Swift

    func drawWithFrame(_ cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – drawWithFrame:inView: (NSCell)
    – lockFocus (NSView)

  • 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)

    Declaration

    Swift

    func drawWithFrame(_ cellFrame: NSRect, inView controlView: NSView, characterIndex charIndex: Int)

    Objective-C

    - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView characterIndex:(NSUInteger)charIndex

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • 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)

    Declaration

    Swift

    func drawWithFrame(_ cellFrame: NSRect, inView controlView: NSView, characterIndex charIndex: Int, layoutManager layoutManager: NSLayoutManager)

    Objective-C

    - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView characterIndex:(NSUInteger)charIndex layoutManager:(NSLayoutManager *)layoutManager

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the receiver’s image—with highlighting if flag is YEStrue—within cellFrame in aView, which should be the focus view. (required)

    Declaration

    Swift

    func highlight(_ flag: Bool, withFrame cellFrame: NSRect, inView controlView: NSView)

    Objective-C

    - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the attachment’s icon. (required)

    Declaration

    Swift

    func cellSize() -> NSSize

    Objective-C

    - (NSSize)cellSize

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – icon (NSFileWrapper)
    – fileWrapper (NSTextAttachment)

  • 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)

    Declaration

    Swift

    func cellBaselineOffset() -> NSPoint

    Objective-C

    - (NSPoint)cellBaselineOffset

    Discussion

    The image should be drawn so its lower-left corner lies on this point.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – icon (NSFileWrapper)

  • 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)

    Declaration

    Swift

    func cellFrameForTextContainer(_ textContainer: NSTextContainer, proposedLineFragment lineFrag: NSRect, glyphPosition position: NSPoint, characterIndex charIndex: Int) -> NSRect

    Objective-C

    - (NSRect)cellFrameForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(NSRect)lineFrag glyphPosition:(NSPoint)position characterIndex:(NSUInteger)charIndex

    Discussion

    The proposed line fragment is specified by lineFrag.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns YEStrue if the receiver will handle a mouse event occurring over its image (to support dragging, for example), NOfalse otherwise. (required)

    Declaration

    Swift

    func wantsToTrackMouse() -> Bool

    Objective-C

    - (BOOL)wantsToTrackMouse

    Discussion

    NSTextAttachmentCell’s implementation of this method returns YEStrue. 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 NOfalse 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Allows an attachment to specify what events it would want to track the mouse for. (required)

    Declaration

    Swift

    func wantsToTrackMouseForEvent(_ theEvent: NSEvent, inRect cellFrame: NSRect, ofView controlView: NSView, atCharacterIndex charIndex: Int) -> Bool

    Objective-C

    - (BOOL)wantsToTrackMouseForEvent:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView atCharacterIndex:(NSUInteger)charIndex

    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 YEStrue, this method allows the attachment to decide whether it wishes to do so for particular events.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Handles a mouse-down event on the receiver’s image. (required)

    Declaration

    Swift

    func trackMouse(_ theEvent: NSEvent, inRect cellFrame: NSRect, ofView controlView: NSView, untilMouseUp flag: Bool) -> Bool

    Objective-C

    - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag

    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 YEStrue, the receiver tracks the mouse until a mouse-up event occurs; if flag is NOfalse, it stops tracking when a mouse-dragged event occurs outside of cellFrame. Returns YEStrue if the receiver successfully finished tracking the mouse (typically through a mouse-up event), NOfalse 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 YEStrue. 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 YEStrue. NSTextAttachmentCell’s implementation returns NOfalse only if flag is NOfalse and the cursor is dragged outside of cellFrame. The delegate methods are invoked only if the delegate responds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Handles a mouse-down event on the receiver’s image. (required)

    Declaration

    Swift

    func trackMouse(_ theEvent: NSEvent, inRect cellFrame: NSRect, ofView controlView: NSView, atCharacterIndex charIndex: Int, untilMouseUp flag: Bool) -> Bool

    Objective-C

    - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView atCharacterIndex:(NSUInteger)charIndex untilMouseUp:(BOOL)flag

    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 YEStrue, the receiver tracks the mouse until a mouse-up event occurs; if flag is NOfalse, it stops tracking when a mouse-dragged event occurs outside of cellFrame. Returns YEStrue if the receiver successfully finished tracking the mouse (typically through a mouse-up event), NOfalse 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 YEStrue. 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 YEStrue. NSTextAttachmentCell’s implementation returns NOfalse only if flag is NOfalse and the mouse is dragged outside of cellFrame. The delegate methods are invoked only if the delegate responds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the text attachment object that owns the receiver to anAttachment, without retaining it (the text attachment, as the owner, retains the cell). (required)

    Declaration

    Swift

    func setAttachment(_ anObject: NSTextAttachment?)

    Objective-C

    - (void)setAttachment:(NSTextAttachment *)anObject

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – attachment
    – setAttachmentCell: (NSTextAttachment)

  • Returns the text attachment object that owns the receiver. (required)

    Declaration

    Swift

    func attachment() -> NSTextAttachment?

    Objective-C

    - (NSTextAttachment *)attachment

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.