-- xtra clipboard -- version 0.9 -- (c) 2015 Valentin Schmidt Clipboard Xtra is a cross-platform scripting xtra for director that allows to access the system's clipboard. It provides more opportunities than director's own copyToClipBoard/pasteClipBoardInto commands. Here some examples of what it can be used for (see demo.dir): - check the formats available in clipboard - paste formatted text from other applications (word, browser, ...) to projectors. - copy formatted text from projectors to other applications (Word, browser, ...) - copy shapes from Illustrator, Freehand, Fireworks, Photoshop or After Effects and paste them to Director as Vector Shape-members - export Vector Shapes from Director as Flash movies (SWF files): - save binary data copied from other applications as files (eg. WAV, BMP, PNG, EPS, ...) - export director text content as Unicode or OEM text-files (this can be done by taking advantage of the fact that for all ANSI text copied to the clipboard windows automatically adds a OEM and a Unicode-representation.) - exchange data with Excel: - receive data copied from Excel as CSV or XML, - copy data from a projector that can directly be pasted to an Excel-sheet *************************************************************** METHODS *************************************************************** new object me clipGetData object me, any clipSetData object me, any, any, * clipGetFormats object me clipGetFormatName object me, integer clipEmptyClipboard object me, clipAddData object me, any, any -- CLIPBOARD NOTIFICATION (WIN ONLY) clipSetCallback object me, symbol cbHandler, *cbTarget clipStopCallback object me *************************************************************** METHOD OVERVIEW *************************************************************** --------------------------------------------------------------- xtraInstance.clipGetFormats () -> list --------------------------------------------------------------- Description: ============ Returns a list of formats currently available in clipboard. The formats are specified as format- numbers which can directly be used for the clipGetData() method. Use clipGetFormatName() to find the name for a certain format-number. Example usage: ============== formatList = clipGetFormats() --------------------------------------------------------------- xtraInstance.clipGetFormatName (integer formatNumber) -> string --------------------------------------------------------------- Description: ============ Returns the name of a clipboard-format with given format-number. For predefined Clipboard Formats (defined in WinUser.h, see list at bottom) the name of the corresponding constant is returned (eg. "CF_TEXT"), for custom formats the format-string (eg. "Rich Text Format"). Example usage: ============== Use the following code to find the names for all formats currently available in the clipboard: formatList = clipGetFormats() repeat with formatNumber in formatList put clipGetFormatName(formatNumber) end repeat --------------------------------------------------------------- xtraInstance.clipGetData (integer|string format) -> string|bytearray --------------------------------------------------------------- Description: ============ Returns content with specified format from clipboard, where format can be either an integer or a string. If the format is not available, VOID is returned, else a string. Depending on the format the returned string might be "binary", i.e. it might contain numtochar(0). Director is able to handle such binary strings, but some lingo commands will not work. Example usage: ============== str = clipGetData(1) -- get text from clipboard as ANSI text str = clipGetData("CF_TEXT") -- get text from clipboard as ANSI text, same as clipGetData(1) str = clipGetData(7) -- get text from clipboard as OEM text str = clipGetData(13) -- get text from clipboard as Unicode text str = clipGetData(12) -- get WAV data from clipboard member(1).rtf = clipGetData("Rich Text Format") -- get formatted text from clipboard str = clipGetData("HTML Format") -- get HTML from clipboard (copied from MS application) str = clipGetData("ADOBE AI3") -- get EPS-data (Illustrator-format) from clipboard. --------------------------------------------------------------- xtraInstance.clipSetData (integer|string format, string|bytearray data[, ...]) --------------------------------------------------------------- Description: ============ Copies data to clipboard as specified format, where format can be either an integer or a string. If format is a string, it can be either the name of a predefined constant (like "CF_TEXT", see list below), or a pre-existing format used by other applications, like "Rich Text Format" as used by Word, Internet Explorer etc., or a projector might also create it's own format by choosing an arbitrary format-name. It's the lingo programmer's responsibility that the format and the data fit together. The data is specified as bytearray in Director 11.5 or newer, and as string in D10 or older (strings can be "binary", i.e. it can contain numtochar(0)). You can add multiple formats (arbitrary number) to the clipboard at once by passing additional parameters, alternately a format and the corresponding data value. Example usage: ============== clipSetData(1, member(1).text) -- copy to clipboard as ANSI text clipSetData("CF_TEXT", member(1).text) -- copy to clipboard as ANSI text, same as clipSetData(1) clipSetData("Rich Text Format", member(1).rtf) -- copy formatted text to clipboard clipSetData("foo", str) -- copy data to clipboard with custom format -- copy formatted text both as RTF and HTML to clipboard clipSetData("Rich Text Format", member(2).rtf, "HTML Format", member(2).html) --------------------------------------------------------------- xtraInstance.clipAddData (integer|string format, string|bytearray data) --------------------------------------------------------------- Description: ============ Adds data to clipboard as specified format, where format can be either an integer or a string. If format is a string, it can be either the name of a predefined constant (like "CF_TEXT", see list below), or a pre-existing format used by other applications, like "Rich Text Format" as used by Word, Internet Explorer etc., or a projector might also create it's own format by choosing an arbitrary format-name. It's the lingo programmer's responsibility that the format and the data fit together. The data is specified as bytearray in Director 11.5 or newer, and as string in D10 or older (strings can be "binary", i.e. it can contain numtochar(0)). Example usage: ============== clipEmptyClipboard() -- not mandatory clipAddData(1, member(2).text) clipAddData("Rich Text Format", member(2).rtf) --------------------------------------------------------------- xtraInstance.clipEmptyClipboard() --------------------------------------------------------------- Description: ============ Empties clipboard. --------------------------------------------------------------- xtraInstance.clipSetCallback (symbol callbackHandler, *object callbackTarget) -> bool success -- WIN ONLY --------------------------------------------------------------- Description: ============ Registers a handler as callback for clipboard-changed notifications (and starts notification). If no object is specified as callbackTraget, the handler is expected in a movie sccript. --------------------------------------------------------------- xtraInstance.clipStopCallback () -- WIN ONLY --------------------------------------------------------------- Description: ============ Stops the clipboard-changed notifications. *************************************************************** Predefined Clipboard Formats in Windows (defined in WinUser.h) *************************************************************** 1 CF_TEXT 2 CF_BITMAP 3 CF_METAFILEPICT 4 CF_SYLK 5 CF_DIF 6 CF_TIFF 7 CF_OEMTEXT 8 CF_DIB 9 CF_PALETTE 10 CF_PENDATA 11 CF_RIFF 12 CF_WAVE 13 CF_UNICODETEXT 14 CF_ENHMETAFILE 15 CF_HDROP 16 CF_LOCALE 17 CF_DIBV5 18 CF_MAX