Vixen
02b45cc4
csharp
public sealed class WindowsClipboard

The Windows clipboard: images and application-defined formats.

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

Remarks

Text is left to , which on the desktop platform is SDL's and is correct. What SDL has no answer for is everything that is not text, and on Windows that is one API — OpenClipboard and a numbered format — rather than the three unrelated ones the three desktops need between them.

Setting anything replaces everything. Windows gives the clipboard to one owner at a time, and the owner declares every format it offers before it lets go, so SetImage and SetData each begin by emptying it. That is the platform's model rather than a simplification: an application that pastes from an application that has quit is reading what the system kept from the last owner, and there is no version of this in which two owners contribute to one clipboard.

OpenClipboard is retried. It fails while another process holds the clipboard open, which is a normal thing to happen for the microsecond somebody else's paste handler takes and not an error worth reporting to a user. Ten attempts a millisecond apart is longer than any well-behaved application holds it and short enough to be invisible in a frame.

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 WindowsClipboard(IClipboard fallback)

    The Windows clipboard: images and application-defined formats.

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

    Reads the clipboard's image.

  • public bool SetImage(in ClipboardImage image)

    Puts an image on the clipboard.

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

    Reads an application-defined 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 (1)

  • WindowsPlatformSupplementVixen.Platform.Windows