Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2019-06-28 05:39:52 -0400
committerLakshmi Shanmugam2019-07-01 07:49:55 -0400
commit5c60fc6d1def122d379b69dbd5f1417347c05175 (patch)
tree2837c4e6778223290d36327b7abf2cc88a0a6bc8
parent83475b5cadbc89585ddf1efa501c62661ab2bcdf (diff)
downloadeclipse.platform.swt-5c60fc6d1def122d379b69dbd5f1417347c05175.tar.gz
eclipse.platform.swt-5c60fc6d1def122d379b69dbd5f1417347c05175.tar.xz
eclipse.platform.swt-5c60fc6d1def122d379b69dbd5f1417347c05175.zip
Bug 548736: [Cocoa]setImage(null) on Label overrides text
If image is set to null and text is not null, then text should be shown in the Label. Refactored the setImage() code to remove multiple image != null checks. Change-Id: I150e191dffae488fa5c00d9487e7c22f545927f0
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java42
1 files changed, 25 insertions, 17 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
index 54e555a90a..09952cbf76 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
@@ -486,28 +486,32 @@ boolean setTabItemFocus () {
public void setImage (Image image) {
checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.image = image;
- isImage = true;
-
- /*
- * Feature in Cocoa. If the NSImage object being set into the view is
- * the same NSImage object that is already there then the new image is
- * not taken. This results in the view's image not changing even if the
- * NSImage object's content has changed since it was last set into the
- * view. The workaround is to temporarily set the view's image to null
- * so that the new image will then be taken.
- */
if (image != null) {
+ if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
+
+ this.image = image;
+ isImage = true;
+ /*
+ * Feature in Cocoa. If the NSImage object being set into the view is
+ * the same NSImage object that is already there then the new image is
+ * not taken. This results in the view's image not changing even if the
+ * NSImage object's content has changed since it was last set into the
+ * view. The workaround is to temporarily set the view's image to null
+ * so that the new image will then be taken.
+ */
NSImage current = imageView.image ();
if (current != null && current.id == image.handle.id) {
imageView.setImage (null);
}
+ imageView.setImage(image.handle);
+ ((NSBox)view).setContentView(imageView);
+ } else {
+ if (this.image == null) return; // do nothing if image is already null
+
+ this.image = image;
+ imageView.setImage(null);
+ _setText();
}
- imageView.setImage(image != null ? image.handle : null);
- ((NSBox)view).setContentView(imageView);
}
/**
@@ -545,8 +549,12 @@ public void setText (String string) {
checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
- isImage = false;
text = string;
+ _setText();
+}
+
+private void _setText () {
+ isImage = false;
NSCell cell = new NSCell(textView.cell());
cell.setAttributedStringValue(createString());
((NSBox)view).setContentView(textView);

Back to the top