Vixen
02b45cc4
csharp
public sealed class MacOSClipboard

The macOS pasteboard: images and application-defined types.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A type here is a UTI. public.png, public.tiff, com.adobe.pdf, or an application's own reverse-DNS identifier — the same namespace the whole system uses for file types, and the one place where the abstract "platform-neutral format name" of TryGetData has a well-defined home. Names are passed through unchanged; inventing a fourth vocabulary to map onto three real ones would help nobody.

Reading an image goes through NSBitmapImageRep and then reads its bytes directly. The alternative — drawing the representation into a second one of a known layout — is what a graphics application does and needs a graphics context, a saved state and an NSRect through objc_msgSend. Reading the bytes handles what a pasteboard actually contains: eight bits a sample, interleaved, three or four samples. A 16-bit or floating-point representation is refused rather than misread, which is a paste that does nothing instead of a paste that is wrong.

Fields and properties (2)

  • public bool HasText

    Whether the clipboard currently holds text.

  • public bool HasImage

    Whether the clipboard currently holds an image.

Methods (8)

  • public MacOSClipboard(IClipboard fallback)

    The macOS pasteboard: images and application-defined types.

  • public bool TryGetText(out string? text)

    Reads the clipboard's text.

  • public bool SetText(string text)

    Puts text on the clipboard.

  • public bool TryGetImage(out ClipboardImage image)
  • public bool SetImage(in ClipboardImage image)

    Puts an image on the clipboard.

  • public bool TryGetData(string format, out ReadOnlyMemory<byte> data)

    Reads a custom format's bytes.

  • public bool SetData(string format, ReadOnlySpan<byte> data)

    Puts a custom format's bytes on the clipboard.

  • public void Clear()

    Empties the clipboard, if the platform allows it.

Used by (2)

  • MacOSPlatformSupplementVixen.Platform.MacOS
  • MacOSSupplementTestsVixen.Platform.MacOS.Tests