flatlaf-natives-windows: support DWM attributes DWMWA_USE_IMMERSIVE_DARK_MODE, DWMWA_CAPTION_COLOR and DWMWA_TEXT_COLOR (all unused in FlatLaf core)

This commit is contained in:
Karl Tauber
2023-12-07 18:53:45 +01:00
parent 417f0f5f1c
commit 7f6f366744
6 changed files with 715 additions and 56 deletions

View File

@@ -50,29 +50,6 @@ JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_get
//---- Desktop Window Manager (DWM) -------------------------------------------
// define constants that may not available in older development environments
#ifndef DWMWA_COLOR_DEFAULT
#define DWMWA_WINDOW_CORNER_PREFERENCE 33
#define DWMWA_BORDER_COLOR 34
typedef enum {
DWMWCP_DEFAULT = 0,
DWMWCP_DONOTROUND = 1,
DWMWCP_ROUND = 2,
DWMWCP_ROUNDSMALL = 3
} DWM_WINDOW_CORNER_PREFERENCE;
// Use this constant to reset any window part colors to the system default behavior
#define DWMWA_COLOR_DEFAULT 0xFFFFFFFF
// Use this constant to specify that a window part should not be rendered
#define DWMWA_COLOR_NONE 0xFFFFFFFE
#endif
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowCornerPreference
( JNIEnv* env, jclass cls, jlong hwnd, jint cornerPreference )
@@ -85,18 +62,23 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_
}
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowBorderColor
( JNIEnv* env, jclass cls, jlong hwnd, jint red, jint green, jint blue )
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeBOOL
( JNIEnv* env, jclass cls, jlong hwnd, jint attribute, jboolean value )
{
if( hwnd == 0 )
return FALSE;
COLORREF attr;
if( red == -1 )
attr = DWMWA_COLOR_DEFAULT;
else if( red == -2 )
attr = DWMWA_COLOR_NONE;
else
attr = RGB( red, green, blue );
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), DWMWA_BORDER_COLOR, &attr, sizeof( attr ) ) == S_OK;
BOOL attr = value;
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), attribute, &attr, sizeof( attr ) ) == S_OK;
}
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeDWORD
( JNIEnv* env, jclass cls, jlong hwnd, jint attribute, jint value )
{
if( hwnd == 0 )
return FALSE;
DWORD attr = value;
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), attribute, &attr, sizeof( attr ) ) == S_OK;
}

View File

@@ -15,6 +15,18 @@ extern "C" {
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_ROUND 2L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_ROUNDSMALL
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_ROUNDSMALL 3L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_USE_IMMERSIVE_DARK_MODE
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_USE_IMMERSIVE_DARK_MODE 20L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_BORDER_COLOR
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_BORDER_COLOR 34L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_CAPTION_COLOR
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_CAPTION_COLOR 35L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_TEXT_COLOR
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_TEXT_COLOR 36L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_COLOR_DEFAULT
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_COLOR_DEFAULT -1L
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_COLOR_NONE
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWA_COLOR_NONE -2L
/*
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
* Method: getOSBuildNumberImpl
@@ -41,11 +53,19 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_
/*
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
* Method: setWindowBorderColor
* Signature: (JIII)Z
* Method: dwmSetWindowAttributeBOOL
* Signature: (JIZ)Z
*/
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowBorderColor
(JNIEnv *, jclass, jlong, jint, jint, jint);
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeBOOL
(JNIEnv *, jclass, jlong, jint, jboolean);
/*
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
* Method: dwmSetWindowAttributeDWORD
* Signature: (JII)Z
*/
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeDWORD
(JNIEnv *, jclass, jlong, jint, jint);
#ifdef __cplusplus
}