8160448: Make GTK3 menus appearence similar to native.
authorssadetsky
Fri, 29 Jul 2016 11:19:28 +0300
changeset 40165 fb2eeee3513f
parent 40164 15ea98f2a6fa
child 40166 b97c433a420b
8160448: Make GTK3 menus appearence similar to native. Reviewed-by: alexsch
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKGraphicsUtils.java
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java
jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKGraphicsUtils.java	Fri Jul 29 11:14:05 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKGraphicsUtils.java	Fri Jul 29 11:19:28 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,16 +49,18 @@
         int componentState = context.getComponentState();
         if ((componentState & SynthConstants.DISABLED) ==
                               SynthConstants.DISABLED){
-            Color orgColor = g.getColor();
-            g.setColor(context.getStyle().getColor(context,
-                                                   GTKColorType.WHITE));
-            x += 1;
-            y += 1;
-            super.paintText(context, g, text, x, y, mnemonicIndex);
+            if (!GTKLookAndFeel.is3()) {
+                Color orgColor = g.getColor();
+                g.setColor(context.getStyle().getColor(context,
+                        GTKColorType.WHITE));
+                x += 1;
+                y += 1;
+                super.paintText(context, g, text, x, y, mnemonicIndex);
 
-            g.setColor(orgColor);
-            x -= 1;
-            y -= 1;
+                g.setColor(orgColor);
+                x -= 1;
+                y -= 1;
+            }
             super.paintText(context, g, text, x, y, mnemonicIndex);
         }
         else {
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java	Fri Jul 29 11:14:05 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java	Fri Jul 29 11:19:28 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -214,6 +214,18 @@
 
             Region region = context.getRegion();
             GTKStyle style = (GTKStyle) context.getStyle();
+            if (GTKLookAndFeel.is3() && region == Region.MENU) {
+                Object value = style.getClassSpecificValue("arrow-scaling");
+                if (value instanceof Number) {
+                    iconDimension = (int)(((Number) value).floatValue() *
+                            (style.getFont(context).getSize2D() +
+                            2 * style.getClassSpecificIntValue(context,
+                            "indicator-spacing", DEFAULT_ICON_SPACING)));
+                    if (iconDimension > 0) {
+                        return iconDimension;
+                    }
+                }
+            }
             iconDimension = style.getClassSpecificIntValue(context,
                     "indicator-size",
                     (region == Region.CHECK_BOX_MENU_ITEM ||
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Fri Jul 29 11:14:05 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Fri Jul 29 11:19:28 2016 +0300
@@ -649,10 +649,19 @@
             y += insets.top;
             if (orientation == JSeparator.HORIZONTAL) {
                 w -= (insets.left + insets.right);
-                detail = "hseparator";
             } else {
                 h -= (insets.top + insets.bottom);
-                detail = "vseparator";
+            }
+            if (GTKLookAndFeel.is3()) {
+                if (id == Region.POPUP_MENU_SEPARATOR) {
+                    detail = "menuitem";
+                    h -= (insets.top + insets.bottom);
+                } else {
+                    detail = "separator";
+                }
+            } else {
+                detail = orientation == JSeparator.HORIZONTAL ?
+                                                    "hseparator" : "vseparator";
             }
             synchronized (UNIXToolkit.GTK_LOCK) {
                 if (! ENGINE.paintCachedImage(g, x, y, w, h, id, state,
@@ -1381,8 +1390,13 @@
         if (gtkState == SynthConstants.MOUSE_OVER) {
             shadow = ShadowType.IN;
         }
+        if (!GTKLookAndFeel.is3()) {
+            x += 3;
+            y += 3;
+            w = h = 7;
+        }
         ENGINE.paintArrow(g, context, Region.MENU_ITEM, gtkState, shadow,
-                dir, "menuitem", x + 3, y + 3, 7, 7);
+                dir, "menuitem", x, y, w, h);
     }
 
     public void paintCheckBoxMenuItemCheckIcon(SynthContext context,