Class WindowsClipboard
- All Implemented Interfaces:
NativeClipboard
Everything this process offers is rendered on demand: the formats are announced with no
data, and WM_RENDERFORMAT asks for one when a program pastes. The window's messages
arrive on the UI thread, inside GLFW's poll, so no thread of ours is involved in offering. A
read is the other way round: any thread may open the clipboard, and the copy out of it is made
on a short-lived one, so that a large picture is decoded off the UI thread.
What this process still owns when it closes is rendered then, as every Windows program does, so that what the user copied outlives the application.
A picture is offered twice, as the PNG format, which keeps its transparency, and as
CF_DIB, which every program reads. It is read from PNG where there is one.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Lets go of the system's resources.booleanisOwner()The types worth making ahead of anybody asking, because this system asks on the UI thread and waits there: the picture's, where making it is slow.voidMakes this process the clipboard's owner.CompletableFuture<byte[]> Asks for the bytes of one type.voidsetChangeListener(Runnable listener) types()The types on the clipboard as the system last reported them, without asking it again.
-
Constructor Details
-
WindowsClipboard
public WindowsClipboard()UI thread.- Throws:
RuntimeException- when the window cannot be made; the caller then keeps GLFW's text clipboard
-
-
Method Details
-
isOwner
public boolean isOwner()- Specified by:
isOwnerin interfaceNativeClipboard- Returns:
- whether what the clipboard holds was put there by the last
NativeClipboard.offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>)of this process and has not been replaced since
-
types
Description copied from interface:NativeClipboardThe types on the clipboard as the system last reported them, without asking it again.- Specified by:
typesin interfaceNativeClipboard- Returns:
- canonical type names, best first; empty when the clipboard is empty or unknown
-
read
Description copied from interface:NativeClipboardAsks for the bytes of one type.- Specified by:
readin interfaceNativeClipboard- Parameters:
type- one ofNativeClipboard.types()- Returns:
- the bytes, completed on whatever thread the implementation reads on; completed exceptionally when the type is not, or no longer, there
-
offer
Description copied from interface:NativeClipboardMakes this process the clipboard's owner.- Specified by:
offerin interfaceNativeClipboard- Parameters:
types- what is offered, best first; empty empties the clipboardbytes- the bytes of one of those types, asked for when a program wants them; it may be called on any thread and may block, and answers null for what it cannot make
-
madeAhead
Description copied from interface:NativeClipboardThe types worth making ahead of anybody asking, because this system asks on the UI thread and waits there: the picture's, where making it is slow.- Specified by:
madeAheadin interfaceNativeClipboard- Parameters:
offered- the types about to be offered- Returns:
- those of
offered, and of the private types this clipboard asks for itself, that should be made in the background as soon as they are offered
-
setChangeListener
- Specified by:
setChangeListenerin interfaceNativeClipboard- Parameters:
listener- called, on any thread, after the clipboard's types or its owner change, anNativeClipboard.offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>)of this process included; replaces the one before
-
close
public void close()Description copied from interface:NativeClipboardLets go of the system's resources. The clipboard is not used afterwards.- Specified by:
closein interfaceNativeClipboard
-