mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Windows 11: use rounded popups with system border and system drop shadow
This commit is contained in:
@@ -22,6 +22,7 @@ plugins {
|
||||
|
||||
flatlafJniHeaders {
|
||||
headers = listOf(
|
||||
"com_formdev_flatlaf_ui_FlatNativeWindowsLibrary.h",
|
||||
"com_formdev_flatlaf_ui_FlatWindowsNativeWindowBorder.h",
|
||||
"com_formdev_flatlaf_ui_FlatWindowsNativeWindowBorder_WndProc.h"
|
||||
)
|
||||
@@ -74,8 +75,8 @@ tasks {
|
||||
|
||||
linkerArgs.addAll( toolChain.map {
|
||||
when( it ) {
|
||||
is Gcc, is Clang -> listOf( "-l${jawt}", "-lUser32", "-lGdi32", "-lshell32", "-lAdvAPI32", "-lKernel32" )
|
||||
is VisualCpp -> listOf( "${jawt}.lib", "User32.lib", "Gdi32.lib", "shell32.lib", "AdvAPI32.lib", "Kernel32.lib", "/NODEFAULTLIB" )
|
||||
is Gcc, is Clang -> listOf( "-l${jawt}", "-lUser32", "-lGdi32", "-lshell32", "-lAdvAPI32", "-lKernel32", "-lDwmapi" )
|
||||
is VisualCpp -> listOf( "${jawt}.lib", "User32.lib", "Gdi32.lib", "shell32.lib", "AdvAPI32.lib", "Kernel32.lib", "Dwmapi.lib", "/NODEFAULTLIB" )
|
||||
else -> emptyList()
|
||||
}
|
||||
} )
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
|
||||
HWND getWindowHandle( JNIEnv* env, jobject window );
|
||||
|
||||
//---- JNI methods ------------------------------------------------------------
|
||||
|
||||
extern "C"
|
||||
@@ -540,7 +542,7 @@ void FlatWndProc::setMenuItemState( HMENU systemMenu, int item, bool enabled ) {
|
||||
::SetMenuItemInfo( systemMenu, item, FALSE, &mii );
|
||||
}
|
||||
|
||||
HWND FlatWndProc::getWindowHandle( JNIEnv* env, jobject window ) {
|
||||
HWND getWindowHandle( JNIEnv* env, jobject window ) {
|
||||
JAWT awt;
|
||||
awt.version = JAWT_VERSION_1_4;
|
||||
if( !JAWT_GetAWT( env, &awt ) )
|
||||
|
||||
@@ -67,6 +67,4 @@ private:
|
||||
void sendMessageToClientArea( HWND hwnd, int uMsg, LPARAM lParam );
|
||||
void openSystemMenu( HWND hwnd, int x, int y );
|
||||
void setMenuItemState( HMENU systemMenu, int item, bool enabled );
|
||||
|
||||
static HWND getWindowHandle( JNIEnv* env, jobject window );
|
||||
};
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2022 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// avoid inlining of printf()
|
||||
#define _NO_CRT_STDIO_INLINE
|
||||
|
||||
#include <windows.h>
|
||||
#include <dwmapi.h>
|
||||
#include "com_formdev_flatlaf_ui_FlatNativeWindowsLibrary.h"
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
|
||||
// see FlatWndProc.cpp
|
||||
HWND getWindowHandle( JNIEnv* env, jobject window );
|
||||
|
||||
//---- Utility ----------------------------------------------------------------
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getOSBuildNumberImpl
|
||||
( JNIEnv* env, jclass cls )
|
||||
{
|
||||
OSVERSIONINFO info;
|
||||
info.dwOSVersionInfoSize = sizeof( info );
|
||||
if( !::GetVersionEx( &info ) )
|
||||
return 0;
|
||||
return info.dwBuildNumber;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getHWND
|
||||
( JNIEnv* env, jclass cls, jobject window )
|
||||
{
|
||||
return reinterpret_cast<jlong>( getWindowHandle( env, window ) );
|
||||
}
|
||||
|
||||
//---- 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 )
|
||||
{
|
||||
if( hwnd == 0 )
|
||||
return FALSE;
|
||||
|
||||
DWM_WINDOW_CORNER_PREFERENCE attr = (DWM_WINDOW_CORNER_PREFERENCE) cornerPreference;
|
||||
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof( attr ) ) == S_OK;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowBorderColor
|
||||
( JNIEnv* env, jclass cls, jlong hwnd, jint red, jint green, jint blue )
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_formdev_flatlaf_ui_FlatNativeWindowsLibrary */
|
||||
|
||||
#ifndef _Included_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
#define _Included_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_DEFAULT
|
||||
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_DEFAULT 0L
|
||||
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_DONOTROUND
|
||||
#define com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_DONOTROUND 1L
|
||||
#undef com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_DWMWCP_ROUND
|
||||
#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
|
||||
/*
|
||||
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
* Method: getOSBuildNumberImpl
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getOSBuildNumberImpl
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
* Method: getHWND
|
||||
* Signature: (Ljava/awt/Window;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getHWND
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
* Method: setWindowCornerPreference
|
||||
* Signature: (JI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowCornerPreference
|
||||
(JNIEnv *, jclass, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
|
||||
* Method: setWindowBorderColor
|
||||
* Signature: (JIII)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowBorderColor
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user