home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / nsClipboard.js < prev    next >
Encoding:
JavaScript  |  2001-02-05  |  2.7 KB  |  83 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Original Author:
  21.  *   Ben Matthew Goodger <ben@netscape.com>
  22.  *
  23.  * Contributor(s): 
  24.  */
  25.  
  26. /** 
  27.  * nsClipboard - wrapper around nsIClipboard and nsITransferable
  28.  *               that simplifies access to the clipboard. 
  29.  **/ 
  30. var nsClipboard = {
  31.   _CB: null,
  32.   get mClipboard()
  33.     {
  34.       if (!this._CB) 
  35.         {
  36.           const kCBContractID = "@mozilla.org/widget/clipboard;1";
  37.           const kCBIID = Components.interfaces.nsIClipboard;
  38.           this._CB = Components.classes[kCBContractID].getService(kCBIID);
  39.         }
  40.       return this._CB;
  41.     },
  42.     
  43.   currentClipboard: null,
  44.   /** 
  45.    * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ;
  46.    *
  47.    * returns the data in the clipboard
  48.    * 
  49.    * @param FlavourSet aFlavourSet
  50.    *        formatted list of desired flavours
  51.    * @param long aClipboard
  52.    *        the clipboard to read data from (kSelectionClipboard/kGlobalClipboard)
  53.    * @param Bool aAnyFlag
  54.    *        should be false.
  55.    **/
  56.   read: function (aFlavourList, aClipboard, aAnyFlag)
  57.     {
  58.       this.currentClipboard = aClipboard;
  59.       var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag);
  60.       return data.first.first;  // only support one item
  61.     },
  62.     
  63.   /**
  64.    * nsISupportsArray getClipboardTransferable (Object aFlavourList) ;
  65.    * 
  66.    * returns a nsISupportsArray of the item on the clipboard
  67.    *
  68.    * @param Object aFlavourList
  69.    *        formatted list of desired flavours.
  70.    **/
  71.   getClipboardTransferable: function (aFlavourList)
  72.     {
  73.       var supportsArray = nsJSSupportsUtils.createSupportsArray();
  74.       var trans = nsTransferable.createTransferable();
  75.       for (var flavour in aFlavourList) 
  76.         trans.addDataFlavor(flavour);
  77.       nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard)
  78.       supportsArray.AppendElement(trans);
  79.       return supportsArray;
  80.     }
  81. };
  82.  
  83.