From 0b11e07842d23b77b170849c793732098c8f9e81 Mon Sep 17 00:00:00 2001
From: Phillipus
Date: Wed, 6 Mar 2024 14:07:39 +0000
Subject: [PATCH] Fix for Mac drawing bug issue 1012
- Add a new selector setClipsToBounds
- Set this selector to true in Widget#drawRect
- See https://github.com/eclipse-platform/eclipse.platform.swt/issues/1012
---
.../cocoa/org/eclipse/swt/internal/cocoa/NSView.java | 4 ++++
.../cocoa/org/eclipse/swt/internal/cocoa/OS.java | 3 +++
.../cocoa/org/eclipse/swt/internal/cocoa/Selector.java | 3 +++
.../Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java | 7 +++++++
4 files changed, 17 insertions(+)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java
index 02a5319e7f3..1c32a746d17 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java
@@ -244,6 +244,10 @@ public void setBoundsSize(NSSize newSize) {
OS.objc_msgSend(this.id, OS.sel_setBoundsSize_, newSize);
}
+public void setClipsToBounds(boolean clipsToBounds) {
+ OS.objc_msgSend(this.id, OS.sel_setClipsToBounds_, clipsToBounds);
+}
+
public void setFocusRingType(long focusRingType) {
OS.objc_msgSend(this.id, OS.sel_setFocusRingType_, focusRingType);
}
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 873c785a1ed..a33aa208419 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
@@ -162,6 +162,9 @@ public static int VERSION (int major, int minor, int bugfix) {
public static final long class_NSToolbarView = objc_getClass("NSToolbarView");
+ /** Since macOS 14 the clipsToBounds property of NSView is exposed */
+ public static final long sel_setClipsToBounds_ = Selector.sel_setClipsToBounds_.value;
+
/*
* Wrapper function which will call NSSavePanel.beginSheetModalForWindow. This
* implementation allows passing of objective-C block from Java to C code, and
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 42425a680d0..d257f420325 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
@@ -84,6 +84,9 @@ public enum Selector {
, sel_awtAppDelegate("awtAppDelegate")
+ /** Since macOS 14 the clipsToBounds property of NSView is exposed */
+ , sel_setClipsToBounds_("setClipsToBounds:")
+
/** This section is auto generated */
, sel_CGEvent("CGEvent")
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
index 0280dd411f2..c5c26d69a01 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
@@ -759,6 +759,13 @@ void drawRect (long id, long sel, NSRect rect) {
if (!isDrawing()) return;
Display display = this.display;
NSView view = new NSView(id);
+
+ /*
+ * Since macOS 14 the clipsToBounds property of NSView has to be set to true
+ * See https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14
+ */
+ view.setClipsToBounds(true);
+
display.isPainting.addObject(view);
NSGraphicsContext context = NSGraphicsContext.currentContext();
context.saveGraphicsState();