home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / nsClipboard.js < prev    next >
Text File  |  2001-02-14  |  3KB  |  77 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.   get mClipboard()
  32.     {
  33.       return nsJSComponentManager.getService("@mozilla.org/widget/clipboard;1",
  34.                                              "nsIClipboard");
  35.     },
  36.     
  37.   mCurrentClipboard: null,
  38.   /** 
  39.    * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ;
  40.    *
  41.    * returns the data in the clipboard
  42.    * 
  43.    * @param Object aFlavourList
  44.    *        formatted list of desired flavours
  45.    * @param long aClipboard
  46.    *        the clipboard to read data from (kSelectionClipboard/kGlobalClipboard)
  47.    * @param Bool aAnyFlag
  48.    *        should be false.
  49.    **/
  50.   read: function (aFlavourList, aClipboard, aAnyFlag)
  51.     {
  52.       this.mCurrentClipboard = aClipboard;
  53.       var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag);
  54.       return data;
  55.     },
  56.     
  57.   /**
  58.    * nsISupportsArray getClipboardTransferable (Object aFlavourList) ;
  59.    * 
  60.    * returns a nsISupportsArray of the item on the clipboard
  61.    *
  62.    * @param Object aFlavourList
  63.    *        formatted list of desired flavours.
  64.    **/
  65.   getClipboardTransferable: function (aFlavourList)
  66.     {
  67.       var supportsArray = nsJSSupportsUtils.createSupportsArray();
  68.       var trans = nsTransferable.createTransferable();
  69.       for (var flavour in aFlavourList) 
  70.         trans.addDataFlavor(flavour);
  71.       nsClipboard.mClipboard.getData(trans, nsClipboard.mCurrentClipboard)
  72.       supportsArray.AppendElement(trans);
  73.       return supportsArray;
  74.     }
  75. };
  76.  
  77.