Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2020-10-30 13:33:14 +0000
committerLakshmi P Shanmugam2020-11-05 10:52:50 +0000
commit539fcb409aa94b548eb95ea792f9f5a63fe9ca70 (patch)
treef840623b974d6f2edb05ced78fd1348be95ad7f1
parent932bc57203a4c3d0c70b064723801419562b245f (diff)
downloadeclipse.platform.swt-539fcb409aa94b548eb95ea792f9f5a63fe9ca70.tar.gz
eclipse.platform.swt-539fcb409aa94b548eb95ea792f9f5a63fe9ca70.tar.xz
eclipse.platform.swt-539fcb409aa94b548eb95ea792f9f5a63fe9ca70.zip
Bug 567862 - [Big Sur] SWT.ICON_INFORMATION returning a generic icon
Use NSImage.imageNamed() with NSImageName strings. Use NSImageNameCaution and NSImageNameInfo for Warning and Info icons respectively. Didn't find a NSImageName for Error icon, so it still uses the deprecated GetIconRefFromTypeInfo with OS.kAlertStopIcon. Change-Id: Icae687eb325cae39b6e912e6c15b9fe00b205129
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c24
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java30
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java20
7 files changed, 78 insertions, 8 deletions
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 f98ad950e8..d38d61677b 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
@@ -3688,6 +3688,30 @@ JNIEXPORT jlong JNICALL OS_NATIVE(NSForegroundColorAttributeName)
}
#endif
+#ifndef NO_NSImageNameCaution
+JNIEXPORT jlong JNICALL OS_NATIVE(NSImageNameCaution)
+ (JNIEnv *env, jclass that)
+{
+ jlong rc = 0;
+ OS_NATIVE_ENTER(env, that, NSImageNameCaution_FUNC);
+ rc = (jlong)NSImageNameCaution;
+ OS_NATIVE_EXIT(env, that, NSImageNameCaution_FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO_NSImageNameInfo
+JNIEXPORT jlong JNICALL OS_NATIVE(NSImageNameInfo)
+ (JNIEnv *env, jclass that)
+{
+ jlong rc = 0;
+ OS_NATIVE_ENTER(env, that, NSImageNameInfo_FUNC);
+ rc = (jlong)NSImageNameInfo;
+ OS_NATIVE_EXIT(env, that, NSImageNameInfo_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO_NSLigatureAttributeName
JNIEXPORT jlong JNICALL OS_NATIVE(NSLigatureAttributeName)
(JNIEnv *env, jclass that)
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 b702fe86f9..346d5ac3aa 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
@@ -280,6 +280,8 @@ char * OS_nativeFunctionNames[] = {
"NSFilenamesPboardType",
"NSFontAttributeName",
"NSForegroundColorAttributeName",
+ "NSImageNameCaution",
+ "NSImageNameInfo",
"NSIntersectionRect",
"NSLigatureAttributeName",
"NSLinkAttributeName",
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 26d5d5ab2d..7e70fb9134 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
@@ -290,6 +290,8 @@ typedef enum {
NSFilenamesPboardType_FUNC,
NSFontAttributeName_FUNC,
NSForegroundColorAttributeName_FUNC,
+ NSImageNameCaution_FUNC,
+ NSImageNameInfo_FUNC,
NSIntersectionRect_FUNC,
NSLigatureAttributeName_FUNC,
NSLinkAttributeName_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 de8ef8e7fc..c0de5c2b41 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
@@ -4309,6 +4309,8 @@
<constant name="NSFilenamesPboardType" swt_gen="true"></constant>
<constant name="NSFontAttributeName" swt_gen="true"></constant>
<constant name="NSForegroundColorAttributeName" swt_gen="true"></constant>
+ <constant name="NSImageNameCaution" swt_gen="true"></constant>
+ <constant name="NSImageNameInfo" swt_gen="true"></constant>
<constant name="NSLigatureAttributeName" swt_gen="true"></constant>
<constant name="NSLinkAttributeName" swt_gen="true"></constant>
<constant name="NSModalPanelRunLoopMode" swt_gen="true"></constant>
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 27f4587ea5..5c6fb563af 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
@@ -2737,6 +2737,12 @@ public static final NSString NSFontAttributeName = new NSString(NSFontAttributeN
public static final native long NSForegroundColorAttributeName();
public static final NSString NSForegroundColorAttributeName = new NSString(NSForegroundColorAttributeName());
/** @method flags=const */
+public static final native long NSImageNameCaution();
+public static final NSString NSImageNameCaution = new NSString(NSImageNameCaution());
+/** @method flags=const */
+public static final native long NSImageNameInfo();
+public static final NSString NSImageNameInfo = new NSString(NSImageNameInfo());
+/** @method flags=const */
public static final native long NSLigatureAttributeName();
public static final NSString NSLigatureAttributeName = new NSString(NSLigatureAttributeName());
/** @method flags=const */
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 c94fbf343a..06c9399be8 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
@@ -2000,6 +2000,12 @@ public Cursor getSystemCursor (int id) {
return cursors [id];
}
+/**
+ * Gets the system icon using GetIconRefFromTypeInfo() which is deprecated in macOS 10.15.
+ * For BigSur and later, try to get the system image using NSImage.imageNamed().
+ *
+ * @return NSImage, the returned NSImage instance should be released (for example in Image.destroy()).
+ */
static NSImage getSystemImageForID(int osType) {
long iconRef[] = new long [1];
OS.GetIconRefFromTypeInfo(OS.kSystemIconsCreator, osType, 0, 0, 0, iconRef);
@@ -2054,12 +2060,32 @@ public Image getSystemImage (int id) {
case SWT.ICON_QUESTION:
case SWT.ICON_WORKING: {
if (infoImage != null) return infoImage;
- NSImage img = getSystemImageForID(OS.kAlertNoteIcon);
+ NSImage img;
+ if (OS.isBigSurOrLater()) {
+ img = NSImage.imageNamed(OS.NSImageNameInfo);
+ /*
+ * retain() is required here, as img is used below to create Image object.
+ * img will be released later in Image.destroy().
+ */
+ img.retain();
+ } else {
+ img = getSystemImageForID(OS.kAlertNoteIcon);
+ }
return infoImage = Image.cocoa_new (this, SWT.ICON, img);
}
case SWT.ICON_WARNING: {
if (warningImage != null) return warningImage;
- NSImage img = getSystemImageForID(OS.kAlertCautionIcon);
+ NSImage img;
+ if (OS.isBigSurOrLater()) {
+ img = NSImage.imageNamed(OS.NSImageNameCaution);
+ /*
+ * retain() is required here, as img is used below to create Image object.
+ * img will be released later in Image.destroy().
+ */
+ img.retain();
+ } else {
+ img = getSystemImageForID(OS.kAlertCautionIcon);
+ }
return warningImage = Image.cocoa_new (this, SWT.ICON, img);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java
index 7ca42e70fc..733d7d3888 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java
@@ -146,15 +146,23 @@ public int open () {
}
if (((style & SWT.ICON_INFORMATION) != 0) || ((style & SWT.ICON_WORKING) != 0) || ((style & SWT.ICON_QUESTION) != 0)) {
alertType = OS.NSInformationalAlertStyle;
- NSImage icon = Display.getSystemImageForID(OS.kAlertNoteIcon);
- alert.setIcon(icon);
- icon.release();
+ if (OS.isBigSurOrLater()) {
+ alert.setIcon(NSImage.imageNamed(OS.NSImageNameInfo));
+ } else {
+ NSImage icon = Display.getSystemImageForID(OS.kAlertNoteIcon);
+ alert.setIcon(icon);
+ icon.release();
+ }
}
if ((style & SWT.ICON_WARNING) != 0) {
alertType = OS.NSWarningAlertStyle;
- NSImage icon = Display.getSystemImageForID(OS.kAlertCautionIcon);
- alert.setIcon(icon);
- icon.release();
+ if (OS.isBigSurOrLater()) {
+ alert.setIcon(NSImage.imageNamed(OS.NSImageNameCaution));
+ } else {
+ NSImage icon = Display.getSystemImageForID(OS.kAlertCautionIcon);
+ alert.setIcon(icon);
+ icon.release();
+ }
}
alert.setAlertStyle(alertType);

Back to the top