Protocol

NSTextAttachmentCellProtocol

A set of methods that declares the interface for objects that draw text attachment icons and handle mouse events on their icons.

Overview

With the exceptions of cellBaselineOffset(), attachment, and attachment, all of these methods are implemented by the NSCell class.For general information on text attachments, see NSAttributedString and NSTextView.

Topics

Drawing

func draw(withFrame: NSRect, in: NSView?)

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

Required.

func draw(withFrame: NSRect, in: NSView?, characterIndex: Int)

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.

func draw(withFrame: NSRect, in: NSView?, characterIndex: Int, layoutManager: NSLayoutManager)

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.

func highlight(Bool, withFrame: NSRect, in: NSView?)

Draws the receiver’s image—with highlighting if flag is true—within cellFrame in aView, which should be the focus view.

Required.

Cell size and position

func cellSize()

Returns the size of the attachment’s icon.

Required.

func cellBaselineOffset()

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.

func cellFrame(for: NSTextContainer, proposedLineFragment: NSRect, glyphPosition: NSPoint, characterIndex: Int)

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.

Event handling

func wantsToTrackMouse()

Returns true if the receiver will handle a mouse event occurring over its image (to support dragging, for example), false otherwise.

Required.

func wantsToTrackMouse(for: NSEvent, in: NSRect, of: NSView?, atCharacterIndex: Int)

Allows an attachment to specify what events it would want to track the mouse for.

Required.

func trackMouse(with: NSEvent, in: NSRect, of: NSView?, untilMouseUp: Bool)

Handles a mouse-down event on the receiver’s image.

Required.

Setting the attachment

var attachment: NSTextAttachment?

Returns the text attachment object that owns the receiver.

Required.

Relationships

Inherits From

See Also

Attachments

class NSTextAttachment

The values for the attachment attributes of attributed strings and related objects.

class NSTextAttachmentCell

An object that implements the functionality of the text attachment cell protocol.

protocol NSTextAttachmentContainer

A set of methods that defines the interface to text attachment objects from NSLayoutManager.