src/macosx/classes/sun/lwawt/macosx/CClipboard.java

Print this page




  40  * sun.awt.datatransfer.DataTransferer.
  41  */
  42 
  43 final class CClipboard extends SunClipboard {
  44 
  45     public CClipboard(String name) {
  46         super(name);
  47     }
  48 
  49     @Override
  50     public long getID() {
  51         return 0;
  52     }
  53 
  54     @Override
  55     protected void clearNativeContext() {
  56         // Leaving Empty, as WClipboard.clearNativeContext is empty as well.
  57     }
  58 
  59     @Override












  60     protected void setContentsNative(Transferable contents) {
  61         FlavorTable flavorMap = getDefaultFlavorTable();
  62         // Don't use delayed Clipboard rendering for the Transferable's data.
  63         // If we did that, we would call Transferable.getTransferData on
  64         // the Toolkit thread, which is a security hole.
  65         //
  66         // Get all of the target formats into which the Transferable can be
  67         // translated. Then, for each format, translate the data and post
  68         // it to the Clipboard.
  69         DataTransferer dataTransferer = DataTransferer.getInstance();
  70         long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
  71         declareTypes(formatArray, this);
  72 
  73         Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap);
  74         for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) {
  75             long format = entry.getKey();
  76             DataFlavor flavor = entry.getValue();
  77 
  78             try {
  79                 byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);


  99 
 100     // 1.5 peer method
 101     @Override
 102     protected void unregisterClipboardViewerChecked() {
 103         // no-op because we lack OS support. This requires 4048791, which requires 4048792
 104     }
 105 
 106     // 1.5 peer method
 107     @Override
 108     protected void registerClipboardViewerChecked()    {
 109         // no-op because we lack OS support. This requires 4048791, which requires 4048792
 110     }
 111 
 112     // 1.5 peer method
 113     // no-op. This appears to be win32 specific. Filed 4048790 for investigation
 114     //protected Transferable createLocaleTransferable(long[] formats) throws IOException;
 115 
 116     private native void declareTypes(long[] formats, SunClipboard newOwner);
 117     private native void setData(byte[] data, long format);
 118 







 119     /**
 120      * Invokes native check whether a change count on the general pasteboard is different
 121      * than when we set it. The different count value means the current owner lost
 122      * pasteboard ownership and someone else put data on the clipboard.
 123      * @since 1.7
 124      */
 125     native void checkPasteboard();
 126 
 127     /*** Native Callbacks ***/
 128     private void notifyLostOwnership() {
 129         lostOwnershipImpl();
 130     }
 131 
 132     private static void notifyChanged() {
 133         CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
 134         if (!clipboard.areFlavorListenersRegistered()) {
 135             return;
 136         }
 137         clipboard.checkChange(clipboard.getClipboardFormats());
 138     }
 139 }


  40  * sun.awt.datatransfer.DataTransferer.
  41  */
  42 
  43 final class CClipboard extends SunClipboard {
  44 
  45     public CClipboard(String name) {
  46         super(name);
  47     }
  48 
  49     @Override
  50     public long getID() {
  51         return 0;
  52     }
  53 
  54     @Override
  55     protected void clearNativeContext() {
  56         // Leaving Empty, as WClipboard.clearNativeContext is empty as well.
  57     }
  58 
  59     @Override
  60     public synchronized Transferable getContents(Object requestor) {
  61         checkPasteboardAndNotify();
  62         return super.getContents(requestor);
  63     }
  64 
  65     @Override
  66     protected synchronized Transferable getContextContents() {
  67         checkPasteboardAndNotify();
  68         return super.getContextContents();
  69     }
  70 
  71     @Override
  72     protected void setContentsNative(Transferable contents) {
  73         FlavorTable flavorMap = getDefaultFlavorTable();
  74         // Don't use delayed Clipboard rendering for the Transferable's data.
  75         // If we did that, we would call Transferable.getTransferData on
  76         // the Toolkit thread, which is a security hole.
  77         //
  78         // Get all of the target formats into which the Transferable can be
  79         // translated. Then, for each format, translate the data and post
  80         // it to the Clipboard.
  81         DataTransferer dataTransferer = DataTransferer.getInstance();
  82         long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
  83         declareTypes(formatArray, this);
  84 
  85         Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap);
  86         for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) {
  87             long format = entry.getKey();
  88             DataFlavor flavor = entry.getValue();
  89 
  90             try {
  91                 byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);


 111 
 112     // 1.5 peer method
 113     @Override
 114     protected void unregisterClipboardViewerChecked() {
 115         // no-op because we lack OS support. This requires 4048791, which requires 4048792
 116     }
 117 
 118     // 1.5 peer method
 119     @Override
 120     protected void registerClipboardViewerChecked()    {
 121         // no-op because we lack OS support. This requires 4048791, which requires 4048792
 122     }
 123 
 124     // 1.5 peer method
 125     // no-op. This appears to be win32 specific. Filed 4048790 for investigation
 126     //protected Transferable createLocaleTransferable(long[] formats) throws IOException;
 127 
 128     private native void declareTypes(long[] formats, SunClipboard newOwner);
 129     private native void setData(byte[] data, long format);
 130 
 131     void checkPasteboardAndNotify() {
 132         if (checkPasteboardWithoutNotification()) {
 133             notifyChanged();
 134             lostOwnershipNow(null);
 135         }
 136     }
 137 
 138     /**
 139      * Invokes native check whether a change count on the general pasteboard is different
 140      * than when we set it. The different count value means the current owner lost
 141      * pasteboard ownership and someone else put data on the clipboard.
 142      * @since 1.7
 143      */
 144     native boolean checkPasteboardWithoutNotification();
 145 
 146     /*** Native Callbacks ***/
 147     private void notifyLostOwnership() {
 148         lostOwnershipImpl();
 149     }
 150 
 151     private static void notifyChanged() {
 152         CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
 153         if (!clipboard.areFlavorListenersRegistered()) {
 154             return;
 155         }
 156         clipboard.checkChange(clipboard.getClipboardFormats());
 157     }
 158 }