michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * nsClipboard - wrapper around nsIClipboard and nsITransferable michael@0: * that simplifies access to the clipboard. michael@0: **/ michael@0: var nsClipboard = { michael@0: _CB: null, michael@0: get mClipboard() michael@0: { michael@0: if (!this._CB) michael@0: { michael@0: const kCBContractID = "@mozilla.org/widget/clipboard;1"; michael@0: const kCBIID = Components.interfaces.nsIClipboard; michael@0: this._CB = Components.classes[kCBContractID].getService(kCBIID); michael@0: } michael@0: return this._CB; michael@0: }, michael@0: michael@0: currentClipboard: null, michael@0: /** michael@0: * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ; michael@0: * michael@0: * returns the data in the clipboard michael@0: * michael@0: * @param FlavourSet aFlavourSet michael@0: * formatted list of desired flavours michael@0: * @param long aClipboard michael@0: * the clipboard to read data from (kSelectionClipboard/kGlobalClipboard) michael@0: * @param Bool aAnyFlag michael@0: * should be false. michael@0: **/ michael@0: read: function (aFlavourList, aClipboard, aAnyFlag) michael@0: { michael@0: this.currentClipboard = aClipboard; michael@0: var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag); michael@0: return data.first.first; // only support one item michael@0: }, michael@0: michael@0: /** michael@0: * nsISupportsArray getClipboardTransferable (Object aFlavourList) ; michael@0: * michael@0: * returns a nsISupportsArray of the item on the clipboard michael@0: * michael@0: * @param Object aFlavourList michael@0: * formatted list of desired flavours. michael@0: **/ michael@0: getClipboardTransferable: function (aFlavourList) michael@0: { michael@0: const supportsContractID = "@mozilla.org/supports-array;1"; michael@0: const supportsIID = Components.interfaces.nsISupportsArray; michael@0: var supportsArray = Components.classes[supportsContractID].createInstance(supportsIID); michael@0: var trans = nsTransferable.createTransferable(); michael@0: for (var flavour in aFlavourList) michael@0: trans.addDataFlavor(flavour); michael@0: nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard) michael@0: supportsArray.AppendElement(trans); michael@0: return supportsArray; michael@0: } michael@0: }; michael@0: