提交 1d3c26d0 编写于 作者: P prr

8207322: Backport GTK3 support on Linux to 8u

Reviewed-by: prr, ssadetsky
上级 b07ece7a
#
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2018, 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
......@@ -606,7 +606,9 @@ ifeq ($(findstring $(OPENJDK_TARGET_OS),windows macosx),)
debug_trace.c \
debug_util.c \
gnome_interface.c \
gtk_interface.c \
gtk2_interface.c \
gtk3_interface.c \
swing_GTKEngine.c \
swing_GTKStyle.c \
rect.c \
......
#
# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2002, 2018, 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
......@@ -174,6 +174,7 @@ SUNWprivate_1.1 {
Java_sun_awt_UNIXToolkit_load_1gtk_1icon;
Java_sun_awt_UNIXToolkit_nativeSync;
Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl;
Java_sun_awt_UNIXToolkit_get_1gtk_1version;
Java_java_awt_AWTEvent_initIDs;
Java_java_awt_event_InputEvent_initIDs;
Java_java_awt_event_KeyEvent_initIDs;
......
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2018, 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
......@@ -158,8 +158,8 @@ class GTKEngine {
int widgetType, int state, int shadowType, String detail,
int x, int y, int width, int height, int synthState, int dir);
private native void native_paint_slider(
int widgetType, int state, int shadowType, String detail,
int x, int y, int width, int height, int orientation);
int widgetType, int state, int shadowType, String detail, int x,
int y, int width, int height, int orientation, boolean hasFocus);
private native void native_paint_vline(
int widgetType, int state, String detail,
int x, int y, int width, int height);
......@@ -491,6 +491,14 @@ class GTKEngine {
int gtkState =
GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int synthState = context.getComponentState();
Container parent = context.getComponent().getParent();
if(GTKLookAndFeel.is3()) {
if (parent != null && parent.getParent() instanceof JComboBox) {
if (parent.getParent().hasFocus()) {
synthState |= SynthConstants.FOCUSED;
}
}
}
int dir = getTextDirection(context);
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_shadow(widget, gtkState, shadowType.ordinal(), detail,
......@@ -498,13 +506,13 @@ class GTKEngine {
}
public void paintSlider(Graphics g, SynthContext context,
Region id, int state, ShadowType shadowType, String detail,
int x, int y, int w, int h, Orientation orientation) {
Region id, int state, ShadowType shadowType, String detail, int x,
int y, int w, int h, Orientation orientation, boolean hasFocus) {
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
int widget = getWidgetType(context.getComponent(), id).ordinal();
native_paint_slider(widget, state, shadowType.ordinal(), detail,
x - x0, y - y0, w, h, orientation.ordinal());
x - x0, y - y0, w, h, orientation.ordinal(), hasFocus);
}
public void paintVline(Graphics g, SynthContext context,
......@@ -578,8 +586,8 @@ class GTKEngine {
* Convenience method that delegates to finishPainting() with
* caching enabled.
*/
public void finishPainting() {
finishPainting(true);
public BufferedImage finishPainting() {
return finishPainting(true);
}
/**
......@@ -587,7 +595,7 @@ class GTKEngine {
* BufferedImage from the offscreen buffer, (optionally) cache it,
* and paint it.
*/
public void finishPainting(boolean useCache) {
public BufferedImage finishPainting(boolean useCache) {
DataBufferInt dataBuffer = new DataBufferInt(w0 * h0);
// Note that stealData() requires a markDirty() afterwards
// since we modify the data in it.
......@@ -601,11 +609,12 @@ class GTKEngine {
dataBuffer, w0, h0, w0, bands, null);
ColorModel cm = COLOR_MODELS[transparency - 1];
Image img = new BufferedImage(cm, raster, false, null);
BufferedImage img = new BufferedImage(cm, raster, false, null);
if (useCache) {
cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
}
graphics.drawImage(img, x0, y0, null);
return img;
}
/**
......
/*
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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
......@@ -47,32 +47,15 @@ class GTKGraphicsUtils extends SynthGraphicsUtils {
return;
}
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);
String themeName = GTKLookAndFeel.getGtkThemeName();
if (themeName != null && themeName.startsWith("blueprint") &&
shouldShadowText(context.getRegion(), componentState)) {
g.setColor(orgColor);
x -= 1;
y -= 1;
super.paintText(context, g, text, x, y, mnemonicIndex);
}
else {
String themeName = GTKLookAndFeel.getGtkThemeName();
if (themeName != null && themeName.startsWith("blueprint") &&
shouldShadowText(context.getRegion(), componentState)) {
g.setColor(Color.BLACK);
super.paintText(context, g, text, x+1, y+1, mnemonicIndex);
g.setColor(Color.WHITE);
}
super.paintText(context, g, text, x, y, mnemonicIndex);
g.setColor(Color.BLACK);
super.paintText(context, g, text, x+1, y+1, mnemonicIndex);
g.setColor(Color.WHITE);
}
super.paintText(context, g, text, x, y, mnemonicIndex);
}
/**
......
/*
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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 @@ class GTKIconFactory {
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 ||
......
/*
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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
......@@ -52,7 +52,8 @@ import sun.swing.SwingUtilities2;
* @author Scott Violet
*/
public class GTKLookAndFeel extends SynthLookAndFeel {
private static final boolean IS_22;
private static boolean IS_22;
private static boolean IS_3;
/**
* Whether or not text is drawn antialiased. This keys off the
......@@ -105,16 +106,6 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
private static String gtkThemeName = "Default";
static {
// Backup for specifying the version, this isn't currently documented.
// If you pass in anything but 2.2 you got the 2.0 colors/look.
String version = AccessController.doPrivileged(
new GetPropertyAction("swing.gtk.version"));
if (version != null) {
IS_22 = version.equals("2.2");
}
else {
IS_22 = true;
}
String language = Locale.getDefault().getLanguage();
boolean cjkLocale =
......@@ -156,6 +147,10 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
return IS_22;
}
static boolean is3() {
return IS_3;
}
/**
* Maps a swing constant to a GTK constant.
*/
......@@ -545,7 +540,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
public Object createValue(UIDefaults table) {
GTKStyleFactory factory = (GTKStyleFactory)getStyleFactory();
GTKStyle style = (GTKStyle)factory.getStyle(null, region);
return style.getFontForState(null);
return style.getDefaultFont();
}
}
......@@ -1457,6 +1452,19 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
throw new InternalError("Unable to load native GTK libraries");
}
if (UNIXToolkit.getGtkVersion() == UNIXToolkit.GtkVersions.GTK2) {
String version = AccessController.doPrivileged(
new GetPropertyAction("jdk.gtk.version"));
if (version != null) {
IS_22 = version.equals("2.2");
} else {
IS_22 = true;
}
} else if (UNIXToolkit.getGtkVersion() ==
UNIXToolkit.GtkVersions.GTK3) {
IS_3 = true;
}
super.initialize();
inInitialize = true;
loadStyles();
......
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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
......@@ -26,6 +26,8 @@ package com.sun.java.swing.plaf.gtk;
import sun.awt.UNIXToolkit;
import sun.awt.ModalExclude;
import sun.awt.SunToolkit;
import javax.swing.plaf.synth.*;
import java.awt.*;
import javax.swing.*;
......@@ -36,6 +38,7 @@ import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -567,8 +570,10 @@ class GTKPainter extends SynthPainter {
Region id = context.getRegion();
int gtkState = GTKLookAndFeel.synthStateToGTKState(
id, context.getComponentState());
boolean isHW = SunToolkit.getHeavyweightComponent(
context.getComponent()) instanceof ModalExclude;
synchronized (UNIXToolkit.GTK_LOCK) {
if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, isHW)) {
return;
}
ENGINE.startPainting(g, x, y, w, h, id, gtkState);
......@@ -582,7 +587,25 @@ class GTKPainter extends SynthPainter {
style.getGTKColor(context, gtkState, GTKColorType.BACKGROUND),
x + xThickness, y + yThickness,
w - xThickness - xThickness, h - yThickness - yThickness);
ENGINE.finishPainting();
BufferedImage img = ENGINE.finishPainting();
if(!isHW) {
int border = img.getRGB(0, h / 2);
if (img != null && border == img.getRGB(w / 2, h / 2)) {
// fix no menu borders in Adwaita theme
Graphics g2 = img.getGraphics();
Color c = new Color(border);
g2.setColor(new Color(Math.max((int) (c.getRed() * 0.8), 0),
Math.max((int) (c.getGreen() * 0.8), 0),
Math.max((int) (c.getBlue() * 0.8), 0)));
g2.drawLine(0, 0, w - 1, 0);
g2.drawLine(w - 1, 0, w - 1, h - 1);
g2.drawLine(0, h - 1, 0, 1);
g2.setColor(c.darker());
g2.drawLine(w - 1, h - 1, 0, h - 1);
g2.dispose();
g.drawImage(img, x, y, null);
}
}
}
}
......@@ -699,6 +722,17 @@ class GTKPainter extends SynthPainter {
} else {
h -= (insets.top + insets.bottom);
}
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) {
......@@ -743,6 +777,15 @@ class GTKPainter extends SynthPainter {
// The ubuntulooks engine paints slider troughs differently depending
// on the current slider value and its component orientation.
JSlider slider = (JSlider)context.getComponent();
if (GTKLookAndFeel.is3()) {
if (slider.getOrientation() == JSlider.VERTICAL) {
y += 1;
h -= 2;
} else {
x += 1;
w -= 2;
}
}
double value = slider.getValue();
double min = slider.getMinimum();
double max = slider.getMaximum();
......@@ -776,15 +819,17 @@ class GTKPainter extends SynthPainter {
Region id = context.getRegion();
int gtkState = GTKLookAndFeel.synthStateToGTKState(
id, context.getComponentState());
boolean hasFocus = GTKLookAndFeel.is3() &&
((context.getComponentState() & SynthConstants.FOCUSED) != 0);
synchronized (UNIXToolkit.GTK_LOCK) {
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir)) {
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir, hasFocus)) {
Orientation orientation = (dir == JSlider.HORIZONTAL ?
Orientation.HORIZONTAL : Orientation.VERTICAL);
String detail = (dir == JSlider.HORIZONTAL ?
"hscale" : "vscale");
ENGINE.startPainting(g, x, y, w, h, id, gtkState, dir);
ENGINE.paintSlider(g, context, id, gtkState,
ShadowType.OUT, detail, x, y, w, h, orientation);
ShadowType.OUT, detail, x, y, w, h, orientation, hasFocus);
ENGINE.finishPainting();
}
}
......@@ -963,15 +1008,21 @@ class GTKPainter extends SynthPainter {
int yThickness = style.getYThickness();
ENGINE.startPainting(g, x, y, w, h, id, state);
if (GTKLookAndFeel.is3()) {
ENGINE.paintBackground(g, context, id, gtkState, null,
x, y, w, h);
}
ENGINE.paintShadow(g, context, id, gtkState,
ShadowType.IN, "entry", x, y, w, h);
ENGINE.paintFlatBox(g, context, id,
gtkState, ShadowType.NONE, "entry_bg",
x + xThickness,
y + yThickness,
w - (2 * xThickness),
h - (2 * yThickness),
ColorType.TEXT_BACKGROUND);
if (!GTKLookAndFeel.is3()) {
ENGINE.paintFlatBox(g, context, id,
gtkState, ShadowType.NONE, "entry_bg",
x + xThickness,
y + yThickness,
w - (2 * xThickness),
h - (2 * yThickness),
ColorType.TEXT_BACKGROUND);
}
if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) {
if (!interiorFocus) {
......@@ -982,14 +1033,14 @@ class GTKPainter extends SynthPainter {
} else {
if (containerParent instanceof JComboBox) {
x += (focusSize + 2);
y += (focusSize + 1);
w -= (2 * focusSize + 1);
h -= (2 * focusSize + 2);
y += focusSize + (GTKLookAndFeel.is3() ? 3 : 1);
w -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 1);
h -= 2 * focusSize + (GTKLookAndFeel.is3() ? 6 : 2);
} else {
x += focusSize;
y += focusSize;
w -= 2 * focusSize;
h -= 2 * focusSize;
x += focusSize + (GTKLookAndFeel.is3() ? 2 : 0);
y += focusSize + (GTKLookAndFeel.is3() ? 2 :0 );
w -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 0);
h -= 2 * focusSize + (GTKLookAndFeel.is3() ? 4 : 0);
}
}
ENGINE.paintFocus(g, context, id, gtkState,
......@@ -1139,7 +1190,7 @@ class GTKPainter extends SynthPainter {
Orientation.HORIZONTAL : Orientation.VERTICAL);
ENGINE.setRangeValue(context, id, value, min, max, visible);
ENGINE.paintSlider(g, context, id, gtkState,
ShadowType.OUT, "slider", x, y, w, h, orientation);
ShadowType.OUT, "slider", x, y, w, h, orientation, false);
ENGINE.finishPainting();
}
}
......@@ -1295,14 +1346,14 @@ class GTKPainter extends SynthPainter {
Graphics g, int state, int x, int y, int w, int h) {
ENGINE.paintExpander(g, context, Region.TREE,
GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
ExpanderStyle.EXPANDED, "treeview", x, y, w, h);
ExpanderStyle.EXPANDED, "expander", x, y, w, h);
}
public void paintTreeCollapsedIcon(SynthContext context,
Graphics g, int state, int x, int y, int w, int h) {
ENGINE.paintExpander(g, context, Region.TREE,
GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
ExpanderStyle.COLLAPSED, "treeview", x, y, w, h);
ExpanderStyle.COLLAPSED, "expander", x, y, w, h);
}
public void paintCheckBoxIcon(SynthContext context,
......@@ -1337,8 +1388,13 @@ class GTKPainter extends SynthPainter {
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,
......
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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
......@@ -278,7 +278,17 @@ class GTKStyle extends SynthStyle implements GTKConstants {
return getColorForState(context, type);
}
Font getDefaultFont() {
return font;
}
protected Font getFontForState(SynthContext context) {
Font propFont = UIManager
.getFont(context.getRegion().getName() + ".font");
if (propFont != null) {
// if font property got a value then return it
return propFont;
}
return font;
}
......@@ -711,29 +721,33 @@ class GTKStyle extends SynthStyle implements GTKConstants {
if (region == Region.COMBO_BOX ||
region == Region.DESKTOP_PANE ||
region == Region.DESKTOP_ICON ||
region == Region.EDITOR_PANE ||
region == Region.FORMATTED_TEXT_FIELD ||
region == Region.INTERNAL_FRAME ||
region == Region.LIST ||
region == Region.MENU_BAR ||
region == Region.PANEL ||
region == Region.PASSWORD_FIELD ||
region == Region.POPUP_MENU ||
region == Region.PROGRESS_BAR ||
region == Region.ROOT_PANE ||
region == Region.SCROLL_PANE ||
region == Region.SPINNER ||
region == Region.SPLIT_PANE_DIVIDER ||
region == Region.TABLE ||
region == Region.TEXT_AREA ||
region == Region.TEXT_FIELD ||
region == Region.TEXT_PANE ||
region == Region.TOOL_BAR_DRAG_WINDOW ||
region == Region.TOOL_TIP ||
region == Region.TREE ||
region == Region.VIEWPORT) {
return true;
}
if (!GTKLookAndFeel.is3()) {
if (region == Region.EDITOR_PANE ||
region == Region.FORMATTED_TEXT_FIELD ||
region == Region.PASSWORD_FIELD ||
region == Region.SPINNER ||
region == Region.TEXT_FIELD ||
region == Region.TEXT_PANE) {
return true;
}
}
Component c = context.getComponent();
String name = c.getName();
if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
......@@ -829,6 +843,14 @@ class GTKStyle extends SynthStyle implements GTKConstants {
int focusPad =
getClassSpecificIntValue(context, "focus-padding", 1);
return indicatorSpacing + focusSize + focusPad;
} else if (GTKLookAndFeel.is3() && "ComboBox.forceOpaque".equals(key)) {
return true;
} else if ("Tree.expanderSize".equals(key)) {
Object value = getClassSpecificValue("expander-size");
if (value instanceof Integer) {
return (Integer)value + 4;
}
return null;
}
// Is it a stock icon ?
......@@ -1108,9 +1130,9 @@ class GTKStyle extends SynthStyle implements GTKConstants {
static {
CLASS_SPECIFIC_MAP = new HashMap<String,String>();
CLASS_SPECIFIC_MAP.put("Slider.thumbHeight", "slider-width");
CLASS_SPECIFIC_MAP.put("Slider.thumbWidth", "slider-length");
CLASS_SPECIFIC_MAP.put("Slider.trackBorder", "trough-border");
CLASS_SPECIFIC_MAP.put("SplitPane.size", "handle-size");
CLASS_SPECIFIC_MAP.put("Tree.expanderSize", "expander-size");
CLASS_SPECIFIC_MAP.put("ScrollBar.thumbHeight", "slider-width");
CLASS_SPECIFIC_MAP.put("ScrollBar.width", "slider-width");
CLASS_SPECIFIC_MAP.put("TextArea.caretForeground", "cursor-color");
......
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2018, 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
......@@ -29,9 +29,11 @@ import static java.awt.RenderingHints.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetIntegerAction;
import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
import sun.java2d.opengl.OGLRenderQueue;
import sun.security.action.GetPropertyAction;
public abstract class UNIXToolkit extends SunToolkit
{
......@@ -42,6 +44,40 @@ public abstract class UNIXToolkit extends SunToolkit
private static final int[] BAND_OFFSETS_ALPHA = { 0, 1, 2, 3 };
private static final int DEFAULT_DATATRANSFER_TIMEOUT = 10000;
// Allowed GTK versions
public enum GtkVersions {
ANY(0),
GTK2(Constants.GTK2_MAJOR_NUMBER),
GTK3(Constants.GTK3_MAJOR_NUMBER);
static class Constants {
static final int GTK2_MAJOR_NUMBER = 2;
static final int GTK3_MAJOR_NUMBER = 3;
}
final int number;
GtkVersions(int number) {
this.number = number;
}
public static GtkVersions getVersion(int number) {
switch (number) {
case Constants.GTK2_MAJOR_NUMBER:
return GTK2;
case Constants.GTK3_MAJOR_NUMBER:
return GTK3;
default:
return ANY;
}
}
// major GTK version number
public int getNumber() {
return number;
}
};
private Boolean nativeGTKAvailable;
private Boolean nativeGTKLoaded;
private BufferedImage tmpImage = null;
......@@ -79,7 +115,7 @@ public abstract class UNIXToolkit extends SunToolkit
return nativeGTKAvailable;
} else {
boolean success = check_gtk();
boolean success = check_gtk(getEnabledGtkVersion().getNumber());
nativeGTKAvailable = success;
return success;
}
......@@ -97,7 +133,8 @@ public abstract class UNIXToolkit extends SunToolkit
public boolean loadGTK() {
synchronized (GTK_LOCK) {
if (nativeGTKLoaded == null) {
nativeGTKLoaded = load_gtk();
nativeGTKLoaded = load_gtk(getEnabledGtkVersion().getNumber(),
isGtkVerbose());
}
}
return nativeGTKLoaded;
......@@ -240,14 +277,15 @@ public abstract class UNIXToolkit extends SunToolkit
tmpImage = new BufferedImage(colorModel, raster, false, null);
}
private static native boolean check_gtk();
private static native boolean load_gtk();
private static native boolean check_gtk(int version);
private static native boolean load_gtk(int version, boolean verbose);
private static native boolean unload_gtk();
private native boolean load_gtk_icon(String filename);
private native boolean load_stock_icon(int widget_type, String stock_id,
int iconSize, int textDirection, String detail);
private native void nativeSync();
private static native int get_gtk_version();
@Override
public void sync() {
......@@ -337,4 +375,26 @@ public abstract class UNIXToolkit extends SunToolkit
}
return false;
}
public static GtkVersions getEnabledGtkVersion() {
String version = AccessController.doPrivileged(
new GetPropertyAction("jdk.gtk.version"));
if (version == null) {
return GtkVersions.ANY;
} else if (version.startsWith("2")) {
return GtkVersions.GTK2;
} else if("3".equals(version) ){
return GtkVersions.GTK3;
}
return GtkVersions.ANY;
}
public static GtkVersions getGtkVersion() {
return GtkVersions.getVersion(get_gtk_version());
}
public static boolean isGtkVerbose() {
return AccessController.doPrivileged((PrivilegedAction<Boolean>)()
-> Boolean.getBoolean("jdk.gtk.verbose"));
}
}
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2018, 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
......@@ -25,6 +25,7 @@
package sun.awt.X11;
import sun.awt.UNIXToolkit;
import java.io.File;
import java.io.IOException;
......@@ -57,7 +58,8 @@ public class XDesktopPeer implements DesktopPeer {
XToolkit.awtLock();
try {
if (!initExecuted) {
nativeLibraryLoaded = init();
nativeLibraryLoaded = init(UNIXToolkit.getEnabledGtkVersion()
.getNumber(), UNIXToolkit.isGtkVerbose());
}
} finally {
initExecuted = true;
......@@ -123,5 +125,5 @@ public class XDesktopPeer implements DesktopPeer {
}
private native boolean gnome_url_show(byte[] url);
private static native boolean init();
private static native boolean init(int gtkVersion, boolean verbose);
}
......@@ -1125,7 +1125,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public FileDialogPeer createFileDialog(FileDialog target) {
FileDialogPeer peer = null;
// The current GtkFileChooser is available from GTK+ 2.4
if (!getSunAwtDisableGtkFileDialogs() && checkGtkVersion(2, 4, 0)) {
if (!getSunAwtDisableGtkFileDialogs() &&
(checkGtkVersion(2, 4, 0) || checkGtkVersion(3, 0, 0))) {
peer = new GtkFileDialogPeer(target);
} else {
peer = new XFileDialogPeer(target);
......
/*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2018, 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
......@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <sys/time.h>
#include "awt.h"
......
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2018, 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
......@@ -34,7 +34,7 @@
#ifndef HEADLESS
#include "awt.h"
#include "gtk2_interface.h"
#include "gtk_interface.h"
#endif /* !HEADLESS */
......@@ -45,13 +45,12 @@ static jmethodID icon_upcall_method = NULL;
/*
* Class: sun_awt_UNIXToolkit
* Method: check_gtk
* Signature: ()Z
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass)
{
Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass, jint version) {
#ifndef HEADLESS
return (jboolean)gtk2_check_version();
return (jboolean)gtk_check_version(version);
#else
return JNI_FALSE;
#endif /* !HEADLESS */
......@@ -61,13 +60,13 @@ Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass)
/*
* Class: sun_awt_UNIXToolkit
* Method: load_gtk
* Signature: ()Z
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass)
{
Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass, jint version,
jboolean verbose) {
#ifndef HEADLESS
return (jboolean)gtk2_load(env);
return (jboolean)gtk_load(env, version, verbose);
#else
return JNI_FALSE;
#endif /* !HEADLESS */
......@@ -83,16 +82,14 @@ JNIEXPORT jboolean JNICALL
Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass)
{
#ifndef HEADLESS
return (jboolean)gtk2_unload();
return (jboolean)gtk->unload();
#else
return JNI_FALSE;
#endif /* !HEADLESS */
}
jboolean _icon_upcall(JNIEnv *env, jobject this, GdkPixbuf *pixbuf)
jboolean init_method(JNIEnv *env, jobject this)
{
jboolean result = JNI_FALSE;
if (this_class == NULL) {
this_class = (*env)->NewGlobalRef(env,
(*env)->GetObjectClass(env, this));
......@@ -101,32 +98,7 @@ jboolean _icon_upcall(JNIEnv *env, jobject this, GdkPixbuf *pixbuf)
CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
}
if (pixbuf != NULL)
{
guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
int row_stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
int width = (*fp_gdk_pixbuf_get_width)(pixbuf);
int height = (*fp_gdk_pixbuf_get_height)(pixbuf);
int bps = (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf);
int channels = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
gboolean alpha = (*fp_gdk_pixbuf_get_has_alpha)(pixbuf);
/* Copy the data array into a Java structure so we can pass it back. */
jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
(*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
(jbyte *)pixbuf_data);
/* Release the pixbuf. */
(*fp_g_object_unref)(pixbuf);
/* Call the callback method to create the image on the Java side. */
(*env)->CallVoidMethod(env, this, icon_upcall_method, data,
width, height, row_stride, bps, channels, alpha);
result = JNI_TRUE;
}
return result;
return JNI_TRUE;
}
/*
......@@ -144,7 +116,6 @@ Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
int len;
char *filename_str = NULL;
GError **error = NULL;
GdkPixbuf *pixbuf;
if (filename == NULL)
{
......@@ -158,13 +129,18 @@ Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
return JNI_FALSE;
}
if (!init_method(env, this) ) {
free(filename_str);
return JNI_FALSE;
}
(*env)->GetStringUTFRegion(env, filename, 0, len, filename_str);
pixbuf = (*fp_gdk_pixbuf_new_from_file)(filename_str, error);
jboolean result = gtk->get_file_icon_data(env, filename_str, error,
icon_upcall_method, this);
/* Release the strings we've allocated. */
free(filename_str);
return _icon_upcall(env, this, pixbuf);
return result;
#else /* HEADLESS */
return JNI_FALSE;
#endif /* !HEADLESS */
......@@ -186,7 +162,6 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
int len;
char *stock_id_str = NULL;
char *detail_str = NULL;
GdkPixbuf *pixbuf;
if (stock_id == NULL)
{
......@@ -215,8 +190,12 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
(*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
}
pixbuf = gtk2_get_stock_icon(widget_type, stock_id_str, icon_size,
text_direction, detail_str);
if (!init_method(env, this) ) {
return JNI_FALSE;
}
jboolean result = gtk->get_icon_data(env, widget_type, stock_id_str,
icon_size, text_direction, detail_str,
icon_upcall_method, this);
/* Release the strings we've allocated. */
free(stock_id_str);
......@@ -225,7 +204,7 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
free(detail_str);
}
return _icon_upcall(env, this, pixbuf);
return result;
#else /* HEADLESS */
return JNI_FALSE;
#endif /* !HEADLESS */
......@@ -279,11 +258,25 @@ Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this,
{
char *ret;
ret = fp_gtk_check_version(major, minor, micro);
ret = gtk->gtk_check_version(major, minor, micro);
if (ret == NULL) {
return TRUE;
}
free(ret);
return FALSE;
}
/*
* Class: sun_awt_UNIXToolkit
* Method: get_gtk_version
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_sun_awt_UNIXToolkit_get_1gtk_1version(JNIEnv *env, jclass klass)
{
#ifndef HEADLESS
return gtk ? gtk->version : GTK_ANY;
#else
return GTK_ANY;
#endif /* !HEADLESS */
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2018, 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
......@@ -579,7 +579,7 @@ static void update_poll_timeout(int timeout_control) {
*/
static uint32_t get_poll_timeout(jlong nextTaskTime)
{
uint32_t ret_timeout;
uint32_t ret_timeout = 0;
uint32_t timeout;
uint32_t taskTimeout;
uint32_t flushTimeout;
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, 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
......@@ -25,7 +25,7 @@
#ifndef _GNOME_INTERFACE_H
#define _GNOME_INTERFACE_H
#include "gtk2_interface.h"
#include "gtk_interface.h"
#include <dlfcn.h>
#include <jvm_md.h>
#include <jni.h>
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册