checkWidget(); if (transfer == null) DND.error(SWT.ERROR_NULL_ARGUMENT); int xDisplay = OS.XtDisplay (shellHandle); if (xDisplay == 0) return null; int xWindow = OS.XtWindow (shellHandle); if (xWindow == 0) return null;   if (OS.XmClipboardStartRetrieve(xDisplay, xWindow, OS.XtLastTimestampProcessed(xDisplay)) != OS.XmClipboardSuccess) return null; byte[] data = null; byte[] type = null; try {  int[] length = new int[1]; String[] supportedTypes = transfer.getTypeNames(); for (int i = 0; i < supportedTypes.length; i++) { byte[] bName = Converter.wcsToMbcs(null, supportedTypes[i], true); if (OS.XmClipboardInquireLength(xDisplay, xWindow, bName, length) == OS.XmClipboardSuccess) { type = bName; break; } }  if (type == null) return null; data = new byte[length[0]]; if (OS.XmClipboardRetrieve(xDisplay, xWindow, type, data, length[0], new int[1], new int[1]) != OS.XmClipboardSuccess) { return null; } } finally {  OS.XmClipboardEndRetrieve(xDisplay, xWindow); }    int pValue = OS.XtMalloc(data.length); if (pValue == 0) return null; try { OS.memmove(pValue, data, data.length); TransferData transferData = new TransferData(); transferData.type = OS.XmInternAtom (xDisplay, type, true); transferData.length = data.length; transferData.format = 8; transferData.pValue = pValue; transferData.result = 1; return transfer.nativeToJava(transferData); } finally {  OS.XtFree(pValue); }
return getContents(transfer, DND.CLIPBOARD);
public Object getContents(Transfer transfer) {	checkWidget();	if (transfer == null) DND.error(SWT.ERROR_NULL_ARGUMENT);	int xDisplay = OS.XtDisplay (shellHandle);	if (xDisplay == 0) return null;	int xWindow = OS.XtWindow (shellHandle);	if (xWindow == 0) return null;		// Open clipboard for retrieval	if (OS.XmClipboardStartRetrieve(xDisplay, xWindow, OS.XtLastTimestampProcessed(xDisplay)) != OS.XmClipboardSuccess) return null;	byte[] data = null;	byte[] type = null;	try {		// Does Clipboard have data in required format?		int[] length = new int[1];		String[] supportedTypes = transfer.getTypeNames();		for (int i = 0; i < supportedTypes.length; i++) {			byte[] bName = Converter.wcsToMbcs(null, supportedTypes[i], true);			if (OS.XmClipboardInquireLength(xDisplay, xWindow, bName, length) == OS.XmClipboardSuccess) {				type = bName;				break;			}		}		// Retrieve data from Clipboard		if (type == null) return null;		data = new byte[length[0]];		if (OS.XmClipboardRetrieve(xDisplay, xWindow, type, data, length[0], new int[1], new int[1]) != OS.XmClipboardSuccess) {			return null;		}	} finally {		// Close Clipboard		OS.XmClipboardEndRetrieve(xDisplay, xWindow);	}		// Pass data to transfer agent for conversion to a Java Object	// Memory is allocated here to emulate the way Drag and Drop transfers data.	int pValue = OS.XtMalloc(data.length);	if (pValue == 0) return null;	try {		OS.memmove(pValue, data, data.length);		TransferData transferData = new TransferData();		transferData.type = OS.XmInternAtom (xDisplay, type, true);		transferData.length = data.length;		transferData.format = 8;		transferData.pValue = pValue;		transferData.result = 1;		return transfer.nativeToJava(transferData);	} finally {		// Clean up allocated memory		OS.XtFree(pValue);	}}