diff options
author | Kevin Barnes <krbarnes> | 2008-07-09 18:51:35 +0000 |
---|---|---|
committer | Kevin Barnes <krbarnes> | 2008-07-09 18:51:35 +0000 |
commit | 4dbd09dcd54c5e8b8416ccbe2fdfacc6901be61f (patch) | |
tree | 7d4709d18db1eed49ac022beba75dacbacb13b1b | |
parent | 6b0a245288556e7224d3c56682401ca81ba95245 (diff) | |
download | eclipse.platform.swt-4dbd09dcd54c5e8b8416ccbe2fdfacc6901be61f.tar.gz eclipse.platform.swt-4dbd09dcd54c5e8b8416ccbe2fdfacc6901be61f.tar.xz eclipse.platform.swt-4dbd09dcd54c5e8b8416ccbe2fdfacc6901be61f.zip |
211536 - RTFTransfer not implemented; code demonstrating NSPasteboard attached
24 files changed, 923 insertions, 1074 deletions
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cocoa.OS.properties b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cocoa.OS.properties index 25d26276bc..6207acd300 100755 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cocoa.OS.properties +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cocoa.OS.properties @@ -793,6 +793,8 @@ OS_NSErrorFailingURLStringKey=flags=const OS_NSFileTypeForHFSTypeCode= OS_NSFileTypeForHFSTypeCode_0= +OS_NSFilenamesPboardType=flags=const + OS_NSFontAttributeName=flags=const OS_NSForegroundColorAttributeName=flags=const @@ -806,12 +808,18 @@ OS_NSLinkAttributeName=flags=const OS_NSParagraphStyleAttributeName=flags=const +OS_NSRTFPboardType=flags=const + OS_NSStrikethroughColorAttributeName=flags=const OS_NSStrikethroughStyleAttributeName=flags=const OS_NSStringPboardType=flags=const +OS_NSTIFFPboardType=flags=const + +OS_NSURLPboardType=flags=const + OS_NSUnderlineColorAttributeName=flags=const OS_NSUnderlineStyleAttributeName=flags=const @@ -2181,6 +2189,17 @@ OS_objc_1msgSend__IIZZ_1=cast=(SEL) OS_objc_1msgSend__IIZZ_2= OS_objc_1msgSend__IIZZ_3= +OS_objc_1msgSend__II_3B=flags=cast +OS_objc_1msgSend__II_3B_0=cast=(id) +OS_objc_1msgSend__II_3B_1=cast=(SEL) +OS_objc_1msgSend__II_3B_2= + +OS_objc_1msgSend__II_3BI=flags=cast +OS_objc_1msgSend__II_3BI_0=cast=(id) +OS_objc_1msgSend__II_3BI_1=cast=(SEL) +OS_objc_1msgSend__II_3BI_2= +OS_objc_1msgSend__II_3BI_3= + OS_objc_1msgSend__II_3C= OS_objc_1msgSend__II_3C_0=cast=(id) OS_objc_1msgSend__II_3C_1=cast=(SEL) diff --git a/bundles/org.eclipse.swt/.classpath_cocoa b/bundles/org.eclipse.swt/.classpath_cocoa index 69fa84eac5..fcd363fe7a 100755 --- a/bundles/org.eclipse.swt/.classpath_cocoa +++ b/bundles/org.eclipse.swt/.classpath_cocoa @@ -22,7 +22,7 @@ <classpathentry kind="src" path="Eclipse SWT AWT/emulated"/> <classpathentry kind="src" path="Eclipse SWT Custom Widgets/common"/> <classpathentry kind="src" path="Eclipse SWT Drag and Drop/common"/> - <classpathentry kind="src" path="Eclipse SWT Drag and Drop/emulated"/> + <classpathentry kind="src" path="Eclipse SWT Drag and Drop/cocoa"/> <classpathentry kind="src" path="Eclipse SWT Printing/common"/> <classpathentry kind="src" path="Eclipse SWT Printing/cocoa"/> <classpathentry kind="src" path="Eclipse SWT Program/common"/> diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ByteArrayTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ByteArrayTransfer.java index 11bd60f7a2..1ea9708f1d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ByteArrayTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ByteArrayTransfer.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.dnd; +import org.eclipse.swt.internal.cocoa.*; + /** * The class <code>ByteArrayTransfer</code> provides a platform specific @@ -119,20 +121,20 @@ package org.eclipse.swt.dnd; public abstract class ByteArrayTransfer extends Transfer { public TransferData[] getSupportedTypes() { - int[] types = getTypeIds(); - TransferData[] data = new TransferData[types.length]; - for (int i = 0; i < types.length; i++) { + String[] registeredTypes = registeredTypes(); + TransferData[] data = new TransferData[registeredTypes.length]; + for (int i = 0; i < registeredTypes.length; i++) { data[i] = new TransferData(); - data[i].type = types[i]; + data[i].type = registeredTypes[i]; } return data; } public boolean isSupportedType(TransferData transferData){ if (transferData == null) return false; - int[] types = getTypeIds(); - for (int i = 0; i < types.length; i++) { - if (transferData.type == types[i]) return true; + String[] registeredTypes = registeredTypes(); + for (int i = 0; i < registeredTypes.length; i++) { + if (transferData.type.equals(registeredTypes[i])) return true; } return false; } @@ -152,11 +154,8 @@ protected void javaToNative (Object object, TransferData transferData) { DND.error(DND.ERROR_INVALID_DATA); } byte[] orig = (byte[])object; - byte[] buffer = new byte[orig.length]; - System.arraycopy(orig, 0, buffer, 0, orig.length); - transferData.data = new byte[1][]; - transferData.data[0] = buffer; - transferData.result = 0; + NSData data = NSData.dataWithBytes(orig, orig.length); + transferData.data = data; } /** @@ -171,8 +170,12 @@ protected void javaToNative (Object object, TransferData transferData) { */ protected Object nativeToJava(TransferData transferData) { if (!isSupportedType(transferData) || transferData.data == null) return null; - if (transferData.data.length == 0 || transferData.data[0].length == 0) return null; - return transferData.data[0]; + if (transferData.data == null) return null; + NSData data = (NSData) transferData.data; + if (data.length() == 0) return null; + byte[] bytes = new byte[data.length()]; + data.getBytes_(bytes); + return bytes; } boolean checkByteArray(Object object) { return (object != null && object instanceof byte[] && ((byte[])object).length > 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Clipboard.java index 4a4d295cf3..c3dde2bd61 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Clipboard.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Clipboard.java @@ -13,7 +13,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.carbon.OS; +import org.eclipse.swt.internal.cocoa.*; /** * The <code>Clipboard</code> provides a mechanism for transferring data from one @@ -169,13 +169,9 @@ public void clearContents() { public void clearContents(int clipboards) { checkWidget(); if ((clipboards & DND.CLIPBOARD) == 0 || scrap == 0) return; - int oldScrap = scrap; - scrap = 0; - int[] currentScrap = new int[1]; - if (OS.GetCurrentScrap(currentScrap) != OS.noErr) return; - if (currentScrap[0] == oldScrap) { - OS.ClearCurrentScrap(); - } + NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); + //TODO +// A declareTypes:owner: message essentially changes the contents of the receiver: It invalidates the current contents of the receiver and increments its change count. } /** @@ -279,23 +275,24 @@ public Object getContents(Transfer transfer, int clipboards) { checkWidget(); if (transfer == null) DND.error(SWT.ERROR_NULL_ARGUMENT); if ((clipboards & DND.CLIPBOARD) == 0) return null; - int[] scrap = new int[1]; - if (OS.GetCurrentScrap(scrap) != OS.noErr) return null; + NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); int[] typeIds = transfer.getTypeIds(); - int[] size = new int[1]; // get data from system clipboard for (int i=0; i<typeIds.length; i++) { - int type = typeIds[i]; - size[0] = 0; - if (OS.GetScrapFlavorSize(scrap[0], type, size) == OS.noErr && size[0] > 0) { - byte[] buffer = new byte[size[0]]; - if (OS.GetScrapFlavorData(scrap[0], type, size, buffer) == OS.noErr) { - TransferData tdata = new TransferData(); - tdata.type = type; - tdata.data = new byte[1][]; - tdata.data[0] = buffer; - return transfer.nativeToJava(tdata); - } + TransferData tdata = new TransferData(); + String type = Transfer.types[typeIds[i]]; + NSString dataType = NSString.stringWith(type); + if (dataType.isEqual(OS.NSStringPboardType) || + dataType.isEqual(OS.NSRTFPboardType)) { + tdata.data = pasteboard.stringForType(dataType); + } else if (dataType.isEqual(OS.NSFilenamesPboardType)) { + tdata.data = new NSArray(pasteboard.propertyListForType(dataType).id); + } else { + tdata.data = pasteboard.dataForType(dataType); + } + if (tdata.data != null) { + tdata.type = type; + return transfer.nativeToJava(tdata); } } return null; // No data available for this transfer @@ -439,35 +436,43 @@ public void setContents(Object[] data, Transfer[] dataTypes, int clipboards) { } } if ((clipboards & DND.CLIPBOARD) == 0) return; - if (OS.ClearCurrentScrap() != OS.noErr) { + NSPasteboard pasteboard = NSPasteboard.generalPasteboard(); + if (pasteboard == null) { DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); } - scrap = 0; - int[] currentScrap = new int[1]; - if (OS.GetCurrentScrap(currentScrap) != OS.noErr) { - DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); - } - scrap = currentScrap[0]; - // copy data directly over to System clipboard (not deferred) for (int i=0; i<dataTypes.length; i++) { int[] typeIds = dataTypes[i].getTypeIds(); for (int j=0; j<typeIds.length; j++) { TransferData transferData = new TransferData(); - transferData.type = typeIds[j]; - dataTypes[i].javaToNative(data[i], transferData); - if (transferData.result != OS.noErr) { - DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); - } - //Drag and Drop can handle multiple items in one transfer but the - //Clipboard can not. - byte[] datum = transferData.data[0]; - if (OS.PutScrapFlavor(scrap, transferData.type, 0, datum.length, datum) != OS.noErr){ - DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); + transferData.type = Transfer.types[typeIds[j]]; + dataTypes[i].javaToNative(data[i], transferData); + NSObject tdata = transferData.data; + NSString dataType = NSString.stringWith(transferData.type); + declareTypes(pasteboard); + if (dataType.isEqual(OS.NSStringPboardType) || + dataType.isEqual(OS.NSRTFPboardType)) { + pasteboard.setString((NSString) tdata, dataType); + } else if (dataType.isEqual(OS.NSFilenamesPboardType)) { + pasteboard.setPropertyList((NSArray) tdata, dataType); + } else { + pasteboard.setData((NSData) tdata, dataType); } } } } +private void declareTypes(NSPasteboard pasteboard) { + String[] typeNames = getAvailableTypeNames(); + NSMutableArray declaredTypes = NSMutableArray.arrayWithCapacity(typeNames.length); + for (int i = 0; i < typeNames.length; i++) { + String typeName = typeNames[i]; + if (typeName != null) { + declaredTypes.addObject(NSString.stringWith(typeName)); + } + } + pasteboard.declareTypes(declaredTypes, null); +} + /** * Returns an array of the data types currently available on the system * clipboard. Use with Transfer.isSupportedType. @@ -512,12 +517,12 @@ public TransferData[] getAvailableTypes() { */ public TransferData[] getAvailableTypes(int clipboards) { checkWidget(); - if ((clipboards & DND.CLIPBOARD) == 0) return new TransferData[0]; - int[] types = _getAvailableTypes(); - TransferData[] result = new TransferData[types.length]; - for (int i = 0; i < types.length; i++) { + if ((clipboards & DND.CLIPBOARD) == 0) return new TransferData[0]; + String[] registeredTypes = Transfer.registeredTypes(); + TransferData[] result = new TransferData[registeredTypes.length]; + for (int i = 0; i < result.length; i++) { result[i] = new TransferData(); - result[i].type = types[i]; + result[i].type = registeredTypes[i]; } return result; } @@ -540,32 +545,6 @@ public TransferData[] getAvailableTypes(int clipboards) { */ public String[] getAvailableTypeNames() { checkWidget(); - int[] types = _getAvailableTypes(); - String[] names = new String[types.length]; - for (int i = 0; i < types.length; i++) { - int type = types[i]; - StringBuffer sb = new StringBuffer(); - sb.append((char)((type & 0xff000000) >> 24)); - sb.append((char)((type & 0x00ff0000) >> 16)); - sb.append((char)((type & 0x0000ff00) >> 8)); - sb.append((char)((type & 0x000000ff) >> 0)); - names[i] = sb.toString(); - } - return names; -} - -int[] _getAvailableTypes() { - int[] types = new int[0]; - int[] scrap = new int[1]; - if (OS.GetCurrentScrap(scrap) != OS.noErr) return types; - int[] count = new int[1]; - if (OS.GetScrapFlavorCount(scrap[0], count) != OS.noErr || count[0] == 0) return types; - int[] info = new int[count[0] * 2]; - if (OS.GetScrapFlavorInfoList(scrap[0], count, info) != OS.noErr) return types; - types = new int[count[0]]; - for (int i= 0; i < count [0]; i++) { - types[i] = info[i*2]; - } - return types; + return Transfer.registeredTypes(); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DragSource.java index 05d9bd77b0..d8aaf76411 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DragSource.java @@ -15,11 +15,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.internal.Callback; -import org.eclipse.swt.internal.carbon.CGPoint; -import org.eclipse.swt.internal.carbon.EventRecord; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Point; - +import org.eclipse.swt.internal.cocoa.*; /** * * <code>DragSource</code> defines the source object for a drag and drop transfer. @@ -111,11 +107,11 @@ public class DragSource extends Widget { static final String DEFAULT_DRAG_SOURCE_EFFECT = "DEFAULT_DRAG_SOURCE_EFFECT"; //$NON-NLS-1$ static Callback DragSendDataProc; - static { - DragSendDataProc = new Callback(DragSource.class, "DragSendDataProc", 4); //$NON-NLS-1$ - int dragSendDataProcAddress = DragSendDataProc.getAddress(); - if (dragSendDataProcAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - } +// static { +// DragSendDataProc = new Callback(DragSource.class, "DragSendDataProc", 4); //$NON-NLS-1$ +// int dragSendDataProcAddress = DragSendDataProc.getAddress(); +// if (dragSendDataProcAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); +// } /** * Creates a new <code>DragSource</code> to handle dragging from the specified <code>Control</code>. @@ -192,20 +188,20 @@ static int checkStyle (int style) { return style; } -static int DragSendDataProc(int theType, int dragSendRefCon, int theItemRef, int theDrag) { - DragSource source = FindDragSource(dragSendRefCon, theDrag); - if (source == null) return OS.cantGetFlavorErr; - return source.dragSendDataProc(theType, dragSendRefCon, theItemRef, theDrag); -} +//static int DragSendDataProc(int theType, int dragSendRefCon, int theItemRef, int theDrag) { +// DragSource source = FindDragSource(dragSendRefCon, theDrag); +// if (source == null) return OS.cantGetFlavorErr; +// return source.dragSendDataProc(theType, dragSendRefCon, theItemRef, theDrag); +//} -static DragSource FindDragSource(int dragSendRefCon, int theDrag) { - if (dragSendRefCon == 0) return null; - Display display = Display.findDisplay(Thread.currentThread()); - if (display == null || display.isDisposed()) return null; - Widget widget = display.findWidget(dragSendRefCon); - if (widget == null) return null; - return (DragSource)widget.getData(DND.DRAG_SOURCE_KEY); -} +//static DragSource FindDragSource(int dragSendRefCon, int theDrag) { +// if (dragSendRefCon == 0) return null; +// Display display = Display.findDisplay(Thread.currentThread()); +// if (display == null || display.isDisposed()) return null; +// Widget widget = display.findWidget(dragSendRefCon); +// if (widget == null) return null; +// return (DragSource)widget.getData(DND.DRAG_SOURCE_KEY); +//} /** * Adds the listener to the collection of listeners who will @@ -255,145 +251,145 @@ protected void checkSubclass () { } void drag(Event dragEvent) { - DNDEvent event = new DNDEvent(); - event.widget = this; - event.x = dragEvent.x; - event.y = dragEvent.y; - event.time = dragEvent.time; - event.doit = true; - notifyListeners(DND.DragStart, event); - if (!event.doit || transferAgents == null || transferAgents.length == 0) return; - - int[] theDrag = new int[1]; - if (OS.NewDrag(theDrag) != OS.noErr) { - event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.doit = false; - event.detail = DND.DROP_NONE; - notifyListeners(DND.DragEnd, event); - return; - } - - Point pt = new Point(); - OS.GetGlobalMouse (pt); - - for (int i = 0; i < transferAgents.length; i++) { - Transfer transfer = transferAgents[i]; - if (transfer != null) { - int[] types = transfer.getTypeIds(); - if (transfer instanceof FileTransfer) { - TransferData transferData = new TransferData(); - transferData.type = types[0]; - DNDEvent event2 = new DNDEvent(); - event2.widget = this; - event2.time = (int)System.currentTimeMillis(); - event2.dataType = transferData; - notifyListeners(DND.DragSetData, event2); - if (event2.data != null) { - for (int j = 0; j < types.length; j++) { - transferData.type = types[j]; - transfer.javaToNative(event2.data, transferData); - if (transferData.result == OS.noErr) { - for (int k = 0; k < transferData.data.length; k++) { - byte[] datum = transferData.data[k]; - OS.AddDragItemFlavor(theDrag[0], 1 + k, types[j], datum, datum.length, 0); - } - } - } - } - } else { - for (int j = 0; j < types.length; j++) { - OS.AddDragItemFlavor(theDrag[0], 1, types[j], null, 0, 0); - } - } - } - } - - OS.SetDragSendProc(theDrag[0], DragSendDataProc.getAddress(), control.handle); - - int theRegion = 0; - Image newImage = null; - try { - theRegion = OS.NewRgn(); - OS.SetRectRgn(theRegion, (short)(pt.h), (short)(pt.v), (short)(pt.h+20), (short)(pt.v+20)); - - int operations = opToOsOp(getStyle()); - //set operations twice - local and not local - OS.SetDragAllowableActions(theDrag[0], operations, true); - OS.SetDragAllowableActions(theDrag[0], operations, false); - - Image image = event.image; - if (image != null) { - CGPoint imageOffsetPt = new CGPoint(); - imageOffsetPt.x = 0; - imageOffsetPt.y = 0; - /* - * Bug in the Macintosh. For some reason, it seems that SetDragImageWithCGImage() - * expects an image with the alpha, otherwise the image does not draw. The fix is - * to make sure that the image has an alpha by creating a new image with alpha - * when necessary. - */ - if (OS.CGImageGetAlphaInfo(image.handle) == OS.kCGImageAlphaNoneSkipFirst) { - ImageData data = image.getImageData(); - data.alpha = 0xFF; - newImage = new Image(image.getDevice(), data); - image = newImage; - } - OS.SetDragImageWithCGImage(theDrag[0], image.handle, imageOffsetPt, 0); - } - EventRecord theEvent = new EventRecord(); - theEvent.message = OS.kEventMouseMoved; - theEvent.modifiers = (short)OS.GetCurrentEventKeyModifiers(); - theEvent.what = (short)OS.osEvt; - theEvent.where_h = pt.h; - theEvent.where_v = pt.v; - int result = OS.TrackDrag(theDrag[0], theEvent, theRegion); - int operation = DND.DROP_NONE; - if (result == OS.noErr) { - int[] outAction = new int[1]; - OS.GetDragDropAction(theDrag[0], outAction); - operation = osOpToOp(outAction[0]); - } - event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.doit = result == OS.noErr; - event.detail = operation; - notifyListeners(DND.DragEnd, event); - } finally { - if (theRegion != 0) OS.DisposeRgn(theRegion); - if (newImage != null) newImage.dispose(); - } - OS.DisposeDrag(theDrag[0]); +// DNDEvent event = new DNDEvent(); +// event.widget = this; +// event.x = dragEvent.x; +// event.y = dragEvent.y; +// event.time = dragEvent.time; +// event.doit = true; +// notifyListeners(DND.DragStart, event); +// if (!event.doit || transferAgents == null || transferAgents.length == 0) return; +// +// int[] theDrag = new int[1]; +// if (OS.NewDrag(theDrag) != OS.noErr) { +// event = new DNDEvent(); +// event.widget = this; +// event.time = (int)System.currentTimeMillis(); +// event.doit = false; +// event.detail = DND.DROP_NONE; +// notifyListeners(DND.DragEnd, event); +// return; +// } +// +// Point pt = new Point(); +// OS.GetGlobalMouse (pt); +// +// for (int i = 0; i < transferAgents.length; i++) { +// Transfer transfer = transferAgents[i]; +// if (transfer != null) { +// int[] types = transfer.getTypeIds(); +// if (transfer instanceof FileTransfer) { +// TransferData transferData = new TransferData(); +// transferData.type = types[0]; +// DNDEvent event2 = new DNDEvent(); +// event2.widget = this; +// event2.time = (int)System.currentTimeMillis(); +// event2.dataType = transferData; +// notifyListeners(DND.DragSetData, event2); +// if (event2.data != null) { +// for (int j = 0; j < types.length; j++) { +// transferData.type = types[j]; +// transfer.javaToNative(event2.data, transferData); +// if (transferData.result == OS.noErr) { +// for (int k = 0; k < transferData.data.length; k++) { +// byte[] datum = transferData.data[k]; +// OS.AddDragItemFlavor(theDrag[0], 1 + k, types[j], datum, datum.length, 0); +// } +// } +// } +// } +// } else { +// for (int j = 0; j < types.length; j++) { +// OS.AddDragItemFlavor(theDrag[0], 1, types[j], null, 0, 0); +// } +// } +// } +// } +// +// OS.SetDragSendProc(theDrag[0], DragSendDataProc.getAddress(), control.handle); +// +// int theRegion = 0; +// Image newImage = null; +// try { +// theRegion = OS.NewRgn(); +// OS.SetRectRgn(theRegion, (short)(pt.h), (short)(pt.v), (short)(pt.h+20), (short)(pt.v+20)); +// +// int operations = opToOsOp(getStyle()); +// //set operations twice - local and not local +// OS.SetDragAllowableActions(theDrag[0], operations, true); +// OS.SetDragAllowableActions(theDrag[0], operations, false); +// +// Image image = event.image; +// if (image != null) { +// CGPoint imageOffsetPt = new CGPoint(); +// imageOffsetPt.x = 0; +// imageOffsetPt.y = 0; +// /* +// * Bug in the Macintosh. For some reason, it seems that SetDragImageWithCGImage() +// * expects an image with the alpha, otherwise the image does not draw. The fix is +// * to make sure that the image has an alpha by creating a new image with alpha +// * when necessary. +// */ +// if (OS.CGImageGetAlphaInfo(image.handle) == OS.kCGImageAlphaNoneSkipFirst) { +// ImageData data = image.getImageData(); +// data.alpha = 0xFF; +// newImage = new Image(image.getDevice(), data); +// image = newImage; +// } +// OS.SetDragImageWithCGImage(theDrag[0], image.handle, imageOffsetPt, 0); +// } +// EventRecord theEvent = new EventRecord(); +// theEvent.message = OS.kEventMouseMoved; +// theEvent.modifiers = (short)OS.GetCurrentEventKeyModifiers(); +// theEvent.what = (short)OS.osEvt; +// theEvent.where_h = pt.h; +// theEvent.where_v = pt.v; +// int result = OS.TrackDrag(theDrag[0], theEvent, theRegion); +// int operation = DND.DROP_NONE; +// if (result == OS.noErr) { +// int[] outAction = new int[1]; +// OS.GetDragDropAction(theDrag[0], outAction); +// operation = osOpToOp(outAction[0]); +// } +// event = new DNDEvent(); +// event.widget = this; +// event.time = (int)System.currentTimeMillis(); +// event.doit = result == OS.noErr; +// event.detail = operation; +// notifyListeners(DND.DragEnd, event); +// } finally { +// if (theRegion != 0) OS.DisposeRgn(theRegion); +// if (newImage != null) newImage.dispose(); +// } +// OS.DisposeDrag(theDrag[0]); } -int dragSendDataProc(int theType, int dragSendRefCon, int theItemRef, int theDrag) { - if (theType == 0) return OS.badDragFlavorErr; - TransferData transferData = new TransferData(); - transferData.type = theType; - DNDEvent event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.dataType = transferData; - notifyListeners(DND.DragSetData, event); - Transfer transfer = null; - for (int i = 0; i < transferAgents.length; i++) { - Transfer transferAgent = transferAgents[i]; - if (transferAgent != null && transferAgent.isSupportedType(transferData)) { - transfer = transferAgent; - break; - } - } - if (transfer == null) return OS.badDragFlavorErr; - transfer.javaToNative(event.data, transferData); - if (transferData.result != OS.noErr) return transferData.result; - // Except for FileTransfer (see #drag), only one item can be transferred - // in a Drag operation - byte[] datum = transferData.data[0]; - if (datum == null) return OS.cantGetFlavorErr; - return OS.SetDragItemFlavorData(theDrag, theItemRef, theType, datum, datum.length, 0); -} +//int dragSendDataProc(int theType, int dragSendRefCon, int theItemRef, int theDrag) { +// if (theType == 0) return OS.badDragFlavorErr; +// TransferData transferData = new TransferData(); +// transferData.type = theType; +// DNDEvent event = new DNDEvent(); +// event.widget = this; +// event.time = (int)System.currentTimeMillis(); +// event.dataType = transferData; +// notifyListeners(DND.DragSetData, event); +// Transfer transfer = null; +// for (int i = 0; i < transferAgents.length; i++) { +// Transfer transferAgent = transferAgents[i]; +// if (transferAgent != null && transferAgent.isSupportedType(transferData)) { +// transfer = transferAgent; +// break; +// } +// } +// if (transfer == null) return OS.badDragFlavorErr; +// transfer.javaToNative(event.data, transferData); +// if (transferData.result != OS.noErr) return transferData.result; +// // Except for FileTransfer (see #drag), only one item can be transferred +// // in a Drag operation +// byte[] datum = transferData.data[0]; +// if (datum == null) return OS.cantGetFlavorErr; +// return OS.SetDragItemFlavorData(theDrag, theItemRef, theType, datum, datum.length, 0); +//} /** * Returns the Control which is registered for this DragSource. This is the control that the @@ -477,42 +473,42 @@ void onDispose() { transferAgents = null; } -int opToOsOp(int operation) { - int osOperation = 0; - if ((operation & DND.DROP_COPY) != 0){ - osOperation |= OS.kDragActionCopy; - } - if ((operation & DND.DROP_LINK) != 0) { - osOperation |= OS.kDragActionAlias; - } - if ((operation & DND.DROP_MOVE) != 0) { - osOperation |= OS.kDragActionMove; - } - if ((operation & DND.DROP_TARGET_MOVE) != 0) { - osOperation |= OS.kDragActionDelete; - } - return osOperation; -} +//int opToOsOp(int operation) { +// int osOperation = 0; +// if ((operation & DND.DROP_COPY) != 0){ +// osOperation |= OS.kDragActionCopy; +// } +// if ((operation & DND.DROP_LINK) != 0) { +// osOperation |= OS.kDragActionAlias; +// } +// if ((operation & DND.DROP_MOVE) != 0) { +// osOperation |= OS.kDragActionMove; +// } +// if ((operation & DND.DROP_TARGET_MOVE) != 0) { +// osOperation |= OS.kDragActionDelete; +// } +// return osOperation; +//} -int osOpToOp(int osOperation){ - int operation = 0; - if ((osOperation & OS.kDragActionCopy) != 0){ - operation |= DND.DROP_COPY; - } - if ((osOperation & OS.kDragActionAlias) != 0) { - operation |= DND.DROP_LINK; - } - if ((osOperation & OS.kDragActionDelete) != 0) { - operation |= DND.DROP_TARGET_MOVE; - } - if ((osOperation & OS.kDragActionMove) != 0) { - operation |= DND.DROP_MOVE; - } - if (osOperation == OS.kDragActionAll) { - operation = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; - } - return operation; -} +//int osOpToOp(int osOperation){ +// int operation = 0; +// if ((osOperation & OS.kDragActionCopy) != 0){ +// operation |= DND.DROP_COPY; +// } +// if ((osOperation & OS.kDragActionAlias) != 0) { +// operation |= DND.DROP_LINK; +// } +// if ((osOperation & OS.kDragActionDelete) != 0) { +// operation |= DND.DROP_TARGET_MOVE; +// } +// if ((osOperation & OS.kDragActionMove) != 0) { +// operation |= DND.DROP_MOVE; +// } +// if (osOperation == OS.kDragActionAll) { +// operation = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; +// } +// return operation; +//} /** * Removes the listener from the collection of listeners who will diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DropTarget.java index 7a6ce9f567..153231aeec 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DropTarget.java @@ -14,7 +14,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.carbon.*; +import org.eclipse.swt.internal.cocoa.*; /** * @@ -102,16 +102,16 @@ public class DropTarget extends Widget { static Callback DragTrackingHandler; static Callback DragReceiveHandler; - static { - DragTrackingHandler = new Callback(DropTarget.class, "DragTrackingHandler", 4); //$NON-NLS-1$ - int dragTrackingHandlerAddress = DragTrackingHandler.getAddress(); - if (dragTrackingHandlerAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - DragReceiveHandler = new Callback(DropTarget.class, "DragReceiveHandler", 3); //$NON-NLS-1$ - int dragReceiveHandlerAddress = DragReceiveHandler.getAddress(); - if (dragReceiveHandlerAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - OS.InstallTrackingHandler(dragTrackingHandlerAddress, 0, null); - OS.InstallReceiveHandler(dragReceiveHandlerAddress, 0, null); - } +// static { +// DragTrackingHandler = new Callback(DropTarget.class, "DragTrackingHandler", 4); //$NON-NLS-1$ +// int dragTrackingHandlerAddress = DragTrackingHandler.getAddress(); +// if (dragTrackingHandlerAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); +// DragReceiveHandler = new Callback(DropTarget.class, "DragReceiveHandler", 3); //$NON-NLS-1$ +// int dragReceiveHandlerAddress = DragReceiveHandler.getAddress(); +// if (dragReceiveHandlerAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); +// OS.InstallTrackingHandler(dragTrackingHandlerAddress, 0, null); +// OS.InstallReceiveHandler(dragReceiveHandlerAddress, 0, null); +// } /** * Creates a new <code>DropTarget</code> to allow data to be dropped on the specified @@ -147,12 +147,12 @@ public class DropTarget extends Widget { public DropTarget(Control control, int style) { super(control, checkStyle(style)); this.control = control; - if (DragTrackingHandler == null || DragTrackingHandler == null) { - DND.error(DND.ERROR_CANNOT_INIT_DROP); - } - if (control.getData(DND.DROP_TARGET_KEY) != null) { - DND.error(DND.ERROR_CANNOT_INIT_DROP); - } +// if (DragTrackingHandler == null || DragTrackingHandler == null) { +// DND.error(DND.ERROR_CANNOT_INIT_DROP); +// } +// if (control.getData(DND.DROP_TARGET_KEY) != null) { +// DND.error(DND.ERROR_CANNOT_INIT_DROP); +// } control.setData(DND.DROP_TARGET_KEY, this); controlListener = new Listener () { @@ -234,51 +234,51 @@ static int checkStyle (int style) { return style; } -static int DragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { - DropTarget target = FindDropTarget(theWindow, theDrag); - if (target == null) return OS.noErr; - return target.dragReceiveHandler(theWindow, handlerRefCon, theDrag); -} - -static int DragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDrag) { - if (message == OS.kDragTrackingLeaveHandler || message == OS.kDragTrackingEnterHandler) { - CurrentDropTarget = null; - return OS.noErr; - } - DropTarget target = FindDropTarget(theWindow, theDrag); - if (CurrentDropTarget != null) { - if (target == null || CurrentDropTarget.control.handle != target.control.handle) { - CurrentDropTarget.dragTrackingHandler(OS.kDragTrackingLeaveWindow, theWindow, handlerRefCon, theDrag); - CurrentDropTarget = target; - message = OS.kDragTrackingEnterWindow; - } - } else { - CurrentDropTarget = target; - message = OS.kDragTrackingEnterWindow; - } - if (target == null) return OS.noErr; - return target.dragTrackingHandler(message, theWindow, handlerRefCon, theDrag); -} - -static DropTarget FindDropTarget(int theWindow, int theDrag) { - Display display = Display.findDisplay(Thread.currentThread()); - if (display == null || display.isDisposed()) return null; - Point mouse = new Point(); - OS.GetDragMouse(theDrag, mouse, null); - int[] theRoot = new int[1]; - OS.GetRootControl(theWindow, theRoot); - int[] theControl = new int[1]; - Rect rect = new Rect(); - OS.GetWindowBounds (theWindow, (short) OS.kWindowContentRgn, rect); - CGPoint inPoint = new CGPoint(); - inPoint.x = mouse.h - rect.left; - inPoint.y = mouse.v - rect.top; - OS.HIViewGetSubviewHit(theRoot[0], inPoint, true, theControl); - if (!OS.IsControlEnabled(theControl[0])) return null; - Widget widget = display.findWidget(theControl[0]); - if (widget == null) return null; - return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); -} +//static int DragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { +// DropTarget target = FindDropTarget(theWindow, theDrag); +// if (target == null) return OS.noErr; +// return target.dragReceiveHandler(theWindow, handlerRefCon, theDrag); +//} + +//static int DragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDrag) { +// if (message == OS.kDragTrackingLeaveHandler || message == OS.kDragTrackingEnterHandler) { +// CurrentDropTarget = null; +// return OS.noErr; +// } +// DropTarget target = FindDropTarget(theWindow, theDrag); +// if (CurrentDropTarget != null) { +// if (target == null || CurrentDropTarget.control.handle != target.control.handle) { +// CurrentDropTarget.dragTrackingHandler(OS.kDragTrackingLeaveWindow, theWindow, handlerRefCon, theDrag); +// CurrentDropTarget = target; +// message = OS.kDragTrackingEnterWindow; +// } +// } else { +// CurrentDropTarget = target; +// message = OS.kDragTrackingEnterWindow; +// } +// if (target == null) return OS.noErr; +// return target.dragTrackingHandler(message, theWindow, handlerRefCon, theDrag); +//} + +//static DropTarget FindDropTarget(int theWindow, int theDrag) { +// Display display = Display.findDisplay(Thread.currentThread()); +// if (display == null || display.isDisposed()) return null; +// Point mouse = new Point(); +// OS.GetDragMouse(theDrag, mouse, null); +// int[] theRoot = new int[1]; +// OS.GetRootControl(theWindow, theRoot); +// int[] theControl = new int[1]; +// Rect rect = new Rect(); +// OS.GetWindowBounds (theWindow, (short) OS.kWindowContentRgn, rect); +// CGPoint inPoint = new CGPoint(); +// inPoint.x = mouse.h - rect.left; +// inPoint.y = mouse.v - rect.top; +// OS.HIViewGetSubviewHit(theRoot[0], inPoint, true, theControl); +// if (!OS.IsControlEnabled(theControl[0])) return null; +// Widget widget = display.findWidget(theControl[0]); +// if (widget == null) return null; +// return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); +//} /** * Adds the listener to the collection of listeners who will * be notified when a drag and drop operation is in progress, by sending @@ -332,187 +332,187 @@ protected void checkSubclass () { } } -int dragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { - updateDragOverHover(0, null); - if (keyOperation == -1) return OS.dragNotAcceptedErr; - - DNDEvent event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.detail = DND.DROP_NONE; - notifyListeners(DND.DragLeave, event); - - event = new DNDEvent(); - if (!setEventData(theDrag, event)) { - return OS.dragNotAcceptedErr; - } - - keyOperation = -1; - int allowedOperations = event.operations; - TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; - System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, event.dataTypes.length); - event.dataType = selectedDataType; - event.detail = selectedOperation; - selectedDataType = null; - selectedOperation = DND.DROP_NONE; - notifyListeners(DND.DropAccept, event); - - if (event.dataType != null) { - for (int i = 0; i < allowedDataTypes.length; i++) { - if (allowedDataTypes[i].type == event.dataType.type) { - selectedDataType = allowedDataTypes[i]; - break; - } - } - } - if (selectedDataType != null && (event.detail & allowedOperations) != 0) { - selectedOperation = event.detail; - } - if (selectedOperation == DND.DROP_NONE) { - // this was not a successful drop - return OS.dragNotAcceptedErr; - } - // ask drag source for dropped data - byte[][] data = new byte[0][]; - // locate all the items with data of the desired type - short[] numItems = new short[1]; - OS.CountDragItems(theDrag, numItems); - for (short i = 0; i < numItems[0]; i++) { - int[] theItemRef = new int[1]; - OS.GetDragItemReferenceNumber(theDrag, (short) (i+1), theItemRef); - int[] size = new int[1]; - OS.GetFlavorDataSize(theDrag, theItemRef[0], selectedDataType.type, size); - if (size[0] > 0) { - byte[] buffer = new byte[size[0]]; - OS.GetFlavorData(theDrag, theItemRef[0], selectedDataType.type, buffer, size, 0); - byte[][] newData = new byte[data.length + 1][]; - System.arraycopy(data, 0, newData, 0, data.length); - newData[data.length] = buffer; - data = newData; - } - } - // Get Data in a Java format - Object object = null; - for (int i = 0; i < transferAgents.length; i++) { - Transfer transfer = transferAgents[i]; - if (transfer != null && transfer.isSupportedType(selectedDataType)) { - selectedDataType.data = data; - object = transfer.nativeToJava(selectedDataType); - break; - } - } - - if (object == null) { - selectedOperation = DND.DROP_NONE; - } - - event.dataType = selectedDataType; - event.detail = selectedOperation; - event.data = object; - notifyListeners(DND.Drop, event); - selectedOperation = DND.DROP_NONE; - if ((allowedOperations & event.detail) == event.detail) { - selectedOperation = event.detail; - } - //notify source of action taken - int action = opToOsOp(selectedOperation); - OS.SetDragDropAction(theDrag, action); - return (selectedOperation == DND.DROP_NONE) ? OS.dragNotAcceptedErr : OS.noErr; -} - -int dragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDrag) { - - if (message == OS.kDragTrackingLeaveWindow) { - updateDragOverHover(0, null); - OS.SetThemeCursor(OS.kThemeArrowCursor); - if (keyOperation == -1) return OS.dragNotAcceptedErr; - keyOperation = -1; - - DNDEvent event = new DNDEvent(); - event.widget = this; - event.time = (int)System.currentTimeMillis(); - event.detail = DND.DROP_NONE; - notifyListeners(DND.DragLeave, event); - return OS.noErr; - } - - int oldKeyOperation = keyOperation; - - if (message == OS.kDragTrackingEnterWindow) { - selectedDataType = null; - selectedOperation = 0; - } - - DNDEvent event = new DNDEvent(); - if (!setEventData(theDrag, event)) { - keyOperation = -1; - OS.SetThemeCursor(OS.kThemeNotAllowedCursor); - return OS.dragNotAcceptedErr; - } - - int allowedOperations = event.operations; - TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; - System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length); - - switch (message) { - case OS.kDragTrackingEnterWindow: - event.type = DND.DragEnter; - break; - case OS.kDragTrackingInWindow: - if (keyOperation == oldKeyOperation) { - event.type = DND.DragOver; - event.dataType = selectedDataType; - event.detail = selectedOperation; - }else { - event.type = DND.DragOperationChanged; - event.dataType = selectedDataType; - } - break; - } - - updateDragOverHover(DRAGOVER_HYSTERESIS, event); - selectedDataType = null; - selectedOperation = DND.DROP_NONE; - notifyListeners(event.type, event); - - if (event.detail == DND.DROP_DEFAULT) { - event.detail = (allowedOperations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE; - } - - if (event.dataType != null) { - for (int i = 0; i < allowedDataTypes.length; i++) { - if (allowedDataTypes[i].type == event.dataType.type) { - selectedDataType = allowedDataTypes[i]; - break; - } - } - } - - if (selectedDataType != null && (allowedOperations & event.detail) != 0) { - selectedOperation = event.detail; - } - - OS.SetDragDropAction(theDrag, opToOsOp(selectedOperation)); - - switch (selectedOperation) { - case DND.DROP_COPY: - OS.SetThemeCursor(OS.kThemeCopyArrowCursor); - break; - case DND.DROP_LINK: - OS.SetThemeCursor(OS.kThemeAliasArrowCursor); - break; - case DND.DROP_MOVE: - OS.SetThemeCursor(OS.kThemeArrowCursor); - break; - default: - OS.SetThemeCursor(OS.kThemeNotAllowedCursor); - } - - if (message == OS.kDragTrackingEnterWindow) { - dragOverHeartbeat.run(); - } - return OS.noErr; -} +//int dragReceiveHandler(int theWindow, int handlerRefCon, int theDrag) { +// updateDragOverHover(0, null); +// if (keyOperation == -1) return OS.dragNotAcceptedErr; +// +// DNDEvent event = new DNDEvent(); +// event.widget = this; +// event.time = (int)System.currentTimeMillis(); +// event.detail = DND.DROP_NONE; +// notifyListeners(DND.DragLeave, event); +// +// event = new DNDEvent(); +// if (!setEventData(theDrag, event)) { +// return OS.dragNotAcceptedErr; +// } +// +// keyOperation = -1; +// int allowedOperations = event.operations; +// TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; +// System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, event.dataTypes.length); +// event.dataType = selectedDataType; +// event.detail = selectedOperation; +// selectedDataType = null; +// selectedOperation = DND.DROP_NONE; +// notifyListeners(DND.DropAccept, event); +// +// if (event.dataType != null) { +// for (int i = 0; i < allowedDataTypes.length; i++) { +// if (allowedDataTypes[i].type == event.dataType.type) { +// selectedDataType = allowedDataTypes[i]; +// break; +// } +// } +// } +// if (selectedDataType != null && (event.detail & allowedOperations) != 0) { +// selectedOperation = event.detail; +// } +// if (selectedOperation == DND.DROP_NONE) { +// // this was not a successful drop +// return OS.dragNotAcceptedErr; +// } +// // ask drag source for dropped data +// byte[][] data = new byte[0][]; +// // locate all the items with data of the desired type +// short[] numItems = new short[1]; +// OS.CountDragItems(theDrag, numItems); +// for (short i = 0; i < numItems[0]; i++) { +// int[] theItemRef = new int[1]; +// OS.GetDragItemReferenceNumber(theDrag, (short) (i+1), theItemRef); +// int[] size = new int[1]; +// OS.GetFlavorDataSize(theDrag, theItemRef[0], selectedDataType.type, size); +// if (size[0] > 0) { +// byte[] buffer = new byte[size[0]]; +// OS.GetFlavorData(theDrag, theItemRef[0], selectedDataType.type, buffer, size, 0); +// byte[][] newData = new byte[data.length + 1][]; +// System.arraycopy(data, 0, newData, 0, data.length); +// newData[data.length] = buffer; +// data = newData; +// } +// } +// // Get Data in a Java format +// Object object = null; +// for (int i = 0; i < transferAgents.length; i++) { +// Transfer transfer = transferAgents[i]; +// if (transfer != null && transfer.isSupportedType(selectedDataType)) { +// selectedDataType.data = data; +// object = transfer.nativeToJava(selectedDataType); +// break; +// } +// } +// +// if (object == null) { +// selectedOperation = DND.DROP_NONE; +// } +// +// event.dataType = selectedDataType; +// event.detail = selectedOperation; +// event.data = object; +// notifyListeners(DND.Drop, event); +// selectedOperation = DND.DROP_NONE; +// if ((allowedOperations & event.detail) == event.detail) { +// selectedOperation = event.detail; +// } +// //notify source of action taken +// int action = opToOsOp(selectedOperation); +// OS.SetDragDropAction(theDrag, action); +// return (selectedOperation == DND.DROP_NONE) ? OS.dragNotAcceptedErr : OS.noErr; +//} + +//int dragTrackingHandler(int message, int theWindow, int handlerRefCon, int theDrag) { +// +// if (message == OS.kDragTrackingLeaveWindow) { +// updateDragOverHover(0, null); +// OS.SetThemeCursor(OS.kThemeArrowCursor); +// if (keyOperation == -1) return OS.dragNotAcceptedErr; +// keyOperation = -1; +// +// DNDEvent event = new DNDEvent(); +// event.widget = this; +// event.time = (int)System.currentTimeMillis(); +// event.detail = DND.DROP_NONE; +// notifyListeners(DND.DragLeave, event); +// return OS.noErr; +// } +// +// int oldKeyOperation = keyOperation; +// +// if (message == OS.kDragTrackingEnterWindow) { +// selectedDataType = null; +// selectedOperation = 0; +// } +// +// DNDEvent event = new DNDEvent(); +// if (!setEventData(theDrag, event)) { +// keyOperation = -1; +// OS.SetThemeCursor(OS.kThemeNotAllowedCursor); +// return OS.dragNotAcceptedErr; +// } +// +// int allowedOperations = event.operations; +// TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; +// System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length); +// +// switch (message) { +// case OS.kDragTrackingEnterWindow: +// event.type = DND.DragEnter; +// break; +// case OS.kDragTrackingInWindow: +// if (keyOperation == oldKeyOperation) { +// event.type = DND.DragOver; +// event.dataType = selectedDataType; +// event.detail = selectedOperation; +// }else { +// event.type = DND.DragOperationChanged; +// event.dataType = selectedDataType; +// } +// break; +// } +// +// updateDragOverHover(DRAGOVER_HYSTERESIS, event); +// selectedDataType = null; +// selectedOperation = DND.DROP_NONE; +// notifyListeners(event.type, event); +// +// if (event.detail == DND.DROP_DEFAULT) { +// event.detail = (allowedOperations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE; +// } +// +// if (event.dataType != null) { +// for (int i = 0; i < allowedDataTypes.length; i++) { +// if (allowedDataTypes[i].type == event.dataType.type) { +// selectedDataType = allowedDataTypes[i]; +// break; +// } +// } +// } +// +// if (selectedDataType != null && (allowedOperations & event.detail) != 0) { +// selectedOperation = event.detail; +// } +// +// OS.SetDragDropAction(theDrag, opToOsOp(selectedOperation)); +// +// switch (selectedOperation) { +// case DND.DROP_COPY: +// OS.SetThemeCursor(OS.kThemeCopyArrowCursor); +// break; +// case DND.DROP_LINK: +// OS.SetThemeCursor(OS.kThemeAliasArrowCursor); +// break; +// case DND.DROP_MOVE: +// OS.SetThemeCursor(OS.kThemeArrowCursor); +// break; +// default: +// OS.SetThemeCursor(OS.kThemeNotAllowedCursor); +// } +// +// if (message == OS.kDragTrackingEnterWindow) { +// dragOverHeartbeat.run(); +// } +// return OS.noErr; +//} /** * Returns the Control which is registered for this DropTarget. This is the control over which the @@ -575,16 +575,16 @@ public DropTargetEffect getDropTargetEffect() { return dropEffect; } -int getOperationFromKeyState(int theDrag) { - short[] modifiers = new short[1]; - OS.GetDragModifiers(theDrag, modifiers, null, null); - boolean option = (modifiers[0] & OS.optionKey) == OS.optionKey; - boolean command = (modifiers[0] & OS.cmdKey) == OS.cmdKey; - if (option && command) return DND.DROP_LINK; - if (option) return DND.DROP_COPY; - if (command) return DND.DROP_MOVE; - return DND.DROP_DEFAULT; -} +//int getOperationFromKeyState(int theDrag) { +// short[] modifiers = new short[1]; +// OS.GetDragModifiers(theDrag, modifiers, null, null); +// boolean option = (modifiers[0] & OS.optionKey) == OS.optionKey; +// boolean command = (modifiers[0] & OS.cmdKey) == OS.cmdKey; +// if (option && command) return DND.DROP_LINK; +// if (option) return DND.DROP_COPY; +// if (command) return DND.DROP_MOVE; +// return DND.DROP_DEFAULT; +//} /** * Returns a list of the data types that can be transferred to this DropTarget. @@ -606,36 +606,36 @@ void onDispose () { control = null; } -int opToOsOp(int operation) { - int osOperation = 0; - if ((operation & DND.DROP_COPY) != 0){ - osOperation |= OS.kDragActionCopy; - } - if ((operation & DND.DROP_LINK) != 0) { - osOperation |= OS.kDragActionAlias; - } - if ((operation & DND.DROP_MOVE) != 0) { - osOperation |= OS.kDragActionMove; - } - return osOperation; -} - -int osOpToOp(int osOperation){ - int operation = 0; - if ((osOperation & OS.kDragActionCopy) != 0){ - operation |= DND.DROP_COPY; - } - if ((osOperation & OS.kDragActionAlias) != 0) { - operation |= DND.DROP_LINK; - } - if ((osOperation & OS.kDragActionMove) != 0) { - operation |= DND.DROP_MOVE; - } - if (osOperation == OS.kDragActionAll) { - operation = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; - } - return operation; -} +//int opToOsOp(int operation) { +// int osOperation = 0; +// if ((operation & DND.DROP_COPY) != 0){ +// osOperation |= OS.kDragActionCopy; +// } +// if ((operation & DND.DROP_LINK) != 0) { +// osOperation |= OS.kDragActionAlias; +// } +// if ((operation & DND.DROP_MOVE) != 0) { +// osOperation |= OS.kDragActionMove; +// } +// return osOperation; +//} + +//int osOpToOp(int osOperation){ +// int operation = 0; +// if ((osOperation & OS.kDragActionCopy) != 0){ +// operation |= DND.DROP_COPY; +// } +// if ((osOperation & OS.kDragActionAlias) != 0) { +// operation |= DND.DROP_LINK; +// } +// if ((osOperation & OS.kDragActionMove) != 0) { +// operation |= DND.DROP_MOVE; +// } +// if (osOperation == OS.kDragActionAll) { +// operation = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; +// } +// return operation; +//} /** * Removes the listener from the collection of listeners who will @@ -679,95 +679,97 @@ public void setDropTargetEffect(DropTargetEffect effect) { } boolean setEventData(int theDrag, DNDEvent event) { - if (theDrag == 0) return false; - - // get allowed operations - int style = getStyle(); - int[] outActions = new int[1]; - OS.GetDragAllowableActions(theDrag, outActions); - int operations = osOpToOp(outActions[0]) & style; - if (operations == DND.DROP_NONE) return false; - - //get current operation - int operation = getOperationFromKeyState(theDrag); - keyOperation = operation; - if (operation == DND.DROP_DEFAULT) { - if ((style & DND.DROP_DEFAULT) == 0) { - operation = (operations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE; - } - } else { - if ((operation & operations) == 0) operation = DND.DROP_NONE; - } +// if (theDrag == 0) return false; +// +// // get allowed operations +// int style = getStyle(); +// int[] outActions = new int[1]; +// OS.GetDragAllowableActions(theDrag, outActions); +// int operations = osOpToOp(outActions[0]) & style; +// if (operations == DND.DROP_NONE) return false; +// +// //get current operation +// int operation = getOperationFromKeyState(theDrag); +// keyOperation = operation; +// if (operation == DND.DROP_DEFAULT) { +// if ((style & DND.DROP_DEFAULT) == 0) { +// operation = (operations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE; +// } +// } else { +// if ((operation & operations) == 0) operation = DND.DROP_NONE; +// } +// +// // get allowed transfer types +// short[] numItems = new short[1]; +// OS.CountDragItems(theDrag, numItems); +// int[] flavors = new int[10]; +// int index = -1; +// //Get a unique list of flavors +// for (short i = 0; i < numItems[0]; i++) { +// int[] theItemRef = new int[1]; +// OS.GetDragItemReferenceNumber(theDrag, (short) (i+1), theItemRef); +// short[] numFlavors = new short[1]; +// OS.CountDragItemFlavors(theDrag, theItemRef[0], numFlavors); +// int[] theType = new int[1]; +// for (int j = 0; j < numFlavors[0]; j++) { +// theType[0] = 0; +// if (OS.GetFlavorType(theDrag, theItemRef[0], (short) (j+1), theType) == OS.noErr) { +// boolean unique = true; +// for (int k = 0; k < flavors.length; k++) { +// if (flavors[k] == theType[0]) { +// unique = false; +// break; +// } +// } +// if (unique) { +// if (index == flavors.length - 1) { +// int[] temp = new int[flavors.length + 10]; +// System.arraycopy(flavors, 0, temp, 0, flavors.length); +// flavors = temp; +// } +// flavors[++index] = theType[0]; +// } +// } +// } +// } +// if (index == -1) return false; +// +// TransferData[] dataTypes = new TransferData[index+1]; +// index = -1; +// for (int i = 0; i < dataTypes.length; i++) { +// if (flavors[i] != 0) { +// TransferData data = new TransferData(); +// data.type = flavors[i]; +// for (int j = 0; j < transferAgents.length; j++) { +// Transfer transfer = transferAgents[j]; +// if (transfer != null && transfer.isSupportedType(data)) { +// dataTypes[++index] = data; +// break; +// } +// } +// } +// } +// if (index == -1) return false; +// +// if (index < dataTypes.length - 1) { +// TransferData[] temp = new TransferData[index + 1]; +// System.arraycopy(dataTypes, 0, temp, 0, index + 1); +// dataTypes = temp; +// } +// +// Point mouse = new Point(); +// OS.GetDragMouse(theDrag, mouse, null); - // get allowed transfer types - short[] numItems = new short[1]; - OS.CountDragItems(theDrag, numItems); - int[] flavors = new int[10]; - int index = -1; - //Get a unique list of flavors - for (short i = 0; i < numItems[0]; i++) { - int[] theItemRef = new int[1]; - OS.GetDragItemReferenceNumber(theDrag, (short) (i+1), theItemRef); - short[] numFlavors = new short[1]; - OS.CountDragItemFlavors(theDrag, theItemRef[0], numFlavors); - int[] theType = new int[1]; - for (int j = 0; j < numFlavors[0]; j++) { - theType[0] = 0; - if (OS.GetFlavorType(theDrag, theItemRef[0], (short) (j+1), theType) == OS.noErr) { - boolean unique = true; - for (int k = 0; k < flavors.length; k++) { - if (flavors[k] == theType[0]) { - unique = false; - break; - } - } - if (unique) { - if (index == flavors.length - 1) { - int[] temp = new int[flavors.length + 10]; - System.arraycopy(flavors, 0, temp, 0, flavors.length); - flavors = temp; - } - flavors[++index] = theType[0]; - } - } - } - } - if (index == -1) return false; - - TransferData[] dataTypes = new TransferData[index+1]; - index = -1; - for (int i = 0; i < dataTypes.length; i++) { - if (flavors[i] != 0) { - TransferData data = new TransferData(); - data.type = flavors[i]; - for (int j = 0; j < transferAgents.length; j++) { - Transfer transfer = transferAgents[j]; - if (transfer != null && transfer.isSupportedType(data)) { - dataTypes[++index] = data; - break; - } - } - } - } - if (index == -1) return false; - - if (index < dataTypes.length - 1) { - TransferData[] temp = new TransferData[index + 1]; - System.arraycopy(dataTypes, 0, temp, 0, index + 1); - dataTypes = temp; - } - - Point mouse = new Point(); - OS.GetDragMouse(theDrag, mouse, null); + int operation = DND.DROP_NONE; event.widget = this; - event.x = mouse.h; - event.y = mouse.v; +// event.x = mouse.h; +// event.y = mouse.v; event.time = (int)System.currentTimeMillis(); event.feedback = DND.FEEDBACK_SELECT; - event.dataTypes = dataTypes; - event.dataType = dataTypes[0]; - event.operations = operations; +// event.dataTypes = dataTypes; +// event.dataType = dataTypes[0]; +// event.operations = operations; event.detail = operation; if (dropEffect != null) { event.item = dropEffect.getItem(event.x, event.y); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/FileTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/FileTransfer.java index be2dfed6c4..011ab4bac8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/FileTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/FileTransfer.java @@ -12,7 +12,8 @@ package org.eclipse.swt.dnd; import java.io.*; -import org.eclipse.swt.internal.carbon.*; + +import org.eclipse.swt.internal.cocoa.*; /** * The class <code>FileTransfer</code> provides a platform specific mechanism @@ -37,10 +38,8 @@ import org.eclipse.swt.internal.carbon.*; public class FileTransfer extends ByteArrayTransfer { static FileTransfer _instance = new FileTransfer(); - static final String HFS = "hfs "; //$NON-NLS-1$ - static final String FURL = "furl"; //$NON-NLS-1$ - static final int HFSID = registerType(HFS); - static final int FURLID = registerType(FURL); + static final String ID_NAME = getString(OS.NSFilenamesPboardType); + static final int ID = registerType(ID_NAME); FileTransfer() {} @@ -70,56 +69,14 @@ public void javaToNative(Object object, TransferData transferData) { DND.error(DND.ERROR_INVALID_DATA); } String[] files = (String[])object; - transferData.result = -1; - byte[][] data = new byte[files.length][]; - for (int i = 0; i < data.length; i++) { - File file = new File(files[i]); - boolean isDirectory = file.isDirectory(); + int length = files.length; + NSMutableArray array = NSMutableArray.arrayWithCapacity(length); + for (int i = 0; i < length; i++) { String fileName = files[i]; - char [] chars = new char [fileName.length ()]; - fileName.getChars (0, chars.length, chars, 0); - int cfstring = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length); - if (cfstring == 0) return; - try { - int url = OS.CFURLCreateWithFileSystemPath(OS.kCFAllocatorDefault, cfstring, OS.kCFURLPOSIXPathStyle, isDirectory); - if (url == 0) return; - try { - if (transferData.type == HFSID) { - byte[] fsRef = new byte[80]; - if (!OS.CFURLGetFSRef(url, fsRef)) return; - byte[] fsSpec = new byte[70]; - if (OS.FSGetCatalogInfo(fsRef, 0, null, null, fsSpec, null) != OS.noErr) return; - byte[] hfsflavor = new byte[10 + fsSpec.length]; - byte[] finfo = new byte[16]; - OS.FSpGetFInfo(fsSpec, finfo); - System.arraycopy(finfo, 0, hfsflavor, 0, 10); - System.arraycopy(fsSpec, 0, hfsflavor, 10, fsSpec.length); - data[i] = hfsflavor; - } - if (transferData.type == FURLID) { - int encoding = OS.CFStringGetSystemEncoding(); - int theData = OS.CFURLCreateData(OS.kCFAllocatorDefault, url, encoding, true); - if (theData == 0) return; - try { - int length = OS.CFDataGetLength(theData); - byte[] buffer = new byte[length]; - CFRange range = new CFRange(); - range.length = length; - OS.CFDataGetBytes(theData, range, buffer); - data[i] = buffer; - } finally { - OS.CFRelease(theData); - } - } - } finally { - OS.CFRelease(url); - } - } finally { - OS.CFRelease(cfstring); - } + NSString string = NSString.stringWith(fileName); + array.addObject(string); } - transferData.data = data; - transferData.result = 0; + transferData.data = array; } /** * This implementation of <code>nativeToJava</code> converts a platform specific @@ -134,52 +91,25 @@ public void javaToNative(Object object, TransferData transferData) { */ public Object nativeToJava(TransferData transferData) { if (!isSupportedType(transferData) || transferData.data == null) return null; - if (transferData.data.length == 0) return null; - int count = transferData.data.length; + NSArray array = (NSArray) transferData.data; + if (array.count() == 0) return null; + int count = array.count(); String[] fileNames = new String[count]; for (int i=0; i<count; i++) { - byte[] data = transferData.data[i]; - int url = 0; - if (transferData.type == HFSID) { - byte[] fsspec = new byte[data.length - 10]; - System.arraycopy(data, 10, fsspec, 0, fsspec.length); - byte[] fsRef = new byte[80]; - if (OS.FSpMakeFSRef(fsspec, fsRef) != OS.noErr) return null; - url = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault, fsRef); - if (url == 0) return null; - } - if (transferData.type == FURLID) { - int encoding = OS.kCFStringEncodingUTF8; - url = OS.CFURLCreateWithBytes(OS.kCFAllocatorDefault, data, data.length, encoding, 0); - if (url == 0) return null; - } - try { - int path = OS.CFURLCopyFileSystemPath(url, OS.kCFURLPOSIXPathStyle); - if (path == 0) return null; - try { - int length = OS.CFStringGetLength(path); - if (length == 0) return null; - char[] buffer= new char[length]; - CFRange range = new CFRange(); - range.length = length; - OS.CFStringGetCharacters(path, range, buffer); - fileNames[i] = new String(buffer); - } finally { - OS.CFRelease(path); - } - } finally { - OS.CFRelease(url); - } + NSString string = new NSString(array.objectAtIndex(i)); + char[] chars = new char[string.length()]; + string.getCharacters_(chars); + fileNames[i] = new String(chars); } return fileNames; } protected int[] getTypeIds(){ - return new int[] {FURLID, HFSID}; + return new int[] {ID}; } protected String[] getTypeNames(){ - return new String[] {FURL, HFS}; + return new String[] {ID_NAME}; } boolean checkFile(Object object) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/HTMLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/HTMLTransfer.java index f3e21ff9be..7490f885d6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/HTMLTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/HTMLTransfer.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.dnd; -import org.eclipse.swt.internal.carbon.OS; +import org.eclipse.swt.internal.cocoa.*; /** * The class <code>HTMLTransfer</code> provides a platform specific mechanism @@ -29,7 +29,7 @@ import org.eclipse.swt.internal.carbon.OS; public class HTMLTransfer extends ByteArrayTransfer { static HTMLTransfer _instance = new HTMLTransfer(); - static final String HTML = "HTML"; //$NON-NLS-1$ + static final String HTML = getString(OS.NSStringPboardType); static final int HTMLID = registerType(HTML); HTMLTransfer() {} @@ -57,15 +57,7 @@ public void javaToNative (Object object, TransferData transferData){ if (!checkHTML(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } - String string = (String)object; - int count = string.length(); - char[] chars = new char[count]; - string.getChars(0, count, chars, 0); - byte[] buffer = new byte[chars.length * 2]; - OS.memmove(buffer, chars, buffer.length); - transferData.data = new byte[1][]; - transferData.data[0] = buffer; - transferData.result = OS.noErr; + transferData.data = NSString.stringWith((String) object); } /** @@ -80,10 +72,9 @@ public void javaToNative (Object object, TransferData transferData){ */ public Object nativeToJava(TransferData transferData){ if (!isSupportedType(transferData) || transferData.data == null) return null; - if (transferData.data.length == 0 || transferData.data[0].length == 0) return null; - byte[] buffer = transferData.data[0]; - char[] chars = new char[(buffer.length + 1) / 2]; - OS.memmove(chars, buffer, buffer.length); + NSString string = (NSString) transferData.data; + char[] chars = new char[string.length()]; + string.getCharacters_(chars); return new String(chars); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ImageTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ImageTransfer.java index 06bad0898f..81511b6ba8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ImageTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/ImageTransfer.java @@ -13,7 +13,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.*; +import org.eclipse.swt.internal.cocoa.*; import org.eclipse.swt.widgets.*; /** @@ -35,9 +35,7 @@ import org.eclipse.swt.widgets.*; public class ImageTransfer extends ByteArrayTransfer { static ImageTransfer _instance = new ImageTransfer(); -static final String PICT = "PICT"; //$NON-NLS-1$ -static final String TIFF = "TIFF"; //$NON-NLS-1$ -static final int PICTID = registerType(PICT); +static final String TIFF = getString(OS.NSTIFFPboardType); static final int TIFFID = registerType(TIFF); ImageTransfer() { @@ -66,50 +64,11 @@ public void javaToNative(Object object, TransferData transferData) { if (!checkImage(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } - transferData.result = -1; - ImageData imgData = (ImageData) object; Image image = new Image(Display.getCurrent(), imgData); - int handle = image.handle; - int width = OS.CGImageGetWidth(handle); - int height = OS.CGImageGetHeight(handle); - int alphaInfo = OS.CGImageGetAlphaInfo(handle); - int bpr = OS.CGImageGetBytesPerRow(handle); - - Rect rect = new Rect(); - rect.left = 0; - rect.top = 0; - rect.right = (short) width; - rect.bottom = (short) height; - - int[] gWorld = new int[1]; - int format = OS.k24RGBPixelFormat; - if (alphaInfo != OS.kCGImageAlphaNoneSkipFirst) { - format = OS.k32ARGBPixelFormat; - } - OS.NewGWorldFromPtr(gWorld, format, rect, 0, 0, 0, image.data, bpr); - int[] curPort = new int[1]; - int[] curGWorld = new int[1]; - OS.GetGWorld(curPort, curGWorld); - OS.SetGWorld(gWorld[0], curGWorld[0]); - int pictHandle = OS.OpenPicture(rect); - int portBitMap = OS.GetPortBitMapForCopyBits(gWorld[0]); - OS.CopyBits(portBitMap, portBitMap, rect, rect, (short) OS.srcCopy, 0); - OS.ClosePicture(); - OS.SetGWorld(curPort[0], curGWorld[0]); - OS.DisposeGWorld(gWorld[0]); - int length = OS.GetHandleSize(pictHandle); - OS.HLock(pictHandle); - int[] buffer = new int[1]; - OS.memmove(buffer, pictHandle, 4); - byte[] pictData = new byte[length]; - OS.memmove(pictData, buffer[0], length); - OS.HUnlock(pictHandle); - OS.KillPicture(pictHandle); + NSImage handle = image.handle; + transferData.data = handle.TIFFRepresentation(); image.dispose(); - - transferData.data = new byte[][] { pictData }; - transferData.result = OS.noErr; } /** @@ -123,75 +82,24 @@ public void javaToNative(Object object, TransferData transferData) { * @see Transfer#javaToNative */ public Object nativeToJava(TransferData transferData) { - if (!isSupportedType(transferData) || transferData.data == null) - return null; - if (transferData.data.length == 0) - return null; - byte[] dataArr = transferData.data[0]; - int size = dataArr.length; - int pictPtr = OS.NewPtr(size); - OS.memmove(pictPtr, dataArr, size); - int dataProvider = OS.CGDataProviderCreateWithData(0, pictPtr, size, 0); - if (dataProvider != 0) { - int pictDataRef = OS.QDPictCreateWithProvider(dataProvider); - // get bounds for the image - CGRect rect = new CGRect(); - OS.QDPictGetBounds(pictDataRef, rect); - int width = (int) rect.width; - int height = (int) rect.height; - - /* Create the image */ - int bpr = width * 4; - int dataSize = height * bpr; - int data = OS.NewPtr(dataSize); - if (data == 0) - SWT.error(SWT.ERROR_NO_HANDLES); - int provider = OS - .CGDataProviderCreateWithData(0, data, dataSize, 0); - if (provider == 0) { - OS.DisposePtr(data); - SWT.error(SWT.ERROR_NO_HANDLES); - } - int colorspace = OS.CGColorSpaceCreateDeviceRGB(); - if (colorspace == 0) - SWT.error(SWT.ERROR_NO_HANDLES); - int handle = OS.CGImageCreate(width, height, 8, 32, bpr, - colorspace, OS.kCGImageAlphaNoneSkipFirst, provider, null, - true, 0); - OS.CGDataProviderRelease(provider); - if (handle == 0) { - OS.DisposePtr(data); - SWT.error(SWT.ERROR_NO_HANDLES); - } - int bpc = OS.CGImageGetBitsPerComponent(handle); - int context = OS.CGBitmapContextCreate(data, width, height, bpc, - bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst); - if (context == 0) { - OS.CGImageRelease(handle); - OS.DisposePtr(data); - SWT.error(SWT.ERROR_NO_HANDLES); - } - int status = OS.QDPictDrawToCGContext(context, rect, pictDataRef); - ImageData imgData = null; - if (status == 0) { - Image image = Image.carbon_new(Display.getCurrent(), - SWT.BITMAP, handle, data); - imgData = image.getImageData(); - image.dispose(); - } - OS.CGContextRelease(context); - OS.QDPictRelease(pictDataRef); - return imgData; - } - return null; + if (!isSupportedType(transferData) || transferData.data == null) return null; + NSData data = (NSData) transferData.data; + if (data.length() == 0) return null; + NSImage nsImage = (NSImage) new NSImage().alloc(); + nsImage.initWithData(data); + //TODO: Image representation wrong??? + Image image = Image.cocoa_new(Display.getCurrent(), SWT.BITMAP, nsImage); + ImageData imageData = image.getImageData(); + image.dispose(); + return imageData; } protected int[] getTypeIds() { - return new int[] { PICTID }; + return new int[] { TIFFID }; } protected String[] getTypeNames() { - return new String[] { PICT }; + return new String[] { TIFF }; } boolean checkImage(Object object) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/RTFTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/RTFTransfer.java index b276243757..f1a1100570 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/RTFTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/RTFTransfer.java @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.dnd; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.CFRange; +import org.eclipse.swt.internal.cocoa.*; /** * The class <code>RTFTransfer</code> provides a platform specific mechanism @@ -30,7 +29,7 @@ import org.eclipse.swt.internal.carbon.CFRange; public class RTFTransfer extends ByteArrayTransfer { static RTFTransfer _instance = new RTFTransfer(); - static final String RTF = "RTF "; //$NON-NLS-1$ + static final String RTF = getString(OS.NSRTFPboardType); static final int RTFID = registerType(RTF); RTFTransfer() {} @@ -58,29 +57,7 @@ public void javaToNative (Object object, TransferData transferData){ if (!checkRTF(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } - transferData.result = -1; - String string = (String)object; - int count = string.length(); - char[] chars = new char[count]; - string.getChars(0, count, chars, 0); - int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, count); - if (cfstring == 0) return; - try { - CFRange range = new CFRange(); - range.length = chars.length; - int encoding = OS.CFStringGetSystemEncoding(); - int[] size = new int[1]; - int numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, null, 0, size); - if (numChars == 0 || size[0] == 0) return; - byte[] buffer = new byte[size[0]]; - numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, buffer, size [0], size); - if (numChars == 0) return; - transferData.data = new byte[1][]; - transferData.data[0] = buffer; - transferData.result = 0; - } finally { - OS.CFRelease(cfstring); - } + transferData.data = NSString.stringWith((String) object); } /** @@ -95,22 +72,10 @@ public void javaToNative (Object object, TransferData transferData){ */ public Object nativeToJava(TransferData transferData){ if (!isSupportedType(transferData) || transferData.data == null) return null; - if (transferData.data.length == 0 || transferData.data[0].length == 0) return null; - byte[] buffer = transferData.data[0]; - int encoding = OS.CFStringGetSystemEncoding(); - int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true); - if (cfstring == 0) return null; - try { - int length = OS.CFStringGetLength(cfstring); - if (length == 0) return null; - char[] chars = new char[length]; - CFRange range = new CFRange(); - range.length = length; - OS.CFStringGetCharacters(cfstring, range, chars); - return new String(chars); - } finally { - OS.CFRelease(cfstring); - } + NSString string = (NSString) transferData.data; + char[] chars = new char[string.length()]; + string.getCharacters_(chars); + return new String(chars); } protected int[] getTypeIds() { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TableDropTargetEffect.java index bcf348ded6..3e258ebe62 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TableDropTargetEffect.java @@ -13,8 +13,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.Callback; -import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; -import org.eclipse.swt.internal.carbon.OS; +import org.eclipse.swt.internal.cocoa.*; import org.eclipse.swt.widgets.*; /** @@ -52,29 +51,29 @@ public class TableDropTargetEffect extends DropTargetEffect { TableItem scrollItem; long scrollBeginTime; - DataBrowserCallbacks callbacks = null; +// DataBrowserCallbacks callbacks = null; - static Callback AcceptDragProc; - static { - AcceptDragProc = new Callback(TableDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ - int acceptDragProc = AcceptDragProc.getAddress(); - if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - } +// static Callback AcceptDragProc; +// static { +// AcceptDragProc = new Callback(TableDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ +// int acceptDragProc = AcceptDragProc.getAddress(); +// if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); +// } - static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { - DropTarget target = FindDropTarget(theControl, theDrag); - if (target == null) return 0; - return (target.feedback & DND.FEEDBACK_SELECT) != 0 ? 1 : 0; - } +// static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { +// DropTarget target = FindDropTarget(theControl, theDrag); +// if (target == null) return 0; +// return (target.feedback & DND.FEEDBACK_SELECT) != 0 ? 1 : 0; +// } - static DropTarget FindDropTarget(int theControl, int theDrag) { - if (theControl == 0) return null; - Display display = Display.findDisplay(Thread.currentThread()); - if (display == null || display.isDisposed()) return null; - Widget widget = display.findWidget(theControl); - if (widget == null) return null; - return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); - } +// static DropTarget FindDropTarget(int theControl, int theDrag) { +// if (theControl == 0) return null; +// Display display = Display.findDisplay(Thread.currentThread()); +// if (display == null || display.isDisposed()) return null; +// Widget widget = display.findWidget(theControl); +// if (widget == null) return null; +// return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); +// } /** * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified @@ -108,13 +107,13 @@ public class TableDropTargetEffect extends DropTargetEffect { * @see DropTargetEvent */ public void dragEnter(DropTargetEvent event) { - if (callbacks == null) { - Table table = (Table) control; - DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); - OS.GetDataBrowserCallbacks (table.handle, callbacks); - callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); - OS.SetDataBrowserCallbacks(table.handle, callbacks); - } +// if (callbacks == null) { +// Table table = (Table) control; +// DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); +// OS.GetDataBrowserCallbacks (table.handle, callbacks); +// callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); +// OS.SetDataBrowserCallbacks(table.handle, callbacks); +// } scrollBeginTime = 0; scrollItem = null; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TextTransfer.java index 479d6ce7fb..5bd978141c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TextTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TextTransfer.java @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.dnd; -import org.eclipse.swt.internal.carbon.CFRange; -import org.eclipse.swt.internal.carbon.OS; +import org.eclipse.swt.internal.cocoa.*; /** * The class <code>TextTransfer</code> provides a platform specific mechanism @@ -30,10 +29,9 @@ import org.eclipse.swt.internal.carbon.OS; public class TextTransfer extends ByteArrayTransfer { static TextTransfer _instance = new TextTransfer(); - static final String TEXT = "TEXT"; //$NON-NLS-1$ - static final String UTEXT = "utxt"; //$NON-NLS-1$ - static final int TEXTID = OS.kScrapFlavorTypeText; - static final int UTEXTID = OS.kScrapFlavorTypeUnicode; + + static final String ID_NAME = getString(OS.NSStringPboardType); + static final int ID = registerType(ID_NAME); TextTransfer() {} @@ -60,42 +58,7 @@ public void javaToNative (Object object, TransferData transferData) { if (!checkText(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } - String string = (String)object; - char[] chars = new char[string.length()]; - string.getChars (0, chars.length, chars, 0); - transferData.result = -1; - switch (transferData.type) { - case TEXTID: { - int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, chars.length); - if (cfstring == 0) return; - byte[] buffer = null; - try { - CFRange range = new CFRange(); - range.length = chars.length; - int encoding = OS.CFStringGetSystemEncoding(); - int[] size = new int[1]; - int numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, null, 0, size); - if (numChars == 0) return; - buffer = new byte[size[0]]; - numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, buffer, size [0], size); - if (numChars == 0) return; - } finally { - OS.CFRelease(cfstring); - } - transferData.data = new byte[1][]; - transferData.data[0] = buffer; - transferData.result = OS.noErr; - break; - } - case UTEXTID: { - byte[] buffer = new byte[chars.length * 2]; - OS.memmove(buffer, chars, buffer.length); - transferData.data = new byte[1][]; - transferData.data[0] = buffer; - transferData.result = OS.noErr; - break; - } - } + transferData.data = NSString.stringWith((String) object); } /** @@ -109,40 +72,18 @@ public void javaToNative (Object object, TransferData transferData) { */ public Object nativeToJava(TransferData transferData){ if (!isSupportedType(transferData) || transferData.data == null) return null; - if (transferData.data.length == 0 || transferData.data[0].length == 0) return null; - byte[] buffer = transferData.data[0]; - switch (transferData.type) { - case TEXTID: { - int encoding = OS.CFStringGetSystemEncoding(); - int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true); - if (cfstring == 0) return null; - try { - int length = OS.CFStringGetLength(cfstring); - if (length == 0) return null; - char[] chars = new char[length]; - CFRange range = new CFRange(); - range.length = length; - OS.CFStringGetCharacters(cfstring, range, chars); - return new String(chars); - } finally { - OS.CFRelease(cfstring); - } - } - case UTEXTID: { - char[] chars = new char[(buffer.length + 1) / 2]; - OS.memmove(chars, buffer, buffer.length); - return new String(chars); - } - } - return null; + NSString string = (NSString) transferData.data; + char[] chars = new char[string.length()]; + string.getCharacters_(chars); + return new String(chars); } protected int[] getTypeIds() { - return new int[] {UTEXTID, TEXTID}; + return new int[] {ID}; } protected String[] getTypeNames() { - return new String[] {UTEXT, TEXT}; + return new String[] {ID_NAME}; } boolean checkText(Object object) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Transfer.java index 1e883da81e..aca866334d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Transfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/Transfer.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.dnd; +import org.eclipse.swt.internal.cocoa.*; + /** * <code>Transfer</code> provides a mechanism for converting between a java @@ -27,7 +29,16 @@ package org.eclipse.swt.dnd; * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public abstract class Transfer { - + +static String[] types = new String[4]; +static int typeCount; + +static String getString (NSString str) { + char[] chars = new char[str.length()]; + str.getCharacters_(chars); + return new String(chars); +} + /** * Returns a list of the platform specific data types that can be converted using * this transfer agent. @@ -131,15 +142,25 @@ abstract protected Object nativeToJava(TransferData transferData); * @return the unique identifier associated with this data type */ public static int registerType(String formatName) { - int length = formatName.length(); - // TODO - hashcode may not be unique - need another way - if (length > 4) return formatName.hashCode(); - int type = 0; - if (length > 0) type |= (formatName.charAt(0) & 0xff) << 24; - if (length > 1) type |= (formatName.charAt(1) & 0xff) << 16; - if (length > 2) type |= (formatName.charAt(2) & 0xff) << 8; - if (length > 3) type |= formatName.charAt(3) & 0xff; - return type; + for (int i = 0; i < typeCount; i++) { + String type = types[i]; + if (type != null && formatName.equals(type)) { + return i; + } + } + if (typeCount + 1 == types.length) { // types[0] is null + String[] newTypes = new String[types.length + 4]; + System.arraycopy(types, 0, newTypes, 0, types.length); + types = newTypes; + } + types[++typeCount] = formatName; + return typeCount; +} + +static String[] registeredTypes() { + String[] result = new String[typeCount]; + System.arraycopy(types, 1, result, 0, typeCount); + return result; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TransferData.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TransferData.java index 8fddd9f84d..b573eeabb1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TransferData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TransferData.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.dnd; +import org.eclipse.swt.internal.cocoa.*; + /** * The <code>TransferData</code> class is a platform specific data structure for @@ -38,7 +40,7 @@ public class TransferData { * platforms and should never be accessed from application code. * </p> */ - public int type; + public String type; /** * The data being transferred. @@ -51,21 +53,6 @@ public class TransferData { * platforms and should never be accessed from application code. * </p> */ - public byte[][] data; - - /** - * The result field contains the result of converting a - * java data type into a platform specific value. - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - * <p>The value of result is 1 if the conversion was successful. - * The value of result is 0 if the conversion failed.</p> - */ - public int result; + public NSObject data; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TreeDropTargetEffect.java index bb1baa2789..14e9337419 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TreeDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/TreeDropTargetEffect.java @@ -13,8 +13,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.Callback; -import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; -import org.eclipse.swt.internal.carbon.OS; +import org.eclipse.swt.internal.cocoa.*; import org.eclipse.swt.widgets.*; /** @@ -66,33 +65,33 @@ public class TreeDropTargetEffect extends DropTargetEffect { TreeItem expandItem; long expandBeginTime; - DataBrowserCallbacks callbacks = null; +// DataBrowserCallbacks callbacks = null; int acceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { return (currentEffect & DND.FEEDBACK_SELECT) != 0 ? 1 : 0; } - static Callback AcceptDragProc; - static { - AcceptDragProc = new Callback(TreeDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ - int acceptDragProc = AcceptDragProc.getAddress(); - if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - } +// static Callback AcceptDragProc; +// static { +// AcceptDragProc = new Callback(TreeDropTargetEffect.class, "AcceptDragProc", 5); //$NON-NLS-1$ +// int acceptDragProc = AcceptDragProc.getAddress(); +// if (acceptDragProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); +// } - static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { - DropTarget target = FindDropTarget(theControl, theDrag); - if (target == null) return 0; - return (target.feedback & DND.FEEDBACK_SELECT) != 0 ? 1 : 0; - } +// static int AcceptDragProc(int theControl, int itemID, int property, int theRect, int theDrag) { +// DropTarget target = FindDropTarget(theControl, theDrag); +// if (target == null) return 0; +// return (target.feedback & DND.FEEDBACK_SELECT) != 0 ? 1 : 0; +// } - static DropTarget FindDropTarget(int theControl, int theDrag) { - if (theControl == 0) return null; - Display display = Display.findDisplay(Thread.currentThread()); - if (display == null || display.isDisposed()) return null; - Widget widget = display.findWidget(theControl); - if (widget == null) return null; - return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); - } +// static DropTarget FindDropTarget(int theControl, int theDrag) { +// if (theControl == 0) return null; +// Display display = Display.findDisplay(Thread.currentThread()); +// if (display == null || display.isDisposed()) return null; +// Widget widget = display.findWidget(theControl); +// if (widget == null) return null; +// return (DropTarget)widget.getData(DND.DROP_TARGET_KEY); +// } /** * Creates a new <code>TreeDropTargetEffect</code> to handle the drag under effect on the specified @@ -126,13 +125,13 @@ public class TreeDropTargetEffect extends DropTargetEffect { * @see DropTargetEvent */ public void dragEnter(DropTargetEvent event) { - if (callbacks == null) { - Tree table = (Tree) control; - DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); - OS.GetDataBrowserCallbacks (table.handle, callbacks); - callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); - OS.SetDataBrowserCallbacks(table.handle, callbacks); - } +// if (callbacks == null) { +// Tree table = (Tree) control; +// DataBrowserCallbacks callbacks = new DataBrowserCallbacks (); +// OS.GetDataBrowserCallbacks (table.handle, callbacks); +// callbacks.v1_acceptDragCallback = AcceptDragProc.getAddress(); +// OS.SetDataBrowserCallbacks(table.handle, callbacks); +// } insertItem = null; expandBeginTime = 0; expandItem = null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/URLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/URLTransfer.java index 01c4161f27..6e9a81af26 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/URLTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/URLTransfer.java @@ -1,4 +1,4 @@ -/*******************************************************************************
* Copyright (c) 20007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.dnd;
import org.eclipse.swt.internal.carbon.*;
/** +/*******************************************************************************
* Copyright (c) 20007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.dnd;
import org.eclipse.swt.internal.cocoa.*;
/** * The class <code>URLTransfer</code> provides a platform specific mechanism * for converting text in URL format represented as a java <code>String</code> * to a platform specific representation of the data and vice versa. The string @@ -11,7 +11,7 @@ * </code></pre> * * @see Transfer - */
public class URLTransfer extends ByteArrayTransfer {
static URLTransfer _instance = new URLTransfer();
static final String URL = "url "; //$NON-NLS-1$
static final int URL_ID = registerType(URL);
static final String URLN = "urln"; //$NON-NLS-1$
static final int URLN_ID = registerType(URLN);
private URLTransfer() {}
/** + */
public class URLTransfer extends ByteArrayTransfer {
static URLTransfer _instance = new URLTransfer();
static final String URL = "url "; //$NON-NLS-1$
static final int URL_ID = registerType(URL);
private URLTransfer() {}
/** * Returns the singleton instance of the URLTransfer class. * * @return the singleton instance of the URLTransfer class @@ -24,7 +24,7 @@ * be filled in on return with the platform specific format of the data * * @see Transfer#nativeToJava - */
public void javaToNative (Object object, TransferData transferData){
if (!checkURL(object) || !isSupportedType(transferData)) {
DND.error(DND.ERROR_INVALID_DATA);
}
transferData.result = -1;
String url = (String)object;
int count = url.length();
char[] chars = new char[count];
url.getChars(0, count, chars, 0);
int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, count);
if (cfstring == 0) return;
try {
CFRange range = new CFRange();
range.length = chars.length;
int encoding = OS.CFStringGetSystemEncoding();
int[] size = new int[1];
int numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, null, 0, size);
if (numChars == 0 || size[0] == 0) return;
byte[] buffer = new byte[size[0]];
numChars = OS.CFStringGetBytes(cfstring, range, encoding, (byte)'?', true, buffer, size [0], size);
if (numChars == 0) return;
transferData.data = new byte[][] {buffer};
transferData.result = 0;
} finally {
OS.CFRelease(cfstring);
}
}
/** + */
public void javaToNative (Object object, TransferData transferData){
if (!checkURL(object) || !isSupportedType(transferData)) {
DND.error(DND.ERROR_INVALID_DATA);
}
String url = (String)object;
NSString nsString = NSString.stringWith(url);
transferData.data = NSURL.static_URLWithString_(nsString);
}
/** * This implementation of <code>nativeToJava</code> converts a platform * specific representation of a URL to a java <code>String</code>. * @@ -33,4 +33,4 @@ * otherwise null * * @see Transfer#javaToNative - */
public Object nativeToJava(TransferData transferData){
if (!isSupportedType(transferData) || transferData.data == null) return null;
if (transferData.data.length == 0) return null;
byte[] buffer = transferData.data[0];
int encoding = OS.CFStringGetSystemEncoding();
int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true);
if (cfstring == 0) return null;
try {
int length = OS.CFStringGetLength(cfstring);
if (length == 0) return null;
char[] chars = new char[length];
CFRange range = new CFRange();
range.length = length;
OS.CFStringGetCharacters(cfstring, range, chars);
return new String(chars);
} finally {
OS.CFRelease(cfstring);
}
}
protected int[] getTypeIds(){
return new int[] {URL_ID, URLN_ID};
}
protected String[] getTypeNames(){
return new String[] {URL, URLN};
}
boolean checkURL(Object object) {
return object != null && (object instanceof String) && ((String)object).length() > 0;
}
protected boolean validate(Object object) {
return checkURL(object);
}
}
\ No newline at end of file + */
public Object nativeToJava(TransferData transferData){
if (!isSupportedType(transferData) || transferData.data == null) return null;
NSURL nsUrl = (NSURL) transferData.data;
NSString nsString = nsUrl.absoluteString();
return getString(nsString);
}
protected int[] getTypeIds(){
return new int[] {URL_ID};
}
protected String[] getTypeNames(){
return new String[] {URL};
}
boolean checkURL(Object object) {
return object != null && (object instanceof String) && ((String)object).length() > 0;
}
protected boolean validate(Object object) {
return checkURL(object);
}
}
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c index 0d9ab14fe8..14ae9aba0b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c @@ -408,6 +408,18 @@ JNIEXPORT jint JNICALL OS_NATIVE(NSFileTypeForHFSTypeCode) } #endif +#ifndef NO_NSFilenamesPboardType +JNIEXPORT jint JNICALL OS_NATIVE(NSFilenamesPboardType) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, NSFilenamesPboardType_FUNC); + rc = (jint)NSFilenamesPboardType; + OS_NATIVE_EXIT(env, that, NSFilenamesPboardType_FUNC); + return rc; +} +#endif + #ifndef NO_NSFontAttributeName JNIEXPORT jint JNICALL OS_NATIVE(NSFontAttributeName) (JNIEnv *env, jclass that) @@ -456,6 +468,18 @@ JNIEXPORT jint JNICALL OS_NATIVE(NSParagraphStyleAttributeName) } #endif +#ifndef NO_NSRTFPboardType +JNIEXPORT jint JNICALL OS_NATIVE(NSRTFPboardType) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, NSRTFPboardType_FUNC); + rc = (jint)NSRTFPboardType; + OS_NATIVE_EXIT(env, that, NSRTFPboardType_FUNC); + return rc; +} +#endif + #ifndef NO_NSStrikethroughColorAttributeName JNIEXPORT jint JNICALL OS_NATIVE(NSStrikethroughColorAttributeName) (JNIEnv *env, jclass that) @@ -492,6 +516,30 @@ JNIEXPORT jint JNICALL OS_NATIVE(NSStringPboardType) } #endif +#ifndef NO_NSTIFFPboardType +JNIEXPORT jint JNICALL OS_NATIVE(NSTIFFPboardType) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, NSTIFFPboardType_FUNC); + rc = (jint)NSTIFFPboardType; + OS_NATIVE_EXIT(env, that, NSTIFFPboardType_FUNC); + return rc; +} +#endif + +#ifndef NO_NSURLPboardType +JNIEXPORT jint JNICALL OS_NATIVE(NSURLPboardType) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, NSURLPboardType_FUNC); + rc = (jint)NSURLPboardType; + OS_NATIVE_EXIT(env, that, NSURLPboardType_FUNC); + return rc; +} +#endif + #ifndef NO_NSUnderlineColorAttributeName JNIEXPORT jint JNICALL OS_NATIVE(NSUnderlineColorAttributeName) (JNIEnv *env, jclass that) @@ -3554,6 +3602,38 @@ JNIEXPORT jint JNICALL OS_NATIVE(objc_1msgSend__IIZZ) } #endif +#ifndef NO_objc_1msgSend__II_3B +JNIEXPORT jint JNICALL OS_NATIVE(objc_1msgSend__II_3B) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jbyteArray arg2) +{ + jbyte *lparg2=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, objc_1msgSend__II_3B_FUNC); + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)((jint (*)(id, SEL, jbyte *))objc_msgSend)((id)arg0, (SEL)arg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0); + OS_NATIVE_EXIT(env, that, objc_1msgSend__II_3B_FUNC); + return rc; +} +#endif + +#ifndef NO_objc_1msgSend__II_3BI +JNIEXPORT jint JNICALL OS_NATIVE(objc_1msgSend__II_3BI) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jbyteArray arg2, jint arg3) +{ + jbyte *lparg2=NULL; + jint rc = 0; + OS_NATIVE_ENTER(env, that, objc_1msgSend__II_3BI_FUNC); + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)((jint (*)(id, SEL, jbyte *, jint))objc_msgSend)((id)arg0, (SEL)arg1, lparg2, arg3); +fail: + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0); + OS_NATIVE_EXIT(env, that, objc_1msgSend__II_3BI_FUNC); + return rc; +} +#endif + #ifndef NO_objc_1msgSend__II_3C JNIEXPORT jint JNICALL OS_NATIVE(objc_1msgSend__II_3C) (JNIEnv *env, jclass that, jint arg0, jint arg1, jcharArray arg2) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c index 97578e6b4a..28da71661c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 331; -int OS_nativeFunctionCallCount[331]; +int OS_nativeFunctionCount = 337; +int OS_nativeFunctionCallCount[337]; char * OS_nativeFunctionNames[] = { "CGWarpMouseCursorPosition", "CloseRgn", @@ -40,14 +40,18 @@ char * OS_nativeFunctionNames[] = { "NSDeviceResolution", "NSErrorFailingURLStringKey", "NSFileTypeForHFSTypeCode", + "NSFilenamesPboardType", "NSFontAttributeName", "NSForegroundColorAttributeName", "NSIntersectionRect", "NSLinkAttributeName", "NSParagraphStyleAttributeName", + "NSRTFPboardType", "NSStrikethroughColorAttributeName", "NSStrikethroughStyleAttributeName", "NSStringPboardType", + "NSTIFFPboardType", + "NSURLPboardType", "NSUnderlineColorAttributeName", "NSUnderlineStyleAttributeName", "NewGlobalRef", @@ -241,6 +245,8 @@ char * OS_nativeFunctionNames[] = { "objc_1msgSend__IIZLorg_eclipse_swt_internal_cocoa_NSRect_2", "objc_1msgSend__IIZLorg_eclipse_swt_internal_cocoa_NSRect_2I", "objc_1msgSend__IIZZ", + "objc_1msgSend__II_3B", + "objc_1msgSend__II_3BI", "objc_1msgSend__II_3C", "objc_1msgSend__II_3CI", "objc_1msgSend__II_3CLorg_eclipse_swt_internal_cocoa_NSRange_2", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h index 1b2905f0eb..b408bb1162 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h @@ -48,14 +48,18 @@ typedef enum { NSDeviceResolution_FUNC, NSErrorFailingURLStringKey_FUNC, NSFileTypeForHFSTypeCode_FUNC, + NSFilenamesPboardType_FUNC, NSFontAttributeName_FUNC, NSForegroundColorAttributeName_FUNC, NSIntersectionRect_FUNC, NSLinkAttributeName_FUNC, NSParagraphStyleAttributeName_FUNC, + NSRTFPboardType_FUNC, NSStrikethroughColorAttributeName_FUNC, NSStrikethroughStyleAttributeName_FUNC, NSStringPboardType_FUNC, + NSTIFFPboardType_FUNC, + NSURLPboardType_FUNC, NSUnderlineColorAttributeName_FUNC, NSUnderlineStyleAttributeName_FUNC, NewGlobalRef_FUNC, @@ -249,6 +253,8 @@ typedef enum { objc_1msgSend__IIZLorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC, objc_1msgSend__IIZLorg_eclipse_swt_internal_cocoa_NSRect_2I_FUNC, objc_1msgSend__IIZZ_FUNC, + objc_1msgSend__II_3B_FUNC, + objc_1msgSend__II_3BI_FUNC, objc_1msgSend__II_3C_FUNC, objc_1msgSend__II_3CI_FUNC, objc_1msgSend__II_3CLorg_eclipse_swt_internal_cocoa_NSRange_2_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSArray.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSArray.java index f49f88e349..0941b10350 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSArray.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSArray.java @@ -58,9 +58,9 @@ public static id arrayWithContentsOfURL(NSURL url) { return result != 0 ? new id(result) : null; } -public static id arrayWithObject(id anObject) { +public static NSArray arrayWithObject(id anObject) { int result = OS.objc_msgSend(OS.class_NSArray, OS.sel_arrayWithObject_1, anObject != null ? anObject.id : 0); - return result != 0 ? new id(result) : null; + return result != 0 ? new NSArray(result) : null; } public static id static_arrayWithObjects_(id arrayWithObjects) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSData.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSData.java index 980252d924..48302c5ed6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSData.java @@ -29,9 +29,14 @@ public static id data() { return result != 0 ? new id(result) : null; } -public static id dataWithBytes(int bytes, int length) { +public static NSData dataWithBytes(int bytes, int length) { int result = OS.objc_msgSend(OS.class_NSData, OS.sel_dataWithBytes_1length_1, bytes, length); - return result != 0 ? new id(result) : null; + return result != 0 ? new NSData(result) : null; +} + +public static NSData dataWithBytes(byte[] bytes, int length) { + int result = OS.objc_msgSend(OS.class_NSData, OS.sel_dataWithBytes_1length_1, bytes, length); + return result != 0 ? new NSData(result) : null; } public static id static_dataWithBytesNoCopy_length_(int bytes, int length) { @@ -83,6 +88,10 @@ public void getBytes_(int buffer) { OS.objc_msgSend(this.id, OS.sel_getBytes_1, buffer); } +public void getBytes_(byte[] buffer) { + OS.objc_msgSend(this.id, OS.sel_getBytes_1, buffer); +} + public void getBytes_length_(int buffer, int length) { OS.objc_msgSend(this.id, OS.sel_getBytes_1length_1, buffer, length); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMutableArray.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMutableArray.java index 7f13945d7b..71da7786c6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMutableArray.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMutableArray.java @@ -28,9 +28,9 @@ public void addObjectsFromArray(NSArray otherArray) { OS.objc_msgSend(this.id, OS.sel_addObjectsFromArray_1, otherArray != null ? otherArray.id : 0); } -public static id arrayWithCapacity(int numItems) { +public static NSMutableArray arrayWithCapacity(int numItems) { int result = OS.objc_msgSend(OS.class_NSMutableArray, OS.sel_arrayWithCapacity_1, numItems); - return result != 0 ? new id(result) : null; + return result != 0 ? new NSMutableArray(result) : null; } public void exchangeObjectAtIndex(int idx1, int idx2) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index 2eab0dce76..cc281e9dbb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -95,6 +95,7 @@ public static final native int object_setInstanceVariable(int obj, String name, public static final native int sel_registerName(String selectorName); +public static final native int objc_msgSend(int id, int sel, byte[] arg0, int arg1); public static final native int objc_msgSend(int id, int sel, char[] arg0); public static final native int objc_msgSend(int id, int sel, char[] arg0, int arg1); public static final native int objc_msgSend(int id, int sel, float[] arg0, int arg1, float arg2); @@ -123,6 +124,7 @@ public static final native int objc_msgSend(int id, int sel, int arg0, int arg1, public static final native void objc_msgSend_stret(NSSize result, int id, int sel, NSRect arg0); public static final native int objc_msgSend(int id, int sel, NSPoint arg0, NSRange arg1); public static final native int objc_msgSend(int id, int sel, int arg0); +public static final native int objc_msgSend(int id, int sel, byte[] arg0); public static final native int objc_msgSend(int id, int sel, NSRect arg0, NSRect arg1, int arg2, float arg3); public static final native int objc_msgSend(int id, int sel, NSRange arg0, NSRange arg1); public static final native int objc_msgSend(int id, int sel, NSPoint arg0, NSRect arg1, float arg2); @@ -9403,7 +9405,8 @@ public static final native int NSDeviceResolution(); //public static final native int NSExcludedKeysBinding(); //public static final native int NSExpansionAttributeName(); //public static final native int NSFileContentsPboardType(); -//public static final native int NSFilenamesPboardType(); +public static final NSString NSFilenamesPboardType = new NSString(NSFilenamesPboardType()); +public static final native int NSFilenamesPboardType(); //public static final native int NSFilesPromisePboardType(); //public static final native int NSFilesystemFileType(); //public static final native int NSFilterPredicateBinding(); @@ -9659,7 +9662,8 @@ public static final native int NSParagraphStyleAttributeName(); //public static final native int NSPrintingCommunicationException(); //public static final native int NSRTFDPboardType(); //public static final native int NSRTFDTextDocumentType(); -//public static final native int NSRTFPboardType(); +public static final NSString NSRTFPboardType = new NSString(NSRTFPboardType()); +public static final native int NSRTFPboardType(); //public static final native int NSRTFPropertyStackOverflowException(); //public static final native int NSRTFTextDocumentType(); //public static final native int NSRaisesForNotApplicableKeysBindingOption(); @@ -9743,6 +9747,7 @@ public static final native int NSParagraphStyleAttributeName(); //public static final native int NSSplitViewWillResizeSubviewsNotification(); public static final native int NSStrikethroughColorAttributeName(); public static final native int NSStrikethroughStyleAttributeName(); +public static final NSString NSStringPboardType = new NSString(NSStringPboardType()); public static final native int NSStringPboardType(); //public static final native int NSStrokeColorAttributeName(); //public static final native int NSStrokeWidthAttributeName(); @@ -9750,7 +9755,8 @@ public static final native int NSStringPboardType(); //public static final native int NSSuperscriptAttributeName(); //public static final native int NSSystemColorsDidChangeNotification(); //public static final native int NSTIFFException(); -//public static final native int NSTIFFPboardType(); +public static final NSString NSTIFFPboardType = new NSString(NSTIFFPboardType()); +public static final native int NSTIFFPboardType(); //public static final native int NSTabColumnTerminatorsAttributeName(); //public static final native int NSTableViewColumnDidMoveNotification(); //public static final native int NSTableViewColumnDidResizeNotification(); @@ -9791,7 +9797,8 @@ public static final native int NSStringPboardType(); //public static final native int NSTopMarginDocumentAttribute(); //public static final native int NSTransparentBinding(); //public static final native int NSTypedStreamVersionException(); -//public static final native int NSURLPboardType(); +public static final NSString NSURLPboardType = new NSString(NSURLPboardType()); +public static final native int NSURLPboardType(); //public static final native int NSUnderlineByWordMask(); public static final native int NSUnderlineColorAttributeName(); //public static final native int NSUnderlineStrikethroughMask(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java index ad35eea470..d0f84bd7d9 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java @@ -678,6 +678,7 @@ public static Image cocoa_new(Device device, int type, NSImage nsImage) { image.type = type; image.handle = nsImage; NSImageRep rep = nsImage.bestRepresentationForDevice(null); + rep.retain(); if (rep.isKindOfClass(NSBitmapImageRep.static_class())) { image.imageRep = new NSBitmapImageRep(rep.id); } |