mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
Native window decorations: show window system menu when left-clicking on application icon, close window on left-double-click on app icon
This commit is contained in:
@@ -196,7 +196,9 @@ public class FlatNativeWindowBorder
|
||||
nativeProvider.setHasCustomDecoration( window, hasCustomDecoration );
|
||||
}
|
||||
|
||||
static void setTitleBarHeightAndHitTestSpots( Window window, int titleBarHeight, List<Rectangle> hitTestSpots ) {
|
||||
static void setTitleBarHeightAndHitTestSpots( Window window, int titleBarHeight,
|
||||
List<Rectangle> hitTestSpots, Rectangle appIconBounds )
|
||||
{
|
||||
if( canUseJBRCustomDecorations ) {
|
||||
JBRCustomDecorations.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots );
|
||||
return;
|
||||
@@ -207,6 +209,7 @@ public class FlatNativeWindowBorder
|
||||
|
||||
nativeProvider.setTitleBarHeight( window, titleBarHeight );
|
||||
nativeProvider.setTitleBarHitTestSpots( window, hitTestSpots );
|
||||
nativeProvider.setTitleBarAppIconBounds( window, appIconBounds );
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
@@ -240,5 +243,6 @@ public class FlatNativeWindowBorder
|
||||
void setHasCustomDecoration( Window window, boolean hasCustomDecoration );
|
||||
void setTitleBarHeight( Window window, int titleBarHeight );
|
||||
void setTitleBarHitTestSpots( Window window, List<Rectangle> hitTestSpots );
|
||||
void setTitleBarAppIconBounds( Window window, Rectangle appIconBounds );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,6 +453,12 @@ public class FlatTitlePane
|
||||
for( Rectangle r : debugHitTestSpots )
|
||||
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
||||
}
|
||||
if( debugAppIconBounds != null ) {
|
||||
g.setColor( Color.red );
|
||||
Point offset = SwingUtilities.convertPoint( this, 0, 0, window );
|
||||
Rectangle r = debugAppIconBounds;
|
||||
g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 );
|
||||
}
|
||||
}
|
||||
debug*/
|
||||
|
||||
@@ -632,16 +638,31 @@ debug*/
|
||||
titleBarHeight--;
|
||||
|
||||
List<Rectangle> hitTestSpots = new ArrayList<>();
|
||||
if( iconLabel.isVisible() )
|
||||
addNativeHitTestSpot( iconLabel, false, hitTestSpots );
|
||||
Rectangle appIconBounds = null;
|
||||
if( iconLabel.isVisible() ) {
|
||||
// compute real icon size (without insets)
|
||||
Point location = SwingUtilities.convertPoint( iconLabel, 0, 0, window );
|
||||
Insets iconInsets = iconLabel.getInsets();
|
||||
Rectangle iconBounds = new Rectangle(
|
||||
location.x + iconInsets.left,
|
||||
location.y + iconInsets.top,
|
||||
iconLabel.getWidth() - iconInsets.left - iconInsets.right,
|
||||
iconLabel.getHeight() - iconInsets.top - iconInsets.bottom );
|
||||
|
||||
if( hasJBRCustomDecoration() )
|
||||
hitTestSpots.add( iconBounds );
|
||||
else
|
||||
appIconBounds = iconBounds;
|
||||
}
|
||||
addNativeHitTestSpot( buttonPanel, false, hitTestSpots );
|
||||
addNativeHitTestSpot( menuBarPlaceholder, true, hitTestSpots );
|
||||
|
||||
FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots );
|
||||
FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds );
|
||||
|
||||
/*debug
|
||||
debugTitleBarHeight = titleBarHeight;
|
||||
debugHitTestSpots = hitTestSpots;
|
||||
debugAppIconBounds = appIconBounds;
|
||||
repaint();
|
||||
debug*/
|
||||
}
|
||||
@@ -663,6 +684,7 @@ debug*/
|
||||
/*debug
|
||||
private int debugTitleBarHeight;
|
||||
private List<Rectangle> debugHitTestSpots;
|
||||
private Rectangle debugAppIconBounds;
|
||||
debug*/
|
||||
|
||||
//---- class TitlePaneBorder ----------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user