/* * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.glass.ui.swt; import com.sun.glass.ui.Pixels; import com.sun.glass.ui.Clipboard; import com.sun.glass.ui.SystemClipboard; import java.nio.IntBuffer; import java.util.HashMap; import java.util.Set; import org.eclipse.swt.*; import org.eclipse.swt.dnd.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; class SWTClipboard extends SystemClipboard { org.eclipse.swt.dnd.Clipboard clipboard; static final String CLIPBOARD_KEY = "SWTClipboard"; //TODO - temporary code to enable multiple transfers on Windows only static final boolean MULTIPLE_TRANSFERS = SWT.getPlatform().equals("win32"); // Define local constants to avoid name conflicts static final int DROP_NONE = org.eclipse.swt.dnd.DND.DROP_NONE; static final int DROP_COPY = org.eclipse.swt.dnd.DND.DROP_COPY; static final int DROP_MOVE = org.eclipse.swt.dnd.DND.DROP_MOVE; static final int DROP_LINK = org.eclipse.swt.dnd.DND.DROP_LINK; private static final boolean MUTIPLE_TRANSFERS = false; // Define standard transfer types including custom transfers static Transfer [] StandardTransfers = new Transfer [] { TextTransfer.getInstance(), RTFTransfer.getInstance(), HTMLTransfer.getInstance(), URLTransfer.getInstance(), ImageTransfer.getInstance(), FileTransfer.getInstance(), }; static Transfer [] CustomTransfers = new Transfer [0]; public SWTClipboard(String name) { super(name); //TODO - implement selection clipboard for Linux if (name.equals(SYSTEM)) { Display display = Display.getDefault(); clipboard = (org.eclipse.swt.dnd.Clipboard) display.getData(CLIPBOARD_KEY); if (clipboard == null) { clipboard = new org.eclipse.swt.dnd.Clipboard(display); display.setData(CLIPBOARD_KEY, clipboard); display.disposeExec(() -> clipboard.dispose()); } } } static Transfer [] getAllTransfers () { Transfer [] transfers = new Transfer[StandardTransfers.length + CustomTransfers.length]; System.arraycopy(StandardTransfers, 0, transfers, 0, StandardTransfers.length); System.arraycopy(CustomTransfers, 0, transfers, StandardTransfers.length, CustomTransfers.length); return transfers; } static Transfer getCustomTransfer(String mime) { for (int i=0; i data, int supportedActions) { int count = 0; ImageData imageData = null; Set keys = data.keySet(); Object [] objects = new Object [keys.size()]; Transfer[] transfers = new Transfer[keys.size()]; for (String key : keys) { Transfer transfer = getTransferType(key); if (transfer != null) { //TODO - image not done, format wrong, alpha wrong if (transfer instanceof ImageTransfer && data.get(key) instanceof Pixels) { Pixels pixels = (Pixels) data.get(key); objects[count] = imageData = SWTApplication.createImageData(pixels); } else { objects[count] = data.get(key); } transfers [count] = transfer; count++; } } if (count == 0) return; if (count != objects.length) { Object [] newObjects = new Object [objects.length]; System.arraycopy(objects, 0, newObjects, 0, objects.length); objects = newObjects; Transfer [] newTransfers = new Transfer [transfers.length]; System.arraycopy(transfers, 0, newTransfers, 0, transfers.length); transfers = newTransfers; } if (clipboard != null) { //TODO - setting and empty string to the clipboard causes an exception //TODO - clear the contents instead (what about multiple objects?) for (int i=0; i