Clipboard
The Clipboard object provides a container for transferring data and objects through the clipboard. The operating system clipboard can be accessed through the static generalClipboard property.
Clipboard can be created from new method or generalClipboard property.
Lib.Media.Clipboard.new() |
creates non operating system clipboard |
|
Lib.Media.Clipboard.generalClipboard |
the operating system clipboard. |
read-only |
Created Clipboard object has properties:
formats |
An array of strings containing the names of the data formats available in this Clipboard object. Only few supported: HTML_FORMAT, RICH_TEXT_FORMAT, TEXT_FORMAT |
read-only |
and methods:
clear() |
Deletes all data representations from this Clipboard object. |
|
clearData(format) |
Deletes the data representation for the specified ClipboardFormats format. |
format - ClipboardFormats object |
getData(format, transferMode) |
Gets the clipboard data if data in the specified format is present. |
format - ClipboardFormats object transferMode (recommended default = "originalPreferred") - Specifies whether to return a reference or serialized copy when an application-defined data format is accessed. The value must be one of the names defined in the ClipboardTransferMode class. This value is ignored for the standard data formats; a copy is always returned. (not supported) |
hasFormat(format) |
Checks whether data in the specified format exists in this Clipboard object. |
format - ClipboardFormats object |
setData(format. data, serializable) |
Adds a representation of the information to be transferred in the specified data format. |
format - ClipboardFormats object data - The information to add. serializable (recommended default = true) - Specify true for objects that can be serialized (and deserialized). |
setDataHandler(format, handler, serializable) |
Adds a reference to a handler function that produces the data to be transfered. Not supported. |
format - ClipboardFormats object handler - Function, The format of the data. serializable (recommended default = true) - Specify true for objects that can be serialized (and deserialized). |
Examples:
Display = Lib.Media.Display
Events = Lib.Media.Events
Text = Lib.Media.Text
Capabilities = Lib.Media.Capabilities
stage = Display.stage
stage.scaleX = Capabilities.screenDPI > 120 and Capabilities.screenDPI / 120 or 1
stage.scaleY = stage.scaleX
local input = Text.TextField.new()
input.x = 10
input.y = 10
input.type = Text.TextFieldType.INPUT
input.wordWrap = true
input.multiline = true
input.width = 240
input.height = 100
input.text = "Text for clipboard"
input.border = true
input.borderColor = 0x000000
input.background = true
input.backgroundColor = 0xffffff
stage.addChild(input)
local clickTxt = Text.TextField.new()
clickTxt.autoSize = Text.TextFieldAutoSize.LEFT
clickTxt.x = 10
clickTxt.y = 120
clickTxt.width = 240
clickTxt.height = 100
clickTxt.text = "Click to copy"
clickTxt.border = true
clickTxt.borderColor = 0x0000FF
clickTxt.background = true
clickTxt.backgroundColor = 0xf0f0ff
clickTxt.selectable = false
stage.addChild(clickTxt)
local clipboard = Lib.Media.Clipboard.generalClipboard
clickTxt.addEventListener(Events.MouseEvent.CLICK,
function (e)
clipboard.setData(Lib.Media.ClipboardFormats.TEXT_FORMAT, input.text, true)
end, false, 0, false)
local paste = Text.TextField.new()
paste.x = 10
paste.y = 150
paste.wordWrap = true
paste.multiline = true
paste.width = 240
paste.height = 100
paste.border = true
paste.borderColor = 0x000000
paste.background = true
paste.backgroundColor = 0xffffff
stage.addChild(paste)
local clickTxt2 = Text.TextField.new()
clickTxt2.autoSize = Text.TextFieldAutoSize.LEFT
clickTxt2.x = 10
clickTxt2.y = 260
clickTxt2.width = 240
clickTxt2.height = 100
clickTxt2.text = "Click to paste"
clickTxt2.border = true
clickTxt2.borderColor = 0x0000FF
clickTxt2.background = true
clickTxt2.backgroundColor = 0xf0f0ff
clickTxt2.selectable = false
stage.addChild(clickTxt2)
clickTxt2.addEventListener(Events.MouseEvent.CLICK,
function (e)
if clipboard.hasFormat(Lib.Media.ClipboardFormats.TEXT_FORMAT) then
paste.text = clipboard.getData(Lib.Media.ClipboardFormats.TEXT_FORMAT, nil)
end
end, false, 0, false)
Created with the Personal Edition of HelpNDoc: Create help files for the Qt Help Framework