Programmer Reference : Common Widgets : Clipboard operations : Examples for using the clipboard
Examples for using the clipboard
The following examples show how to copy String data to and from the clipboard.
Example 1: copying data to the clipboard
| window itemId copyText |
window := CgWindow default.
copyText := 'This text will be copied'.
itemId := ReturnParameter new.
"Set up storage and data structures."
window display
clipboardStartCopy: window
clipLabel: 'STRING'
itemIdReturn: itemId.
"Copy a data item of String format to temporary storage."
window display
clipboardCopy: window
itemId: itemId value
formatName: 'STRING'
buffer: copyText
privateId: 0.
"End the clipboard transaction."
window display
clipboardEndCopy: window
itemId: itemId value.
Example 2: retrieving data from the clipboard
| window status bufferHolder lengthHolder |
window := CgWindow default.
"Ask for the length of the string in the clipboard."
status := window display
clipboardInquireLength: window
formatName: 'STRING'
lengthReturn: (lengthHolder := ReturnParameter new).
status = ClipboardSuccess
ifTrue: [
Transcript cr; show: 'XmClipboardStatus...', status printString; cr.
^self].
"Retrieve a string from the clipboard and place it in bufferHolder."
status := window display
clipboardRetrieve: window
formatName: 'STRING'
bufferReturn: (bufferHolder := ReturnParameter new)
privateIdReturn: ReturnParameter null. "Ignore result"
status = ClipboardSuccess
ifTrue: [
Transcript cr; show: 'XmClipboardStatus...', status printString; cr.
^self].
^bufferHolder value
Last modified date: 01/29/2015