<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextAttachmentCellProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextAttachmentCell"
  },
  "title" : "NSTextAttachmentCellProtocol"
}
-->

# NSTextAttachmentCellProtocol

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

```
protocol NSTextAttachmentCellProtocol : NSObjectProtocol
```

## Overview

With the exceptions of [`cellBaselineOffset()`](/documentation/AppKit/NSTextAttachmentCellProtocol/cellBaselineOffset()), [`attachment`](/documentation/AppKit/NSTextAttachmentCellProtocol/attachment), and [`attachment`](/documentation/AppKit/NSTextAttachmentCellProtocol/attachment), all of these methods are implemented by the [`NSCell`](/documentation/AppKit/NSCell) class.For general information on text attachments, see <doc://com.apple.documentation/documentation/Foundation/NSAttributedString> and [`NSTextView`](/documentation/AppKit/NSTextView).

## Topics

### Setting the attachment

[`attachment`](/documentation/AppKit/NSTextAttachmentCellProtocol/attachment)

Returns the text attachment object that owns the cell.

[`attachment`](/documentation/AppKit/NSTextAttachmentCellProtocol/attachment)

Returns the text attachment object that owns the cell.

### Drawing the cell contents

[`-  drawWithFrame:inView:`](/documentation/AppKit/NSTextAttachmentCellProtocol/draw(withFrame:in:))

Draws the cell’s image in the specified rectangle of the currently focused view.

[`-  drawWithFrame:inView:characterIndex:`](/documentation/AppKit/NSTextAttachmentCellProtocol/draw(withFrame:in:characterIndex:))

Draws the cell’s image at the specified index point in the view.

[`-  drawWithFrame:inView:characterIndex:layoutManager:`](/documentation/AppKit/NSTextAttachmentCellProtocol/draw(withFrame:in:characterIndex:layoutManager:))

Draws the cell’s image using the specified layout manager.

[`-  highlight:withFrame:inView:`](/documentation/AppKit/NSTextAttachmentCellProtocol/highlight(_:withFrame:in:))

Draws the receiver’s image with optional highlighting.

### Providing the cell metrics

[`-  cellSize`](/documentation/AppKit/NSTextAttachmentCellProtocol/cellSize())

Returns the size of the attachment’s icon.

[`-  cellBaselineOffset`](/documentation/AppKit/NSTextAttachmentCellProtocol/cellBaselineOffset())

Returns the text position where you draw the attachment cell’s image, relative to the current point established in the glyph layout.

[`-  cellFrameForTextContainer:proposedLineFragment:glyphPosition:characterIndex:`](/documentation/AppKit/NSTextAttachmentCellProtocol/cellFrame(for:proposedLineFragment:glyphPosition:characterIndex:))

Returns the frame of the cell to draw at the specified position in a text container.

### Responding to mouse events

[`-  wantsToTrackMouse`](/documentation/AppKit/NSTextAttachmentCellProtocol/wantsToTrackMouse())

Returns a Boolean value that indicates whether the attachment handles mouse events occurring over its image.

[`-  wantsToTrackMouseForEvent:inRect:ofView:atCharacterIndex:`](/documentation/AppKit/NSTextAttachmentCellProtocol/wantsToTrackMouse(for:in:of:atCharacterIndex:))

Allows an attachment to specify the events for which it tracks the mouse.

[`-  trackMouse:inRect:ofView:untilMouseUp:`](/documentation/AppKit/NSTextAttachmentCellProtocol/trackMouse(with:in:of:untilMouseUp:))

Handles a mouse-down event on the cell’s image, and optionally waits until a mouse-up event

[`-  trackMouse:inRect:ofView:atCharacterIndex:untilMouseUp:`](/documentation/AppKit/NSTextAttachmentCellProtocol/trackMouse(with:in:of:atCharacterIndex:untilMouseUp:))

Handles a mouse-down event on the image at the specified character position.

## Relationships

### Conforming Types

[`NSTextAttachmentCell-swift.class`](/documentation/AppKit/NSTextAttachmentCell-swift.class)

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)