NsImage callback changes Change-Id: Iaba21020cdfaf5e91a71e4e5544735f1dbb09057
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 58e3a92..97273d9 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
@@ -1265,7 +1265,7 @@ jintLong rc = 0; OS_NATIVE_ENTER(env, that, CFURLCreateFromFSRef_FUNC); if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; - rc = (jintLong)CFURLCreateFromFSRef((CFAllocatorRef)arg0, (struct FSRef*)lparg1); + rc = (jintLong)CFURLCreateFromFSRef((CFAllocatorRef)arg0, (structFSRef*)lparg1); fail: if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); OS_NATIVE_EXIT(env, that, CFURLCreateFromFSRef_FUNC); @@ -9906,6 +9906,33 @@ } #endif +#if (!defined(NO_objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2) && !defined(JNI64)) || (!defined(NO_objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2) && defined(JNI64)) +#ifndef JNI64 +JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2, jobject arg3) +#else +JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2, jobject arg3) +#endif +{ + NSRect _arg3, *lparg3=NULL; + jboolean rc = 0; +#ifndef JNI64 + OS_NATIVE_ENTER(env, that, objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#else + OS_NATIVE_ENTER(env, that, objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#endif + if (arg3) if ((lparg3 = getNSRectFields(env, arg3, &_arg3)) == NULL) goto fail; + rc = (jboolean)((BOOL (*)(jintLong, jintLong, jintLong, NSRect))objc_msgSend_bool)(arg0, arg1, arg2, *lparg3); +fail: + if (arg3 && lparg3) setNSRectFields(env, arg3, lparg3); +#ifndef JNI64 + OS_NATIVE_EXIT(env, that, objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#else + OS_NATIVE_EXIT(env, that, objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#endif + return rc; +} +#endif + #if (!defined(NO_objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSSize_2Z) && !defined(JNI64)) || (!defined(NO_objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSSize_2Z) && defined(JNI64)) #ifndef JNI64 JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSSize_2Z)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2, jobject arg3, jboolean arg4)
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 05d934f..8ebc81e 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
@@ -1119,6 +1119,11 @@ "objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSPoint_2", #endif #ifndef JNI64 + "objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2", +#else + "objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2", +#endif +#ifndef JNI64 "objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSSize_2Z", #else "objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSSize_2Z",
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 6d43bdd..4b4c412 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
@@ -1129,6 +1129,11 @@ objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSPoint_2_FUNC, #endif #ifndef JNI64 + objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC, +#else + objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC, +#endif +#ifndef JNI64 objc_1msgSend_1bool__IIILorg_eclipse_swt_internal_cocoa_NSSize_2Z_FUNC, #else objc_1msgSend_1bool__JJJLorg_eclipse_swt_internal_cocoa_NSSize_2Z_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras index 4193447..05c77fa 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras
@@ -1553,6 +1553,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="drawInRect:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="drawInRect:fromRect:operation:fraction:" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> @@ -1560,6 +1564,11 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="drawRepresentation:inRect:" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method class_method="true" selector="imageNamed:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true" swt_java_type="NSImage"></retval>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSImage.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSImage.java index b93d6ad..ee097b4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSImage.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSImage.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -42,10 +42,18 @@ OS.objc_msgSend(this.id, OS.sel_drawAtPoint_fromRect_operation_fraction_, point, fromRect, op, delta); } +public void drawInRect(NSRect rect) { + OS.objc_msgSend(this.id, OS.sel_drawInRect_, rect); +} + public void drawInRect(NSRect rect, NSRect fromRect, long /*int*/ op, double /*float*/ delta) { OS.objc_msgSend(this.id, OS.sel_drawInRect_fromRect_operation_fraction_, rect, fromRect, op, delta); } +public boolean drawRepresentation(NSImageRep imageRep, NSRect rect) { + return OS.objc_msgSend_bool(this.id, OS.sel_drawRepresentation_inRect_, imageRep != null ? imageRep.id : 0, rect); +} + public static NSImage imageNamed(NSString name) { long /*int*/ result = OS.objc_msgSend(OS.class_NSImage, OS.sel_imageNamed_, name != null ? name.id : 0); return result != 0 ? new NSImage(result) : null;
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 3ab61a3..8b604e5 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
@@ -1334,6 +1334,7 @@ public static final long /*int*/ sel_drawInteriorWithFrame_inView_ = Selector.sel_drawInteriorWithFrame_inView_.value; public static final long /*int*/ sel_drawLabel_inRect_ = Selector.sel_drawLabel_inRect_.value; public static final long /*int*/ sel_drawRect_ = Selector.sel_drawRect_.value; +public static final long /*int*/ sel_drawRepresentation_inRect_ = Selector.sel_drawRepresentation_inRect_.value; public static final long /*int*/ sel_drawSortIndicatorWithFrame_inView_ascending_priority_ = Selector.sel_drawSortIndicatorWithFrame_inView_ascending_priority_.value; public static final long /*int*/ sel_drawStatusBarBackgroundInRect_withHighlight_ = Selector.sel_drawStatusBarBackgroundInRect_withHighlight_.value; public static final long /*int*/ sel_drawTitle_withFrame_inView_ = Selector.sel_drawTitle_withFrame_inView_.value; @@ -3387,7 +3388,7 @@ public static final native long /*int*/ CFStringCreateWithCharacters(long /*int*/ alloc, char[] chars, long /*int*/ numChars); /** * @param allocator cast=(CFAllocatorRef) - * @param fsRef cast=(struct FSRef*) + * @param fsRef cast=(structFSRef*) */ public static final native long /*int*/ CFURLCreateFromFSRef(long /*int*/ allocator, byte[] fsRef); /** @@ -3911,6 +3912,11 @@ * @method flags=cast * @param arg1 flags=struct */ +public static final native boolean objc_msgSend_bool(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, NSRect arg1); +/** + * @method flags=cast + * @param arg1 flags=struct + */ public static final native boolean objc_msgSend_bool(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, NSSize arg1, boolean arg2); /** @method flags=cast */ public static final native boolean objc_msgSend_bool(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java index fa99603..9da4cf4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
@@ -455,6 +455,7 @@ , sel_drawInteriorWithFrame_inView_("drawInteriorWithFrame:inView:") , sel_drawLabel_inRect_("drawLabel:inRect:") , sel_drawRect_("drawRect:") + , sel_drawRepresentation_inRect_("drawRepresentation:inRect:") , sel_drawSortIndicatorWithFrame_inView_ascending_priority_("drawSortIndicatorWithFrame:inView:ascending:priority:") , sel_drawStatusBarBackgroundInRect_withHighlight_("drawStatusBarBackgroundInRect:withHighlight:") , sel_drawTitle_withFrame_inView_("drawTitle:withFrame:inView:")
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java index 923012f..c798e05 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java
@@ -28,7 +28,7 @@ /** * SWT Minor version number (must be in the range 0..999) */ - static int MINOR_VERSION = 858; + static int MINOR_VERSION = 863; /** * SWT revision number (must be >= 0) @@ -55,7 +55,7 @@ static { DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$ - SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$ + SEPARATOR = File.separator; USER_HOME = System.getProperty ("user.home"); SWT_LIB_DIR = ".swt" + SEPARATOR + "lib" + SEPARATOR + os() + SEPARATOR + arch(); //$NON-NLS-1$ $NON-NLS-2$ JAVA_VERSION = parseVersion(System.getProperty("java.version")); //$NON-NLS-1$
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 fe7317c..b9ec82a 100644 --- 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
@@ -136,6 +136,18 @@ */ private AlphaInfo alphaInfo_100, alphaInfo_200; + private Callback callback_draw_representation; + + private long method; + + private long methodImpl; + + private Callback callback_drawInRect; + + private long method1; + + private long methodImpl1; + static class AlphaInfo { /** * The alpha data of the image. @@ -803,10 +815,13 @@ */ public Image(Device device, ImageDataProvider imageDataProvider) { super(device); + if (imageDataProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.imageDataProvider = imageDataProvider; ImageData data = imageDataProvider.getImageData (100); if (data == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + + NSAutoreleasePool pool = null; if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); try { @@ -819,11 +834,43 @@ handle.addRepresentation(rep); rep.release(); } + addCallBacks (); } finally { if (pool != null) pool.release(); } } +void addCallBacks () { + System.out.println("add call backs"); + callback_draw_representation = new Callback(this, "_drawRepresentationInRect", 4); + long /*int*/ proc = callback_draw_representation.getAddress(); + if (proc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + method = OS.class_getInstanceMethod(OS.class_NSImage, OS.sel_drawRepresentation_inRect_); + if (method != 0) methodImpl = OS.method_setImplementation(method, proc); + + callback_drawInRect = new Callback(this, "_drawAtPoint", 5); + proc = 0; + proc = callback_draw_representation.getAddress(); + if (proc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + method1 = OS.class_getInstanceMethod(OS.class_NSImage, OS.sel_drawAtPoint_fromRect_operation_fraction_); + if (method1 != 0) methodImpl1 = OS.method_setImplementation(method1, proc); +} + +long /*int*/ _drawRepresentationInRect (long id, long sel, long imageRep, long NSRect) { + System.out.println("draw representation"); + return 1; +} + +long /*int*/ _drawInRect (long id, long sel, long NSRect) { + System.out.println("draw in rect"); + return 1; +} + +long /*int*/ _drawAtPoint (long id, long sel, long NSRect, long op, long fraction) { + System.out.println("draw at point"); + return 1; +} + private AlphaInfo _getAlphaInfoAtCurrentZoom (NSBitmapImageRep rep) { int deviceZoom = DPIUtil.getDeviceZoom(); if (deviceZoom != 100 && (imageFileNameProvider != null || imageDataProvider != null)) { @@ -1079,6 +1126,14 @@ @Override void destroy() { + if (method != 0) OS.method_setImplementation(method, methodImpl); + if (callback_draw_representation != null) callback_draw_representation.dispose(); + callback_draw_representation = null; + + if (method1 != 0) OS.method_setImplementation(method1, methodImpl1); + if (callback_drawInRect != null) callback_drawInRect.dispose(); + callback_drawInRect = null; + if (memGC != null) memGC.dispose(); handle.release(); handle = null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 1407a04..aeba87f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -2601,6 +2601,12 @@ OS.class_addMethod(cls, OS.sel_shouldChangeTextInRange_replacementString_, shouldChangeTextInRange_replacementString_Proc, "@:{NSRange}@"); OS.objc_registerClassPair(cls); +// className = "SWTImage"; +// cls = OS.objc_allocateClassPair(OS.class_NSImage, className, 0); +// OS.class_addMethod(cls, OS.sel_drawRect_, drawRectProc, "@:{NSRect}"); +// OS.class_addMethod(cls, OS.sel_drawRepresentation_inRect_, proc4, "@:@{NSRect}"); +// OS.objc_registerClassPair(cls); + className = "SWTImageView"; cls = OS.objc_allocateClassPair(OS.class_NSImageView, className, 0); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); @@ -6339,6 +6345,11 @@ } static long /*int*/ windowProc(long /*int*/ id, long /*int*/ sel, long /*int*/ arg0, long /*int*/ arg1) { +// if (sel == OS.sel_drawRepresentation_inRect_){ +// System.out.println("draw representation"); +// return 0; +// } + Widget widget = LookupWidget(id, sel); if (widget == null) return 0;