macOS native:

- removed `FlatNativeMacLibrary.getWindowPtr()` because it is too dangerous to use `windowPtr` (which is `NSWindow*`) in Java (using invalid window pointer would crash app)
- made `getNSWindow()` 20x faster
- catch exceptions in `getNSWindow()`
- digitally signed dylibs
This commit is contained in:
Karl Tauber
2023-12-14 14:39:26 +01:00
parent 9bf4da7acf
commit 46de81c1c9
9 changed files with 108 additions and 74 deletions

View File

@@ -23,6 +23,20 @@ import java.awt.Window;
* <p>
* <b>Note</b>: This is private API. Do not use!
*
* <h2>Methods that use windows as parameter</h2>
*
* For all methods that accept a {@link java.awt.Window} as parameter,
* the underlying macOS window must be already created,
* otherwise the method fails. You can use following to ensure this:
* <pre>{@code
* if( !window.isDisplayable() )
* window.addNotify();
* }</pre>
* or invoke the method after packing the window. E.g.
* <pre>{@code
* window.pack();
* }</pre>
*
* @author Karl Tauber
* @since 3.3
*/
@@ -38,22 +52,5 @@ public class FlatNativeMacLibrary
return FlatNativeLibrary.isLoaded();
}
/**
* Gets the macOS window pointer (NSWindow) for the given Swing window.
* <p>
* Note that the underlying macOS window must be already created,
* otherwise this method returns zero. Use following to ensure this:
* <pre>{@code
* if( !window.isDisplayable() )
* window.addNotify();
* }</pre>
* or invoke this method after packing the window. E.g.
* <pre>{@code
* window.pack();
* long windowPtr = getWindowPtr( window );
* }</pre>
*/
public native static long getWindowPtr( Window window );
public native static void setWindowRoundedBorder( long windowPtr, float radius, float borderWidth, int borderColor );
public native static boolean setWindowRoundedBorder( Window window, float radius, float borderWidth, int borderColor );
}

View File

@@ -324,13 +324,6 @@ public class FlatPopupFactory
if( !popupWindow.isDisplayable() )
popupWindow.addNotify();
// get native window handle/pointer
long hwnd = SystemInfo.isWindows
? FlatNativeWindowsLibrary.getHWND( popupWindow )
: FlatNativeMacLibrary.getWindowPtr( popupWindow );
if( hwnd == 0 )
return;
int borderCornerRadius = getBorderCornerRadius( owner, contents );
float borderWidth = getRoundedBorderWidth( owner, contents );
@@ -353,6 +346,9 @@ public class FlatPopupFactory
}
if( SystemInfo.isWindows ) {
// get native window handle
long hwnd = FlatNativeWindowsLibrary.getHWND( popupWindow );
// set corner preference
int cornerPreference = (borderCornerRadius <= 4)
? FlatNativeWindowsLibrary.DWMWCP_ROUNDSMALL // 4px
@@ -366,7 +362,7 @@ public class FlatPopupFactory
borderWidth = 0;
// set corner radius, border width and color
FlatNativeMacLibrary.setWindowRoundedBorder( hwnd, borderCornerRadius,
FlatNativeMacLibrary.setWindowRoundedBorder( popupWindow, borderCornerRadius,
borderWidth, (borderColor != null) ? borderColor.getRGB() : 0 );
}
}