From 84d39544eec45a48c26df84c30d9bafa3d90fb3e Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Mon, 7 Sep 2020 16:22:23 +0700 Subject: [PATCH] Remove awt_xawt --- .../java/net/kdt/pojavlaunch/JREUtils.java | 2 +- .../net/kdt/pojavlaunch/MainActivity.java | 5 +- app/src/main/jni/Android.mk | 12 +- app/src/main/jni/awt_xawt/awt/HPkeysym.h | 165 - app/src/main/jni/awt_xawt/awt/Xrandr.h | 233 -- app/src/main/jni/awt_xawt/awt/awt_AWTEvent.c | 75 - app/src/main/jni/awt_xawt/awt/awt_AWTEvent.h | 56 - .../jni/awt_xawt/awt/awt_DrawingSurface.c | 430 --- app/src/main/jni/awt_xawt/awt/awt_Event.c | 48 - app/src/main/jni/awt_xawt/awt/awt_Event.h | 43 - .../main/jni/awt_xawt/awt/awt_GraphicsEnv.c | 2266 ------------- .../main/jni/awt_xawt/awt/awt_InputMethod.c | 1651 ---------- app/src/main/jni/awt_xawt/awt/awt_Insets.c | 41 - app/src/main/jni/awt_xawt/awt/awt_Insets.h | 33 - .../main/jni/awt_xawt/awt/awt_MenuComponent.h | 32 - app/src/main/jni/awt_xawt/awt/awt_Robot.c | 524 --- .../main/jni/awt_xawt/awt/awt_UNIXToolkit.c | 280 -- app/src/main/jni/awt_xawt/awt/awt_util.c | 104 - app/src/main/jni/awt_xawt/awt/canvas.h | 32 - .../main/jni/awt_xawt/awt/gtk2_interface.c | 2628 --------------- .../main/jni/awt_xawt/awt/gtk2_interface.h | 452 --- .../main/jni/awt_xawt/awt/gtk3_interface.c | 2914 ----------------- .../main/jni/awt_xawt/awt/gtk3_interface.h | 577 ---- app/src/main/jni/awt_xawt/awt/gtk_interface.c | 162 - app/src/main/jni/awt_xawt/awt/gtk_interface.h | 570 ---- app/src/main/jni/awt_xawt/awt/list.c | 323 -- app/src/main/jni/awt_xawt/awt/list.h | 149 - app/src/main/jni/awt_xawt/awt/multiVis.c | 1215 ------- app/src/main/jni/awt_xawt/awt/multiVis.h | 90 - app/src/main/jni/awt_xawt/awt/multi_font.c | 393 --- app/src/main/jni/awt_xawt/awt/multi_font.h | 40 - app/src/main/jni/awt_xawt/awt/randr.h | 79 - app/src/main/jni/awt_xawt/awt/robot_common.c | 101 - app/src/main/jni/awt_xawt/awt/robot_common.h | 39 - .../awt/sun_awt_X11_GtkFileDialogPeer.c | 419 --- .../main/jni/awt_xawt/awt/swing_GTKEngine.c | 375 --- .../main/jni/awt_xawt/awt/swing_GTKStyle.c | 112 - app/src/main/jni/awt_xawt/awt/wsutils.h | 380 --- .../jni/awt_xawt/java2d/x11/XRBackendNative.c | 1112 ------- .../jni/awt_xawt/java2d/x11/XRSurfaceData.c | 145 - app/src/main/jni/awt_xawt/xawt/XToolkit.c | 1090 ------ app/src/main/jni/awt_xawt/xawt/XWindow.c | 1290 -------- app/src/main/jni/awt_xawt/xawt/XlibWrapper.c | 2361 ------------- app/src/main/jni/awt_xawt/xawt/awt_Desktop.c | 87 - app/src/main/jni/awt_xawt/xawt/awt_Taskbar.c | 257 -- app/src/main/jni/awt_xawt/xawt/awt_Taskbar.h | 58 - .../main/jni/awt_xawt/xawt/gnome_interface.c | 87 - .../main/jni/awt_xawt/xawt/gnome_interface.h | 39 - app/src/main/jni/egl_bridge.c | 14 +- 49 files changed, 12 insertions(+), 23578 deletions(-) delete mode 100644 app/src/main/jni/awt_xawt/awt/HPkeysym.h delete mode 100644 app/src/main/jni/awt_xawt/awt/Xrandr.h delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_AWTEvent.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_AWTEvent.h delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_DrawingSurface.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_Event.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_Event.h delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_GraphicsEnv.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_InputMethod.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_Insets.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_Insets.h delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_MenuComponent.h delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_Robot.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_UNIXToolkit.c delete mode 100644 app/src/main/jni/awt_xawt/awt/awt_util.c delete mode 100644 app/src/main/jni/awt_xawt/awt/canvas.h delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk2_interface.c delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk2_interface.h delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk3_interface.c delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk3_interface.h delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk_interface.c delete mode 100644 app/src/main/jni/awt_xawt/awt/gtk_interface.h delete mode 100644 app/src/main/jni/awt_xawt/awt/list.c delete mode 100644 app/src/main/jni/awt_xawt/awt/list.h delete mode 100644 app/src/main/jni/awt_xawt/awt/multiVis.c delete mode 100644 app/src/main/jni/awt_xawt/awt/multiVis.h delete mode 100644 app/src/main/jni/awt_xawt/awt/multi_font.c delete mode 100644 app/src/main/jni/awt_xawt/awt/multi_font.h delete mode 100644 app/src/main/jni/awt_xawt/awt/randr.h delete mode 100644 app/src/main/jni/awt_xawt/awt/robot_common.c delete mode 100644 app/src/main/jni/awt_xawt/awt/robot_common.h delete mode 100644 app/src/main/jni/awt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c delete mode 100644 app/src/main/jni/awt_xawt/awt/swing_GTKEngine.c delete mode 100644 app/src/main/jni/awt_xawt/awt/swing_GTKStyle.c delete mode 100644 app/src/main/jni/awt_xawt/awt/wsutils.h delete mode 100644 app/src/main/jni/awt_xawt/java2d/x11/XRBackendNative.c delete mode 100644 app/src/main/jni/awt_xawt/java2d/x11/XRSurfaceData.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/XToolkit.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/XWindow.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/XlibWrapper.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/awt_Desktop.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/awt_Taskbar.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/awt_Taskbar.h delete mode 100644 app/src/main/jni/awt_xawt/xawt/gnome_interface.c delete mode 100644 app/src/main/jni/awt_xawt/xawt/gnome_interface.h diff --git a/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java b/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java index 90ce44672..c4dd7895a 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java +++ b/app/src/main/java/net/kdt/pojavlaunch/JREUtils.java @@ -20,7 +20,7 @@ public class JREUtils } public static File redirectStdio(boolean current) throws ErrnoException { - File logFile = new File(Tools.datapath, (current ? "current" : "latest") + "log.txt"); + File logFile = new File(current ? Tools.datapath : Tools.MAIN_PATH, (current ? "current" : "latest") + "log.txt"); FileDescriptor fd = Os.open(logFile.getAbsolutePath(), OsConstants.O_WRONLY | OsConstants.O_CREAT | OsConstants.O_TRUNC, 0666); Os.dup2(fd, OsConstants.STDERR_FILENO); diff --git a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java index b85d88a3c..b95a6c398 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -837,7 +837,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener, private FileObserver mLogObserver; private void runCraft() throws Throwable { if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) { - final File currLogFile = JREUtils.redirectStdio(false); + final File currLogFile = JREUtils.redirectStdio(true); // DEPRECATED constructor (String) api 29 mLogObserver = new FileObserver(currLogFile.getAbsolutePath(), FileObserver.MODIFY){ @Override @@ -848,7 +848,8 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener, Tools.write(file, ""); } } catch (Throwable th) { - th.printStackTrace(); + Tools.showError(MainActivity.this, th); + mLogObserver.stopWatching(); } } }; diff --git a/app/src/main/jni/Android.mk b/app/src/main/jni/Android.mk index c35b890ba..8c5a43b11 100644 --- a/app/src/main/jni/Android.mk +++ b/app/src/main/jni/Android.mk @@ -16,16 +16,6 @@ LOCAL_PATH := $(LOCAL_PATH)/awt_xawt include $(CLEAR_VARS) LOCAL_MODULE := awt_xawt LOCAL_CFLAGS += -DHEADLESS -LOCAL_SRC_FILES := \ - xawt_fake.c -# awt/awt_AWTEvent.c \ -# awt/awt_DrawingSurface.c \ -# awt/awt_Event.c \ -# awt/awt_GraphicsEnv.c \ -# awt/awt_InputMethod.c \ -# awt/awt_Insets.c \ -# awt/awt_Robot.c \ - - +LOCAL_SRC_FILES := xawt_fake.c include $(BUILD_SHARED_LIBRARY) diff --git a/app/src/main/jni/awt_xawt/awt/HPkeysym.h b/app/src/main/jni/awt_xawt/awt/HPkeysym.h deleted file mode 100644 index f736e7521..000000000 --- a/app/src/main/jni/awt_xawt/awt/HPkeysym.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* $Xorg: HPkeysym.h,v 1.4 2000/08/18 04:05:43 coskrey Exp $ */ -/* - -Copyright 1987, 1998 The Open Group - -All Rights Reserved. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Hewlett Packard -or Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD -TO THIS SOFWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. Hewlett-Packard shall not be liable for errors -contained herein or direct, indirect, special, incidental or -consequential damages in connection with the furnishing, -performance, or use of this material. - -*/ - -#ifndef _HPKEYSYM_H - -#define _HPKEYSYM_H - -#define hpXK_ClearLine 0x1000FF6F -#define hpXK_InsertLine 0x1000FF70 -#define hpXK_DeleteLine 0x1000FF71 -#define hpXK_InsertChar 0x1000FF72 -#define hpXK_DeleteChar 0x1000FF73 -#define hpXK_BackTab 0x1000FF74 -#define hpXK_KP_BackTab 0x1000FF75 -#define hpXK_Modelock1 0x1000FF48 -#define hpXK_Modelock2 0x1000FF49 -#define hpXK_Reset 0x1000FF6C -#define hpXK_System 0x1000FF6D -#define hpXK_User 0x1000FF6E -#define hpXK_mute_acute 0x100000A8 -#define hpXK_mute_grave 0x100000A9 -#define hpXK_mute_asciicircum 0x100000AA -#define hpXK_mute_diaeresis 0x100000AB -#define hpXK_mute_asciitilde 0x100000AC -#define hpXK_lira 0x100000AF -#define hpXK_guilder 0x100000BE -#define hpXK_Ydiaeresis 0x100000EE -#define hpXK_IO 0x100000EE -#define hpXK_longminus 0x100000F6 -#define hpXK_block 0x100000FC - - -#ifndef _OSF_Keysyms -#define _OSF_Keysyms - -#define osfXK_Copy 0x1004FF02 -#define osfXK_Cut 0x1004FF03 -#define osfXK_Paste 0x1004FF04 -#define osfXK_BackTab 0x1004FF07 -#define osfXK_BackSpace 0x1004FF08 -#define osfXK_Clear 0x1004FF0B -#define osfXK_Escape 0x1004FF1B -#define osfXK_AddMode 0x1004FF31 -#define osfXK_PrimaryPaste 0x1004FF32 -#define osfXK_QuickPaste 0x1004FF33 -#define osfXK_PageLeft 0x1004FF40 -#define osfXK_PageUp 0x1004FF41 -#define osfXK_PageDown 0x1004FF42 -#define osfXK_PageRight 0x1004FF43 -#define osfXK_Activate 0x1004FF44 -#define osfXK_MenuBar 0x1004FF45 -#define osfXK_Left 0x1004FF51 -#define osfXK_Up 0x1004FF52 -#define osfXK_Right 0x1004FF53 -#define osfXK_Down 0x1004FF54 -#define osfXK_EndLine 0x1004FF57 -#define osfXK_BeginLine 0x1004FF58 -#define osfXK_EndData 0x1004FF59 -#define osfXK_BeginData 0x1004FF5A -#define osfXK_PrevMenu 0x1004FF5B -#define osfXK_NextMenu 0x1004FF5C -#define osfXK_PrevField 0x1004FF5D -#define osfXK_NextField 0x1004FF5E -#define osfXK_Select 0x1004FF60 -#define osfXK_Insert 0x1004FF63 -#define osfXK_Undo 0x1004FF65 -#define osfXK_Menu 0x1004FF67 -#define osfXK_Cancel 0x1004FF69 -#define osfXK_Help 0x1004FF6A -#define osfXK_SelectAll 0x1004FF71 -#define osfXK_DeselectAll 0x1004FF72 -#define osfXK_Reselect 0x1004FF73 -#define osfXK_Extend 0x1004FF74 -#define osfXK_Restore 0x1004FF78 -#define osfXK_Delete 0x1004FFFF - -#endif /* _OSF_Keysyms */ - - -/************************************************************** - * The use of the following macros is deprecated. - * They are listed below only for backwards compatibility. - */ -#define XK_Reset 0x1000FF6C -#define XK_System 0x1000FF6D -#define XK_User 0x1000FF6E -#define XK_ClearLine 0x1000FF6F -#define XK_InsertLine 0x1000FF70 -#define XK_DeleteLine 0x1000FF71 -#define XK_InsertChar 0x1000FF72 -#define XK_DeleteChar 0x1000FF73 -#define XK_BackTab 0x1000FF74 -#define XK_KP_BackTab 0x1000FF75 -#define XK_Ext16bit_L 0x1000FF76 -#define XK_Ext16bit_R 0x1000FF77 -#define XK_mute_acute 0x100000a8 -#define XK_mute_grave 0x100000a9 -#define XK_mute_asciicircum 0x100000aa -#define XK_mute_diaeresis 0x100000ab -#define XK_mute_asciitilde 0x100000ac -#define XK_lira 0x100000af -#define XK_guilder 0x100000be -#ifndef XK_Ydiaeresis -#define XK_Ydiaeresis 0x100000ee -#endif -#define XK_IO 0x100000ee -#define XK_longminus 0x100000f6 -#define XK_block 0x100000fc - -#endif /* _HPKEYSYM_H */ diff --git a/app/src/main/jni/awt_xawt/awt/Xrandr.h b/app/src/main/jni/awt_xawt/awt/Xrandr.h deleted file mode 100644 index d9d91c586..000000000 --- a/app/src/main/jni/awt_xawt/awt/Xrandr.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * $XFree86: xc/lib/Xrandr/Xrandr.h,v 1.9 2002/09/29 23:39:44 keithp Exp $ - * - * Copyright © 2000 Compaq Computer Corporation, Inc. - * Copyright © 2002 Hewlett-Packard Company, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Compaq not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. HP makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL COMPAQ - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Jim Gettys, HP Labs, HP. - */ - -#ifndef _XRANDR_H_ -#define _XRANDR_H_ - -/*#include */ -#include "randr.h" - -#include - -_XFUNCPROTOBEGIN - - -typedef struct { - int width, height; - int mwidth, mheight; -} XRRScreenSize; - -/* - * Events. - */ - -typedef struct { - int type; /* event base */ - unsigned long serial; /* # of last request processed by server */ - Bool send_event; /* true if this came from a SendEvent request */ - Display *display; /* Display the event was read from */ - Window window; /* window which selected for this event */ - Window root; /* Root window for changed screen */ - Time timestamp; /* when the screen change occurred */ - Time config_timestamp; /* when the last configuration change */ - SizeID size_index; - SubpixelOrder subpixel_order; - Rotation rotation; - int width; - int height; - int mwidth; - int mheight; -} XRRScreenChangeNotifyEvent; - -typedef XID RROutput; -typedef XID RRCrtc; -typedef XID RRMode; - -typedef unsigned long XRRModeFlags; - -typedef struct { - RRMode id; - unsigned int width; - unsigned int height; - unsigned long dotClock; - unsigned int hSyncStart; - unsigned int hSyncEnd; - unsigned int hTotal; - unsigned int hSkew; - unsigned int vSyncStart; - unsigned int vSyncEnd; - unsigned int vTotal; - char *name; - unsigned int nameLength; - XRRModeFlags modeFlags; -} XRRModeInfo; - -typedef struct { - Time timestamp; - Time configTimestamp; - int ncrtc; - RRCrtc *crtcs; - int noutput; - RROutput *outputs; - int nmode; - XRRModeInfo *modes; -} XRRScreenResources; - -typedef struct { - Time timestamp; - RRCrtc crtc; - char *name; - int nameLen; - unsigned long mm_width; - unsigned long mm_height; - Connection connection; - SubpixelOrder subpixel_order; - int ncrtc; - RRCrtc *crtcs; - int nclone; - RROutput *clones; - int nmode; - int npreferred; - RRMode *modes; -} XRROutputInfo; - -typedef struct { - Time timestamp; - int x, y; - unsigned int width, height; - RRMode mode; - Rotation rotation; - int noutput; - RROutput *outputs; - Rotation rotations; - int npossible; - RROutput *possible; -} XRRCrtcInfo; - -XRRScreenResources *XRRGetScreenResources (Display *dpy, Window window); - -void XRRFreeScreenResources (XRRScreenResources *resources); - -XRROutputInfo * XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, - RROutput output); -void XRRFreeOutputInfo (XRROutputInfo *outputInfo); - -XRRCrtcInfo *XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, - RRCrtc crtc); -void XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo); - - -/* internal representation is private to the library */ -typedef struct _XRRScreenConfiguration XRRScreenConfiguration; - -Bool XRRQueryExtension (Display *dpy, int *event_basep, int *error_basep); -Status XRRQueryVersion (Display *dpy, - int *major_versionp, - int *minor_versionp); - -XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, - Drawable draw); - -void XRRFreeScreenConfigInfo (XRRScreenConfiguration *config); - -/* - * Note that screen configuration changes are only permitted if the client can - * prove it has up to date configuration information. We are trying to - * insist that it become possible for screens to change dynamically, so - * we want to ensure the client knows what it is talking about when requesting - * changes. - */ -Status XRRSetScreenConfig (Display *dpy, - XRRScreenConfiguration *config, - Drawable draw, - int size_index, - Rotation rotation, - Time timestamp); - -/* added in v1.1, sorry for the lame name */ -Status XRRSetScreenConfigAndRate (Display *dpy, - XRRScreenConfiguration *config, - Drawable draw, - int size_index, - Rotation rotation, - short rate, - Time timestamp); - - -Rotation XRRConfigRotations(XRRScreenConfiguration *config, Rotation *current_rotation); - -Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp); - -XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes); - -short *XRRConfigRates (XRRScreenConfiguration *config, int sizeID, int *nrates); - -SizeID XRRConfigCurrentConfiguration (XRRScreenConfiguration *config, - Rotation *rotation); - -short XRRConfigCurrentRate (XRRScreenConfiguration *config); - -int XRRRootToScreen(Display *dpy, Window root); - -/* - * returns the screen configuration for the specified screen; does a lazy - * evalution to delay getting the information, and caches the result. - * These routines should be used in preference to XRRGetScreenInfo - * to avoid unneeded round trips to the X server. These are new - * in protocol version 0.1. - */ - - -XRRScreenConfiguration *XRRScreenConfig(Display *dpy, int screen); -XRRScreenConfiguration *XRRConfig(Screen *screen); -void XRRSelectInput(Display *dpy, Window window, int mask); - -/* - * the following are always safe to call, even if RandR is not implemented - * on a screen - */ - - -Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation); -XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes); -short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates); -Time XRRTimes (Display *dpy, int screen, Time *config_timestamp); - - -/* - * intended to take RRScreenChangeNotify, or - * ConfigureNotify (on the root window) - * returns 1 if it is an event type it understands, 0 if not - */ -int XRRUpdateConfiguration(XEvent *event); - -_XFUNCPROTOEND - -#endif /* _XRANDR_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.c b/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.c deleted file mode 100644 index 317e346e9..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1998, 2014, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* - * Implements the native code for the java.awt.AWTEvent class - * and all of the classes in the java.awt.event package. - * - * THIS FILE DOES NOT IMPLEMENT ANY OF THE OBSOLETE java.awt.Event - * CLASS. SEE awt_Event.[ch] FOR THAT CLASS' IMPLEMENTATION. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include "awt_p.h" -#include "java_awt_AWTEvent.h" -#include "java_awt_event_InputEvent.h" -#include "java_awt_event_KeyEvent.h" -#include "jni_util.h" - -#include "awt_AWTEvent.h" - -struct AWTEventIDs awtEventIDs; -struct InputEventIDs inputEventIDs; -struct KeyEventIDs keyEventIDs; - -JNIEXPORT void JNICALL -Java_java_awt_AWTEvent_initIDs(JNIEnv *env, jclass cls) -{ - CHECK_NULL(awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B")); - CHECK_NULL(awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z")); - CHECK_NULL(awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I")); -} - -JNIEXPORT void JNICALL -Java_java_awt_event_InputEvent_initIDs(JNIEnv *env, jclass cls) -{ - CHECK_NULL(inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I")); -} - -JNIEXPORT void JNICALL -Java_java_awt_event_KeyEvent_initIDs(JNIEnv *env, jclass cls) -{ - CHECK_NULL(keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I")); - CHECK_NULL(keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C")); -} - -JNIEXPORT void JNICALL -Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self, - jobject newSource) -{ - -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.h b/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.h deleted file mode 100644 index 4810621d9..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_AWTEvent.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1998, 2001, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* - * Implements the native code for the java.awt.AWTEvent class - * and all of the classes in the java.awt.event package. - * - * THIS FILE DOES NOT IMPLEMENT ANY OF THE OBSOLETE java.awt.Event - * CLASS. SEE awt_Event.[ch] FOR THAT CLASS' IMPLEMENTATION. - */ -#ifndef _AWT_AWTEVENT_H_ -#define _AWT_AWTEVENT_H_ - -#include "jni_util.h" - -struct AWTEventIDs { - jfieldID bdata; - jfieldID consumed; - jfieldID id; -}; - -struct InputEventIDs { - jfieldID modifiers; -}; - -struct KeyEventIDs { - jfieldID keyCode; - jfieldID keyChar; -}; - -extern struct AWTEventIDs awtEventIDs; -extern struct InputEventIDs inputEventIDs; -extern struct KeyEventIDs keyEventIDs; - -#endif /* _AWT_AWTEVENT_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/awt_DrawingSurface.c b/app/src/main/jni/awt_xawt/awt/awt_DrawingSurface.c deleted file mode 100644 index 1cc09c9ac..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_DrawingSurface.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (c) 1996, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include "awt_p.h" -#include "java_awt_Component.h" - -#include "awt_Component.h" - -#include -#include -#include - -extern struct ComponentIDs componentIDs; - -#include "awt_GraphicsEnv.h" -extern jfieldID windowID; -extern jfieldID targetID; -extern jfieldID graphicsConfigID; -extern jfieldID drawStateID; -extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; - -/* - * Lock the surface of the target component for native rendering. - * When finished drawing, the surface must be unlocked with - * Unlock(). This function returns a bitmask with one or more of the - * following values: - * - * JAWT_LOCK_ERROR - When an error has occurred and the surface could not - * be locked. - * - * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed. - * - * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed. - * - * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed - */ -JNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds) -{ - JNIEnv* env; - jobject target, peer; - jclass componentClass; - jint drawState; - - if (ds == NULL) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface is NULL\n"); -#endif - return (jint)JAWT_LOCK_ERROR; - } - env = ds->env; - target = ds->target; - - /* Make sure the target is a java.awt.Component */ - componentClass = (*env)->FindClass(env, "java/awt/Component"); - CHECK_NULL_RETURN(componentClass, (jint)JAWT_LOCK_ERROR); - - if (!(*env)->IsInstanceOf(env, target, componentClass)) { -#ifdef DEBUG - fprintf(stderr, "Target is not a component\n"); -#endif - return (jint)JAWT_LOCK_ERROR; - } - - if (!awtLockInited) { - return (jint)JAWT_LOCK_ERROR; - } - AWT_LOCK(); - - /* Get the peer of the target component */ - peer = (*env)->GetObjectField(env, target, componentIDs.peer); - if (JNU_IsNull(env, peer)) { -#ifdef DEBUG - fprintf(stderr, "Component peer is NULL\n"); -#endif - AWT_FLUSH_UNLOCK(); - return (jint)JAWT_LOCK_ERROR; - } - - drawState = (*env)->GetIntField(env, peer, drawStateID); - (*env)->SetIntField(env, peer, drawStateID, 0); - return drawState; -} - -JNIEXPORT int32_t JNICALL - awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b) -{ - JNIEnv* env; - jobject target, peer; - jclass componentClass; - AwtGraphicsConfigDataPtr adata; - int32_t result; - jobject gc_object; - if (ds == NULL) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface is NULL\n"); -#endif - return (int32_t) 0; - } - - env = ds->env; - target = ds->target; - - /* Make sure the target is a java.awt.Component */ - componentClass = (*env)->FindClass(env, "java/awt/Component"); - CHECK_NULL_RETURN(componentClass, (int32_t) 0); - - if (!(*env)->IsInstanceOf(env, target, componentClass)) { -#ifdef DEBUG - fprintf(stderr, "DrawingSurface target must be a component\n"); -#endif - return (int32_t) 0; - } - - if (!awtLockInited) { - return (int32_t) 0; - } - - AWT_LOCK(); - - /* Get the peer of the target component */ - peer = (*env)->GetObjectField(env, target, componentIDs.peer); - if (JNU_IsNull(env, peer)) { -#ifdef DEBUG - fprintf(stderr, "Component peer is NULL\n"); -#endif - AWT_UNLOCK(); - return (int32_t) 0; - } - /* GraphicsConfiguration object of MComponentPeer */ - gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID); - - if (gc_object != NULL) { - adata = (AwtGraphicsConfigDataPtr) - JNU_GetLongFieldAsPtr(env, gc_object, - x11GraphicsConfigIDs.aData); - } else { - adata = getDefaultConfig(DefaultScreen(awt_display)); - } - - result = adata->AwtColorMatch(r, g, b, adata); - AWT_UNLOCK(); - return result; -} - -/* - * Get the drawing surface info. - * The value returned may be cached, but the values may change if - * additional calls to Lock() or Unlock() are made. - * Lock() must be called before this can return a valid value. - * Returns NULL if an error has occurred. - * When finished with the returned value, FreeDrawingSurfaceInfo must be - * called. - */ -JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL -awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds) -{ - JNIEnv* env; - jobject target, peer; - jclass componentClass; - JAWT_X11DrawingSurfaceInfo* px; - JAWT_DrawingSurfaceInfo* p; - XWindowAttributes attrs; - - if (ds == NULL) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface is NULL\n"); -#endif - return NULL; - } - - env = ds->env; - target = ds->target; - - /* Make sure the target is a java.awt.Component */ - componentClass = (*env)->FindClass(env, "java/awt/Component"); - CHECK_NULL_RETURN(componentClass, NULL); - - if (!(*env)->IsInstanceOf(env, target, componentClass)) { -#ifdef DEBUG - fprintf(stderr, "DrawingSurface target must be a component\n"); -#endif - return NULL; - } - - if (!awtLockInited) { - return NULL; - } - - AWT_LOCK(); - - /* Get the peer of the target component */ - peer = (*env)->GetObjectField(env, target, componentIDs.peer); - if (JNU_IsNull(env, peer)) { -#ifdef DEBUG - fprintf(stderr, "Component peer is NULL\n"); -#endif - AWT_UNLOCK(); - return NULL; - } - - AWT_UNLOCK(); - - /* Allocate platform-specific data */ - px = (JAWT_X11DrawingSurfaceInfo*) - malloc(sizeof(JAWT_X11DrawingSurfaceInfo)); - - /* Set drawable and display */ - px->drawable = (*env)->GetLongField(env, peer, windowID); - px->display = awt_display; - - /* Get window attributes to set other values */ - XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs); - - /* Set the other values */ - px->visualID = XVisualIDFromVisual(attrs.visual); - px->colormapID = attrs.colormap; - px->depth = attrs.depth; - px->GetAWTColor = awt_GetColor; - - /* Allocate and initialize platform-independent data */ - p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo)); - p->platformInfo = px; - p->ds = ds; - p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x); - p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y); - p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width); - p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height); - p->clipSize = 1; - p->clip = &(p->bounds); - - /* Return our new structure */ - return p; -} - -/* - * Free the drawing surface info. - */ -JNIEXPORT void JNICALL -awt_DrawingSurface_FreeDrawingSurfaceInfo(JAWT_DrawingSurfaceInfo* dsi) -{ - if (dsi == NULL ) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface Info is NULL\n"); -#endif - return; - } - free(dsi->platformInfo); - free(dsi); -} - -/* - * Unlock the drawing surface of the target component for native rendering. - */ -JNIEXPORT void JNICALL awt_DrawingSurface_Unlock(JAWT_DrawingSurface* ds) -{ - JNIEnv* env; - if (ds == NULL) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface is NULL\n"); -#endif - return; - } - env = ds->env; - AWT_FLUSH_UNLOCK(); -} - -JNIEXPORT JAWT_DrawingSurface* JNICALL - awt_GetDrawingSurface(JNIEnv* env, jobject target) -{ - jclass componentClass; - JAWT_DrawingSurface* p; - - /* Make sure the target component is a java.awt.Component */ - componentClass = (*env)->FindClass(env, "java/awt/Component"); - CHECK_NULL_RETURN(componentClass, NULL); - - if (!(*env)->IsInstanceOf(env, target, componentClass)) { -#ifdef DEBUG - fprintf(stderr, - "GetDrawingSurface target must be a java.awt.Component\n"); -#endif - return NULL; - } - - p = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface)); - p->env = env; - p->target = (*env)->NewGlobalRef(env, target); - p->Lock = awt_DrawingSurface_Lock; - p->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo; - p->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo; - p->Unlock = awt_DrawingSurface_Unlock; - return p; -} - -JNIEXPORT void JNICALL - awt_FreeDrawingSurface(JAWT_DrawingSurface* ds) -{ - JNIEnv* env; - - if (ds == NULL ) { -#ifdef DEBUG - fprintf(stderr, "Drawing Surface is NULL\n"); -#endif - return; - } - env = ds->env; - (*env)->DeleteGlobalRef(env, ds->target); - free(ds); -} - -JNIEXPORT void JNICALL - awt_Lock(JNIEnv* env) -{ - if (awtLockInited) { - AWT_LOCK(); - } -} - -JNIEXPORT void JNICALL - awt_Unlock(JNIEnv* env) -{ - if (awtLockInited) { - AWT_FLUSH_UNLOCK(); - } -} - -JNIEXPORT jobject JNICALL - awt_GetComponent(JNIEnv* env, void* platformInfo) -{ - Window window = (Window)platformInfo; - jobject peer = NULL; - jobject target = NULL; - - AWT_LOCK(); - - if (window != None) { - peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", - "windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l; - if ((*env)->ExceptionCheck(env)) { - AWT_UNLOCK(); - return (jobject)NULL; - } - } - if ((peer != NULL) && - (JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) { - target = (*env)->GetObjectField(env, peer, targetID); - } - - if (target == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowNullPointerException(env, "NullPointerException"); - AWT_UNLOCK(); - return (jobject)NULL; - } - - AWT_UNLOCK(); - - return target; -} - -// EmbeddedFrame support - -static char *const embeddedClassName = "sun/awt/X11/XEmbeddedFrame"; - -JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame -(JNIEnv* env, void* platformInfo) -{ - static jmethodID mid = NULL; - static jclass cls; - if (mid == NULL) { - cls = (*env)->FindClass(env, embeddedClassName); - CHECK_NULL_RETURN(cls, NULL); - mid = (*env)->GetMethodID(env, cls, "", "(JZ)V"); - CHECK_NULL_RETURN(mid, NULL); - } - return (*env)->NewObject(env, cls, mid, platformInfo, JNI_TRUE); -} - - -JNIEXPORT void JNICALL awt_SetBounds -(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h) -{ - static jmethodID mid = NULL; - if (mid == NULL) { - jclass cls = (*env)->FindClass(env, embeddedClassName); - CHECK_NULL(cls); - mid = (*env)->GetMethodID(env, cls, "setBoundsPrivate", "(IIII)V"); - CHECK_NULL(mid); - } - (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h); -} - -JNIEXPORT void JNICALL awt_SynthesizeWindowActivation -(JNIEnv *env, jobject embeddedFrame, jboolean doActivate) -{ - static jmethodID mid = NULL; - if (mid == NULL) { - jclass cls = (*env)->FindClass(env, embeddedClassName); - CHECK_NULL(cls); - mid = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V"); - CHECK_NULL(mid); - } - (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate); -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_Event.c b/app/src/main/jni/awt_xawt/awt/awt_Event.c deleted file mode 100644 index 644246971..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_Event.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1998, 2001, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/*** - *** THIS IMPLEMENTS ONLY THE OBSOLETE java.awt.Event CLASS! SEE - *** awt_AWTEvent.[ch] FOR THE NEWER EVENT CLASSES. - *** - ***/ -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include "java_awt_Event.h" -#include "jni_util.h" - -#include "awt_Event.h" - -struct EventIDs eventIDs; - -JNIEXPORT void JNICALL -Java_java_awt_Event_initIDs(JNIEnv *env, jclass cls) -{ - CHECK_NULL(eventIDs.data = (*env)->GetFieldID(env, cls, "data", "J")); - CHECK_NULL(eventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z")); - CHECK_NULL(eventIDs.id = (*env)->GetFieldID(env, cls, "id", "I")); -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_Event.h b/app/src/main/jni/awt_xawt/awt/awt_Event.h deleted file mode 100644 index 06659ef93..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_Event.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1998, 2015, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/*** - *** THIS IMPLEMENTS ONLY THE OBSOLETE java.awt.Event CLASS! SEE - *** awt_AWTEvent.[ch] FOR THE NEWER EVENT CLASSES. - *** - ***/ -#ifndef _AWT_EVENT_H_ -#define _AWT_EVENT_H_ - -#include "jni_util.h" - -struct EventIDs { - jfieldID data; - jfieldID consumed; - jfieldID id; -}; - -extern struct EventIDs eventIDs; - -#endif /* _AWT_EVENT_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/awt_GraphicsEnv.c b/app/src/main/jni/awt_xawt/awt/awt_GraphicsEnv.c deleted file mode 100644 index 5ecbb8c2d..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_GraphicsEnv.c +++ /dev/null @@ -1,2266 +0,0 @@ -/* - * Copyright (c) 1997, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_util.h" -#include "awt_p.h" -#include "awt.h" -#include "color.h" -#include -#include -#include -#include -#if !defined(HEADLESS) && !defined(__ANDROID__) -#include -#include -#include "Xrandr.h" -#include "GLXGraphicsConfig.h" -#endif /* !HEADLESS */ - -#include -#include -#include -#include -#include -#include "systemScale.h" -#include - -#include "awt_GraphicsEnv.h" -#include "awt_util.h" -#include "gdefs.h" -#include -#include "Trace.h" - -#ifdef NETSCAPE -#include -extern int awt_init_xt; -#endif - -#ifndef HEADLESS - -int awt_numScreens; /* Xinerama-aware number of screens */ - -AwtScreenDataPtr x11Screens; - -/* - * Set in initDisplay() to indicate whether we should attempt to initialize - * GLX for the default configuration. - */ -static jboolean glxRequested = JNI_FALSE; - -#endif /* !HEADLESS */ - -#ifdef HEADLESS -// TODO: use Android width height -/* -#ifdef __ANDROID__ - -#endif -*/ -#define GLOBAL_WIDTH 1280 -#define GLOBAL_HEIGHT 720 - -#define Display void -#endif /* HEADLESS */ - -Display *awt_display; - -jclass tkClass = NULL; -jmethodID awtLockMID = NULL; -jmethodID awtUnlockMID = NULL; -jmethodID awtWaitMID = NULL; -jmethodID awtNotifyMID = NULL; -jmethodID awtNotifyAllMID = NULL; -jboolean awtLockInited = JNI_FALSE; - -/** Convenience macro for loading the lock-related method IDs. */ -#define GET_STATIC_METHOD(klass, method_id, method_name, method_sig) \ - do { \ - method_id = (*env)->GetStaticMethodID(env, klass, \ - method_name, method_sig); \ - if (method_id == NULL) return NULL; \ - } while (0) - -struct X11GraphicsConfigIDs x11GraphicsConfigIDs; -struct X11GraphicsDeviceIDs x11GraphicsDeviceIDs; - -#ifndef HEADLESS -int awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata); -#endif /* HEADLESS */ - -static char *x11GraphicsConfigClassName = "sun/awt/X11GraphicsConfig"; - -/* AWT and Xinerama - * - * As of fix 4356756, AWT is Xinerama-aware. X11GraphicsDevices are created for - * each screen of a Xinerama setup, though X11 itself still only sees a single - * display. - * In many places where we talk to X11, a xinawareScreen variable is used to - * pass the correct Display value, depending on the circumstances (a single - * X display, multiple X displays, or a single X display with multiple - * Xinerama screens). - * - * Solaris and Linux differ in the functions used to access Xinerama-related - * data. This is in part because at this time, the X consortium has not - * finalized the "official" Xinerama API. Once this spec is available, and - * both OSes are conformant, one code base should be sufficient for Xinerama - * operation on both OSes. Until then, some of the Xinerama-related code - * is ifdef'd appropriately. -bchristi, 7/12/01 - */ - -#define MAXFRAMEBUFFERS 16 -#if defined(__linux__) || defined(MACOSX) -typedef struct { - int screen_number; - short x_org; - short y_org; - short width; - short height; -} XineramaScreenInfo; - -typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*); - -#else /* SOLARIS */ -typedef Status XineramaGetInfoFunc(Display* display, int screen_number, - XRectangle* framebuffer_rects, unsigned char* framebuffer_hints, - int* num_framebuffers); -typedef Status XineramaGetCenterHintFunc(Display* display, int screen_number, - int* x, int* y); - -XineramaGetCenterHintFunc* XineramaSolarisCenterFunc = NULL; -#endif - -Bool usingXinerama = False; -XRectangle fbrects[MAXFRAMEBUFFERS]; - -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls) -{ - x11GraphicsConfigIDs.aData = NULL; - x11GraphicsConfigIDs.bitsPerPixel = NULL; - x11GraphicsConfigIDs.screen = NULL; - - x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J"); - CHECK_NULL(x11GraphicsConfigIDs.aData); - x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I"); - CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel); - x11GraphicsConfigIDs.screen = (*env)->GetFieldID (env, cls, "screen", "Lsun/awt/X11GraphicsDevice;"); - CHECK_NULL(x11GraphicsConfigIDs.screen); - - if (x11GraphicsConfigIDs.aData == NULL || - x11GraphicsConfigIDs.bitsPerPixel == NULL || - x11GraphicsConfigIDs.screen == NULL) { - - JNU_ThrowNoSuchFieldError(env, "Can't find a field"); - return; - } -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_initIDs (JNIEnv *env, jclass cls) -{ - x11GraphicsDeviceIDs.screen = NULL; - x11GraphicsDeviceIDs.screen = (*env)->GetFieldID (env, cls, "screen", "I"); - DASSERT(x11GraphicsDeviceIDs.screen); -} - -#ifndef HEADLESS - -/* - * XIOErrorHandler - */ -static int xioerror_handler(Display *disp) -{ - if (awtLockInited) { - if (errno == EPIPE) { - jio_fprintf(stderr, "X connection to %s host broken (explicit kill or server shutdown)\n", XDisplayName(NULL)); - } - /*SignalError(lockedee->lastpc, lockedee, "fp/ade/gui/GUIException", "I/O error"); */ - } - return 0; -} - -static AwtGraphicsConfigDataPtr -findWithTemplate(XVisualInfo *vinfo, - long mask) -{ - - XVisualInfo *visualList; - XColor color; - AwtGraphicsConfigDataPtr defaultConfig; - int visualsMatched, i; - - visualList = XGetVisualInfo(awt_display, - mask, vinfo, &visualsMatched); - if (visualList) { - defaultConfig = ZALLOC(_AwtGraphicsConfigData); - for (i = 0; i < visualsMatched; i++) { - memcpy(&defaultConfig->awt_visInfo, &visualList[i], sizeof(XVisualInfo)); - defaultConfig->awt_depth = visualList[i].depth; - - /* we can't use awtJNI_CreateColorData here, because it'll pull, - SystemColor, which in turn will cause toolkit to be reinitialized */ - if (awtCreateX11Colormap(defaultConfig)) { - /* Allocate white and black pixels for this visual */ - color.flags = DoRed | DoGreen | DoBlue; - color.red = color.green = color.blue = 0x0000; - XAllocColor(awt_display, defaultConfig->awt_cmap, &color); - x11Screens[visualList[i].screen].blackpixel = color.pixel; - color.flags = DoRed | DoGreen | DoBlue; - color.red = color.green = color.blue = 0xffff; - XAllocColor(awt_display, defaultConfig->awt_cmap, &color); - x11Screens[visualList[i].screen].whitepixel = color.pixel; - - XFree(visualList); - return defaultConfig; - } - } - XFree(visualList); - free((void *)defaultConfig); - } - return NULL; -} - -/* default config is based on X11 screen. All Xinerama screens of that X11 - screen will have the same default config */ -/* Need more notes about which fields of the structure are based on the X - screen, and which are based on the Xinerama screen */ -static AwtGraphicsConfigDataPtr -makeDefaultConfig(JNIEnv *env, int screen) { - - AwtGraphicsConfigDataPtr defaultConfig; - int xinawareScreen = 0; - VisualID forcedVisualID = 0, defaultVisualID; - char *forcedVisualStr; - XVisualInfo vinfo; - long mask; - - xinawareScreen = usingXinerama ? 0 : screen; - defaultVisualID = - XVisualIDFromVisual(DefaultVisual(awt_display, xinawareScreen)); - - memset(&vinfo, 0, sizeof(XVisualInfo)); - vinfo.screen = xinawareScreen; - - if ((forcedVisualStr = getenv("FORCEDEFVIS"))) { - mask = VisualIDMask | VisualScreenMask; - if (sscanf(forcedVisualStr, "%lx", &forcedVisualID) > 0 && - forcedVisualID > 0) - { - vinfo.visualid = forcedVisualID; - } else { - vinfo.visualid = defaultVisualID; - } - } else { - VisualID bestGLXVisualID; - if (glxRequested && - (bestGLXVisualID = GLXGC_FindBestVisual(env, xinawareScreen)) > 0) - { - /* we've found the best visual for use with GLX, so use it */ - vinfo.visualid = bestGLXVisualID; - mask = VisualIDMask | VisualScreenMask; - } else { - /* otherwise, continue looking for the best X11 visual */ - vinfo.depth = 24; - vinfo.class = TrueColor; - mask = VisualDepthMask | VisualScreenMask | VisualClassMask; - } - } - - /* try the best, or forced visual */ - defaultConfig = findWithTemplate(&vinfo, mask); - if (defaultConfig) { - return defaultConfig; - } - - /* try the default visual */ - vinfo.visualid = defaultVisualID; - mask = VisualIDMask | VisualScreenMask; - defaultConfig = findWithTemplate(&vinfo, mask); - if (defaultConfig) { - return defaultConfig; - } - - /* try any TrueColor */ - vinfo.class = TrueColor; - mask = VisualScreenMask | VisualClassMask; - defaultConfig = findWithTemplate(&vinfo, mask); - if (defaultConfig) { - return defaultConfig; - } - - /* try 8-bit PseudoColor */ - vinfo.depth = 8; - vinfo.class = PseudoColor; - mask = VisualDepthMask | VisualScreenMask | VisualClassMask; - defaultConfig = findWithTemplate(&vinfo, mask); - if (defaultConfig) { - return defaultConfig; - } - - /* try any 8-bit */ - vinfo.depth = 8; - mask = VisualDepthMask | VisualScreenMask; - defaultConfig = findWithTemplate(&vinfo, mask); - if (defaultConfig) { - return defaultConfig; - } - - /* we tried everything, give up */ - JNU_ThrowInternalError(env, "Can't find supported visual"); - XCloseDisplay(awt_display); - awt_display = NULL; - return NULL; -} - -static void -getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) { - - int i; - int n8p=0, n12p=0, n8s=0, n8gs=0, n8sg=0, n1sg=0, nTrue=0; - int nConfig; - XVisualInfo *pVI8p, *pVI12p, *pVI8s, *pVITrue, *pVI8gs, - *pVI8sg, *pVI1sg = NULL, viTmp; - AwtGraphicsConfigDataPtr *graphicsConfigs; - AwtGraphicsConfigDataPtr defaultConfig; - int ind; - char errmsg[128]; - int xinawareScreen; - void* xrenderLibHandle = NULL; - XRenderFindVisualFormatFunc* xrenderFindVisualFormat = NULL; - int major_opcode, first_event, first_error; - - if (usingXinerama) { - xinawareScreen = 0; - } - else { - xinawareScreen = screen; - } - - AWT_LOCK (); - - viTmp.screen = xinawareScreen; - - viTmp.depth = 8; - viTmp.class = PseudoColor; - viTmp.colormap_size = 256; - pVI8p = XGetVisualInfo (awt_display, - VisualDepthMask | VisualClassMask | - VisualColormapSizeMask | VisualScreenMask, - &viTmp, &n8p); - - viTmp.depth = 12; - viTmp.class = PseudoColor; - viTmp.colormap_size = 4096; - pVI12p = XGetVisualInfo (awt_display, - VisualDepthMask | VisualClassMask | - VisualColormapSizeMask | VisualScreenMask, - &viTmp, &n12p); - - viTmp.class = TrueColor; - pVITrue = XGetVisualInfo (awt_display, - VisualClassMask | - VisualScreenMask, - &viTmp, &nTrue); - - viTmp.depth = 8; - viTmp.class = StaticColor; - pVI8s = XGetVisualInfo (awt_display, VisualDepthMask | VisualClassMask | - VisualScreenMask, &viTmp, &n8s); - - viTmp.depth = 8; - viTmp.class = GrayScale; - viTmp.colormap_size = 256; - pVI8gs = XGetVisualInfo (awt_display, - VisualDepthMask | VisualClassMask | - VisualColormapSizeMask | VisualScreenMask, - &viTmp, &n8gs); - viTmp.depth = 8; - viTmp.class = StaticGray; - viTmp.colormap_size = 256; - pVI8sg = XGetVisualInfo (awt_display, - VisualDepthMask | VisualClassMask | - VisualColormapSizeMask | VisualScreenMask, - &viTmp, &n8sg); - -/* REMIND.. remove when we have support for the color classes below */ -/* viTmp.depth = 1; */ -/* viTmp.class = StaticGray; */ -/* pVI1sg = XGetVisualInfo (awt_display, VisualDepthMask | VisualClassMask, */ -/* viTmp, &n1sg); */ - - nConfig = n8p + n12p + n8s + n8gs + n8sg + n1sg + nTrue + 1; - graphicsConfigs = (AwtGraphicsConfigDataPtr *) - calloc(nConfig, sizeof(AwtGraphicsConfigDataPtr)); - if (graphicsConfigs == NULL) { - JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), - NULL); - AWT_UNLOCK(); - return; - } - - if (screenDataPtr->defaultConfig == NULL) { - /* - * After a display change event, the default config field will have - * been reset, so we need to recreate the default config here. - */ - screenDataPtr->defaultConfig = makeDefaultConfig(env, screen); - } - - defaultConfig = screenDataPtr->defaultConfig; - graphicsConfigs[0] = defaultConfig; - nConfig = 1; /* reserve index 0 for default config */ - - // Only use the RENDER extension if it is available on the X server - if (XQueryExtension(awt_display, "RENDER", - &major_opcode, &first_event, &first_error)) - { - xrenderLibHandle = dlopen("libXrender.so.1", RTLD_LAZY | RTLD_GLOBAL); - -#ifdef MACOSX -#define XRENDER_LIB "/usr/X11/lib/libXrender.dylib" -#else -#define XRENDER_LIB "libXrender.so" -#endif - - if (xrenderLibHandle == NULL) { - xrenderLibHandle = dlopen(XRENDER_LIB, - RTLD_LAZY | RTLD_GLOBAL); - } - -#ifndef __linux__ /* SOLARIS */ - if (xrenderLibHandle == NULL) { - xrenderLibHandle = dlopen("/usr/lib/libXrender.so.1", - RTLD_LAZY | RTLD_GLOBAL); - } -#endif - - if (xrenderLibHandle != NULL) { - xrenderFindVisualFormat = - (XRenderFindVisualFormatFunc*)dlsym(xrenderLibHandle, - "XRenderFindVisualFormat"); - } - } - - for (i = 0; i < nTrue; i++) { - if (XVisualIDFromVisual(pVITrue[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) || - pVITrue[i].depth == 12) { - /* Skip the non-supported 12-bit TrueColor visual */ - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVITrue [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i], - sizeof (XVisualInfo)); - if (xrenderFindVisualFormat != NULL) { - XRenderPictFormat *format = xrenderFindVisualFormat (awt_display, - pVITrue [i].visual); - if (format && - format->type == PictTypeDirect && - format->direct.alphaMask) - { - graphicsConfigs [ind]->isTranslucencySupported = 1; - memcpy(&graphicsConfigs [ind]->renderPictFormat, format, - sizeof(*format)); - } - } - } - - if (xrenderLibHandle != NULL) { - dlclose(xrenderLibHandle); - xrenderLibHandle = NULL; - } - - for (i = 0; i < n8p; i++) { - if (XVisualIDFromVisual(pVI8p[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI8p [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8p [i], - sizeof (XVisualInfo)); - } - - for (i = 0; i < n12p; i++) { - if (XVisualIDFromVisual(pVI12p[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI12p [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI12p [i], - sizeof (XVisualInfo)); - } - - for (i = 0; i < n8s; i++) { - if (XVisualIDFromVisual(pVI8s[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI8s [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8s [i], - sizeof (XVisualInfo)); - } - - for (i = 0; i < n8gs; i++) { - if (XVisualIDFromVisual(pVI8gs[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI8gs [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8gs [i], - sizeof (XVisualInfo)); - } - - for (i = 0; i < n8sg; i++) { - if (XVisualIDFromVisual(pVI8sg[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI8sg [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8sg [i], - sizeof (XVisualInfo)); - } - - for (i = 0; i < n1sg; i++) { - if (XVisualIDFromVisual(pVI1sg[i].visual) == - XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) { - continue; - } else { - ind = nConfig++; - } - graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData); - graphicsConfigs [ind]->awt_depth = pVI1sg [i].depth; - memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI1sg [i], - sizeof (XVisualInfo)); - } - - if (n8p != 0) - XFree (pVI8p); - if (n12p != 0) - XFree (pVI12p); - if (n8s != 0) - XFree (pVI8s); - if (n8gs != 0) - XFree (pVI8gs); - if (n8sg != 0) - XFree (pVI8sg); - if (n1sg != 0) - XFree (pVI1sg); - - screenDataPtr->numConfigs = nConfig; - screenDataPtr->configs = graphicsConfigs; - - AWT_UNLOCK (); -} - -#ifndef HEADLESS -#if defined(__linux__) || defined(MACOSX) -static void xinerama_init_linux() -{ - void* libHandle = NULL; - int32_t locNumScr = 0; - XineramaScreenInfo *xinInfo; - char* XineramaQueryScreensName = "XineramaQueryScreens"; - XineramaQueryScreensFunc* XineramaQueryScreens = NULL; - - /* load library */ - libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"), - RTLD_LAZY | RTLD_GLOBAL); - if (libHandle == NULL) { - libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL); - } - if (libHandle != NULL) { - XineramaQueryScreens = (XineramaQueryScreensFunc*) - dlsym(libHandle, XineramaQueryScreensName); - - if (XineramaQueryScreens != NULL) { - DTRACE_PRINTLN("calling XineramaQueryScreens func on Linux"); - xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr); - if (xinInfo != NULL && locNumScr > XScreenCount(awt_display)) { - int32_t idx; - DTRACE_PRINTLN("Enabling Xinerama support"); - usingXinerama = True; - /* set global number of screens */ - DTRACE_PRINTLN1(" num screens = %i\n", locNumScr); - awt_numScreens = locNumScr; - - /* stuff values into fbrects */ - for (idx = 0; idx < awt_numScreens; idx++) { - DASSERT(xinInfo[idx].screen_number == idx); - - fbrects[idx].width = xinInfo[idx].width; - fbrects[idx].height = xinInfo[idx].height; - fbrects[idx].x = xinInfo[idx].x_org; - fbrects[idx].y = xinInfo[idx].y_org; - } - } else { - DTRACE_PRINTLN("calling XineramaQueryScreens didn't work"); - } - } else { - DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol"); - } - dlclose(libHandle); - } else { - DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror()); - } -} -#endif -#if !defined(__linux__) && !defined(MACOSX) /* Solaris */ -static void xinerama_init_solaris() -{ - void* libHandle = NULL; - unsigned char fbhints[MAXFRAMEBUFFERS]; - int32_t locNumScr = 0; - /* load and run XineramaGetInfo */ - char* XineramaGetInfoName = "XineramaGetInfo"; - char* XineramaGetCenterHintName = "XineramaGetCenterHint"; - XineramaGetInfoFunc* XineramaSolarisFunc = NULL; - - /* load library */ - libHandle = dlopen(JNI_LIB_NAME("Xext"), RTLD_LAZY | RTLD_GLOBAL); - if (libHandle != NULL) { - XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName); - XineramaSolarisCenterFunc = - (XineramaGetCenterHintFunc*)dlsym(libHandle, XineramaGetCenterHintName); - - if (XineramaSolarisFunc != NULL) { - DTRACE_PRINTLN("calling XineramaGetInfo func on Solaris"); - if ((*XineramaSolarisFunc)(awt_display, 0, &fbrects[0], - &fbhints[0], &locNumScr) != 0 && - locNumScr > XScreenCount(awt_display)) - { - DTRACE_PRINTLN("Enabling Xinerama support"); - usingXinerama = True; - /* set global number of screens */ - DTRACE_PRINTLN1(" num screens = %i\n", locNumScr); - awt_numScreens = locNumScr; - } else { - DTRACE_PRINTLN("calling XineramaGetInfo didn't work"); - } - } else { - DTRACE_PRINTLN("couldn't load XineramaGetInfo symbol"); - } - dlclose(libHandle); - } else { - DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror()); - } -} -#endif - -/* - * Checks if Xinerama is running and perform Xinerama-related - * platform dependent initialization. - */ -static void xineramaInit(void) { - char* XinExtName = "XINERAMA"; - int32_t major_opcode, first_event, first_error; - Bool gotXinExt = False; - - gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode, - &first_event, &first_error); - - if (!gotXinExt) { - DTRACE_PRINTLN("Xinerama extension is not available"); - return; - } - - DTRACE_PRINTLN("Xinerama extension is available"); -#if defined(__linux__) || defined(MACOSX) - xinerama_init_linux(); -#else /* Solaris */ - xinerama_init_solaris(); -#endif /* __linux__ || MACOSX */ -} -#endif /* HEADLESS */ - -Display * -awt_init_Display(JNIEnv *env, jobject this) -{ - jclass klass; - Display *dpy; - char errmsg[128]; - int i; -#ifdef NETSCAPE - sigset_t alarm_set, oldset; -#endif - - if (awt_display) { - return awt_display; - } - -#ifdef NETSCAPE - /* Disable interrupts during XtOpenDisplay to avoid bugs in unix os select - code: some unix systems don't implement SA_RESTART properly and - because of this, select returns with EINTR. Most implementations of - gethostbyname don't cope with EINTR properly and as a result we get - stuck (forever) in the gethostbyname code - */ - sigemptyset(&alarm_set); - sigaddset(&alarm_set, SIGALRM); - sigprocmask(SIG_BLOCK, &alarm_set, &oldset); -#endif - - /* Load AWT lock-related methods in SunToolkit */ - klass = (*env)->FindClass(env, "sun/awt/SunToolkit"); - if (klass == NULL) return NULL; - GET_STATIC_METHOD(klass, awtLockMID, "awtLock", "()V"); - GET_STATIC_METHOD(klass, awtUnlockMID, "awtUnlock", "()V"); - GET_STATIC_METHOD(klass, awtWaitMID, "awtLockWait", "(J)V"); - GET_STATIC_METHOD(klass, awtNotifyMID, "awtLockNotify", "()V"); - GET_STATIC_METHOD(klass, awtNotifyAllMID, "awtLockNotifyAll", "()V"); - tkClass = (*env)->NewGlobalRef(env, klass); - awtLockInited = JNI_TRUE; - - if (getenv("_AWT_IGNORE_XKB") != NULL && - strlen(getenv("_AWT_IGNORE_XKB")) > 0) { - if (XkbIgnoreExtension(True)) { - printf("Ignoring XKB.\n"); - } - } - - dpy = awt_display = XOpenDisplay(NULL); -#ifdef NETSCAPE - sigprocmask(SIG_SETMASK, &oldset, NULL); -#endif - if (!dpy) { - jio_snprintf(errmsg, - sizeof(errmsg), - "Can't connect to X11 window server using '%s' as the value of the DISPLAY variable.", - (getenv("DISPLAY") == NULL) ? ":0.0" : getenv("DISPLAY")); - JNU_ThrowByName(env, "java/awt/AWTError", errmsg); - return NULL; - } - - XSetIOErrorHandler(xioerror_handler); - JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "init", "(J)V", - ptr_to_jlong(awt_display)); - JNU_CHECK_EXCEPTION_RETURN(env, NULL); - - /* set awt_numScreens, and whether or not we're using Xinerama */ - xineramaInit(); - - if (!usingXinerama) { - awt_numScreens = XScreenCount(awt_display); - } - - DTRACE_PRINTLN1("allocating %i screens\n", awt_numScreens); - /* Allocate screen data structure array */ - x11Screens = calloc(awt_numScreens, sizeof(AwtScreenData)); - if (x11Screens == NULL) { - JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), - NULL); - return NULL; - } - - for (i = 0; i < awt_numScreens; i++) { - if (usingXinerama) { - /* All Xinerama screens use the same X11 root for now */ - x11Screens[i].root = RootWindow(awt_display, 0); - } - else { - x11Screens[i].root = RootWindow(awt_display, i); - } - x11Screens[i].defaultConfig = makeDefaultConfig(env, i); - JNU_CHECK_EXCEPTION_RETURN(env, NULL); - } - - return dpy; -} -#endif /* !HEADLESS */ - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: getDefaultScreenNum - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsEnvironment_getDefaultScreenNum( -JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return (jint)0; -#else - return DefaultScreen(awt_display); -#endif /* !HEADLESS */ -} - -#ifndef HEADLESS -static void ensureConfigsInited(JNIEnv* env, int screen) { - if (x11Screens[screen].numConfigs == 0) { - if (env == NULL) { - env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - } - getAllConfigs (env, screen, &(x11Screens[screen])); - } -} -#endif - -#ifdef HEADLESS -void* getDefaultConfig(int screen) { - return NULL; -} -#else -AwtGraphicsConfigDataPtr -getDefaultConfig(int screen) { - ensureConfigsInited(NULL, screen); - return x11Screens[screen].defaultConfig; -} - -AwtScreenDataPtr -getScreenData(int screen) { - return &(x11Screens[screen]); -} -#endif /* !HEADLESS */ - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: initDisplay - * Signature: (Z)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsEnvironment_initDisplay(JNIEnv *env, jobject this, - jboolean glxReq) -{ -#ifndef HEADLESS - glxRequested = glxReq; - (void) awt_init_Display(env, this); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: initGLX - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsEnvironment_initGLX(JNIEnv *env, jclass x11ge) -{ -#ifndef HEADLESS - jboolean glxAvailable; - - AWT_LOCK(); - glxAvailable = GLXGC_IsGLXAvailable(); - AWT_UNLOCK(); - - return glxAvailable; -#else - return JNI_FALSE; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: getNumScreens - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsEnvironment_getNumScreens(JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return (jint)0; -#else - return awt_numScreens; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getDisplay - * Signature: ()J - */ -JNIEXPORT jlong JNICALL -Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return NULL; -#else - return ptr_to_jlong(awt_display); -#endif /* !HEADLESS */ -} - -#ifdef MITSHM - -static jint canUseShmExt = UNSET_MITSHM; -static jint canUseShmExtPixmaps = UNSET_MITSHM; -static jboolean xshmAttachFailed = JNI_FALSE; - -int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr) { - if (xerr->minor_code == X_ShmAttach) { - xshmAttachFailed = JNI_TRUE; - } - return 0; -} -jboolean isXShmAttachFailed() { - return xshmAttachFailed; -} -void resetXShmAttachFailed() { - xshmAttachFailed = JNI_FALSE; -} - -extern int mitShmPermissionMask; - -void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { - XShmSegmentInfo shminfo; - int XShmMajor, XShmMinor; - int a, b, c; - - AWT_LOCK(); - if (canUseShmExt != UNSET_MITSHM) { - *shmExt = canUseShmExt; - *shmPixmaps = canUseShmExtPixmaps; - AWT_UNLOCK(); - return; - } - - *shmExt = canUseShmExt = CANT_USE_MITSHM; - *shmPixmaps = canUseShmExtPixmaps = CANT_USE_MITSHM; - - if (awt_display == (Display *)NULL) { - AWT_NOFLUSH_UNLOCK(); - return; - } - - /** - * XShmQueryExtension returns False in remote server case. - * Unfortunately it also returns True in ssh case, so - * we need to test that we can actually do XShmAttach. - */ - if (XShmQueryExtension(awt_display)) { - shminfo.shmid = shmget(IPC_PRIVATE, 0x10000, - IPC_CREAT|mitShmPermissionMask); - if (shminfo.shmid < 0) { - AWT_UNLOCK(); - J2dRlsTraceLn1(J2D_TRACE_ERROR, - "TryInitMITShm: shmget has failed: %s", - strerror(errno)); - return; - } - shminfo.shmaddr = (char *) shmat(shminfo.shmid, 0, 0); - if (shminfo.shmaddr == ((char *) -1)) { - shmctl(shminfo.shmid, IPC_RMID, 0); - AWT_UNLOCK(); - J2dRlsTraceLn1(J2D_TRACE_ERROR, - "TryInitMITShm: shmat has failed: %s", - strerror(errno)); - return; - } - shminfo.readOnly = True; - - resetXShmAttachFailed(); - /** - * The J2DXErrHandler handler will set xshmAttachFailed - * to JNI_TRUE if any Shm error has occured. - */ - EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler, - XShmAttach(awt_display, &shminfo)); - - /** - * Get rid of the id now to reduce chances of leaking - * system resources. - */ - shmctl(shminfo.shmid, IPC_RMID, 0); - - if (isXShmAttachFailed() == JNI_FALSE) { - canUseShmExt = CAN_USE_MITSHM; - /* check if we can use shared pixmaps */ - XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor, - (Bool*)&canUseShmExtPixmaps); - canUseShmExtPixmaps = canUseShmExtPixmaps && - (XShmPixmapFormat(awt_display) == ZPixmap); - XShmDetach(awt_display, &shminfo); - } - shmdt(shminfo.shmaddr); - *shmExt = canUseShmExt; - *shmPixmaps = canUseShmExtPixmaps; - } - AWT_UNLOCK(); -} -#endif /* MITSHM */ - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: checkShmExt - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsEnvironment_checkShmExt(JNIEnv *env, jobject this) -{ - - int shmExt = NOEXT_MITSHM, shmPixmaps; -#ifdef MITSHM - TryInitMITShm(env, &shmExt, &shmPixmaps); -#endif - return shmExt; -} - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: getDisplayString - * Signature: ()Ljava/lang/String - */ -JNIEXPORT jstring JNICALL -Java_sun_awt_X11GraphicsEnvironment_getDisplayString - (JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return (jstring)NULL; -#elif defined(__ANDROID__) - return (*env)->NewStringUTF(env, ":0"); -#else - return (*env)->NewStringUTF(env, DisplayString(awt_display)); -#endif /* HEADLESS */ -} - - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getNumConfigs - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsDevice_getNumConfigs( -JNIEnv *env, jobject this, jint screen) -{ -#ifdef HEADLESS - return (jint)0; -#else - ensureConfigsInited(env, screen); - return x11Screens[screen].numConfigs; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getConfigVisualId - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsDevice_getConfigVisualId( -JNIEnv *env, jobject this, jint index, jint screen) -{ -#ifdef HEADLESS - return (jint)0; -#else - int visNum; - - ensureConfigsInited(env, screen); - if (index == 0) { - return ((jint)x11Screens[screen].defaultConfig->awt_visInfo.visualid); - } else { - return ((jint)x11Screens[screen].configs[index]->awt_visInfo.visualid); - } -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getConfigDepth - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsDevice_getConfigDepth( -JNIEnv *env, jobject this, jint index, jint screen) -{ -#ifdef HEADLESS - return (jint)0; -#else - int visNum; - - ensureConfigsInited(env, screen); - if (index == 0) { - return ((jint)x11Screens[screen].defaultConfig->awt_visInfo.depth); - } else { - return ((jint)x11Screens[screen].configs[index]->awt_visInfo.depth); - } -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getConfigColormap - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsDevice_getConfigColormap( -JNIEnv *env, jobject this, jint index, jint screen) -{ -#ifdef HEADLESS - return (jint)0; -#else - int visNum; - - ensureConfigsInited(env, screen); - if (index == 0) { - return ((jint)x11Screens[screen].defaultConfig->awt_cmap); - } else { - return ((jint)x11Screens[screen].configs[index]->awt_cmap); - } -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: resetNativeData - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_resetNativeData - (JNIEnv *env, jclass x11gd, jint screen) -{ -#ifndef HEADLESS - /* - * Reset references to the various configs; the actual native config data - * will be free'd later by the Disposer mechanism when the Java-level - * X11GraphicsConfig objects go away. By setting these values to NULL, - * we ensure that they will be reinitialized as necessary (for example, - * see the getNumConfigs() method). - */ - if (x11Screens[screen].configs) { - free(x11Screens[screen].configs); - x11Screens[screen].configs = NULL; - } - x11Screens[screen].defaultConfig = NULL; - x11Screens[screen].numConfigs = 0; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: dispose - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsConfig_dispose - (JNIEnv *env, jclass x11gc, jlong configData) -{ -#ifndef HEADLESS - AwtGraphicsConfigDataPtr aData = (AwtGraphicsConfigDataPtr) - jlong_to_ptr(configData); - - if (aData == NULL) { - return; - } - - AWT_LOCK(); - if (aData->awt_cmap) { - XFreeColormap(awt_display, aData->awt_cmap); - } - if (aData->awtImage) { - free(aData->awtImage); - } - if (aData->monoImage) { - XFree(aData->monoImage); - } - if (aData->monoPixmap) { - XFreePixmap(awt_display, aData->monoPixmap); - } - if (aData->monoPixmapGC) { - XFreeGC(awt_display, aData->monoPixmapGC); - } - if (aData->color_data) { - free(aData->color_data); - } - AWT_UNLOCK(); - - if (aData->glxInfo) { - /* - * The native GLXGraphicsConfig data needs to be disposed separately - * on the OGL queue flushing thread (should not be called while - * the AWT lock is held). - */ - JNU_CallStaticMethodByName(env, NULL, - "sun/java2d/opengl/OGLRenderQueue", - "disposeGraphicsConfig", "(J)V", - ptr_to_jlong(aData->glxInfo)); - } - - free(aData); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: getXResolution - * Signature: ()I - */ -JNIEXPORT jdouble JNICALL -Java_sun_awt_X11GraphicsConfig_getXResolution( -JNIEnv *env, jobject this, jint screen) -{ -#ifdef HEADLESS - return (jdouble)0; -#else - return ((DisplayWidth(awt_display, screen) * 25.4) / - DisplayWidthMM(awt_display, screen)); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: getYResolution - * Signature: ()I - */ -JNIEXPORT jdouble JNICALL -Java_sun_awt_X11GraphicsConfig_getYResolution( -JNIEnv *env, jobject this, jint screen) -{ -#ifdef HEADLESS - return (jdouble)0; -#else - return ((DisplayHeight(awt_display, screen) * 25.4) / - DisplayHeightMM(awt_display, screen)); -#endif /* !HEADLESS */ -} - - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: getNumColors - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_sun_awt_X11GraphicsConfig_getNumColors( -JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return (jint)0; -#else - AwtGraphicsConfigData *adata; - - adata = (AwtGraphicsConfigData *) JNU_GetLongFieldAsPtr(env, this, - x11GraphicsConfigIDs.aData); - - return adata->awt_num_colors; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: init - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsConfig_init( -JNIEnv *env, jobject this, jint visualNum, jint screen) -{ -#ifndef HEADLESS - AwtGraphicsConfigData *adata = NULL; - AwtScreenData asd = x11Screens[screen]; - int i, n; - int depth; - XImage * tempImage; - - /* If haven't gotten all of the configs yet, do it now. */ - if (asd.numConfigs == 0) { - getAllConfigs (env, screen, &asd); - } - - /* Check the graphicsConfig for this visual */ - for (i = 0; i < asd.numConfigs; i++) { - AwtGraphicsConfigDataPtr agcPtr = asd.configs[i]; - if ((jint)agcPtr->awt_visInfo.visualid == visualNum) { - adata = agcPtr; - break; - } - } - - /* If didn't find the visual, throw an exception... */ - if (adata == (AwtGraphicsConfigData *) NULL) { - JNU_ThrowIllegalArgumentException(env, "Unknown Visual Specified"); - return; - } - - /* adata->awt_cmap initialization has been deferred to - * makeColorModel call - */ - - JNU_SetLongFieldFromPtr(env, this, x11GraphicsConfigIDs.aData, adata); - - depth = adata->awt_visInfo.depth; - tempImage = XCreateImage(awt_display, - adata->awt_visInfo.visual, - depth, ZPixmap, 0, NULL, 1, 1, 32, 0); - adata->pixelStride = (tempImage->bits_per_pixel + 7) / 8; - (*env)->SetIntField(env, this, x11GraphicsConfigIDs.bitsPerPixel, - (jint)tempImage->bits_per_pixel); - XDestroyImage(tempImage); -#endif /* !HEADLESS */ -} - - - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: makeColorModel - * Signature: ()Ljava/awt/image/ColorModel - */ -JNIEXPORT jobject JNICALL -Java_sun_awt_X11GraphicsConfig_makeColorModel( -JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return NULL; -#else - AwtGraphicsConfigData *adata; - jobject colorModel; - - /* - * If awt is not locked yet, return null since the toolkit is not - * initialized yet. - */ - if (!awtLockInited) { - return NULL; - } - - AWT_LOCK (); - - adata = (AwtGraphicsConfigData *) JNU_GetLongFieldAsPtr(env, this, - x11GraphicsConfigIDs.aData); - - /* If colormap entry of adata is NULL, need to create it now */ - if (adata->awt_cmap == (Colormap) NULL) { - awtJNI_CreateColorData (env, adata, 1); - } - - /* Make Color Model object for this GraphicsConfiguration */ - colorModel = (*env)->ExceptionCheck(env) - ? NULL : awtJNI_GetColorModel (env, adata); - - AWT_UNLOCK (); - - return colorModel; -#endif /* !HEADLESS */ -} - - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: getBounds - * Signature: ()Ljava/awt/Rectangle - */ -JNIEXPORT jobject JNICALL -Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen) -{ - jclass clazz; - jmethodID mid; - jobject bounds = NULL; - - clazz = (*env)->FindClass(env, "java/awt/Rectangle"); - CHECK_NULL_RETURN(clazz, NULL); - mid = (*env)->GetMethodID(env, clazz, "", "(IIII)V"); -#ifdef HEADLESS - if (mid != NULL) { - bounds = (*env)->NewObject(env, clazz, mid, 0, 0, GLOBAL_WIDTH, GLOBAL_HEIGHT); - } - return bounds; -#else - AwtGraphicsConfigDataPtr adata; - - adata = (AwtGraphicsConfigDataPtr) - JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData); - - if (mid != NULL) { - if (usingXinerama) { - if (0 <= screen && screen < awt_numScreens) { - bounds = (*env)->NewObject(env, clazz, mid, fbrects[screen].x, - fbrects[screen].y, - fbrects[screen].width, - fbrects[screen].height); - } else { - jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalArgumentException"); - if (exceptionClass != NULL) { - (*env)->ThrowNew(env, exceptionClass, "Illegal screen index"); - } - } - } else { - XWindowAttributes xwa; - memset(&xwa, 0, sizeof(xwa)); - - AWT_LOCK (); - XGetWindowAttributes(awt_display, - RootWindow(awt_display, adata->awt_visInfo.screen), - &xwa); - AWT_UNLOCK (); - - bounds = (*env)->NewObject(env, clazz, mid, 0, 0, - xwa.width, xwa.height); - } - - if ((*env)->ExceptionOccurred(env)) { - return NULL; - } - } - return bounds; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: createBackBuffer - * Signature: (JI)J - */ -JNIEXPORT jlong JNICALL -Java_sun_awt_X11GraphicsConfig_createBackBuffer - (JNIEnv *env, jobject this, jlong window, jint swapAction) -{ - int32_t v1, v2; - XdbeBackBuffer ret = (unsigned long) 0; - Window w = (Window)window; - AWT_LOCK(); - if (!XdbeQueryExtension(awt_display, &v1, &v2)) { - JNU_ThrowByName(env, "java/lang/Exception", - "Could not query double-buffer extension"); - AWT_UNLOCK(); - return (jlong)0; - } - ret = XdbeAllocateBackBufferName(awt_display, w, - (XdbeSwapAction)swapAction); - AWT_FLUSH_UNLOCK(); - return (jlong)ret; -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: destroyBackBuffer - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsConfig_destroyBackBuffer - (JNIEnv *env, jobject this, jlong backBuffer) -{ - AWT_LOCK(); - XdbeDeallocateBackBufferName(awt_display, (XdbeBackBuffer)backBuffer); - AWT_FLUSH_UNLOCK(); -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: swapBuffers - * Signature: (JI)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsConfig_swapBuffers - (JNIEnv *env, jobject this, - jlong window, jint swapAction) -{ - XdbeSwapInfo swapInfo; - - AWT_LOCK(); - - XdbeBeginIdiom(awt_display); - swapInfo.swap_window = (Window)window; - swapInfo.swap_action = (XdbeSwapAction)swapAction; - if (!XdbeSwapBuffers(awt_display, &swapInfo, 1)) { - JNU_ThrowInternalError(env, "Could not swap buffers"); - } - XdbeEndIdiom(awt_display); - - AWT_FLUSH_UNLOCK(); -} - -/* - * Class: sun_awt_X11GraphicsConfig - * Method: isTranslucencyCapable - * Signature: (J)V - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsConfig_isTranslucencyCapable - (JNIEnv *env, jobject this, jlong configData) -{ -#ifdef __ANDROID__ - return JNI_TRUE; -#elif defined(HEADLESS) - return JNI_FALSE; -#else - AwtGraphicsConfigDataPtr aData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(configData); - if (aData == NULL) { - return JNI_FALSE; - } - return aData->isTranslucencySupported ? JNI_TRUE : JNI_FALSE; -#endif -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: isDBESupported - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsDevice_isDBESupported(JNIEnv *env, jobject this) -{ -#ifdef HEADLESS - return JNI_FALSE; -#else - int opcode = 0, firstEvent = 0, firstError = 0; - jboolean ret; - - AWT_LOCK(); - ret = (jboolean)XQueryExtension(awt_display, "DOUBLE-BUFFER", - &opcode, &firstEvent, &firstError); - AWT_FLUSH_UNLOCK(); - return ret; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getDoubleBufferVisuals - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_getDoubleBufferVisuals(JNIEnv *env, - jobject this, jint screen) -{ -#ifndef HEADLESS - jclass clazz; - jmethodID midAddVisual; - Window rootWindow; - int i, n = 1; - XdbeScreenVisualInfo* visScreenInfo; - int xinawareScreen; - - if (usingXinerama) { - xinawareScreen = 0; - } - else { - xinawareScreen = screen; - } - - clazz = (*env)->GetObjectClass(env, this); - midAddVisual = (*env)->GetMethodID(env, clazz, "addDoubleBufferVisual", - "(I)V"); - CHECK_NULL(midAddVisual); - AWT_LOCK(); - rootWindow = RootWindow(awt_display, xinawareScreen); - visScreenInfo = XdbeGetVisualInfo(awt_display, &rootWindow, &n); - if (visScreenInfo == NULL) { - JNU_ThrowInternalError(env, "Could not get visual info"); - AWT_UNLOCK(); - return; - } - AWT_FLUSH_UNLOCK(); - for (i = 0; i < visScreenInfo->count; i++) { - XdbeVisualInfo* visInfo = visScreenInfo->visinfo; - (*env)->CallVoidMethod(env, this, midAddVisual, (visInfo[i]).visual); - if ((*env)->ExceptionCheck(env)) { - break; - } - } -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: pRunningXinerama - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsEnvironment_pRunningXinerama(JNIEnv *env, - jobject this) -{ -#ifdef HEADLESS - return JNI_FALSE; -#else - return usingXinerama ? JNI_TRUE : JNI_FALSE; -#endif /* HEADLESS */ -} - -/* - * Can return NULL. - * - * Class: sun_awt_X11GraphicsEnvironment - * Method: getXineramaCenterPoint - * Signature: ()Ljava/awt/Point - */ -JNIEXPORT jobject JNICALL -Java_sun_awt_X11GraphicsEnvironment_getXineramaCenterPoint(JNIEnv *env, - jobject this) -{ - jobject point = NULL; -#ifndef HEADLESS /* return NULL in HEADLESS, Linux */ -#if !defined(__linux__) && !defined(MACOSX) - int x,y; - - AWT_LOCK(); - DASSERT(usingXinerama); - if (XineramaSolarisCenterFunc != NULL) { - (XineramaSolarisCenterFunc)(awt_display, 0, &x, &y); - point = JNU_NewObjectByName(env, "java/awt/Point","(II)V", x, y); - DASSERT(point); - } else { - DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null"); - } - AWT_FLUSH_UNLOCK(); -#endif /* __linux __ || MACOSX */ -#endif /* HEADLESS */ - return point; -} - - -/** - * Begin DisplayMode/FullScreen support - */ - -#ifndef HEADLESS - -#define BIT_DEPTH_MULTI java_awt_DisplayMode_BIT_DEPTH_MULTI -#define REFRESH_RATE_UNKNOWN java_awt_DisplayMode_REFRESH_RATE_UNKNOWN - -typedef Status - (*XRRQueryVersionType) (Display *dpy, int *major_versionp, int *minor_versionp); -typedef XRRScreenConfiguration* - (*XRRGetScreenInfoType)(Display *dpy, Drawable root); -typedef void - (*XRRFreeScreenConfigInfoType)(XRRScreenConfiguration *config); -typedef short* - (*XRRConfigRatesType)(XRRScreenConfiguration *config, - int sizeID, int *nrates); -typedef short - (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config); -typedef XRRScreenSize* - (*XRRConfigSizesType)(XRRScreenConfiguration *config, - int *nsizes); -typedef SizeID - (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config, - Rotation *rotation); -typedef Status - (*XRRSetScreenConfigAndRateType)(Display *dpy, - XRRScreenConfiguration *config, - Drawable draw, - int size_index, - Rotation rotation, - short rate, - Time timestamp); -typedef Rotation - (*XRRConfigRotationsType)(XRRScreenConfiguration *config, - Rotation *current_rotation); - -typedef XRRScreenResources* (*XRRGetScreenResourcesType)(Display *dpy, - Window window); - -typedef void (*XRRFreeScreenResourcesType)(XRRScreenResources *resources); - -typedef XRROutputInfo * (*XRRGetOutputInfoType)(Display *dpy, - XRRScreenResources *resources, RROutput output); - -typedef void (*XRRFreeOutputInfoType)(XRROutputInfo *outputInfo); - -typedef XRRCrtcInfo* (*XRRGetCrtcInfoType)(Display *dpy, - XRRScreenResources *resources, RRCrtc crtc); - -typedef void (*XRRFreeCrtcInfoType)(XRRCrtcInfo *crtcInfo); - -static XRRQueryVersionType awt_XRRQueryVersion; -static XRRGetScreenInfoType awt_XRRGetScreenInfo; -static XRRFreeScreenConfigInfoType awt_XRRFreeScreenConfigInfo; -static XRRConfigRatesType awt_XRRConfigRates; -static XRRConfigCurrentRateType awt_XRRConfigCurrentRate; -static XRRConfigSizesType awt_XRRConfigSizes; -static XRRConfigCurrentConfigurationType awt_XRRConfigCurrentConfiguration; -static XRRSetScreenConfigAndRateType awt_XRRSetScreenConfigAndRate; -static XRRConfigRotationsType awt_XRRConfigRotations; -static XRRGetScreenResourcesType awt_XRRGetScreenResources; -static XRRFreeScreenResourcesType awt_XRRFreeScreenResources; -static XRRGetOutputInfoType awt_XRRGetOutputInfo; -static XRRFreeOutputInfoType awt_XRRFreeOutputInfo; -static XRRGetCrtcInfoType awt_XRRGetCrtcInfo; -static XRRFreeCrtcInfoType awt_XRRFreeCrtcInfo; - -#define LOAD_XRANDR_FUNC(f) \ - do { \ - awt_##f = (f##Type)dlsym(pLibRandR, #f); \ - if (awt_##f == NULL) { \ - J2dRlsTraceLn1(J2D_TRACE_ERROR, \ - "X11GD_InitXrandrFuncs: Could not load %s", #f); \ - dlclose(pLibRandR); \ - return JNI_FALSE; \ - } \ - } while (0) - -static jboolean -X11GD_InitXrandrFuncs(JNIEnv *env) -{ - int rr_maj_ver = 0, rr_min_ver = 0; - - void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"), - RTLD_LAZY | RTLD_LOCAL); - if (pLibRandR == NULL) { - pLibRandR = dlopen(JNI_LIB_NAME("Xrandr"), RTLD_LAZY | RTLD_LOCAL); - } - if (pLibRandR == NULL) { - J2dRlsTraceLn(J2D_TRACE_ERROR, - "X11GD_InitXrandrFuncs: Could not open libXrandr.so.2"); - return JNI_FALSE; - } - - LOAD_XRANDR_FUNC(XRRQueryVersion); - - if (!(*awt_XRRQueryVersion)(awt_display, &rr_maj_ver, &rr_min_ver)) { - J2dRlsTraceLn(J2D_TRACE_ERROR, - "X11GD_InitXrandrFuncs: XRRQueryVersion returned an error status"); - dlclose(pLibRandR); - return JNI_FALSE; - } - - if (usingXinerama) { - /* - * We can proceed as long as this is RANDR 1.2 or above. - * As of Xorg server 1.3 onwards the Xinerama backend may actually be - * a fake one provided by RANDR itself. See Java bug 6636469 for info. - */ - if (!(rr_maj_ver > 1 || (rr_maj_ver == 1 && rr_min_ver >= 2))) { - J2dRlsTraceLn2(J2D_TRACE_INFO, "X11GD_InitXrandrFuncs: Can't use Xrandr. " - "Xinerama is active and Xrandr version is %d.%d", - rr_maj_ver, rr_min_ver); - dlclose(pLibRandR); - return JNI_FALSE; - } - - /* - * REMIND: Fullscreen mode doesn't work quite right with multi-monitor - * setups and RANDR 1.2. - */ - if ((rr_maj_ver == 1 && rr_min_ver <= 2) && awt_numScreens > 1) { - J2dRlsTraceLn(J2D_TRACE_INFO, "X11GD_InitXrandrFuncs: Can't use Xrandr. " - "Multiple screens in use"); - dlclose(pLibRandR); - return JNI_FALSE; - } - } - - LOAD_XRANDR_FUNC(XRRGetScreenInfo); - LOAD_XRANDR_FUNC(XRRFreeScreenConfigInfo); - LOAD_XRANDR_FUNC(XRRConfigRates); - LOAD_XRANDR_FUNC(XRRConfigCurrentRate); - LOAD_XRANDR_FUNC(XRRConfigSizes); - LOAD_XRANDR_FUNC(XRRConfigCurrentConfiguration); - LOAD_XRANDR_FUNC(XRRSetScreenConfigAndRate); - LOAD_XRANDR_FUNC(XRRConfigRotations); - LOAD_XRANDR_FUNC(XRRGetScreenResources); - LOAD_XRANDR_FUNC(XRRFreeScreenResources); - LOAD_XRANDR_FUNC(XRRGetOutputInfo); - LOAD_XRANDR_FUNC(XRRFreeOutputInfo); - LOAD_XRANDR_FUNC(XRRGetCrtcInfo); - LOAD_XRANDR_FUNC(XRRFreeCrtcInfo); - - return JNI_TRUE; -} - -static void -X11GD_AddDisplayMode(JNIEnv *env, jobject arrayList, - jint width, jint height, - jint bitDepth, jint refreshRate) -{ - jobject displayMode = X11GD_CreateDisplayMode(env, width, height, - bitDepth, refreshRate); - if (!JNU_IsNull(env, displayMode)) { - jclass arrayListClass; - jmethodID mid; - arrayListClass = (*env)->GetObjectClass(env, arrayList); - if (JNU_IsNull(env, arrayListClass)) { - JNU_ThrowInternalError(env, - "Could not get class java.util.ArrayList"); - return; - } - mid = (*env)->GetMethodID(env, arrayListClass, "add", - "(Ljava/lang/Object;)Z"); - CHECK_NULL(mid); - if (mid == NULL) { - JNU_ThrowInternalError(env, - "Could not get method java.util.ArrayList.add()"); - return; - } - (*env)->CallObjectMethod(env, arrayList, mid, displayMode); - (*env)->DeleteLocalRef(env, displayMode); - } -} - -static void -X11GD_SetFullscreenMode(Window win, jboolean enabled) -{ - Atom wmState = XInternAtom(awt_display, "_NET_WM_STATE", False); - Atom wmStateFs = XInternAtom(awt_display, - "_NET_WM_STATE_FULLSCREEN", False); - XWindowAttributes attr; - XEvent event; - - if (wmState == None || wmStateFs == None - || !XGetWindowAttributes(awt_display, win, &attr)) { - return; - } - - memset(&event, 0, sizeof(event)); - event.xclient.type = ClientMessage; - event.xclient.message_type = wmState; - event.xclient.display = awt_display; - event.xclient.window = win; - event.xclient.format = 32; - event.xclient.data.l[0] = enabled ? 1 : 0; // 1==add, 0==remove - event.xclient.data.l[1] = wmStateFs; - - XSendEvent(awt_display, attr.root, False, - SubstructureRedirectMask | SubstructureNotifyMask, - &event); - XSync(awt_display, False); -} -#endif /* !HEADLESS */ - -// #if !defined(HEADLESS) || defined(__ANDROID__) -static jobject -X11GD_CreateDisplayMode(JNIEnv *env, jint width, jint height, - jint bitDepth, jint refreshRate) -{ - jclass displayModeClass; - jmethodID cid; - jint validRefreshRate = refreshRate; - - displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode"); - CHECK_NULL_RETURN(displayModeClass, NULL); - if (JNU_IsNull(env, displayModeClass)) { - JNU_ThrowInternalError(env, - "Could not get display mode class"); - return NULL; - } - - cid = (*env)->GetMethodID(env, displayModeClass, "", "(IIII)V"); - CHECK_NULL_RETURN(cid, NULL); - if (cid == NULL) { - JNU_ThrowInternalError(env, - "Could not get display mode constructor"); - return NULL; - } - - // early versions of xrandr may report "empty" rates (6880694) - if (validRefreshRate <= 0) { - validRefreshRate = REFRESH_RATE_UNKNOWN; - } - - return (*env)->NewObject(env, displayModeClass, cid, - width, height, bitDepth, validRefreshRate); -} -// #endif - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: initXrandrExtension - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsDevice_initXrandrExtension - (JNIEnv *env, jclass x11gd) -{ -#ifdef HEADLESS - return JNI_FALSE; -#else - int opcode = 0, firstEvent = 0, firstError = 0; - jboolean ret; - - AWT_LOCK(); - ret = (jboolean)XQueryExtension(awt_display, "RANDR", - &opcode, &firstEvent, &firstError); - if (ret) { - ret = X11GD_InitXrandrFuncs(env); - } - AWT_FLUSH_UNLOCK(); - - return ret; -#endif /* HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getCurrentDisplayMode - * Signature: (I)Ljava/awt/DisplayMode; - */ -JNIEXPORT jobject JNICALL -Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode - (JNIEnv* env, jclass x11gd, jint screen) -{ -#ifdef HEADLESS - return X11GD_CreateDisplayMode(env, GLOBAL_WIDTH, GLOBAL_HEIGHT /* mode->width, mode->height */, BIT_DEPTH_MULTI, (int)(/* rate */ 60 +.2)); -#else - XRRScreenConfiguration *config; - jobject displayMode = NULL; - - AWT_LOCK(); - - if (usingXinerama && XScreenCount(awt_display) > 0) { - XRRScreenResources *res = awt_XRRGetScreenResources(awt_display, - RootWindow(awt_display, 0)); - if (res) { - if (res->noutput > screen) { - XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display, - res, res->outputs[screen]); - if (output_info) { - if (output_info->crtc) { - XRRCrtcInfo *crtc_info = - awt_XRRGetCrtcInfo (awt_display, res, - output_info->crtc); - if (crtc_info) { - if (crtc_info->mode) { - int i; - for (i = 0; i < res->nmode; i++) { - XRRModeInfo *mode = &res->modes[i]; - if (mode->id == crtc_info->mode) { - float rate = 0; - if (mode->hTotal && mode->vTotal) { - rate = ((float)mode->dotClock / - ((float)mode->hTotal * - (float)mode->vTotal)); - } - displayMode = X11GD_CreateDisplayMode( - env, - mode->width, - mode->height, - BIT_DEPTH_MULTI, - (int)(rate +.2)); - break; - } - } - } - awt_XRRFreeCrtcInfo(crtc_info); - } - } - awt_XRRFreeOutputInfo(output_info); - } - } - awt_XRRFreeScreenResources(res); - } - } else { - - config = awt_XRRGetScreenInfo(awt_display, - RootWindow(awt_display, screen)); - if (config != NULL) { - Rotation rotation; - short curRate; - SizeID curSizeIndex; - XRRScreenSize *sizes; - int nsizes; - - curSizeIndex = awt_XRRConfigCurrentConfiguration(config, &rotation); - sizes = awt_XRRConfigSizes(config, &nsizes); - curRate = awt_XRRConfigCurrentRate(config); - - if ((sizes != NULL) && - (curSizeIndex < nsizes)) - { - XRRScreenSize curSize = sizes[curSizeIndex]; - displayMode = X11GD_CreateDisplayMode(env, - curSize.width, - curSize.height, - BIT_DEPTH_MULTI, - curRate); - } - - awt_XRRFreeScreenConfigInfo(config); - } - } - - AWT_FLUSH_UNLOCK(); - - return displayMode; -#endif /* HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: enumDisplayModes - * Signature: (ILjava/util/ArrayList;)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_enumDisplayModes - (JNIEnv* env, jclass x11gd, - jint screen, jobject arrayList) -{ -#ifndef HEADLESS - - AWT_LOCK(); - - if (usingXinerama && XScreenCount(awt_display) > 0) { - XRRScreenResources *res = awt_XRRGetScreenResources(awt_display, - RootWindow(awt_display, 0)); - if (res) { - if (res->noutput > screen) { - XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display, - res, res->outputs[screen]); - if (output_info) { - int i; - for (i = 0; i < output_info->nmode; i++) { - RRMode m = output_info->modes[i]; - int j; - XRRModeInfo *mode; - for (j = 0; j < res->nmode; j++) { - mode = &res->modes[j]; - if (mode->id == m) { - float rate = 0; - if (mode->hTotal && mode->vTotal) { - rate = ((float)mode->dotClock / - ((float)mode->hTotal * - (float)mode->vTotal)); - } - X11GD_AddDisplayMode(env, arrayList, - mode->width, mode->height, - BIT_DEPTH_MULTI, (int)(rate +.2)); - if ((*env)->ExceptionCheck(env)) { - goto ret0; - } - break; - } - } - } -ret0: - awt_XRRFreeOutputInfo(output_info); - } - } - awt_XRRFreeScreenResources(res); - } - } else { - XRRScreenConfiguration *config; - - config = awt_XRRGetScreenInfo(awt_display, - RootWindow(awt_display, screen)); - if (config != NULL) { - int nsizes, i, j; - XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes); - - if (sizes != NULL) { - for (i = 0; i < nsizes; i++) { - int nrates; - XRRScreenSize size = sizes[i]; - short *rates = awt_XRRConfigRates(config, i, &nrates); - - for (j = 0; j < nrates; j++) { - X11GD_AddDisplayMode(env, arrayList, - size.width, - size.height, - BIT_DEPTH_MULTI, - rates[j]); - if ((*env)->ExceptionCheck(env)) { - goto ret1; - } - } - } - } -ret1: - awt_XRRFreeScreenConfigInfo(config); - } - } - - AWT_FLUSH_UNLOCK(); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: configDisplayMode - * Signature: (IIII)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_configDisplayMode - (JNIEnv* env, jclass x11gd, - jint screen, jint width, jint height, jint refreshRate) -{ -#ifndef HEADLESS - jboolean success = JNI_FALSE; - XRRScreenConfiguration *config; - Drawable root; - Rotation currentRotation = RR_Rotate_0; - - AWT_LOCK(); - - root = RootWindow(awt_display, screen); - config = awt_XRRGetScreenInfo(awt_display, root); - if (config != NULL) { - jboolean foundConfig = JNI_FALSE; - int chosenSizeIndex = -1; - short chosenRate = -1; - int nsizes; - XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes); - awt_XRRConfigRotations(config, ¤tRotation); - - if (sizes != NULL) { - int i, j; - - /* find the size index that matches the requested dimensions */ - for (i = 0; i < nsizes; i++) { - XRRScreenSize size = sizes[i]; - - if ((size.width == width) && (size.height == height)) { - /* we've found our size index... */ - int nrates; - short *rates = awt_XRRConfigRates(config, i, &nrates); - - /* now find rate that matches requested refresh rate */ - for (j = 0; j < nrates; j++) { - if (rates[j] == refreshRate) { - /* we've found our rate; break out of the loop */ - chosenSizeIndex = i; - chosenRate = rates[j]; - foundConfig = JNI_TRUE; - break; - } - } - - break; - } - } - } - - if (foundConfig) { - Status status = - awt_XRRSetScreenConfigAndRate(awt_display, config, root, - chosenSizeIndex, - currentRotation, - chosenRate, - CurrentTime); - - /* issue XSync to ensure immediate mode change */ - XSync(awt_display, False); - - if (status == RRSetConfigSuccess) { - success = JNI_TRUE; - } - } - - awt_XRRFreeScreenConfigInfo(config); - } - - AWT_FLUSH_UNLOCK(); - - if (!success && !(*env)->ExceptionCheck(env)) { - JNU_ThrowInternalError(env, "Could not set display mode"); - } -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: enterFullScreenExclusive - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_enterFullScreenExclusive - (JNIEnv* env, jclass x11gd, - jlong window) -{ -#ifndef HEADLESS - Window win = (Window)window; - - AWT_LOCK(); - XSync(awt_display, False); /* ensures window is visible first */ - X11GD_SetFullscreenMode(win, JNI_TRUE); - AWT_UNLOCK(); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: exitFullScreenExclusive - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11GraphicsDevice_exitFullScreenExclusive - (JNIEnv* env, jclass x11gd, - jlong window) -{ -#ifndef HEADLESS - Window win = (Window)window; - - AWT_LOCK(); - X11GD_SetFullscreenMode(win, JNI_FALSE); - AWT_UNLOCK(); -#endif /* !HEADLESS */ -} - -/** - * End DisplayMode/FullScreen support - */ - -static char *get_output_screen_name(JNIEnv *env, int screen) { - if (!awt_XRRGetScreenResources || !awt_XRRGetOutputInfo) { - return NULL; - } - char *name = NULL; - AWT_LOCK(); - int scr = 0, out = 0; - if (usingXinerama && XScreenCount(awt_display) > 0) { - out = screen; - } else { - scr = screen; - } - - XRRScreenResources *res = awt_XRRGetScreenResources(awt_display, - RootWindow(awt_display, scr)); - if (res) { - if (res->noutput > out) { - XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display, - res, res->outputs[out]); - if (output_info) { - if (output_info->name) { - name = strdup(output_info->name); - } - awt_XRRFreeOutputInfo(output_info); - } - } - awt_XRRFreeScreenResources(res); - } - AWT_UNLOCK(); - return name; -} - -/* - * Class: sun_awt_X11GraphicsDevice - * Method: getNativeScaleFactor - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor - (JNIEnv *env, jobject this, jint screen) { - // in case of Xinerama individual screen scales are not supported - char *name = get_output_screen_name(env, usingXinerama ? 0 : screen); - double scale = getNativeScaleFactor(name); - if (name) { - free(name); - } - return scale; -} - diff --git a/app/src/main/jni/awt_xawt/awt/awt_InputMethod.c b/app/src/main/jni/awt_xawt/awt/awt_InputMethod.c deleted file mode 100644 index fbf11575e..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_InputMethod.c +++ /dev/null @@ -1,1651 +0,0 @@ -/* - * Copyright (c) 1997, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include -#include -#include -#include -#include - -#include "awt.h" -#include "awt_p.h" - -#include -#include - -#define THROW_OUT_OF_MEMORY_ERROR() \ - JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL) - -struct X11InputMethodIDs { - jfieldID pData; -} x11InputMethodIDs; - -static void PreeditStartCallback(XIC, XPointer, XPointer); -static void PreeditDoneCallback(XIC, XPointer, XPointer); -static void PreeditDrawCallback(XIC, XPointer, - XIMPreeditDrawCallbackStruct *); -static void PreeditCaretCallback(XIC, XPointer, - XIMPreeditCaretCallbackStruct *); -#if defined(__linux__) || defined(MACOSX) -static void StatusStartCallback(XIC, XPointer, XPointer); -static void StatusDoneCallback(XIC, XPointer, XPointer); -static void StatusDrawCallback(XIC, XPointer, - XIMStatusDrawCallbackStruct *); -#endif - -#define ROOT_WINDOW_STYLES (XIMPreeditNothing | XIMStatusNothing) -#define NO_STYLES (XIMPreeditNone | XIMStatusNone) - -#define PreeditStartIndex 0 -#define PreeditDoneIndex 1 -#define PreeditDrawIndex 2 -#define PreeditCaretIndex 3 -#if defined(__linux__) || defined(MACOSX) -#define StatusStartIndex 4 -#define StatusDoneIndex 5 -#define StatusDrawIndex 6 -#define NCALLBACKS 7 -#else -#define NCALLBACKS 4 -#endif - -/* - * Callback function pointers: the order has to match the *Index - * values above. - */ -static XIMProc callback_funcs[NCALLBACKS] = { - (XIMProc)PreeditStartCallback, - (XIMProc)PreeditDoneCallback, - (XIMProc)PreeditDrawCallback, - (XIMProc)PreeditCaretCallback, -#if defined(__linux__) || defined(MACOSX) - (XIMProc)StatusStartCallback, - (XIMProc)StatusDoneCallback, - (XIMProc)StatusDrawCallback, -#endif -}; - -#if defined(__linux__) || defined(MACOSX) -#define MAX_STATUS_LEN 100 -typedef struct { - Window w; /*status window id */ - Window root; /*the root window id */ - Window parent; /*parent shell window */ - int x, y; /*parent's upperleft position */ - int width, height; /*parent's width, height */ - GC lightGC; /*gc for light border */ - GC dimGC; /*gc for dim border */ - GC bgGC; /*normal painting */ - GC fgGC; /*normal painting */ - int statusW, statusH; /*status window's w, h */ - int rootW, rootH; /*root window's w, h */ - int bWidth; /*border width */ - char status[MAX_STATUS_LEN]; /*status text */ - XFontSet fontset; /*fontset for drawing */ - int off_x, off_y; - Bool on; /*if the status window on*/ -} StatusWindow; -#endif - -/* - * X11InputMethodData keeps per X11InputMethod instance information. A pointer - * to this data structure is kept in an X11InputMethod object (pData). - */ -typedef struct _X11InputMethodData { - XIC current_ic; /* current X Input Context */ - XIC ic_active; /* X Input Context for active clients */ - XIC ic_passive; /* X Input Context for passive clients */ - XIMCallback *callbacks; /* callback parameters */ - jobject x11inputmethod; /* global ref to X11InputMethod instance */ - /* associated with the XIC */ -#if defined(__linux__) || defined(MACOSX) - StatusWindow *statusWindow; /* our own status window */ -#endif - char *lookup_buf; /* buffer used for XmbLookupString */ - int lookup_buf_len; /* lookup buffer size in bytes */ -} X11InputMethodData; - -/* - * When XIC is created, a global reference is created for - * sun.awt.X11InputMethod object so that it could be used by the XIM callback - * functions. This could be a dangerous thing to do when the original - * X11InputMethod object is garbage collected and as a result, - * destroyX11InputMethodData is called to delete the global reference. - * If any XIM callback function still holds and uses the "already deleted" - * global reference, disaster is going to happen. So we have to maintain - * a list for these global references which is consulted first when the - * callback functions or any function tries to use "currentX11InputMethodObject" - * which always refers to the global reference try to use it. - * - */ -typedef struct _X11InputMethodGRefNode { - jobject inputMethodGRef; - struct _X11InputMethodGRefNode* next; -} X11InputMethodGRefNode; - -X11InputMethodGRefNode *x11InputMethodGRefListHead = NULL; - -/* reference to the current X11InputMethod instance, it is always - point to the global reference to the X11InputMethodObject since - it could be referenced by different threads. */ -jobject currentX11InputMethodInstance = NULL; - -Window currentFocusWindow = 0; /* current window that has focus for input - method. (the best place to put this - information should be - currentX11InputMethodInstance's pData) */ -static XIM X11im = NULL; -Display * dpy = NULL; - -#define GetJNIEnv() (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2) - -static void DestroyXIMCallback(XIM, XPointer, XPointer); -static void OpenXIMCallback(Display *, XPointer, XPointer); -/* Solaris XIM Extention */ -#define XNCommitStringCallback "commitStringCallback" -static void CommitStringCallback(XIC, XPointer, XPointer); - -static X11InputMethodData * getX11InputMethodData(JNIEnv *, jobject); -static void setX11InputMethodData(JNIEnv *, jobject, X11InputMethodData *); -static void destroyX11InputMethodData(JNIEnv *, X11InputMethodData *); -static void freeX11InputMethodData(JNIEnv *, X11InputMethodData *); - -#ifdef __solaris__ -/* Prototype for this function is missing in Solaris X11R6 Xlib.h */ -extern char *XSetIMValues( -#if NeedVarargsPrototypes - XIM /* im */, ... -#endif -); -#endif - -/* - * This function is stolen from /src/solaris/hpi/src/system_md.c - * It is used in setting the time in Java-level InputEvents - */ -jlong -awt_util_nowMillisUTC() -{ - struct timeval t; - gettimeofday(&t, NULL); - return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000); -} - -/* - * Converts the wchar_t string to a multi-byte string calling wcstombs(). A - * buffer is allocated by malloc() to store the multi-byte string. NULL is - * returned if the given wchar_t string pointer is NULL or buffer allocation is - * failed. - */ -static char * -wcstombsdmp(wchar_t *wcs, int len) -{ - size_t n; - char *mbs; - - if (wcs == NULL) - return NULL; - - n = len*MB_CUR_MAX + 1; - - mbs = (char *) malloc(n * sizeof(char)); - if (mbs == NULL) { - THROW_OUT_OF_MEMORY_ERROR(); - return NULL; - } - - /* TODO: check return values... Handle invalid characters properly... */ - if (wcstombs(mbs, wcs, n) == (size_t)-1) { - free(mbs); - return NULL; - } - - return mbs; -} - -/* - * Returns True if the global reference is still in the list, - * otherwise False. - */ -static Bool isX11InputMethodGRefInList(jobject imGRef) { - X11InputMethodGRefNode *pX11InputMethodGRef = x11InputMethodGRefListHead; - - if (imGRef == NULL) { - return False; - } - - while (pX11InputMethodGRef != NULL) { - if (pX11InputMethodGRef->inputMethodGRef == imGRef) { - return True; - } - pX11InputMethodGRef = pX11InputMethodGRef->next; - } - - return False; -} - -/* - * Add the new created global reference to the list. - */ -static void addToX11InputMethodGRefList(jobject newX11InputMethodGRef) { - X11InputMethodGRefNode *newNode = NULL; - - if (newX11InputMethodGRef == NULL || - isX11InputMethodGRefInList(newX11InputMethodGRef)) { - return; - } - - newNode = (X11InputMethodGRefNode *)malloc(sizeof(X11InputMethodGRefNode)); - - if (newNode == NULL) { - return; - } else { - newNode->inputMethodGRef = newX11InputMethodGRef; - newNode->next = x11InputMethodGRefListHead; - x11InputMethodGRefListHead = newNode; - } -} - -/* - * Remove the global reference from the list. - */ -static void removeX11InputMethodGRefFromList(jobject x11InputMethodGRef) { - X11InputMethodGRefNode *pX11InputMethodGRef = NULL; - X11InputMethodGRefNode *cX11InputMethodGRef = x11InputMethodGRefListHead; - - if (x11InputMethodGRefListHead == NULL || - x11InputMethodGRef == NULL) { - return; - } - - /* cX11InputMethodGRef always refers to the current node while - pX11InputMethodGRef refers to the previous node. - */ - while (cX11InputMethodGRef != NULL) { - if (cX11InputMethodGRef->inputMethodGRef == x11InputMethodGRef) { - break; - } - pX11InputMethodGRef = cX11InputMethodGRef; - cX11InputMethodGRef = cX11InputMethodGRef->next; - } - - if (cX11InputMethodGRef == NULL) { - return; /* Not found. */ - } - - if (cX11InputMethodGRef == x11InputMethodGRefListHead) { - x11InputMethodGRefListHead = x11InputMethodGRefListHead->next; - } else { - pX11InputMethodGRef->next = cX11InputMethodGRef->next; - } - free(cX11InputMethodGRef); - - return; -} - - -static X11InputMethodData * getX11InputMethodData(JNIEnv * env, jobject imInstance) { - X11InputMethodData *pX11IMData = - (X11InputMethodData *)JNU_GetLongFieldAsPtr(env, imInstance, x11InputMethodIDs.pData); - - /* - * In case the XIM server was killed somehow, reset X11InputMethodData. - */ - if (X11im == NULL && pX11IMData != NULL) { - JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod, - "flushText", - "()V"); - JNU_CHECK_EXCEPTION_RETURN(env, NULL); - /* IMPORTANT: - The order of the following calls is critical since "imInstance" may - point to the global reference itself, if "freeX11InputMethodData" is called - first, the global reference will be destroyed and "setX11InputMethodData" - will in fact fail silently. So pX11IMData will not be set to NULL. - This could make the original java object refers to a deleted pX11IMData - object. - */ - setX11InputMethodData(env, imInstance, NULL); - freeX11InputMethodData(env, pX11IMData); - pX11IMData = NULL; - } - - return pX11IMData; -} - -static void setX11InputMethodData(JNIEnv * env, jobject imInstance, X11InputMethodData *pX11IMData) { - JNU_SetLongFieldFromPtr(env, imInstance, x11InputMethodIDs.pData, pX11IMData); -} - -/* this function should be called within AWT_LOCK() */ -static void -destroyX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData) -{ - /* - * Destroy XICs - */ - if (pX11IMData == NULL) { - return; - } - - if (pX11IMData->ic_active != (XIC)0) { - XUnsetICFocus(pX11IMData->ic_active); - XDestroyIC(pX11IMData->ic_active); - if (pX11IMData->ic_active != pX11IMData->ic_passive) { - if (pX11IMData->ic_passive != (XIC)0) { - XUnsetICFocus(pX11IMData->ic_passive); - XDestroyIC(pX11IMData->ic_passive); - } - pX11IMData->ic_passive = (XIC)0; - pX11IMData->current_ic = (XIC)0; - } - } - - freeX11InputMethodData(env, pX11IMData); -} - -static void -freeX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData) -{ -#if defined(__linux__) || defined(MACOSX) - if (pX11IMData->statusWindow != NULL){ - StatusWindow *sw = pX11IMData->statusWindow; - XFreeGC(awt_display, sw->lightGC); - XFreeGC(awt_display, sw->dimGC); - XFreeGC(awt_display, sw->bgGC); - XFreeGC(awt_display, sw->fgGC); - if (sw->fontset != NULL) { - XFreeFontSet(awt_display, sw->fontset); - } - XDestroyWindow(awt_display, sw->w); - free((void*)sw); - } -#endif - - if (pX11IMData->callbacks) - free((void *)pX11IMData->callbacks); - - if (env) { - /* Remove the global reference from the list, so that - the callback function or whoever refers to it could know. - */ - removeX11InputMethodGRefFromList(pX11IMData->x11inputmethod); - (*env)->DeleteGlobalRef(env, pX11IMData->x11inputmethod); - } - - if (pX11IMData->lookup_buf) { - free((void *)pX11IMData->lookup_buf); - } - - free((void *)pX11IMData); -} - -/* - * Sets or unsets the focus to the given XIC. - */ -static void -setXICFocus(XIC ic, unsigned short req) -{ - if (ic == NULL) { - (void)fprintf(stderr, "Couldn't find X Input Context\n"); - return; - } - if (req == 1) - XSetICFocus(ic); - else - XUnsetICFocus(ic); -} - -/* - * Sets the focus window to the given XIC. - */ -static void -setXICWindowFocus(XIC ic, Window w) -{ - if (ic == NULL) { - (void)fprintf(stderr, "Couldn't find X Input Context\n"); - return; - } - (void) XSetICValues(ic, XNFocusWindow, w, NULL); -} - -/* - * Invokes XmbLookupString() to get something from the XIM. It invokes - * X11InputMethod.dispatchCommittedText() if XmbLookupString() returns - * committed text. This function is called from handleKeyEvent in canvas.c and - * it's under the Motif event loop thread context. - * - * Buffer usage: There is a bug in XFree86-4.3.0 XmbLookupString implementation, - * where it never returns XBufferOverflow. We need to allocate the initial lookup buffer - * big enough, so that the possibility that user encounters this problem is relatively - * small. When this bug gets fixed, we can make the initial buffer size smaller. - * Note that XmbLookupString() sometimes produces a non-null-terminated string. - * - * Returns True when there is a keysym value to be handled. - */ -#define INITIAL_LOOKUP_BUF_SIZE 512 - -Boolean -awt_x11inputmethod_lookupString(XKeyPressedEvent *event, KeySym *keysymp) -{ - JNIEnv *env = GetJNIEnv(); - X11InputMethodData *pX11IMData = NULL; - KeySym keysym = NoSymbol; - Status status; - int mblen; - jstring javastr; - XIC ic; - Boolean result = True; - static Boolean composing = False; - - /* - printf("lookupString: entering...\n"); - */ - - if (!isX11InputMethodGRefInList(currentX11InputMethodInstance)) { - currentX11InputMethodInstance = NULL; - return False; - } - - pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance); - - if (pX11IMData == NULL) { -#if defined(__linux__) || defined(MACOSX) - return False; -#else - return result; -#endif - } - - if ((ic = pX11IMData->current_ic) == (XIC)0){ -#if defined(__linux__) || defined(MACOSX) - return False; -#else - return result; -#endif - } - - /* allocate the lookup buffer at the first invocation */ - if (pX11IMData->lookup_buf_len == 0) { - pX11IMData->lookup_buf = (char *)malloc(INITIAL_LOOKUP_BUF_SIZE); - if (pX11IMData->lookup_buf == NULL) { - THROW_OUT_OF_MEMORY_ERROR(); - return result; - } - pX11IMData->lookup_buf_len = INITIAL_LOOKUP_BUF_SIZE; - } - - mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf, - pX11IMData->lookup_buf_len - 1, &keysym, &status); - - /* - * In case of overflow, a buffer is allocated and it retries - * XmbLookupString(). - */ - if (status == XBufferOverflow) { - free((void *)pX11IMData->lookup_buf); - pX11IMData->lookup_buf_len = 0; - pX11IMData->lookup_buf = (char *)malloc(mblen + 1); - if (pX11IMData->lookup_buf == NULL) { - THROW_OUT_OF_MEMORY_ERROR(); - return result; - } - pX11IMData->lookup_buf_len = mblen + 1; - mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf, - pX11IMData->lookup_buf_len - 1, &keysym, &status); - } - pX11IMData->lookup_buf[mblen] = 0; - - /* Get keysym without taking modifiers into account first to map - * to AWT keyCode table. - */ - switch (status) { - case XLookupBoth: - if (!composing) { - if (event->keycode != 0) { - *keysymp = keysym; - result = False; - break; - } - } - composing = False; - /*FALLTHRU*/ - case XLookupChars: - /* - printf("lookupString: status=XLookupChars, type=%d, state=%x, keycode=%x, keysym=%x\n", - event->type, event->state, event->keycode, keysym); - */ - javastr = JNU_NewStringPlatform(env, (const char *)pX11IMData->lookup_buf); - if (javastr != NULL) { - JNU_CallMethodByName(env, NULL, - currentX11InputMethodInstance, - "dispatchCommittedText", - "(Ljava/lang/String;J)V", - javastr, - event->time); - } - break; - - case XLookupKeySym: - /* - printf("lookupString: status=XLookupKeySym, type=%d, state=%x, keycode=%x, keysym=%x\n", - event->type, event->state, event->keycode, keysym); - */ - if (keysym == XK_Multi_key) - composing = True; - if (! composing) { - *keysymp = keysym; - result = False; - } - break; - - case XLookupNone: - /* - printf("lookupString: status=XLookupNone, type=%d, state=%x, keycode=%x, keysym=%x\n", - event->type, event->state, event->keycode, keysym); - */ - break; - } - - return result; -} - -#if defined(__linux__) || defined(MACOSX) -static StatusWindow *createStatusWindow( - Window parent) { - StatusWindow *statusWindow; - XSetWindowAttributes attrib; - unsigned long attribmask; - Window containerWindow; - Window status; - Window child; - XWindowAttributes xwa; - XWindowAttributes xxwa; - /* Variable for XCreateFontSet()*/ - char **mclr; - int mccr = 0; - char *dsr; - unsigned long bg, fg, light, dim; - int x, y, off_x, off_y, xx, yy; - unsigned int w, h, bw, depth; - XGCValues values; - unsigned long valuemask = 0; /*ignore XGCvalue and use defaults*/ - int screen = 0; - int i; - AwtGraphicsConfigDataPtr adata; - extern int awt_numScreens; - /*hardcode the size right now, should get the size base on font*/ - int width=80, height=22; - Window rootWindow; - Window *ignoreWindowPtr; - unsigned int ignoreUnit; - - XGetGeometry(dpy, parent, &rootWindow, &x, &y, &w, &h, &bw, &depth); - - attrib.override_redirect = True; - attribmask = CWOverrideRedirect; - for (i = 0; i < awt_numScreens; i++) { - if (RootWindow(dpy, i) == rootWindow) { - screen = i; - break; - } - } - adata = getDefaultConfig(screen); - bg = adata->AwtColorMatch(255, 255, 255, adata); - fg = adata->AwtColorMatch(0, 0, 0, adata); - light = adata->AwtColorMatch(195, 195, 195, adata); - dim = adata->AwtColorMatch(128, 128, 128, adata); - - XGetWindowAttributes(dpy, parent, &xwa); - bw = 2; /*xwa.border_width does not have the correct value*/ - - /*compare the size difference between parent container - and shell widget, the diff should be the border frame - and title bar height (?)*/ - - XQueryTree( dpy, - parent, - &rootWindow, - &containerWindow, - &ignoreWindowPtr, - &ignoreUnit); - XGetWindowAttributes(dpy, containerWindow, &xxwa); - - off_x = (xxwa.width - xwa.width) / 2; - off_y = xxwa.height - xwa.height - off_x; /*it's magic:-) */ - - /*get the size of root window*/ - XGetWindowAttributes(dpy, rootWindow, &xxwa); - - XTranslateCoordinates(dpy, - parent, xwa.root, - xwa.x, xwa.y, - &x, &y, - &child); - xx = x - off_x; - yy = y + xwa.height - off_y; - if (xx < 0 ){ - xx = 0; - } - if (xx + width > xxwa.width){ - xx = xxwa.width - width; - } - if (yy + height > xxwa.height){ - yy = xxwa.height - height; - } - - status = XCreateWindow(dpy, - xwa.root, - xx, yy, - width, height, - 0, - xwa.depth, - InputOutput, - adata->awt_visInfo.visual, - attribmask, &attrib); - XSelectInput(dpy, status, - ExposureMask | StructureNotifyMask | EnterWindowMask | - LeaveWindowMask | VisibilityChangeMask); - statusWindow = (StatusWindow*) calloc(1, sizeof(StatusWindow)); - if (statusWindow == NULL){ - THROW_OUT_OF_MEMORY_ERROR(); - return NULL; - } - statusWindow->w = status; - //12-point font - statusWindow->fontset = XCreateFontSet(dpy, - "-*-*-medium-r-normal-*-*-120-*-*-*-*", - &mclr, &mccr, &dsr); - /* In case we didn't find the font set, release the list of missing characters */ - if (mccr > 0) { - XFreeStringList(mclr); - } - statusWindow->parent = parent; - statusWindow->on = False; - statusWindow->x = x; - statusWindow->y = y; - statusWindow->width = xwa.width; - statusWindow->height = xwa.height; - statusWindow->off_x = off_x; - statusWindow->off_y = off_y; - statusWindow->bWidth = bw; - statusWindow->statusH = height; - statusWindow->statusW = width; - statusWindow->rootH = xxwa.height; - statusWindow->rootW = xxwa.width; - statusWindow->lightGC = XCreateGC(dpy, status, valuemask, &values); - XSetForeground(dpy, statusWindow->lightGC, light); - statusWindow->dimGC = XCreateGC(dpy, status, valuemask, &values); - XSetForeground(dpy, statusWindow->dimGC, dim); - statusWindow->fgGC = XCreateGC(dpy, status, valuemask, &values); - XSetForeground(dpy, statusWindow->fgGC, fg); - statusWindow->bgGC = XCreateGC(dpy, status, valuemask, &values); - XSetForeground(dpy, statusWindow->bgGC, bg); - return statusWindow; -} - -/* This method is to turn off or turn on the status window. */ -static void onoffStatusWindow(X11InputMethodData* pX11IMData, - Window parent, - Bool ON){ - XWindowAttributes xwa; - Window child; - int x, y; - StatusWindow *statusWindow = NULL; - - if (NULL == currentX11InputMethodInstance || - NULL == pX11IMData || - NULL == (statusWindow = pX11IMData->statusWindow)){ - return; - } - - if (ON == False){ - XUnmapWindow(dpy, statusWindow->w); - statusWindow->on = False; - return; - } - parent = JNU_CallMethodByName(GetJNIEnv(), NULL, pX11IMData->x11inputmethod, - "getCurrentParentWindow", - "()J").j; - if (statusWindow->parent != parent){ - statusWindow->parent = parent; - } - XGetWindowAttributes(dpy, parent, &xwa); - XTranslateCoordinates(dpy, - parent, xwa.root, - xwa.x, xwa.y, - &x, &y, - &child); - if (statusWindow->x != x - || statusWindow->y != y - || statusWindow->height != xwa.height){ - statusWindow->x = x; - statusWindow->y = y; - statusWindow->height = xwa.height; - x = statusWindow->x - statusWindow->off_x; - y = statusWindow->y + statusWindow->height - statusWindow->off_y; - if (x < 0 ){ - x = 0; - } - if (x + statusWindow->statusW > statusWindow->rootW){ - x = statusWindow->rootW - statusWindow->statusW; - } - if (y + statusWindow->statusH > statusWindow->rootH){ - y = statusWindow->rootH - statusWindow->statusH; - } - XMoveWindow(dpy, statusWindow->w, x, y); - } - statusWindow->on = True; - XMapWindow(dpy, statusWindow->w); -} - -void paintStatusWindow(StatusWindow *statusWindow){ - Window win = statusWindow->w; - GC lightgc = statusWindow->lightGC; - GC dimgc = statusWindow->dimGC; - GC bggc = statusWindow->bgGC; - GC fggc = statusWindow->fgGC; - - int width = statusWindow->statusW; - int height = statusWindow->statusH; - int bwidth = statusWindow->bWidth; - XFillRectangle(dpy, win, bggc, 0, 0, width, height); - /* draw border */ - XDrawLine(dpy, win, fggc, 0, 0, width, 0); - XDrawLine(dpy, win, fggc, 0, height-1, width-1, height-1); - XDrawLine(dpy, win, fggc, 0, 0, 0, height-1); - XDrawLine(dpy, win, fggc, width-1, 0, width-1, height-1); - - XDrawLine(dpy, win, lightgc, 1, 1, width-bwidth, 1); - XDrawLine(dpy, win, lightgc, 1, 1, 1, height-2); - XDrawLine(dpy, win, lightgc, 1, height-2, width-bwidth, height-2); - XDrawLine(dpy, win, lightgc, width-bwidth-1, 1, width-bwidth-1, height-2); - - XDrawLine(dpy, win, dimgc, 2, 2, 2, height-3); - XDrawLine(dpy, win, dimgc, 2, height-3, width-bwidth-1, height-3); - XDrawLine(dpy, win, dimgc, 2, 2, width-bwidth-2, 2); - XDrawLine(dpy, win, dimgc, width-bwidth, 2, width-bwidth, height-3); - if (statusWindow->fontset){ - XmbDrawString(dpy, win, statusWindow->fontset, fggc, - bwidth + 2, height - bwidth - 4, - statusWindow->status, - strlen(statusWindow->status)); - } - else{ - /*too bad we failed to create a fontset for this locale*/ - XDrawString(dpy, win, fggc, bwidth + 2, height - bwidth - 4, - "[InputMethod ON]", strlen("[InputMethod ON]")); - } -} - -void statusWindowEventHandler(XEvent event){ - JNIEnv *env = GetJNIEnv(); - X11InputMethodData *pX11IMData = NULL; - StatusWindow *statusWindow; - - if (!isX11InputMethodGRefInList(currentX11InputMethodInstance)) { - currentX11InputMethodInstance = NULL; - return; - } - - if (NULL == currentX11InputMethodInstance - || NULL == (pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance)) - || NULL == (statusWindow = pX11IMData->statusWindow) - || statusWindow->w != event.xany.window){ - return; - } - - switch (event.type){ - case Expose: - paintStatusWindow(statusWindow); - break; - case MapNotify: - case ConfigureNotify: - { - /*need to reset the stackMode...*/ - XWindowChanges xwc; - int value_make = CWStackMode; - xwc.stack_mode = TopIf; - XConfigureWindow(dpy, statusWindow->w, value_make, &xwc); - } - break; - /* - case UnmapNotify: - case VisibilityNotify: - break; - */ - default: - break; - } -} - -static void adjustStatusWindow(Window shell){ - JNIEnv *env = GetJNIEnv(); - X11InputMethodData *pX11IMData = NULL; - StatusWindow *statusWindow; - - if (NULL == currentX11InputMethodInstance - || !isX11InputMethodGRefInList(currentX11InputMethodInstance) - || NULL == (pX11IMData = getX11InputMethodData(env,currentX11InputMethodInstance)) - || NULL == (statusWindow = pX11IMData->statusWindow) - || !statusWindow->on) { - return; - } - { - XWindowAttributes xwa; - int x, y; - Window child; - XGetWindowAttributes(dpy, shell, &xwa); - XTranslateCoordinates(dpy, - shell, xwa.root, - xwa.x, xwa.y, - &x, &y, - &child); - if (statusWindow->x != x - || statusWindow->y != y - || statusWindow->height != xwa.height){ - statusWindow->x = x; - statusWindow->y = y; - statusWindow->height = xwa.height; - - x = statusWindow->x - statusWindow->off_x; - y = statusWindow->y + statusWindow->height - statusWindow->off_y; - if (x < 0 ){ - x = 0; - } - if (x + statusWindow->statusW > statusWindow->rootW){ - x = statusWindow->rootW - statusWindow->statusW; - } - if (y + statusWindow->statusH > statusWindow->rootH){ - y = statusWindow->rootH - statusWindow->statusH; - } - XMoveWindow(dpy, statusWindow->w, x, y); - } - } -} -#endif /* __linux__ || MACOSX */ -/* - * Creates two XICs, one for active clients and the other for passive - * clients. All information on those XICs are stored in the - * X11InputMethodData given by the pX11IMData parameter. - * - * For active clients: Try to use preedit callback to support - * on-the-spot. If tc is not null, the XIC to be created will - * share the Status Area with Motif widgets (TextComponents). If the - * preferable styles can't be used, fallback to root-window styles. If - * root-window styles failed, fallback to None styles. - * - * For passive clients: Try to use root-window styles. If failed, - * fallback to None styles. - */ -static Bool -createXIC(JNIEnv * env, X11InputMethodData *pX11IMData, Window w) -{ - XVaNestedList preedit = NULL; - XVaNestedList status = NULL; - XIMStyle on_the_spot_styles = XIMPreeditCallbacks, - active_styles = 0, - passive_styles = 0, - no_styles = 0; - XIMCallback *callbacks; - unsigned short i; - XIMStyles *im_styles; - char *ret = NULL; - - if (X11im == NULL) { - return False; - } - if (!w) { - return False; - } - - ret = XGetIMValues(X11im, XNQueryInputStyle, &im_styles, NULL); - - if (ret != NULL) { - jio_fprintf(stderr,"XGetIMValues: %s\n",ret); - return FALSE ; - } - -#if defined(__linux__) || defined(MACOSX) - on_the_spot_styles |= XIMStatusNothing; - - /*kinput does not support XIMPreeditCallbacks and XIMStatusArea - at the same time, so use StatusCallback to draw the status - ourself - */ - for (i = 0; i < im_styles->count_styles; i++) { - if (im_styles->supported_styles[i] == (XIMPreeditCallbacks | XIMStatusCallbacks)) { - on_the_spot_styles = (XIMPreeditCallbacks | XIMStatusCallbacks); - break; - } - } -#else /*! __linux__ && !MACOSX */ - on_the_spot_styles |= XIMStatusNothing; -#endif /* __linux__ || MACOSX */ - - for (i = 0; i < im_styles->count_styles; i++) { - active_styles |= im_styles->supported_styles[i] & on_the_spot_styles; - passive_styles |= im_styles->supported_styles[i] & ROOT_WINDOW_STYLES; - no_styles |= im_styles->supported_styles[i] & NO_STYLES; - } - - XFree(im_styles); - - if (active_styles != on_the_spot_styles) { - if (passive_styles == ROOT_WINDOW_STYLES) - active_styles = passive_styles; - else { - if (no_styles == NO_STYLES) - active_styles = passive_styles = NO_STYLES; - else - active_styles = passive_styles = 0; - } - } else { - if (passive_styles != ROOT_WINDOW_STYLES) { - if (no_styles == NO_STYLES) - active_styles = passive_styles = NO_STYLES; - else - active_styles = passive_styles = 0; - } - } - - if (active_styles == on_the_spot_styles) { - pX11IMData->ic_passive = XCreateIC(X11im, - XNClientWindow, w, - XNFocusWindow, w, - XNInputStyle, passive_styles, - NULL); - - callbacks = (XIMCallback *)malloc(sizeof(XIMCallback) * NCALLBACKS); - if (callbacks == (XIMCallback *)NULL) - return False; - pX11IMData->callbacks = callbacks; - - for (i = 0; i < NCALLBACKS; i++, callbacks++) { - callbacks->client_data = (XPointer) pX11IMData->x11inputmethod; - callbacks->callback = callback_funcs[i]; - } - - callbacks = pX11IMData->callbacks; - preedit = (XVaNestedList)XVaCreateNestedList(0, - XNPreeditStartCallback, &callbacks[PreeditStartIndex], - XNPreeditDoneCallback, &callbacks[PreeditDoneIndex], - XNPreeditDrawCallback, &callbacks[PreeditDrawIndex], - XNPreeditCaretCallback, &callbacks[PreeditCaretIndex], - NULL); - if (preedit == (XVaNestedList)NULL) - goto err; -#if defined(__linux__) || defined(MACOSX) - /*always try XIMStatusCallbacks for active client...*/ - { - status = (XVaNestedList)XVaCreateNestedList(0, - XNStatusStartCallback, &callbacks[StatusStartIndex], - XNStatusDoneCallback, &callbacks[StatusDoneIndex], - XNStatusDrawCallback, &callbacks[StatusDrawIndex], - NULL); - - if (status == NULL) - goto err; - pX11IMData->statusWindow = createStatusWindow(w); - pX11IMData->ic_active = XCreateIC(X11im, - XNClientWindow, w, - XNFocusWindow, w, - XNInputStyle, active_styles, - XNPreeditAttributes, preedit, - XNStatusAttributes, status, - NULL); - XFree((void *)status); - XFree((void *)preedit); - } -#else /* !__linux__ && !MACOSX */ - pX11IMData->ic_active = XCreateIC(X11im, - XNClientWindow, w, - XNFocusWindow, w, - XNInputStyle, active_styles, - XNPreeditAttributes, preedit, - NULL); - XFree((void *)preedit); -#endif /* __linux__ || MACOSX */ - } else { - pX11IMData->ic_active = XCreateIC(X11im, - XNClientWindow, w, - XNFocusWindow, w, - XNInputStyle, active_styles, - NULL); - pX11IMData->ic_passive = pX11IMData->ic_active; - } - - if (pX11IMData->ic_active == (XIC)0 - || pX11IMData->ic_passive == (XIC)0) { - return False; - } - - /* - * Use commit string call back if possible. - * This will ensure the correct order of preedit text and commit text - */ - { - XIMCallback cb; - cb.client_data = (XPointer) pX11IMData->x11inputmethod; - cb.callback = (XIMProc) CommitStringCallback; - XSetICValues (pX11IMData->ic_active, XNCommitStringCallback, &cb, NULL); - if (pX11IMData->ic_active != pX11IMData->ic_passive) { - XSetICValues (pX11IMData->ic_passive, XNCommitStringCallback, &cb, NULL); - } - } - - /* Add the global reference object to X11InputMethod to the list. */ - addToX11InputMethodGRefList(pX11IMData->x11inputmethod); - - return True; - - err: - if (preedit) - XFree((void *)preedit); - THROW_OUT_OF_MEMORY_ERROR(); - return False; -} - -static void -PreeditStartCallback(XIC ic, XPointer client_data, XPointer call_data) -{ - /*ARGSUSED*/ - /* printf("Native: PreeditCaretCallback\n"); */ -} - -static void -PreeditDoneCallback(XIC ic, XPointer client_data, XPointer call_data) -{ - /*ARGSUSED*/ - /* printf("Native: StatusStartCallback\n"); */ -} - -/* - * Translate the preedit draw callback items to Java values and invoke - * X11InputMethod.dispatchComposedText(). - * - * client_data: X11InputMethod object - */ -static void -PreeditDrawCallback(XIC ic, XPointer client_data, - XIMPreeditDrawCallbackStruct *pre_draw) -{ - JNIEnv *env = GetJNIEnv(); - X11InputMethodData *pX11IMData = NULL; - jmethodID x11imMethodID; - - XIMText *text; - jstring javastr = NULL; - jintArray style = NULL; - - /* printf("Native: PreeditDrawCallback() \n"); */ - if (pre_draw == NULL) { - return; - } - AWT_LOCK(); - if (!isX11InputMethodGRefInList((jobject)client_data)) { - if ((jobject)client_data == currentX11InputMethodInstance) { - currentX11InputMethodInstance = NULL; - } - goto finally; - } - if ((pX11IMData = getX11InputMethodData(env, (jobject)client_data)) == NULL) { - goto finally; - } - - if ((text = pre_draw->text) != NULL) { - if (text->string.multi_byte != NULL) { - if (pre_draw->text->encoding_is_wchar == False) { - javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte); - if (javastr == NULL) { - goto finally; - } - } else { - char *mbstr = wcstombsdmp(text->string.wide_char, text->length); - if (mbstr == NULL) { - goto finally; - } - javastr = JNU_NewStringPlatform(env, (const char *)mbstr); - free(mbstr); - if (javastr == NULL) { - goto finally; - } - } - } - if (text->feedback != NULL) { - int cnt; - jint *tmpstyle; - - style = (*env)->NewIntArray(env, text->length); - if (JNU_IsNull(env, style)) { - (*env)->ExceptionClear(env); - THROW_OUT_OF_MEMORY_ERROR(); - goto finally; - } - - if (sizeof(XIMFeedback) == sizeof(jint)) { - /* - * Optimization to avoid copying the array - */ - (*env)->SetIntArrayRegion(env, style, 0, - text->length, (jint *)text->feedback); - } else { - tmpstyle = (jint *)malloc(sizeof(jint)*(text->length)); - if (tmpstyle == (jint *) NULL) { - THROW_OUT_OF_MEMORY_ERROR(); - goto finally; - } - for (cnt = 0; cnt < (int)text->length; cnt++) - tmpstyle[cnt] = text->feedback[cnt]; - (*env)->SetIntArrayRegion(env, style, 0, - text->length, (jint *)tmpstyle); - } - } - } - JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod, - "dispatchComposedText", - "(Ljava/lang/String;[IIIIJ)V", - javastr, - style, - (jint)pre_draw->chg_first, - (jint)pre_draw->chg_length, - (jint)pre_draw->caret, - awt_util_nowMillisUTC()); -finally: - AWT_UNLOCK(); - return; -} - -static void -PreeditCaretCallback(XIC ic, XPointer client_data, - XIMPreeditCaretCallbackStruct *pre_caret) -{ - /*ARGSUSED*/ - /* printf("Native: PreeditCaretCallback\n"); */ - -} - -#if defined(__linux__) || defined(MACOSX) -static void -StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data) -{ - /*ARGSUSED*/ - /*printf("StatusStartCallback:\n"); */ - -} - -static void -StatusDoneCallback(XIC ic, XPointer client_data, XPointer call_data) -{ - /*ARGSUSED*/ - /*printf("StatusDoneCallback:\n"); */ - -} - -static void -StatusDrawCallback(XIC ic, XPointer client_data, - XIMStatusDrawCallbackStruct *status_draw) -{ - /*ARGSUSED*/ - /*printf("StatusDrawCallback:\n"); */ - JNIEnv *env = GetJNIEnv(); - X11InputMethodData *pX11IMData = NULL; - StatusWindow *statusWindow; - - AWT_LOCK(); - - if (!isX11InputMethodGRefInList((jobject)client_data)) { - if ((jobject)client_data == currentX11InputMethodInstance) { - currentX11InputMethodInstance = NULL; - } - goto finally; - } - - if (NULL == (pX11IMData = getX11InputMethodData(env, (jobject)client_data)) - || NULL == (statusWindow = pX11IMData->statusWindow)){ - goto finally; - } - currentX11InputMethodInstance = (jobject)client_data; - - if (status_draw->type == XIMTextType){ - XIMText *text = (status_draw->data).text; - if (text != NULL){ - if (text->string.multi_byte != NULL) { - strncpy(statusWindow->status, text->string.multi_byte, MAX_STATUS_LEN); - statusWindow->status[MAX_STATUS_LEN - 1] = '\0'; - } - else { - char *mbstr = wcstombsdmp(text->string.wide_char, text->length); - strncpy(statusWindow->status, mbstr, MAX_STATUS_LEN); - statusWindow->status[MAX_STATUS_LEN - 1] = '\0'; - } - statusWindow->on = True; - onoffStatusWindow(pX11IMData, statusWindow->parent, True); - paintStatusWindow(statusWindow); - } - else { - statusWindow->on = False; - /*just turnoff the status window - paintStatusWindow(statusWindow); - */ - onoffStatusWindow(pX11IMData, 0, False); - } - } - - finally: - AWT_UNLOCK(); -} -#endif /* __linux__ || MACOSX */ - -static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) { - JNIEnv *env = GetJNIEnv(); - XIMText * text = (XIMText *)call_data; - X11InputMethodData *pX11IMData = NULL; - jstring javastr; - - AWT_LOCK(); - - if (!isX11InputMethodGRefInList((jobject)client_data)) { - if ((jobject)client_data == currentX11InputMethodInstance) { - currentX11InputMethodInstance = NULL; - } - goto finally; - } - - if ((pX11IMData = getX11InputMethodData(env, (jobject)client_data)) == NULL) { - goto finally; - } - currentX11InputMethodInstance = (jobject)client_data; - - if (text->encoding_is_wchar == False) { - javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte); - } else { - char *mbstr = wcstombsdmp(text->string.wide_char, text->length); - if (mbstr == NULL) { - goto finally; - } - javastr = JNU_NewStringPlatform(env, (const char *)mbstr); - free(mbstr); - } - - if (javastr != NULL) { - JNU_CallMethodByName(env, NULL, - pX11IMData->x11inputmethod, - "dispatchCommittedText", - "(Ljava/lang/String;J)V", - javastr, - awt_util_nowMillisUTC()); - } - finally: - AWT_UNLOCK(); -} - -static void OpenXIMCallback(Display *display, XPointer client_data, XPointer call_data) { - XIMCallback ximCallback; - - X11im = XOpenIM(display, NULL, NULL, NULL); - if (X11im == NULL) { - return; - } - - ximCallback.callback = (XIMProc)DestroyXIMCallback; - ximCallback.client_data = NULL; - XSetIMValues(X11im, XNDestroyCallback, &ximCallback, NULL); -} - -static void DestroyXIMCallback(XIM im, XPointer client_data, XPointer call_data) { - /* mark that XIM server was destroyed */ - X11im = NULL; - JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - /* free the old pX11IMData and set it to null. this also avoids crashing - * the jvm if the XIM server reappears */ - X11InputMethodData *pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance); -} - -/* - * Class: sun_awt_X11InputMethod - * Method: initIDs - * Signature: ()V - */ - -/* This function gets called from the static initializer for - X11InputMethod.java - to initialize the fieldIDs for fields that may be accessed from C */ -JNIEXPORT void JNICALL -Java_sun_awt_X11InputMethod_initIDs(JNIEnv *env, jclass cls) -{ - x11InputMethodIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J"); -} - - -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11_XInputMethod_openXIMNative(JNIEnv *env, - jobject this, - jlong display) -{ - Bool registered; - - AWT_LOCK(); - - dpy = (Display *)jlong_to_ptr(display); - -/* Use IMInstantiate call back only on Linux, as there is a bug in Solaris - (4768335) -*/ -#if defined(__linux__) || defined(MACOSX) - registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL, - NULL, (XIDProc)OpenXIMCallback, NULL); - if (!registered) { - /* directly call openXIM callback */ -#endif - OpenXIMCallback(dpy, NULL, NULL); -#if defined(__linux__) || defined(MACOSX) - } -#endif - - AWT_UNLOCK(); - - return JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11_XInputMethod_createXICNative(JNIEnv *env, - jobject this, - jlong window) -{ - X11InputMethodData *pX11IMData; - jobject globalRef; - XIC ic; - - AWT_LOCK(); - - if (!window) { - JNU_ThrowNullPointerException(env, "NullPointerException"); - AWT_UNLOCK(); - return JNI_FALSE; - } - - pX11IMData = (X11InputMethodData *) calloc(1, sizeof(X11InputMethodData)); - if (pX11IMData == NULL) { - THROW_OUT_OF_MEMORY_ERROR(); - AWT_UNLOCK(); - return JNI_FALSE; - } - - globalRef = (*env)->NewGlobalRef(env, this); - pX11IMData->x11inputmethod = globalRef; -#if defined(__linux__) || defined(MACOSX) - pX11IMData->statusWindow = NULL; -#endif /* __linux__ || MACOSX */ - - pX11IMData->lookup_buf = 0; - pX11IMData->lookup_buf_len = 0; - - if (createXIC(env, pX11IMData, (Window)window) == False) { - destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData); - pX11IMData = (X11InputMethodData *) NULL; - if ((*env)->ExceptionCheck(env)) { - goto finally; - } - } - - setX11InputMethodData(env, this, pX11IMData); - -finally: - AWT_UNLOCK(); - return (pX11IMData != NULL); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env, - jobject this, - jlong w, - jboolean req, - jboolean active) -{ - X11InputMethodData *pX11IMData; - AWT_LOCK(); - pX11IMData = getX11InputMethodData(env, this); - if (pX11IMData == NULL) { - AWT_UNLOCK(); - return; - } - - if (req) { - if (!w) { - AWT_UNLOCK(); - return; - } - pX11IMData->current_ic = active ? - pX11IMData->ic_active : pX11IMData->ic_passive; - /* - * On Solaris2.6, setXICWindowFocus() has to be invoked - * before setting focus. - */ - setXICWindowFocus(pX11IMData->current_ic, w); - setXICFocus(pX11IMData->current_ic, req); - currentX11InputMethodInstance = pX11IMData->x11inputmethod; - currentFocusWindow = w; -#if defined(__linux__) || defined(MACOSX) - if (active && pX11IMData->statusWindow && pX11IMData->statusWindow->on) - onoffStatusWindow(pX11IMData, w, True); -#endif - } else { - currentX11InputMethodInstance = NULL; - currentFocusWindow = 0; -#if defined(__linux__) || defined(MACOSX) - onoffStatusWindow(pX11IMData, 0, False); - if (pX11IMData->current_ic != NULL) -#endif - setXICFocus(pX11IMData->current_ic, req); - - pX11IMData->current_ic = (XIC)0; - } - - XFlush(dpy); - AWT_UNLOCK(); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11InputMethod_turnoffStatusWindow(JNIEnv *env, - jobject this) -{ -#if defined(__linux__) || defined(MACOSX) - X11InputMethodData *pX11IMData; - StatusWindow *statusWindow; - - AWT_LOCK(); - - if (NULL == currentX11InputMethodInstance - || !isX11InputMethodGRefInList(currentX11InputMethodInstance) - || NULL == (pX11IMData = getX11InputMethodData(env,currentX11InputMethodInstance)) - || NULL == (statusWindow = pX11IMData->statusWindow) - || !statusWindow->on ){ - AWT_UNLOCK(); - return; - } - onoffStatusWindow(pX11IMData, 0, False); - - AWT_UNLOCK(); -#endif -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11InputMethod_disposeXIC(JNIEnv *env, - jobject this) -{ - X11InputMethodData *pX11IMData = NULL; - - AWT_LOCK(); - pX11IMData = getX11InputMethodData(env, this); - if (pX11IMData == NULL) { - AWT_UNLOCK(); - return; - } - - setX11InputMethodData(env, this, NULL); - - if (pX11IMData->x11inputmethod == currentX11InputMethodInstance) { - currentX11InputMethodInstance = NULL; - currentFocusWindow = 0; - } - destroyX11InputMethodData(env, pX11IMData); - AWT_UNLOCK(); -} - -JNIEXPORT jstring JNICALL -Java_sun_awt_X11InputMethod_resetXIC(JNIEnv *env, - jobject this) -{ - X11InputMethodData *pX11IMData; - char *xText = NULL; - jstring jText = (jstring)0; - - AWT_LOCK(); - pX11IMData = getX11InputMethodData(env, this); - if (pX11IMData == NULL) { - AWT_UNLOCK(); - return jText; - } - - if (pX11IMData->current_ic) - xText = XmbResetIC(pX11IMData->current_ic); - else { - /* - * If there is no reference to the current XIC, try to reset both XICs. - */ - xText = XmbResetIC(pX11IMData->ic_active); - /*it may also means that the real client component does - not have focus -- has been deactivated... its xic should - not have the focus, bug#4284651 showes reset XIC for htt - may bring the focus back, so de-focus it again. - */ - setXICFocus(pX11IMData->ic_active, FALSE); - if (pX11IMData->ic_active != pX11IMData->ic_passive) { - char *tmpText = XmbResetIC(pX11IMData->ic_passive); - setXICFocus(pX11IMData->ic_passive, FALSE); - if (xText == (char *)NULL && tmpText) - xText = tmpText; - } - - } - if (xText != NULL) { - jText = JNU_NewStringPlatform(env, (const char *)xText); - XFree((void *)xText); - } - - AWT_UNLOCK(); - return jText; -} - -/* - * Class: sun_awt_X11InputMethod - * Method: setCompositionEnabledNative - * Signature: (ZJ)V - * - * This method tries to set the XNPreeditState attribute associated with the current - * XIC to the passed in 'enable' state. - * - * Return JNI_TRUE if XNPreeditState attribute is successfully changed to the - * 'enable' state; Otherwise, if XSetICValues fails to set this attribute, - * java.lang.UnsupportedOperationException will be thrown. JNI_FALSE is returned if this - * method fails due to other reasons. - * - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethod_setCompositionEnabledNative - (JNIEnv *env, jobject this, jboolean enable) -{ - X11InputMethodData *pX11IMData; - char * ret = NULL; - - AWT_LOCK(); - pX11IMData = getX11InputMethodData(env, this); - - if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { - AWT_UNLOCK(); - return JNI_FALSE; - } - - ret = XSetICValues(pX11IMData->current_ic, XNPreeditState, - (enable ? XIMPreeditEnable : XIMPreeditDisable), NULL); - AWT_UNLOCK(); - - if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) { - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); - } - - return (jboolean)(ret == 0); -} - -/* - * Class: sun_awt_X11InputMethod - * Method: isCompositionEnabledNative - * Signature: (J)Z - * - * This method tries to get the XNPreeditState attribute associated with the current XIC. - * - * Return JNI_TRUE if the XNPreeditState is successfully retrieved. Otherwise, if - * XGetICValues fails to get this attribute, java.lang.UnsupportedOperationException - * will be thrown. JNI_FALSE is returned if this method fails due to other reasons. - * - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethod_isCompositionEnabledNative - (JNIEnv *env, jobject this) -{ - X11InputMethodData *pX11IMData = NULL; - char * ret = NULL; - XIMPreeditState state; - - AWT_LOCK(); - pX11IMData = getX11InputMethodData(env, this); - - if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { - AWT_UNLOCK(); - return JNI_FALSE; - } - - ret = XGetICValues(pX11IMData->current_ic, XNPreeditState, &state, NULL); - AWT_UNLOCK(); - - if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) { - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); - return JNI_FALSE; - } - - return (jboolean)(state == XIMPreeditEnable); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow - (JNIEnv *env, jobject this, jlong window) -{ -#if defined(__linux__) || defined(MACOSX) - AWT_LOCK(); - adjustStatusWindow(window); - AWT_UNLOCK(); -#endif -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_Insets.c b/app/src/main/jni/awt_xawt/awt/awt_Insets.c deleted file mode 100644 index 0ae5b0142..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_Insets.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1998, 2014, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "java_awt_Insets.h" -#include "jni_util.h" - -#include "awt_Insets.h" - -struct InsetsIDs insetsIDs; - - -JNIEXPORT void JNICALL -Java_java_awt_Insets_initIDs(JNIEnv *env, jclass cls) -{ - CHECK_NULL(insetsIDs.top = (*env)->GetFieldID(env, cls, "top", "I")); - CHECK_NULL(insetsIDs.bottom = (*env)->GetFieldID(env, cls, "bottom", "I")); - CHECK_NULL(insetsIDs.left = (*env)->GetFieldID(env, cls, "left", "I")); - CHECK_NULL(insetsIDs.right = (*env)->GetFieldID(env, cls, "right", "I")); -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_Insets.h b/app/src/main/jni/awt_xawt/awt/awt_Insets.h deleted file mode 100644 index ab61a7c4d..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_Insets.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1998, 2001, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_util.h" - -struct InsetsIDs { - jfieldID top; - jfieldID bottom; - jfieldID left; - jfieldID right; -}; diff --git a/app/src/main/jni/awt_xawt/awt/awt_MenuComponent.h b/app/src/main/jni/awt_xawt/awt/awt_MenuComponent.h deleted file mode 100644 index f254e0cc1..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_MenuComponent.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1998, 2006, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_util.h" - -struct MenuComponentIDs { - jfieldID font; - jfieldID appContext; - jmethodID getParent; -}; diff --git a/app/src/main/jni/awt_xawt/awt/awt_Robot.c b/app/src/main/jni/awt_xawt/awt/awt_Robot.c deleted file mode 100644 index 3b08c197e..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_Robot.c +++ /dev/null @@ -1,524 +0,0 @@ -/* - * Copyright (c) 1999, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include "jvm_md.h" -#include - -#include "awt_p.h" -#include "awt_GraphicsEnv.h" -#define XK_MISCELLANY -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "robot_common.h" -#include "canvas.h" -#include "wsutils.h" -#include "list.h" -#include "multiVis.h" -#include "gtk_interface.h" - -#if defined(__linux__) || defined(MACOSX) -#include -#endif - -static Bool (*compositeQueryExtension) (Display*, int*, int*); -static Status (*compositeQueryVersion) (Display*, int*, int*); -static Window (*compositeGetOverlayWindow) (Display *, Window); - -extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; - -static jint * masks; -static jint num_buttons; - -static void *xCompositeHandle; - -static const char* XCOMPOSITE = JNI_LIB_NAME("Xcomposite"); -static const char* XCOMPOSITE_VERSIONED = VERSIONED_JNI_LIB_NAME("Xcomposite", "1"); - -static Bool checkXCompositeFunctions(void) { - return (compositeQueryExtension != NULL && - compositeQueryVersion != NULL && - compositeGetOverlayWindow != NULL); -} - -static void initXCompositeFunctions(void) { - - if (xCompositeHandle == NULL) { - xCompositeHandle = dlopen(XCOMPOSITE, RTLD_LAZY | RTLD_GLOBAL); - if (xCompositeHandle == NULL) { - xCompositeHandle = dlopen(XCOMPOSITE_VERSIONED, RTLD_LAZY | RTLD_GLOBAL); - } - } - //*(void **)(&asyncGetCallTraceFunction) - if (xCompositeHandle != NULL) { - *(void **)(&compositeQueryExtension) = dlsym(xCompositeHandle, "XCompositeQueryExtension"); - *(void **)(&compositeQueryVersion) = dlsym(xCompositeHandle, "XCompositeQueryVersion"); - *(void **)(&compositeGetOverlayWindow) = dlsym(xCompositeHandle, "XCompositeGetOverlayWindow"); - } - - if (xCompositeHandle && !checkXCompositeFunctions()) { - dlclose(xCompositeHandle); - } -} - -static int32_t isXTestAvailable() { - int32_t major_opcode, first_event, first_error; - int32_t event_basep, error_basep, majorp, minorp; - int32_t isXTestAvailable; - - /* check if XTest is available */ - isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error); - if (isXTestAvailable) { - DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d", - major_opcode, first_event, first_error); - /* check if XTest version is OK */ - XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp); - DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d", - event_basep, error_basep, majorp, minorp); - if (majorp < 2 || (majorp == 2 && minorp < 2)) { - /* bad version*/ - DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp); - if (majorp == 2 && minorp == 1) { - DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n"); - } else { - isXTestAvailable = False; - } - } else { - /* allow XTest calls even if someone else has the grab; e.g. during - * a window resize operation. Works only with XTEST2.2*/ - XTestGrabControl(awt_display, True); - } - } else { - DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable"); - } - - return isXTestAvailable; -} - -static Bool hasXCompositeOverlayExtension(Display *display) { - - int xoverlay = False; - int eventBase, errorBase; - if (checkXCompositeFunctions() && - compositeQueryExtension(display, &eventBase, &errorBase)) - { - int major = 0; - int minor = 0; - - compositeQueryVersion(display, &major, &minor); - if (major > 0 || minor >= 3) { - xoverlay = True; - } - } - - return xoverlay; -} - -static jboolean isXCompositeDisplay(Display *display, int screenNumber) { - - char NET_WM_CM_Sn[25]; - snprintf(NET_WM_CM_Sn, sizeof(NET_WM_CM_Sn), "_NET_WM_CM_S%d\0", screenNumber); - - Atom managerSelection = XInternAtom(display, NET_WM_CM_Sn, 0); - Window owner = XGetSelectionOwner(display, managerSelection); - - return owner != 0; -} - -static XImage *getWindowImage(Display * display, Window window, - int32_t x, int32_t y, - int32_t w, int32_t h) { - XImage *image; - int32_t transparentOverlays; - int32_t numVisuals; - XVisualInfo *pVisuals; - int32_t numOverlayVisuals; - OverlayInfo *pOverlayVisuals; - int32_t numImageVisuals; - XVisualInfo **pImageVisuals; - list_ptr vis_regions; /* list of regions to read from */ - list_ptr vis_image_regions ; - int32_t allImage = 0 ; - int32_t format = ZPixmap; - - /* prevent user from moving stuff around during the capture */ - XGrabServer(display); - - /* - * The following two functions live in multiVis.c-- they are pretty - * much verbatim taken from the source to the xwd utility from the - * X11 source. This version of the xwd source was somewhat better written - * for reuse compared to Sun's version. - * - * ftp.x.org/pub/R6.3/xc/programs/xwd - * - * We use these functions since they do the very tough job of capturing - * the screen correctly when it contains multiple visuals. They take into - * account the depth/colormap of each visual and produce a capture as a - * 24-bit RGB image so we don't have to fool around with colormaps etc. - */ - - GetMultiVisualRegions( - display, - window, - x, y, w, h, - &transparentOverlays, - &numVisuals, - &pVisuals, - &numOverlayVisuals, - &pOverlayVisuals, - &numImageVisuals, - &pImageVisuals, - &vis_regions, - &vis_image_regions, - &allImage ); - - image = ReadAreaToImage( - display, - window, - x, y, w, h, - numVisuals, - pVisuals, - numOverlayVisuals, - pOverlayVisuals, - numImageVisuals, - pImageVisuals, - vis_regions, - vis_image_regions, - format, - allImage ); - - /* allow user to do stuff again */ - XUngrabServer(display); - - /* make sure the grab/ungrab is flushed */ - XSync(display, False); - - return image; -} - -/*********************************************************************************************/ - -// this should be called from XRobotPeer constructor -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls, jint numberOfButtons, jintArray buttonDownMasks) -{ - int32_t xtestAvailable; - jint *tmp; - int i; - - DTRACE_PRINTLN("RobotPeer: setup()"); - - num_buttons = numberOfButtons; - tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE); - CHECK_NULL(tmp); - - masks = (jint *)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), num_buttons); - if (masks == (jint *) NULL) { - (*env)->ExceptionClear(env); - (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0); - JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL); - return; - } - for (i = 0; i < num_buttons; i++) { - masks[i] = tmp[i]; - } - (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0); - - AWT_LOCK(); - xtestAvailable = isXTestAvailable(); - DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable); - if (!xtestAvailable) { - JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2"); - } - - AWT_UNLOCK(); -} - - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env, - jclass cls, - jobject xgc, - jint jx, - jint jy, - jint jwidth, - jint jheight, - jintArray pixelArray, - jboolean useGtk) { - XImage *image; - jint *ary; /* Array of jints for sending pixel values back - * to parent process. - */ - Window rootWindow; - XWindowAttributes attr; - AwtGraphicsConfigDataPtr adata; - - DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray); - - if (jwidth <= 0 || jheight <= 0) { - return; - } - - adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); - DASSERT(adata != NULL); - - AWT_LOCK(); - - rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen); - - if (!useGtk) { - if (hasXCompositeOverlayExtension(awt_display) && - isXCompositeDisplay(awt_display, adata->awt_visInfo.screen)) - { - rootWindow = compositeGetOverlayWindow(awt_display, rootWindow); - } - } - - if (!XGetWindowAttributes(awt_display, rootWindow, &attr) - || jx + jwidth <= attr.x - || attr.x + attr.width <= jx - || jy + jheight <= attr.y - || attr.y + attr.height <= jy) { - - AWT_UNLOCK(); - return; // Does not intersect with root window - } - - gboolean gtk_failed = TRUE; - jint _x, _y; - - jint x = MAX(jx, attr.x); - jint y = MAX(jy, attr.y); - jint width = MIN(jx + jwidth, attr.x + attr.width) - x; - jint height = MIN(jy + jheight, attr.y + attr.height) - y; - - int dx = attr.x > jx ? attr.x - jx : 0; - int dy = attr.y > jy ? attr.y - jy : 0; - - int index; - - if (useGtk) { - gtk->gdk_threads_enter(); - gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width, - height, jwidth, dx, dy, 1); - gtk->gdk_threads_leave(); - } - - if (gtk_failed) { - image = getWindowImage(awt_display, rootWindow, x, y, width, height); - - ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - - if (!ary) { - XDestroyImage(image); - AWT_UNLOCK(); - return; - } - - /* convert to Java ARGB pixels */ - for (_y = 0; _y < height; _y++) { - for (_x = 0; _x < width; _x++) { - jint pixel = (jint) XGetPixel(image, _x, _y); - /* Note ignore upper - * 32-bits on 64-bit - * OSes. - */ - pixel |= 0xff000000; /* alpha - full opacity */ - - index = (_y + dy) * jwidth + (_x + dx); - ary[index] = pixel; - } - } - - XDestroyImage(image); - (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); - } - AWT_UNLOCK(); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env, - jclass cls, - jint keycode) { - - AWT_LOCK(); - - DTRACE_PRINTLN1("RobotPeer: keyPressImpl(%i)", keycode); - - XTestFakeKeyEvent(awt_display, - XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), - True, - CurrentTime); - - XSync(awt_display, False); - - AWT_UNLOCK(); - -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env, - jclass cls, - jint keycode) { - AWT_LOCK(); - - DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode); - - XTestFakeKeyEvent(awt_display, - XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)), - False, - CurrentTime); - - XSync(awt_display, False); - - AWT_UNLOCK(); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env, - jclass cls, - jobject xgc, - jint root_x, - jint root_y) { - - AwtGraphicsConfigDataPtr adata; - - AWT_LOCK(); - - DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y); - - adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData); - DASSERT(adata != NULL); - - XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y); - XSync(awt_display, False); - - AWT_UNLOCK(); -} - -/* - * Function joining the code of mousePressImpl and mouseReleaseImpl - */ -void mouseAction(JNIEnv *env, - jclass cls, - jint buttonMask, - Bool isMousePress) -{ - AWT_LOCK(); - - DTRACE_PRINTLN1("RobotPeer: mouseAction(%i)", buttonMask); - DTRACE_PRINTLN1("RobotPeer: mouseAction, press = %d", isMousePress); - - if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK || - buttonMask & java_awt_event_InputEvent_BUTTON1_DOWN_MASK ) - { - XTestFakeButtonEvent(awt_display, 1, isMousePress, CurrentTime); - } - if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK || - buttonMask & java_awt_event_InputEvent_BUTTON2_DOWN_MASK) && - (num_buttons >= 2)) { - XTestFakeButtonEvent(awt_display, 2, isMousePress, CurrentTime); - } - if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK || - buttonMask & java_awt_event_InputEvent_BUTTON3_DOWN_MASK) && - (num_buttons >= 3)) { - XTestFakeButtonEvent(awt_display, 3, isMousePress, CurrentTime); - } - - if (num_buttons > 3){ - int32_t i; - int32_t button = 0; - for (i = 3; i +1 - // users wants to affect 4 or 5 button but they are assigned - // to the wheel so => we have to shift it to the right by 2. - button = i + 3; - XTestFakeButtonEvent(awt_display, button, isMousePress, CurrentTime); - } - } - } - - XSync(awt_display, False); - AWT_UNLOCK(); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_mousePressImpl (JNIEnv *env, - jclass cls, - jint buttonMask) { - mouseAction(env, cls, buttonMask, True); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl (JNIEnv *env, - jclass cls, - jint buttonMask) { - mouseAction(env, cls, buttonMask, False); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env, - jclass cls, - jint wheelAmt) { -/* Mouse wheel is implemented as a button press of button 4 and 5, so it */ -/* probably could have been hacked into robot_mouseButtonEvent, but it's */ -/* cleaner to give it its own command type, in case the implementation */ -/* needs to be changed later. -bchristi, 6/20/01 */ - - int32_t repeat = abs(wheelAmt); - int32_t button = wheelAmt < 0 ? 4 : 5; /* wheel up: button 4 */ - /* wheel down: button 5 */ - int32_t loopIdx; - - AWT_LOCK(); - - DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt); - - for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for */ - /* wheelAmt == 0 */ - XTestFakeButtonEvent(awt_display, button, True, CurrentTime); - XTestFakeButtonEvent(awt_display, button, False, CurrentTime); - } - XSync(awt_display, False); - - AWT_UNLOCK(); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XRobotPeer_loadNativeLibraries (JNIEnv *env, jclass cls) { - initXCompositeFunctions(); -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_UNIXToolkit.c b/app/src/main/jni/awt_xawt/awt/awt_UNIXToolkit.c deleted file mode 100644 index 7fae8f4a1..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_UNIXToolkit.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2004, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include - -#include -#include -#include "sun_awt_UNIXToolkit.h" - -#ifndef HEADLESS -#include "awt.h" -#include "gtk_interface.h" -#endif /* !HEADLESS */ - - -static jclass this_class = NULL; -static jmethodID icon_upcall_method = NULL; - - -/* - * Class: sun_awt_UNIXToolkit - * Method: check_gtk - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass, jint version) { -#ifndef HEADLESS - return (jboolean)gtk_check_version(version); -#else - return JNI_FALSE; -#endif /* !HEADLESS */ -} - - -/* - * Class: sun_awt_UNIXToolkit - * Method: load_gtk - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass, jint version, - jboolean verbose) { -#ifndef HEADLESS - return (jboolean)gtk_load(env, version, verbose); -#else - return JNI_FALSE; -#endif /* !HEADLESS */ -} - - -/* - * Class: sun_awt_UNIXToolkit - * Method: unload_gtk - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass) -{ -#ifndef HEADLESS - return (jboolean)gtk->unload(); -#else - return JNI_FALSE; -#endif /* !HEADLESS */ -} - -jboolean init_method(JNIEnv *env, jobject this) -{ - if (this_class == NULL) { - this_class = (*env)->NewGlobalRef(env, - (*env)->GetObjectClass(env, this)); - icon_upcall_method = (*env)->GetMethodID(env, this_class, - "loadIconCallback", "([BIIIIIZ)V"); - CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE); - } - return JNI_TRUE; -} - -/* - * Class: sun_awt_UNIXToolkit - * Method: load_gtk_icon - * Signature: (Ljava/lang/String)Z - * - * This method assumes that GTK libs are present. - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this, - jstring filename) -{ -#ifndef HEADLESS - int len; - char *filename_str = NULL; - GError **error = NULL; - - if (filename == NULL) - { - return JNI_FALSE; - } - - len = (*env)->GetStringUTFLength(env, filename); - filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, - sizeof(char), len + 1); - if (filename_str == NULL) { - 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); - 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 result; -#else /* HEADLESS */ - return JNI_FALSE; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_UNIXToolkit - * Method: load_stock_icon - * Signature: (ILjava/lang/String;IILjava/lang/String;)Z - * - * This method assumes that GTK libs are present. - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this, - jint widget_type, jstring stock_id, jint icon_size, - jint text_direction, jstring detail) -{ -#ifndef HEADLESS - int len; - char *stock_id_str = NULL; - char *detail_str = NULL; - - if (stock_id == NULL) - { - return JNI_FALSE; - } - - len = (*env)->GetStringUTFLength(env, stock_id); - stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, - sizeof(char), len + 1); - if (stock_id_str == NULL) { - JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); - return JNI_FALSE; - } - (*env)->GetStringUTFRegion(env, stock_id, 0, len, stock_id_str); - - /* Detail isn't required so check for NULL. */ - if (detail != NULL) - { - len = (*env)->GetStringUTFLength(env, detail); - detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, - sizeof(char), len + 1); - if (detail_str == NULL) { - JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); - return JNI_FALSE; - } - (*env)->GetStringUTFRegion(env, detail, 0, len, 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); - if (detail_str != NULL) - { - free(detail_str); - } - return result; -#else /* HEADLESS */ - return JNI_FALSE; -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_UNIXToolkit - * Method: nativeSync - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_sun_awt_UNIXToolkit_nativeSync(JNIEnv *env, jobject this) -{ -#ifndef HEADLESS - AWT_LOCK(); - XSync(awt_display, False); - AWT_UNLOCK(); -#endif /* !HEADLESS */ -} - -/* - * Class: sun_awt_SunToolkit - * Method: closeSplashScreen - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls) -{ - typedef void (*SplashClose_t)(); - SplashClose_t splashClose; - void* hSplashLib = dlopen(0, RTLD_LAZY); - if (!hSplashLib) { - return; - } - splashClose = (SplashClose_t)dlsym(hSplashLib, - "SplashClose"); - if (splashClose) { - splashClose(); - } - dlclose(hSplashLib); -} - -/* - * Class: sun_awt_UNIXToolkit - * Method: gtkCheckVersionImpl - * Signature: (III)Ljava/lang/String; - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this, - jint major, jint minor, jint micro) -{ - char *ret; - - ret = gtk->gtk_check_version(major, minor, micro); - if (ret == NULL) { - return TRUE; - } - - 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 */ -} diff --git a/app/src/main/jni/awt_xawt/awt/awt_util.c b/app/src/main/jni/awt_xawt/awt/awt_util.c deleted file mode 100644 index d61c59b59..000000000 --- a/app/src/main/jni/awt_xawt/awt/awt_util.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 1995, 2014, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include "awt_p.h" -#include "color.h" -#include -#include -#include -#include -#include -#include -#include - - -#include "java_awt_event_MouseWheelEvent.h" - -/* - * Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file. - */ -XErrorHandler current_native_xerror_handler = NULL; - -extern jint getModifiers(uint32_t state, jint button, jint keyCode); -extern jint getButton(uint32_t button); - -static Atom OLDecorDelAtom = 0; -static Atom MWMHints = 0; -static Atom DTWMHints = 0; -static Atom decor_list[9]; - -#ifndef MAX -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - -jboolean -awtJNI_ThreadYield(JNIEnv *env) { - - static jclass threadClass = NULL; - static jmethodID yieldMethodID = NULL; - - /* Initialize our java identifiers once. Checking before locking - * is a huge performance win. - */ - if (threadClass == NULL) { - // should enter a monitor here... - Boolean err = FALSE; - if (threadClass == NULL) { - jclass tc = (*env)->FindClass(env, "java/lang/Thread"); - CHECK_NULL_RETURN(tc, JNI_FALSE); - threadClass = (*env)->NewGlobalRef(env, tc); - (*env)->DeleteLocalRef(env, tc); - if (threadClass != NULL) { - yieldMethodID = (*env)->GetStaticMethodID(env, - threadClass, - "yield", - "()V" - ); - } - } - if (yieldMethodID == NULL) { - threadClass = NULL; - err = TRUE; - } - if (err) { - return JNI_FALSE; - } - } /* threadClass == NULL*/ - - (*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID); - DASSERT(!((*env)->ExceptionOccurred(env))); - if ((*env)->ExceptionCheck(env)) { - return JNI_FALSE; - } - return JNI_TRUE; -} /* awtJNI_ThreadYield() */ diff --git a/app/src/main/jni/awt_xawt/awt/canvas.h b/app/src/main/jni/awt_xawt/awt/canvas.h deleted file mode 100644 index f35decb65..000000000 --- a/app/src/main/jni/awt_xawt/awt/canvas.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1995, 2011, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#ifndef _CANVAS_H_ -#define _CANVAS_H_ -#ifndef HEADLESS - -KeySym awt_getX11KeySym(jint awtKey); - -#endif /* !HEADLESS */ -#endif /* _CANVAS_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/gtk2_interface.c b/app/src/main/jni/awt_xawt/awt/gtk2_interface.c deleted file mode 100644 index 800af14d6..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk2_interface.c +++ /dev/null @@ -1,2628 +0,0 @@ -/* - * Copyright (c) 2005, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include -#include "gtk2_interface.h" -#include "java_awt_Transparency.h" -#include "jvm_md.h" -#include "sizecalc.h" -#include -#include "awt.h" - -#define GTK_TYPE_BORDER ((*fp_gtk_border_get_type)()) - -#define G_TYPE_FUNDAMENTAL_SHIFT (2) -#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT)) - -#define CONV_BUFFER_SIZE 128 - -#define NO_SYMBOL_EXCEPTION 1 - -static void *gtk2_libhandle = NULL; -static void *gthread_libhandle = NULL; - -static jmp_buf j; - -/* Widgets */ -static GtkWidget *gtk2_widget = NULL; -static GtkWidget *gtk2_window = NULL; -static GtkFixed *gtk2_fixed = NULL; - -/* Paint system */ -static GdkPixmap *gtk2_white_pixmap = NULL; -static GdkPixmap *gtk2_black_pixmap = NULL; -static GdkPixbuf *gtk2_white_pixbuf = NULL; -static GdkPixbuf *gtk2_black_pixbuf = NULL; -static int gtk2_pixbuf_width = 0; -static int gtk2_pixbuf_height = 0; - -/* Static buffer for conversion from java.lang.String to UTF-8 */ -static char convertionBuffer[CONV_BUFFER_SIZE]; - -static gboolean new_combo = TRUE; -const char ENV_PREFIX[] = "GTK_MODULES="; - - -static GtkWidget *gtk2_widgets[_GTK_WIDGET_TYPE_SIZE]; - -/************************* - * Glib function pointers - *************************/ - -static gboolean (*fp_g_main_context_iteration)(GMainContext *context, - gboolean may_block); - -static GValue* (*fp_g_value_init)(GValue *value, GType g_type); -static gboolean (*fp_g_type_is_a)(GType type, GType is_a_type); -static gboolean (*fp_g_value_get_boolean)(const GValue *value); -static gchar (*fp_g_value_get_char)(const GValue *value); -static guchar (*fp_g_value_get_uchar)(const GValue *value); -static gint (*fp_g_value_get_int)(const GValue *value); -static guint (*fp_g_value_get_uint)(const GValue *value); -static glong (*fp_g_value_get_long)(const GValue *value); -static gulong (*fp_g_value_get_ulong)(const GValue *value); -static gint64 (*fp_g_value_get_int64)(const GValue *value); -static guint64 (*fp_g_value_get_uint64)(const GValue *value); -static gfloat (*fp_g_value_get_float)(const GValue *value); -static gdouble (*fp_g_value_get_double)(const GValue *value); -static const gchar* (*fp_g_value_get_string)(const GValue *value); -static gint (*fp_g_value_get_enum)(const GValue *value); -static guint (*fp_g_value_get_flags)(const GValue *value); -static GParamSpec* (*fp_g_value_get_param)(const GValue *value); -static gpointer* (*fp_g_value_get_boxed)(const GValue *value); -static gpointer* (*fp_g_value_get_pointer)(const GValue *value); -static GObject* (*fp_g_value_get_object)(const GValue *value); -static GParamSpec* (*fp_g_param_spec_int)(const gchar *name, - const gchar *nick, const gchar *blurb, - gint minimum, gint maximum, gint default_value, - GParamFlags flags); -static void (*fp_g_object_get)(gpointer object, - const gchar* fpn, ...); -static void (*fp_g_object_set)(gpointer object, - const gchar *first_property_name, - ...); -/************************ - * GDK function pointers - ************************/ -static GdkPixmap *(*fp_gdk_pixmap_new)(GdkDrawable *drawable, - gint width, gint height, gint depth); -static GdkGC *(*fp_gdk_gc_new)(GdkDrawable*); -static void (*fp_gdk_rgb_gc_set_foreground)(GdkGC*, guint32); -static void (*fp_gdk_draw_rectangle)(GdkDrawable*, GdkGC*, gboolean, - gint, gint, gint, gint); -static GdkPixbuf *(*fp_gdk_pixbuf_new)(GdkColorspace colorspace, - gboolean has_alpha, int bits_per_sample, int width, int height); -static void (*fp_gdk_drawable_get_size)(GdkDrawable *drawable, - gint* width, gint* height); - -/************************ - * Gtk function pointers - ************************/ -static gboolean (*fp_gtk_init_check)(int* argc, char** argv); - -/* Painting */ -static void (*fp_gtk_paint_hline)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GdkRectangle* area, GtkWidget* widget, - const gchar* detail, gint x1, gint x2, gint y); -static void (*fp_gtk_paint_vline)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GdkRectangle* area, GtkWidget* widget, - const gchar* detail, gint y1, gint y2, gint x); -static void (*fp_gtk_paint_shadow)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_arrow)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - GtkArrowType arrow_type, gboolean fill, gint x, gint y, - gint width, gint height); -static void (*fp_gtk_paint_diamond)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_box)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_flat_box)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_check)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_option)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_box_gap)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height, - GtkPositionType gap_side, gint gap_x, gint gap_width); -static void (*fp_gtk_paint_extension)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height, GtkPositionType gap_side); -static void (*fp_gtk_paint_focus)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GdkRectangle* area, GtkWidget* widget, - const gchar* detail, gint x, gint y, gint width, gint height); -static void (*fp_gtk_paint_slider)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation); -static void (*fp_gtk_paint_handle)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GtkShadowType shadow_type, - GdkRectangle* area, GtkWidget* widget, const gchar* detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation); -static void (*fp_gtk_paint_expander)(GtkStyle* style, GdkWindow* window, - GtkStateType state_type, GdkRectangle* area, GtkWidget* widget, - const gchar* detail, gint x, gint y, GtkExpanderStyle expander_style); -static void (*fp_gtk_style_apply_default_background)(GtkStyle* style, - GdkWindow* window, gboolean set_bg, GtkStateType state_type, - GdkRectangle* area, gint x, gint y, gint width, gint height); - -/* Widget creation */ -static GtkWidget* (*fp_gtk_arrow_new)(GtkArrowType arrow_type, - GtkShadowType shadow_type); -static GtkWidget* (*fp_gtk_button_new)(); -static GtkWidget* (*fp_gtk_check_button_new)(); -static GtkWidget* (*fp_gtk_check_menu_item_new)(); -static GtkWidget* (*fp_gtk_color_selection_dialog_new)(const gchar* title); -static GtkWidget* (*fp_gtk_combo_box_new)(); -static GtkWidget* (*fp_gtk_combo_box_entry_new)(); -static GtkWidget* (*fp_gtk_entry_new)(); -static GtkWidget* (*fp_gtk_fixed_new)(); -static GtkWidget* (*fp_gtk_handle_box_new)(); -static GtkWidget* (*fp_gtk_hpaned_new)(); -static GtkWidget* (*fp_gtk_vpaned_new)(); -static GtkWidget* (*fp_gtk_hscale_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_vscale_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_hscrollbar_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_vscrollbar_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_hseparator_new)(); -static GtkWidget* (*fp_gtk_vseparator_new)(); -static GtkWidget* (*fp_gtk_image_new)(); -static GtkWidget* (*fp_gtk_label_new)(const gchar* str); -static GtkWidget* (*fp_gtk_menu_new)(); -static GtkWidget* (*fp_gtk_menu_bar_new)(); -static GtkWidget* (*fp_gtk_menu_item_new)(); -static GtkWidget* (*fp_gtk_notebook_new)(); -static GtkWidget* (*fp_gtk_progress_bar_new)(); -static GtkWidget* (*fp_gtk_progress_bar_set_orientation)( - GtkProgressBar *pbar, - GtkProgressBarOrientation orientation); -static GtkWidget* (*fp_gtk_radio_button_new)(GSList *group); -static GtkWidget* (*fp_gtk_radio_menu_item_new)(GSList *group); -static GtkWidget* (*fp_gtk_scrolled_window_new)(GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -static GtkWidget* (*fp_gtk_separator_menu_item_new)(); -static GtkWidget* (*fp_gtk_separator_tool_item_new)(); -static GtkWidget* (*fp_gtk_text_view_new)(); -static GtkWidget* (*fp_gtk_toggle_button_new)(); -static GtkWidget* (*fp_gtk_toolbar_new)(); -static GtkWidget* (*fp_gtk_tree_view_new)(); -static GtkWidget* (*fp_gtk_viewport_new)(GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -static GtkWidget* (*fp_gtk_window_new)(GtkWindowType type); -static GtkWidget* (*fp_gtk_dialog_new)(); -static GtkWidget* (*fp_gtk_spin_button_new)(GtkAdjustment *adjustment, - gdouble climb_rate, guint digits); -static GtkWidget* (*fp_gtk_frame_new)(const gchar *label); - -/* Other widget operations */ -static GtkObject* (*fp_gtk_adjustment_new)(gdouble value, - gdouble lower, gdouble upper, gdouble step_increment, - gdouble page_increment, gdouble page_size); -static void (*fp_gtk_container_add)(GtkContainer *window, GtkWidget *widget); -static void (*fp_gtk_menu_shell_append)(GtkMenuShell *menu_shell, - GtkWidget *child); -static void (*fp_gtk_menu_item_set_submenu)(GtkMenuItem *menu_item, - GtkWidget *submenu); -static void (*fp_gtk_widget_realize)(GtkWidget *widget); -static GdkPixbuf* (*fp_gtk_widget_render_icon)(GtkWidget *widget, - const gchar *stock_id, GtkIconSize size, const gchar *detail); -static void (*fp_gtk_widget_set_name)(GtkWidget *widget, const gchar *name); -static void (*fp_gtk_widget_set_parent)(GtkWidget *widget, GtkWidget *parent); -static void (*fp_gtk_widget_set_direction)(GtkWidget *widget, - GtkTextDirection direction); -static void (*fp_gtk_widget_style_get)(GtkWidget *widget, - const gchar *first_property_name, ...); -static void (*fp_gtk_widget_class_install_style_property)( - GtkWidgetClass* class, GParamSpec *pspec); -static GParamSpec* (*fp_gtk_widget_class_find_style_property)( - GtkWidgetClass* class, const gchar* property_name); -static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget, - const gchar* property_name, GValue* value); -static char* (*fp_pango_font_description_to_string)( - const PangoFontDescription* fd); -static GtkSettings* (*fp_gtk_settings_get_default)(); -static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget); -static GType (*fp_gtk_border_get_type)(); -static void (*fp_gtk_arrow_set)(GtkWidget* arrow, - GtkArrowType arrow_type, - GtkShadowType shadow_type); -static void (*fp_gtk_widget_size_request)(GtkWidget *widget, - GtkRequisition *requisition); -static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range); - -/* Method bodies */ - -static void throw_exception(JNIEnv *env, const char* name, const char* message) -{ - jclass class = (*env)->FindClass(env, name); - - if (class != NULL) - (*env)->ThrowNew(env, class, message); - - (*env)->DeleteLocalRef(env, class); -} - -/* This is a workaround for the bug: - * http://sourceware.org/bugzilla/show_bug.cgi?id=1814 - * (dlsym/dlopen clears dlerror state) - * This bug is specific to Linux, but there is no harm in - * applying this workaround on Solaris as well. - */ -static void* dl_symbol(const char* name) -{ - void* result = dlsym(gtk2_libhandle, name); - if (!result) - longjmp(j, NO_SYMBOL_EXCEPTION); - - return result; -} - -static void* dl_symbol_gthread(const char* name) -{ - void* result = dlsym(gthread_libhandle, name); - if (!result) - longjmp(j, NO_SYMBOL_EXCEPTION); - - return result; -} - -gboolean gtk2_check(const char* lib_name, gboolean load) -{ - if (gtk2_libhandle != NULL) { - /* We've already successfully opened the GTK libs, so return true. */ - return TRUE; - } else { - void *lib = NULL; - -#ifdef RTLD_NOLOAD - /* Just check if gtk libs are already in the process space */ - lib = dlopen(lib_name, RTLD_LAZY | RTLD_NOLOAD); - if (!load || lib != NULL) { - return lib != NULL; - } -#else -#ifdef _AIX - /* On AIX we could implement this with the help of loadquery(L_GETINFO, ..) */ - /* (see reload_table() in hotspot/src/os/aix/vm/loadlib_aix.cpp) but it is */ - /* probably not worth it because most AIX servers don't have GTK libs anyway */ -#endif -#endif - - lib = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); - if (lib == NULL) { - return FALSE; - } - - fp_gtk_check_version = dlsym(lib, "gtk_check_version"); - /* Check for GTK 2.2+ */ - if (!fp_gtk_check_version(2, 2, 0)) { - return TRUE; - } - - // 8048289: workaround for https://bugzilla.gnome.org/show_bug.cgi?id=733065 - // dlclose(lib); - - return FALSE; - } -} - -#define ADD_SUPPORTED_ACTION(actionStr) \ -do { \ - jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, "Ljava/awt/Desktop$Action;"); \ - if (!(*env)->ExceptionCheck(env)) { \ - jobject action = (*env)->GetStaticObjectField(env, cls_action, fld_action); \ - (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, action); \ - } else { \ - (*env)->ExceptionClear(env); \ - } \ -} while(0); - - -static void update_supported_actions(JNIEnv *env) { - GVfs * (*fp_g_vfs_get_default) (void); - const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs); - const gchar * const * schemes = NULL; - - jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action"); - CHECK_NULL(cls_action); - jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer"); - CHECK_NULL(cls_xDesktopPeer); - jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;"); - CHECK_NULL(fld_supportedActions); - jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions); - - jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList"); - CHECK_NULL(cls_arrayList); - jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z"); - CHECK_NULL(mid_arrayListAdd); - jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V"); - CHECK_NULL(mid_arrayListClear); - - (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear); - - ADD_SUPPORTED_ACTION("OPEN"); - - /** - * gtk_show_uri() documentation says: - * - * > you need to install gvfs to get support for uri schemes such as http:// - * > or ftp://, as only local files are handled by GIO itself. - * - * So OPEN action was safely added here. - * However, it looks like Solaris 11 have gvfs support only for 32-bit - * applications only by default. - */ - - fp_g_vfs_get_default = dl_symbol("g_vfs_get_default"); - fp_g_vfs_get_supported_uri_schemes = dl_symbol("g_vfs_get_supported_uri_schemes"); - dlerror(); - - if (fp_g_vfs_get_default && fp_g_vfs_get_supported_uri_schemes) { - GVfs * vfs = fp_g_vfs_get_default(); - schemes = vfs ? fp_g_vfs_get_supported_uri_schemes(vfs) : NULL; - if (schemes) { - int i = 0; - while (schemes[i]) { - if (strcmp(schemes[i], "http") == 0) { - ADD_SUPPORTED_ACTION("BROWSE"); - ADD_SUPPORTED_ACTION("MAIL"); - break; - } - i++; - } - } - } else { -#ifdef DEBUG - fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n"); -#endif /* DEBUG */ - } - -} -/** - * Functions for awt_Desktop.c - */ -static gboolean gtk2_show_uri_load(JNIEnv *env) { - gboolean success = FALSE; - dlerror(); - const char *gtk_version = fp_gtk_check_version(2, 14, 0); - if (gtk_version != NULL) { - // The gtk_show_uri is available from GTK+ 2.14 -#ifdef DEBUG - fprintf (stderr, "The version of GTK is %s. " - "The gtk_show_uri function is supported " - "since GTK+ 2.14.\n", gtk_version); -#endif /* DEBUG */ - } else { - // Loading symbols only if the GTK version is 2.14 and higher - fp_gtk_show_uri = dl_symbol("gtk_show_uri"); - const char *dlsym_error = dlerror(); - if (dlsym_error) { -#ifdef DEBUG - fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error); -#endif /* DEBUG */ - } else if (fp_gtk_show_uri == NULL) { -#ifdef DEBUG - fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n"); -#endif /* DEBUG */ - } else { - gtk->gtk_show_uri = fp_gtk_show_uri; - update_supported_actions(env); - success = TRUE; - } - } - return success; -} - -/** - * Functions for sun_awt_X11_GtkFileDialogPeer.c - */ -static void gtk2_file_chooser_load() -{ - fp_gtk_file_chooser_get_filename = dl_symbol( - "gtk_file_chooser_get_filename"); - fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new"); - fp_gtk_file_chooser_set_current_folder = dl_symbol( - "gtk_file_chooser_set_current_folder"); - fp_gtk_file_chooser_set_filename = dl_symbol( - "gtk_file_chooser_set_filename"); - fp_gtk_file_chooser_set_current_name = dl_symbol( - "gtk_file_chooser_set_current_name"); - fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom"); - fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter"); - fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type"); - fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new"); - if (fp_gtk_check_version(2, 8, 0) == NULL) { - fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol( - "gtk_file_chooser_set_do_overwrite_confirmation"); - } - fp_gtk_file_chooser_set_select_multiple = dl_symbol( - "gtk_file_chooser_set_select_multiple"); - fp_gtk_file_chooser_get_current_folder = dl_symbol( - "gtk_file_chooser_get_current_folder"); - fp_gtk_file_chooser_get_filenames = dl_symbol( - "gtk_file_chooser_get_filenames"); - fp_gtk_g_slist_length = dl_symbol("g_slist_length"); - fp_gdk_x11_drawable_get_xid = dl_symbol("gdk_x11_drawable_get_xid"); -} - -GtkApi* gtk2_load(JNIEnv *env, const char* lib_name) -{ - gboolean result; - int i; - int (*handler)(); - int (*io_handler)(); - char *gtk_modules_env; - - gtk2_libhandle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); - if (gtk2_libhandle == NULL) { - return FALSE; - } - - gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL); - if (gthread_libhandle == NULL) { - gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL); - if (gthread_libhandle == NULL) - return FALSE; - } - - if (setjmp(j) == 0) - { - fp_gtk_check_version = dl_symbol("gtk_check_version"); - /* Check for GTK 2.2+ */ - if (fp_gtk_check_version(2, 2, 0)) { - longjmp(j, NO_SYMBOL_EXCEPTION); - } - - /* GLib */ - fp_glib_check_version = dlsym(gtk2_libhandle, "glib_check_version"); - if (!fp_glib_check_version) { - dlerror(); - } - fp_g_free = dl_symbol("g_free"); - fp_g_object_unref = dl_symbol("g_object_unref"); - - fp_g_main_context_iteration = - dl_symbol("g_main_context_iteration"); - - fp_g_value_init = dl_symbol("g_value_init"); - fp_g_type_is_a = dl_symbol("g_type_is_a"); - - fp_g_value_get_boolean = dl_symbol("g_value_get_boolean"); - fp_g_value_get_char = dl_symbol("g_value_get_char"); - fp_g_value_get_uchar = dl_symbol("g_value_get_uchar"); - fp_g_value_get_int = dl_symbol("g_value_get_int"); - fp_g_value_get_uint = dl_symbol("g_value_get_uint"); - fp_g_value_get_long = dl_symbol("g_value_get_long"); - fp_g_value_get_ulong = dl_symbol("g_value_get_ulong"); - fp_g_value_get_int64 = dl_symbol("g_value_get_int64"); - fp_g_value_get_uint64 = dl_symbol("g_value_get_uint64"); - fp_g_value_get_float = dl_symbol("g_value_get_float"); - fp_g_value_get_double = dl_symbol("g_value_get_double"); - fp_g_value_get_string = dl_symbol("g_value_get_string"); - fp_g_value_get_enum = dl_symbol("g_value_get_enum"); - fp_g_value_get_flags = dl_symbol("g_value_get_flags"); - fp_g_value_get_param = dl_symbol("g_value_get_param"); - fp_g_value_get_boxed = dl_symbol("g_value_get_boxed"); - fp_g_value_get_pointer = dl_symbol("g_value_get_pointer"); - fp_g_value_get_object = dl_symbol("g_value_get_object"); - fp_g_param_spec_int = dl_symbol("g_param_spec_int"); - fp_g_object_get = dl_symbol("g_object_get"); - fp_g_object_set = dl_symbol("g_object_set"); - - /* GDK */ - fp_gdk_get_default_root_window = - dl_symbol("gdk_get_default_root_window"); - fp_gdk_pixmap_new = dl_symbol("gdk_pixmap_new"); - fp_gdk_pixbuf_get_from_drawable = - dl_symbol("gdk_pixbuf_get_from_drawable"); - fp_gdk_pixbuf_scale_simple = - dl_symbol("gdk_pixbuf_scale_simple"); - fp_gdk_gc_new = dl_symbol("gdk_gc_new"); - fp_gdk_rgb_gc_set_foreground = - dl_symbol("gdk_rgb_gc_set_foreground"); - fp_gdk_draw_rectangle = dl_symbol("gdk_draw_rectangle"); - fp_gdk_drawable_get_size = dl_symbol("gdk_drawable_get_size"); - - /* Pixbuf */ - fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new"); - fp_gdk_pixbuf_new_from_file = - dl_symbol("gdk_pixbuf_new_from_file"); - fp_gdk_pixbuf_get_width = dl_symbol("gdk_pixbuf_get_width"); - fp_gdk_pixbuf_get_height = dl_symbol("gdk_pixbuf_get_height"); - fp_gdk_pixbuf_get_pixels = dl_symbol("gdk_pixbuf_get_pixels"); - fp_gdk_pixbuf_get_rowstride = - dl_symbol("gdk_pixbuf_get_rowstride"); - fp_gdk_pixbuf_get_has_alpha = - dl_symbol("gdk_pixbuf_get_has_alpha"); - fp_gdk_pixbuf_get_bits_per_sample = - dl_symbol("gdk_pixbuf_get_bits_per_sample"); - fp_gdk_pixbuf_get_n_channels = - dl_symbol("gdk_pixbuf_get_n_channels"); - fp_gdk_pixbuf_get_colorspace = - dl_symbol("gdk_pixbuf_get_colorspace"); - - /* GTK painting */ - fp_gtk_init_check = dl_symbol("gtk_init_check"); - fp_gtk_paint_hline = dl_symbol("gtk_paint_hline"); - fp_gtk_paint_vline = dl_symbol("gtk_paint_vline"); - fp_gtk_paint_shadow = dl_symbol("gtk_paint_shadow"); - fp_gtk_paint_arrow = dl_symbol("gtk_paint_arrow"); - fp_gtk_paint_diamond = dl_symbol("gtk_paint_diamond"); - fp_gtk_paint_box = dl_symbol("gtk_paint_box"); - fp_gtk_paint_flat_box = dl_symbol("gtk_paint_flat_box"); - fp_gtk_paint_check = dl_symbol("gtk_paint_check"); - fp_gtk_paint_option = dl_symbol("gtk_paint_option"); - fp_gtk_paint_box_gap = dl_symbol("gtk_paint_box_gap"); - fp_gtk_paint_extension = dl_symbol("gtk_paint_extension"); - fp_gtk_paint_focus = dl_symbol("gtk_paint_focus"); - fp_gtk_paint_slider = dl_symbol("gtk_paint_slider"); - fp_gtk_paint_handle = dl_symbol("gtk_paint_handle"); - fp_gtk_paint_expander = dl_symbol("gtk_paint_expander"); - fp_gtk_style_apply_default_background = - dl_symbol("gtk_style_apply_default_background"); - - /* GTK widgets */ - fp_gtk_arrow_new = dl_symbol("gtk_arrow_new"); - fp_gtk_button_new = dl_symbol("gtk_button_new"); - fp_gtk_spin_button_new = dl_symbol("gtk_spin_button_new"); - fp_gtk_check_button_new = dl_symbol("gtk_check_button_new"); - fp_gtk_check_menu_item_new = - dl_symbol("gtk_check_menu_item_new"); - fp_gtk_color_selection_dialog_new = - dl_symbol("gtk_color_selection_dialog_new"); - fp_gtk_entry_new = dl_symbol("gtk_entry_new"); - fp_gtk_fixed_new = dl_symbol("gtk_fixed_new"); - fp_gtk_handle_box_new = dl_symbol("gtk_handle_box_new"); - fp_gtk_image_new = dl_symbol("gtk_image_new"); - fp_gtk_hpaned_new = dl_symbol("gtk_hpaned_new"); - fp_gtk_vpaned_new = dl_symbol("gtk_vpaned_new"); - fp_gtk_hscale_new = dl_symbol("gtk_hscale_new"); - fp_gtk_vscale_new = dl_symbol("gtk_vscale_new"); - fp_gtk_hscrollbar_new = dl_symbol("gtk_hscrollbar_new"); - fp_gtk_vscrollbar_new = dl_symbol("gtk_vscrollbar_new"); - fp_gtk_hseparator_new = dl_symbol("gtk_hseparator_new"); - fp_gtk_vseparator_new = dl_symbol("gtk_vseparator_new"); - fp_gtk_label_new = dl_symbol("gtk_label_new"); - fp_gtk_menu_new = dl_symbol("gtk_menu_new"); - fp_gtk_menu_bar_new = dl_symbol("gtk_menu_bar_new"); - fp_gtk_menu_item_new = dl_symbol("gtk_menu_item_new"); - fp_gtk_menu_item_set_submenu = - dl_symbol("gtk_menu_item_set_submenu"); - fp_gtk_notebook_new = dl_symbol("gtk_notebook_new"); - fp_gtk_progress_bar_new = - dl_symbol("gtk_progress_bar_new"); - fp_gtk_progress_bar_set_orientation = - dl_symbol("gtk_progress_bar_set_orientation"); - fp_gtk_radio_button_new = - dl_symbol("gtk_radio_button_new"); - fp_gtk_radio_menu_item_new = - dl_symbol("gtk_radio_menu_item_new"); - fp_gtk_scrolled_window_new = - dl_symbol("gtk_scrolled_window_new"); - fp_gtk_separator_menu_item_new = - dl_symbol("gtk_separator_menu_item_new"); - fp_gtk_text_view_new = dl_symbol("gtk_text_view_new"); - fp_gtk_toggle_button_new = - dl_symbol("gtk_toggle_button_new"); - fp_gtk_toolbar_new = dl_symbol("gtk_toolbar_new"); - fp_gtk_tree_view_new = dl_symbol("gtk_tree_view_new"); - fp_gtk_viewport_new = dl_symbol("gtk_viewport_new"); - fp_gtk_window_new = dl_symbol("gtk_window_new"); - fp_gtk_window_present = dl_symbol("gtk_window_present"); - fp_gtk_window_move = dl_symbol("gtk_window_move"); - fp_gtk_window_resize = dl_symbol("gtk_window_resize"); - - fp_gtk_dialog_new = dl_symbol("gtk_dialog_new"); - fp_gtk_frame_new = dl_symbol("gtk_frame_new"); - - fp_gtk_adjustment_new = dl_symbol("gtk_adjustment_new"); - fp_gtk_container_add = dl_symbol("gtk_container_add"); - fp_gtk_menu_shell_append = - dl_symbol("gtk_menu_shell_append"); - fp_gtk_widget_realize = dl_symbol("gtk_widget_realize"); - fp_gtk_widget_destroy = dl_symbol("gtk_widget_destroy"); - fp_gtk_widget_render_icon = - dl_symbol("gtk_widget_render_icon"); - fp_gtk_widget_set_name = - dl_symbol("gtk_widget_set_name"); - fp_gtk_widget_set_parent = - dl_symbol("gtk_widget_set_parent"); - fp_gtk_widget_set_direction = - dl_symbol("gtk_widget_set_direction"); - fp_gtk_widget_style_get = - dl_symbol("gtk_widget_style_get"); - fp_gtk_widget_class_install_style_property = - dl_symbol("gtk_widget_class_install_style_property"); - fp_gtk_widget_class_find_style_property = - dl_symbol("gtk_widget_class_find_style_property"); - fp_gtk_widget_style_get_property = - dl_symbol("gtk_widget_style_get_property"); - fp_pango_font_description_to_string = - dl_symbol("pango_font_description_to_string"); - fp_gtk_settings_get_default = - dl_symbol("gtk_settings_get_default"); - fp_gtk_widget_get_settings = - dl_symbol("gtk_widget_get_settings"); - fp_gtk_border_get_type = dl_symbol("gtk_border_get_type"); - fp_gtk_arrow_set = dl_symbol("gtk_arrow_set"); - fp_gtk_widget_size_request = - dl_symbol("gtk_widget_size_request"); - fp_gtk_range_get_adjustment = - dl_symbol("gtk_range_get_adjustment"); - - fp_gtk_widget_hide = dl_symbol("gtk_widget_hide"); - fp_gtk_main_quit = dl_symbol("gtk_main_quit"); - fp_g_signal_connect_data = dl_symbol("g_signal_connect_data"); - fp_gtk_widget_show = dl_symbol("gtk_widget_show"); - fp_gtk_main = dl_symbol("gtk_main"); - - fp_g_path_get_dirname = dl_symbol("g_path_get_dirname"); - - /** - * GLib thread system - */ - if (GLIB_CHECK_VERSION(2, 20, 0)) { - fp_g_thread_get_initialized = dl_symbol_gthread("g_thread_get_initialized"); - } - fp_g_thread_init = dl_symbol_gthread("g_thread_init"); - fp_gdk_threads_init = dl_symbol("gdk_threads_init"); - fp_gdk_threads_enter = dl_symbol("gdk_threads_enter"); - fp_gdk_threads_leave = dl_symbol("gdk_threads_leave"); - - /** - * Functions for sun_awt_X11_GtkFileDialogPeer.c - */ - if (fp_gtk_check_version(2, 4, 0) == NULL) { - // The current GtkFileChooser is available from GTK+ 2.4 - gtk2_file_chooser_load(); - } - - /* Some functions may be missing in pre-2.4 GTK. - We handle them specially here. - */ - fp_gtk_combo_box_new = dlsym(gtk2_libhandle, "gtk_combo_box_new"); - if (fp_gtk_combo_box_new == NULL) { - fp_gtk_combo_box_new = dl_symbol("gtk_combo_new"); - } - - fp_gtk_combo_box_entry_new = - dlsym(gtk2_libhandle, "gtk_combo_box_entry_new"); - if (fp_gtk_combo_box_entry_new == NULL) { - fp_gtk_combo_box_entry_new = dl_symbol("gtk_combo_new"); - new_combo = FALSE; - } - - fp_gtk_separator_tool_item_new = - dlsym(gtk2_libhandle, "gtk_separator_tool_item_new"); - if (fp_gtk_separator_tool_item_new == NULL) { - fp_gtk_separator_tool_item_new = - dl_symbol("gtk_vseparator_new"); - } - - fp_g_list_append = dl_symbol("g_list_append"); - fp_g_list_free = dl_symbol("g_list_free"); - fp_g_list_free_full = dl_symbol("g_list_free_full"); - } - /* Now we have only one kind of exceptions: NO_SYMBOL_EXCEPTION - * Otherwise we can check the return value of setjmp method. - */ - else - { - dlclose(gtk2_libhandle); - gtk2_libhandle = NULL; - - dlclose(gthread_libhandle); - gthread_libhandle = NULL; - - return FALSE; - } - - /* - * Strip the AT-SPI GTK_MODULES if present - */ - gtk_modules_env = getenv ("GTK_MODULES"); - if ((gtk_modules_env && strstr(gtk_modules_env, "atk-bridge")) || - (gtk_modules_env && strstr(gtk_modules_env, "gail"))) { - /* careful, strtok modifies its args */ - gchar *tmp_env = strdup(gtk_modules_env); - if (tmp_env) { - /* the new env will be smaller than the old one */ - gchar *s, *new_env = SAFE_SIZE_STRUCT_ALLOC(malloc, - sizeof(ENV_PREFIX), 1, strlen (gtk_modules_env)); - - if (new_env) { - strcpy(new_env, ENV_PREFIX); - - /* strip out 'atk-bridge' and 'gail' */ - size_t PREFIX_LENGTH = strlen(ENV_PREFIX); - gchar *tmp_ptr = NULL; - for (s = strtok_r(tmp_env, ":", &tmp_ptr); s; - s = strtok_r(NULL, ":", &tmp_ptr)) { - if ((!strstr(s, "atk-bridge")) && (!strstr(s, "gail"))) { - if (strlen(new_env) > PREFIX_LENGTH) { - new_env = strcat(new_env, ":"); - } - new_env = strcat(new_env, s); - } - } - if (putenv(new_env) != 0) { - /* no free() on success, putenv() doesn't copy string */ - free(new_env); - } - } - free(tmp_env); - } - } - /* - * GTK should be initialized with gtk_init_check() before use. - * - * gtk_init_check installs its own error handlers. It is critical that - * we preserve error handler set from AWT. Otherwise we'll crash on - * BadMatch errors which we would normally ignore. The IO error handler - * is preserved here, too, just for consistency. - */ - AWT_LOCK(); - handler = XSetErrorHandler(NULL); - io_handler = XSetIOErrorHandler(NULL); - - if (fp_gtk_check_version(2, 2, 0) == NULL) { - - // Calling g_thread_init() multiple times leads to crash on GLib < 2.24 - // We can use g_thread_get_initialized () but it is available only for - // GLib >= 2.20. - gboolean is_g_thread_get_initialized = FALSE; - if (GLIB_CHECK_VERSION(2, 20, 0)) { - is_g_thread_get_initialized = fp_g_thread_get_initialized(); - } - - if (!is_g_thread_get_initialized) { - fp_g_thread_init(NULL); - } - - //According the GTK documentation, gdk_threads_init() should be - //called before gtk_init() or gtk_init_check() - fp_gdk_threads_init(); - } - result = (*fp_gtk_init_check)(NULL, NULL); - - XSetErrorHandler(handler); - XSetIOErrorHandler(io_handler); - AWT_UNLOCK(); - - /* Initialize widget array. */ - for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++) - { - gtk2_widgets[i] = NULL; - } - if (result) { - GtkApi* gtk = (GtkApi*)malloc(sizeof(GtkApi)); - gtk2_init(gtk); - return gtk; - } - return NULL; -} - -int gtk2_unload() -{ - int i; - char *gtk2_error; - - if (!gtk2_libhandle) - return TRUE; - - /* Release painting objects */ - if (gtk2_white_pixmap != NULL) { - (*fp_g_object_unref)(gtk2_white_pixmap); - (*fp_g_object_unref)(gtk2_black_pixmap); - (*fp_g_object_unref)(gtk2_white_pixbuf); - (*fp_g_object_unref)(gtk2_black_pixbuf); - gtk2_white_pixmap = gtk2_black_pixmap = - gtk2_white_pixbuf = gtk2_black_pixbuf = NULL; - } - gtk2_pixbuf_width = 0; - gtk2_pixbuf_height = 0; - - if (gtk2_window != NULL) { - /* Destroying toplevel widget will destroy all contained widgets */ - (*fp_gtk_widget_destroy)(gtk2_window); - - /* Unset some static data so they get reinitialized on next load */ - gtk2_window = NULL; - } - - dlerror(); - dlclose(gtk2_libhandle); - dlclose(gthread_libhandle); - if ((gtk2_error = dlerror()) != NULL) - { - return FALSE; - } - return TRUE; -} - -/* Dispatch all pending events from the GTK event loop. - * This is needed to catch theme change and update widgets' style. - */ -static void flush_gtk_event_loop() -{ - while( (*fp_g_main_context_iteration)(NULL, FALSE)); -} - -/* - * Initialize components of containment hierarchy. This creates a GtkFixed - * inside a GtkWindow. All widgets get realized. - */ -static void init_containers() -{ - if (gtk2_window == NULL) - { - gtk2_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - gtk2_fixed = (GtkFixed *)(*fp_gtk_fixed_new)(); - (*fp_gtk_container_add)((GtkContainer*)gtk2_window, - (GtkWidget *)gtk2_fixed); - (*fp_gtk_widget_realize)(gtk2_window); - (*fp_gtk_widget_realize)((GtkWidget *)gtk2_fixed); - } -} - -/* - * Ensure everything is ready for drawing an element of the specified width - * and height. - * - * We should somehow handle translucent images. GTK can draw to X Drawables - * only, which don't support alpha. When we retrieve the image back from - * the server, translucency information is lost. There're several ways to - * work around this: - * 1) Subclass GdkPixmap and cache translucent objects on client side. This - * requires us to implement parts of X server drawing logic on client side. - * Many X requests can potentially be "translucent"; e.g. XDrawLine with - * fill=tile and a translucent tile is a "translucent" operation, whereas - * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some - * do) intermix transparent and opaque operations which makes caching even - * more problematic. - * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support - * for it (as of version 2.6). Also even in JDS 3 Xorg does not support - * these visuals by default, which makes optimizing for them pointless. - * We can consider doing this at a later point when ARGB visuals become more - * popular. - * 3') GTK has plans to use Cairo as its graphical backend (presumably in - * 2.8), and Cairo supports alpha. With it we could also get rid of the - * unnecessary round trip to server and do all the drawing on client side. - * 4) For now we draw to two different pixmaps and restore alpha channel by - * comparing results. This can be optimized by using subclassed pixmap and - * doing the second drawing only if necessary. -*/ -static void gtk2_init_painting(JNIEnv *env, gint width, gint height) -{ - GdkGC *gc; - GdkPixbuf *white, *black; - - init_containers(); - - if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height) - { - white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height); - black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height); - - if (white == NULL || black == NULL) - { - snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height); - throw_exception(env, "java/lang/RuntimeException", convertionBuffer); - fp_gdk_threads_leave(); - return; - } - - if (gtk2_white_pixmap != NULL) { - /* free old stuff */ - (*fp_g_object_unref)(gtk2_white_pixmap); - (*fp_g_object_unref)(gtk2_black_pixmap); - (*fp_g_object_unref)(gtk2_white_pixbuf); - (*fp_g_object_unref)(gtk2_black_pixbuf); - } - - gtk2_white_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1); - gtk2_black_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1); - - gtk2_white_pixbuf = white; - gtk2_black_pixbuf = black; - - gtk2_pixbuf_width = width; - gtk2_pixbuf_height = height; - } - - /* clear the pixmaps */ - gc = (*fp_gdk_gc_new)(gtk2_white_pixmap); - (*fp_gdk_rgb_gc_set_foreground)(gc, 0xffffff); - (*fp_gdk_draw_rectangle)(gtk2_white_pixmap, gc, TRUE, 0, 0, width, height); - (*fp_g_object_unref)(gc); - - gc = (*fp_gdk_gc_new)(gtk2_black_pixmap); - (*fp_gdk_rgb_gc_set_foreground)(gc, 0x000000); - (*fp_gdk_draw_rectangle)(gtk2_black_pixmap, gc, TRUE, 0, 0, width, height); - (*fp_g_object_unref)(gc); -} - -/* - * Restore image from white and black pixmaps and copy it into destination - * buffer. This method compares two pixbufs taken from white and black - * pixmaps and decodes color and alpha components. Pixbufs are RGB without - * alpha, destination buffer is ABGR. - * - * The return value is the transparency type of the resulting image, either - * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and - * java_awt_Transparency_TRANSLUCENT. - */ -static gint gtk2_copy_image(gint *dst, gint width, gint height) -{ - gint i, j, r, g, b; - guchar *white, *black; - gint stride, padding; - gboolean is_opaque = TRUE; - gboolean is_bitmask = TRUE; - - (*fp_gdk_pixbuf_get_from_drawable)(gtk2_white_pixbuf, gtk2_white_pixmap, - NULL, 0, 0, 0, 0, width, height); - (*fp_gdk_pixbuf_get_from_drawable)(gtk2_black_pixbuf, gtk2_black_pixmap, - NULL, 0, 0, 0, 0, width, height); - - white = (*fp_gdk_pixbuf_get_pixels)(gtk2_white_pixbuf); - black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf); - stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf); - padding = stride - width * 4; - - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - int r1 = *white++; - int r2 = *black++; - int alpha = 0xff + r2 - r1; - - switch (alpha) { - case 0: /* transparent pixel */ - r = g = b = 0; - black += 3; - white += 3; - is_opaque = FALSE; - break; - - case 0xff: /* opaque pixel */ - r = r2; - g = *black++; - b = *black++; - black++; - white += 3; - break; - - default: /* translucent pixel */ - r = 0xff * r2 / alpha; - g = 0xff * *black++ / alpha; - b = 0xff * *black++ / alpha; - black++; - white += 3; - is_opaque = FALSE; - is_bitmask = FALSE; - break; - } - - *dst++ = (alpha << 24 | r << 16 | g << 8 | b); - } - - white += padding; - black += padding; - } - return is_opaque ? java_awt_Transparency_OPAQUE : - (is_bitmask ? java_awt_Transparency_BITMASK : - java_awt_Transparency_TRANSLUCENT); -} - -static void -gtk2_set_direction(GtkWidget *widget, GtkTextDirection dir) -{ - /* - * Some engines (inexplicably) look at the direction of the widget's - * parent, so we need to set the direction of both the widget and its - * parent. - */ - (*fp_gtk_widget_set_direction)(widget, dir); - if (widget->parent != NULL) { - (*fp_gtk_widget_set_direction)(widget->parent, dir); - } -} - -/* - * Initializes the widget to correct state for some engines. - * This is a pure empirical method. - */ -static void init_toggle_widget(WidgetType widget_type, gint synth_state) -{ - gboolean is_active = ((synth_state & SELECTED) != 0); - - if (widget_type == RADIO_BUTTON || - widget_type == CHECK_BOX || - widget_type == TOGGLE_BUTTON) { - ((GtkToggleButton*)gtk2_widget)->active = is_active; - } - - if ((synth_state & FOCUSED) != 0) { - ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS; - } else { - ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS; - } - - if ((synth_state & MOUSE_OVER) != 0 && (synth_state & PRESSED) == 0 || - (synth_state & FOCUSED) != 0 && (synth_state & PRESSED) != 0) { - gtk2_widget->state = GTK_STATE_PRELIGHT; - } else if ((synth_state & DISABLED) != 0) { - gtk2_widget->state = GTK_STATE_INSENSITIVE; - } else { - gtk2_widget->state = is_active ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL; - } -} - -/* GTK state_type filter */ -static GtkStateType get_gtk_state_type(WidgetType widget_type, gint synth_state) -{ - GtkStateType result = GTK_STATE_NORMAL; - - if ((synth_state & DISABLED) != 0) { - result = GTK_STATE_INSENSITIVE; - } else if ((synth_state & PRESSED) != 0) { - result = GTK_STATE_ACTIVE; - } else if ((synth_state & MOUSE_OVER) != 0) { - result = GTK_STATE_PRELIGHT; - } - return result; -} - -/* GTK shadow_type filter */ -static GtkShadowType get_gtk_shadow_type(WidgetType widget_type, gint synth_state) -{ - GtkShadowType result = GTK_SHADOW_OUT; - - if ((synth_state & SELECTED) != 0) { - result = GTK_SHADOW_IN; - } - return result; -} - - -static GtkWidget* gtk2_get_arrow(GtkArrowType arrow_type, GtkShadowType shadow_type) -{ - GtkWidget *arrow = NULL; - if (NULL == gtk2_widgets[_GTK_ARROW_TYPE]) - { - gtk2_widgets[_GTK_ARROW_TYPE] = (*fp_gtk_arrow_new)(arrow_type, shadow_type); - (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, gtk2_widgets[_GTK_ARROW_TYPE]); - (*fp_gtk_widget_realize)(gtk2_widgets[_GTK_ARROW_TYPE]); - } - arrow = gtk2_widgets[_GTK_ARROW_TYPE]; - - (*fp_gtk_arrow_set)(arrow, arrow_type, shadow_type); - return arrow; -} - -static GtkAdjustment* create_adjustment() -{ - return (GtkAdjustment *) - (*fp_gtk_adjustment_new)(50.0, 0.0, 100.0, 10.0, 20.0, 20.0); -} - -/** - * Returns a pointer to the cached native widget for the specified widget - * type. - */ -static GtkWidget *gtk2_get_widget(WidgetType widget_type) -{ - gboolean init_result = FALSE; - GtkWidget *result = NULL; - switch (widget_type) - { - case BUTTON: - case TABLE_HEADER: - if (init_result = (NULL == gtk2_widgets[_GTK_BUTTON_TYPE])) - { - gtk2_widgets[_GTK_BUTTON_TYPE] = (*fp_gtk_button_new)(); - } - result = gtk2_widgets[_GTK_BUTTON_TYPE]; - break; - case CHECK_BOX: - if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_BUTTON_TYPE])) - { - gtk2_widgets[_GTK_CHECK_BUTTON_TYPE] = - (*fp_gtk_check_button_new)(); - } - result = gtk2_widgets[_GTK_CHECK_BUTTON_TYPE]; - break; - case CHECK_BOX_MENU_ITEM: - if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE])) - { - gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE] = - (*fp_gtk_check_menu_item_new)(); - } - result = gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE]; - break; - /************************************************************ - * Creation a dedicated color chooser is dangerous because - * it deadlocks the EDT - ************************************************************/ -/* case COLOR_CHOOSER: - if (init_result = - (NULL == gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE])) - { - gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE] = - (*fp_gtk_color_selection_dialog_new)(NULL); - } - result = gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE]; - break;*/ - case COMBO_BOX: - if (init_result = (NULL == gtk2_widgets[_GTK_COMBO_BOX_TYPE])) - { - gtk2_widgets[_GTK_COMBO_BOX_TYPE] = - (*fp_gtk_combo_box_new)(); - } - result = gtk2_widgets[_GTK_COMBO_BOX_TYPE]; - break; - case COMBO_BOX_ARROW_BUTTON: - if (init_result = - (NULL == gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE])) - { - gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE] = - (*fp_gtk_toggle_button_new)(); - } - result = gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE]; - break; - case COMBO_BOX_TEXT_FIELD: - if (init_result = - (NULL == gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE])) - { - result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE] = - (*fp_gtk_entry_new)(); - } - result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE]; - break; - case DESKTOP_ICON: - case INTERNAL_FRAME_TITLE_PANE: - case LABEL: - if (init_result = (NULL == gtk2_widgets[_GTK_LABEL_TYPE])) - { - gtk2_widgets[_GTK_LABEL_TYPE] = - (*fp_gtk_label_new)(NULL); - } - result = gtk2_widgets[_GTK_LABEL_TYPE]; - break; - case DESKTOP_PANE: - case PANEL: - case ROOT_PANE: - if (init_result = (NULL == gtk2_widgets[_GTK_CONTAINER_TYPE])) - { - /* There is no constructor for a container type. I've - * chosen GtkFixed container since it has a default - * constructor. - */ - gtk2_widgets[_GTK_CONTAINER_TYPE] = - (*fp_gtk_fixed_new)(); - } - result = gtk2_widgets[_GTK_CONTAINER_TYPE]; - break; - case EDITOR_PANE: - case TEXT_AREA: - case TEXT_PANE: - if (init_result = (NULL == gtk2_widgets[_GTK_TEXT_VIEW_TYPE])) - { - gtk2_widgets[_GTK_TEXT_VIEW_TYPE] = - (*fp_gtk_text_view_new)(); - } - result = gtk2_widgets[_GTK_TEXT_VIEW_TYPE]; - break; - case FORMATTED_TEXT_FIELD: - case PASSWORD_FIELD: - case TEXT_FIELD: - if (init_result = (NULL == gtk2_widgets[_GTK_ENTRY_TYPE])) - { - gtk2_widgets[_GTK_ENTRY_TYPE] = - (*fp_gtk_entry_new)(); - } - result = gtk2_widgets[_GTK_ENTRY_TYPE]; - break; - case HANDLE_BOX: - if (init_result = (NULL == gtk2_widgets[_GTK_HANDLE_BOX_TYPE])) - { - gtk2_widgets[_GTK_HANDLE_BOX_TYPE] = - (*fp_gtk_handle_box_new)(); - } - result = gtk2_widgets[_GTK_HANDLE_BOX_TYPE]; - break; - case HSCROLL_BAR: - case HSCROLL_BAR_BUTTON_LEFT: - case HSCROLL_BAR_BUTTON_RIGHT: - case HSCROLL_BAR_TRACK: - case HSCROLL_BAR_THUMB: - if (init_result = (NULL == gtk2_widgets[_GTK_HSCROLLBAR_TYPE])) - { - gtk2_widgets[_GTK_HSCROLLBAR_TYPE] = - (*fp_gtk_hscrollbar_new)(create_adjustment()); - } - result = gtk2_widgets[_GTK_HSCROLLBAR_TYPE]; - break; - case HSEPARATOR: - if (init_result = (NULL == gtk2_widgets[_GTK_HSEPARATOR_TYPE])) - { - gtk2_widgets[_GTK_HSEPARATOR_TYPE] = - (*fp_gtk_hseparator_new)(); - } - result = gtk2_widgets[_GTK_HSEPARATOR_TYPE]; - break; - case HSLIDER: - case HSLIDER_THUMB: - case HSLIDER_TRACK: - if (init_result = (NULL == gtk2_widgets[_GTK_HSCALE_TYPE])) - { - gtk2_widgets[_GTK_HSCALE_TYPE] = - (*fp_gtk_hscale_new)(NULL); - } - result = gtk2_widgets[_GTK_HSCALE_TYPE]; - break; - case HSPLIT_PANE_DIVIDER: - case SPLIT_PANE: - if (init_result = (NULL == gtk2_widgets[_GTK_HPANED_TYPE])) - { - gtk2_widgets[_GTK_HPANED_TYPE] = (*fp_gtk_hpaned_new)(); - } - result = gtk2_widgets[_GTK_HPANED_TYPE]; - break; - case IMAGE: - if (init_result = (NULL == gtk2_widgets[_GTK_IMAGE_TYPE])) - { - gtk2_widgets[_GTK_IMAGE_TYPE] = (*fp_gtk_image_new)(); - } - result = gtk2_widgets[_GTK_IMAGE_TYPE]; - break; - case INTERNAL_FRAME: - if (init_result = (NULL == gtk2_widgets[_GTK_WINDOW_TYPE])) - { - gtk2_widgets[_GTK_WINDOW_TYPE] = - (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - } - result = gtk2_widgets[_GTK_WINDOW_TYPE]; - break; - case TOOL_TIP: - if (init_result = (NULL == gtk2_widgets[_GTK_TOOLTIP_TYPE])) - { - result = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - (*fp_gtk_widget_set_name)(result, "gtk-tooltips"); - gtk2_widgets[_GTK_TOOLTIP_TYPE] = result; - } - result = gtk2_widgets[_GTK_TOOLTIP_TYPE]; - break; - case LIST: - case TABLE: - case TREE: - case TREE_CELL: - if (init_result = (NULL == gtk2_widgets[_GTK_TREE_VIEW_TYPE])) - { - gtk2_widgets[_GTK_TREE_VIEW_TYPE] = - (*fp_gtk_tree_view_new)(); - } - result = gtk2_widgets[_GTK_TREE_VIEW_TYPE]; - break; - case TITLED_BORDER: - if (init_result = (NULL == gtk2_widgets[_GTK_FRAME_TYPE])) - { - gtk2_widgets[_GTK_FRAME_TYPE] = fp_gtk_frame_new(NULL); - } - result = gtk2_widgets[_GTK_FRAME_TYPE]; - break; - case POPUP_MENU: - if (init_result = (NULL == gtk2_widgets[_GTK_MENU_TYPE])) - { - gtk2_widgets[_GTK_MENU_TYPE] = - (*fp_gtk_menu_new)(); - } - result = gtk2_widgets[_GTK_MENU_TYPE]; - break; - case MENU: - case MENU_ITEM: - case MENU_ITEM_ACCELERATOR: - if (init_result = (NULL == gtk2_widgets[_GTK_MENU_ITEM_TYPE])) - { - gtk2_widgets[_GTK_MENU_ITEM_TYPE] = - (*fp_gtk_menu_item_new)(); - } - result = gtk2_widgets[_GTK_MENU_ITEM_TYPE]; - break; - case MENU_BAR: - if (init_result = (NULL == gtk2_widgets[_GTK_MENU_BAR_TYPE])) - { - gtk2_widgets[_GTK_MENU_BAR_TYPE] = - (*fp_gtk_menu_bar_new)(); - } - result = gtk2_widgets[_GTK_MENU_BAR_TYPE]; - break; - case COLOR_CHOOSER: - case OPTION_PANE: - if (init_result = (NULL == gtk2_widgets[_GTK_DIALOG_TYPE])) - { - gtk2_widgets[_GTK_DIALOG_TYPE] = - (*fp_gtk_dialog_new)(); - } - result = gtk2_widgets[_GTK_DIALOG_TYPE]; - break; - case POPUP_MENU_SEPARATOR: - if (init_result = - (NULL == gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE])) - { - gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE] = - (*fp_gtk_separator_menu_item_new)(); - } - result = gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE]; - break; - case HPROGRESS_BAR: - if (init_result = (NULL == gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE])) - { - gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE] = - (*fp_gtk_progress_bar_new)(); - } - result = gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE]; - break; - case VPROGRESS_BAR: - if (init_result = (NULL == gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE])) - { - gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE] = - (*fp_gtk_progress_bar_new)(); - /* - * Vertical JProgressBars always go bottom-to-top, - * regardless of the ComponentOrientation. - */ - (*fp_gtk_progress_bar_set_orientation)( - (GtkProgressBar *)gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE], - GTK_PROGRESS_BOTTOM_TO_TOP); - } - result = gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE]; - break; - case RADIO_BUTTON: - if (init_result = (NULL == gtk2_widgets[_GTK_RADIO_BUTTON_TYPE])) - { - gtk2_widgets[_GTK_RADIO_BUTTON_TYPE] = - (*fp_gtk_radio_button_new)(NULL); - } - result = gtk2_widgets[_GTK_RADIO_BUTTON_TYPE]; - break; - case RADIO_BUTTON_MENU_ITEM: - if (init_result = - (NULL == gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE])) - { - gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE] = - (*fp_gtk_radio_menu_item_new)(NULL); - } - result = gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE]; - break; - case SCROLL_PANE: - if (init_result = - (NULL == gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE])) - { - gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE] = - (*fp_gtk_scrolled_window_new)(NULL, NULL); - } - result = gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE]; - break; - case SPINNER: - case SPINNER_ARROW_BUTTON: - case SPINNER_TEXT_FIELD: - if (init_result = (NULL == gtk2_widgets[_GTK_SPIN_BUTTON_TYPE])) - { - result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE] = - (*fp_gtk_spin_button_new)(NULL, 0, 0); - } - result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE]; - break; - case TABBED_PANE: - case TABBED_PANE_TAB_AREA: - case TABBED_PANE_CONTENT: - case TABBED_PANE_TAB: - if (init_result = (NULL == gtk2_widgets[_GTK_NOTEBOOK_TYPE])) - { - gtk2_widgets[_GTK_NOTEBOOK_TYPE] = - (*fp_gtk_notebook_new)(NULL); - } - result = gtk2_widgets[_GTK_NOTEBOOK_TYPE]; - break; - case TOGGLE_BUTTON: - if (init_result = (NULL == gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE])) - { - gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE] = - (*fp_gtk_toggle_button_new)(NULL); - } - result = gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE]; - break; - case TOOL_BAR: - case TOOL_BAR_DRAG_WINDOW: - if (init_result = (NULL == gtk2_widgets[_GTK_TOOLBAR_TYPE])) - { - gtk2_widgets[_GTK_TOOLBAR_TYPE] = - (*fp_gtk_toolbar_new)(NULL); - } - result = gtk2_widgets[_GTK_TOOLBAR_TYPE]; - break; - case TOOL_BAR_SEPARATOR: - if (init_result = - (NULL == gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE])) - { - gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE] = - (*fp_gtk_separator_tool_item_new)(); - } - result = gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE]; - break; - case VIEWPORT: - if (init_result = (NULL == gtk2_widgets[_GTK_VIEWPORT_TYPE])) - { - GtkAdjustment *adjustment = create_adjustment(); - gtk2_widgets[_GTK_VIEWPORT_TYPE] = - (*fp_gtk_viewport_new)(adjustment, adjustment); - } - result = gtk2_widgets[_GTK_VIEWPORT_TYPE]; - break; - case VSCROLL_BAR: - case VSCROLL_BAR_BUTTON_UP: - case VSCROLL_BAR_BUTTON_DOWN: - case VSCROLL_BAR_TRACK: - case VSCROLL_BAR_THUMB: - if (init_result = (NULL == gtk2_widgets[_GTK_VSCROLLBAR_TYPE])) - { - gtk2_widgets[_GTK_VSCROLLBAR_TYPE] = - (*fp_gtk_vscrollbar_new)(create_adjustment()); - } - result = gtk2_widgets[_GTK_VSCROLLBAR_TYPE]; - break; - case VSEPARATOR: - if (init_result = (NULL == gtk2_widgets[_GTK_VSEPARATOR_TYPE])) - { - gtk2_widgets[_GTK_VSEPARATOR_TYPE] = - (*fp_gtk_vseparator_new)(); - } - result = gtk2_widgets[_GTK_VSEPARATOR_TYPE]; - break; - case VSLIDER: - case VSLIDER_THUMB: - case VSLIDER_TRACK: - if (init_result = (NULL == gtk2_widgets[_GTK_VSCALE_TYPE])) - { - gtk2_widgets[_GTK_VSCALE_TYPE] = - (*fp_gtk_vscale_new)(NULL); - } - result = gtk2_widgets[_GTK_VSCALE_TYPE]; - /* - * Vertical JSliders start at the bottom, while vertical - * GtkVScale widgets start at the top (by default), so to fix - * this we set the "inverted" flag to get the Swing behavior. - */ - ((GtkRange*)result)->inverted = 1; - break; - case VSPLIT_PANE_DIVIDER: - if (init_result = (NULL == gtk2_widgets[_GTK_VPANED_TYPE])) - { - gtk2_widgets[_GTK_VPANED_TYPE] = (*fp_gtk_vpaned_new)(); - } - result = gtk2_widgets[_GTK_VPANED_TYPE]; - break; - default: - result = NULL; - break; - } - - if (result != NULL && init_result) - { - if (widget_type == RADIO_BUTTON_MENU_ITEM || - widget_type == CHECK_BOX_MENU_ITEM || - widget_type == MENU_ITEM || - widget_type == MENU || - widget_type == POPUP_MENU_SEPARATOR) - { - GtkWidget *menu = gtk2_get_widget(POPUP_MENU); - (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu, result); - } - else if (widget_type == POPUP_MENU) - { - GtkWidget *menu_bar = gtk2_get_widget(MENU_BAR); - GtkWidget *root_menu = (*fp_gtk_menu_item_new)(); - (*fp_gtk_menu_item_set_submenu)((GtkMenuItem*)root_menu, result); - (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu_bar, root_menu); - } - else if (widget_type == COMBO_BOX_ARROW_BUTTON || - widget_type == COMBO_BOX_TEXT_FIELD) - { - /* - * We add a regular GtkButton/GtkEntry to a GtkComboBoxEntry - * in order to trick engines into thinking it's a real combobox - * arrow button/text field. - */ - GtkWidget *combo = (*fp_gtk_combo_box_entry_new)(); - - if (new_combo && widget_type == COMBO_BOX_ARROW_BUTTON) { - (*fp_gtk_widget_set_parent)(result, combo); - ((GtkBin*)combo)->child = result; - } else { - (*fp_gtk_container_add)((GtkContainer *)combo, result); - } - (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, combo); - } - else if (widget_type != TOOL_TIP && - widget_type != INTERNAL_FRAME && - widget_type != OPTION_PANE) - { - (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, result); - } - (*fp_gtk_widget_realize)(result); - } - return result; -} - -void gtk2_paint_arrow(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkArrowType arrow_type, gboolean fill) -{ - static int w, h; - static GtkRequisition size; - - if (widget_type == COMBO_BOX_ARROW_BUTTON || widget_type == TABLE) - gtk2_widget = gtk2_get_arrow(arrow_type, shadow_type); - else - gtk2_widget = gtk2_get_widget(widget_type); - - switch (widget_type) - { - case SPINNER_ARROW_BUTTON: - x = 1; - y = ((arrow_type == GTK_ARROW_UP) ? 2 : 0); - height -= 2; - width -= 3; - - w = width / 2; - w -= w % 2 - 1; - h = (w + 1) / 2; - break; - - case HSCROLL_BAR_BUTTON_LEFT: - case HSCROLL_BAR_BUTTON_RIGHT: - case VSCROLL_BAR_BUTTON_UP: - case VSCROLL_BAR_BUTTON_DOWN: - w = width / 2; - h = height / 2; - break; - - case COMBO_BOX_ARROW_BUTTON: - case TABLE: - x = 1; - (*fp_gtk_widget_size_request)(gtk2_widget, &size); - w = size.width - ((GtkMisc*)gtk2_widget)->xpad * 2; - h = size.height - ((GtkMisc*)gtk2_widget)->ypad * 2; - w = h = MIN(MIN(w, h), MIN(width,height)) * 0.7; - break; - - default: - w = width; - h = height; - break; - } - x += (width - w) / 2; - y += (height - h) / 2; - - (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, arrow_type, fill, - x, y, w, h); - (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, arrow_type, fill, - x, y, w, h); -} - -static void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir) -{ - gtk2_widget = gtk2_get_widget(widget_type); - - /* - * The clearlooks engine sometimes looks at the widget's state field - * instead of just the state_type variable that we pass in, so to account - * for those cases we set the widget's state field accordingly. The - * flags field is similarly important for things like focus/default state. - */ - gtk2_widget->state = state_type; - - if (widget_type == HSLIDER_TRACK) { - /* - * For horizontal JSliders with right-to-left orientation, we need - * to set the "inverted" flag to match the native GTK behavior where - * the foreground highlight is on the right side of the slider thumb. - * This is needed especially for the ubuntulooks engine, which looks - * exclusively at the "inverted" flag to determine on which side of - * the thumb to paint the highlight... - */ - ((GtkRange*)gtk2_widget)->inverted = (dir == GTK_TEXT_DIR_RTL); - - /* - * Note however that other engines like clearlooks will look at both - * the "inverted" field and the text direction to determine how - * the foreground highlight is painted: - * !inverted && ltr --> paint highlight on left side - * !inverted && rtl --> paint highlight on right side - * inverted && ltr --> paint highlight on right side - * inverted && rtl --> paint highlight on left side - * So the only way to reliably get the desired results for horizontal - * JSlider (i.e., highlight on left side for LTR ComponentOrientation - * and highlight on right side for RTL ComponentOrientation) is to - * always override text direction as LTR, and then set the "inverted" - * flag accordingly (as we have done above). - */ - dir = GTK_TEXT_DIR_LTR; - } - - /* - * Some engines (e.g. clearlooks) will paint the shadow of certain - * widgets (e.g. COMBO_BOX_ARROW_BUTTON) differently depending on the - * the text direction. - */ - gtk2_set_direction(gtk2_widget, dir); - - switch (widget_type) { - case BUTTON: - if (synth_state & DEFAULT) { - ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_DEFAULT; - } else { - ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_DEFAULT; - } - break; - case TOGGLE_BUTTON: - init_toggle_widget(widget_type, synth_state); - break; - case HSCROLL_BAR_BUTTON_LEFT: - /* - * The clearlooks engine will draw a "left" button when: - * x == w->allocation.x - * - * The ubuntulooks engine will draw a "left" button when: - * [x,y,width,height] - * intersects - * [w->alloc.x,w->alloc.y,width,height] - * - * The values that are set below should ensure that a "left" - * button is rendered for both of these (and other) engines. - */ - gtk2_widget->allocation.x = x; - gtk2_widget->allocation.y = y; - gtk2_widget->allocation.width = width; - gtk2_widget->allocation.height = height; - break; - case HSCROLL_BAR_BUTTON_RIGHT: - /* - * The clearlooks engine will draw a "right" button when: - * x + width == w->allocation.x + w->allocation.width - * - * The ubuntulooks engine will draw a "right" button when: - * [x,y,width,height] - * does not intersect - * [w->alloc.x,w->alloc.y,width,height] - * but does intersect - * [w->alloc.x+width,w->alloc.y,width,height] - * - * The values that are set below should ensure that a "right" - * button is rendered for both of these (and other) engines. - */ - gtk2_widget->allocation.x = x+width; - gtk2_widget->allocation.y = 0; - gtk2_widget->allocation.width = 0; - gtk2_widget->allocation.height = height; - break; - case VSCROLL_BAR_BUTTON_UP: - /* - * The clearlooks engine will draw an "up" button when: - * y == w->allocation.y - * - * The ubuntulooks engine will draw an "up" button when: - * [x,y,width,height] - * intersects - * [w->alloc.x,w->alloc.y,width,height] - * - * The values that are set below should ensure that an "up" - * button is rendered for both of these (and other) engines. - */ - gtk2_widget->allocation.x = x; - gtk2_widget->allocation.y = y; - gtk2_widget->allocation.width = width; - gtk2_widget->allocation.height = height; - break; - case VSCROLL_BAR_BUTTON_DOWN: - /* - * The clearlooks engine will draw a "down" button when: - * y + height == w->allocation.y + w->allocation.height - * - * The ubuntulooks engine will draw a "down" button when: - * [x,y,width,height] - * does not intersect - * [w->alloc.x,w->alloc.y,width,height] - * but does intersect - * [w->alloc.x,w->alloc.y+height,width,height] - * - * The values that are set below should ensure that a "down" - * button is rendered for both of these (and other) engines. - */ - gtk2_widget->allocation.x = x; - gtk2_widget->allocation.y = y+height; - gtk2_widget->allocation.width = width; - gtk2_widget->allocation.height = 0; - break; - default: - break; - } - - (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, x, y, width, height); - (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, x, y, width, height); - - /* - * Reset the text direction to the default value so that we don't - * accidentally affect other operations and widgets. - */ - gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR); -} - -void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkPositionType gap_side, gint gap_x, gint gap_width) -{ - /* Clearlooks needs a real clip area to paint the gap properly */ - GdkRectangle area = { x, y, width, height }; - - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, &area, gtk2_widget, detail, - x, y, width, height, gap_side, gap_x, gap_width); - (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, &area, gtk2_widget, detail, - x, y, width, height, gap_side, gap_x, gap_width); -} - -static void gtk2_paint_check(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - GtkStateType state_type = get_gtk_state_type(widget_type, synth_state); - GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state); - - gtk2_widget = gtk2_get_widget(widget_type); - init_toggle_widget(widget_type, synth_state); - - (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); - (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); -} - -static void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); - (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); -} - -static void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height, - GtkExpanderStyle expander_style) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_white_pixmap, - state_type, NULL, gtk2_widget, detail, - x + width / 2, y + height / 2, expander_style); - (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_black_pixmap, - state_type, NULL, gtk2_widget, detail, - x + width / 2, y + height / 2, expander_style); -} - -static void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkPositionType gap_side) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_white_pixmap, - state_type, shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, gap_side); - (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_black_pixmap, - state_type, shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, gap_side); -} - -static void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, gboolean has_focus) -{ - gtk2_widget = gtk2_get_widget(widget_type); - - if (has_focus) - ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS; - else - ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS; - - (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_white_pixmap, - state_type, shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); - (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_black_pixmap, - state_type, shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); -} - -static void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type, - const char *detail, gint x, gint y, gint width, gint height) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_white_pixmap, state_type, - NULL, gtk2_widget, detail, x, y, width, height); - (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_black_pixmap, state_type, - NULL, gtk2_widget, detail, x, y, width, height); -} - -static void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, orientation); - (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, orientation); -} - -static void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_white_pixmap, state_type, - NULL, gtk2_widget, detail, x, x + width, y); - (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_black_pixmap, state_type, - NULL, gtk2_widget, detail, x, x + width, y); -} - -static void gtk2_paint_option(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - GtkStateType state_type = get_gtk_state_type(widget_type, synth_state); - GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state); - - gtk2_widget = gtk2_get_widget(widget_type); - init_toggle_widget(widget_type, synth_state); - - (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); - (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height); -} - -static void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir) -{ - gtk2_widget = gtk2_get_widget(widget_type); - - /* - * The clearlooks engine sometimes looks at the widget's state field - * instead of just the state_type variable that we pass in, so to account - * for those cases we set the widget's state field accordingly. The - * flags field is similarly important for things like focus state. - */ - gtk2_widget->state = state_type; - - /* - * Some engines (e.g. clearlooks) will paint the shadow of certain - * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the - * the text direction. - */ - gtk2_set_direction(gtk2_widget, dir); - - switch (widget_type) { - case COMBO_BOX_TEXT_FIELD: - case FORMATTED_TEXT_FIELD: - case PASSWORD_FIELD: - case SPINNER_TEXT_FIELD: - case TEXT_FIELD: - if (synth_state & FOCUSED) { - ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS; - } else { - ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS; - } - break; - default: - break; - } - - (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, x, y, width, height); - (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, x, y, width, height); - - /* - * Reset the text direction to the default value so that we don't - * accidentally affect other operations and widgets. - */ - gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR); -} - -static void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation, - gboolean has_focus) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_white_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, orientation); - (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_black_pixmap, state_type, - shadow_type, NULL, gtk2_widget, detail, - x, y, width, height, orientation); -} - -static void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_white_pixmap, state_type, - NULL, gtk2_widget, detail, y, y + height, x); - (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_black_pixmap, state_type, - NULL, gtk2_widget, detail, y, y + height, x); -} - -static void gtk_paint_background(WidgetType widget_type, GtkStateType state_type, - gint x, gint y, gint width, gint height) -{ - gtk2_widget = gtk2_get_widget(widget_type); - (*fp_gtk_style_apply_default_background)(gtk2_widget->style, - gtk2_white_pixmap, TRUE, state_type, NULL, x, y, width, height); - (*fp_gtk_style_apply_default_background)(gtk2_widget->style, - gtk2_black_pixmap, TRUE, state_type, NULL, x, y, width, height); -} - -static GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id, - GtkIconSize size, GtkTextDirection direction, const char *detail) -{ - init_containers(); - gtk2_widget = gtk2_get_widget((widget_type < 0) ? IMAGE : widget_type); - gtk2_widget->state = GTK_STATE_NORMAL; - (*fp_gtk_widget_set_direction)(gtk2_widget, direction); - return (*fp_gtk_widget_render_icon)(gtk2_widget, stock_id, size, detail); -} - -static jboolean gtk2_get_pixbuf_data(JNIEnv *env, GdkPixbuf* pixbuf, - jmethodID icon_upcall_method, jobject this) { - if (!pixbuf) { - return JNI_FALSE; - } - guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf); - if (pixbuf_data) { - 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); - - 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); - (*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); - return JNI_TRUE; - } - return JNI_FALSE; -} - -static jboolean gtk2_get_file_icon_data(JNIEnv *env, const char *filename, - GError **error, jmethodID icon_upcall_method, jobject this) { - GdkPixbuf* pixbuf = fp_gdk_pixbuf_new_from_file(filename, error); - return gtk2_get_pixbuf_data(env, pixbuf, icon_upcall_method, this); -} - -static jboolean gtk2_get_icon_data(JNIEnv *env, gint widget_type, - const gchar *stock_id, GtkIconSize size, - GtkTextDirection direction, const char *detail, - jmethodID icon_upcall_method, jobject this) { - GdkPixbuf* pixbuf = gtk2_get_stock_icon(widget_type, stock_id, size, - direction, detail); - return gtk2_get_pixbuf_data(env, pixbuf, icon_upcall_method, this); -} - -/*************************************************/ -static gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk2_widget = gtk2_get_widget(widget_type); - GtkStyle* style = gtk2_widget->style; - return style->xthickness; -} - -static gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk2_widget = gtk2_get_widget(widget_type); - GtkStyle* style = gtk2_widget->style; - return style->ythickness; -} - -/*************************************************/ -static guint8 recode_color(guint16 channel) -{ - return (guint8)(channel>>8); -} - -static gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type, - GtkStateType state_type, ColorType color_type) -{ - gint result = 0; - GdkColor *color = NULL; - - init_containers(); - - gtk2_widget = gtk2_get_widget(widget_type); - GtkStyle* style = gtk2_widget->style; - - switch (color_type) - { - case FOREGROUND: - color = &(style->fg[state_type]); - break; - case BACKGROUND: - color = &(style->bg[state_type]); - break; - case TEXT_FOREGROUND: - color = &(style->text[state_type]); - break; - case TEXT_BACKGROUND: - color = &(style->base[state_type]); - break; - case LIGHT: - color = &(style->light[state_type]); - break; - case DARK: - color = &(style->dark[state_type]); - break; - case MID: - color = &(style->mid[state_type]); - break; - case FOCUS: - case BLACK: - color = &(style->black); - break; - case WHITE: - color = &(style->white); - break; - } - - if (color) - result = recode_color(color->red) << 16 | - recode_color(color->green) << 8 | - recode_color(color->blue); - - return result; -} - -/*************************************************/ -static jobject create_Boolean(JNIEnv *env, jboolean boolean_value); -static jobject create_Integer(JNIEnv *env, jint int_value); -static jobject create_Long(JNIEnv *env, jlong long_value); -static jobject create_Float(JNIEnv *env, jfloat float_value); -static jobject create_Double(JNIEnv *env, jdouble double_value); -static jobject create_Character(JNIEnv *env, jchar char_value); -static jobject create_Insets(JNIEnv *env, GtkBorder *border); - -static jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type, - const char* key) -{ - init_containers(); - - gtk2_widget = gtk2_get_widget(widget_type); - - GValue value; - value.g_type = 0; - - GParamSpec* param = (*fp_gtk_widget_class_find_style_property)( - ((GTypeInstance*)gtk2_widget)->g_class, key); - if( param ) - { - (*fp_g_value_init)( &value, param->value_type ); - (*fp_gtk_widget_style_get_property)(gtk2_widget, key, &value); - - if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN )) - { - gboolean val = (*fp_g_value_get_boolean)(&value); - return create_Boolean(env, (jboolean)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR )) - { - gchar val = (*fp_g_value_get_char)(&value); - return create_Character(env, (jchar)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UCHAR )) - { - guchar val = (*fp_g_value_get_uchar)(&value); - return create_Character(env, (jchar)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT )) - { - gint val = (*fp_g_value_get_int)(&value); - return create_Integer(env, (jint)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT )) - { - guint val = (*fp_g_value_get_uint)(&value); - return create_Integer(env, (jint)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_LONG )) - { - glong val = (*fp_g_value_get_long)(&value); - return create_Long(env, (jlong)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ULONG )) - { - gulong val = (*fp_g_value_get_ulong)(&value); - return create_Long(env, (jlong)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT64 )) - { - gint64 val = (*fp_g_value_get_int64)(&value); - return create_Long(env, (jlong)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT64 )) - { - guint64 val = (*fp_g_value_get_uint64)(&value); - return create_Long(env, (jlong)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLOAT )) - { - gfloat val = (*fp_g_value_get_float)(&value); - return create_Float(env, (jfloat)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_DOUBLE )) - { - gdouble val = (*fp_g_value_get_double)(&value); - return create_Double(env, (jdouble)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ENUM )) - { - gint val = (*fp_g_value_get_enum)(&value); - return create_Integer(env, (jint)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLAGS )) - { - guint val = (*fp_g_value_get_flags)(&value); - return create_Integer(env, (jint)val); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_STRING )) - { - const gchar* val = (*fp_g_value_get_string)(&value); - - /* We suppose that all values come in C locale and - * utf-8 representation of a string is the same as - * the string itself. If this isn't so we should - * use g_convert. - */ - return (*env)->NewStringUTF(env, val); - } - else if( (*fp_g_type_is_a)( param->value_type, GTK_TYPE_BORDER )) - { - GtkBorder *border = (GtkBorder*)(*fp_g_value_get_boxed)(&value); - return border ? create_Insets(env, border) : NULL; - } - - /* TODO: Other types are not supported yet.*/ -/* else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_PARAM )) - { - GParamSpec* val = (*fp_g_value_get_param)(&value); - printf( "Param: %p\n", val ); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED )) - { - gpointer* val = (*fp_g_value_get_boxed)(&value); - printf( "Boxed: %p\n", val ); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER )) - { - gpointer* val = (*fp_g_value_get_pointer)(&value); - printf( "Pointer: %p\n", val ); - } - else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT )) - { - GObject* val = (GObject*)(*fp_g_value_get_object)(&value); - printf( "Object: %p\n", val ); - }*/ - } - - return NULL; -} - -static void gtk2_set_range_value(WidgetType widget_type, jdouble value, - jdouble min, jdouble max, jdouble visible) -{ - GtkAdjustment *adj; - - gtk2_widget = gtk2_get_widget(widget_type); - - adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk2_widget); - adj->value = (gdouble)value; - adj->lower = (gdouble)min; - adj->upper = (gdouble)max; - adj->page_size = (gdouble)visible; -} - -/*************************************************/ -static jobject create_Object(JNIEnv *env, jmethodID *cid, - const char* class_name, - const char* signature, - jvalue* value) -{ - jclass class; - jobject result; - - class = (*env)->FindClass(env, class_name); - if( class == NULL ) - return NULL; /* can't find/load the class, exception thrown */ - - if( *cid == NULL) - { - *cid = (*env)->GetMethodID(env, class, "", signature); - if( *cid == NULL ) - { - (*env)->DeleteLocalRef(env, class); - return NULL; /* can't find/get the method, exception thrown */ - } - } - - result = (*env)->NewObjectA(env, class, *cid, value); - - (*env)->DeleteLocalRef(env, class); - return result; -} - -jobject create_Boolean(JNIEnv *env, jboolean boolean_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.z = boolean_value; - - return create_Object(env, &cid, "java/lang/Boolean", "(Z)V", &value); -} - -jobject create_Integer(JNIEnv *env, jint int_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.i = int_value; - - return create_Object(env, &cid, "java/lang/Integer", "(I)V", &value); -} - -jobject create_Long(JNIEnv *env, jlong long_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.j = long_value; - - return create_Object(env, &cid, "java/lang/Long", "(J)V", &value); -} - -jobject create_Float(JNIEnv *env, jfloat float_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.f = float_value; - - return create_Object(env, &cid, "java/lang/Float", "(F)V", &value); -} - -jobject create_Double(JNIEnv *env, jdouble double_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.d = double_value; - - return create_Object(env, &cid, "java/lang/Double", "(D)V", &value); -} - -jobject create_Character(JNIEnv *env, jchar char_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.c = char_value; - - return create_Object(env, &cid, "java/lang/Character", "(C)V", &value); -} - - -jobject create_Insets(JNIEnv *env, GtkBorder *border) -{ - static jmethodID cid = NULL; - jvalue values[4]; - - values[0].i = border->top; - values[1].i = border->left; - values[2].i = border->bottom; - values[3].i = border->right; - - return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values); -} - -/*********************************************/ -static jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk2_widget = gtk2_get_widget(widget_type); - jstring result = NULL; - GtkStyle* style = gtk2_widget->style; - - if (style && style->font_desc) - { - gchar* val = (*fp_pango_font_description_to_string)(style->font_desc); - result = (*env)->NewStringUTF(env, val); - (*fp_g_free)( val ); - } - - return result; -} - -/***********************************************/ -static jobject get_string_property(JNIEnv *env, GtkSettings* settings, const gchar* key) -{ - jobject result = NULL; - gchar* strval = NULL; - - (*fp_g_object_get)(settings, key, &strval, NULL); - result = (*env)->NewStringUTF(env, strval); - (*fp_g_free)(strval); - - return result; -} - -static jobject get_integer_property(JNIEnv *env, GtkSettings* settings, const gchar* key) -{ - gint intval = NULL; - (*fp_g_object_get)(settings, key, &intval, NULL); - return create_Integer(env, intval); -} - -static jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, const gchar* key) -{ - gint intval = NULL; - (*fp_g_object_get)(settings, key, &intval, NULL); - return create_Boolean(env, intval); -} - -static jobject gtk2_get_setting(JNIEnv *env, Setting property) -{ - GtkSettings* settings = (*fp_gtk_settings_get_default)(); - - switch (property) - { - case GTK_FONT_NAME: - return get_string_property(env, settings, "gtk-font-name"); - case GTK_ICON_SIZES: - return get_string_property(env, settings, "gtk-icon-sizes"); - case GTK_CURSOR_BLINK: - return get_boolean_property(env, settings, "gtk-cursor-blink"); - case GTK_CURSOR_BLINK_TIME: - return get_integer_property(env, settings, "gtk-cursor-blink-time"); - } - - return NULL; -} - -static gboolean gtk2_get_drawable_data(JNIEnv *env, jintArray pixelArray, jint x, - jint y, jint width, jint height, jint jwidth, int dx, int dy, jint scale) { - GdkPixbuf *pixbuf; - jint *ary; - - GdkWindow *root = (*fp_gdk_get_default_root_window)(); - - pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL, x, y, - 0, 0, width, height); - if (pixbuf && scale != 1) { - GdkPixbuf *scaledPixbuf; - x /= scale; - y /= scale; - width /= scale; - height /= scale; - dx /= scale; - dy /= scale; - scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height, - GDK_INTERP_BILINEAR); - (*fp_g_object_unref)(pixbuf); - pixbuf = scaledPixbuf; - } - - if (pixbuf) { - int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf); - int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf); - - if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width - && (*fp_gdk_pixbuf_get_height)(pixbuf) == height - && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8 - && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB - && nchan >= 3 - ) { - guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf); - - ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - if (ary) { - jint _x, _y; - int index; - for (_y = 0; _y < height; _y++) { - for (_x = 0; _x < width; _x++) { - p = pix + _y * stride + _x * nchan; - - index = (_y + dy) * jwidth + (_x + dx); - ary[index] = 0xff000000 - | (p[0] << 16) - | (p[1] << 8) - | (p[2]); - - } - } - (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); - } - } - (*fp_g_object_unref)(pixbuf); - } - return JNI_FALSE; -} - -static GdkWindow* gtk2_get_window(void *widget) { - return ((GtkWidget*)widget)->window; -} - -void gtk2_init(GtkApi* gtk) { - gtk->version = GTK_2; - - gtk->show_uri_load = >k2_show_uri_load; - gtk->unload = >k2_unload; - gtk->flush_event_loop = &flush_gtk_event_loop; - gtk->gtk_check_version = fp_gtk_check_version; - gtk->get_setting = >k2_get_setting; - - gtk->paint_arrow = >k2_paint_arrow; - gtk->paint_box = >k2_paint_box; - gtk->paint_box_gap = >k2_paint_box_gap; - gtk->paint_expander = >k2_paint_expander; - gtk->paint_extension = >k2_paint_extension; - gtk->paint_flat_box = >k2_paint_flat_box; - gtk->paint_focus = >k2_paint_focus; - gtk->paint_handle = >k2_paint_handle; - gtk->paint_hline = >k2_paint_hline; - gtk->paint_vline = >k2_paint_vline; - gtk->paint_option = >k2_paint_option; - gtk->paint_shadow = >k2_paint_shadow; - gtk->paint_slider = >k2_paint_slider; - gtk->paint_background = >k_paint_background; - gtk->paint_check = >k2_paint_check; - gtk->set_range_value = >k2_set_range_value; - - gtk->init_painting = >k2_init_painting; - gtk->copy_image = >k2_copy_image; - - gtk->get_xthickness = >k2_get_xthickness; - gtk->get_ythickness = >k2_get_ythickness; - gtk->get_color_for_state = >k2_get_color_for_state; - gtk->get_class_value = >k2_get_class_value; - - gtk->get_pango_font_name = >k2_get_pango_font_name; - gtk->get_icon_data = >k2_get_icon_data; - gtk->get_file_icon_data = >k2_get_file_icon_data; - gtk->gdk_threads_enter = fp_gdk_threads_enter; - gtk->gdk_threads_leave = fp_gdk_threads_leave; - gtk->gtk_show_uri = fp_gtk_show_uri; - gtk->get_drawable_data = >k2_get_drawable_data; - gtk->g_free = fp_g_free; - - gtk->gtk_file_chooser_get_filename = fp_gtk_file_chooser_get_filename; - gtk->gtk_widget_hide = fp_gtk_widget_hide; - gtk->gtk_main_quit = fp_gtk_main_quit; - gtk->gtk_file_chooser_dialog_new = fp_gtk_file_chooser_dialog_new; - gtk->gtk_file_chooser_set_current_folder = - fp_gtk_file_chooser_set_current_folder; - gtk->gtk_file_chooser_set_filename = fp_gtk_file_chooser_set_filename; - gtk->gtk_file_chooser_set_current_name = - fp_gtk_file_chooser_set_current_name; - gtk->gtk_file_filter_add_custom = fp_gtk_file_filter_add_custom; - gtk->gtk_file_chooser_set_filter = fp_gtk_file_chooser_set_filter; - gtk->gtk_file_chooser_get_type = fp_gtk_file_chooser_get_type; - gtk->gtk_file_filter_new = fp_gtk_file_filter_new; - gtk->gtk_file_chooser_set_do_overwrite_confirmation = - fp_gtk_file_chooser_set_do_overwrite_confirmation; - gtk->gtk_file_chooser_set_select_multiple = - fp_gtk_file_chooser_set_select_multiple; - gtk->gtk_file_chooser_get_current_folder = - fp_gtk_file_chooser_get_current_folder; - gtk->gtk_file_chooser_get_filenames = fp_gtk_file_chooser_get_filenames; - gtk->gtk_g_slist_length = fp_gtk_g_slist_length; - gtk->g_signal_connect_data = fp_g_signal_connect_data; - gtk->gtk_widget_show = fp_gtk_widget_show; - gtk->gtk_main = fp_gtk_main; - gtk->gtk_main_level = fp_gtk_main_level; - gtk->g_path_get_dirname = fp_g_path_get_dirname; - gtk->gdk_x11_drawable_get_xid = fp_gdk_x11_drawable_get_xid; - gtk->gtk_widget_destroy = fp_gtk_widget_destroy; - gtk->gtk_window_present = fp_gtk_window_present; - gtk->gtk_window_move = fp_gtk_window_move; - gtk->gtk_window_resize = fp_gtk_window_resize; - gtk->get_window = >k2_get_window; - - gtk->g_object_unref = fp_g_object_unref; - gtk->g_list_append = fp_g_list_append; - gtk->g_list_free = fp_g_list_free; - gtk->g_list_free_full = fp_g_list_free_full; -} diff --git a/app/src/main/jni/awt_xawt/awt/gtk2_interface.h b/app/src/main/jni/awt_xawt/awt/gtk2_interface.h deleted file mode 100644 index 18e534968..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk2_interface.h +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#ifndef _GTK2_INTERFACE_H -#define _GTK2_INTERFACE_H - -#include -#include -#include -#include "gtk_interface.h" - -#define GTK_HAS_FOCUS (1 << 12) -#define GTK_HAS_DEFAULT (1 << 14) - -typedef enum -{ - GTK_WINDOW_TOPLEVEL, - GTK_WINDOW_POPUP -} GtkWindowType; - -typedef enum -{ - G_PARAM_READABLE = 1 << 0, - G_PARAM_WRITABLE = 1 << 1, - G_PARAM_CONSTRUCT = 1 << 2, - G_PARAM_CONSTRUCT_ONLY = 1 << 3, - G_PARAM_LAX_VALIDATION = 1 << 4, - G_PARAM_PRIVATE = 1 << 5 -} GParamFlags; - -/* We define all structure pointers to be void* */ -typedef void GMainContext; -typedef void GVfs; - -typedef void GdkColormap; -typedef void GdkDrawable; -typedef void GdkGC; -typedef void GdkPixbuf; -typedef void GdkPixmap; - -typedef void GtkFixed; -typedef void GtkMenuItem; -typedef void GtkMenuShell; -typedef void GtkWidgetClass; -typedef void PangoFontDescription; -typedef void GtkSettings; - -/* Some real structures */ -typedef struct -{ - guint32 pixel; - guint16 red; - guint16 green; - guint16 blue; -} GdkColor; - -typedef struct { - gint fd; - gushort events; - gushort revents; -} GPollFD; - -typedef struct { - gint x; - gint y; - gint width; - gint height; -} GdkRectangle; - -typedef struct { - gint x; - gint y; - gint width; - gint height; -} GtkAllocation; - -typedef struct { - gint width; - gint height; -} GtkRequisition; - -typedef struct { - GtkWidgetClass *g_class; -} GTypeInstance; - -typedef struct { - gint left; - gint right; - gint top; - gint bottom; -} GtkBorder; - -/****************************************************** - * FIXME: it is more safe to include gtk headers for - * the precise type definition of GType and other - * structures. This is a place where getting rid of gtk - * headers may be dangerous. - ******************************************************/ - -typedef struct -{ - GType g_type; - - union { - gint v_int; - guint v_uint; - glong v_long; - gulong v_ulong; - gint64 v_int64; - guint64 v_uint64; - gfloat v_float; - gdouble v_double; - gpointer v_pointer; - } data[2]; -} GValue; - -typedef struct -{ - GTypeInstance g_type_instance; - - gchar *name; - GParamFlags flags; - GType value_type; - GType owner_type; -} GParamSpec; - -typedef struct { - GTypeInstance g_type_instance; - guint ref_count; - void *qdata; -} GObject; - -typedef struct { - GObject parent_instance; - guint32 flags; -} GtkObject; - -typedef struct -{ - GObject parent_instance; - - GdkColor fg[5]; - GdkColor bg[5]; - GdkColor light[5]; - GdkColor dark[5]; - GdkColor mid[5]; - GdkColor text[5]; - GdkColor base[5]; - GdkColor text_aa[5]; /* Halfway between text/base */ - - GdkColor black; - GdkColor white; - PangoFontDescription *font_desc; - - gint xthickness; - gint ythickness; - - GdkGC *fg_gc[5]; - GdkGC *bg_gc[5]; - GdkGC *light_gc[5]; - GdkGC *dark_gc[5]; - GdkGC *mid_gc[5]; - GdkGC *text_gc[5]; - GdkGC *base_gc[5]; - GdkGC *text_aa_gc[5]; - GdkGC *black_gc; - GdkGC *white_gc; - - GdkPixmap *bg_pixmap[5]; -} GtkStyle; - -typedef struct _GtkWidget GtkWidget; -struct _GtkWidget -{ - GtkObject object; - guint16 private_flags; - guint8 state; - guint8 saved_state; - gchar *name; - GtkStyle *style; - GtkRequisition requisition; - GtkAllocation allocation; - GdkWindow *window; - GtkWidget *parent; -}; - -typedef struct -{ - GtkWidget widget; - - gfloat xalign; - gfloat yalign; - - guint16 xpad; - guint16 ypad; -} GtkMisc; - -typedef struct { - GtkWidget widget; - GtkWidget *focus_child; - guint border_width : 16; - guint need_resize : 1; - guint resize_mode : 2; - guint reallocate_redraws : 1; - guint has_focus_chain : 1; -} GtkContainer; - -typedef struct { - GtkContainer container; - GtkWidget *child; -} GtkBin; - -typedef struct { - GtkBin bin; - GdkWindow *event_window; - gchar *label_text; - guint activate_timeout; - guint constructed : 1; - guint in_button : 1; - guint button_down : 1; - guint relief : 2; - guint use_underline : 1; - guint use_stock : 1; - guint depressed : 1; - guint depress_on_activate : 1; - guint focus_on_click : 1; -} GtkButton; - -typedef struct { - GtkButton button; - guint active : 1; - guint draw_indicator : 1; - guint inconsistent : 1; -} GtkToggleButton; - -typedef struct _GtkAdjustment GtkAdjustment; -struct _GtkAdjustment -{ - GtkObject parent_instance; - - gdouble lower; - gdouble upper; - gdouble value; - gdouble step_increment; - gdouble page_increment; - gdouble page_size; -}; - -typedef enum -{ - GTK_UPDATE_CONTINUOUS, - GTK_UPDATE_DISCONTINUOUS, - GTK_UPDATE_DELAYED -} GtkUpdateType; - -typedef struct _GtkRange GtkRange; -struct _GtkRange -{ - GtkWidget widget; - GtkAdjustment *adjustment; - GtkUpdateType update_policy; - guint inverted : 1; - /*< protected >*/ - guint flippable : 1; - guint has_stepper_a : 1; - guint has_stepper_b : 1; - guint has_stepper_c : 1; - guint has_stepper_d : 1; - guint need_recalc : 1; - guint slider_size_fixed : 1; - gint min_slider_size; - GtkOrientation orientation; - GdkRectangle range_rect; - gint slider_start, slider_end; - gint round_digits; - /*< private >*/ - guint trough_click_forward : 1; - guint update_pending : 1; - /*GtkRangeLayout * */ void *layout; - /*GtkRangeStepTimer * */ void* timer; - gint slide_initial_slider_position; - gint slide_initial_coordinate; - guint update_timeout_id; - GdkWindow *event_window; -}; - -typedef struct _GtkProgressBar GtkProgressBar; - -typedef enum -{ - GTK_PROGRESS_CONTINUOUS, - GTK_PROGRESS_DISCRETE -} GtkProgressBarStyle; - -typedef enum -{ - GTK_PROGRESS_LEFT_TO_RIGHT, - GTK_PROGRESS_RIGHT_TO_LEFT, - GTK_PROGRESS_BOTTOM_TO_TOP, - GTK_PROGRESS_TOP_TO_BOTTOM -} GtkProgressBarOrientation; - -typedef struct _GtkProgress GtkProgress; - -struct _GtkProgress -{ - GtkWidget widget; - GtkAdjustment *adjustment; - GdkPixmap *offscreen_pixmap; - gchar *format; - gfloat x_align; - gfloat y_align; - guint show_text : 1; - guint activity_mode : 1; - guint use_text_format : 1; -}; - -struct _GtkProgressBar -{ - GtkProgress progress; - GtkProgressBarStyle bar_style; - GtkProgressBarOrientation orientation; - guint blocks; - gint in_block; - gint activity_pos; - guint activity_step; - guint activity_blocks; - gdouble pulse_fraction; - guint activity_dir : 1; - guint ellipsize : 3; -}; - -/** - * Returns : - * NULL if the GLib library is compatible with the given version, or a string - * describing the version mismatch. - * Please note that the glib_check_version() is available since 2.6, - * so you should use GLIB_CHECK_VERSION macro instead. - */ -static gchar* (*fp_glib_check_version)(guint required_major, guint required_minor, - guint required_micro); - -/** - * Returns : - * TRUE if the GLib library is compatible with the given version - */ -#define GLIB_CHECK_VERSION(major, minor, micro) \ - (fp_glib_check_version && fp_glib_check_version(major, minor, micro) == NULL) - -/** - * Returns : - * NULL if the GTK+ library is compatible with the given version, or a string - * describing the version mismatch. - */ -static gchar* (*fp_gtk_check_version)(guint required_major, guint required_minor, - guint required_micro); - -static void gtk2_init(GtkApi* gtk); - -static void (*fp_g_free)(gpointer mem); -static void (*fp_g_object_unref)(gpointer object); -static GdkWindow *(*fp_gdk_get_default_root_window) (void); - -static int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf); -static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf); -static gboolean (*fp_gdk_pixbuf_get_has_alpha)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_height)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_n_channels)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_rowstride)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_width)(const GdkPixbuf *pixbuf); -static GdkPixbuf *(*fp_gdk_pixbuf_new_from_file)(const char *filename, GError **error); -static GdkColorspace (*fp_gdk_pixbuf_get_colorspace)(const GdkPixbuf *pixbuf); - -static GdkPixbuf *(*fp_gdk_pixbuf_get_from_drawable)(GdkPixbuf *dest, - GdkDrawable *src, GdkColormap *cmap, int src_x, int src_y, - int dest_x, int dest_y, int width, int height); -static GdkPixbuf *(*fp_gdk_pixbuf_scale_simple)(GdkPixbuf *src, - int dest_width, int dest_heigh, GdkInterpType interp_type); - - -static void (*fp_gtk_widget_destroy)(void *widget); -static void (*fp_gtk_window_present)(GtkWindow *window); -static void (*fp_gtk_window_move)(GtkWindow *window, gint x, gint y); -static void (*fp_gtk_window_resize)(GtkWindow *window, gint width, gint height); - -/** - * Function Pointers for GtkFileChooser - */ -static gchar* (*fp_gtk_file_chooser_get_filename)(GtkFileChooser *chooser); -static void (*fp_gtk_widget_hide)(void *widget); -static void (*fp_gtk_main_quit)(void); -static void* (*fp_gtk_file_chooser_dialog_new)(const gchar *title, - GtkWindow *parent, GtkFileChooserAction action, - const gchar *first_button_text, ...); -static gboolean (*fp_gtk_file_chooser_set_current_folder)(GtkFileChooser *chooser, - const gchar *filename); -static gboolean (*fp_gtk_file_chooser_set_filename)(GtkFileChooser *chooser, - const char *filename); -static void (*fp_gtk_file_chooser_set_current_name)(GtkFileChooser *chooser, - const gchar *name); -static void (*fp_gtk_file_filter_add_custom)(GtkFileFilter *filter, - GtkFileFilterFlags needed, GtkFileFilterFunc func, gpointer data, - GDestroyNotify notify); -static void (*fp_gtk_file_chooser_set_filter)(GtkFileChooser *chooser, - GtkFileFilter *filter); -static GType (*fp_gtk_file_chooser_get_type)(void); -static GtkFileFilter* (*fp_gtk_file_filter_new)(void); -static void (*fp_gtk_file_chooser_set_do_overwrite_confirmation)( - GtkFileChooser *chooser, gboolean do_overwrite_confirmation); -static void (*fp_gtk_file_chooser_set_select_multiple)( - GtkFileChooser *chooser, gboolean select_multiple); -static gchar* (*fp_gtk_file_chooser_get_current_folder)(GtkFileChooser *chooser); -static GSList* (*fp_gtk_file_chooser_get_filenames)(GtkFileChooser *chooser); -static guint (*fp_gtk_g_slist_length)(GSList *list); -static gulong (*fp_g_signal_connect_data)(gpointer instance, - const gchar *detailed_signal, GCallback c_handler, gpointer data, - GClosureNotify destroy_data, GConnectFlags connect_flags); -static void (*fp_gtk_widget_show)(void *widget); -static void (*fp_gtk_main)(void); -static guint (*fp_gtk_main_level)(void); -static gchar* (*fp_g_path_get_dirname) (const gchar *file_name); -static XID (*fp_gdk_x11_drawable_get_xid) (GdkWindow *drawable); - -static GList* (*fp_g_list_append) (GList *list, gpointer data); -static void (*fp_g_list_free) (GList *list); -static void (*fp_g_list_free_full) (GList *list, GDestroyNotify free_func); - -static gboolean (*fp_gtk_show_uri)(GdkScreen *screen, const gchar *uri, - guint32 timestamp, GError **error); - -#endif /* !_GTK2_INTERFACE_H */ diff --git a/app/src/main/jni/awt_xawt/awt/gtk3_interface.c b/app/src/main/jni/awt_xawt/awt/gtk3_interface.c deleted file mode 100644 index af4cf9eba..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk3_interface.c +++ /dev/null @@ -1,2914 +0,0 @@ -/* - * Copyright (c) 2005, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include -#include -#include -#include "gtk3_interface.h" -#include "java_awt_Transparency.h" -#include "sizecalc.h" -#include -#include -#include "awt.h" - -static void *gtk3_libhandle = NULL; -static void *gthread_libhandle = NULL; - -static jmp_buf j; - -/* Widgets */ -static GtkWidget *gtk3_widget = NULL; -static GtkWidget *gtk3_window = NULL; -static GtkFixed *gtk3_fixed = NULL; -static GtkStyleProvider *gtk3_css = NULL; - -/* Paint system */ -static cairo_surface_t *surface = NULL; -static cairo_t *cr = NULL; - -static const char ENV_PREFIX[] = "GTK_MODULES="; - -static GtkWidget *gtk3_widgets[_GTK_WIDGET_TYPE_SIZE]; - -static void throw_exception(JNIEnv *env, const char* name, const char* message) -{ - jclass class = (*env)->FindClass(env, name); - - if (class != NULL) - (*env)->ThrowNew(env, class, message); - - (*env)->DeleteLocalRef(env, class); -} - -static void gtk3_add_state(GtkWidget *widget, GtkStateType state) { - GtkStateType old_state = fp_gtk_widget_get_state(widget); - fp_gtk_widget_set_state(widget, old_state | state); -} - -static void gtk3_remove_state(GtkWidget *widget, GtkStateType state) { - GtkStateType old_state = fp_gtk_widget_get_state(widget); - fp_gtk_widget_set_state(widget, old_state & ~state); -} - -/* This is a workaround for the bug: - * http://sourceware.org/bugzilla/show_bug.cgi?id=1814 - * (dlsym/dlopen clears dlerror state) - * This bug is specific to Linux, but there is no harm in - * applying this workaround on Solaris as well. - */ -static void* dl_symbol(const char* name) -{ - void* result = dlsym(gtk3_libhandle, name); - if (!result) - longjmp(j, NO_SYMBOL_EXCEPTION); - - return result; -} - -static void* dl_symbol_gthread(const char* name) -{ - void* result = dlsym(gthread_libhandle, name); - if (!result) - longjmp(j, NO_SYMBOL_EXCEPTION); - - return result; -} - -gboolean gtk3_check(const char* lib_name, gboolean load) -{ - if (gtk3_libhandle != NULL) { - /* We've already successfully opened the GTK libs, so return true. */ - return TRUE; - } else { -#ifdef RTLD_NOLOAD - void *lib = dlopen(lib_name, RTLD_LAZY | RTLD_NOLOAD); - if (!load || lib != NULL) { - return lib != NULL; - } -#else -#ifdef _AIX - /* On AIX we could implement this with the help of loadquery(L_GETINFO, ..) */ - /* (see reload_table() in hotspot/src/os/aix/vm/loadlib_aix.cpp) but it is */ - /* probably not worth it because most AIX servers don't have GTK libs anyway */ -#endif -#endif - return dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL) != NULL; - } -} - -#define ADD_SUPPORTED_ACTION(actionStr) \ -do { \ - jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, \ - "Ljava/awt/Desktop$Action;"); \ - if (!(*env)->ExceptionCheck(env)) { \ - jobject action = (*env)->GetStaticObjectField(env, cls_action, \ - fld_action); \ - (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, \ - action); \ - } else { \ - (*env)->ExceptionClear(env); \ - } \ -} while(0); - - -static void update_supported_actions(JNIEnv *env) { - GVfs * (*fp_g_vfs_get_default) (void); - const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs); - const gchar * const * schemes = NULL; - - jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action"); - CHECK_NULL(cls_action); - jclass cls_xDesktopPeer = (*env)-> - FindClass(env, "sun/awt/X11/XDesktopPeer"); - CHECK_NULL(cls_xDesktopPeer); - jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, - cls_xDesktopPeer, "supportedActions", "Ljava/util/List;"); - CHECK_NULL(fld_supportedActions); - jobject supportedActions = (*env)->GetStaticObjectField(env, - cls_xDesktopPeer, fld_supportedActions); - - jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList"); - CHECK_NULL(cls_arrayList); - jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", - "(Ljava/lang/Object;)Z"); - CHECK_NULL(mid_arrayListAdd); - jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, - "clear", "()V"); - CHECK_NULL(mid_arrayListClear); - - (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear); - - ADD_SUPPORTED_ACTION("OPEN"); - - /** - * gtk_show_uri() documentation says: - * - * > you need to install gvfs to get support for uri schemes such as http:// - * > or ftp://, as only local files are handled by GIO itself. - * - * So OPEN action was safely added here. - * However, it looks like Solaris 11 have gvfs support only for 32-bit - * applications only by default. - */ - - fp_g_vfs_get_default = dl_symbol("g_vfs_get_default"); - fp_g_vfs_get_supported_uri_schemes = - dl_symbol("g_vfs_get_supported_uri_schemes"); - dlerror(); - - if (fp_g_vfs_get_default && fp_g_vfs_get_supported_uri_schemes) { - GVfs * vfs = fp_g_vfs_get_default(); - schemes = vfs ? fp_g_vfs_get_supported_uri_schemes(vfs) : NULL; - if (schemes) { - int i = 0; - while (schemes[i]) { - if (strcmp(schemes[i], "http") == 0) { - ADD_SUPPORTED_ACTION("BROWSE"); - ADD_SUPPORTED_ACTION("MAIL"); - break; - } - i++; - } - } - } else { -#ifdef DEBUG - fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n"); -#endif /* DEBUG */ - } - -} -/** - * Functions for awt_Desktop.c - */ -static gboolean gtk3_show_uri_load(JNIEnv *env) { - gboolean success = FALSE; - dlerror(); - fp_gtk_show_uri = dl_symbol("gtk_show_uri"); - const char *dlsym_error = dlerror(); - if (dlsym_error) { -#ifdef DEBUG - fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error); -#endif /* DEBUG */ - } else if (fp_gtk_show_uri == NULL) { -#ifdef DEBUG - fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n"); -#endif /* DEBUG */ - } else { - gtk->gtk_show_uri = fp_gtk_show_uri; - update_supported_actions(env); - success = TRUE; - } - return success; -} - -/** - * Functions for sun_awt_X11_GtkFileDialogPeer.c - */ -static void gtk3_file_chooser_load() -{ - fp_gtk_file_chooser_get_filename = dl_symbol( - "gtk_file_chooser_get_filename"); - fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new"); - fp_gtk_file_chooser_set_current_folder = dl_symbol( - "gtk_file_chooser_set_current_folder"); - fp_gtk_file_chooser_set_filename = dl_symbol( - "gtk_file_chooser_set_filename"); - fp_gtk_file_chooser_set_current_name = dl_symbol( - "gtk_file_chooser_set_current_name"); - fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom"); - fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter"); - fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type"); - fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new"); - fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol( - "gtk_file_chooser_set_do_overwrite_confirmation"); - fp_gtk_file_chooser_set_select_multiple = dl_symbol( - "gtk_file_chooser_set_select_multiple"); - fp_gtk_file_chooser_get_current_folder = dl_symbol( - "gtk_file_chooser_get_current_folder"); - fp_gtk_file_chooser_get_filenames = dl_symbol( - "gtk_file_chooser_get_filenames"); - fp_gtk_g_slist_length = dl_symbol("g_slist_length"); - fp_gdk_x11_drawable_get_xid = dl_symbol("gdk_x11_window_get_xid"); -} - -static void empty() {} - -static gboolean gtk3_version_3_10 = TRUE; -static gboolean gtk3_version_3_14 = FALSE; - -GtkApi* gtk3_load(JNIEnv *env, const char* lib_name) -{ - gboolean result; - int i; - int (*handler)(); - int (*io_handler)(); - char *gtk_modules_env; - gtk3_libhandle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); - if (gtk3_libhandle == NULL) { - return FALSE; - } - - gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL); - if (gthread_libhandle == NULL) { - gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL); - if (gthread_libhandle == NULL) - return FALSE; - } - - if (setjmp(j) == 0) - { - fp_gtk_check_version = dl_symbol("gtk_check_version"); - - /* GLib */ - fp_glib_check_version = dlsym(gtk3_libhandle, "glib_check_version"); - if (!fp_glib_check_version) { - dlerror(); - } - fp_g_free = dl_symbol("g_free"); - fp_g_object_unref = dl_symbol("g_object_unref"); - - fp_g_main_context_iteration = - dl_symbol("g_main_context_iteration"); - - fp_g_value_init = dl_symbol("g_value_init"); - fp_g_type_is_a = dl_symbol("g_type_is_a"); - fp_g_value_get_boolean = dl_symbol("g_value_get_boolean"); - fp_g_value_get_char = dl_symbol("g_value_get_char"); - fp_g_value_get_uchar = dl_symbol("g_value_get_uchar"); - fp_g_value_get_int = dl_symbol("g_value_get_int"); - fp_g_value_get_uint = dl_symbol("g_value_get_uint"); - fp_g_value_get_long = dl_symbol("g_value_get_long"); - fp_g_value_get_ulong = dl_symbol("g_value_get_ulong"); - fp_g_value_get_int64 = dl_symbol("g_value_get_int64"); - fp_g_value_get_uint64 = dl_symbol("g_value_get_uint64"); - fp_g_value_get_float = dl_symbol("g_value_get_float"); - fp_g_value_get_double = dl_symbol("g_value_get_double"); - fp_g_value_get_string = dl_symbol("g_value_get_string"); - fp_g_value_get_enum = dl_symbol("g_value_get_enum"); - fp_g_value_get_flags = dl_symbol("g_value_get_flags"); - fp_g_value_get_param = dl_symbol("g_value_get_param"); - fp_g_value_get_boxed = dl_symbol("g_value_get_boxed"); - fp_g_value_get_pointer = dl_symbol("g_value_get_pointer"); - - fp_g_object_get = dl_symbol("g_object_get"); - fp_g_object_set = dl_symbol("g_object_set"); - - fp_g_str_has_prefix = dl_symbol("g_str_has_prefix"); - fp_g_strsplit = dl_symbol("g_strsplit"); - fp_g_strfreev = dl_symbol("g_strfreev"); - - /* GDK */ - fp_gdk_get_default_root_window = - dl_symbol("gdk_get_default_root_window"); - - /* Pixbuf */ - fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new"); - fp_gdk_pixbuf_new_from_file = - dl_symbol("gdk_pixbuf_new_from_file"); - fp_gdk_pixbuf_get_from_drawable = - dl_symbol("gdk_pixbuf_get_from_window"); - fp_gdk_pixbuf_get_width = dl_symbol("gdk_pixbuf_get_width"); - fp_gdk_pixbuf_get_height = dl_symbol("gdk_pixbuf_get_height"); - fp_gdk_pixbuf_get_pixels = dl_symbol("gdk_pixbuf_get_pixels"); - fp_gdk_pixbuf_get_rowstride = - dl_symbol("gdk_pixbuf_get_rowstride"); - fp_gdk_pixbuf_get_has_alpha = - dl_symbol("gdk_pixbuf_get_has_alpha"); - fp_gdk_pixbuf_get_bits_per_sample = - dl_symbol("gdk_pixbuf_get_bits_per_sample"); - fp_gdk_pixbuf_get_n_channels = - dl_symbol("gdk_pixbuf_get_n_channels"); - fp_gdk_pixbuf_get_colorspace = - dl_symbol("gdk_pixbuf_get_colorspace"); - - fp_cairo_image_surface_create = dl_symbol("cairo_image_surface_create"); - fp_cairo_surface_destroy = dl_symbol("cairo_surface_destroy"); - fp_cairo_create = dl_symbol("cairo_create"); - fp_cairo_destroy = dl_symbol("cairo_destroy"); - fp_cairo_fill = dl_symbol("cairo_fill"); - fp_cairo_rectangle = dl_symbol("cairo_rectangle"); - fp_cairo_set_source_rgb = dl_symbol("cairo_set_source_rgb"); - fp_cairo_set_source_rgba = dl_symbol("cairo_set_source_rgba"); - fp_cairo_surface_flush = dl_symbol("cairo_surface_flush"); - fp_cairo_paint = dl_symbol("cairo_paint"); - fp_cairo_clip = dl_symbol("cairo_clip"); - fp_cairo_image_surface_get_data = - dl_symbol("cairo_image_surface_get_data"); - fp_cairo_image_surface_get_stride = - dl_symbol("cairo_image_surface_get_stride"); - - fp_gdk_pixbuf_get_from_surface = - dl_symbol("gdk_pixbuf_get_from_surface"); - - fp_gtk_widget_get_state = dl_symbol("gtk_widget_get_state"); - fp_gtk_widget_set_state = dl_symbol("gtk_widget_set_state"); - - fp_gtk_widget_is_focus = dl_symbol("gtk_widget_is_focus"); - fp_gtk_widget_set_allocation = dl_symbol("gtk_widget_set_allocation"); - fp_gtk_widget_get_parent = dl_symbol("gtk_widget_get_parent"); - fp_gtk_widget_get_window = dl_symbol("gtk_widget_get_window"); - - fp_gtk_widget_get_style_context = - dl_symbol("gtk_widget_get_style_context"); - fp_gtk_style_context_get_color = - dl_symbol("gtk_style_context_get_color"); - fp_gtk_style_context_get_background_color = - dl_symbol("gtk_style_context_get_background_color"); - fp_gtk_widget_get_state_flags = dl_symbol("gtk_widget_get_state_flags"); - fp_gtk_style_context_set_state = - dl_symbol("gtk_style_context_set_state"); - fp_gtk_style_context_add_class = - dl_symbol("gtk_style_context_add_class"); - fp_gtk_style_context_save = dl_symbol("gtk_style_context_save"); - fp_gtk_style_context_restore = dl_symbol("gtk_style_context_restore"); - fp_gtk_render_check = dl_symbol("gtk_render_check"); - fp_gtk_render_option = dl_symbol("gtk_render_option"); - fp_gtk_render_extension = dl_symbol("gtk_render_extension"); - fp_gtk_render_expander = dl_symbol("gtk_render_expander"); - fp_gtk_render_frame_gap = dl_symbol("gtk_render_frame_gap"); - fp_gtk_render_line = dl_symbol("gtk_render_line"); - fp_gtk_widget_render_icon_pixbuf = - dl_symbol("gtk_widget_render_icon_pixbuf"); - if (fp_gtk_check_version(3, 10, 0)) { - gtk3_version_3_10 = FALSE; - } else { - fp_gdk_window_create_similar_image_surface = - dl_symbol("gdk_window_create_similar_image_surface"); - } - gtk3_version_3_14 = !fp_gtk_check_version(3, 14, 0); - - fp_gdk_window_create_similar_surface = - dl_symbol("gdk_window_create_similar_surface"); - fp_gtk_settings_get_for_screen = - dl_symbol("gtk_settings_get_for_screen"); - fp_gtk_widget_get_screen = dl_symbol("gtk_widget_get_screen"); - fp_gtk_css_provider_get_named = dl_symbol("gtk_css_provider_get_named"); - fp_gtk_style_context_add_provider = - dl_symbol("gtk_style_context_add_provider"); - fp_gtk_render_frame = dl_symbol("gtk_render_frame"); - fp_gtk_render_focus = dl_symbol("gtk_render_focus"); - fp_gtk_render_handle = dl_symbol("gtk_render_handle"); - fp_gtk_render_arrow = dl_symbol("gtk_render_arrow"); - - fp_gtk_style_context_get_property = - dl_symbol("gtk_style_context_get_property"); - fp_gtk_scrolled_window_set_shadow_type = - dl_symbol("gtk_scrolled_window_set_shadow_type"); - fp_gtk_render_slider = dl_symbol("gtk_render_slider"); - fp_gtk_style_context_get_padding = - dl_symbol("gtk_style_context_get_padding"); - fp_gtk_range_set_inverted = dl_symbol("gtk_range_set_inverted"); - fp_gtk_style_context_get_font = dl_symbol("gtk_style_context_get_font"); - fp_gtk_widget_get_allocated_width = - dl_symbol("gtk_widget_get_allocated_width"); - fp_gtk_widget_get_allocated_height = - dl_symbol("gtk_widget_get_allocated_height"); - fp_gtk_icon_theme_get_default = dl_symbol("gtk_icon_theme_get_default"); - fp_gtk_icon_theme_load_icon = dl_symbol("gtk_icon_theme_load_icon"); - - fp_gtk_adjustment_set_lower = dl_symbol("gtk_adjustment_set_lower"); - fp_gtk_adjustment_set_page_increment = - dl_symbol("gtk_adjustment_set_page_increment"); - fp_gtk_adjustment_set_page_size = - dl_symbol("gtk_adjustment_set_page_size"); - fp_gtk_adjustment_set_step_increment = - dl_symbol("gtk_adjustment_set_step_increment"); - fp_gtk_adjustment_set_upper = dl_symbol("gtk_adjustment_set_upper"); - fp_gtk_adjustment_set_value = dl_symbol("gtk_adjustment_set_value"); - - fp_gtk_render_activity = dl_symbol("gtk_render_activity"); - fp_gtk_render_background = dl_symbol("gtk_render_background"); - fp_gtk_style_context_has_class = - dl_symbol("gtk_style_context_has_class"); - - fp_gtk_style_context_set_junction_sides = - dl_symbol("gtk_style_context_set_junction_sides"); - fp_gtk_style_context_add_region = - dl_symbol("gtk_style_context_add_region"); - - fp_gtk_init_check = dl_symbol("gtk_init_check"); - - /* GTK widgets */ - fp_gtk_arrow_new = dl_symbol("gtk_arrow_new"); - fp_gtk_button_new = dl_symbol("gtk_button_new"); - fp_gtk_spin_button_new = dl_symbol("gtk_spin_button_new"); - fp_gtk_check_button_new = dl_symbol("gtk_check_button_new"); - fp_gtk_check_menu_item_new = - dl_symbol("gtk_check_menu_item_new"); - fp_gtk_color_selection_dialog_new = - dl_symbol("gtk_color_selection_dialog_new"); - fp_gtk_entry_new = dl_symbol("gtk_entry_new"); - fp_gtk_fixed_new = dl_symbol("gtk_fixed_new"); - fp_gtk_handle_box_new = dl_symbol("gtk_handle_box_new"); - fp_gtk_image_new = dl_symbol("gtk_image_new"); - fp_gtk_hpaned_new = dl_symbol("gtk_hpaned_new"); - fp_gtk_vpaned_new = dl_symbol("gtk_vpaned_new"); - fp_gtk_scale_new = dl_symbol("gtk_scale_new"); - fp_gtk_hscrollbar_new = dl_symbol("gtk_hscrollbar_new"); - fp_gtk_vscrollbar_new = dl_symbol("gtk_vscrollbar_new"); - fp_gtk_hseparator_new = dl_symbol("gtk_hseparator_new"); - fp_gtk_vseparator_new = dl_symbol("gtk_vseparator_new"); - fp_gtk_label_new = dl_symbol("gtk_label_new"); - fp_gtk_menu_new = dl_symbol("gtk_menu_new"); - fp_gtk_menu_bar_new = dl_symbol("gtk_menu_bar_new"); - fp_gtk_menu_item_new = dl_symbol("gtk_menu_item_new"); - fp_gtk_menu_item_set_submenu = - dl_symbol("gtk_menu_item_set_submenu"); - fp_gtk_notebook_new = dl_symbol("gtk_notebook_new"); - fp_gtk_progress_bar_new = - dl_symbol("gtk_progress_bar_new"); - fp_gtk_progress_bar_set_orientation = - dl_symbol("gtk_orientable_set_orientation"); - fp_gtk_radio_button_new = - dl_symbol("gtk_radio_button_new"); - fp_gtk_radio_menu_item_new = - dl_symbol("gtk_radio_menu_item_new"); - fp_gtk_scrolled_window_new = - dl_symbol("gtk_scrolled_window_new"); - fp_gtk_separator_menu_item_new = - dl_symbol("gtk_separator_menu_item_new"); - fp_gtk_text_view_new = dl_symbol("gtk_text_view_new"); - fp_gtk_toggle_button_new = - dl_symbol("gtk_toggle_button_new"); - fp_gtk_toolbar_new = dl_symbol("gtk_toolbar_new"); - fp_gtk_tree_view_new = dl_symbol("gtk_tree_view_new"); - fp_gtk_viewport_new = dl_symbol("gtk_viewport_new"); - fp_gtk_window_new = dl_symbol("gtk_window_new"); - fp_gtk_window_present = dl_symbol("gtk_window_present"); - fp_gtk_window_move = dl_symbol("gtk_window_move"); - fp_gtk_window_resize = dl_symbol("gtk_window_resize"); - - fp_gtk_dialog_new = dl_symbol("gtk_dialog_new"); - fp_gtk_frame_new = dl_symbol("gtk_frame_new"); - - fp_gtk_adjustment_new = dl_symbol("gtk_adjustment_new"); - fp_gtk_container_add = dl_symbol("gtk_container_add"); - fp_gtk_menu_shell_append = - dl_symbol("gtk_menu_shell_append"); - fp_gtk_widget_realize = dl_symbol("gtk_widget_realize"); - fp_gtk_widget_destroy = dl_symbol("gtk_widget_destroy"); - fp_gtk_widget_render_icon = - dl_symbol("gtk_widget_render_icon"); - fp_gtk_widget_set_name = - dl_symbol("gtk_widget_set_name"); - fp_gtk_widget_set_parent = - dl_symbol("gtk_widget_set_parent"); - fp_gtk_widget_set_direction = - dl_symbol("gtk_widget_set_direction"); - fp_gtk_widget_style_get = - dl_symbol("gtk_widget_style_get"); - fp_gtk_widget_class_install_style_property = - dl_symbol("gtk_widget_class_install_style_property"); - fp_gtk_widget_class_find_style_property = - dl_symbol("gtk_widget_class_find_style_property"); - fp_gtk_widget_style_get_property = - dl_symbol("gtk_widget_style_get_property"); - fp_pango_font_description_to_string = - dl_symbol("pango_font_description_to_string"); - fp_gtk_settings_get_default = - dl_symbol("gtk_settings_get_default"); - fp_gtk_widget_get_settings = - dl_symbol("gtk_widget_get_settings"); - fp_gtk_border_get_type = dl_symbol("gtk_border_get_type"); - fp_gtk_arrow_set = dl_symbol("gtk_arrow_set"); - fp_gtk_widget_size_request = - dl_symbol("gtk_widget_size_request"); - fp_gtk_range_get_adjustment = - dl_symbol("gtk_range_get_adjustment"); - - fp_gtk_widget_hide = dl_symbol("gtk_widget_hide"); - fp_gtk_main_quit = dl_symbol("gtk_main_quit"); - fp_g_signal_connect_data = dl_symbol("g_signal_connect_data"); - fp_gtk_widget_show = dl_symbol("gtk_widget_show"); - fp_gtk_main = dl_symbol("gtk_main"); - - fp_g_path_get_dirname = dl_symbol("g_path_get_dirname"); - - fp_gdk_threads_enter = dl_symbol("gdk_threads_enter"); - fp_gdk_threads_leave = dl_symbol("gdk_threads_leave"); - - /** - * Functions for sun_awt_X11_GtkFileDialogPeer.c - */ - gtk3_file_chooser_load(); - - fp_gtk_combo_box_new = dlsym(gtk3_libhandle, "gtk_combo_box_new"); - fp_gtk_combo_box_entry_new = dlsym(gtk3_libhandle, - "gtk_combo_box_new_with_entry"); - fp_gtk_separator_tool_item_new = dlsym(gtk3_libhandle, - "gtk_separator_tool_item_new"); - - fp_g_list_append = dl_symbol("g_list_append"); - fp_g_list_free = dl_symbol("g_list_free"); - fp_g_list_free_full = dl_symbol("g_list_free_full"); - } - /* Now we have only one kind of exceptions: NO_SYMBOL_EXCEPTION - * Otherwise we can check the return value of setjmp method. - */ - else - { - dlclose(gtk3_libhandle); - gtk3_libhandle = NULL; - - dlclose(gthread_libhandle); - gthread_libhandle = NULL; - - return NULL; - } - - /* - * Strip the AT-SPI GTK_MODULES if present - */ - gtk_modules_env = getenv ("GTK_MODULES"); - if ((gtk_modules_env && strstr(gtk_modules_env, "atk-bridge")) || - (gtk_modules_env && strstr(gtk_modules_env, "gail"))) { - /* careful, strtok modifies its args */ - gchar *tmp_env = strdup(gtk_modules_env); - if (tmp_env) { - /* the new env will be smaller than the old one */ - gchar *s, *new_env = SAFE_SIZE_STRUCT_ALLOC(malloc, - sizeof(ENV_PREFIX), 1, strlen (gtk_modules_env)); - - if (new_env) { - strcpy(new_env, ENV_PREFIX); - - /* strip out 'atk-bridge' and 'gail' */ - size_t PREFIX_LENGTH = strlen(ENV_PREFIX); - gchar *tmp_ptr = NULL; - for (s = strtok_r(tmp_env, ":", &tmp_ptr); s; - s = strtok_r(NULL, ":", &tmp_ptr)) { - if ((!strstr(s, "atk-bridge")) && (!strstr(s, "gail"))) { - if (strlen(new_env) > PREFIX_LENGTH) { - new_env = strcat(new_env, ":"); - } - new_env = strcat(new_env, s); - } - } - if (putenv(new_env) != 0) { - /* no free() on success, putenv() doesn't copy string */ - free(new_env); - } - } - free(tmp_env); - } - } - /* - * GTK should be initialized with gtk_init_check() before use. - * - * gtk_init_check installs its own error handlers. It is critical that - * we preserve error handler set from AWT. Otherwise we'll crash on - * BadMatch errors which we would normally ignore. The IO error handler - * is preserved here, too, just for consistency. - */ - AWT_LOCK(); - handler = XSetErrorHandler(NULL); - io_handler = XSetIOErrorHandler(NULL); - result = (*fp_gtk_init_check)(NULL, NULL); - XSetErrorHandler(handler); - XSetIOErrorHandler(io_handler); - AWT_UNLOCK(); - /* Initialize widget array. */ - for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++) - { - gtk3_widgets[i] = NULL; - } - if (result) { - GtkApi* gtk = (GtkApi*)malloc(sizeof(GtkApi)); - gtk3_init(gtk); - return gtk; - } - return NULL; -} - -static int gtk3_unload() -{ - int i; - char *gtk3_error; - - if (!gtk3_libhandle) - return TRUE; - - /* Release painting objects */ - if (surface != NULL) { - fp_cairo_destroy(cr); - fp_cairo_surface_destroy(surface); - surface = NULL; - } - - if (gtk3_window != NULL) { - /* Destroying toplevel widget will destroy all contained widgets */ - (*fp_gtk_widget_destroy)(gtk3_window); - - /* Unset some static data so they get reinitialized on next load */ - gtk3_window = NULL; - } - - dlerror(); - dlclose(gtk3_libhandle); - dlclose(gthread_libhandle); - if ((gtk3_error = dlerror()) != NULL) - { - return FALSE; - } - return TRUE; -} - -/* Dispatch all pending events from the GTK event loop. - * This is needed to catch theme change and update widgets' style. - */ -static void flush_gtk_event_loop() -{ - while((*fp_g_main_context_iteration)(NULL)); -} - -/* - * Initialize components of containment hierarchy. This creates a GtkFixed - * inside a GtkWindow. All widgets get realized. - */ -static void init_containers() -{ - if (gtk3_window == NULL) - { - gtk3_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - gtk3_fixed = (GtkFixed *)(*fp_gtk_fixed_new)(); - (*fp_gtk_container_add)((GtkContainer*)gtk3_window, - (GtkWidget *)gtk3_fixed); - (*fp_gtk_widget_realize)(gtk3_window); - (*fp_gtk_widget_realize)((GtkWidget *)gtk3_fixed); - - GtkSettings* settings = fp_gtk_settings_get_for_screen( - fp_gtk_widget_get_screen(gtk3_window)); - gchar* strval = NULL; - fp_g_object_get(settings, "gtk-theme-name", &strval, NULL); - gtk3_css = fp_gtk_css_provider_get_named(strval, NULL); - } -} - -/* - * Ensure everything is ready for drawing an element of the specified width - * and height. - * - * We should somehow handle translucent images. GTK can draw to X Drawables - * only, which don't support alpha. When we retrieve the image back from - * the server, translucency information is lost. There're several ways to - * work around this: - * 1) Subclass GdkPixmap and cache translucent objects on client side. This - * requires us to implement parts of X server drawing logic on client side. - * Many X requests can potentially be "translucent"; e.g. XDrawLine with - * fill=tile and a translucent tile is a "translucent" operation, whereas - * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some - * do) intermix transparent and opaque operations which makes caching even - * more problematic. - * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support - * for it (as of version 2.6). Also even in JDS 3 Xorg does not support - * these visuals by default, which makes optimizing for them pointless. - * We can consider doing this at a later point when ARGB visuals become more - * popular. - * 3') GTK has plans to use Cairo as its graphical backend (presumably in - * 2.8), and Cairo supports alpha. With it we could also get rid of the - * unnecessary round trip to server and do all the drawing on client side. - * 4) For now we draw to two different pixmaps and restore alpha channel by - * comparing results. This can be optimized by using subclassed pixmap and -*/ -static void gtk3_init_painting(JNIEnv *env, gint width, gint height) -{ - init_containers(); - - if (cr) { - fp_cairo_destroy(cr); - } - - if (surface != NULL) { - /* free old stuff */ - fp_cairo_surface_destroy(surface); - - } - - if (gtk3_version_3_10) { - surface = fp_gdk_window_create_similar_image_surface( - fp_gtk_widget_get_window(gtk3_window), - CAIRO_FORMAT_ARGB32, width, height, 1); - } else { - surface = fp_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - width, height); - } - - cr = fp_cairo_create(surface); -} - -/* - * Restore image from white and black pixmaps and copy it into destination - * buffer. This method compares two pixbufs taken from white and black - * pixmaps and decodes color and alpha components. Pixbufs are RGB without - * alpha, destination buffer is ABGR. - * - * The return value is the transparency type of the resulting image, either - * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and - * java_awt_Transparency_TRANSLUCENT. - */ -static gint gtk3_copy_image(gint *dst, gint width, gint height) -{ - gint i, j, r, g, b; - guchar *data; - gint stride, padding; - - fp_cairo_surface_flush(surface); - data = (*fp_cairo_image_surface_get_data)(surface); - stride = (*fp_cairo_image_surface_get_stride)(surface); - padding = stride - width * 4; - - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - int r = *data++; - int g = *data++; - int b = *data++; - int a = *data++; - *dst++ = (a << 24 | b << 16 | g << 8 | r); - } - data += padding; - } - return java_awt_Transparency_TRANSLUCENT; -} - -static void gtk3_set_direction(GtkWidget *widget, GtkTextDirection dir) -{ - /* - * Some engines (inexplicably) look at the direction of the widget's - * parent, so we need to set the direction of both the widget and its - * parent. - */ - (*fp_gtk_widget_set_direction)(widget, dir); - GtkWidget* parent = fp_gtk_widget_get_parent(widget); - if (parent != NULL) { - fp_gtk_widget_set_direction(parent, dir); - } -} - -/* GTK state_type filter */ -static GtkStateType get_gtk_state_type(WidgetType widget_type, gint synth_state) -{ - GtkStateType result = GTK_STATE_NORMAL; - - if ((synth_state & DISABLED) != 0) { - result = GTK_STATE_INSENSITIVE; - } else if ((synth_state & PRESSED) != 0) { - result = GTK_STATE_ACTIVE; - } else if ((synth_state & MOUSE_OVER) != 0) { - result = GTK_STATE_PRELIGHT; - } - return result; -} - -static GtkStateFlags get_gtk_state_flags(gint synth_state) -{ - GtkStateFlags flags = 0; - - if ((synth_state & DISABLED) != 0) { - flags |= GTK_STATE_FLAG_INSENSITIVE; - } - if (((synth_state & PRESSED) != 0 || (synth_state & SELECTED) != 0)) { - flags |= GTK_STATE_FLAG_ACTIVE; - } - if ((synth_state & MOUSE_OVER) != 0) { - flags |= GTK_STATE_FLAG_PRELIGHT; - } - if ((synth_state & FOCUSED) != 0) { - flags |= GTK_STATE_FLAG_FOCUSED; - } - return flags; -} - -static GtkStateFlags get_gtk_flags(GtkStateType state_type) { - GtkStateFlags flags = 0; - switch (state_type) - { - case GTK_STATE_PRELIGHT: - flags |= GTK_STATE_FLAG_PRELIGHT; - break; - case GTK_STATE_SELECTED: - flags |= GTK_STATE_FLAG_SELECTED; - break; - case GTK_STATE_INSENSITIVE: - flags |= GTK_STATE_FLAG_INSENSITIVE; - break; - case GTK_STATE_ACTIVE: - flags |= GTK_STATE_FLAG_ACTIVE; - break; - case GTK_STATE_FOCUSED: - flags |= GTK_STATE_FLAG_FOCUSED; - break; - default: - break; - } - return flags; -} - -/* GTK shadow_type filter */ -static GtkShadowType get_gtk_shadow_type(WidgetType widget_type, - gint synth_state) -{ - GtkShadowType result = GTK_SHADOW_OUT; - - if ((synth_state & SELECTED) != 0) { - result = GTK_SHADOW_IN; - } - return result; -} - - -static GtkWidget* gtk3_get_arrow(GtkArrowType arrow_type, - GtkShadowType shadow_type) -{ - GtkWidget *arrow = NULL; - if (NULL == gtk3_widgets[_GTK_ARROW_TYPE]) - { - gtk3_widgets[_GTK_ARROW_TYPE] = (*fp_gtk_arrow_new)(arrow_type, - shadow_type); - (*fp_gtk_container_add)((GtkContainer *)gtk3_fixed, - gtk3_widgets[_GTK_ARROW_TYPE]); - (*fp_gtk_widget_realize)(gtk3_widgets[_GTK_ARROW_TYPE]); - } - arrow = gtk3_widgets[_GTK_ARROW_TYPE]; - - (*fp_gtk_arrow_set)(arrow, arrow_type, shadow_type); - return arrow; -} - -static GtkAdjustment* create_adjustment() -{ - return (GtkAdjustment *) - (*fp_gtk_adjustment_new)(50.0, 0.0, 100.0, 10.0, 20.0, 20.0); -} - -/** - * Returns a pointer to the cached native widget for the specified widget - * type. - */ -static GtkWidget *gtk3_get_widget(WidgetType widget_type) -{ - gboolean init_result = FALSE; - GtkWidget *result = NULL; - switch (widget_type) - { - case BUTTON: - case TABLE_HEADER: - if (init_result = (NULL == gtk3_widgets[_GTK_BUTTON_TYPE])) - { - gtk3_widgets[_GTK_BUTTON_TYPE] = (*fp_gtk_button_new)(); - } - result = gtk3_widgets[_GTK_BUTTON_TYPE]; - break; - case CHECK_BOX: - if (init_result = (NULL == gtk3_widgets[_GTK_CHECK_BUTTON_TYPE])) - { - gtk3_widgets[_GTK_CHECK_BUTTON_TYPE] = - (*fp_gtk_check_button_new)(); - } - result = gtk3_widgets[_GTK_CHECK_BUTTON_TYPE]; - break; - case CHECK_BOX_MENU_ITEM: - if (init_result = (NULL == gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE])) - { - gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE] = - (*fp_gtk_check_menu_item_new)(); - } - result = gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE]; - break; - /************************************************************ - * Creation a dedicated color chooser is dangerous because - * it deadlocks the EDT - ************************************************************/ -/* case COLOR_CHOOSER: - if (init_result = - (NULL == gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE])) - { - gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE] = - (*fp_gtk_color_selection_dialog_new)(NULL); - } - result = gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE]; - break;*/ - case COMBO_BOX: - if (init_result = (NULL == gtk3_widgets[_GTK_COMBO_BOX_TYPE])) - { - gtk3_widgets[_GTK_COMBO_BOX_TYPE] = - (*fp_gtk_combo_box_new)(); - } - result = gtk3_widgets[_GTK_COMBO_BOX_TYPE]; - break; - case COMBO_BOX_ARROW_BUTTON: - if (init_result = - (NULL == gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE])) - { - gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE] = - (*fp_gtk_toggle_button_new)(); - } - result = gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE]; - break; - case COMBO_BOX_TEXT_FIELD: - if (init_result = - (NULL == gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE])) - { - result = gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE] = - (*fp_gtk_entry_new)(); - } - result = gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE]; - break; - case DESKTOP_ICON: - case INTERNAL_FRAME_TITLE_PANE: - case LABEL: - if (init_result = (NULL == gtk3_widgets[_GTK_LABEL_TYPE])) - { - gtk3_widgets[_GTK_LABEL_TYPE] = - (*fp_gtk_label_new)(NULL); - } - result = gtk3_widgets[_GTK_LABEL_TYPE]; - break; - case DESKTOP_PANE: - case PANEL: - case ROOT_PANE: - if (init_result = (NULL == gtk3_widgets[_GTK_CONTAINER_TYPE])) - { - /* There is no constructor for a container type. I've - * chosen GtkFixed container since it has a default - * constructor. - */ - gtk3_widgets[_GTK_CONTAINER_TYPE] = - (*fp_gtk_fixed_new)(); - } - result = gtk3_widgets[_GTK_CONTAINER_TYPE]; - break; - case EDITOR_PANE: - case TEXT_AREA: - case TEXT_PANE: - if (init_result = (NULL == gtk3_widgets[_GTK_TEXT_VIEW_TYPE])) - { - gtk3_widgets[_GTK_TEXT_VIEW_TYPE] = - (*fp_gtk_text_view_new)(); - } - result = gtk3_widgets[_GTK_TEXT_VIEW_TYPE]; - break; - case FORMATTED_TEXT_FIELD: - case PASSWORD_FIELD: - case TEXT_FIELD: - if (init_result = (NULL == gtk3_widgets[_GTK_ENTRY_TYPE])) - { - gtk3_widgets[_GTK_ENTRY_TYPE] = - (*fp_gtk_entry_new)(); - } - result = gtk3_widgets[_GTK_ENTRY_TYPE]; - break; - case HANDLE_BOX: - if (init_result = (NULL == gtk3_widgets[_GTK_HANDLE_BOX_TYPE])) - { - gtk3_widgets[_GTK_HANDLE_BOX_TYPE] = - (*fp_gtk_handle_box_new)(); - } - result = gtk3_widgets[_GTK_HANDLE_BOX_TYPE]; - break; - case HSCROLL_BAR: - case HSCROLL_BAR_BUTTON_LEFT: - case HSCROLL_BAR_BUTTON_RIGHT: - case HSCROLL_BAR_TRACK: - case HSCROLL_BAR_THUMB: - if (init_result = (NULL == gtk3_widgets[_GTK_HSCROLLBAR_TYPE])) - { - gtk3_widgets[_GTK_HSCROLLBAR_TYPE] = - (*fp_gtk_hscrollbar_new)(create_adjustment()); - } - result = gtk3_widgets[_GTK_HSCROLLBAR_TYPE]; - break; - case HSEPARATOR: - if (init_result = (NULL == gtk3_widgets[_GTK_HSEPARATOR_TYPE])) - { - gtk3_widgets[_GTK_HSEPARATOR_TYPE] = - (*fp_gtk_hseparator_new)(); - } - result = gtk3_widgets[_GTK_HSEPARATOR_TYPE]; - break; - case HSLIDER: - case HSLIDER_THUMB: - case HSLIDER_TRACK: - if (init_result = (NULL == gtk3_widgets[_GTK_HSCALE_TYPE])) - { - gtk3_widgets[_GTK_HSCALE_TYPE] = - (*fp_gtk_scale_new)(GTK_ORIENTATION_HORIZONTAL, NULL); - } - result = gtk3_widgets[_GTK_HSCALE_TYPE]; - break; - case HSPLIT_PANE_DIVIDER: - case SPLIT_PANE: - if (init_result = (NULL == gtk3_widgets[_GTK_HPANED_TYPE])) - { - gtk3_widgets[_GTK_HPANED_TYPE] = (*fp_gtk_hpaned_new)(); - } - result = gtk3_widgets[_GTK_HPANED_TYPE]; - break; - case IMAGE: - if (init_result = (NULL == gtk3_widgets[_GTK_IMAGE_TYPE])) - { - gtk3_widgets[_GTK_IMAGE_TYPE] = (*fp_gtk_image_new)(); - } - result = gtk3_widgets[_GTK_IMAGE_TYPE]; - break; - case INTERNAL_FRAME: - if (init_result = (NULL == gtk3_widgets[_GTK_WINDOW_TYPE])) - { - gtk3_widgets[_GTK_WINDOW_TYPE] = - (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - } - result = gtk3_widgets[_GTK_WINDOW_TYPE]; - break; - case TOOL_TIP: - if (init_result = (NULL == gtk3_widgets[_GTK_TOOLTIP_TYPE])) - { - result = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL); - gtk3_widgets[_GTK_TOOLTIP_TYPE] = result; - } - result = gtk3_widgets[_GTK_TOOLTIP_TYPE]; - break; - case LIST: - case TABLE: - case TREE: - case TREE_CELL: - if (init_result = (NULL == gtk3_widgets[_GTK_TREE_VIEW_TYPE])) - { - gtk3_widgets[_GTK_TREE_VIEW_TYPE] = - (*fp_gtk_tree_view_new)(); - } - result = gtk3_widgets[_GTK_TREE_VIEW_TYPE]; - break; - case TITLED_BORDER: - if (init_result = (NULL == gtk3_widgets[_GTK_FRAME_TYPE])) - { - gtk3_widgets[_GTK_FRAME_TYPE] = fp_gtk_frame_new(NULL); - } - result = gtk3_widgets[_GTK_FRAME_TYPE]; - break; - case POPUP_MENU: - if (init_result = (NULL == gtk3_widgets[_GTK_MENU_TYPE])) - { - gtk3_widgets[_GTK_MENU_TYPE] = - (*fp_gtk_menu_new)(); - } - result = gtk3_widgets[_GTK_MENU_TYPE]; - break; - case MENU: - case MENU_ITEM: - case MENU_ITEM_ACCELERATOR: - if (init_result = (NULL == gtk3_widgets[_GTK_MENU_ITEM_TYPE])) - { - gtk3_widgets[_GTK_MENU_ITEM_TYPE] = - (*fp_gtk_menu_item_new)(); - } - result = gtk3_widgets[_GTK_MENU_ITEM_TYPE]; - break; - case MENU_BAR: - if (init_result = (NULL == gtk3_widgets[_GTK_MENU_BAR_TYPE])) - { - gtk3_widgets[_GTK_MENU_BAR_TYPE] = - (*fp_gtk_menu_bar_new)(); - } - result = gtk3_widgets[_GTK_MENU_BAR_TYPE]; - break; - case COLOR_CHOOSER: - case OPTION_PANE: - if (init_result = (NULL == gtk3_widgets[_GTK_DIALOG_TYPE])) - { - gtk3_widgets[_GTK_DIALOG_TYPE] = - (*fp_gtk_dialog_new)(); - } - result = gtk3_widgets[_GTK_DIALOG_TYPE]; - break; - case POPUP_MENU_SEPARATOR: - if (init_result = - (NULL == gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE])) - { - gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE] = - (*fp_gtk_separator_menu_item_new)(); - } - result = gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE]; - break; - case HPROGRESS_BAR: - if (init_result = (NULL == gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE])) - { - gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE] = - (*fp_gtk_progress_bar_new)(); - } - result = gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE]; - break; - case VPROGRESS_BAR: - if (init_result = (NULL == gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE])) - { - gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE] = - (*fp_gtk_progress_bar_new)(); - /* - * Vertical JProgressBars always go bottom-to-top, - * regardless of the ComponentOrientation. - */ - (*fp_gtk_progress_bar_set_orientation)( - (GtkProgressBar *)gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE], - GTK_PROGRESS_BOTTOM_TO_TOP); - } - result = gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE]; - break; - case RADIO_BUTTON: - if (init_result = (NULL == gtk3_widgets[_GTK_RADIO_BUTTON_TYPE])) - { - gtk3_widgets[_GTK_RADIO_BUTTON_TYPE] = - (*fp_gtk_radio_button_new)(NULL); - } - result = gtk3_widgets[_GTK_RADIO_BUTTON_TYPE]; - break; - case RADIO_BUTTON_MENU_ITEM: - if (init_result = - (NULL == gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE])) - { - gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE] = - (*fp_gtk_radio_menu_item_new)(NULL); - } - result = gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE]; - break; - case SCROLL_PANE: - if (init_result = - (NULL == gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE])) - { - gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE] = - (*fp_gtk_scrolled_window_new)(NULL, NULL); - } - result = gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE]; - break; - case SPINNER: - case SPINNER_ARROW_BUTTON: - case SPINNER_TEXT_FIELD: - if (init_result = (NULL == gtk3_widgets[_GTK_SPIN_BUTTON_TYPE])) - { - result = gtk3_widgets[_GTK_SPIN_BUTTON_TYPE] = - (*fp_gtk_spin_button_new)(NULL, 0, 0); - } - result = gtk3_widgets[_GTK_SPIN_BUTTON_TYPE]; - break; - case TABBED_PANE: - case TABBED_PANE_TAB_AREA: - case TABBED_PANE_CONTENT: - case TABBED_PANE_TAB: - if (init_result = (NULL == gtk3_widgets[_GTK_NOTEBOOK_TYPE])) - { - gtk3_widgets[_GTK_NOTEBOOK_TYPE] = - (*fp_gtk_notebook_new)(NULL); - } - result = gtk3_widgets[_GTK_NOTEBOOK_TYPE]; - break; - case TOGGLE_BUTTON: - if (init_result = (NULL == gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE])) - { - gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE] = - (*fp_gtk_toggle_button_new)(NULL); - } - result = gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE]; - break; - case TOOL_BAR: - case TOOL_BAR_DRAG_WINDOW: - if (init_result = (NULL == gtk3_widgets[_GTK_TOOLBAR_TYPE])) - { - gtk3_widgets[_GTK_TOOLBAR_TYPE] = - (*fp_gtk_toolbar_new)(NULL); - } - result = gtk3_widgets[_GTK_TOOLBAR_TYPE]; - break; - case TOOL_BAR_SEPARATOR: - if (init_result = - (NULL == gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE])) - { - gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE] = - (*fp_gtk_separator_tool_item_new)(); - } - result = gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE]; - break; - case VIEWPORT: - if (init_result = (NULL == gtk3_widgets[_GTK_VIEWPORT_TYPE])) - { - GtkAdjustment *adjustment = create_adjustment(); - gtk3_widgets[_GTK_VIEWPORT_TYPE] = - (*fp_gtk_viewport_new)(adjustment, adjustment); - } - result = gtk3_widgets[_GTK_VIEWPORT_TYPE]; - break; - case VSCROLL_BAR: - case VSCROLL_BAR_BUTTON_UP: - case VSCROLL_BAR_BUTTON_DOWN: - case VSCROLL_BAR_TRACK: - case VSCROLL_BAR_THUMB: - if (init_result = (NULL == gtk3_widgets[_GTK_VSCROLLBAR_TYPE])) - { - gtk3_widgets[_GTK_VSCROLLBAR_TYPE] = - (*fp_gtk_vscrollbar_new)(create_adjustment()); - } - result = gtk3_widgets[_GTK_VSCROLLBAR_TYPE]; - break; - case VSEPARATOR: - if (init_result = (NULL == gtk3_widgets[_GTK_VSEPARATOR_TYPE])) - { - gtk3_widgets[_GTK_VSEPARATOR_TYPE] = - (*fp_gtk_vseparator_new)(); - } - result = gtk3_widgets[_GTK_VSEPARATOR_TYPE]; - break; - case VSLIDER: - case VSLIDER_THUMB: - case VSLIDER_TRACK: - if (init_result = (NULL == gtk3_widgets[_GTK_VSCALE_TYPE])) - { - gtk3_widgets[_GTK_VSCALE_TYPE] = - (*fp_gtk_scale_new)(GTK_ORIENTATION_VERTICAL, NULL); - } - result = gtk3_widgets[_GTK_VSCALE_TYPE]; - /* - * Vertical JSliders start at the bottom, while vertical - * GtkVScale widgets start at the top (by default), so to fix - * this we set the "inverted" flag to get the Swing behavior. - */ - fp_gtk_range_set_inverted((GtkRange*)result, TRUE); - break; - case VSPLIT_PANE_DIVIDER: - if (init_result = (NULL == gtk3_widgets[_GTK_VPANED_TYPE])) - { - gtk3_widgets[_GTK_VPANED_TYPE] = (*fp_gtk_vpaned_new)(); - } - result = gtk3_widgets[_GTK_VPANED_TYPE]; - break; - default: - result = NULL; - break; - } - - if (result != NULL && init_result) - { - if (widget_type == RADIO_BUTTON_MENU_ITEM || - widget_type == CHECK_BOX_MENU_ITEM || - widget_type == MENU_ITEM || - widget_type == MENU || - widget_type == POPUP_MENU_SEPARATOR) - { - GtkWidget *menu = gtk3_get_widget(POPUP_MENU); - (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu, result); - } - else if (widget_type == POPUP_MENU) - { - GtkWidget *menu_bar = gtk3_get_widget(MENU_BAR); - GtkWidget *root_menu = (*fp_gtk_menu_item_new)(); - (*fp_gtk_menu_item_set_submenu)((GtkMenuItem*)root_menu, result); - (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu_bar, root_menu); - } - else if (widget_type == COMBO_BOX_TEXT_FIELD ) - { - GtkWidget* combo = gtk3_get_widget(COMBO_BOX); - - /* - * We add a regular GtkButton/GtkEntry to a GtkComboBoxEntry - * in order to trick engines into thinking it's a real combobox - * arrow button/text field. - */ - - fp_gtk_container_add ((GtkContainer*)(combo), result); - GtkStyleContext* context = fp_gtk_widget_get_style_context (combo); - fp_gtk_style_context_add_class (context, "combobox-entry"); - context = fp_gtk_widget_get_style_context (result); - fp_gtk_style_context_add_class (context, "combobox"); - fp_gtk_style_context_add_class (context, "entry"); - } - else if (widget_type == COMBO_BOX_ARROW_BUTTON ) - { - GtkWidget* combo = gtk3_get_widget(COMBO_BOX); - fp_gtk_widget_set_parent(result, combo); - } - else if (widget_type != TOOL_TIP && - widget_type != INTERNAL_FRAME && - widget_type != OPTION_PANE) - { - (*fp_gtk_container_add)((GtkContainer *)gtk3_fixed, result); - } - (*fp_gtk_widget_realize)(result); - } - return result; -} - -static void gtk3_paint_arrow(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkArrowType arrow_type, gboolean fill) -{ - gdouble xx, yy, a = G_PI; - int s = width; - gtk3_widget = gtk3_get_arrow(arrow_type, shadow_type); - - switch (widget_type) - { - case SPINNER_ARROW_BUTTON: - s = (int)(0.4 * width + 0.5) + 1; - if (arrow_type == GTK_ARROW_UP) { - a = 0; - } else if (arrow_type == GTK_ARROW_DOWN) { - a = G_PI; - } - break; - - case HSCROLL_BAR_BUTTON_LEFT: - s = (int)(0.5 * MIN(height, width * 2) + 0.5) + 1; - a = 3 * G_PI / 2; - break; - - case HSCROLL_BAR_BUTTON_RIGHT: - s = (int)(0.5 * MIN(height, width * 2) + 0.5) + 1; - a = G_PI / 2; - break; - - case VSCROLL_BAR_BUTTON_UP: - s = (int)(0.5 * MIN(height * 2, width) + 0.5) + 1; - a = 0; - break; - - case VSCROLL_BAR_BUTTON_DOWN: - s = (int)(0.5 * MIN(height * 2, width) + 0.5) + 1; - a = G_PI; - break; - - case COMBO_BOX_ARROW_BUTTON: - s = (int)(0.3 * height + 0.5) + 1; - a = G_PI; - break; - - case TABLE: - s = (int)(0.8 * height + 0.5) + 1; - if (arrow_type == GTK_ARROW_UP) { - a = G_PI; - } else if (arrow_type == GTK_ARROW_DOWN) { - a = 0; - } - break; - - case MENU_ITEM: - if (arrow_type == GTK_ARROW_UP) { - a = G_PI; - } else if (arrow_type == GTK_ARROW_DOWN) { - a = 0; - } else if (arrow_type == GTK_ARROW_RIGHT) { - a = G_PI / 2; - } else if (arrow_type == GTK_ARROW_LEFT) { - a = 3 * G_PI / 2; - } - break; - - default: - if (arrow_type == GTK_ARROW_UP) { - a = G_PI; - } else if (arrow_type == GTK_ARROW_DOWN) { - a = 0; - } else if (arrow_type == GTK_ARROW_RIGHT) { - a = G_PI / 2; - } else if (arrow_type == GTK_ARROW_LEFT) { - a = 3 * G_PI / 2; - } - break; - } - - if (s < width && s < height) { - xx = x + (0.5 * (width - s) + 0.5); - yy = y + (0.5 * (height - s) + 0.5); - } else { - xx = x; - yy = y; - } - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - fp_gtk_style_context_save (context); - - - if (detail != NULL) { - transform_detail_string(detail, context); - } - - GtkStateFlags flags = get_gtk_flags(state_type); - - fp_gtk_style_context_set_state (context, flags); - - (*fp_gtk_render_arrow)(context, cr, a, xx, yy, s); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_box(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - if (widget_type == HSLIDER_TRACK) { - /* - * For horizontal JSliders with right-to-left orientation, we need - * to set the "inverted" flag to match the native GTK behavior where - * the foreground highlight is on the right side of the slider thumb. - * This is needed especially for the ubuntulooks engine, which looks - * exclusively at the "inverted" flag to determine on which side of - * the thumb to paint the highlight... - */ - fp_gtk_range_set_inverted((GtkRange*)gtk3_widget, dir == - GTK_TEXT_DIR_RTL); - - /* - * Note however that other engines like clearlooks will look at both - * the "inverted" field and the text direction to determine how - * the foreground highlight is painted: - * !inverted && ltr --> paint highlight on left side - * !inverted && rtl --> paint highlight on right side - * inverted && ltr --> paint highlight on right side - * inverted && rtl --> paint highlight on left side - * So the only way to reliably get the desired results for horizontal - * JSlider (i.e., highlight on left side for LTR ComponentOrientation - * and highlight on right side for RTL ComponentOrientation) is to - * always override text direction as LTR, and then set the "inverted" - * flag accordingly (as we have done above). - */ - dir = GTK_TEXT_DIR_LTR; - } - - /* - * Some engines (e.g. clearlooks) will paint the shadow of certain - * widgets (e.g. COMBO_BOX_ARROW_BUTTON) differently depending on the - * the text direction. - */ - gtk3_set_direction(gtk3_widget, dir); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - fp_gtk_style_context_save (context); - - transform_detail_string(detail, context); - - GtkStateFlags flags = get_gtk_flags(state_type); - - if (shadow_type == GTK_SHADOW_IN && widget_type != COMBO_BOX_ARROW_BUTTON) { - flags |= GTK_STATE_FLAG_ACTIVE; - } - - if (synth_state & MOUSE_OVER) { - flags |= GTK_STATE_FLAG_PRELIGHT; - } - - if (synth_state & FOCUSED) { - flags |= GTK_STATE_FLAG_FOCUSED; - } - - if (synth_state & DEFAULT) { - fp_gtk_style_context_add_class (context, "default"); - } - - fp_gtk_style_context_set_state (context, flags); - - if (fp_gtk_style_context_has_class(context, "progressbar")) { - fp_gtk_render_activity (context, cr, x, y, width, height); - } else { - fp_gtk_render_background (context, cr, x, y, width, height); - if (shadow_type != GTK_SHADOW_NONE) { - fp_gtk_render_frame(context, cr, x, y, width, height); - } - } - - fp_gtk_style_context_restore (context); - /* - * Reset the text direction to the default value so that we don't - * accidentally affect other operations and widgets. - */ - gtk3_set_direction(gtk3_widget, GTK_TEXT_DIR_LTR); -} - -static void gtk3_paint_box_gap(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkPositionType gap_side, gint gap_x, gint gap_width) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_flags(state_type); - fp_gtk_style_context_set_state(context, flags); - - if (detail != 0) { - transform_detail_string(detail, context); - } - fp_gtk_render_background(context, cr, x, y, width, height); - - if (shadow_type != GTK_SHADOW_NONE) { - fp_gtk_render_frame_gap(context, cr, x, y, width, height, gap_side, - (gdouble)gap_x, (gdouble)gap_x + gap_width); - } - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_check(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_state_flags(synth_state); - if (gtk3_version_3_14 && (synth_state & SELECTED)) { - flags = GTK_STATE_FLAG_CHECKED; - } - fp_gtk_style_context_set_state(context, flags); - - fp_gtk_style_context_add_class (context, "check"); - - fp_gtk_render_check (context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); -} - - -static void gtk3_paint_expander(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height, - GtkExpanderStyle expander_style) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_flags(state_type); - if (expander_style == GTK_EXPANDER_EXPANDED) { - flags |= GTK_STATE_FLAG_ACTIVE; - } - - fp_gtk_style_context_set_state(context, flags); - - if (detail != 0) { - transform_detail_string(detail, context); - } - - fp_gtk_render_expander (context, cr, x + 2, y + 2, width - 4, height - 4); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_extension(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkPositionType gap_side) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = GTK_STATE_FLAG_NORMAL; - - if (state_type == 0) { - flags = GTK_STATE_FLAG_ACTIVE; - } - - fp_gtk_style_context_set_state(context, flags); - - if (detail != 0) { - transform_detail_string(detail, context); - } - switch(gap_side) { - case GTK_POS_LEFT: - fp_gtk_style_context_add_class(context, "right"); - break; - case GTK_POS_RIGHT: - fp_gtk_style_context_add_class(context, "left"); - break; - case GTK_POS_TOP: - fp_gtk_style_context_add_class(context, "bottom"); - break; - case GTK_POS_BOTTOM: - fp_gtk_style_context_add_class(context, "top"); - break; - default: - break; - } - - fp_gtk_render_extension(context, cr, x, y, width, height, gap_side); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_flat_box(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, gboolean has_focus) -{ - if (state_type == GTK_STATE_PRELIGHT && - (widget_type == CHECK_BOX || widget_type == RADIO_BUTTON)) { - return; - } - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - if (detail != 0) { - transform_detail_string(detail, context); - } - - GtkStateFlags flags = get_gtk_flags(state_type); - - if (has_focus) { - flags |= GTK_STATE_FLAG_FOCUSED; - } - - fp_gtk_style_context_set_state (context, flags); - - if (widget_type == COMBO_BOX_TEXT_FIELD) { - width += height /2; - } - - fp_gtk_render_background (context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_focus(WidgetType widget_type, GtkStateType state_type, - const char *detail, gint x, gint y, gint width, gint height) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - fp_gtk_style_context_save (context); - - transform_detail_string(detail, context); - fp_gtk_render_focus (context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); - -} - -static void gtk3_paint_handle(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_flags(state_type); - fp_gtk_style_context_set_state(context, GTK_STATE_FLAG_PRELIGHT); - - if (detail != 0) { - transform_detail_string(detail, context); - fp_gtk_style_context_add_class (context, "handlebox_bin"); - } - - fp_gtk_render_handle(context, cr, x, y, width, height); - fp_gtk_render_background(context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_hline(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - if (detail != 0) { - transform_detail_string(detail, context); - } - - fp_gtk_render_line(context, cr, x, y, x + width, y); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_vline(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - if (detail != 0) { - transform_detail_string(detail, context); - } - - fp_gtk_render_line(context, cr, x, y, x, y + height); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_option(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_state_flags(synth_state); - if (gtk3_version_3_14 && (synth_state & SELECTED)) { - flags = GTK_STATE_FLAG_CHECKED; - } - fp_gtk_style_context_set_state(context, flags); - - if (detail != 0) { - transform_detail_string(detail, context); - } - - fp_gtk_render_option(context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_shadow(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir) -{ - if (shadow_type == GTK_SHADOW_NONE) { - return; - } - gtk3_widget = gtk3_get_widget(widget_type); - - /* - * Some engines (e.g. clearlooks) will paint the shadow of certain - * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the - * the text direction. - */ - gtk3_set_direction(gtk3_widget, dir); - - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - fp_gtk_style_context_save (context); - - if (detail) { - transform_detail_string(detail, context); - } - - GtkStateFlags flags = get_gtk_flags(state_type); - - if (synth_state & MOUSE_OVER) { - flags |= GTK_STATE_FLAG_PRELIGHT; - } - - if (synth_state & FOCUSED) { - flags |= GTK_STATE_FLAG_FOCUSED; - } - - fp_gtk_style_context_set_state (context, flags); - - if (widget_type == COMBO_BOX_TEXT_FIELD) { - width += height / 2; - } - fp_gtk_render_frame(context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); - - /* - * Reset the text direction to the default value so that we don't - * accidentally affect other operations and widgets. - */ - gtk3_set_direction(gtk3_widget, GTK_TEXT_DIR_LTR); -} - -static void gtk3_paint_slider(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation, - gboolean has_focus) -{ - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - - fp_gtk_style_context_save (context); - - if (detail) { - transform_detail_string(detail, context); - } - - GtkStateFlags flags = get_gtk_flags(state_type); - - if (state_type == GTK_STATE_ACTIVE) { - flags |= GTK_STATE_FLAG_PRELIGHT; - } - - if (has_focus) { - flags |= GTK_STATE_FLAG_FOCUSED; - } - - fp_gtk_style_context_set_state (context, flags); - - (*fp_gtk_render_slider)(context, cr, x, y, width, height, orientation); - - fp_gtk_style_context_restore (context); -} - -static void gtk3_paint_background(WidgetType widget_type, - GtkStateType state_type, gint x, gint y, gint width, gint height) { - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - fp_gtk_style_context_save (context); - - GtkStateFlags flags = get_gtk_flags(state_type); - - fp_gtk_style_context_set_state (context, flags); - - fp_gtk_render_background (context, cr, x, y, width, height); - - fp_gtk_style_context_restore (context); -} - -static GdkPixbuf *gtk3_get_stock_icon(gint widget_type, const gchar *stock_id, - GtkIconSize size, GtkTextDirection direction, const char *detail) -{ - int sz; - - switch(size) { - case GTK_ICON_SIZE_MENU: - sz = 16; - break; - case GTK_ICON_SIZE_SMALL_TOOLBAR: - sz = 18; - break; - case GTK_ICON_SIZE_LARGE_TOOLBAR: - sz = 24; - break; - case GTK_ICON_SIZE_BUTTON: - sz = 20; - break; - case GTK_ICON_SIZE_DND: - sz = 32; - break; - case GTK_ICON_SIZE_DIALOG: - sz = 48; - break; - default: - sz = 0; - break; - } - - init_containers(); - gtk3_widget = gtk3_get_widget((widget_type < 0) ? IMAGE : widget_type); - (*fp_gtk_widget_set_direction)(gtk3_widget, direction); - GtkIconTheme *icon_theme = fp_gtk_icon_theme_get_default(); - GdkPixbuf *result = fp_gtk_icon_theme_load_icon(icon_theme, stock_id, sz, - GTK_ICON_LOOKUP_USE_BUILTIN, NULL); - return result; -} - -static jboolean gtk3_get_pixbuf_data(JNIEnv *env, GdkPixbuf* pixbuf, - jmethodID icon_upcall_method, jobject this) { - if (!pixbuf) { - return JNI_FALSE; - } - guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf); - if (pixbuf_data) { - 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); - - 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); - (*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); - return JNI_TRUE; - } - return JNI_FALSE; -} - -static jboolean gtk3_get_file_icon_data(JNIEnv *env, const char *filename, - GError **error, jmethodID icon_upcall_method, jobject this) { - GdkPixbuf* pixbuf = fp_gdk_pixbuf_new_from_file(filename, error); - return gtk3_get_pixbuf_data(env, pixbuf, icon_upcall_method, this); -} - -static jboolean gtk3_get_icon_data(JNIEnv *env, gint widget_type, - const gchar *stock_id, GtkIconSize size, - GtkTextDirection direction, const char *detail, - jmethodID icon_upcall_method, jobject this) { - GdkPixbuf* pixbuf = gtk3_get_stock_icon(widget_type, stock_id, size, - direction, detail); - return gtk3_get_pixbuf_data(env, pixbuf, icon_upcall_method, this); -} - -/*************************************************/ -static gint gtk3_get_xthickness(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk3_widget = gtk3_get_widget(widget_type); - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - if (context) { - GtkBorder padding; - fp_gtk_style_context_get_padding(context, 0, &padding); - return padding.left + 1; - } - return 0; -} - -static gint gtk3_get_ythickness(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk3_widget = gtk3_get_widget(widget_type); - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - if (context) { - GtkBorder padding; - fp_gtk_style_context_get_padding(context, 0, &padding); - return padding.top + 1; - } - return 0; -} - -/*************************************************/ -static guint8 recode_color(gdouble channel) -{ - guint16 result = (guint16)(channel * 65535); - if (result > 65535) { - result = 65535; - } - return (guint8)( result >> 8); -} - -static GtkStateFlags gtk3_get_state_flags(GtkStateType state_type) { - switch (state_type) - { - case GTK_STATE_NORMAL: - return GTK_STATE_FLAG_NORMAL; - case GTK_STATE_ACTIVE: - return GTK_STATE_FLAG_ACTIVE; - case GTK_STATE_PRELIGHT: - return GTK_STATE_FLAG_PRELIGHT; - case GTK_STATE_SELECTED: - return GTK_STATE_FLAG_SELECTED; - case GTK_STATE_INSENSITIVE: - return GTK_STATE_FLAG_INSENSITIVE; - case GTK_STATE_INCONSISTENT: - return GTK_STATE_FLAG_INCONSISTENT; - case GTK_STATE_FOCUSED: - return GTK_STATE_FLAG_FOCUSED; - } - return 0; -} - - -static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b) { - gdouble min; - gdouble max; - gdouble red; - gdouble green; - gdouble blue; - gdouble h, l, s; - gdouble delta; - - red = *r; - green = *g; - blue = *b; - - if (red > green) - { - if (red > blue) - max = red; - else - max = blue; - - if (green < blue) - min = green; - else - min = blue; - } - else - { - if (green > blue) - max = green; - else - max = blue; - - if (red < blue) - min = red; - else - min = blue; - } - - l = (max + min) / 2; - s = 0; - h = 0; - - if (max != min) - { - if (l <= 0.5) - s = (max - min) / (max + min); - else - s = (max - min) / (2 - max - min); - - delta = max -min; - if (red == max) - h = (green - blue) / delta; - else if (green == max) - h = 2 + (blue - red) / delta; - else if (blue == max) - h = 4 + (red - green) / delta; - - h *= 60; - if (h < 0.0) - h += 360; - } - - *r = h; - *g = l; - *b = s; -} - -static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s) -{ - gdouble hue; - gdouble lightness; - gdouble saturation; - gdouble m1, m2; - gdouble r, g, b; - - lightness = *l; - saturation = *s; - - if (lightness <= 0.5) - m2 = lightness * (1 + saturation); - else - m2 = lightness + saturation - lightness * saturation; - m1 = 2 * lightness - m2; - - if (saturation == 0) - { - *h = lightness; - *l = lightness; - *s = lightness; - } - else - { - hue = *h + 120; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - - if (hue < 60) - r = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - r = m2; - else if (hue < 240) - r = m1 + (m2 - m1) * (240 - hue) / 60; - else - r = m1; - - hue = *h; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - - if (hue < 60) - g = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - g = m2; - else if (hue < 240) - g = m1 + (m2 - m1) * (240 - hue) / 60; - else - g = m1; - - hue = *h - 120; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - - if (hue < 60) - b = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - b = m2; - else if (hue < 240) - b = m1 + (m2 - m1) * (240 - hue) / 60; - else - b = m1; - - *h = r; - *l = g; - *s = b; - } -} - - - -static void gtk3_style_shade (const GdkRGBA *a, GdkRGBA *b, gdouble k) { - gdouble red = a->red; - gdouble green = a->green; - gdouble blue = a->blue; - - rgb_to_hls (&red, &green, &blue); - - green *= k; - if (green > 1.0) - green = 1.0; - else if (green < 0.0) - green = 0.0; - - blue *= k; - if (blue > 1.0) - blue = 1.0; - else if (blue < 0.0) - blue = 0.0; - - hls_to_rgb (&red, &green, &blue); - - b->red = red; - b->green = green; - b->blue = blue; -} - -static GdkRGBA gtk3_get_color_for_flags(GtkStyleContext* context, - GtkStateFlags flags, ColorType color_type) { - GdkRGBA c, color; - color.alpha = 1; - - switch (color_type) - { - case FOREGROUND: - case TEXT_FOREGROUND: - fp_gtk_style_context_get_color(context, flags, &color); - break; - case BACKGROUND: - case TEXT_BACKGROUND: - fp_gtk_style_context_get_background_color(context, flags, &color); - break; - case LIGHT: - c = gtk3_get_color_for_flags(context, flags, BACKGROUND); - gtk3_style_shade(&c, &color, LIGHTNESS_MULT); - break; - case DARK: - c = gtk3_get_color_for_flags(context, flags, BACKGROUND); - gtk3_style_shade (&c, &color, DARKNESS_MULT); - break; - case MID: - { - GdkRGBA c1 = gtk3_get_color_for_flags(context, flags, LIGHT); - GdkRGBA c2 = gtk3_get_color_for_flags(context, flags, DARK); - color.red = (c1.red + c2.red) / 2; - color.green = (c1.green + c2.green) / 2; - color.blue = (c1.blue + c2.blue) / 2; - } - break; - case FOCUS: - case BLACK: - color.red = 0; - color.green = 0; - color.blue = 0; - break; - case WHITE: - color.red = 1; - color.green = 1; - color.blue = 1; - break; - } - return color; -} - -static gint gtk3_get_color_for_state(JNIEnv *env, WidgetType widget_type, - GtkStateType state_type, ColorType color_type) -{ - - gint result = 0; - - GtkStateFlags flags = gtk3_get_state_flags(state_type); - - init_containers(); - - gtk3_widget = gtk3_get_widget(widget_type); - - GtkStyleContext* context = fp_gtk_widget_get_style_context(gtk3_widget); - - if (widget_type == TOOL_TIP) { - fp_gtk_style_context_add_class(context, "tooltip"); - } - if (widget_type == CHECK_BOX_MENU_ITEM - || widget_type == RADIO_BUTTON_MENU_ITEM) { - flags &= GTK_STATE_FLAG_NORMAL | GTK_STATE_FLAG_SELECTED - | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_FOCUSED; - } - - GdkRGBA color = gtk3_get_color_for_flags(context, flags, color_type); - - if (recode_color(color.alpha) == 0) { - color = gtk3_get_color_for_flags( - fp_gtk_widget_get_style_context(gtk3_get_widget(INTERNAL_FRAME)), - 0, BACKGROUND); - } - - result = recode_color(color.alpha) << 24 | recode_color(color.red) << 16 | - recode_color(color.green) << 8 | recode_color(color.blue); - - return result; -} - -/*************************************************/ -static jobject create_Boolean(JNIEnv *env, jboolean boolean_value); -static jobject create_Integer(JNIEnv *env, jint int_value); -static jobject create_Long(JNIEnv *env, jlong long_value); -static jobject create_Float(JNIEnv *env, jfloat float_value); -static jobject create_Double(JNIEnv *env, jdouble double_value); -static jobject create_Character(JNIEnv *env, jchar char_value); -static jobject create_Insets(JNIEnv *env, GtkBorder *border); - -static jobject gtk3_get_class_value(JNIEnv *env, WidgetType widget_type, - const char* key) -{ - init_containers(); - - gtk3_widget = gtk3_get_widget(widget_type); - - GValue value = { 0, { { 0 } } }; - - GParamSpec* param = (*fp_gtk_widget_class_find_style_property)( - ((GTypeInstance*)gtk3_widget)->g_class, key); - if ( param ) - { - (*fp_g_value_init)( &value, param->value_type ); - (*fp_gtk_widget_style_get_property)(gtk3_widget, key, &value); - - if ((*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN )) - { - gboolean val = (*fp_g_value_get_boolean)(&value); - return create_Boolean(env, (jboolean)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR )) - { - gchar val = (*fp_g_value_get_char)(&value); - return create_Character(env, (jchar)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UCHAR )) - { - guchar val = (*fp_g_value_get_uchar)(&value); - return create_Character(env, (jchar)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_INT )) - { - gint val = (*fp_g_value_get_int)(&value); - return create_Integer(env, (jint)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UINT )) - { - guint val = (*fp_g_value_get_uint)(&value); - return create_Integer(env, (jint)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_LONG )) - { - glong val = (*fp_g_value_get_long)(&value); - return create_Long(env, (jlong)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_ULONG )) - { - gulong val = (*fp_g_value_get_ulong)(&value); - return create_Long(env, (jlong)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_INT64 )) - { - gint64 val = (*fp_g_value_get_int64)(&value); - return create_Long(env, (jlong)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UINT64 )) - { - guint64 val = (*fp_g_value_get_uint64)(&value); - return create_Long(env, (jlong)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_FLOAT )) - { - gfloat val = (*fp_g_value_get_float)(&value); - return create_Float(env, (jfloat)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_DOUBLE )) - { - gdouble val = (*fp_g_value_get_double)(&value); - return create_Double(env, (jdouble)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_ENUM )) - { - gint val = (*fp_g_value_get_enum)(&value); - return create_Integer(env, (jint)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_FLAGS )) - { - guint val = (*fp_g_value_get_flags)(&value); - return create_Integer(env, (jint)val); - } - else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_STRING )) - { - const gchar* val = (*fp_g_value_get_string)(&value); - - /* We suppose that all values come in C locale and - * utf-8 representation of a string is the same as - * the string itself. If this isn't so we should - * use g_convert. - */ - return (*env)->NewStringUTF(env, val); - } - else if ((*fp_g_type_is_a)( param->value_type, GTK_TYPE_BORDER )) - { - GtkBorder *border = (GtkBorder*)(*fp_g_value_get_boxed)(&value); - return border ? create_Insets(env, border) : NULL; - } - - /* TODO: Other types are not supported yet.*/ -/* else if((*fp_g_type_is_a)( param->value_type, G_TYPE_PARAM )) - { - GParamSpec* val = (*fp_g_value_get_param)(&value); - printf( "Param: %p\n", val ); - } - else if((*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED )) - { - gpointer* val = (*fp_g_value_get_boxed)(&value); - printf( "Boxed: %p\n", val ); - } - else if((*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER )) - { - gpointer* val = (*fp_g_value_get_pointer)(&value); - printf( "Pointer: %p\n", val ); - } - else if((*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT )) - { - GObject* val = (GObject*)(*fp_g_value_get_object)(&value); - printf( "Object: %p\n", val ); - }*/ - } - - return NULL; -} - -static void gtk3_set_range_value(WidgetType widget_type, jdouble value, - jdouble min, jdouble max, jdouble visible) -{ - GtkAdjustment *adj; - - gtk3_widget = gtk3_get_widget(widget_type); - - adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk3_widget); - - fp_gtk_adjustment_set_value(adj, value); - fp_gtk_adjustment_set_lower(adj, min); - fp_gtk_adjustment_set_upper(adj, max); - fp_gtk_adjustment_set_page_size(adj, visible); -} - -/*************************************************/ -static jobject create_Object(JNIEnv *env, jmethodID *cid, - const char* class_name, - const char* signature, - jvalue* value) -{ - jclass class; - jobject result; - - class = (*env)->FindClass(env, class_name); - if (class == NULL) - return NULL; /* can't find/load the class, exception thrown */ - - if (*cid == NULL) - { - *cid = (*env)->GetMethodID(env, class, "", signature); - if (*cid == NULL) - { - (*env)->DeleteLocalRef(env, class); - return NULL; /* can't find/get the method, exception thrown */ - } - } - - result = (*env)->NewObjectA(env, class, *cid, value); - - (*env)->DeleteLocalRef(env, class); - return result; -} - -jobject create_Boolean(JNIEnv *env, jboolean boolean_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.z = boolean_value; - - return create_Object(env, &cid, "java/lang/Boolean", "(Z)V", &value); -} - -jobject create_Integer(JNIEnv *env, jint int_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.i = int_value; - - return create_Object(env, &cid, "java/lang/Integer", "(I)V", &value); -} - -jobject create_Long(JNIEnv *env, jlong long_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.j = long_value; - - return create_Object(env, &cid, "java/lang/Long", "(J)V", &value); -} - -jobject create_Float(JNIEnv *env, jfloat float_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.f = float_value; - - return create_Object(env, &cid, "java/lang/Float", "(F)V", &value); -} - -jobject create_Double(JNIEnv *env, jdouble double_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.d = double_value; - - return create_Object(env, &cid, "java/lang/Double", "(D)V", &value); -} - -jobject create_Character(JNIEnv *env, jchar char_value) -{ - static jmethodID cid = NULL; - jvalue value; - - value.c = char_value; - - return create_Object(env, &cid, "java/lang/Character", "(C)V", &value); -} - - -jobject create_Insets(JNIEnv *env, GtkBorder *border) -{ - static jmethodID cid = NULL; - jvalue values[4]; - - values[0].i = border->top; - values[1].i = border->left; - values[2].i = border->bottom; - values[3].i = border->right; - - return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values); -} - -/*********************************************/ -static jstring gtk3_get_pango_font_name(JNIEnv *env, WidgetType widget_type) -{ - init_containers(); - - gtk3_widget = gtk3_get_widget(widget_type); - jstring result = NULL; - GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget); - if (context) - { - PangoFontDescription* fd = fp_gtk_style_context_get_font(context, 0); - gchar* val = (*fp_pango_font_description_to_string)(fd); - result = (*env)->NewStringUTF(env, val); - (*fp_g_free)( val ); - } - - return result; -} - -/***********************************************/ -static jobject get_string_property(JNIEnv *env, GtkSettings* settings, - const gchar* key) { - jobject result = NULL; - gchar* strval = NULL; - - (*fp_g_object_get)(settings, key, &strval, NULL); - result = (*env)->NewStringUTF(env, strval); - (*fp_g_free)(strval); - - return result; -} - -static jobject get_integer_property(JNIEnv *env, GtkSettings* settings, - const gchar* key) { - gint intval = 0; - (*fp_g_object_get)(settings, key, &intval, NULL); - return create_Integer(env, intval); -} - -static jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, - const gchar* key) { - gint intval = 0; - (*fp_g_object_get)(settings, key, &intval, NULL); - return create_Boolean(env, intval); -} - -static jobject gtk3_get_setting(JNIEnv *env, Setting property) -{ - GtkSettings* settings = (*fp_gtk_settings_get_default)(); - - switch (property) - { - case GTK_FONT_NAME: - return get_string_property(env, settings, "gtk-font-name"); - case GTK_ICON_SIZES: - return get_string_property(env, settings, "gtk-icon-sizes"); - case GTK_CURSOR_BLINK: - return get_boolean_property(env, settings, "gtk-cursor-blink"); - case GTK_CURSOR_BLINK_TIME: - return get_integer_property(env, settings, "gtk-cursor-blink-time"); - } - - return NULL; -} - -static void transform_detail_string (const gchar *detail, - GtkStyleContext *context) { - if (!detail) - return; - - if (strcmp (detail, "arrow") == 0) - fp_gtk_style_context_add_class (context, "arrow"); - else if (strcmp (detail, "button") == 0) - fp_gtk_style_context_add_class (context, "button"); - else if (strcmp (detail, "buttondefault") == 0) - { - fp_gtk_style_context_add_class (context, "button"); - fp_gtk_style_context_add_class (context, "default"); - } - else if (strcmp (detail, "calendar") == 0) - fp_gtk_style_context_add_class (context, "calendar"); - else if (strcmp (detail, "cellcheck") == 0) - { - fp_gtk_style_context_add_class (context, "cell"); - fp_gtk_style_context_add_class (context, "check"); - } - else if (strcmp (detail, "cellradio") == 0) - { - fp_gtk_style_context_add_class (context, "cell"); - fp_gtk_style_context_add_class (context, "radio"); - } - else if (strcmp (detail, "checkbutton") == 0) - fp_gtk_style_context_add_class (context, "check"); - else if (strcmp (detail, "check") == 0) - { - fp_gtk_style_context_add_class (context, "check"); - fp_gtk_style_context_add_class (context, "menu"); - } - else if (strcmp (detail, "radiobutton") == 0) - { - fp_gtk_style_context_add_class (context, "radio"); - } - else if (strcmp (detail, "option") == 0) - { - fp_gtk_style_context_add_class (context, "radio"); - fp_gtk_style_context_add_class (context, "menu"); - } - else if (strcmp (detail, "entry") == 0 || - strcmp (detail, "entry_bg") == 0) - fp_gtk_style_context_add_class (context, "entry"); - else if (strcmp (detail, "expander") == 0) - fp_gtk_style_context_add_class (context, "expander"); - else if (strcmp (detail, "tooltip") == 0) - fp_gtk_style_context_add_class (context, "tooltip"); - else if (strcmp (detail, "frame") == 0) - fp_gtk_style_context_add_class (context, "frame"); - else if (strcmp (detail, "scrolled_window") == 0) - fp_gtk_style_context_add_class (context, "scrolled-window"); - else if (strcmp (detail, "viewport") == 0 || - strcmp (detail, "viewportbin") == 0) - fp_gtk_style_context_add_class (context, "viewport"); - else if (strncmp (detail, "trough", 6) == 0) - fp_gtk_style_context_add_class (context, "trough"); - else if (strcmp (detail, "spinbutton") == 0) - fp_gtk_style_context_add_class (context, "spinbutton"); - else if (strcmp (detail, "spinbutton_up") == 0) - { - fp_gtk_style_context_add_class (context, "spinbutton"); - fp_gtk_style_context_add_class (context, "button"); - fp_gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); - } - else if (strcmp (detail, "spinbutton_down") == 0) - { - fp_gtk_style_context_add_class (context, "spinbutton"); - fp_gtk_style_context_add_class (context, "button"); - fp_gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); - } - else if ((detail[0] == 'h' || detail[0] == 'v') && - strncmp (&detail[1], "scrollbar_", 9) == 0) - { - fp_gtk_style_context_add_class (context, "button"); - fp_gtk_style_context_add_class (context, "scrollbar"); - } - else if (strcmp (detail, "slider") == 0) - { - fp_gtk_style_context_add_class (context, "slider"); - fp_gtk_style_context_add_class (context, "scrollbar"); - } - else if (strcmp (detail, "vscale") == 0 || - strcmp (detail, "hscale") == 0) - { - fp_gtk_style_context_add_class (context, "slider"); - fp_gtk_style_context_add_class (context, "scale"); - } - else if (strcmp (detail, "menuitem") == 0) - { - fp_gtk_style_context_add_class (context, "menuitem"); - fp_gtk_style_context_add_class (context, "menu"); - } - else if (strcmp (detail, "menu") == 0) - { - fp_gtk_style_context_add_class (context, "popup"); - fp_gtk_style_context_add_class (context, "menu"); - } - else if (strcmp (detail, "accellabel") == 0) - fp_gtk_style_context_add_class (context, "accelerator"); - else if (strcmp (detail, "menubar") == 0) - fp_gtk_style_context_add_class (context, "menubar"); - else if (strcmp (detail, "base") == 0) - fp_gtk_style_context_add_class (context, "background"); - else if (strcmp (detail, "bar") == 0 || - strcmp (detail, "progressbar") == 0) - fp_gtk_style_context_add_class (context, "progressbar"); - else if (strcmp (detail, "toolbar") == 0) - fp_gtk_style_context_add_class (context, "toolbar"); - else if (strcmp (detail, "handlebox_bin") == 0) - fp_gtk_style_context_add_class (context, "dock"); - else if (strcmp (detail, "notebook") == 0) - fp_gtk_style_context_add_class (context, "notebook"); - else if (strcmp (detail, "tab") == 0) - { - fp_gtk_style_context_add_class (context, "notebook"); - fp_gtk_style_context_add_region (context, "tab", 0); - } else if (strcmp (detail, "paned") == 0) { - fp_gtk_style_context_add_class (context, "pane-separator"); - } - else if (fp_g_str_has_prefix (detail, "cell")) - { - GtkRegionFlags row, col; - gboolean ruled = FALSE; - gchar** tokens; - guint i; - - tokens = fp_g_strsplit (detail, "_", -1); - row = col = 0; - i = 0; - - while (tokens[i]) - { - if (strcmp (tokens[i], "even") == 0) - row |= GTK_REGION_EVEN; - else if (strcmp (tokens[i], "odd") == 0) - row |= GTK_REGION_ODD; - else if (strcmp (tokens[i], "start") == 0) - col |= GTK_REGION_FIRST; - else if (strcmp (tokens[i], "end") == 0) - col |= GTK_REGION_LAST; - else if (strcmp (tokens[i], "ruled") == 0) - ruled = TRUE; - else if (strcmp (tokens[i], "sorted") == 0) - col |= GTK_REGION_SORTED; - - i++; - } - - if (!ruled) - row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD); - - fp_gtk_style_context_add_class (context, "cell"); - fp_gtk_style_context_add_region (context, "row", row); - fp_gtk_style_context_add_region (context, "column", col); - - fp_g_strfreev (tokens); - } -} - -static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray, - int x, jint y, jint width, jint height, jint jwidth, int dx, int dy, - jint scale) { - GdkPixbuf *pixbuf; - jint *ary; - - GdkWindow *root = (*fp_gdk_get_default_root_window)(); - pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(root, x, y, width, height); - if (pixbuf && scale != 1) { - GdkPixbuf *scaledPixbuf; - x /= scale; - y /= scale; - width /= scale; - height /= scale; - dx /= scale; - dy /= scale; - scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height, - GDK_INTERP_BILINEAR); - (*fp_g_object_unref)(pixbuf); - pixbuf = scaledPixbuf; - } - - if (pixbuf) { - int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf); - int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf); - if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width - && (*fp_gdk_pixbuf_get_height)(pixbuf) == height - && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8 - && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB - && nchan >= 3 - ) { - guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf); - ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - if (ary) { - jint _x, _y; - int index; - for (_y = 0; _y < height; _y++) { - for (_x = 0; _x < width; _x++) { - p = pix + _y * stride + _x * nchan; - - index = (_y + dy) * jwidth + (_x + dx); - ary[index] = 0xff000000 - | (p[0] << 16) - | (p[1] << 8) - | (p[2]); - - } - } - (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); - } - } - (*fp_g_object_unref)(pixbuf); - } - return JNI_FALSE; -} - -static GdkWindow* gtk3_get_window(void *widget) { - return fp_gtk_widget_get_window((GtkWidget*)widget); -} - -static void gtk3_init(GtkApi* gtk) { - gtk->version = GTK_3; - - gtk->show_uri_load = >k3_show_uri_load; - gtk->unload = >k3_unload; - gtk->flush_event_loop = &flush_gtk_event_loop; - gtk->gtk_check_version = fp_gtk_check_version; - gtk->get_setting = >k3_get_setting; - - gtk->paint_arrow = >k3_paint_arrow; - gtk->paint_box = >k3_paint_box; - gtk->paint_box_gap = >k3_paint_box_gap; - gtk->paint_expander = >k3_paint_expander; - gtk->paint_extension = >k3_paint_extension; - gtk->paint_flat_box = >k3_paint_flat_box; - gtk->paint_focus = >k3_paint_focus; - gtk->paint_handle = >k3_paint_handle; - gtk->paint_hline = >k3_paint_hline; - gtk->paint_vline = >k3_paint_vline; - gtk->paint_option = >k3_paint_option; - gtk->paint_shadow = >k3_paint_shadow; - gtk->paint_slider = >k3_paint_slider; - gtk->paint_background = >k3_paint_background; - gtk->paint_check = >k3_paint_check; - gtk->set_range_value = >k3_set_range_value; - - gtk->init_painting = >k3_init_painting; - gtk->copy_image = >k3_copy_image; - - gtk->get_xthickness = >k3_get_xthickness; - gtk->get_ythickness = >k3_get_ythickness; - gtk->get_color_for_state = >k3_get_color_for_state; - gtk->get_class_value = >k3_get_class_value; - - gtk->get_pango_font_name = >k3_get_pango_font_name; - gtk->get_icon_data = >k3_get_icon_data; - gtk->get_file_icon_data = >k3_get_file_icon_data; - gtk->gdk_threads_enter = fp_gdk_threads_enter; - gtk->gdk_threads_leave = fp_gdk_threads_leave; - gtk->gtk_show_uri = fp_gtk_show_uri; - gtk->get_drawable_data = >k3_get_drawable_data; - gtk->g_free = fp_g_free; - - gtk->gtk_file_chooser_get_filename = fp_gtk_file_chooser_get_filename; - gtk->gtk_widget_hide = fp_gtk_widget_hide; - gtk->gtk_main_quit = fp_gtk_main_quit; - gtk->gtk_file_chooser_dialog_new = fp_gtk_file_chooser_dialog_new; - gtk->gtk_file_chooser_set_current_folder = - fp_gtk_file_chooser_set_current_folder; - gtk->gtk_file_chooser_set_filename = fp_gtk_file_chooser_set_filename; - gtk->gtk_file_chooser_set_current_name = - fp_gtk_file_chooser_set_current_name; - gtk->gtk_file_filter_add_custom = fp_gtk_file_filter_add_custom; - gtk->gtk_file_chooser_set_filter = fp_gtk_file_chooser_set_filter; - gtk->gtk_file_chooser_get_type = fp_gtk_file_chooser_get_type; - gtk->gtk_file_filter_new = fp_gtk_file_filter_new; - gtk->gtk_file_chooser_set_do_overwrite_confirmation = - fp_gtk_file_chooser_set_do_overwrite_confirmation; - gtk->gtk_file_chooser_set_select_multiple = - fp_gtk_file_chooser_set_select_multiple; - gtk->gtk_file_chooser_get_current_folder = - fp_gtk_file_chooser_get_current_folder; - gtk->gtk_file_chooser_get_filenames = fp_gtk_file_chooser_get_filenames; - gtk->gtk_g_slist_length = fp_gtk_g_slist_length; - gtk->g_signal_connect_data = fp_g_signal_connect_data; - gtk->gtk_widget_show = fp_gtk_widget_show; - gtk->gtk_main = fp_gtk_main; - gtk->gtk_main_level = fp_gtk_main_level; - gtk->g_path_get_dirname = fp_g_path_get_dirname; - gtk->gdk_x11_drawable_get_xid = fp_gdk_x11_drawable_get_xid; - gtk->gtk_widget_destroy = fp_gtk_widget_destroy; - gtk->gtk_window_present = fp_gtk_window_present; - gtk->gtk_window_move = fp_gtk_window_move; - gtk->gtk_window_resize = fp_gtk_window_resize; - gtk->get_window = >k3_get_window; - - gtk->g_object_unref = fp_g_object_unref; - gtk->g_list_append = fp_g_list_append; - gtk->g_list_free = fp_g_list_free; - gtk->g_list_free_full = fp_g_list_free_full; -} diff --git a/app/src/main/jni/awt_xawt/awt/gtk3_interface.h b/app/src/main/jni/awt_xawt/awt/gtk3_interface.h deleted file mode 100644 index 1ffaa8fa9..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk3_interface.h +++ /dev/null @@ -1,577 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#ifndef _GTK3_INTERFACE_H -#define _GTK3_INTERFACE_H - -#include -#include -#include -#include "gtk_interface.h" - -#define LIGHTNESS_MULT 1.3 -#define DARKNESS_MULT 0.7 - -#define G_PI 3.1415926535897932384626433832795028841971693993751 - -typedef enum -{ - GTK_STATE_FLAG_NORMAL = 0, - GTK_STATE_FLAG_ACTIVE = 1 << 0, - GTK_STATE_FLAG_PRELIGHT = 1 << 1, - GTK_STATE_FLAG_SELECTED = 1 << 2, - GTK_STATE_FLAG_INSENSITIVE = 1 << 3, - GTK_STATE_FLAG_INCONSISTENT = 1 << 4, - GTK_STATE_FLAG_FOCUSED = 1 << 5, - GTK_STATE_FLAG_BACKDROP = 1 << 6, - GTK_STATE_FLAG_DIR_LTR = 1 << 7, - GTK_STATE_FLAG_DIR_RTL = 1 << 8, - GTK_STATE_FLAG_LINK = 1 << 9, - GTK_STATE_FLAG_VISITED = 1 << 10, - GTK_STATE_FLAG_CHECKED = 1 << 11 -} GtkStateFlags; - -typedef enum { - GTK_JUNCTION_NONE = 0, - GTK_JUNCTION_CORNER_TOPLEFT = 1 << 0, - GTK_JUNCTION_CORNER_TOPRIGHT = 1 << 1, - GTK_JUNCTION_CORNER_BOTTOMLEFT = 1 << 2, - GTK_JUNCTION_CORNER_BOTTOMRIGHT = 1 << 3, - GTK_JUNCTION_TOP = - (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_TOPRIGHT), - GTK_JUNCTION_BOTTOM = - (GTK_JUNCTION_CORNER_BOTTOMLEFT | GTK_JUNCTION_CORNER_BOTTOMRIGHT), - GTK_JUNCTION_LEFT = - (GTK_JUNCTION_CORNER_TOPLEFT | GTK_JUNCTION_CORNER_BOTTOMLEFT), - GTK_JUNCTION_RIGHT = - (GTK_JUNCTION_CORNER_TOPRIGHT | GTK_JUNCTION_CORNER_BOTTOMRIGHT) -} GtkJunctionSides; - -typedef enum { - GTK_REGION_EVEN = 1 << 0, - GTK_REGION_ODD = 1 << 1, - GTK_REGION_FIRST = 1 << 2, - GTK_REGION_LAST = 1 << 3, - GTK_REGION_ONLY = 1 << 4, - GTK_REGION_SORTED = 1 << 5 -} GtkRegionFlags; - -typedef enum -{ - GTK_WINDOW_TOPLEVEL, - GTK_WINDOW_POPUP -} GtkWindowType; - -typedef enum -{ - G_PARAM_READABLE = 1 << 0, - G_PARAM_WRITABLE = 1 << 1, - G_PARAM_CONSTRUCT = 1 << 2, - G_PARAM_CONSTRUCT_ONLY = 1 << 3, - G_PARAM_LAX_VALIDATION = 1 << 4, - G_PARAM_STATIC_NAME = 1 << 5 -} GParamFlags; - -typedef enum -{ - GTK_ICON_LOOKUP_NO_SVG = 1 << 0, - GTK_ICON_LOOKUP_FORCE_SVG = 1 << 1, - GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2, - GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3, - GTK_ICON_LOOKUP_FORCE_SIZE = 1 << 4 -} GtkIconLookupFlags; - -typedef enum -{ - GTK_UPDATE_CONTINUOUS, - GTK_UPDATE_DISCONTINUOUS, - GTK_UPDATE_DELAYED -} GtkUpdateType; - -typedef enum -{ - GTK_PROGRESS_CONTINUOUS, - GTK_PROGRESS_DISCRETE -} GtkProgressBarStyle; - -typedef enum -{ - GTK_PROGRESS_LEFT_TO_RIGHT, - GTK_PROGRESS_RIGHT_TO_LEFT, - GTK_PROGRESS_BOTTOM_TO_TOP, - GTK_PROGRESS_TOP_TO_BOTTOM -} GtkProgressBarOrientation; - -typedef enum { - CAIRO_FORMAT_INVALID = -1, - CAIRO_FORMAT_ARGB32 = 0, - CAIRO_FORMAT_RGB24 = 1, - CAIRO_FORMAT_A8 = 2, - CAIRO_FORMAT_A1 = 3, - CAIRO_FORMAT_RGB16_565 = 4 -} cairo_format_t; - -/* We define all structure pointers to be void* */ -typedef void GdkPixbuf; -typedef void GMainContext; -typedef void GVfs; - -typedef void GdkColormap; -typedef void GdkDrawable; -typedef void GdkGC; -typedef void GdkPixmap; -typedef void GtkStyleContext; -typedef void GtkFixed; -typedef void GtkMenuItem; -typedef void GtkMenuShell; -typedef void GtkWidgetClass; -typedef void PangoFontDescription; -typedef void GtkSettings; -typedef void GtkStyleProvider; -typedef void cairo_pattern_t; -typedef void cairo_t; -typedef void cairo_surface_t; -typedef void GtkScrolledWindow; -typedef void GtkIconTheme; -typedef void GtkWidget; -typedef void GtkMisc; -typedef void GtkContainer; -typedef void GtkBin; -typedef void GtkAdjustment; -typedef void GtkRange; -typedef void GtkProgressBar; -typedef void GtkProgress; - -/* Some real structures */ -typedef struct -{ - guint32 pixel; - guint16 red; - guint16 green; - guint16 blue; -} GdkColor; - -typedef struct -{ - gdouble red; - gdouble green; - gdouble blue; - gdouble alpha; -} GdkRGBA; - -typedef struct { - gint fd; - gushort events; - gushort revents; -} GPollFD; - -typedef struct { - gint x; - gint y; - gint width; - gint height; -} GdkRectangle; - -typedef struct { - int x, y; - int width, height; -} GtkAllocation; - -typedef struct { - gint width; - gint height; -} GtkRequisition; - -typedef struct { - GtkWidgetClass *g_class; -} GTypeInstance; - -typedef struct { - gint16 left; - gint16 right; - gint16 top; - gint16 bottom; -} GtkBorder; - -typedef struct -{ - GType g_type; - union { - gint v_int; - guint v_uint; - glong v_long; - gulong v_ulong; - gint64 v_int64; - guint64 v_uint64; - gfloat v_float; - gdouble v_double; - gpointer v_pointer; - } data[2]; -} GValue; - -typedef struct { - GTypeInstance g_type_instance; - const gchar *name; - GParamFlags flags; - GType value_type; - GType owner_type; -} GParamSpec; - - -static gchar* (*fp_glib_check_version)(guint required_major, - guint required_minor, guint required_micro); - -/** - * Returns : - * NULL if the GTK+ library is compatible with the given version, or a string - * describing the version mismatch. - */ -static gchar* (*fp_gtk_check_version)(guint required_major, guint - required_minor, guint required_micro); - -static void (*fp_g_free)(gpointer mem); -static void (*fp_g_object_unref)(gpointer object); -static GdkWindow *(*fp_gdk_get_default_root_window) (void); - -static int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf); -static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf); -static gboolean (*fp_gdk_pixbuf_get_has_alpha)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_height)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_n_channels)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_rowstride)(const GdkPixbuf *pixbuf); -static int (*fp_gdk_pixbuf_get_width)(const GdkPixbuf *pixbuf); -static GdkPixbuf *(*fp_gdk_pixbuf_new_from_file)(const char *filename, - GError **error); -static GdkColorspace (*fp_gdk_pixbuf_get_colorspace)(const GdkPixbuf *pixbuf); - -static GdkPixbuf *(*fp_gdk_pixbuf_get_from_drawable)(GdkWindow *window, - int src_x, int src_y, int width, int height); -static GdkPixbuf *(*fp_gdk_pixbuf_scale_simple)(GdkPixbuf *src, - int dest_width, int dest_heigh, GdkInterpType interp_type); - - -static void (*fp_gtk_widget_destroy)(void *widget); -static void (*fp_gtk_window_present)(GtkWindow *window); -static void (*fp_gtk_window_move)(GtkWindow *window, gint x, gint y); -static void (*fp_gtk_window_resize)(GtkWindow *window, gint width, gint height); - -/** - * Function Pointers for GtkFileChooser - */ -static gchar* (*fp_gtk_file_chooser_get_filename)(GtkFileChooser *chooser); -static void (*fp_gtk_widget_hide)(void *widget); -static void (*fp_gtk_main_quit)(void); -static void* (*fp_gtk_file_chooser_dialog_new)(const gchar *title, - GtkWindow *parent, GtkFileChooserAction action, - const gchar *first_button_text, ...); -static gboolean (*fp_gtk_file_chooser_set_current_folder) - (GtkFileChooser *chooser, const gchar *filename); -static gboolean (*fp_gtk_file_chooser_set_filename)(GtkFileChooser *chooser, - const char *filename); -static void (*fp_gtk_file_chooser_set_current_name)(GtkFileChooser *chooser, - const gchar *name); -static void (*fp_gtk_file_filter_add_custom)(GtkFileFilter *filter, - GtkFileFilterFlags needed, GtkFileFilterFunc func, gpointer data, - GDestroyNotify notify); -static void (*fp_gtk_file_chooser_set_filter)(GtkFileChooser *chooser, - GtkFileFilter *filter); -static GType (*fp_gtk_file_chooser_get_type)(void); -static GtkFileFilter* (*fp_gtk_file_filter_new)(void); -static void (*fp_gtk_file_chooser_set_do_overwrite_confirmation)( - GtkFileChooser *chooser, gboolean do_overwrite_confirmation); -static void (*fp_gtk_file_chooser_set_select_multiple)( - GtkFileChooser *chooser, gboolean select_multiple); -static gchar* (*fp_gtk_file_chooser_get_current_folder) - (GtkFileChooser *chooser); -static GSList* (*fp_gtk_file_chooser_get_filenames)(GtkFileChooser *chooser); -static guint (*fp_gtk_g_slist_length)(GSList *list); -static gulong (*fp_g_signal_connect_data)(gpointer instance, - const gchar *detailed_signal, GCallback c_handler, gpointer data, - GClosureNotify destroy_data, GConnectFlags connect_flags); -static void (*fp_gtk_widget_show)(void *widget); -static void (*fp_gtk_main)(void); -static guint (*fp_gtk_main_level)(void); -static gchar* (*fp_g_path_get_dirname) (const gchar *file_name); -static XID (*fp_gdk_x11_drawable_get_xid) (GdkWindow *drawable); - -static GList* (*fp_g_list_append) (GList *list, gpointer data); -static void (*fp_g_list_free) (GList *list); -static void (*fp_g_list_free_full) (GList *list, GDestroyNotify free_func); - -static void (*fp_gdk_threads_enter)(void); -static void (*fp_gdk_threads_leave)(void); - -static gboolean (*fp_gtk_show_uri)(GdkScreen *screen, const gchar *uri, - guint32 timestamp, GError **error); - -// Implementation functions prototypes -static void gtk3_init(GtkApi* gtk); -static GValue* (*fp_g_value_init)(GValue *value, GType g_type); -static gboolean (*fp_g_type_is_a)(GType type, GType is_a_type); -static gboolean (*fp_g_value_get_boolean)(const GValue *value); -static gchar (*fp_g_value_get_char)(const GValue *value); -static guchar (*fp_g_value_get_uchar)(const GValue *value); -static gint (*fp_g_value_get_int)(const GValue *value); -static guint (*fp_g_value_get_uint)(const GValue *value); -static glong (*fp_g_value_get_long)(const GValue *value); -static gulong (*fp_g_value_get_ulong)(const GValue *value); -static gint64 (*fp_g_value_get_int64)(const GValue *value); -static guint64 (*fp_g_value_get_uint64)(const GValue *value); -static gfloat (*fp_g_value_get_float)(const GValue *value); -static gdouble (*fp_g_value_get_double)(const GValue *value); -static const gchar* (*fp_g_value_get_string)(const GValue *value); -static gint (*fp_g_value_get_enum)(const GValue *value); -static guint (*fp_g_value_get_flags)(const GValue *value); -static GParamSpec* (*fp_g_value_get_param)(const GValue *value); -static gpointer* (*fp_g_value_get_boxed)(const GValue *value); -static gpointer* (*fp_g_value_get_pointer)(const GValue *value); -static void (*fp_g_object_get)(gpointer object, - const gchar* fpn, ...); -static void (*fp_g_object_set)(gpointer object, - const gchar *first_property_name, - ...); - -static gboolean (*fp_g_main_context_iteration)(GMainContext *context); -static gboolean (*fp_g_str_has_prefix)(const gchar *str, const gchar *prefix); -static gchar** (*fp_g_strsplit)(const gchar *string, const gchar *delimiter, - gint max_tokens); -static void (*fp_g_strfreev)(gchar **str_array); - - -static cairo_surface_t* (*fp_cairo_image_surface_create)(cairo_format_t format, - int width, int height); -static void (*fp_cairo_surface_destroy)(cairo_surface_t *surface); -static cairo_t* (*fp_cairo_create)(cairo_surface_t *target); -static void (*fp_cairo_destroy)(cairo_t *cr); -static void (*fp_cairo_fill)(cairo_t *cr); -static void (*fp_cairo_surface_flush)(cairo_surface_t *surface); -static void (*fp_cairo_rectangle)(cairo_t *cr, double x, double y, double width, - double height); -static void (*fp_cairo_set_source_rgb)(cairo_t *cr, double red, double green, - double blue); -static void (*fp_cairo_set_source_rgba)(cairo_t *cr, double red, double green, - double blue, double alpha); -static void (*fp_cairo_paint)(cairo_t *cr); -static void (*fp_cairo_clip)(cairo_t *cr); -static unsigned char* (*fp_cairo_image_surface_get_data)( - cairo_surface_t *surface); -static int (*fp_cairo_image_surface_get_stride) (cairo_surface_t *surface); -static GdkPixbuf* (*fp_gdk_pixbuf_get_from_surface)(cairo_surface_t *surface, - gint src_x, gint src_y, gint width, gint height); -static GtkStateType (*fp_gtk_widget_get_state)(GtkWidget *widget); -static void (*fp_gtk_widget_set_state)(GtkWidget *widget, GtkStateType state); -static gboolean (*fp_gtk_widget_is_focus)(GtkWidget *widget); -static void (*fp_gtk_widget_set_allocation)(GtkWidget *widget, - const GtkAllocation *allocation); -static GtkWidget* (*fp_gtk_widget_get_parent)(GtkWidget *widget); -static GtkStyleContext* (*fp_gtk_widget_get_style_context)(GtkWidget *widget); -static void (*fp_gtk_style_context_get_color)(GtkStyleContext *context, - GtkStateFlags state, GdkRGBA *color); -static void (*fp_gtk_style_context_get_background_color) - (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color); -static void (*fp_gtk_style_context_get)(GtkStyleContext *context, - GtkStateFlags state, ...); -static GtkStateFlags (*fp_gtk_widget_get_state_flags)(GtkWidget* widget); -static void (*fp_gtk_style_context_set_state)(GtkStyleContext* style, - GtkStateFlags flags); -static void (*fp_gtk_style_context_add_class)(GtkStyleContext *context, - const gchar *class_name); -static void (*fp_gtk_style_context_save)(GtkStyleContext *context); -static void (*fp_gtk_style_context_restore)(GtkStyleContext *context); -static void (*fp_gtk_render_check)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_option)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_extension)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height, - GtkPositionType gap_side); -static void (*fp_gtk_render_expander)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_frame_gap)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height, - GtkPositionType gap_side, gdouble xy0_gap, - gdouble xy1_gap); -static void (*fp_gtk_render_line)(GtkStyleContext *context, cairo_t *cr, - gdouble x0, gdouble y0, gdouble x1, gdouble y1); -static GdkPixbuf* (*fp_gtk_widget_render_icon_pixbuf)(GtkWidget *widget, - const gchar *stock_id, GtkIconSize size); -static cairo_surface_t* (*fp_gdk_window_create_similar_image_surface)( - GdkWindow *window, cairo_format_t format, int width, - int height, int scale); -static cairo_surface_t* (*fp_gdk_window_create_similar_surface)( - GdkWindow *window, cairo_format_t format, - int width, int height); -static GdkWindow* (*fp_gtk_widget_get_window)(GtkWidget *widget); -static GtkSettings *(*fp_gtk_settings_get_for_screen)(GdkScreen *screen); -static GdkScreen *(*fp_gtk_widget_get_screen)(GtkWidget *widget); -static GtkStyleProvider* (*fp_gtk_css_provider_get_named)(const gchar *name, - const gchar *variant); -static void (*fp_gtk_style_context_add_provider)(GtkStyleContext *context, - GtkStyleProvider *provider, guint priority); -static void (*fp_gtk_render_frame)(GtkStyleContext *context,cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_focus)(GtkStyleContext *context,cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_handle)(GtkStyleContext *context,cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_style_context_get_property)(GtkStyleContext *context, - const gchar *property, GtkStateFlags state, GValue *value); -static void (*fp_gtk_render_activity)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static void (*fp_gtk_render_background)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height); -static gboolean (*fp_gtk_style_context_has_class)(GtkStyleContext *context, - const gchar *class_name); -static void transform_detail_string (const gchar *detail, - GtkStyleContext *context); -void (*fp_gtk_style_context_set_junction_sides)(GtkStyleContext *context, - GtkJunctionSides sides); -void (*fp_gtk_style_context_add_region)(GtkStyleContext *context, - const gchar *region_name, GtkRegionFlags flags); -void (*fp_gtk_render_arrow)(GtkStyleContext *context, cairo_t *cr, - gdouble angle, gdouble x, gdouble y, gdouble size); -void (*fp_gtk_bin_set_child)(GtkBin *bin, GtkWidget *widget); -void (*fp_gtk_scrolled_window_set_shadow_type)( - GtkScrolledWindow *scrolled_window, GtkShadowType type); -static void (*fp_gtk_render_slider)(GtkStyleContext *context, cairo_t *cr, - gdouble x, gdouble y, gdouble width, gdouble height, - GtkOrientation orientation); -static void (*fp_gtk_style_context_get_padding)(GtkStyleContext *self, - GtkStateFlags state, GtkBorder* padding); -static void (*fp_gtk_range_set_inverted)(GtkRange *range, gboolean setting); -static PangoFontDescription* (*fp_gtk_style_context_get_font)( - GtkStyleContext *context, GtkStateFlags state); -static int (*fp_gtk_widget_get_allocated_width)(GtkWidget *widget); -static int (*fp_gtk_widget_get_allocated_height)(GtkWidget *widget); -static GtkIconTheme* (*fp_gtk_icon_theme_get_default)(void); -static GdkPixbuf* (*fp_gtk_icon_theme_load_icon)(GtkIconTheme *icon_theme, - const gchar *icon_name, gint size, - GtkIconLookupFlags flags, GError **error); -static void (*fp_gtk_adjustment_set_lower)(GtkAdjustment *adjustment, - gdouble lower); -static void (*fp_gtk_adjustment_set_page_increment)(GtkAdjustment *adjustment, - gdouble page_increment); -static void (*fp_gtk_adjustment_set_page_size)(GtkAdjustment *adjustment, - gdouble page_size); -static void (*fp_gtk_adjustment_set_step_increment)(GtkAdjustment *adjustment, - gdouble step_increment); -static void (*fp_gtk_adjustment_set_upper)(GtkAdjustment *adjustment, - gdouble upper); -static void (*fp_gtk_adjustment_set_value)(GtkAdjustment *adjustment, - gdouble value); -static GdkGC *(*fp_gdk_gc_new)(GdkDrawable*); -static void (*fp_gdk_rgb_gc_set_foreground)(GdkGC*, guint32); -static void (*fp_gdk_draw_rectangle)(GdkDrawable*, GdkGC*, gboolean, - gint, gint, gint, gint); -static GdkPixbuf *(*fp_gdk_pixbuf_new)(GdkColorspace colorspace, - gboolean has_alpha, int bits_per_sample, int width, int height); -static void (*fp_gdk_drawable_get_size)(GdkDrawable *drawable, - gint* width, gint* height); -static gboolean (*fp_gtk_init_check)(int* argc, char** argv); - -/* Widget creation */ -static GtkWidget* (*fp_gtk_arrow_new)(GtkArrowType arrow_type, - GtkShadowType shadow_type); -static GtkWidget* (*fp_gtk_button_new)(); -static GtkWidget* (*fp_gtk_check_button_new)(); -static GtkWidget* (*fp_gtk_check_menu_item_new)(); -static GtkWidget* (*fp_gtk_color_selection_dialog_new)(const gchar* title); -static GtkWidget* (*fp_gtk_combo_box_new)(); -static GtkWidget* (*fp_gtk_combo_box_entry_new)(); -static GtkWidget* (*fp_gtk_entry_new)(); -static GtkWidget* (*fp_gtk_fixed_new)(); -static GtkWidget* (*fp_gtk_handle_box_new)(); -static GtkWidget* (*fp_gtk_hpaned_new)(); -static GtkWidget* (*fp_gtk_vpaned_new)(); -static GtkWidget* (*fp_gtk_scale_new)(GtkOrientation orientation, - GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_hscrollbar_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_vscrollbar_new)(GtkAdjustment* adjustment); -static GtkWidget* (*fp_gtk_hseparator_new)(); -static GtkWidget* (*fp_gtk_vseparator_new)(); -static GtkWidget* (*fp_gtk_image_new)(); -static GtkWidget* (*fp_gtk_label_new)(const gchar* str); -static GtkWidget* (*fp_gtk_menu_new)(); -static GtkWidget* (*fp_gtk_menu_bar_new)(); -static GtkWidget* (*fp_gtk_menu_item_new)(); -static GtkWidget* (*fp_gtk_notebook_new)(); -static GtkWidget* (*fp_gtk_progress_bar_new)(); -static GtkWidget* (*fp_gtk_progress_bar_set_orientation)( - GtkProgressBar *pbar, - GtkProgressBarOrientation orientation); -static GtkWidget* (*fp_gtk_radio_button_new)(GSList *group); -static GtkWidget* (*fp_gtk_radio_menu_item_new)(GSList *group); -static GtkWidget* (*fp_gtk_scrolled_window_new)(GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -static GtkWidget* (*fp_gtk_separator_menu_item_new)(); -static GtkWidget* (*fp_gtk_separator_tool_item_new)(); -static GtkWidget* (*fp_gtk_text_view_new)(); -static GtkWidget* (*fp_gtk_toggle_button_new)(); -static GtkWidget* (*fp_gtk_toolbar_new)(); -static GtkWidget* (*fp_gtk_tree_view_new)(); -static GtkWidget* (*fp_gtk_viewport_new)(GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -static GtkWidget* (*fp_gtk_window_new)(GtkWindowType type); -static GtkWidget* (*fp_gtk_dialog_new)(); -static GtkWidget* (*fp_gtk_spin_button_new)(GtkAdjustment *adjustment, - gdouble climb_rate, guint digits); -static GtkWidget* (*fp_gtk_frame_new)(const gchar *label); - -/* Other widget operations */ -static GtkAdjustment* (*fp_gtk_adjustment_new)(gdouble value, - gdouble lower, gdouble upper, gdouble step_increment, - gdouble page_increment, gdouble page_size); -static void (*fp_gtk_container_add)(GtkContainer *window, GtkWidget *widget); -static void (*fp_gtk_menu_shell_append)(GtkMenuShell *menu_shell, - GtkWidget *child); -static void (*fp_gtk_menu_item_set_submenu)(GtkMenuItem *menu_item, - GtkWidget *submenu); -static void (*fp_gtk_widget_realize)(GtkWidget *widget); -static GdkPixbuf* (*fp_gtk_widget_render_icon)(GtkWidget *widget, - const gchar *stock_id, GtkIconSize size, const gchar *detail); -static void (*fp_gtk_widget_set_name)(GtkWidget *widget, const gchar *name); -static void (*fp_gtk_widget_set_parent)(GtkWidget *widget, GtkWidget *parent); -static void (*fp_gtk_widget_set_direction)(GtkWidget *widget, - GtkTextDirection direction); -static void (*fp_gtk_widget_style_get)(GtkWidget *widget, - const gchar *first_property_name, ...); -static void (*fp_gtk_widget_class_install_style_property)( - GtkWidgetClass* class, GParamSpec *pspec); -static GParamSpec* (*fp_gtk_widget_class_find_style_property)( - GtkWidgetClass* class, const gchar* property_name); -static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget, - const gchar* property_name, GValue* value); -static char* (*fp_pango_font_description_to_string)( - const PangoFontDescription* fd); -static GtkSettings* (*fp_gtk_settings_get_default)(); -static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget); -static GType (*fp_gtk_border_get_type)(); -static void (*fp_gtk_arrow_set)(GtkWidget* arrow, - GtkArrowType arrow_type, - GtkShadowType shadow_type); -static void (*fp_gtk_widget_size_request)(GtkWidget *widget, - GtkRequisition *requisition); -static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range); - -#endif /* !_GTK3_INTERFACE_H */ diff --git a/app/src/main/jni/awt_xawt/awt/gtk_interface.c b/app/src/main/jni/awt_xawt/awt/gtk_interface.c deleted file mode 100644 index a45245cb4..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk_interface.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include -#include -#include "jvm_md.h" -#include "gtk_interface.h" - -GtkApi* gtk2_load(JNIEnv *env, const char* lib_name); -GtkApi* gtk3_load(JNIEnv *env, const char* lib_name); - -gboolean gtk2_check(const char* lib_name, gboolean load); -gboolean gtk3_check(const char* lib_name, gboolean load); - -GtkApi *gtk; - -typedef struct { - GtkVersion version; - const char* name; - const char* vname; - GtkApi* (*load)(JNIEnv *env, const char* lib_name); - gboolean (*check)(const char* lib_name, gboolean load); -} GtkLib; - -static GtkLib gtk_libs[] = { - { - GTK_3, - JNI_LIB_NAME("gtk-3"), - VERSIONED_JNI_LIB_NAME("gtk-3", "0"), - >k3_load, - >k3_check - }, - { - GTK_2, - JNI_LIB_NAME("gtk-x11-2.0"), - VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"), - >k2_load, - >k2_check - } -}; - -static GtkLib** get_libs_order(GtkVersion version) { - static GtkLib** load_order; - static int n_libs = 0; - if (!n_libs) { - n_libs = sizeof(gtk_libs) / sizeof(GtkLib); - load_order = calloc(n_libs + 1, sizeof(GtkLib *)); - } - int i, first = 0; - for (i = 0; i < n_libs; i++) { - load_order[i] = >k_libs[i]; - if (load_order[i]->version == version) { - first = i; - } - } - if (first) { - for (i = first; i > 0; i--) { - load_order[i] = load_order[i - 1]; - } - load_order[0] = >k_libs[first]; - } - return load_order; -} - -static GtkLib* get_loaded() { - GtkLib** libs = get_libs_order(GTK_ANY); - while(!gtk && *libs) { - GtkLib* lib = *libs++; - if (lib->check(lib->vname, /* load = */FALSE)) { - return lib; - } - if (lib->check(lib->name, /* load = */FALSE)) { - return lib; - } - } - return NULL; -} - -gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) { - if (gtk == NULL) { - GtkLib* lib = get_loaded(); - if (lib) { - if (verbose) { - fprintf(stderr, "Looking for GTK%d library...\n", - lib->version); - } - gtk = lib->load(env, lib->vname); - if (!gtk) { - gtk = lib->load(env, lib->name); - } - } else { - GtkLib** libs = get_libs_order(version); - while (!gtk && *libs) { - lib = *libs++; - if (version == GTK_ANY || lib->version == version) { - if (verbose) { - fprintf(stderr, "Looking for GTK%d library...\n", - lib->version); - } - gtk = lib->load(env, lib->vname); - if (!gtk) { - gtk = lib->load(env, lib->name); - } - if (verbose && !gtk) { - fprintf(stderr, "Not found.\n"); - } - } - } - } - if (verbose) { - if (gtk) { - fprintf(stderr, "GTK%d library loaded.\n", lib->version); - } else { - fprintf(stderr, "Failed to load GTK library.\n"); - } - } - } - return gtk != NULL; -} - -static gboolean check_version(GtkVersion version) { - GtkLib** libs = get_libs_order(version); - while (*libs) { - GtkLib* lib = *libs++; - if (lib->check(lib->vname, /* load = */TRUE)) { - return TRUE; - } - if (lib->check(lib->name, /* load = */TRUE)) { - return TRUE; - } - } - return FALSE; -} - -gboolean gtk_check_version(GtkVersion version) { - if (gtk || get_loaded()) { - return TRUE; - } - return check_version(version); -} - diff --git a/app/src/main/jni/awt_xawt/awt/gtk_interface.h b/app/src/main/jni/awt_xawt/awt/gtk_interface.h deleted file mode 100644 index a2021ff02..000000000 --- a/app/src/main/jni/awt_xawt/awt/gtk_interface.h +++ /dev/null @@ -1,570 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#ifndef _GTK_INTERFACE_H -#define _GTK_INTERFACE_H - -#include -#include - -#ifndef FALSE -#define FALSE (0) -#define TRUE (!FALSE) -#endif - -#define GTHREAD_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gthread-2.0", "0") -#define GTHREAD_LIB JNI_LIB_NAME("gthread-2.0") - -#define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip) -#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) \ - (_G_TYPE_CIC ((instance), (g_type), c_type)) -#define GTK_TYPE_FILE_CHOOSER (fp_gtk_file_chooser_get_type ()) -#define GTK_FILE_CHOOSER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_CHOOSER, GtkFileChooser)) -#define G_CALLBACK(f) ((GCallback) (f)) -#define G_TYPE_FUNDAMENTAL_SHIFT (2) -#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT)) -#define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20) -#define GTK_STOCK_CANCEL "gtk-cancel" -#define GTK_STOCK_SAVE "gtk-save" -#define GTK_STOCK_OPEN "gtk-open" -#define GDK_CURRENT_TIME 0L - -#define G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL (0) -#define G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL (1) -#define G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL (2) -#define G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL (3) -#define G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL (4) -#define G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL (5) -#define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6) -#define G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL (7) -#define G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL (8) -#define G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL (9) -#define G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL (10) -#define G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL (11) -#define G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL (12) -#define G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL (13) -#define G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL (14) -#define G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL (15) -#define G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL (16) -#define G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL (17) -#define G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL (18) -#define G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL (19) -#define G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL (20) - -#define GTK_TYPE_BORDER ((*fp_gtk_border_get_type)()) - -#define G_TYPE_FUNDAMENTAL_SHIFT (2) -#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT)) - -#ifndef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -#define CONV_BUFFER_SIZE 128 -#define NO_SYMBOL_EXCEPTION 1 - -/* basic types */ -typedef char gchar; -typedef short gshort; -typedef int gint; -typedef long glong; -typedef float gfloat; -typedef double gdouble; -typedef void* gpointer; -typedef gint gboolean; -typedef signed char gint8; -typedef signed short gint16; -typedef signed int gint32; -typedef unsigned char guchar; -typedef unsigned char guint8; -typedef unsigned short gushort; -typedef unsigned short guint16; -typedef unsigned int guint; -typedef unsigned int guint32; -typedef unsigned int gsize; -typedef unsigned long gulong; -typedef signed long long gint64; -typedef unsigned long long guint64; -typedef gulong GType; - -typedef struct _GList GList; -struct _GList -{ - gpointer data; - GList *next; - GList *prev; -}; - -typedef struct _GSList GSList; -struct _GSList { - gpointer data; - GSList *next; -}; - -typedef enum { - BUTTON, /* GtkButton */ - CHECK_BOX, /* GtkCheckButton */ - CHECK_BOX_MENU_ITEM, /* GtkCheckMenuItem */ - COLOR_CHOOSER, /* GtkColorSelectionDialog */ - COMBO_BOX, /* GtkComboBox */ - COMBO_BOX_ARROW_BUTTON, /* GtkComboBoxEntry */ - COMBO_BOX_TEXT_FIELD, /* GtkComboBoxEntry */ - DESKTOP_ICON, /* GtkLabel */ - DESKTOP_PANE, /* GtkContainer */ - EDITOR_PANE, /* GtkTextView */ - FORMATTED_TEXT_FIELD, /* GtkEntry */ - HANDLE_BOX, /* GtkHandleBox */ - HPROGRESS_BAR, /* GtkProgressBar */ - HSCROLL_BAR, /* GtkHScrollbar */ - HSCROLL_BAR_BUTTON_LEFT, /* GtkHScrollbar */ - HSCROLL_BAR_BUTTON_RIGHT, /* GtkHScrollbar */ - HSCROLL_BAR_TRACK, /* GtkHScrollbar */ - HSCROLL_BAR_THUMB, /* GtkHScrollbar */ - HSEPARATOR, /* GtkHSeparator */ - HSLIDER, /* GtkHScale */ - HSLIDER_TRACK, /* GtkHScale */ - HSLIDER_THUMB, /* GtkHScale */ - HSPLIT_PANE_DIVIDER, /* GtkHPaned */ - INTERNAL_FRAME, /* GtkWindow */ - INTERNAL_FRAME_TITLE_PANE, /* GtkLabel */ - IMAGE, /* GtkImage */ - LABEL, /* GtkLabel */ - LIST, /* GtkTreeView */ - MENU, /* GtkMenu */ - MENU_BAR, /* GtkMenuBar */ - MENU_ITEM, /* GtkMenuItem */ - MENU_ITEM_ACCELERATOR, /* GtkLabel */ - OPTION_PANE, /* GtkMessageDialog */ - PANEL, /* GtkContainer */ - PASSWORD_FIELD, /* GtkEntry */ - POPUP_MENU, /* GtkMenu */ - POPUP_MENU_SEPARATOR, /* GtkSeparatorMenuItem */ - RADIO_BUTTON, /* GtkRadioButton */ - RADIO_BUTTON_MENU_ITEM, /* GtkRadioMenuItem */ - ROOT_PANE, /* GtkContainer */ - SCROLL_PANE, /* GtkScrolledWindow */ - SPINNER, /* GtkSpinButton */ - SPINNER_ARROW_BUTTON, /* GtkSpinButton */ - SPINNER_TEXT_FIELD, /* GtkSpinButton */ - SPLIT_PANE, /* GtkPaned */ - TABBED_PANE, /* GtkNotebook */ - TABBED_PANE_TAB_AREA, /* GtkNotebook */ - TABBED_PANE_CONTENT, /* GtkNotebook */ - TABBED_PANE_TAB, /* GtkNotebook */ - TABLE, /* GtkTreeView */ - TABLE_HEADER, /* GtkButton */ - TEXT_AREA, /* GtkTextView */ - TEXT_FIELD, /* GtkEntry */ - TEXT_PANE, /* GtkTextView */ - TITLED_BORDER, /* GtkFrame */ - TOGGLE_BUTTON, /* GtkToggleButton */ - TOOL_BAR, /* GtkToolbar */ - TOOL_BAR_DRAG_WINDOW, /* GtkToolbar */ - TOOL_BAR_SEPARATOR, /* GtkSeparatorToolItem */ - TOOL_TIP, /* GtkWindow */ - TREE, /* GtkTreeView */ - TREE_CELL, /* GtkTreeView */ - VIEWPORT, /* GtkViewport */ - VPROGRESS_BAR, /* GtkProgressBar */ - VSCROLL_BAR, /* GtkVScrollbar */ - VSCROLL_BAR_BUTTON_UP, /* GtkVScrollbar */ - VSCROLL_BAR_BUTTON_DOWN, /* GtkVScrollbar */ - VSCROLL_BAR_TRACK, /* GtkVScrollbar */ - VSCROLL_BAR_THUMB, /* GtkVScrollbar */ - VSEPARATOR, /* GtkVSeparator */ - VSLIDER, /* GtkVScale */ - VSLIDER_TRACK, /* GtkVScale */ - VSLIDER_THUMB, /* GtkVScale */ - VSPLIT_PANE_DIVIDER, /* GtkVPaned */ - WIDGET_TYPE_SIZE -} WidgetType; - -typedef enum -{ - _GTK_ARROW_TYPE, - _GTK_BUTTON_TYPE, - _GTK_CHECK_BUTTON_TYPE, - _GTK_CHECK_MENU_ITEM_TYPE, - _GTK_COLOR_SELECTION_DIALOG_TYPE, - _GTK_COMBO_BOX_TYPE, - _GTK_COMBO_BOX_ARROW_BUTTON_TYPE, - _GTK_COMBO_BOX_TEXT_FIELD_TYPE, - _GTK_CONTAINER_TYPE, - _GTK_ENTRY_TYPE, - _GTK_FRAME_TYPE, - _GTK_HANDLE_BOX_TYPE, - _GTK_HPANED_TYPE, - _GTK_HPROGRESS_BAR_TYPE, - _GTK_HSCALE_TYPE, - _GTK_HSCROLLBAR_TYPE, - _GTK_HSEPARATOR_TYPE, - _GTK_IMAGE_TYPE, - _GTK_MENU_TYPE, - _GTK_MENU_BAR_TYPE, - _GTK_MENU_ITEM_TYPE, - _GTK_NOTEBOOK_TYPE, - _GTK_LABEL_TYPE, - _GTK_RADIO_BUTTON_TYPE, - _GTK_RADIO_MENU_ITEM_TYPE, - _GTK_SCROLLED_WINDOW_TYPE, - _GTK_SEPARATOR_MENU_ITEM_TYPE, - _GTK_SEPARATOR_TOOL_ITEM_TYPE, - _GTK_SPIN_BUTTON_TYPE, - _GTK_TEXT_VIEW_TYPE, - _GTK_TOGGLE_BUTTON_TYPE, - _GTK_TOOLBAR_TYPE, - _GTK_TOOLTIP_TYPE, - _GTK_TREE_VIEW_TYPE, - _GTK_VIEWPORT_TYPE, - _GTK_VPANED_TYPE, - _GTK_VPROGRESS_BAR_TYPE, - _GTK_VSCALE_TYPE, - _GTK_VSCROLLBAR_TYPE, - _GTK_VSEPARATOR_TYPE, - _GTK_WINDOW_TYPE, - _GTK_DIALOG_TYPE, - _GTK_WIDGET_TYPE_SIZE -} GtkWidgetType; - -typedef enum -{ - GTK_STATE_NORMAL, - GTK_STATE_ACTIVE, - GTK_STATE_PRELIGHT, - GTK_STATE_SELECTED, - GTK_STATE_INSENSITIVE, - GTK_STATE_INCONSISTENT, - GTK_STATE_FOCUSED -} GtkStateType; - -typedef enum -{ - GTK_SHADOW_NONE, - GTK_SHADOW_IN, - GTK_SHADOW_OUT, - GTK_SHADOW_ETCHED_IN, - GTK_SHADOW_ETCHED_OUT -} GtkShadowType; - -typedef enum -{ - GTK_EXPANDER_COLLAPSED, - GTK_EXPANDER_SEMI_COLLAPSED, - GTK_EXPANDER_SEMI_EXPANDED, - GTK_EXPANDER_EXPANDED -} GtkExpanderStyle; - -typedef enum -{ - GTK_ICON_SIZE_INVALID, - GTK_ICON_SIZE_MENU, - GTK_ICON_SIZE_SMALL_TOOLBAR, - GTK_ICON_SIZE_LARGE_TOOLBAR, - GTK_ICON_SIZE_BUTTON, - GTK_ICON_SIZE_DND, - GTK_ICON_SIZE_DIALOG -} GtkIconSize; - -typedef enum -{ - GTK_ORIENTATION_HORIZONTAL, - GTK_ORIENTATION_VERTICAL -} GtkOrientation; - -typedef enum -{ - FOREGROUND, - BACKGROUND, - TEXT_FOREGROUND, - TEXT_BACKGROUND, - FOCUS, - LIGHT, - DARK, - MID, - BLACK, - WHITE -} ColorType; - -typedef enum -{ - GTK_FONT_NAME, - GTK_ICON_SIZES, - GTK_CURSOR_BLINK, - GTK_CURSOR_BLINK_TIME -} Setting; - -typedef enum -{ - GTK_ARROW_UP, - GTK_ARROW_DOWN, - GTK_ARROW_LEFT, - GTK_ARROW_RIGHT, - GTK_ARROW_NONE -} GtkArrowType; - -typedef enum -{ - GTK_TEXT_DIR_NONE, - GTK_TEXT_DIR_LTR, - GTK_TEXT_DIR_RTL -} GtkTextDirection; - -typedef enum -{ - GTK_POS_LEFT, - GTK_POS_RIGHT, - GTK_POS_TOP, - GTK_POS_BOTTOM -} GtkPositionType; - -/* SynthConstants */ -static const gint ENABLED = 1 << 0; -static const gint MOUSE_OVER = 1 << 1; -static const gint PRESSED = 1 << 2; -static const gint DISABLED = 1 << 3; -static const gint FOCUSED = 1 << 8; -static const gint SELECTED = 1 << 9; -static const gint DEFAULT = 1 << 10; - -typedef enum -{ - GTK_ANY, - GTK_1, - GTK_2, - GTK_3 -} GtkVersion; - -//------------------------------ - - - -typedef enum { - GTK_RESPONSE_NONE = -1, - GTK_RESPONSE_REJECT = -2, - GTK_RESPONSE_ACCEPT = -3, - GTK_RESPONSE_DELETE_EVENT = -4, - GTK_RESPONSE_OK = -5, - GTK_RESPONSE_CANCEL = -6, - GTK_RESPONSE_CLOSE = -7, - GTK_RESPONSE_YES = -8, - GTK_RESPONSE_NO = -9, - GTK_RESPONSE_APPLY = -10, - GTK_RESPONSE_HELP = -11 -} GtkResponseType; - -typedef enum { - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER -} GtkFileChooserAction; - -typedef enum { - GTK_FILE_FILTER_FILENAME = 1 << 0, - GTK_FILE_FILTER_URI = 1 << 1, - GTK_FILE_FILTER_DISPLAY_NAME = 1 << 2, - GTK_FILE_FILTER_MIME_TYPE = 1 << 3 -} GtkFileFilterFlags; - -typedef enum { - GDK_COLORSPACE_RGB -} GdkColorspace; - -typedef enum { - GDK_INTERP_NEAREST, - GDK_INTERP_TILES, - GDK_INTERP_BILINEAR, - GDK_INTERP_HYPER -} GdkInterpType; - -typedef enum { - G_CONNECT_AFTER = 1 << 0, G_CONNECT_SWAPPED = 1 << 1 -} GConnectFlags; -//------------------------------ - - -typedef void GError; -typedef void GdkScreen; -typedef void GtkWindow; -typedef void GdkWindow; -typedef void GClosure; -typedef void GtkFileChooser; -typedef void GtkFileFilter; -typedef struct { - GtkFileFilterFlags contains; - const gchar *filename; - const gchar *uri; - const gchar *display_name; - const gchar *mime_type; -} GtkFileFilterInfo; -typedef gboolean (*GtkFileFilterFunc)(const GtkFileFilterInfo *filter_info, - gpointer data); -typedef void (*GClosureNotify)(gpointer data, GClosure *closure); -typedef void (*GDestroyNotify)(gpointer data); -typedef void (*GCallback)(void); - - -typedef struct GtkApi { - int version; - gboolean (*show_uri_load)(JNIEnv *env); - gboolean (*unload)(); - void (*flush_event_loop)(); - gchar* (*gtk_check_version)(guint required_major, guint required_minor, - guint required_micro); - jobject (*get_setting)(JNIEnv *env, Setting property); - - void (*paint_arrow)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkArrowType arrow_type, gboolean fill); - void (*paint_box)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir); - void (*paint_box_gap)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - GtkPositionType gap_side, gint gap_x, gint gap_width); - void (*paint_expander)(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height, - GtkExpanderStyle expander_style); - void (*paint_extension)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkPositionType gap_side); - void (*paint_flat_box)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, gboolean has_focus); - void (*paint_focus)(WidgetType widget_type, GtkStateType state_type, - const char *detail, gint x, gint y, gint width, gint height); - void (*paint_handle)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation); - void (*paint_hline)(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height); - void (*paint_vline)(WidgetType widget_type, GtkStateType state_type, - const gchar *detail, gint x, gint y, gint width, gint height); - void (*paint_option)(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height); - void (*paint_shadow)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, - gint synth_state, GtkTextDirection dir); - void (*paint_slider)(WidgetType widget_type, GtkStateType state_type, - GtkShadowType shadow_type, const gchar *detail, - gint x, gint y, gint width, gint height, GtkOrientation orientation, - gboolean has_focus); - void (*paint_background)(WidgetType widget_type, GtkStateType state_type, - gint x, gint y, gint width, gint height); - void (*paint_check)(WidgetType widget_type, gint synth_state, - const gchar *detail, gint x, gint y, gint width, gint height); - void (*set_range_value)(WidgetType widget_type, jdouble value, - jdouble min, jdouble max, jdouble visible); - - void (*init_painting)(JNIEnv *env, gint w, gint h); - gint (*copy_image)(gint *dest, gint width, gint height); - - gint (*get_xthickness)(JNIEnv *env, WidgetType widget_type); - gint (*get_ythickness)(JNIEnv *env, WidgetType widget_type); - gint (*get_color_for_state)(JNIEnv *env, WidgetType widget_type, - GtkStateType state_type, ColorType color_type); - jobject (*get_class_value)(JNIEnv *env, WidgetType widget_type, - const char* key); - - jstring (*get_pango_font_name)(JNIEnv *env, WidgetType widget_type); - jboolean (*get_icon_data)(JNIEnv *env, gint widget_type, - const gchar *stock_id, GtkIconSize size, - GtkTextDirection direction, const char *detail, - jmethodID icon_upcall_method, jobject this); - jboolean (*get_file_icon_data)(JNIEnv *env, const char *filename, - GError **error, jmethodID icon_upcall_method, jobject this); - void (*gdk_threads_enter)(void); - void (*gdk_threads_leave)(void); - gboolean (*gtk_show_uri)(GdkScreen *screen, const gchar *uri, - guint32 timestamp, GError **error); - gboolean (*get_drawable_data)(JNIEnv *env, jintArray pixelArray, - jint x, jint y, jint width, jint height, - jint jwidth, int dx, int dy, jint scale); - void (*g_free)(gpointer mem); - - - gchar* (*gtk_file_chooser_get_filename)(GtkFileChooser *chooser); - void (*gtk_widget_hide)(void* widget); - void (*gtk_main_quit)(void); - void* (*gtk_file_chooser_dialog_new)(const gchar *title, - GtkWindow *parent, GtkFileChooserAction action, - const gchar *first_button_text, ...); - gboolean (*gtk_file_chooser_set_current_folder)(GtkFileChooser *chooser, - const gchar *filename); - gboolean (*gtk_file_chooser_set_filename)(GtkFileChooser *chooser, - const char *filename); - void (*gtk_file_chooser_set_current_name)(GtkFileChooser *chooser, - const gchar *name); - void (*gtk_file_filter_add_custom)(GtkFileFilter *filter, - GtkFileFilterFlags needed, GtkFileFilterFunc func, gpointer data, - GDestroyNotify notify); - void (*gtk_file_chooser_set_filter)(GtkFileChooser *chooser, - GtkFileFilter *filter); - GType (*gtk_file_chooser_get_type)(void); - GtkFileFilter* (*gtk_file_filter_new)(void); - void (*gtk_file_chooser_set_do_overwrite_confirmation)( - GtkFileChooser *chooser, gboolean do_overwrite_confirmation); - void (*gtk_file_chooser_set_select_multiple)( - GtkFileChooser *chooser, gboolean select_multiple); - gchar* (*gtk_file_chooser_get_current_folder)(GtkFileChooser *chooser); - GSList* (*gtk_file_chooser_get_filenames)(GtkFileChooser *chooser); - guint (*gtk_g_slist_length)(GSList *list); - gulong (*g_signal_connect_data)(gpointer instance, - const gchar *detailed_signal, GCallback c_handler, gpointer data, - GClosureNotify destroy_data, GConnectFlags connect_flags); - void (*gtk_widget_show)(void *widget); - void (*gtk_main)(void); - guint (*gtk_main_level)(void); - gchar* (*g_path_get_dirname) (const gchar *file_name); - XID (*gdk_x11_drawable_get_xid) (void *drawable); - void (*gtk_widget_destroy)(void *widget); - void (*gtk_window_present)(void *window); - void (*gtk_window_move)(void *window, gint x, gint y); - void (*gtk_window_resize)(void *window, gint width, gint height); - GdkWindow *(*get_window)(void *widget); - - void (*g_object_unref)(gpointer object); - GList* (*g_list_append) (GList *list, gpointer data); - void (*g_list_free) (GList *list); - void (*g_list_free_full) (GList *list, GDestroyNotify free_func); -} GtkApi; - -gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose); -gboolean gtk_check_version(GtkVersion version); - -typedef struct _GThreadFunctions GThreadFunctions; -static gboolean (*fp_g_thread_get_initialized)(void); -static void (*fp_g_thread_init)(GThreadFunctions *vtable); -static void (*fp_gdk_threads_init)(void); -static void (*fp_gdk_threads_enter)(void); -static void (*fp_gdk_threads_leave)(void); - -extern GtkApi* gtk; - -#endif /* !_GTK_INTERFACE_H */ diff --git a/app/src/main/jni/awt_xawt/awt/list.c b/app/src/main/jni/awt_xawt/awt/list.c deleted file mode 100644 index af3fcb929..000000000 --- a/app/src/main/jni/awt_xawt/awt/list.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* $XConsortium: list.c /main/4 1996/10/14 15:03:56 swick $ */ -/** ------------------------------------------------------------------------ - This file contains routines for manipulating generic lists. - Lists are implemented with a "harness". In other words, each - node in the list consists of two pointers, one to the data item - and one to the next node in the list. The head of the list is - the same struct as each node, but the "item" ptr is used to point - to the current member of the list (used by the first_in_list and - next_in_list functions). - - This file is available under and governed by the GNU General Public - License version 2 only, as published by the Free Software Foundation. - However, the following notice accompanied the original version of this - file: - -Copyright (c) 1994 Hewlett-Packard Co. -Copyright (c) 1996 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - - ----------------------------------------------------------------------- **/ - -#include -#include -#include "list.h" - - -/** ------------------------------------------------------------------------ - Sets the pointers of the specified list to NULL. - --------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -void zero_list(list_ptr lp) -#else -void zero_list(lp) - list_ptr lp; -#endif -{ - lp->next = NULL; - lp->ptr.item = NULL; -} - - -/** ------------------------------------------------------------------------ - Adds item to the list pointed to by lp. Finds the end of the - list, then mallocs a new list node onto the end of the list. - The item pointer in the new node is set to "item" passed in, - and the next pointer in the new node is set to NULL. - Returns 1 if successful, 0 if the malloc failed. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -int32_t add_to_list(list_ptr lp, void *item) -#else -int32_t add_to_list(lp, item) - list_ptr lp; - void *item; -#endif -{ - while (lp->next) { - lp = lp->next; - } - if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) { - - return 0; - } - lp->next->ptr.item = item; - lp->next->next = NULL; - - return 1; -} - - -/** ------------------------------------------------------------------------ - Creates a new list and sets its pointers to NULL. - Returns a pointer to the new list. - -------------------------------------------------------------------- **/ -list_ptr new_list () -{ - list_ptr lp; - - if (lp = (list_ptr) malloc( sizeof( list_item))) { - lp->next = NULL; - lp->ptr.item = NULL; - } - - return lp; -} - - -/** ------------------------------------------------------------------------ - Creates a new list head, pointing to the same list as the one - passed in. If start_at_curr is TRUE, the new list's first item - is the "current" item (as set by calls to first/next_in_list()). - If start_at_curr is FALSE, the first item in the new list is the - same as the first item in the old list. In either case, the - curr pointer in the new list is the same as in the old list. - Returns a pointer to the new list head. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr) -#else -list_ptr dup_list_head(lp, start_at_curr) - list_ptr lp; - int32_t start_at_curr; -#endif -{ - list_ptr new_list; - - if ((new_list = (list_ptr) malloc( sizeof( list_item))) == NULL) { - - return (list_ptr)NULL; - } - new_list->next = start_at_curr ? lp->ptr.curr : lp->next; - new_list->ptr.curr = lp->ptr.curr; - - return new_list; -} - - -/** ------------------------------------------------------------------------ - Returns the number of items in the list. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -uint32_t list_length(list_ptr lp) -#else -uint32_t list_length(lp) - list_ptr lp; -#endif -{ - uint32_t count = 0; - - while (lp->next) { - count++; - lp = lp->next; - } - - return count; -} - - -/** ------------------------------------------------------------------------ - Scans thru list, looking for a node whose ptr.item is equal to - the "item" passed in. "Equal" here means the same address - no - attempt is made to match equivalent values stored in different - locations. If a match is found, that node is deleted from the - list. Storage for the node is freed, but not for the item itself. - Returns a pointer to the item, so the caller can free it if it - so desires. If a match is not found, returns NULL. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -void *delete_from_list(list_ptr lp, void *item) -#else -void *delete_from_list(lp, item) - list_ptr lp; - void *item; -#endif -{ - list_ptr new_next; - - while (lp->next) { - if (lp->next->ptr.item == item) { - new_next = lp->next->next; - free (lp->next); - lp->next = new_next; - - return item; - } - lp = lp->next; - } - - return NULL; -} - - -/** ------------------------------------------------------------------------ - Deletes each node in the list *except the head*. This allows - the deletion of lists where the head is not malloced or created - with new_list(). If free_items is true, each item pointed to - from the node is freed, in addition to the node itself. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -void delete_list(list_ptr lp, int32_t free_items) -#else -void delete_list(lp, free_items) - list_ptr lp; - int32_t free_items; -#endif -{ - list_ptr del_node; - void *item; - - while (lp->next) { - del_node = lp->next; - item = del_node->ptr.item; - lp->next = del_node->next; - free (del_node); - if (free_items) { - free( item); - } - } -} - -#if NeedFunctionPrototypes -void delete_list_destroying(list_ptr lp, void destructor(void *item)) -#else -void delete_list_destroying(lp, destructor) - list_ptr lp; - void (*destructor)(); -#endif -{ - list_ptr del_node; - void *item; - - while (lp->next) { - del_node = lp->next; - item = del_node->ptr.item; - lp->next = del_node->next; - free( del_node); - if (destructor) { - destructor( item); - } - } -} - - -/** ------------------------------------------------------------------------ - Returns a ptr to the first *item* (not list node) in the list. - Sets the list head node's curr ptr to the first node in the list. - Returns NULL if the list is empty. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -void * first_in_list(list_ptr lp) -#else -void * first_in_list(lp) - list_ptr lp; -#endif -{ - if (! lp) { - - return NULL; - } - lp->ptr.curr = lp->next; - - return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL; -} - -/** ------------------------------------------------------------------------ - Returns a ptr to the next *item* (not list node) in the list. - Sets the list head node's curr ptr to the next node in the list. - first_in_list must have been called prior. - Returns NULL if no next item. - -------------------------------------------------------------------- **/ -#if NeedFunctionPrototypes -void * next_in_list(list_ptr lp) -#else -void * next_in_list(lp) - list_ptr lp; -#endif -{ - if (! lp) { - - return NULL; - } - if (lp->ptr.curr) { - lp->ptr.curr = lp->ptr.curr->next; - } - - return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL; -} - -#if NeedFunctionPrototypes -int32_t list_is_empty(list_ptr lp) -#else -int32_t list_is_empty(lp) - list_ptr lp; -#endif -{ - return (lp == NULL || lp->next == NULL); -} diff --git a/app/src/main/jni/awt_xawt/awt/list.h b/app/src/main/jni/awt_xawt/awt/list.h deleted file mode 100644 index 7528b7c3e..000000000 --- a/app/src/main/jni/awt_xawt/awt/list.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* $XConsortium: list.h /main/4 1996/10/14 15:04:04 swick $ */ -/** ------------------------------------------------------------------------ - This file contains routines for manipulating generic lists. - Lists are implemented with a "harness". In other words, each - node in the list consists of two pointers, one to the data item - and one to the next node in the list. The head of the list is - the same struct as each node, but the "item" ptr is used to point - to the current member of the list (used by the first_in_list and - next_in_list functions). - - This file is available under and governed by the GNU General Public - License version 2 only, as published by the Free Software Foundation. - However, the following notice accompanied the original version of this - file: - -Copyright (c) 1994 Hewlett-Packard Co. -Copyright (c) 1996 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - - -------------------------------------------------------------------- **/ - -#include "gdefs.h" - -#ifndef LIST_DEF -#define LIST_DEF - -#define LESS -1 -#define EQUAL 0 -#define GREATER 1 -#define DUP_WHOLE_LIST 0 -#define START_AT_CURR 1 - -typedef struct _list_item { - struct _list_item *next; - union { - void *item; /* in normal list node, pts to data */ - struct _list_item *curr; /* in list head, pts to curr for 1st, next */ - } ptr; -} list, list_item, *list_ptr; - -typedef void (*DESTRUCT_FUNC_PTR)( -#if NeedFunctionPrototypes -void * -#endif -); - -void zero_list( -#if NeedFunctionPrototypes - list_ptr -#endif - ); -int32_t add_to_list ( -#if NeedFunctionPrototypes - list_ptr , void * -#endif - ); -list_ptr new_list ( -#if NeedFunctionPrototypes - void -#endif - ); -list_ptr dup_list_head ( -#if NeedFunctionPrototypes - list_ptr , int32_t -#endif - ); -uint32_t list_length( -#if NeedFunctionPrototypes - list_ptr -#endif - ); -void *delete_from_list ( -#if NeedFunctionPrototypes - list_ptr , void * -#endif - ); -void delete_list( -#if NeedFunctionPrototypes - list_ptr , int32_t -#endif - ); -void delete_list_destroying ( -#if NeedFunctionPrototypes - list_ptr , DESTRUCT_FUNC_PTR -#endif - ); -void *first_in_list ( -#if NeedFunctionPrototypes - list_ptr -#endif - ); -void *next_in_list ( -#if NeedFunctionPrototypes - list_ptr -#endif - ); -int32_t list_is_empty ( -#if NeedFunctionPrototypes - list_ptr -#endif - ); - -#endif diff --git a/app/src/main/jni/awt_xawt/awt/multiVis.c b/app/src/main/jni/awt_xawt/awt/multiVis.c deleted file mode 100644 index aca780906..000000000 --- a/app/src/main/jni/awt_xawt/awt/multiVis.c +++ /dev/null @@ -1,1215 +0,0 @@ -/* - * Copyright (c) 1999, 2013, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* $XConsortium: multiVis.c /main/4 1996/10/14 15:04:08 swick $ */ -/** ------------------------------------------------------------------------ - This file contains functions to create a list of regions which - tile a specified window. Each region contains all visible - portions of the window which are drawn with the same visual. - If the window consists of subwindows of two different visual types, - there will be two regions in the list. The list can be traversed - to correctly pull an image of the window using XGetImage or the - Image Library. - - This file is available under and governed by the GNU General Public - License version 2 only, as published by the Free Software Foundation. - However, the following notice accompanied the original version of this - file: - -Copyright (c) 1994 Hewlett-Packard Co. -Copyright (c) 1996 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - - ------------------------------------------------------------------------ **/ -#include -#include -#include -#include -#include -#include "list.h" -#include "wsutils.h" -#include "multiVis.h" -#include "robot_common.h" - -static char *vis_class_str[] = { "StaticGray" , "GrayScale" , "StaticColor", - "PseudoColor","TrueColor","DirectColor" } ; -/* These structures are copied from X11/region.h. For some reason - * they're invisible from the outside.*/ - -typedef struct { - short x1, x2, y1, y2; -} myBox, myBOX, myBoxRec, *myBoxPtr; - -typedef struct my_XRegion { /* 64-bit: Region is supposed to be opaque */ - long size; /* but it is defined here anyway. I'm going */ - long numRects; /* to leave those longs alone. */ - myBOX *rects; - myBOX extents; -} myREGION; - -/* Items in long list of windows that have some part in the grabbed area */ -typedef struct { - Window win; - Visual *vis; - Colormap cmap; - int32_t x_rootrel, y_rootrel; /* root relative location of window */ - int32_t x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ - int32_t width, height; /* width and height of visible part */ - int32_t border_width; /* border width of the window */ - Window parent; /* id of parent (for debugging) */ -} image_win_type; - -/* Items in short list of regions that tile the grabbed area. May have - multiple windows in the region. -*/ -typedef struct { - Window win; /* lowest window of this visual */ - Visual *vis; - Colormap cmap; - int32_t x_rootrel, y_rootrel; /* root relative location of bottom window */ - int32_t x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ - int32_t width, height; /* w & h of visible rect of bottom window */ - int32_t border; /* border width of the window */ - Region visible_region; -} image_region_type; - -/** ------------------------------------------------------------------------ - Returns TRUE if the two structs pointed to have the same "vis" & - "cmap" fields and s2 lies completely within s1. s1 and s2 can - point to structs of image_win_type or image_region_type. - ------------------------------------------------------------------------ **/ -#define SAME_REGIONS( s1, s2) \ - ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap && \ - (s1)->x_vis <= (s2)->x_vis && \ - (s1)->y_vis <= (s2)->y_vis && \ - (s1)->x_vis + (s1)->width >= (s2)->x_vis + (s2)->width && \ - (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height) - -#ifndef MIN -#define MIN( a, b) ((a) < (b) ? a : b) -#define MAX( a, b) ((a) > (b) ? a : b) -#endif - -#define RED_SHIFT 16 -#define GREEN_SHIFT 8 -#define BLUE_SHIFT 0 - -/* -extern list_ptr new_list(); -extern list_ptr dup_list_head(); -extern void * first_in_list(); -extern void * next_in_list(); -extern int32_t add_to_list(); -extern void zero_list(); -extern void delete_list(); -extern void delete_list_destroying(); -extern uint32_t list_length(); -*/ - -/* Prototype Declarations for Static Functions */ -static void TransferImage( -#if NeedFunctionPrototypes - Display *, XImage *,int32_t, int32_t , image_region_type*, - XImage *,int32_t ,int32_t -#endif - ); -static XImage * ReadRegionsInList( -#if NeedFunctionPrototypes - Display *, Visual *, int32_t ,int32_t ,int32_t , - int32_t , XRectangle, list_ptr -#endif - ); - -static list_ptr make_region_list( -#if NeedFunctionPrototypes - Display*, Window, XRectangle*, - int32_t*, int32_t, XVisualInfo**, int32_t * -#endif - ); - -static void destroy_region_list( -#if NeedFunctionPrototypes - list_ptr -#endif - ) ; -static void subtr_rect_from_image_region( -#if NeedFunctionPrototypes - image_region_type *, int32_t , int32_t , int32_t , int32_t -#endif - ); -static void add_rect_to_image_region( -#if NeedFunctionPrototypes - image_region_type *, - int32_t , int32_t , int32_t , int32_t -#endif - ); -static int32_t src_in_region_list( -#if NeedFunctionPrototypes - image_win_type *, list_ptr -#endif - ); -static void add_window_to_list( -#if NeedFunctionPrototypes - list_ptr, Window, int32_t, int32_t , - int32_t , int32_t , int32_t , int32_t, int32_t, - Visual*, Colormap, Window -#endif - ); -static int32_t src_in_image( -#if NeedFunctionPrototypes - image_win_type *, int32_t , XVisualInfo** -#endif - ); -static int32_t src_in_overlay( -#if NeedFunctionPrototypes - image_region_type *, int32_t, OverlayInfo *, int32_t*, int32_t* -#endif - ); - -/* End of Prototype Declarations */ - -void initFakeVisual(Vis) -Visual *Vis ; -{ - Vis->ext_data=NULL; - Vis->class = DirectColor ; - Vis->red_mask = 0x00FF0000; - Vis->green_mask = 0x0000FF00 ; - Vis->blue_mask = 0x000000FF ; - Vis->map_entries = 256 ; - Vis->bits_per_rgb = 8 ; -} - -/* QueryColorMap has been moved into robot_common.c so it can be used by - * awt_DataTransferer.c as well. - */ - -int32_t -GetMultiVisualRegions(disp,srcRootWinid, x, y, width, height, - transparentOverlays,numVisuals, pVisuals,numOverlayVisuals, pOverlayVisuals, - numImageVisuals, pImageVisuals,vis_regions,vis_image_regions,allImage) - Display *disp; - Window srcRootWinid; /* root win on which grab was done */ - int32_t x; /* root rel UL corner of bounding box of grab */ - int32_t y; - uint32_t width; /* size of bounding box of grab */ - uint32_t height; - int32_t *transparentOverlays ; - int32_t *numVisuals; - XVisualInfo **pVisuals; - int32_t *numOverlayVisuals; - OverlayInfo **pOverlayVisuals; - int32_t *numImageVisuals; - XVisualInfo ***pImageVisuals; - list_ptr *vis_regions; /* list of regions to read from */ - list_ptr *vis_image_regions ; - int32_t *allImage ; -{ - int32_t hasNonDefault; - XRectangle bbox; /* bounding box of grabbed area */ - - - /* Java uses 32-bit ints for coordinates, but XRectangles use 16-bit shorts. - * Hope nobody passes in too big a coordinate */ - - bbox.x = (short) x; /* init X rect for bounding box */ - bbox.y = (short) y; - bbox.width = (unsigned short) width; - bbox.height = (unsigned short) height; - - GetXVisualInfo(disp,DefaultScreen(disp), - transparentOverlays, - numVisuals, pVisuals, - numOverlayVisuals, pOverlayVisuals, - numImageVisuals, pImageVisuals); - - *vis_regions = *vis_image_regions = NULL ; - if ((*vis_regions = make_region_list( disp, srcRootWinid, &bbox, - &hasNonDefault, *numImageVisuals, - *pImageVisuals, allImage)) == NULL) - return 0 ; - - if (*transparentOverlays) - { - *allImage = 1; /* until proven otherwise, - this flags that it to be an image only list */ - *vis_image_regions = - make_region_list( disp, srcRootWinid, &bbox, &hasNonDefault, - *numImageVisuals, *pImageVisuals, allImage); - } - - /* if there is a second region in any of the two lists return 1 **/ - if ( ( *vis_regions && (*vis_regions)->next && (*vis_regions)->next->next ) || - ( *vis_image_regions && (*vis_image_regions)->next && - (*vis_image_regions)->next->next ) ) return 1 ; - else return 0 ; - -} - -static void TransferImage(disp,reg_image,srcw,srch,reg, - target_image,dst_x,dst_y) -Display *disp; -XImage *reg_image,*target_image ; -image_region_type *reg; -int32_t srcw,srch,dst_x , dst_y ; -{ - int32_t ncolors; - int32_t i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ; - XColor *colors; - int32_t rShift,gShift,bShift; - int32_t targetBytesPerLine ; - - ncolors = QueryColorMap(disp,reg->cmap,reg->vis,&colors, - &rShift,&gShift,&bShift) ; - - targetBytesPerLine = target_image->bytes_per_line; - - switch (reg->vis->class) { - case TrueColor : - for(i=0 ; i < srch ; i++) - { - for(j=0 ; j < srcw ; j++) - { - old_pixel = (int32_t) XGetPixel(reg_image,j,i) ; - -/* commented out since not using server RGB masks in all true color modes - * causes the R and B values to be swapped around on some X servers - * - robi.khan@eng 9/7/1999 - * if( reg->vis->map_entries == 16) { - */ - red_ind = (old_pixel & reg->vis->red_mask) >> rShift ; - green_ind = (old_pixel & reg->vis->green_mask) >> gShift ; - blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ; - - new_pixel = ( - ((colors[red_ind].red >> 8) << RED_SHIFT) - |((colors[green_ind].green >> 8) << GREEN_SHIFT) - |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) - ); -/* } - * else - * new_pixel = old_pixel; - */ - - XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - - } - } - break; - case DirectColor : - for(i=0 ; i < srch ; i++) - { - for(j=0 ; j < srcw ; j++) - { - old_pixel = (int32_t) XGetPixel(reg_image,j,i) ; - red_ind = (old_pixel & reg->vis->red_mask) >> rShift ; - green_ind = (old_pixel & reg->vis->green_mask) >> gShift ; - blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ; - - new_pixel = ( - ((colors[red_ind].red >> 8) << RED_SHIFT) - |((colors[green_ind].green >> 8) << GREEN_SHIFT) - |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) - ); - XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - - } - } - break; - default : - for(i=0 ; i < srch ; i++) - { - for(j=0 ; j < srcw ; j++) - { - old_pixel = (int32_t) XGetPixel(reg_image,j,i) ; - - new_pixel = ( - ((colors[old_pixel].red >> 8) << RED_SHIFT) - |((colors[old_pixel].green >> 8) << GREEN_SHIFT) - |((colors[old_pixel].blue >> 8) << BLUE_SHIFT) - ); - XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - - } - } - break; - } - - /* Fix memory leak by freeing colors - * - robi.khan@eng 9/22/1999 - */ - free(colors); -} - -static XImage * -ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions) -Display *disp ; -Visual *fakeVis ; -int32_t depth , width , height ; -int32_t format ; -XRectangle bbox; /* bounding box of grabbed area */ -list_ptr regions;/* list of regions to read from */ -{ - XImage *ximage ; - image_region_type* reg; - int32_t rect; - - ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL, - (uint32_t)width,(uint32_t)height,8,0); - - ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char)); - ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/ - - for (reg = (image_region_type *) first_in_list( regions); reg; - reg = (image_region_type *) next_in_list( regions)) - { - struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region); - for (rect = 0; rect < vis_reg->numRects; rect++) - { - /** ------------------------------------------------------------------------ - Intersect bbox with visible part of region giving src rect & output - location. Width is the min right side minus the max left side. - Similar for height. Offset src rect so x,y are relative to - origin of win, not the root-relative visible rect of win. - ------------------------------------------------------------------------ **/ - int32_t srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) - - MAX( vis_reg->rects[rect].x1, bbox.x); - - int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) - - MAX( vis_reg->rects[rect].y1, bbox.y); - - int32_t diff = bbox.x - vis_reg->rects[rect].x1; - int32_t srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border); - int32_t dst_x = MAX( 0, -diff) ; - - diff = bbox.y - vis_reg->rects[rect].y1; - int32_t srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border); - int32_t dst_y = MAX( 0, -diff) ; - XImage* reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y, - (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ; - - if (reg_image) { - TransferImage(disp,reg_image,srcRect_width, - srcRect_height,reg,ximage,dst_x,dst_y) ; - XDestroyImage(reg_image); - } - } - } - return ximage ; -} - - -/** ------------------------------------------------------------------------ - ------------------------------------------------------------------------ **/ - -XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height, - numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals, - pImageVisuals,vis_regions,vis_image_regions,format,allImage) - Display *disp; - Window srcRootWinid; /* root win on which grab was done */ - int32_t x; /* root rel UL corner of bounding box of grab */ - int32_t y; - uint32_t width; /* size of bounding box of grab */ - uint32_t height; - /** int32_t transparentOverlays; ***/ - int32_t numVisuals; - XVisualInfo *pVisuals; - int32_t numOverlayVisuals; - OverlayInfo *pOverlayVisuals; - int32_t numImageVisuals; - XVisualInfo **pImageVisuals; - list_ptr vis_regions; /* list of regions to read from */ - list_ptr vis_image_regions ;/* list of regions to read from */ - int32_t format; - int32_t allImage ; -{ - image_region_type *reg; - XRectangle bbox; /* bounding box of grabbed area */ - int32_t depth ; - XImage *ximage, *ximage_ipm ; - Visual fakeVis ; - int32_t x1, y1; - XImage *image; - unsigned char *pmData , *ipmData ; - int32_t transparentColor, transparentType; - int32_t srcRect_x,srcRect_y,srcRect_width,srcRect_height ; - int32_t diff ; - int32_t dst_x, dst_y; /* where in pixmap to write (UL) */ - int32_t pixel; - - bbox.x = (short) x; /* init X rect for bounding box */ - bbox.y = (short) y; - bbox.width = (unsigned short) width; - bbox.height = (unsigned short) height; - ximage_ipm = NULL; - - - initFakeVisual(&fakeVis) ; - - depth = 24 ; - ximage = ReadRegionsInList(disp,&fakeVis,depth,format, - (int32_t) width, (int32_t) height, bbox,vis_regions) ; - - pmData = (unsigned char *)ximage -> data ; - -/* if transparency possible do it again, but this time for image planes only */ - if (vis_image_regions && (vis_image_regions->next) && !allImage) - { - ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format, - (int32_t) width, (int32_t) height,bbox,vis_image_regions) ; - ipmData = (unsigned char *)ximage_ipm -> data ; - } -/* Now tranverse the overlay visual windows and test for transparency index. */ -/* If you find one, subsitute the value from the matching image plane pixmap. */ - - for (reg = (image_region_type *) first_in_list( vis_regions); reg; - reg = (image_region_type *) next_in_list( vis_regions)) - { - - if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals, - &transparentColor, &transparentType)) - { - int32_t test = 0 ; - srcRect_width = MIN( reg->width + reg->x_vis, bbox.width + bbox.x) - - MAX( reg->x_vis, bbox.x); - srcRect_height = MIN( reg->height + reg->y_vis, bbox.height - + bbox.y) - MAX( reg->y_vis, bbox.y); - diff = bbox.x - reg->x_vis; - srcRect_x = MAX( 0, diff) + (reg->x_vis - reg->x_rootrel - reg->border); - dst_x = MAX( 0, -diff) ; - diff = bbox.y - reg->y_vis; - srcRect_y = MAX( 0, diff) + (reg->y_vis - reg->y_rootrel - reg->border); - dst_y = MAX( 0, -diff) ; - /* let's test some pixels for transparency */ - image = XGetImage(disp, reg->win, srcRect_x, srcRect_y, - (uint32_t) srcRect_width, (uint32_t) srcRect_height, - 0xffffffff, ZPixmap); - - /* let's assume byte per pixel for overlay image for now */ - if ((image->depth == 8) && (transparentType == TransparentPixel)) - { - unsigned char *pixel_ptr; - unsigned char *start_of_line = (unsigned char *) image->data; - - for (y1 = 0; y1 < srcRect_height; y1++) { - pixel_ptr = start_of_line; - for (x1 = 0; x1 < srcRect_width; x1++) - { - if (*pixel_ptr++ == transparentColor) - { - /* - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - */ - pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ; - XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel); - - if(!test){ - test = 1 ; - } - } - /* - else { - pmData +=3; - ipmData +=3; - } - */ - } - start_of_line += image->bytes_per_line; - } - } else { - if (transparentType == TransparentPixel) { - for (y1 = 0; y1 < srcRect_height; y1++) { - for (x1 = 0; x1 < srcRect_width; x1++) - { - int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1); - if (pixel_value == transparentColor) - { - /* - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - */ - pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ; - XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel); - if(!test){ - test = 1 ; - } - } - /* - else { - pmData +=3; - ipmData +=3; - } - */ - } - } - } else { - for (y1 = 0; y1 < srcRect_height; y1++) { - for (x1 = 0; x1 < srcRect_width; x1++) - { - int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1); - if (pixel_value & transparentColor) - { - /* - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - */ - pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1, - dst_y+y1) ; - XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel); - if(!test){ - test = 1 ; - } - } - /* - else { - pmData +=3; - ipmData +=3; - } - */ - } - } - } - } - XDestroyImage (image); - } /* end of src_in_overlay */ - } /** end transparency **/ - if (ximage_ipm != NULL) { - XDestroyImage(ximage_ipm); - } - destroy_region_list( vis_regions); - if (vis_image_regions) destroy_region_list( vis_image_regions ); - FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals); - XSync(disp, 0); - - return ximage; -} - -/** ------------------------------------------------------------------------ - Creates a list of the subwindows of a given window which have a - different visual than their parents. The function is recursive. - This list is used in make_region_list(), which coalesces the - windows with the same visual into a region. - image_wins must point to an existing list struct that's already - been zeroed (zero_list()). - ------------------------------------------------------------------------ **/ -static void make_src_list( disp, image_wins, bbox, curr, x_rootrel, y_rootrel, - curr_attrs, pclip) - Display *disp; - list_ptr image_wins; - XRectangle *bbox; /* bnding box of area we want */ - Window curr; - int32_t x_rootrel; /* pos of curr WRT root */ - int32_t y_rootrel; - XWindowAttributes *curr_attrs; - XRectangle *pclip; /* visible part of curr, not */ - /* obscurred by ancestors */ -{ - XWindowAttributes child_attrs; - Window root, parent, *child; /* variables for XQueryTree() */ - Window *save_child_list; /* variables for XQueryTree() */ - uint32_t nchild; /* variables for XQueryTree() */ - XRectangle child_clip; /* vis part of child */ - int32_t curr_clipX, curr_clipY, curr_clipRt, curr_clipBt; - - /* check that win is mapped & not outside bounding box */ - if (curr_attrs->map_state == IsViewable && - curr_attrs->class == InputOutput && - !( pclip->x >= (bbox->x + bbox->width) || - pclip->y >= (bbox->y + bbox->height) || - (pclip->x + pclip->width) <= bbox->x || - (pclip->y + pclip->height) <= bbox->y)) { - - XQueryTree( disp, curr, &root, &parent, &child, &nchild ); - save_child_list = child; /* so we can free list when we're done */ - add_window_to_list( image_wins, curr, x_rootrel, y_rootrel, - (int32_t) pclip->x, (int32_t) pclip->y, - (int32_t) pclip->width, (int32_t) pclip->height, - curr_attrs->border_width,curr_attrs->visual, - curr_attrs->colormap, parent); - - -/** ------------------------------------------------------------------------ - set RR coords of right (Rt), left (X), bottom (Bt) and top (Y) - of rect we clip all children by. This is our own clip rect (pclip) - inflicted on us by our parent plus our own borders. Within the - child loop, we figure the clip rect for each child by adding in - it's rectangle (not taking into account the child's borders). - ------------------------------------------------------------------------ **/ - curr_clipX = MAX( pclip->x, x_rootrel + curr_attrs->border_width); - curr_clipY = MAX( pclip->y, y_rootrel + curr_attrs->border_width); - curr_clipRt = MIN(pclip->x + pclip->width, - x_rootrel + curr_attrs->width + 2 * curr_attrs->border_width); - - curr_clipBt = MIN(pclip->y + pclip->height, - y_rootrel + curr_attrs->height + 2 * curr_attrs->border_width); - - - while (nchild--) { - int32_t new_width, new_height; - int32_t child_xrr, child_yrr; /* root relative x & y of child */ - - XGetWindowAttributes( disp, *child, &child_attrs); - - /* intersect parent & child clip rects */ - child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width; - child_clip.x = (short) MAX( curr_clipX, child_xrr); - new_width = MIN(curr_clipRt, - child_xrr + child_attrs.width + - 2 * child_attrs.border_width) - child_clip.x; - - if (new_width >= 0) { - child_clip.width = (unsigned short) new_width; - - child_yrr = y_rootrel + child_attrs.y + - curr_attrs->border_width; - child_clip.y = (short) MAX( curr_clipY, child_yrr); - new_height = MIN(curr_clipBt, - child_yrr + (int32_t) child_attrs.height + - 2 * child_attrs.border_width) - child_clip.y; - - if (new_height >= 0) { - child_clip.height = (unsigned short) new_height; - make_src_list( disp, image_wins, bbox, *child, - child_xrr, child_yrr, - &child_attrs, &child_clip); - } - } - child++; - } - XFree( save_child_list); - } -} - - -/** ------------------------------------------------------------------------ - This function creates a list of regions which tile a specified - window. Each region contains all visible portions of the window - which are drawn with the same visual. For example, if the - window consists of subwindows of two different visual types, - there will be two regions in the list. - Returns a pointer to the list. - ------------------------------------------------------------------------ **/ -static list_ptr make_region_list( disp, win, bbox, hasNonDefault, - numImageVisuals, pImageVisuals, allImage) - Display *disp; - Window win; - XRectangle *bbox; - int32_t *hasNonDefault; - int32_t numImageVisuals; - XVisualInfo **pImageVisuals; - int32_t *allImage; -{ - XWindowAttributes win_attrs; - list image_wins; - list_ptr image_regions; - list_ptr srcs_left; - image_region_type *new_reg; - image_win_type *base_src, *src; - Region bbox_region = XCreateRegion(); - XRectangle clip; - int32_t image_only; - - int32_t count=0 ; - - *hasNonDefault = False; - XUnionRectWithRegion( bbox, bbox_region, bbox_region); - XGetWindowAttributes( disp, win, &win_attrs); - - zero_list( &image_wins); - clip.x = 0; - clip.y = 0; - clip.width = (unsigned short) win_attrs.width; - clip.height = (unsigned short) win_attrs.height; - make_src_list( disp, &image_wins, bbox, win, - 0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip); - - image_regions = new_list(); - image_only = (*allImage) ? True:False; - - for (base_src = (image_win_type *) first_in_list( &image_wins); base_src; - base_src = (image_win_type *) next_in_list( &image_wins)) - { - /* test for image visual */ - if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals)) - { - /* find a window whose visual hasn't been put in list yet */ - if (!src_in_region_list( base_src, image_regions)) - { - if (! (new_reg = (image_region_type *) - malloc( sizeof( image_region_type)))) { - return (list_ptr) NULL; - } - count++; - - new_reg->visible_region = XCreateRegion(); - new_reg->win = base_src->win; - new_reg->vis = base_src->vis; - new_reg->cmap = base_src->cmap; - new_reg->x_rootrel = base_src->x_rootrel; - new_reg->y_rootrel = base_src->y_rootrel; - new_reg->x_vis = base_src->x_vis; - new_reg->y_vis = base_src->y_vis; - new_reg->width = base_src->width; - new_reg->height = base_src->height; - new_reg->border = base_src->border_width; - - srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR); - for (src = (image_win_type *) first_in_list( srcs_left); src; - src = (image_win_type *) next_in_list( srcs_left)) { - if (SAME_REGIONS( base_src, src)) { - add_rect_to_image_region( new_reg, src->x_vis, src->y_vis, - src->width, src->height); - } - else { - if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals)) - { - subtr_rect_from_image_region( new_reg, src->x_vis, - src->y_vis, src->width, src->height); - } - } - } - XIntersectRegion( bbox_region, new_reg->visible_region, - new_reg->visible_region); - if (! XEmptyRegion( new_reg->visible_region)) { - add_to_list( image_regions, new_reg); - if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) || - new_reg->cmap != DefaultColormapOfScreen( - win_attrs.screen)) { - *hasNonDefault = True; - } - } - else { - XDestroyRegion( new_reg->visible_region); - free( (void *) new_reg); - } - } - } else *allImage = 0; - } - delete_list( &image_wins, True); - XDestroyRegion( bbox_region); - return image_regions; -} -/** ------------------------------------------------------------------------ - Destructor called from destroy_region_list(). - ------------------------------------------------------------------------ **/ -void destroy_image_region( image_region) - image_region_type *image_region; -{ - XDestroyRegion( image_region->visible_region); - free( (void *) image_region); -} - -/** ------------------------------------------------------------------------ - Destroys the region list, destroying all the regions contained in it. - ------------------------------------------------------------------------ **/ -static void destroy_region_list( rlist) - list_ptr rlist; -{ - delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region); -} - - -/** ------------------------------------------------------------------------ - Subtracts the specified rectangle from the region in image_region. - First converts the rectangle to a region of its own, since X - only provides a way to subtract one region from another, not a - rectangle from a region. - ------------------------------------------------------------------------ **/ -static void subtr_rect_from_image_region( image_region, x, y, width, height) - image_region_type *image_region; - int32_t x; - int32_t y; - int32_t width; - int32_t height; -{ - XRectangle rect; - Region rect_region; - - rect_region = XCreateRegion(); - rect.x = (short)x; - rect.y = (short)y; - rect.width = (unsigned short)width; - rect.height = (unsigned short)height; - XUnionRectWithRegion( &rect, rect_region, rect_region); - XSubtractRegion( image_region->visible_region, rect_region, - image_region->visible_region); - XDestroyRegion( rect_region); -} - - -/** ------------------------------------------------------------------------ - Adds the specified rectangle to the region in image_region. - ------------------------------------------------------------------------ **/ -static void add_rect_to_image_region( image_region, x, y, width, height) - image_region_type *image_region; - int32_t x; - int32_t y; - int32_t width; - int32_t height; -{ - XRectangle rect; - - rect.x = (short) x; - rect.y = (short) y; - rect.width = (unsigned short) width; - rect.height = (unsigned short) height; - XUnionRectWithRegion( &rect, image_region->visible_region, - image_region->visible_region); -} - - -/** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is already represented in - the image_regions list, FALSE otherwise. - ------------------------------------------------------------------------ **/ -static int32_t src_in_region_list( src, image_regions) - image_win_type *src; - list_ptr image_regions; -{ - image_region_type *ir; - - for (ir = (image_region_type *) first_in_list( image_regions); ir; - ir = (image_region_type *) next_in_list( image_regions)) { - if (SAME_REGIONS( ir, src)) { - - return 1; - } - } - - return 0; -} - - -/** ------------------------------------------------------------------------ - Makes a new entry in image_wins with the given fields filled in. - ------------------------------------------------------------------------ **/ -static void add_window_to_list( image_wins, w, xrr, yrr, x_vis, y_vis, - width, height, border_width,vis, cmap, parent) - list_ptr image_wins; - Window w; - int32_t xrr; - int32_t yrr; - int32_t x_vis; - int32_t y_vis; - int32_t width; - int32_t height; - int32_t border_width; - Visual *vis; - Colormap cmap; - Window parent; -{ - image_win_type *new_src; - - if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL) - - return; - - new_src->win = w; - new_src->x_rootrel = xrr; - new_src->y_rootrel = yrr; - new_src->x_vis = x_vis; - new_src->y_vis = y_vis; - new_src->width = width; - new_src->height = height; - new_src->border_width = border_width; - new_src->vis = vis; - new_src->cmap = cmap; - new_src->parent = parent; - add_to_list( image_wins, new_src); -} - -/** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is in the image planes, - FALSE otherwise. - ------------------------------------------------------------------------ **/ -static int32_t src_in_image( src, numImageVisuals, pImageVisuals) - image_win_type *src; - int32_t numImageVisuals; - XVisualInfo **pImageVisuals; -{ - int32_t i; - - for (i = 0 ; i < numImageVisuals ; i++) - { - if (pImageVisuals[i]->visual == src->vis) - return 1; - } - return 0; -} - - -/** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is in the overlay planes - and transparency is possible, FALSE otherwise. - ------------------------------------------------------------------------ **/ -static int32_t src_in_overlay( src, numOverlayVisuals, pOverlayVisuals, - transparentColor, transparentType) - image_region_type *src; - int32_t numOverlayVisuals; - OverlayInfo *pOverlayVisuals; - int32_t *transparentColor; - int32_t *transparentType; -{ - int32_t i; - - for (i = 0 ; i < numOverlayVisuals ; i++) - { - if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis) - && (pOverlayVisuals[i].transparentType != None)) - { - *transparentColor = pOverlayVisuals[i].value; - *transparentType = pOverlayVisuals[i].transparentType; - return 1; - } - - else { - } - - } - return 0; -} - - -/********************** from wsutils.c ******************************/ - -/****************************************************************************** - * - * This file contains a set of example utility procedures; procedures that can - * help a "window-smart" Starbase or PHIGS program determine information about - * a device, and create image and overlay plane windows. To use these - * utilities, #include "wsutils.h" and compile this file and link the results - * with your program. - * - ******************************************************************************/ - - - -#define STATIC_GRAY 0x01 -#define GRAY_SCALE 0x02 -#define PSEUDO_COLOR 0x04 -#define TRUE_COLOR 0x10 -#define DIRECT_COLOR 0x11 - - -static int32_t weCreateServerOverlayVisualsProperty = False; - - -/****************************************************************************** - * - * GetXVisualInfo() - * - * This routine takes an X11 Display, screen number, and returns whether the - * screen supports transparent overlays and three arrays: - * - * 1) All of the XVisualInfo struct's for the screen. - * 2) All of the OverlayInfo struct's for the screen. - * 3) An array of pointers to the screen's image plane XVisualInfo - * structs. - * - * The code below obtains the array of all the screen's visuals, and obtains - * the array of all the screen's overlay visual information. It then processes - * the array of the screen's visuals, determining whether the visual is an - * overlay or image visual. - * - * If the routine sucessfully obtained the visual information, it returns zero. - * If the routine didn't obtain the visual information, it returns non-zero. - * - ******************************************************************************/ - -int32_t GetXVisualInfo(display, screen, transparentOverlays, - numVisuals, pVisuals, - numOverlayVisuals, pOverlayVisuals, - numImageVisuals, pImageVisuals) - - Display *display; /* Which X server (aka "display"). */ - int32_t screen; /* Which screen of the "display". */ - int32_t *transparentOverlays; /* Non-zero if there's at least one - * overlay visual and if at least one - * of those supports a transparent - * pixel. */ - int32_t *numVisuals; /* Number of XVisualInfo struct's - * pointed to by pVisuals. */ - XVisualInfo **pVisuals; /* All of the device's visuals. */ - int32_t *numOverlayVisuals; /* Number of OverlayInfo's pointed - * to by pOverlayVisuals. If this - * number is zero, the device does - * not have overlay planes. */ - OverlayInfo **pOverlayVisuals; /* The device's overlay plane visual - * information. */ - int32_t *numImageVisuals; /* Number of XVisualInfo's pointed - * to by pImageVisuals. */ - XVisualInfo ***pImageVisuals; /* The device's image visuals. */ -{ - XVisualInfo getVisInfo; /* Parameters of XGetVisualInfo */ - int32_t mask; - XVisualInfo *pVis, **pIVis; /* Faster, local copies */ - OverlayInfo *pOVis; - OverlayVisualPropertyRec *pOOldVis; - int32_t nVisuals, nOVisuals; - Atom overlayVisualsAtom; /* Parameters for XGetWindowProperty */ - Atom actualType; - unsigned long numLongs, bytesAfter; - int32_t actualFormat; - int32_t nImageVisualsAlloced; /* Values to process the XVisualInfo */ - int32_t imageVisual; /* array */ - - - /* First, get the list of visuals for this screen. */ - getVisInfo.screen = screen; - mask = VisualScreenMask; - - *pVisuals = XGetVisualInfo(display, mask, &getVisInfo, numVisuals); - if ((nVisuals = *numVisuals) <= 0) - { - /* Return that the information wasn't sucessfully obtained: */ - return(1); - } - pVis = *pVisuals; - - - /* Now, get the overlay visual information for this screen. To obtain - * this information, get the SERVER_OVERLAY_VISUALS property. - */ - overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True); - if (overlayVisualsAtom != None) - { - /* Since the Atom exists, we can request the property's contents. The - * do-while loop makes sure we get the entire list from the X server. - */ - bytesAfter = 0; - numLongs = sizeof(OverlayVisualPropertyRec) / 4; - do - { - numLongs += bytesAfter * 4; - XGetWindowProperty(display, RootWindow(display, screen), - overlayVisualsAtom, 0, numLongs, False, - overlayVisualsAtom, &actualType, &actualFormat, - &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals); - } while (bytesAfter > 0); - - - /* Calculate the number of overlay visuals in the list. */ - /* *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4); */ - *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / sizeof(long)); - } - else - { - /* This screen doesn't have overlay planes. */ - *numOverlayVisuals = 0; - *pOverlayVisuals = NULL; - *transparentOverlays = 0; - } - - - /* Process the pVisuals array. */ - *numImageVisuals = 0; - nImageVisualsAlloced = 1; - pIVis = *pImageVisuals = (XVisualInfo **) malloc(sizeof(XVisualInfo *)); - while (--nVisuals >= 0) - { - nOVisuals = *numOverlayVisuals; - pOVis = *pOverlayVisuals; - imageVisual = True; - while (--nOVisuals >= 0) - { - pOOldVis = (OverlayVisualPropertyRec *) pOVis; - if (pVis->visualid == pOOldVis->visualID) - { - imageVisual = False; - pOVis->pOverlayVisualInfo = pVis; - if (pOVis->transparentType == TransparentPixel) - *transparentOverlays = 1; - } - pOVis++; - } - if (imageVisual) - { - if ((*numImageVisuals += 1) > nImageVisualsAlloced) - { - nImageVisualsAlloced++; - *pImageVisuals = (XVisualInfo **) - realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *))); - pIVis = *pImageVisuals + (*numImageVisuals - 1); - } - *pIVis++ = pVis; - } - pVis++; - } - - - /* Return that the information was sucessfully obtained: */ - return(0); - -} /* GetXVisualInfo() */ - - -/****************************************************************************** - * - * FreeXVisualInfo() - * - * This routine frees the data that was allocated by GetXVisualInfo(). - * - ******************************************************************************/ - -void FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals) - - XVisualInfo *pVisuals; - OverlayInfo *pOverlayVisuals; - XVisualInfo **pImageVisuals; -{ - XFree(pVisuals); - if (weCreateServerOverlayVisualsProperty) - free(pOverlayVisuals); - else - XFree(pOverlayVisuals); - free(pImageVisuals); - -} /* FreeXVisualInfo() */ diff --git a/app/src/main/jni/awt_xawt/awt/multiVis.h b/app/src/main/jni/awt_xawt/awt/multiVis.h deleted file mode 100644 index b1d7085a7..000000000 --- a/app/src/main/jni/awt_xawt/awt/multiVis.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* $XConsortium: multiVis.h /main/4 1996/10/14 15:04:12 swick $ */ -/** ------------------------------------------------------------------------ - This file contains routines for manipulating generic lists. - Lists are implemented with a "harness". In other words, each - node in the list consists of two pointers, one to the data item - and one to the next node in the list. The head of the list is - the same struct as each node, but the "item" ptr is used to point - to the current member of the list (used by the first_in_list and - next_in_list functions). - - This file is available under and governed by the GNU General Public - License version 2 only, as published by the Free Software Foundation. - However, the following notice accompanied the original version of this - file: - -Copyright (c) 1994 Hewlett-Packard Co. -Copyright (c) 1996 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - - ------------------------------------------------------------------------ **/ - -extern int32_t GetMultiVisualRegions( -#if NeedFunctionPrototypes - Display *, Window, int32_t, int32_t, uint32_t, - uint32_t, int32_t *, int32_t *, XVisualInfo **, int32_t *, - OverlayInfo **, int32_t *, XVisualInfo ***, list_ptr *, - list_ptr *, int32_t * -#endif -); - -extern XImage *ReadAreaToImage( -#if NeedFunctionPrototypes - Display *, Window, int32_t, int32_t, uint32_t, - uint32_t, int32_t, XVisualInfo *, int32_t, - OverlayInfo *, int32_t, XVisualInfo **, list_ptr, - list_ptr, int32_t, int32_t -#endif -); - -extern void initFakeVisual( -#if NeedFunctionPrototypes - Visual * -#endif -); diff --git a/app/src/main/jni/awt_xawt/awt/multi_font.c b/app/src/main/jni/awt_xawt/awt/multi_font.c deleted file mode 100644 index adf85d4fa..000000000 --- a/app/src/main/jni/awt_xawt/awt/multi_font.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright (c) 1996, 2014, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * These routines are used for display string with multi font. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "awt_Font.h" -#include "awt_p.h" -#include "multi_font.h" - -extern XFontStruct *loadFont(Display *, char *, int32_t); - -extern struct FontIDs fontIDs; -extern struct PlatformFontIDs platformFontIDs; -extern struct XFontPeerIDs xFontPeerIDs; - -/* - * make string with str + string representation of num - * This string is used as tag string of Motif Compound String and FontList. - */ -static void -makeTag(char *str, int32_t num, char *buf) -{ - int32_t len = strlen(str); - - strcpy(buf, str); - buf[len] = '0' + num % 100; - buf[len + 1] = '\0'; -} - -static int32_t -awtJNI_GetFontDescriptorNumber(JNIEnv * env - ,jobject font - ,jobject fd) -{ - int32_t i = 0, num; - /* initialize to NULL so that DeleteLocalRef will work. */ - jobjectArray componentFonts = NULL; - jobject peer = NULL; - jobject temp = NULL; - jboolean validRet = JNI_FALSE; - - if ((*env)->EnsureLocalCapacity(env, 2) < 0 || (*env)->ExceptionCheck(env)) - goto done; - - peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer); - if (peer == NULL) - goto done; - - componentFonts = (jobjectArray) - (*env)->GetObjectField(env,peer,platformFontIDs.componentFonts); - - if (componentFonts == NULL) - goto done; - - num = (*env)->GetArrayLength(env, componentFonts); - - for (i = 0; i < num; i++) { - temp = (*env)->GetObjectArrayElement(env, componentFonts, i); - - if ((*env)->IsSameObject(env, fd, temp)) { - validRet = JNI_TRUE; - break; - } - (*env)->DeleteLocalRef(env, temp); - } - - done: - (*env)->DeleteLocalRef(env, peer); - (*env)->DeleteLocalRef(env, componentFonts); - - if (validRet) - return i; - - return 0; -} - -jobject -awtJNI_GetFMFont(JNIEnv * env, jobject this) -{ - return JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode", - "()Ljava/awt/Font;").l; -} - -jboolean -awtJNI_IsMultiFont(JNIEnv * env, jobject this) -{ - jobject peer = NULL; - jobject fontConfig = NULL; - - if (this == NULL) { - return JNI_FALSE; - } - - if ((*env)->EnsureLocalCapacity(env, 2) < 0) { - return JNI_FALSE; - } - - peer = (*env)->CallObjectMethod(env,this,fontIDs.getPeer); - if (peer == NULL) { - return JNI_FALSE; - } - - fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig); - (*env)->DeleteLocalRef(env, peer); - - if (fontConfig == NULL) { - return JNI_FALSE; - } - (*env)->DeleteLocalRef(env, fontConfig); - - return JNI_TRUE; -} - -jboolean -awtJNI_IsMultiFontMetrics(JNIEnv * env, jobject this) -{ - jobject peer = NULL; - jobject fontConfig = NULL; - jobject font = NULL; - - if (JNU_IsNull(env, this)) { - return JNI_FALSE; - } - if ((*env)->EnsureLocalCapacity(env, 3) < 0) { - return JNI_FALSE; - } - - font = JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode", - "()Ljava/awt/Font;").l; - if (JNU_IsNull(env, font) || (*env)->ExceptionCheck(env)) { - return JNI_FALSE; - } - - peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer); - (*env)->DeleteLocalRef(env, font); - - if (peer == NULL) { - return JNI_FALSE; - } - - fontConfig = (*env)->GetObjectField(env,peer,platformFontIDs.fontConfig); - (*env)->DeleteLocalRef(env, peer); - if (fontConfig == NULL) { - return JNI_FALSE; - } - (*env)->DeleteLocalRef(env, fontConfig); - - return JNI_TRUE; -} - -/* #define FONT_DEBUG 2 */ - -XFontSet -awtJNI_MakeFontSet(JNIEnv * env, jobject font) -{ - jstring xlfd = NULL; - char *xfontset = NULL; - int32_t size; - int32_t length = 0; - char *realxlfd = NULL, *ptr = NULL, *prev = NULL; - char **missing_list = NULL; - int32_t missing_count; - char *def_string = NULL; - XFontSet xfs; - jobject peer = NULL; - jstring xfsname = NULL; -#ifdef FONT_DEBUG - char xx[1024]; -#endif - - if ((*env)->EnsureLocalCapacity(env, 2) < 0) - return 0; - - size = (*env)->GetIntField(env, font, fontIDs.size) * 10; - - peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer); - xfsname = (*env)->GetObjectField(env, peer, xFontPeerIDs.xfsname); - - if (JNU_IsNull(env, xfsname)) - xfontset = ""; - else - xfontset = (char *)JNU_GetStringPlatformChars(env, xfsname, NULL); - - realxlfd = malloc(strlen(xfontset) + 50); - - prev = ptr = xfontset; - while ((ptr = strstr(ptr, "%d"))) { - char save = *(ptr + 2); - - *(ptr + 2) = '\0'; - jio_snprintf(realxlfd + length, strlen(xfontset) + 50 - length, - prev, size); - length = strlen(realxlfd); - *(ptr + 2) = save; - - prev = ptr + 2; - ptr += 2; - } - strcpy(realxlfd + length, prev); - -#ifdef FONT_DEBUG - strcpy(xx, realxlfd); -#endif - xfs = XCreateFontSet(awt_display, realxlfd, &missing_list, - &missing_count, &def_string); -#if FONT_DEBUG >= 2 - fprintf(stderr, "XCreateFontSet(%s)->0x%x\n", xx, xfs); -#endif - -#if FONT_DEBUG - if (missing_count != 0) { - int32_t i; - fprintf(stderr, "XCreateFontSet missing %d fonts:\n", missing_count); - for (i = 0; i < missing_count; ++i) { - fprintf(stderr, "\t\"%s\"\n", missing_list[i]); - } - fprintf(stderr, " requested \"%s\"\n", xx); -#if FONT_DEBUG >= 3 - exit(-1); -#endif - } -#endif - - free((void *)realxlfd); - - if (xfontset && !JNU_IsNull(env, xfsname)) - JNU_ReleaseStringPlatformChars(env, xfsname, (const char *) xfontset); - - (*env)->DeleteLocalRef(env, peer); - (*env)->DeleteLocalRef(env, xfsname); - return xfs; -} - -/* - * get multi font string width with multiple X11 font - * - * ASSUMES: We are not running on a privileged thread - */ -int32_t -awtJNI_GetMFStringWidth(JNIEnv * env, jcharArray s, int offset, int sLength, jobject font) -{ - char *err = NULL; - unsigned char *stringData = NULL; - char *offsetStringData = NULL; - int32_t stringCount, i; - int32_t size; - struct FontData *fdata = NULL; - jobject fontDescriptor = NULL; - jbyteArray data = NULL; - int32_t j; - int32_t width = 0; - int32_t length; - XFontStruct *xf = NULL; - jobjectArray dataArray = NULL; - if ((*env)->EnsureLocalCapacity(env, 3) < 0) - return 0; - - if (!JNU_IsNull(env, s) && !JNU_IsNull(env, font)) - { - jobject peer; - peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer); - - dataArray = (*env)->CallObjectMethod( - env, - peer, - platformFontIDs.makeConvertedMultiFontChars, - s, offset, sLength); - - if ((*env)->ExceptionOccurred(env)) - { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - - (*env)->DeleteLocalRef(env, peer); - - if(dataArray == NULL) - { - return 0; - } - } else { - return 0; - } - - fdata = awtJNI_GetFontData(env, font, &err); - if ((*env)->ExceptionCheck(env)) { - (*env)->DeleteLocalRef(env, dataArray); - return 0; - } - - stringCount = (*env)->GetArrayLength(env, dataArray); - - size = (*env)->GetIntField(env, font, fontIDs.size); - - for (i = 0; i < stringCount; i+=2) - { - fontDescriptor = (*env)->GetObjectArrayElement(env, dataArray, i); - data = (*env)->GetObjectArrayElement(env, dataArray, i + 1); - - /* Bail if we've finished */ - if (fontDescriptor == NULL || data == NULL) { - (*env)->DeleteLocalRef(env, fontDescriptor); - (*env)->DeleteLocalRef(env, data); - break; - } - - j = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor); - if ((*env)->ExceptionCheck(env)) { - (*env)->DeleteLocalRef(env, fontDescriptor); - (*env)->DeleteLocalRef(env, data); - break; - } - - if (fdata->flist[j].load == 0) { - xf = loadFont(awt_display, - fdata->flist[j].xlfd, size * 10); - if (xf == NULL) { - (*env)->DeleteLocalRef(env, fontDescriptor); - (*env)->DeleteLocalRef(env, data); - continue; - } - fdata->flist[j].load = 1; - fdata->flist[j].xfont = xf; - if (xf->min_byte1 == 0 && xf->max_byte1 == 0) - fdata->flist[j].index_length = 1; - else - fdata->flist[j].index_length = 2; - } - xf = fdata->flist[j].xfont; - - stringData = - (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, data,NULL); - if (stringData == NULL) { - (*env)->DeleteLocalRef(env, fontDescriptor); - (*env)->DeleteLocalRef(env, data); - (*env)->ExceptionClear(env); - JNU_ThrowOutOfMemoryError(env, "Could not get string data"); - break; - } - - length = (stringData[0] << 24) | (stringData[1] << 16) | - (stringData[2] << 8) | stringData[3]; - offsetStringData = (char *)(stringData + (4 * sizeof(char))); - - if (fdata->flist[j].index_length == 2) { - width += XTextWidth16(xf, (XChar2b *)offsetStringData, length/2); - } else { - width += XTextWidth(xf, offsetStringData, length); - } - - (*env)->ReleasePrimitiveArrayCritical(env, data, stringData, JNI_ABORT); - (*env)->DeleteLocalRef(env, fontDescriptor); - (*env)->DeleteLocalRef(env, data); - } - (*env)->DeleteLocalRef(env, dataArray); - - return width; -} diff --git a/app/src/main/jni/awt_xawt/awt/multi_font.h b/app/src/main/jni/awt_xawt/awt/multi_font.h deleted file mode 100644 index 377306aa7..000000000 --- a/app/src/main/jni/awt_xawt/awt/multi_font.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 1996, 2011, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* - * header for Multi Font String - */ -#ifndef _MULTI_FONT_H_ -#define _MULTI_FONT_H_ - -#ifndef HEADLESS -jboolean awtJNI_IsMultiFont(JNIEnv *env,jobject this); -jboolean awtJNI_IsMultiFontMetrics(JNIEnv *env,jobject this); -XFontSet awtJNI_MakeFontSet(JNIEnv *env,jobject font); -struct FontData *awtJNI_GetFontData(JNIEnv *env,jobject font, char **errmsg); -int32_t awtJNI_GetMFStringWidth(JNIEnv * env, jcharArray s, int32_t offset, - int32_t length, jobject font); -#endif /* !HEADLESS */ - -#endif /* _MULTI_FONT_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/randr.h b/app/src/main/jni/awt_xawt/awt/randr.h deleted file mode 100644 index e289c7b8f..000000000 --- a/app/src/main/jni/awt_xawt/awt/randr.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * $XFree86: xc/include/extensions/randr.h,v 1.4 2001/11/24 07:24:58 keithp Exp $ - * - * Copyright © 2000, Compaq Computer Corporation, - * Copyright © 2002, Hewlett Packard, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Compaq or HP not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. HP makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * HP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HP - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc. - */ - -#ifndef _RANDR_H_ -#define _RANDR_H_ - -typedef unsigned short Connection; -typedef unsigned short Rotation; -typedef unsigned short SizeID; -typedef unsigned short SubpixelOrder; - -#define RANDR_NAME "RANDR" -#define RANDR_MAJOR 1 -#define RANDR_MINOR 1 - -#define RRNumberErrors 0 -#define RRNumberEvents 1 - -#define X_RRQueryVersion 0 -/* we skip 1 to make old clients fail pretty immediately */ -#define X_RROldGetScreenInfo 1 -#define X_RR1_0SetScreenConfig 2 -/* V1.0 apps share the same set screen config request id */ -#define X_RRSetScreenConfig 2 -#define X_RROldScreenChangeSelectInput 3 -/* 3 used to be ScreenChangeSelectInput; deprecated */ -#define X_RRSelectInput 4 -#define X_RRGetScreenInfo 5 - -/* used in XRRSelectInput */ - -#define RRScreenChangeNotifyMask (1L << 0) - -#define RRScreenChangeNotify 0 - -/* used in the rotation field; rotation and reflection in 0.1 proto. */ -#define RR_Rotate_0 1 -#define RR_Rotate_90 2 -#define RR_Rotate_180 4 -#define RR_Rotate_270 8 - -/* new in 1.0 protocol, to allow reflection of screen */ - -#define RR_Reflect_X 16 -#define RR_Reflect_Y 32 - -#define RRSetConfigSuccess 0 -#define RRSetConfigInvalidConfigTime 1 -#define RRSetConfigInvalidTime 2 -#define RRSetConfigFailed 3 - -#endif /* _RANDR_H_ */ diff --git a/app/src/main/jni/awt_xawt/awt/robot_common.c b/app/src/main/jni/awt_xawt/awt/robot_common.c deleted file mode 100644 index da61f299b..000000000 --- a/app/src/main/jni/awt_xawt/awt/robot_common.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 1999, 2012, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#ifdef MACOSX -#include -#endif - -#include "robot_common.h" - -/* - * QueryColorMap is taken from multiVis.c, part of the xwd distribution from - * X.org. It was moved here so it can be shared with awt_DataTransferer.c - */ -int32_t -QueryColorMap(Display *disp, - Colormap src_cmap, - Visual *src_vis, - XColor **src_colors, - int32_t *rShift, int32_t *gShift, int32_t *bShift) - -{ - int32_t ncolors, i; - unsigned long redMask, greenMask, blueMask; - int32_t redShift, greenShift, blueShift; - XColor *colors ; - - ncolors = src_vis->map_entries ; - *src_colors = colors = (XColor *)calloc(ncolors,sizeof(XColor) ) ; - - if(src_vis->class != TrueColor && src_vis->class != DirectColor) - { - for(i=0 ; i < ncolors ; i++) - { - colors[i].pixel = i ; - colors[i].pad = 0; - colors[i].flags = DoRed|DoGreen|DoBlue; - } - } - else /** src is decomposed rgb ***/ - { - /* Get the X colormap */ - redMask = src_vis->red_mask; - greenMask = src_vis->green_mask; - blueMask = src_vis->blue_mask; - redShift = 0; while (!(redMask&0x1)) { - redShift++; - redMask = redMask>>1; - } - greenShift = 0; while (!(greenMask&0x1)) { - greenShift++; - greenMask = greenMask>>1; - } - blueShift = 0; while (!(blueMask&0x1)) { - blueShift++; - blueMask = blueMask>>1; - } - *rShift = redShift ; - *gShift = greenShift ; - *bShift = blueShift ; - for (i=0; i -#include "gdefs.h" - -int QueryColorMap(Display *disp, - Colormap src_cmap, - Visual *src_vis, - XColor **src_colors, - int *rShift, int *gShift, int *bShift); - -#endif /* _ROBOT_COMMON_H */ diff --git a/app/src/main/jni/awt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c b/app/src/main/jni/awt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c deleted file mode 100644 index 556fe2525..000000000 --- a/app/src/main/jni/awt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (c) 2010, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#include -#include "gtk_interface.h" -#include "sun_awt_X11_GtkFileDialogPeer.h" -#include "java_awt_FileDialog.h" -#include "debug_assert.h" - -typedef void GtkWidget; -static JavaVM *jvm; - -/* To cache some method IDs */ -static jmethodID filenameFilterCallbackMethodID = NULL; -static jmethodID setFileInternalMethodID = NULL; -static jfieldID widgetFieldID = NULL; -static jmethodID setWindowMethodID = NULL; - -JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs -(JNIEnv *env, jclass cx) -{ - filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx, - "filenameFilterCallback", "(Ljava/lang/String;)Z"); - DASSERT(filenameFilterCallbackMethodID != NULL); - CHECK_NULL(filenameFilterCallbackMethodID); - - setFileInternalMethodID = (*env)->GetMethodID(env, cx, - "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V"); - DASSERT(setFileInternalMethodID != NULL); - CHECK_NULL(setFileInternalMethodID); - - widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J"); - DASSERT(widgetFieldID != NULL); - CHECK_NULL(widgetFieldID); - - setWindowMethodID = (*env)->GetMethodID(env, cx, "setWindow", "(J)Z"); - DASSERT(setWindowMethodID != NULL); -} - -static gboolean filenameFilterCallback(const GtkFileFilterInfo * filter_info, gpointer obj) -{ - JNIEnv *env; - jstring filename; - - env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); - - filename = (*env)->NewStringUTF(env, filter_info->filename); - JNU_CHECK_EXCEPTION_RETURN(env, FALSE); - - return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID, - filename); -} - -static void quit(JNIEnv * env, jobject jpeer, gboolean isSignalHandler) -{ - jthrowable pendingException; - if (pendingException = (*env)->ExceptionOccurred(env)) { - (*env)->ExceptionClear(env); - } - - GtkWidget * dialog = (GtkWidget*)jlong_to_ptr( - (*env)->GetLongField(env, jpeer, widgetFieldID)); - - if (dialog != NULL) - { - // Callbacks from GTK signals are made within the GTK lock - // So, within a signal handler there is no need to call - // gdk_threads_enter() / gtk->gdk_threads_leave() - if (!isSignalHandler) { - gtk->gdk_threads_enter(); - } - - gtk->gtk_widget_hide (dialog); - gtk->gtk_widget_destroy (dialog); - - gtk->gtk_main_quit (); - - (*env)->SetLongField(env, jpeer, widgetFieldID, 0); - - if (!isSignalHandler) { - gtk->gdk_threads_leave(); - } - } - - if (pendingException) { - (*env)->Throw(env, pendingException); - } -} - -/* - * Class: sun_awt_X11_GtkFileDialogPeer - * Method: quit - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_quit -(JNIEnv * env, jobject jpeer) -{ - quit(env, jpeer, FALSE); -} - -/* - * Class: sun_awt_X11_GtkFileDialogPeer - * Method: toFront - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_toFront -(JNIEnv * env, jobject jpeer) -{ - GtkWidget * dialog; - - gtk->gdk_threads_enter(); - - dialog = (GtkWidget*)jlong_to_ptr( - (*env)->GetLongField(env, jpeer, widgetFieldID)); - - if (dialog != NULL) { - gtk->gtk_window_present((GtkWindow*)dialog); - } - - gtk->gdk_threads_leave(); -} - -/* - * Class: sun_awt_X11_GtkFileDialogPeer - * Method: setBounds - * Signature: (IIIII)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_setBounds -(JNIEnv * env, jobject jpeer, jint x, jint y, jint width, jint height, jint op) -{ - GtkWindow* dialog; - - gtk->gdk_threads_enter(); - - dialog = (GtkWindow*)jlong_to_ptr( - (*env)->GetLongField(env, jpeer, widgetFieldID)); - - if (dialog != NULL) { - if (x >= 0 && y >= 0) { - gtk->gtk_window_move(dialog, (gint)x, (gint)y); - } - if (width > 0 && height > 0) { - gtk->gtk_window_resize(dialog, (gint)width, (gint)height); - } - } - - gtk->gdk_threads_leave(); -} - -/* - * baseDir should be freed by user. - */ -static gboolean isFromSameDirectory(GSList* list, gchar** baseDir) { - - GSList *it = list; - gchar* prevDir = NULL; - gboolean isAllDirsSame = TRUE; - - while (it) { - gchar* dir = gtk->g_path_get_dirname((gchar*) it->data); - - if (prevDir && strcmp(prevDir, dir) != 0) { - isAllDirsSame = FALSE; - gtk->g_free(dir); - break; - } - - if (!prevDir) { - prevDir = strdup(dir); - } - gtk->g_free(dir); - - it = it->next; - } - - if (isAllDirsSame) { - *baseDir = prevDir; - } else { - free(prevDir); - *baseDir = strdup("/"); - } - - return isAllDirsSame; -} - -/** - * Convert a GSList to an array of filenames - */ -static jobjectArray toFilenamesArray(JNIEnv *env, GSList* list, jstring* jcurrent_folder) -{ - jstring str; - jclass stringCls; - GSList *iterator; - jobjectArray array; - int i; - gchar* entry; - gchar * baseDir; - gboolean isFromSameDir; - - if (list == NULL) { - return NULL; - } - - stringCls = (*env)->FindClass(env, "java/lang/String"); - if (stringCls == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowInternalError(env, "Could not get java.lang.String class"); - return NULL; - } - - array = (*env)->NewObjectArray(env, gtk->gtk_g_slist_length(list), stringCls, NULL); - if (array == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowInternalError(env, "Could not instantiate array files array"); - return NULL; - } - - isFromSameDir = isFromSameDirectory(list, &baseDir); - - *jcurrent_folder = (*env)->NewStringUTF(env, baseDir); - if (*jcurrent_folder == NULL) { - free(baseDir); - return NULL; - } - - for (iterator = list, i=0; - iterator; - iterator = iterator->next, i++) { - - entry = (gchar*) iterator->data; - - if (isFromSameDir) { - entry = strrchr(entry, '/') + 1; - } else if (entry[0] == '/') { - entry++; - } - - str = (*env)->NewStringUTF(env, entry); - if((*env)->ExceptionCheck(env)){ - break; - } - if (str) { - (*env)->SetObjectArrayElement(env, array, i, str); - if((*env)->ExceptionCheck(env)){ - break; - } - } - } - - free(baseDir); - return array; -} - -static void handle_response(GtkWidget* aDialog, gint responseId, gpointer obj) -{ - JNIEnv *env; - GSList *filenames; - jstring jcurrent_folder = NULL; - jobjectArray jfilenames; - - env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); - filenames = NULL; - - if (responseId == GTK_RESPONSE_ACCEPT) { - filenames = gtk->gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog)); - } - - jfilenames = toFilenamesArray(env, filenames, &jcurrent_folder); - - if (!(*env)->ExceptionCheck(env)) { - (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, - jcurrent_folder, jfilenames); - } - - quit(env, (jobject)obj, TRUE); -} - -/* - * Class: sun_awt_X11_GtkFileDialogPeer - * Method: run - * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer, - jstring jtitle, jint mode, jstring jdir, jstring jfile, - jobject jfilter, jboolean multiple, int x, int y) -{ - GtkWidget *dialog = NULL; - GtkFileFilter *filter; - - if (jvm == NULL) { - (*env)->GetJavaVM(env, &jvm); - JNU_CHECK_EXCEPTION(env); - } - - gtk->gdk_threads_enter(); - - const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0); - if (title == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowOutOfMemoryError(env, "Could not get title"); - return; - } - - if (mode == java_awt_FileDialog_SAVE) { - /* Save action */ - dialog = gtk->gtk_file_chooser_dialog_new(title, NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); - } - else { - /* Default action OPEN */ - dialog = gtk->gtk_file_chooser_dialog_new(title, NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - - /* Set multiple selection mode, that is allowed only in OPEN action */ - if (multiple) { - gtk->gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), - multiple); - } - } - - if (jtitle != NULL) { - (*env)->ReleaseStringUTFChars(env, jtitle, title); - } - - /* Set the directory */ - if (jdir != NULL) { - const char *dir = (*env)->GetStringUTFChars(env, jdir, 0); - if (dir == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowOutOfMemoryError(env, "Could not get dir"); - return; - } - gtk->gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir); - (*env)->ReleaseStringUTFChars(env, jdir, dir); - } - - /* Set the filename */ - if (jfile != NULL) { - const char *filename = (*env)->GetStringUTFChars(env, jfile, 0); - if (filename == NULL) { - (*env)->ExceptionClear(env); - JNU_ThrowOutOfMemoryError(env, "Could not get filename"); - return; - } - if (mode == java_awt_FileDialog_SAVE) { - gtk->gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); - } else { - gtk->gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename); - } - (*env)->ReleaseStringUTFChars(env, jfile, filename); - } - - /* Set the file filter */ - if (jfilter != NULL) { - filter = gtk->gtk_file_filter_new(); - gtk->gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, - filenameFilterCallback, jpeer, NULL); - gtk->gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); - } - - /* Other Properties */ - if (gtk->gtk_check_version(2, 8, 0) == NULL || - gtk->gtk_check_version(3, 0, 0) == NULL) { - gtk->gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER( - dialog), TRUE); - } - - /* Set the initial location */ - if (x >= 0 && y >= 0) { - gtk->gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y); - - // NOTE: it doesn't set the initial size for the file chooser - // as it seems like the file chooser overrides the size internally - } - - gtk->g_signal_connect_data(dialog, "response", G_CALLBACK( - handle_response), jpeer, 0, 0); - - (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog)); - - gtk->gtk_widget_show(dialog); - - XID xid = gtk->gdk_x11_drawable_get_xid(gtk->get_window(dialog)); - if( (*env)->CallBooleanMethod(env, jpeer, setWindowMethodID, xid) ) { - gtk->gtk_main(); - } - - gtk->gdk_threads_leave(); -} - diff --git a/app/src/main/jni/awt_xawt/awt/swing_GTKEngine.c b/app/src/main/jni/awt_xawt/awt/swing_GTKEngine.c deleted file mode 100644 index 47c7ad23e..000000000 --- a/app/src/main/jni/awt_xawt/awt/swing_GTKEngine.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "gtk_interface.h" -#include "com_sun_java_swing_plaf_gtk_GTKEngine.h" - -/* Static buffer for conversion from java.lang.String to UTF-8 */ -static char conversionBuffer[CONV_BUFFER_SIZE]; - -const char *getStrFor(JNIEnv *env, jstring val) -{ - int length = (*env)->GetStringLength(env, val); - if (length > CONV_BUFFER_SIZE-1) - { - length = CONV_BUFFER_SIZE-1; - } - - (*env)->GetStringUTFRegion(env, val, 0, length, conversionBuffer); - return conversionBuffer; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_arrow - * Signature: (IIILjava/lang/String;IIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1arrow( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, jint arrow_type) -{ - gtk->gdk_threads_enter(); - gtk->paint_arrow(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, arrow_type, TRUE); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_box - * Signature: (IIILjava/lang/String;IIIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, - jint synth_state, jint dir) -{ - gtk->gdk_threads_enter(); - gtk->paint_box(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, synth_state, dir); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_box_gap - * Signature: (IIILjava/lang/String;IIIIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box_1gap( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, - jint gap_side, jint gap_x, jint gap_w) -{ - gtk->gdk_threads_enter(); - gtk->paint_box_gap(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, gap_side, gap_x, gap_w); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_check - * Signature: (IILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1check( - JNIEnv *env, jobject this, - jint widget_type, jint synth_state, jstring detail, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_check(widget_type, synth_state, getStrFor(env, detail), - x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_expander - * Signature: (IILjava/lang/String;IIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1expander( - JNIEnv *env, jobject this, - jint widget_type, jint state, jstring detail, - jint x, jint y, jint w, jint h, jint expander_style) -{ - gtk->gdk_threads_enter(); - gtk->paint_expander(widget_type, state, getStrFor(env, detail), - x, y, w, h, expander_style); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_extension - * Signature: (IIILjava/lang/String;IIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1extension( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, jint placement) -{ - gtk->gdk_threads_enter(); - gtk->paint_extension(widget_type, state, shadow_type, - getStrFor(env, detail), x, y, w, h, placement); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_flat_box - * Signature: (IIILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1flat_1box( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, jboolean has_focus) -{ - gtk->gdk_threads_enter(); - gtk->paint_flat_box(widget_type, state, shadow_type, - getStrFor(env, detail), x, y, w, h, has_focus); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_focus - * Signature: (IILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1focus( - JNIEnv *env, jobject this, - jint widget_type, jint state, jstring detail, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_focus(widget_type, state, getStrFor(env, detail), - x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_handle - * Signature: (IIILjava/lang/String;IIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1handle( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, jint orientation) -{ - gtk->gdk_threads_enter(); - gtk->paint_handle(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, orientation); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_hline - * Signature: (IILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1hline( - JNIEnv *env, jobject this, - jint widget_type, jint state, jstring detail, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_hline(widget_type, state, getStrFor(env, detail), - x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_option - * Signature: (IILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1option( - JNIEnv *env, jobject this, - jint widget_type, jint synth_state, jstring detail, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_option(widget_type, synth_state, getStrFor(env, detail), - x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_shadow - * Signature: (IIILjava/lang/String;IIIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1shadow( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, - jint synth_state, jint dir) -{ - gtk->gdk_threads_enter(); - gtk->paint_shadow(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, synth_state, dir); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_slider - * Signature: (IIILjava/lang/String;IIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1slider( - JNIEnv *env, jobject this, - jint widget_type, jint state, jint shadow_type, jstring detail, - jint x, jint y, jint w, jint h, jint orientation, jboolean has_focus) -{ - gtk->gdk_threads_enter(); - gtk->paint_slider(widget_type, state, shadow_type, getStrFor(env, detail), - x, y, w, h, orientation, has_focus); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_vline - * Signature: (IILjava/lang/String;IIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1vline( - JNIEnv *env, jobject this, - jint widget_type, jint state, jstring detail, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_vline(widget_type, state, getStrFor(env, detail), - x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_paint_background - * Signature: (IIIIII)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1background( - JNIEnv *env, jobject this, jint widget_type, jint state, - jint x, jint y, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->paint_background(widget_type, state, x, y, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: nativeStartPainting - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting( - JNIEnv *env, jobject this, jint w, jint h) -{ - gtk->gdk_threads_enter(); - gtk->init_painting(env, w, h); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: nativeFinishPainting - * Signature: ([III)I - */ -JNIEXPORT jint JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting( - JNIEnv *env, jobject this, jintArray dest, jint width, jint height) -{ - jint transparency; - gint *buffer = (gint*) (*env)->GetPrimitiveArrayCritical(env, dest, 0); - gtk->gdk_threads_enter(); - transparency = gtk->copy_image(buffer, width, height); - gtk->gdk_threads_leave(); - (*env)->ReleasePrimitiveArrayCritical(env, dest, buffer, 0); - return transparency; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_switch_theme - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme( - JNIEnv *env, jobject this) -{ - // Note that flush_gtk_event_loop takes care of locks (7053002) - gtk->gdk_threads_enter(); - gtk->flush_event_loop(); - gtk->gdk_threads_leave(); -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: native_get_gtk_setting - * Signature: (I)Ljava/lang/Object; - */ -JNIEXPORT jobject JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1get_1gtk_1setting( - JNIEnv *env, jobject this, jint property) -{ - jobject obj; - gtk->gdk_threads_enter(); - obj = gtk->get_setting(env, property); - gtk->gdk_threads_leave(); - return obj; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKEngine - * Method: nativeSetRangeValue - * Signature: (IDDDD)V - */ -JNIEXPORT void JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeSetRangeValue( - JNIEnv *env, jobject this, jint widget_type, - jdouble value, jdouble min, jdouble max, jdouble visible) -{ - gtk->gdk_threads_enter(); - gtk->set_range_value(widget_type, value, min, max, visible); - gtk->gdk_threads_leave(); -} diff --git a/app/src/main/jni/awt_xawt/awt/swing_GTKStyle.c b/app/src/main/jni/awt_xawt/awt/swing_GTKStyle.c deleted file mode 100644 index a977f6bee..000000000 --- a/app/src/main/jni/awt_xawt/awt/swing_GTKStyle.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include "gtk_interface.h" -#include "com_sun_java_swing_plaf_gtk_GTKStyle.h" - -const char *getStrFor(JNIEnv *env, jstring val); - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKStyle - * Method: nativeGetXThickness - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetXThickness( - JNIEnv *env, jclass klass, jint widget_type) -{ - jint ret; - gtk->gdk_threads_enter(); - ret = gtk->get_xthickness(env, widget_type); - gtk->gdk_threads_leave(); - return ret; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKStyle - * Method: nativeGetYThickness - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetYThickness( - JNIEnv *env, jclass klass, jint widget_type) -{ - jint ret; - gtk->gdk_threads_enter(); - ret = gtk->get_ythickness(env, widget_type); - gtk->gdk_threads_leave(); - return ret; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKStyle - * Method: nativeGetColorForState - * Signature: (III)I - */ -JNIEXPORT jint JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetColorForState( - JNIEnv *env, jclass klass, jint widget_type, - jint state_type, jint type_id) -{ - jint ret; - gtk->gdk_threads_enter(); - ret = gtk->get_color_for_state(env, widget_type, state_type, type_id); - gtk->gdk_threads_leave(); - return ret; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKStyle - * Method: nativeGetClassValue - * Signature: (ILjava/lang/String;)Ljava/lang/Object; - */ -JNIEXPORT jobject JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetClassValue( - JNIEnv *env, jclass klass, jint widget_type, jstring key) -{ - jobject ret; - gtk->gdk_threads_enter(); - ret = gtk->get_class_value(env, widget_type, getStrFor(env, key)); - gtk->gdk_threads_leave(); - return ret; -} - -/* - * Class: com_sun_java_swing_plaf_gtk_GTKStyle - * Method: nativeGetPangoFontName - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_com_sun_java_swing_plaf_gtk_GTKStyle_nativeGetPangoFontName( - JNIEnv *env, jclass klass, jint widget_type) -{ - jstring ret; - gtk->gdk_threads_enter(); - ret = gtk->get_pango_font_name(env, widget_type); - gtk->gdk_threads_leave(); - return ret; -} diff --git a/app/src/main/jni/awt_xawt/awt/wsutils.h b/app/src/main/jni/awt_xawt/awt/wsutils.h deleted file mode 100644 index 5903e1696..000000000 --- a/app/src/main/jni/awt_xawt/awt/wsutils.h +++ /dev/null @@ -1,380 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -/* $XConsortium: wsutils.h /main/3 1996/10/14 15:04:17 swick $ */ -/** ------------------------------------------------------------------------ - This file contains routines for manipulating generic lists. - Lists are implemented with a "harness". In other words, each - node in the list consists of two pointers, one to the data item - and one to the next node in the list. The head of the list is - the same struct as each node, but the "item" ptr is used to point - to the current member of the list (used by the first_in_list and - next_in_list functions). - - This file is available under and governed by the GNU General Public - License version 2 only, as published by the Free Software Foundation. - However, the following notice accompanied the original version of this - file: - -Copyright (c) 1994 Hewlett-Packard Co. -Copyright (c) 1996 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from the X Consortium. - - ------------------------------------------------------------------------ **/ -/****************************************************************************** - * - * This file contains various typedef's, macros and procedure declarations for - * a set of example utility procedures contained in the file "wsutils.c". - * - ******************************************************************************/ - -/* This is the actual structure returned by the X server describing the - * SERVER_OVERLAY_VISUAL property. - */ -typedef struct -{ - VisualID visualID; /* The VisualID of the overlay visual */ - long transparentType; /* Can be None, TransparentPixel or - * TransparentMask */ - long value; /* Pixel value */ - long layer; /* Overlay planes will always be in - * layer 1 */ -} OverlayVisualPropertyRec; - - -/* This is structure also describes the SERVER_OVERLAY_VISUAL property, but - * should be more useful than the one actually returned by the X server - * because it actually points to the visual's XVisualInfo struct rather than - * refering to the visual's ID. - */ -typedef struct -{ - XVisualInfo *pOverlayVisualInfo; /* Pointer to the XVisualInfo struct */ - long transparentType; /* Can be None, TransparentPixel or - * TransparentMask */ - long value; /* Pixel value */ - long layer; /* Overlay planes will always be in - * layer 1 */ -} OverlayInfo; - - -/* These macros are the values of the "transparentType" above: */ -#ifndef None -#define None 0 -#endif -#ifndef TransparentPixel -#define TransparentPixel 1 -#endif - - -/* These macros define how flexible a program is when it requests a window's - * creation with either the CreateImagePlanesWindow() or - * CreateOverlayPlanesWindow(): - */ -#ifndef NOT_FLEXIBLE -#define NOT_FLEXIBLE 0 -#define FLEXIBLE 1 -#endif - - -/* These macros define the values of the "sbCmapHint" parameter of the - * CreateImagePlanesWindow(): - */ -#ifndef SB_CMAP_TYPE_NORMAL -#define SB_CMAP_TYPE_NORMAL 1 -#endif - -#ifndef SB_CMAP_TYPE_MONOTONIC -#define SB_CMAP_TYPE_MONOTONIC 2 -#endif - -#ifndef SB_CMAP_TYPE_FULL -#define SB_CMAP_TYPE_FULL 4 -#endif - - -/****************************************************************************** - * - * GetXVisualInfo() - * - * This routine takes an X11 Display, screen number, and returns whether the - * screen supports transparent overlays and three arrays: - * - * 1) All of the XVisualInfo struct's for the screen. - * 2) All of the OverlayInfo struct's for the screen. - * 3) An array of pointers to the screen's image plane XVisualInfo - * structs. - * - * The code below obtains the array of all the screen's visuals, and obtains - * the array of all the screen's overlay visual information. It then processes - * the array of the screen's visuals, determining whether the visual is an - * overlay or image visual. - * - * If the routine sucessfully obtained the visual information, it returns zero. - * If the routine didn't obtain the visual information, it returns non-zero. - * - ******************************************************************************/ - -extern int32_t GetXVisualInfo( -#if NeedFunctionPrototypes - Display *display, /* Which X server (aka "display"). */ - int32_t screen, /* Which screen of the "display". */ - int32_t *transparentOverlays, /* Non-zero if there's at least one - * overlay visual and if at least one - * of those supports a transparent - * pixel. */ - int32_t *numVisuals, /* Number of XVisualInfo struct's - * pointed to by pVisuals. */ - XVisualInfo **pVisuals, /* All of the device's visuals. */ - int32_t *numOverlayVisuals, /* Number of OverlayInfo's pointed - * to by pOverlayVisuals. If this - * number is zero, the device does - * not have overlay planes. */ - OverlayInfo **pOverlayVisuals, /* The device's overlay plane visual - * information. */ - int32_t *numImageVisuals, /* Number of XVisualInfo's pointed - * to by pImageVisuals. */ - XVisualInfo ***pImageVisuals /* The device's image visuals. */ -#endif - ); - - -/****************************************************************************** - * - * FreeXVisualInfo() - * - * This routine frees the data that was allocated by GetXVisualInfo(). - * - ******************************************************************************/ - -extern void FreeXVisualInfo( -#if NeedFunctionPrototypes - XVisualInfo *pVisuals, - OverlayInfo *pOverlayVisuals, - XVisualInfo **pImageVisuals -#endif - ); - - -/****************************************************************************** - * - * FindImagePlanesVisual() - * - * This routine attempts to find a visual to use to create an image planes - * window based upon the information passed in. - * - * The "Hint" values give guides to the routine as to what the program wants. - * The "depthFlexibility" value tells the routine how much the program wants - * the actual "depthHint" specified. If the program can't live with the - * screen's image planes visuals, the routine returns non-zero, and the - * "depthObtained" and "pImageVisualToUse" return parameters are NOT valid. - * Otherwise, the "depthObtained" and "pImageVisualToUse" return parameters - * are valid and the routine returns zero. - * - * NOTE: This is just an example of what can be done. It may or may not be - * useful for any specific application. - * - ******************************************************************************/ - -extern int32_t FindImagePlanesVisual( -#if NeedFunctionPrototypes - Display *display, /* Which X server (aka "display"). */ - int32_t screen, /* Which screen of the "display". */ - int32_t numImageVisuals, /* Number of XVisualInfo's pointed - * to by pImageVisuals. */ - XVisualInfo **pImageVisuals, /* The device's image visuals. */ - int32_t sbCmapHint, /* What Starbase cmap modes will be - * used with the visual. NOTE: This - * is a mask of the possible values. */ - int32_t depthHint, /* Desired depth. */ - int32_t depthFlexibility, /* How much the actual value in - * "depthHint" is desired. */ - Visual **pImageVisualToUse, /* The screen's image visual to use. */ - int32_t *depthObtained /* Actual depth of the visual. */ -#endif - ); - - -/****************************************************************************** - * - * FindOverlayPlanesVisual() - * - * This routine attempts to find a visual to use to create an overlay planes - * window based upon the information passed in. - * - * While the CreateImagePlanesWindow() routine took a sbCmapHint, this - * routine doesn't. Starbase's CMAP_FULL shouldn't be used in overlay planes - * windows. This is partially because this functionality is better suited in - * the image planes where there are generally more planes, and partially - * because the overlay planes generally have PseudoColor visuals with one - * color being transparent (the transparent normally being the "white" color - * for CMAP_FULL). - * - * The "depthHint" values give guides to the routine as to what depth the - * program wants the window to be. The "depthFlexibility" value tells the - * routine how much the program wants the actual "depthHint" specified. If - * the program can't live with the screen's overlay planes visuals, the - * routine returns non-zero, and the "depthObtained" and "pOverlayVisualToUse" - * return parameters are NOT valid. Otherwise, the "depthObtained" and - * "pOverlayVisualToUse" return parameters are valid and the routine returns - * zero. - * - * NOTE: This is just an example of what can be done. It may or may not be - * useful for any specific application. - * - ******************************************************************************/ - -extern int32_t FindOverlayPlanesVisual( -#if NeedFunctionPrototypes - Display *display, /* Which X server (aka "display"). */ - int32_t screen, /* Which screen of the "display". */ - int32_t numOverlayVisuals, /* Number of OverlayInfo's pointed - * to by pOverlayVisuals. */ - OverlayInfo *pOverlayVisuals, /* The device's overlay plane visual - * information. */ - int32_t depthHint, /* Desired depth. */ - int32_t depthFlexibility, /* How much the actual value in - * "depthHint" is desired. */ - int32_t transparentBackground, /* Non-zero if the visual must have - * a transparent color. */ - Visual **pOverlayVisualToUse, /* The screen's overlay visual to - * use. */ - int32_t *depthObtained, /* Actual depth of the visual. */ - int32_t *transparentColor /* The transparent color the program - * can use with the visual. */ -#endif - ); - - -/****************************************************************************** - * - * CreateImagePlanesWindow() - * - * This routine creates an image planes window, potentially creates a colormap - * for the window to use, and sets the window's standard properties, based - * upon the information passed in to the routine. While "created," the window - * has not been mapped. - * - * If the routine suceeds, it returns zero and the return parameters - * "imageWindow", "imageColormap" and "mustFreeImageColormap" are valid. - * Otherwise, the routine returns non-zero and the return parameters are - * NOT valid. - * - * NOTE: This is just an example of what can be done. It may or may not be - * useful for any specific application. - * - ******************************************************************************/ - -extern int32_t CreateImagePlanesWindow( -#if NeedFunctionPrototypes - Display *display, /* Which X server (aka "display"). */ - int32_t screen, /* Which screen of the "display". */ - Window parentWindow, /* Window ID of the parent window for - * the created window. */ - int32_t windowX, /* Desired X coord. of the window. */ - int32_t windowY, /* Desired Y coord of the window. */ - int32_t windowWidth, /* Desired width of the window. */ - int32_t windowHeight, /* Desired height of the window. */ - int32_t windowDepth, /* Desired depth of the window. */ - Visual *pImageVisualToUse, /* The window's image planes visual. */ - int32_t argc, /* Program's argc parameter. */ - char *argv[], /* Program's argv parameter. */ - char *windowName, /* Name to put on window's border. */ - char *iconName, /* Name to put on window's icon. */ - Window *imageWindow, /* Window ID of the created window. */ - Colormap *imageColormap, /* The window's colormap. */ - int32_t *mustFreeImageColormap /* Non-zero if the program must call - * XFreeColormap() for imageColormap. */ -#endif - ); - - -/****************************************************************************** - * - * CreateOverlayPlanesWindow() - * - * This routine creates an overlay planes window, potentially creates a colormap - * for the window to use, and sets the window's standard properties, based - * upon the information passed in to the routine. While "created," the window - * has not been mapped. - * - * If the routine suceeds, it returns zero and the return parameters - * "overlayWindow", "overlayColormap" and "mustFreeOverlayColormap" are valid. - * Otherwise, the routine returns non-zero and the return parameters are - * NOT valid. - * - * NOTE: This is just an example of what can be done. It may or may not be - * useful for any specific application. - * - ******************************************************************************/ - -int32_t CreateOverlayPlanesWindow( -#if NeedFunctionPrototypes - Display *display, /* Which X server (aka "display"). */ - int32_t screen, /* Which screen of the "display". */ - Window parentWindow, /* Window ID of the parent window for - * the created window. */ - int32_t windowX, /* Desired X coord. of the window. */ - int32_t windowY, /* Desired Y coord of the window. */ - int32_t windowWidth, /* Desired width of the window. */ - int32_t windowHeight, /* Desired height of the window. */ - int32_t windowDepth, /* Desired depth of the window. */ - Visual *pOverlayVisualToUse, /* The window's overlay planes visual.*/ - int32_t argc, /* Program's argc parameter. */ - char *argv[], /* Program's argv parameter. */ - char *windowName, /* Name to put on window's border. */ - char *iconName, /* Name to put on window's icon. */ - int32_t transparentBackground, /* Non-zero if the window's background - * should be a transparent color. */ - int32_t *transparentColor, /* The transparent color to use as the - * window's background. */ - Window *overlayWindow, /* Window ID of the created window. */ - Colormap *overlayColormap, /* The window's colormap. */ - int32_t *mustFreeOverlayColormap/* Non-zero if the program must call - * XFreeColormap() for - * overlayColormap. */ -#endif - ); diff --git a/app/src/main/jni/awt_xawt/java2d/x11/XRBackendNative.c b/app/src/main/jni/awt_xawt/java2d/x11/XRBackendNative.c deleted file mode 100644 index 9410001da..000000000 --- a/app/src/main/jni/awt_xawt/java2d/x11/XRBackendNative.c +++ /dev/null @@ -1,1112 +0,0 @@ -/* - * Copyright (c) 2010, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "X11SurfaceData.h" -#include -#include -#include "Region.h" -#include "fontscalerdefs.h" - -#include - -#ifdef __linux__ - #include -#endif - -/* On Solaris 10 updates 8, 9, the render.h file defines these - * protocol values but does not define the structs in Xrender.h. - * Thus in order to get these always defined on Solaris 10 - * we will undefine the symbols if we have determined via the - * makefiles that Xrender.h is lacking the structs. This will - * trigger providing our own definitions as on earlier updates. - * We could assume that *all* Solaris 10 update versions will lack the updated - * Xrender.h and do this based solely on O/S being any 5.10 version, but this - * could still change and we'd be broken again as we'd be re-defining them. - */ -#ifdef SOLARIS10_NO_XRENDER_STRUCTS -#undef X_RenderCreateLinearGradient -#undef X_RenderCreateRadialGradient -#endif - -#ifndef X_RenderCreateLinearGradient -typedef struct _XLinearGradient { - XPointFixed p1; - XPointFixed p2; -} XLinearGradient; -#endif - -#ifndef X_RenderCreateRadialGradient -typedef struct _XCircle { - XFixed x; - XFixed y; - XFixed radius; -} XCircle; - -typedef struct _XRadialGradient { - XCircle inner; - XCircle outer; -} XRadialGradient; -#endif - -#include - -#if defined(__solaris__) -/* Solaris 10 will not have these symbols at compile time */ - -typedef Picture (*XRenderCreateLinearGradientFuncType) - (Display *dpy, - const XLinearGradient *gradient, - const XFixed *stops, - const XRenderColor *colors, - int nstops); - -typedef Picture (*XRenderCreateRadialGradientFuncType) - (Display *dpy, - const XRadialGradient *gradient, - const XFixed *stops, - const XRenderColor *colors, - int nstops); - -static -XRenderCreateLinearGradientFuncType XRenderCreateLinearGradientFunc = NULL; -static - XRenderCreateRadialGradientFuncType XRenderCreateRadialGradientFunc = NULL; -#endif - -#define BUILD_TRANSFORM_MATRIX(TRANSFORM, M00, M01, M02, M10, M11, M12) \ - { \ - TRANSFORM.matrix[0][0] = M00; \ - TRANSFORM.matrix[0][1] = M01; \ - TRANSFORM.matrix[0][2] = M02; \ - TRANSFORM.matrix[1][0] = M10; \ - TRANSFORM.matrix[1][1] = M11; \ - TRANSFORM.matrix[1][2] = M12; \ - TRANSFORM.matrix[2][0] = 0; \ - TRANSFORM.matrix[2][1] = 0; \ - TRANSFORM.matrix[2][2] = 1<<16; \ - } - -/* The xrender pipleine requires libXrender.so version 0.9.3 or later. */ -#define REQUIRED_XRENDER_VER1 0 -#define REQUIRED_XRENDER_VER2 9 -#define REQUIRED_XRENDER_VER3 3 - -#define PKGINFO_LINE_LEN_MAX 256 -#define PKGINFO_LINE_CNT_MAX 50 - -/* - * X protocol uses (u_int16)length to specify the length in 4 bytes quantities - * of the whole request. Both XRenderFillRectangles() and XFillRectangles() - * have provisions to fragment into several requests if the number of rectangles - * plus the current x request does not fit into 65535*4 bytes. While - * XRenderCreateLinearGradient() and XRenderCreateRadialGradient() have - * provisions to gracefully degrade if the resulting request would exceed - * 65535*4 bytes. - * - * Below, we define a cap of 65535*4 bytes for the maximum X request payload - * allowed for Non-(XRenderFillRectangles() or XFillRectangles()) API calls, - * just to be conservative. This is offset by the size of our maximum x*Req - * type in this compilation unit, which is xRenderCreateRadiaGradientReq. - * - * Note that sizeof(xRenderCreateRadiaGradientReq) = 36 - */ -#define MAX_PAYLOAD (262140u - 36u) -#define MAXUINT (0xffffffffu) - -static jboolean IsXRenderAvailable(jboolean verbose, jboolean ignoreLinuxVersion) { - - void *xrenderlib; - - int major_opcode, first_event, first_error; - jboolean available = JNI_TRUE; - - if (!XQueryExtension(awt_display, "RENDER", - &major_opcode, &first_event, &first_error)) { - return JNI_FALSE; - } - -#if defined(_AIX) - // On AIX we have to use a special syntax because the shared libraries are packed in - // multi-architecture archives. We first try to load the system default libXrender - // which is contained in the 'X11.base.lib' fileset starting with AIX 6.1 - xrenderlib = dlopen("libXrender.a(shr_64.o)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER); - if (xrenderlib == NULL) { - // If the latter wasn't successful, we also try to load the version under /opt/freeware - // This may be downloaded from the "AIX Toolbox for Linux Applications" even for AIX 5.3 - xrenderlib = dlopen("libXrender.a(libXrender.so.0)", RTLD_GLOBAL | RTLD_LAZY | RTLD_MEMBER); - } - if (xrenderlib != NULL) { - dlclose(xrenderlib); - } else { - available = JNI_FALSE; - } -#elif defined(__solaris__) - xrenderlib = dlopen("libXrender.so",RTLD_GLOBAL|RTLD_LAZY); - if (xrenderlib != NULL) { - - XRenderCreateLinearGradientFunc = - (XRenderCreateLinearGradientFuncType) - dlsym(xrenderlib, "XRenderCreateLinearGradient"); - - XRenderCreateRadialGradientFunc = - (XRenderCreateRadialGradientFuncType) - dlsym(xrenderlib, "XRenderCreateRadialGradient"); - - if (XRenderCreateLinearGradientFunc == NULL || - XRenderCreateRadialGradientFunc == NULL) - { - available = JNI_FALSE; - } - dlclose(xrenderlib); - } else { - available = JNI_FALSE; - } -#else - Dl_info info; - jboolean versionInfoIsFound = JNI_FALSE; - - memset(&info, 0, sizeof(Dl_info)); - if (dladdr(&XRenderChangePicture, &info) && info.dli_fname != NULL) { - char pkgInfoPath[FILENAME_MAX]; - char *pkgFileName = "/pkgconfig/xrender.pc"; - size_t pkgFileNameLen = strlen(pkgFileName); - size_t pos, len = strlen(info.dli_fname); - - pos = len; - while (pos > 0 && info.dli_fname[pos] != '/') { - pos -= 1; - } - - if (pos > 0 && pos < (FILENAME_MAX - pkgFileNameLen - 1)) { - struct stat stat_info; - - // compose absolute filename to package config - strncpy(pkgInfoPath, info.dli_fname, pos); - - strcpy(pkgInfoPath + pos, pkgFileName); - pkgInfoPath[pos + pkgFileNameLen] = '\0'; - - // check whether the config file exist and is a regular file - if ((stat(pkgInfoPath, &stat_info)== 0) && - S_ISREG(stat_info.st_mode)) - { - FILE *fp = fopen(pkgInfoPath, "r"); - if (fp != NULL) { - char line[PKGINFO_LINE_LEN_MAX]; - int lineCount = PKGINFO_LINE_CNT_MAX; - char *versionPrefix = "Version: "; - size_t versionPrefixLen = strlen(versionPrefix); - - // look for version - while(fgets(line,sizeof(line),fp) != NULL && --lineCount > 0) { - size_t lineLen = strlen(line); - - if (lineLen > versionPrefixLen && - strncmp(versionPrefix, line, versionPrefixLen) == 0) - { - int v1 = 0, v2 = 0, v3 = 0; - int numNeeded = 3,numProcessed; - char* version = line + versionPrefixLen; - numProcessed = sscanf(version, "%d.%d.%d", &v1, &v2, &v3); - - if (numProcessed == numNeeded) { - // we successfuly read the library version - versionInfoIsFound = JNI_TRUE; - - if (REQUIRED_XRENDER_VER1 == v1 && - ((REQUIRED_XRENDER_VER2 > v2) || - ((REQUIRED_XRENDER_VER2 == v2) && (REQUIRED_XRENDER_VER3 > v3)))) - { - available = JNI_FALSE; - - if (verbose) { - printf("INFO: the version %d.%d.%d of libXrender.so is " - "not supported.\n\tSee release notes for more details.\n", - v1, v2, v3); - fflush(stdout); - } - } else { - if (verbose) { - printf("INFO: The version of libXrender.so " - "is detected as %d.%d%d\n", v1, v2, v3); - fflush(stdout); - } - } - } - break; - } - } - fclose(fp); - } - } - } - } - if (verbose && !versionInfoIsFound) { - printf("WARNING: The version of libXrender.so cannot be detected.\n," - "The pipe line will be enabled, but note that versions less than 0.9.3\n" - "may cause hangs and crashes\n" - "\tSee the release notes for more details.\n"); - fflush(stdout); - } -#endif - -#ifdef __linux__ - /* - * Check for Linux >= 3.5 (Ubuntu 12.04.02 LTS) to avoid hitting - * https://bugs.freedesktop.org/show_bug.cgi?id=48045 - */ - struct utsname utsbuf; - if(uname(&utsbuf) >= 0) { - int major, minor, revision; - if(sscanf(utsbuf.release, "%i.%i.%i", &major, &minor, &revision) == 3) { - if(major < 3 || (major == 3 && minor < 5)) { - if(!ignoreLinuxVersion) { - available = JNI_FALSE; - } - else if(verbose) { - printf("WARNING: Linux < 3.5 detected.\n" - "The pipeline will be enabled, but graphical " - "artifacts can occur with old graphic drivers.\n" - "See the release notes for more details.\n"); - fflush(stdout); - } - } - } - } -#endif // __linux__ - - return available; -} -/* - * Class: sun_awt_X11GraphicsEnvironment - * Method: initGLX - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11GraphicsEnvironment_initXRender -(JNIEnv *env, jclass x11ge, jboolean verbose, jboolean ignoreLinuxVersion) -{ -#ifndef HEADLESS - static jboolean xrenderAvailable = JNI_FALSE; - static jboolean firstTime = JNI_TRUE; - - if (firstTime) { -#ifdef DISABLE_XRENDER_BY_DEFAULT - if (verbose == JNI_FALSE) { - xrenderAvailable = JNI_FALSE; - firstTime = JNI_FALSE; - return xrenderAvailable; - } -#endif - AWT_LOCK(); - xrenderAvailable = IsXRenderAvailable(verbose, ignoreLinuxVersion); - AWT_UNLOCK(); - firstTime = JNI_FALSE; - } - return xrenderAvailable; -#else - return JNI_FALSE; -#endif /* !HEADLESS */ -} - - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_initIDs(JNIEnv *env, jclass cls) { - char *maskData; - XImage* defaultImg; - jfieldID maskImgID; - jlong fmt8; - jlong fmt32; - - jfieldID a8ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_A8", "J"); - if (a8ID == NULL) { - return; - } - jfieldID argb32ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_ARGB32", "J"); - if (argb32ID == NULL) { - return; - } - - if (awt_display == (Display *)NULL) { - return; - } - - fmt8 = ptr_to_jlong(XRenderFindStandardFormat(awt_display, PictStandardA8)); - fmt32 = ptr_to_jlong(XRenderFindStandardFormat(awt_display, PictStandardARGB32)); - - (*env)->SetStaticLongField(env, cls, a8ID, fmt8); - (*env)->SetStaticLongField(env, cls, argb32ID, fmt32); - - maskData = (char *) malloc(32*32); - if (maskData == NULL) { - return; - } - - defaultImg = XCreateImage(awt_display, NULL, 8, ZPixmap, 0, maskData, 32, 32, 8, 0); - defaultImg->data = maskData; //required? - maskImgID = (*env)->GetStaticFieldID(env, cls, "MASK_XIMG", "J"); - if (maskImgID == NULL) { - return; - } - - (*env)->SetStaticLongField(env, cls, maskImgID, ptr_to_jlong(defaultImg)); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_freeGC - (JNIEnv *env, jobject this, jlong gc) { - XFreeGC(awt_display, (GC) jlong_to_ptr(gc)); -} - -JNIEXPORT jlong JNICALL -Java_sun_java2d_xr_XRBackendNative_createGC - (JNIEnv *env, jobject this, jint drawable) { - GC xgc = XCreateGC(awt_display, (Drawable) drawable, 0L, NULL); - return ptr_to_jlong(xgc); -} - -JNIEXPORT jint JNICALL -Java_sun_java2d_xr_XRBackendNative_createPixmap(JNIEnv *env, jobject this, - jint drawable, jint depth, - jint width, jint height) { - return (jint) XCreatePixmap(awt_display, (Drawable) drawable, - width, height, depth); -} - -JNIEXPORT jint JNICALL -Java_sun_java2d_xr_XRBackendNative_createPictureNative - (JNIEnv *env, jclass cls, jint drawable, jlong formatPtr) { - XRenderPictureAttributes pict_attr; - return XRenderCreatePicture(awt_display, (Drawable) drawable, - (XRenderPictFormat *) jlong_to_ptr(formatPtr), - 0, &pict_attr); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_freePicture - (JNIEnv *env, jobject this, jint picture) { - XRenderFreePicture(awt_display, (Picture) picture); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_freePixmap - (JNIEnv *env, jobject this, jint pixmap) { - XFreePixmap(awt_display, (Pixmap) pixmap); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_setPictureRepeat - (JNIEnv *env, jobject this, jint picture, jint repeat) { - XRenderPictureAttributes pict_attr; - pict_attr.repeat = repeat; - XRenderChangePicture (awt_display, (Picture) picture, CPRepeat, &pict_attr); -} - - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_setGCExposures - (JNIEnv *env, jobject this, jlong gc, jboolean exposure) { - XSetGraphicsExposures(awt_display, - (GC) jlong_to_ptr(gc), exposure ? True : False); //TODO: ???? -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_setGCForeground - (JNIEnv *env, jobject this, jlong gc, jint pixel) { - XSetForeground(awt_display, (GC) jlong_to_ptr(gc), (unsigned long) pixel); -} - - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_copyArea - (JNIEnv *env, jobject this, jint src, jint dst, jlong gc, - jint srcx, jint srcy, jint width, jint height, jint dstx, jint dsty) { - XCopyArea(awt_display, (Drawable) src, (Drawable) dst, - (GC) jlong_to_ptr(gc), srcx, srcy, width, height, dstx, dsty); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_renderComposite - (JNIEnv *env, jobject this, jbyte op, jint src, jint mask, jint dst, - jint srcX, jint srcY, jint maskX, jint maskY, - jint dstX, jint dstY, jint width, jint height) { - XRenderComposite (awt_display, op, - (Picture)src, (Picture)mask, (Picture)dst, - srcX, srcY, maskX, maskY, dstX, dstY, width, height); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_renderRectangle - (JNIEnv *env, jobject this, jint dst, jbyte op, - jshort red, jshort green, jshort blue, jshort alpha, - jint x, jint y, jint width, jint height) { - XRenderColor color; - color.alpha = alpha; - color.red = red; - color.green = green; - color.blue = blue; - XRenderFillRectangle(awt_display, op, (Picture) dst, &color, - x, y, width, height); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRenderRectanglesNative - (JNIEnv *env, jclass xsd, jint dst, jbyte op, - jshort red, jshort green, jshort blue, jshort alpha, - jintArray rectArray, jint rectCnt) { - int i; - jint* rects; - XRectangle *xRects; - XRectangle sRects[256]; - - XRenderColor color; - color.alpha = alpha; - color.red = red; - color.green = green; - color.blue = blue; - - if (rectCnt <= 256) { - xRects = &sRects[0]; - } else { - if (MAXUINT / sizeof(XRectangle) < (unsigned)rectCnt) { - /* rectCnt too big, integer overflow */ - return; - } - xRects = (XRectangle *) malloc(sizeof(XRectangle) * rectCnt); - if (xRects == NULL) { - return; - } - } - - if ((rects = (jint *) - (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL)) == NULL) { - if (xRects != &sRects[0]) { - free(xRects); - } - return; - } - - for (i=0; i < rectCnt; i++) { - xRects[i].x = rects[i*4 + 0]; - xRects[i].y = rects[i*4 + 1]; - xRects[i].width = rects[i*4 + 2]; - xRects[i].height = rects[i*4 + 3]; - } - - XRenderFillRectangles(awt_display, op, - (Picture) dst, &color, xRects, rectCnt); - - (*env)->ReleasePrimitiveArrayCritical(env, rectArray, rects, JNI_ABORT); - if (xRects != &sRects[0]) { - free(xRects); - } -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRSetTransformNative - (JNIEnv *env, jclass xsd, jint pic, - jint m00, jint m01, jint m02, jint m10, jint m11, jint m12) { - - XTransform tr; - BUILD_TRANSFORM_MATRIX(tr, m00, m01, m02, m10, m11, m12); - XRenderSetPictureTransform (awt_display, (Picture) pic, &tr); -} - -JNIEXPORT jint JNICALL -Java_sun_java2d_xr_XRBackendNative_XRCreateLinearGradientPaintNative - (JNIEnv *env, jclass xsd, jfloatArray fractionsArray, - jshortArray pixelsArray, jint x1, jint y1, jint x2, jint y2, - jint numStops, jint repeat) { - jint i; - jshort* pixels; - jfloat* fractions; - XRenderPictureAttributes pict_attr; - Picture gradient = 0; - XRenderColor *colors; - XFixed *stops; - XLinearGradient grad; - - if (MAX_PAYLOAD / (sizeof(XRenderColor) + sizeof(XFixed)) - < (unsigned)numStops) { - /* numStops too big, payload overflow */ - return -1; - } - - if ((pixels = (jshort *) - (*env)->GetPrimitiveArrayCritical(env, pixelsArray, NULL)) == NULL) { - return -1; - } - if ((fractions = (jfloat *) - (*env)->GetPrimitiveArrayCritical(env, fractionsArray, NULL)) == NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, - pixelsArray, pixels, JNI_ABORT); - return -1; - } - - grad.p1.x = x1; - grad.p1.y = y1; - grad.p2.x = x2; - grad.p2.y = y2; - - /*TODO optimized & malloc check*/ - colors = (XRenderColor *) malloc(numStops * sizeof(XRenderColor)); - stops = (XFixed *) malloc(numStops * sizeof(XFixed)); - - if (colors == NULL || stops == NULL) { - if (colors != NULL) { - free(colors); - } - if (stops != NULL) { - free(stops); - } - (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT); - return -1; - } - - for (i=0; i < numStops; i++) { - stops[i] = XDoubleToFixed(fractions[i]); - colors[i].alpha = pixels[i*4 + 0]; - colors[i].red = pixels[i*4 + 1]; - colors[i].green = pixels[i*4 + 2]; - colors[i].blue = pixels[i*4 + 3]; - } -#ifdef __solaris__ - if (XRenderCreateLinearGradientFunc!=NULL) { - gradient = (*XRenderCreateLinearGradientFunc)(awt_display, &grad, stops, colors, numStops); - } -#else - gradient = XRenderCreateLinearGradient(awt_display, &grad, stops, colors, numStops); -#endif - free(colors); - free(stops); - - (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT); - - if (gradient != 0) { - pict_attr.repeat = repeat; - XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr); - } - - return (jint) gradient; -} - - -JNIEXPORT jint JNICALL -Java_sun_java2d_xr_XRBackendNative_XRCreateRadialGradientPaintNative - (JNIEnv *env, jclass xsd, jfloatArray fractionsArray, - jshortArray pixelsArray, jint numStops, - jint centerX, jint centerY, - jint innerRadius, jint outerRadius, jint repeat) { - jint i; - jshort* pixels; - jfloat* fractions; - XRenderPictureAttributes pict_attr; - Picture gradient = 0; - XRenderColor *colors; - XFixed *stops; - XRadialGradient grad; - - if (MAX_PAYLOAD / (sizeof(XRenderColor) + sizeof(XFixed)) - < (unsigned)numStops) { - /* numStops too big, payload overflow */ - return -1; - } - - if ((pixels = - (jshort *)(*env)->GetPrimitiveArrayCritical(env, pixelsArray, NULL)) == NULL) { - return -1; - } - if ((fractions = (jfloat *) - (*env)->GetPrimitiveArrayCritical(env, fractionsArray, NULL)) == NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, - pixelsArray, pixels, JNI_ABORT); - return -1; //TODO release pixels first - } - - grad.inner.x = centerX; - grad.inner.y = centerY; - grad.inner.radius = innerRadius; - grad.outer.x = centerX; - grad.outer.y = centerY; - grad.outer.radius = outerRadius; - - /*TODO optimized & malloc check*/ - colors = (XRenderColor *) malloc(numStops * sizeof(XRenderColor)); - stops = (XFixed *) malloc(numStops * sizeof(XFixed)); - - if (colors == NULL || stops == NULL) { - if (colors != NULL) { - free(colors); - } - if (stops != NULL) { - free(stops); - } - (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT); - return -1; - } - - for (i=0; i < numStops; i++) { - stops[i] = XDoubleToFixed(fractions[i]); - colors[i].alpha = pixels[i*4 + 0]; - colors[i].red = pixels[i*4 + 1]; - colors[i].green = pixels[i*4 + 2]; - colors[i].blue = pixels[i*4 + 3]; - } -#ifdef __solaris__ - if (XRenderCreateRadialGradientFunc != NULL) { - gradient = (jint) (*XRenderCreateRadialGradientFunc)(awt_display, &grad, stops, colors, numStops); - } -#else - gradient = (jint) XRenderCreateRadialGradient(awt_display, &grad, stops, colors, numStops); -#endif - free(colors); - free(stops); - - (*env)->ReleasePrimitiveArrayCritical(env, pixelsArray, pixels, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, fractions, JNI_ABORT); - - - if (gradient != 0) { - pict_attr.repeat = repeat; - XRenderChangePicture (awt_display, gradient, CPRepeat, &pict_attr); - } - - return (jint) gradient; -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_setFilter - (JNIEnv *env, jobject this, jint picture, jint filter) { - - char * filterName = "fast"; - - switch(filter) { - case 0: - filterName = "fast"; - break; - - case 1: - filterName = "good"; - break; - - case 2: - filterName = "best"; - break; - } - - XRenderSetPictureFilter(awt_display, (Picture) picture, filterName, NULL, 0); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRSetClipNative - (JNIEnv *env, jclass xsd, jlong dst, - jint x1, jint y1, jint x2, jint y2, - jobject complexclip, jboolean isGC) -{ - int numrects; - XRectangle rects[256]; - XRectangle *pRect = rects; - - numrects = RegionToYXBandedRectangles(env, - x1, y1, x2, y2, complexclip, - &pRect, 256); - - if (isGC == JNI_TRUE) { - if (dst != (jlong) 0) { - XSetClipRectangles(awt_display, (GC) jlong_to_ptr(dst), 0, 0, pRect, numrects, YXBanded); - } - } else { - XRenderSetPictureClipRectangles (awt_display, (Picture) dst, 0, 0, pRect, numrects); - } - - if (pRect != rects) { - free(pRect); - } -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_putMaskNative - (JNIEnv *env, jclass cls, jint drawable, jlong gc, jbyteArray imageData, - jint sx, jint sy, jint dx, jint dy, jint width, jint height, - jint maskOff, jint maskScan, jfloat ea, jlong imgPtr) { - - int line, pix; - char *mask; - char *defaultData; - XImage *defaultImg, *img; - jboolean imageFits; - - if ((mask = (char *) - (*env)->GetPrimitiveArrayCritical(env, imageData, NULL)) == NULL) { - return; - } - - defaultImg = (XImage *) jlong_to_ptr(imgPtr); - - if (ea != 1.0f) { - for (line=0; line < height; line++) { - for (pix=0; pix < width; pix++) { - int index = maskScan*line + pix + maskOff; - mask[index] = (((unsigned char) mask[index])*ea); - } - } - } - - /* - * 1. If existing XImage and supplied buffer match, only adjust the data pointer - * 2. If existing XImage is large enough to hold the data but does not match in - * scan the data is copied to fit the XImage. - * 3. If data is larger than the existing XImage a new temporary XImage is - * allocated. - * The default XImage is optimized for the AA tiles, which are currently 32x32. - */ - defaultData = defaultImg->data; - img = defaultImg; - imageFits = defaultImg->width >= width && defaultImg->height >= height; - - if (imageFits && - maskOff == defaultImg->xoffset && maskScan == defaultImg->bytes_per_line) { - defaultImg->data = mask; - } else { - if (imageFits) { - for (line=0; line < height; line++) { - for (pix=0; pix < width; pix++) { - img->data[line*img->bytes_per_line + pix] = - (unsigned char) (mask[maskScan*line + pix + maskOff]); - } - } - } else { - img = XCreateImage(awt_display, NULL, 8, ZPixmap, - maskOff, mask, maskScan, height, 8, 0); - } - } - - XPutImage(awt_display, (Pixmap) drawable, (GC) jlong_to_ptr(gc), - img, 0, 0, 0, 0, width, height); - (*env)->ReleasePrimitiveArrayCritical(env, imageData, mask, JNI_ABORT); - - if (img != defaultImg) { - img->data = NULL; - XDestroyImage(img); - } - defaultImg->data = defaultData; -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRAddGlyphsNative - (JNIEnv *env, jclass cls, jint glyphSet, - jlongArray glyphInfoPtrsArray, jint glyphCnt, - jbyteArray pixelDataArray, int pixelDataLength) { - jlong *glyphInfoPtrs; - unsigned char *pixelData; - int i; - - if (MAX_PAYLOAD / (sizeof(XGlyphInfo) + sizeof(Glyph)) - < (unsigned)glyphCnt) { - /* glyphCnt too big, payload overflow */ - return; - } - - XGlyphInfo *xginfo = (XGlyphInfo *) malloc(sizeof(XGlyphInfo) * glyphCnt); - Glyph *gid = (Glyph *) malloc(sizeof(Glyph) * glyphCnt); - - if (xginfo == NULL || gid == NULL) { - if (xginfo != NULL) { - free(xginfo); - } - if (gid != NULL) { - free(gid); - } - return; - } - - if ((glyphInfoPtrs = (jlong *)(*env)-> - GetPrimitiveArrayCritical(env, glyphInfoPtrsArray, NULL)) == NULL) - { - free(xginfo); - free(gid); - return; - } - - if ((pixelData = (unsigned char *) - (*env)->GetPrimitiveArrayCritical(env, pixelDataArray, NULL)) == NULL) - { - (*env)->ReleasePrimitiveArrayCritical(env, - glyphInfoPtrsArray, glyphInfoPtrs, JNI_ABORT); - free(xginfo); - free(gid); - return; - } - - for (i=0; i < glyphCnt; i++) { - GlyphInfo *jginfo = (GlyphInfo *) jlong_to_ptr(glyphInfoPtrs[i]); - - // 'jginfo->cellInfo' is of type 'void*' - // (see definition of 'GlyphInfo' in fontscalerdefs.h) - // 'Glyph' is typedefed to 'unsigned long' - // (see http://www.x.org/releases/X11R7.7/doc/libXrender/libXrender.txt) - // Maybe we should assert that (sizeof(void*) == sizeof(Glyph)) ? - gid[i] = (Glyph) (jginfo->cellInfo); - xginfo[i].x = (-jginfo->topLeftX); - xginfo[i].y = (-jginfo->topLeftY); - xginfo[i].width = jginfo->width; - xginfo[i].height = jginfo->height; - xginfo[i].xOff = round(jginfo->advanceX); - xginfo[i].yOff = round(jginfo->advanceY); - } - - XRenderAddGlyphs(awt_display, glyphSet, &gid[0], &xginfo[0], glyphCnt, - (const char*)pixelData, pixelDataLength); - - (*env)->ReleasePrimitiveArrayCritical(env, glyphInfoPtrsArray, glyphInfoPtrs, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, pixelDataArray, pixelData, JNI_ABORT); - - free(xginfo); - free(gid); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRFreeGlyphsNative - (JNIEnv *env, jclass cls, jint glyphSet, jintArray gidArray, jint glyphCnt) { - - if (MAX_PAYLOAD / sizeof(Glyph) < (unsigned)glyphCnt) { - /* glyphCnt too big, payload overflow */ - return; - } - - /* The glyph ids are 32 bit but may be stored in a 64 bit long on - * a 64 bit architecture. So optimise the 32 bit case to avoid - * extra stack or heap allocations by directly referencing the - * underlying Java array and only allocate on 64 bit. - */ - if (sizeof(jint) == sizeof(Glyph)) { - jint *gids = - (*env)->GetPrimitiveArrayCritical(env, gidArray, NULL); - if (gids == NULL) { - return; - } else { - XRenderFreeGlyphs(awt_display, - (GlyphSet)glyphSet, (Glyph *)gids, glyphCnt); - (*env)->ReleasePrimitiveArrayCritical(env, gidArray, - gids, JNI_ABORT); - } - return; - } else { - Glyph stack_ids[64]; - Glyph *gids = NULL; - jint* jgids = NULL; - int i; - - if (glyphCnt <= 64) { - gids = stack_ids; - } else { - gids = (Glyph *)malloc(sizeof(Glyph) * glyphCnt); - if (gids == NULL) { - return; - } - } - jgids = (*env)->GetPrimitiveArrayCritical(env, gidArray, NULL); - if (jgids == NULL) { - if (gids != stack_ids) { - free(gids); - } - return; - } - for (i=0; i < glyphCnt; i++) { - gids[i] = jgids[i]; - } - XRenderFreeGlyphs(awt_display, - (GlyphSet) glyphSet, gids, glyphCnt); - (*env)->ReleasePrimitiveArrayCritical(env, gidArray, - jgids, JNI_ABORT); - if (gids != stack_ids) { - free(gids); - } - } -} - -JNIEXPORT jint JNICALL -Java_sun_java2d_xr_XRBackendNative_XRenderCreateGlyphSetNative - (JNIEnv *env, jclass cls, jlong format) { - return XRenderCreateGlyphSet(awt_display, (XRenderPictFormat *) jlong_to_ptr(format)); -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_XRenderCompositeTextNative - (JNIEnv *env, jclass cls, jint op, jint src, jint dst, - jint sx, jint sy, jlong maskFmt, jintArray eltArray, - jintArray glyphIDArray, jint eltCnt, jint glyphCnt) { - jint i; - jint *ids; - jint *elts; - XGlyphElt32 *xelts; - unsigned int *xids; - XGlyphElt32 selts[24]; - unsigned int sids[256]; - int charCnt = 0; - - if ((MAX_PAYLOAD / sizeof(XGlyphElt32) < (unsigned)eltCnt) - || (MAX_PAYLOAD / sizeof(unsigned int) < (unsigned)glyphCnt) - || ((MAX_PAYLOAD - sizeof(XGlyphElt32)*(unsigned)eltCnt) / - sizeof(unsigned int) < (unsigned)glyphCnt)) - { - /* (eltCnt, glyphCnt) too big, payload overflow */ - return; - } - - if (eltCnt <= 24) { - xelts = &selts[0]; - }else { - xelts = (XGlyphElt32 *) malloc(sizeof(XGlyphElt32) * eltCnt); - if (xelts == NULL) { - return; - } - } - - if (glyphCnt <= 256) { - xids = &sids[0]; - } else { - xids = (unsigned int*)malloc(sizeof(unsigned int) * glyphCnt); - if (xids == NULL) { - if (xelts != &selts[0]) { - free(xelts); - } - return; - } - } - - if ((ids = (jint *) - (*env)->GetPrimitiveArrayCritical(env, glyphIDArray, NULL)) == NULL) { - if (xelts != &selts[0]) { - free(xelts); - } - if (xids != &sids[0]) { - free(xids); - } - return; - } - if ((elts = (jint *) - (*env)->GetPrimitiveArrayCritical(env, eltArray, NULL)) == NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, - glyphIDArray, ids, JNI_ABORT); - if (xelts != &selts[0]) { - free(xelts); - } - if (xids != &sids[0]) { - free(xids); - } - return; - } - - for (i=0; i < glyphCnt; i++) { - xids[i] = ids[i]; - } - - for (i=0; i < eltCnt; i++) { - xelts[i].nchars = elts[i*4 + 0]; - xelts[i].xOff = elts[i*4 + 1]; - xelts[i].yOff = elts[i*4 + 2]; - xelts[i].glyphset = (GlyphSet) elts[i*4 + 3]; - xelts[i].chars = &xids[charCnt]; - - charCnt += xelts[i].nchars; - } - - XRenderCompositeText32(awt_display, op, (Picture) src, (Picture) dst, - (XRenderPictFormat *) jlong_to_ptr(maskFmt), - sx, sy, 0, 0, xelts, eltCnt); - - (*env)->ReleasePrimitiveArrayCritical(env, glyphIDArray, ids, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, eltArray, elts, JNI_ABORT); - - if (xelts != &selts[0]) { - free(xelts); - } - - if (xids != &sids[0]) { - free(xids); - } -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_setGCMode - (JNIEnv *env, jobject this, jlong gc, jboolean copy) { - GC xgc = (GC) jlong_to_ptr(gc); - - if (copy == JNI_TRUE) { - XSetFunction(awt_display, xgc, GXcopy); - } else { - XSetFunction(awt_display, xgc, GXxor); - } -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRBackendNative_GCRectanglesNative - (JNIEnv *env, jclass xsd, jint dst, jlong gc, - jintArray rectArray, jint rectCnt) { - int i; - jint* rects; - XRectangle *xRects; - XRectangle sRects[256]; - - if (rectCnt <= 256) { - xRects = &sRects[0]; - } else { - if (MAXUINT / sizeof(XRectangle) < (unsigned)rectCnt) { - /* rectCnt too big, integer overflow */ - return; - } - - xRects = (XRectangle *) malloc(sizeof(XRectangle) * rectCnt); - if (xRects == NULL) { - return; - } - } - - if ((rects = (jint*) - (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL)) == NULL) { - if (xRects != &sRects[0]) { - free(xRects); - } - return; - } - - for (i=0; i < rectCnt; i++) { - xRects[i].x = rects[i*4 + 0]; - xRects[i].y = rects[i*4 + 1]; - xRects[i].width = rects[i*4 + 2]; - xRects[i].height = rects[i*4 + 3]; - } - - XFillRectangles(awt_display, (Drawable) dst, (GC) jlong_to_ptr(gc), xRects, rectCnt); - - (*env)->ReleasePrimitiveArrayCritical(env, rectArray, rects, JNI_ABORT); - if (xRects != &sRects[0]) { - free(xRects); - } -} diff --git a/app/src/main/jni/awt_xawt/java2d/x11/XRSurfaceData.c b/app/src/main/jni/awt_xawt/java2d/x11/XRSurfaceData.c deleted file mode 100644 index 60b4d5b71..000000000 --- a/app/src/main/jni/awt_xawt/java2d/x11/XRSurfaceData.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2010, 2013, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "GraphicsPrimitiveMgr.h" -#include "Region.h" -#include "Trace.h" -#include "X11SurfaceData.h" - -/*#include */ -#include - -#ifndef RepeatNone /* added in 0.10 */ -#define RepeatNone 0 -#define RepeatNormal 1 -#define RepeatPad 2 -#define RepeatReflect 3 -#endif - - -#include -#include -#include - -#ifndef HEADLESS -jfieldID pictID; -jfieldID xidID; -jfieldID blitMaskPMID; -jfieldID blitMaskPictID; -#endif /* !HEADLESS */ - -JNIEXPORT void JNICALL - Java_sun_java2d_xr_XRSurfaceData_initXRPicture(JNIEnv *env, jobject xsd, - jlong pXSData, - jint pictFormat) -{ -#ifndef HEADLESS - - X11SDOps *xsdo; - XRenderPictFormat *fmt; - - J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initXRender"); - - xsdo = (X11SDOps *) jlong_to_ptr(pXSData); - if (xsdo == NULL) { - return; - } - - if (xsdo->xrPic == None) { - XRenderPictureAttributes pict_attr; - pict_attr.repeat = RepeatNone; - fmt = XRenderFindStandardFormat(awt_display, pictFormat); - xsdo->xrPic = - XRenderCreatePicture(awt_display, xsdo->drawable, fmt, - CPRepeat, &pict_attr); - } - - (*env)->SetIntField (env, xsd, pictID, xsdo->xrPic); - (*env)->SetIntField (env, xsd, xidID, xsdo->drawable); -#endif /* !HEADLESS */ -} - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRSurfaceData_initIDs(JNIEnv *env, jclass xsd) -{ -#ifndef HEADLESS - J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initIDs"); - - pictID = (*env)->GetFieldID(env, xsd, "picture", "I"); - if (pictID == NULL) { - return; - } - xidID = (*env)->GetFieldID(env, xsd, "xid", "I"); - if (xidID == NULL) { - return; - } - - XShared_initIDs(env, JNI_FALSE); -#endif /* !HEADLESS */ -} - - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRSurfaceData_XRInitSurface(JNIEnv *env, jclass xsd, - jint depth, - jint width, jint height, - jlong drawable, jint pictFormat) -{ -#ifndef HEADLESS - X11SDOps *xsdo; - - J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_initSurface"); - - xsdo = X11SurfaceData_GetOps(env, xsd); - if (xsdo == NULL) { - return; - } - - XShared_initSurface(env, xsdo, depth, width, height, drawable); -#endif /* !HEADLESS */ -} - - - -JNIEXPORT void JNICALL -Java_sun_java2d_xr_XRSurfaceData_freeXSDOPicture(JNIEnv *env, jobject xsd, - jlong pXSData) -{ -#ifndef HEADLESS - X11SDOps *xsdo; - - J2dTraceLn(J2D_TRACE_INFO, "in XRSurfaceData_freeXSDOPicture"); - - xsdo = X11SurfaceData_GetOps(env, xsd); - if (xsdo == NULL) { - return; - } - - if(xsdo->xrPic != None) { - XRenderFreePicture(awt_display, xsdo->xrPic); - xsdo->xrPic = None; - } -#endif /* !HEADLESS */ -} diff --git a/app/src/main/jni/awt_xawt/xawt/XToolkit.c b/app/src/main/jni/awt_xawt/xawt/XToolkit.c deleted file mode 100644 index 5814bb6c8..000000000 --- a/app/src/main/jni/awt_xawt/xawt/XToolkit.c +++ /dev/null @@ -1,1090 +0,0 @@ -/* - * 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include -#include -#include -#ifdef __linux__ -#include -#endif - -#include -#include -#include -#include - -#include "awt_p.h" -#include "awt_Component.h" -#include "awt_MenuComponent.h" -#include "awt_Font.h" -#include "awt_util.h" - -#include "sun_awt_X11_XToolkit.h" -#include "java_awt_SystemColor.h" -#include "java_awt_TrayIcon.h" -#include - -#include - -uint32_t awt_NumLockMask = 0; -Boolean awt_ModLockIsShiftLock = False; - -static int32_t num_buttons = 0; -int32_t getNumButtons(); - -extern JavaVM *jvm; - -// Tracing level -static int tracing = 0; -#ifdef PRINT -#undef PRINT -#endif -#ifdef PRINT2 -#undef PRINT2 -#endif - -#define PRINT if (tracing) printf -#define PRINT2 if (tracing > 1) printf - - -struct ComponentIDs componentIDs; - -struct MenuComponentIDs menuComponentIDs; - -#ifndef HEADLESS - -extern Display* awt_init_Display(JNIEnv *env, jobject this); -extern void freeNativeStringArray(char **array, jsize length); -extern char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length); - -struct XFontPeerIDs xFontPeerIDs; - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XFontPeer_initIDs - (JNIEnv *env, jclass cls) -{ - xFontPeerIDs.xfsname = - (*env)->GetFieldID(env, cls, "xfsname", "Ljava/lang/String;"); -} -#endif /* !HEADLESS */ - -/* This function gets called from the static initializer for FileDialog.java - to initialize the fieldIDs for fields that may be accessed from C */ - -JNIEXPORT void JNICALL -Java_java_awt_FileDialog_initIDs - (JNIEnv *env, jclass cls) -{ - -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XToolkit_initIDs - (JNIEnv *env, jclass clazz) -{ - jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I"); - CHECK_NULL(fid); - awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid); - DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask); - fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I"); - CHECK_NULL(fid); - awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False; -} - -/* - * Class: sun_awt_X11_XToolkit - * Method: getTrayIconDisplayTimeout - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getTrayIconDisplayTimeout - (JNIEnv *env, jclass clazz) -{ - return (jlong) 2000; -} - -/* - * Class: sun_awt_X11_XToolkit - * Method: getDefaultXColormap - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultXColormap - (JNIEnv *env, jclass clazz) -{ - AwtGraphicsConfigDataPtr defaultConfig = - getDefaultConfig(DefaultScreen(awt_display)); - - return (jlong) defaultConfig->awt_cmap; -} - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultScreenData - (JNIEnv *env, jclass clazz) -{ - return ptr_to_jlong(getDefaultConfig(DefaultScreen(awt_display))); -} - - -JNIEXPORT jint JNICALL -DEF_JNI_OnLoad(JavaVM *vm, void *reserved) -{ - jvm = vm; - return JNI_VERSION_1_2; -} - -/* - * Class: sun_awt_X11_XToolkit - * Method: nativeLoadSystemColors - * Signature: ([I)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_nativeLoadSystemColors - (JNIEnv *env, jobject this, jintArray systemColors) -{ - AwtGraphicsConfigDataPtr defaultConfig = - getDefaultConfig(DefaultScreen(awt_display)); - awtJNI_CreateColorData(env, defaultConfig, 1); -} - -JNIEXPORT void JNICALL -Java_java_awt_Component_initIDs - (JNIEnv *env, jclass cls) -{ - jclass keyclass = NULL; - - - componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I"); - CHECK_NULL(componentIDs.x); - componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I"); - CHECK_NULL(componentIDs.y); - componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I"); - CHECK_NULL(componentIDs.width); - componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I"); - CHECK_NULL(componentIDs.height); - componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z"); - CHECK_NULL(componentIDs.isPacked); - componentIDs.peer = - (*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;"); - CHECK_NULL(componentIDs.peer); - componentIDs.background = - (*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;"); - CHECK_NULL(componentIDs.background); - componentIDs.foreground = - (*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;"); - CHECK_NULL(componentIDs.foreground); - componentIDs.graphicsConfig = - (*env)->GetFieldID(env, cls, "graphicsConfig", - "Ljava/awt/GraphicsConfiguration;"); - CHECK_NULL(componentIDs.graphicsConfig); - componentIDs.name = - (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); - CHECK_NULL(componentIDs.name); - - /* Use _NoClientCode() methods for trusted methods, so that we - * know that we are not invoking client code on trusted threads - */ - componentIDs.getParent = - (*env)->GetMethodID(env, cls, "getParent_NoClientCode", - "()Ljava/awt/Container;"); - CHECK_NULL(componentIDs.getParent); - - componentIDs.getLocationOnScreen = - (*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock", - "()Ljava/awt/Point;"); - CHECK_NULL(componentIDs.getLocationOnScreen); - - keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent"); - CHECK_NULL(keyclass); - - componentIDs.isProxyActive = - (*env)->GetFieldID(env, keyclass, "isProxyActive", - "Z"); - CHECK_NULL(componentIDs.isProxyActive); - - componentIDs.appContext = - (*env)->GetFieldID(env, cls, "appContext", - "Lsun/awt/AppContext;"); - - (*env)->DeleteLocalRef(env, keyclass); -} - - -JNIEXPORT void JNICALL -Java_java_awt_Container_initIDs - (JNIEnv *env, jclass cls) -{ - -} - - -JNIEXPORT void JNICALL -Java_java_awt_Button_initIDs - (JNIEnv *env, jclass cls) -{ - -} - -JNIEXPORT void JNICALL -Java_java_awt_Scrollbar_initIDs - (JNIEnv *env, jclass cls) -{ - -} - - -JNIEXPORT void JNICALL -Java_java_awt_Window_initIDs - (JNIEnv *env, jclass cls) -{ - -} - -JNIEXPORT void JNICALL -Java_java_awt_Frame_initIDs - (JNIEnv *env, jclass cls) -{ - -} - - -JNIEXPORT void JNICALL -Java_java_awt_MenuComponent_initIDs(JNIEnv *env, jclass cls) -{ - menuComponentIDs.appContext = - (*env)->GetFieldID(env, cls, "appContext", "Lsun/awt/AppContext;"); -} - -JNIEXPORT void JNICALL -Java_java_awt_Cursor_initIDs(JNIEnv *env, jclass cls) -{ -} - - -JNIEXPORT void JNICALL Java_java_awt_MenuItem_initIDs - (JNIEnv *env, jclass cls) -{ -} - - -JNIEXPORT void JNICALL Java_java_awt_Menu_initIDs - (JNIEnv *env, jclass cls) -{ -} - -JNIEXPORT void JNICALL -Java_java_awt_TextArea_initIDs - (JNIEnv *env, jclass cls) -{ -} - - -JNIEXPORT void JNICALL -Java_java_awt_Checkbox_initIDs - (JNIEnv *env, jclass cls) -{ -} - - -JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs - (JNIEnv *env, jclass cls) -{ -} - -JNIEXPORT void JNICALL -Java_java_awt_TextField_initIDs - (JNIEnv *env, jclass cls) -{ -} - -JNIEXPORT jboolean JNICALL AWTIsHeadless() { -#ifdef HEADLESS - return JNI_TRUE; -#else - return JNI_FALSE; -#endif -} - -JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls) -{ -} - - -/* ========================== Begin poll section ================================ */ - -// Includes - -#include -#include -#include -#include - -#include -#include - -#include -#ifndef POLLRDNORM -#define POLLRDNORM POLLIN -#endif - -// Prototypes - -static void waitForEvents(JNIEnv *, jlong); -static void awt_pipe_init(); -static Boolean performPoll(JNIEnv *, jlong); -static void wakeUp(); -static void update_poll_timeout(int timeout_control); -static uint32_t get_poll_timeout(jlong nextTaskTime); - -// Defines - -#ifndef bzero -#define bzero(a,b) memset(a, 0, b) -#endif - -#define AWT_POLL_BUFSIZE 100 /* bytes */ -#define AWT_READPIPE (awt_pipe_fds[0]) -#define AWT_WRITEPIPE (awt_pipe_fds[1]) - -#define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */ -#define DEF_AWT_FLUSH_TIMEOUT ((uint32_t)100) /* milliseconds */ -#define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */ - -#define TIMEOUT_TIMEDOUT 0 -#define TIMEOUT_EVENTS 1 - -/* awt_poll_alg - AWT Poll Events Aging Algorithms */ -#define AWT_POLL_FALSE 1 -#define AWT_POLL_AGING_SLOW 2 -#define AWT_POLL_AGING_FAST 3 - -#define AWT_POLL_THRESHOLD 1000 // msec, Block if delay is larger -#define AWT_POLL_BLOCK -1 // cause poll() block - -// Static fields - -static int awt_poll_alg = AWT_POLL_AGING_SLOW; - -static uint32_t AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT; /* milliseconds */ -static uint32_t AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; /* milliseconds */ -static pthread_t awt_MainThread = 0; -static int32_t awt_pipe_fds[2]; /* fds for wkaeup pipe */ -static Boolean awt_pipe_inited = False; /* make sure pipe is initialized before write */ -static jlong awt_next_flush_time = 0LL; /* 0 == no scheduled flush */ -static jlong awt_last_flush_time = 0LL; /* 0 == no scheduled flush */ -static uint32_t curPollTimeout; -static struct pollfd pollFds[2]; -static jlong poll_sleep_time = 0LL; // Used for tracing -static jlong poll_wakeup_time = 0LL; // Used for tracing - -// AWT static poll timeout. Zero means "not set", aging algorithm is -// used. Static poll timeout values higher than 50 cause application -// look "slow" - they don't respond to user request fast -// enough. Static poll timeout value less than 10 are usually -// considered by schedulers as zero, so this might cause unnecessary -// CPU consumption by Java. The values between 10 - 50 are suggested -// for single client desktop configurations. For SunRay servers, it -// is highly recomended to use aging algorithm (set static poll timeout -// to 0). -static int32_t static_poll_timeout = 0; - -static Bool isMainThread() { - return awt_MainThread == pthread_self(); -} - -/* - * Creates the AWT utility pipe. This pipe exists solely so that - * we can cause the main event thread to wake up from a poll() or - * select() by writing to this pipe. - */ -static void -awt_pipe_init() { - - if (awt_pipe_inited) { - return; - } - - if ( pipe ( awt_pipe_fds ) == 0 ) - { - /* - ** the write wakes us up from the infinite sleep, which - ** then we cause a delay of AWT_FLUSHTIME and then we - ** flush. - */ - int32_t flags = 0; - /* set the pipe to be non-blocking */ - flags = fcntl ( AWT_READPIPE, F_GETFL, 0 ); - fcntl( AWT_READPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK ); - flags = fcntl ( AWT_WRITEPIPE, F_GETFL, 0 ); - fcntl( AWT_WRITEPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK ); - awt_pipe_inited = True; - } - else - { - AWT_READPIPE = -1; - AWT_WRITEPIPE = -1; - } - - -} /* awt_pipe_init() */ - -/** - * Reads environment variables to initialize timeout fields. - */ -static void readEnv() { - char * value; - int tmp_poll_alg; - static Boolean env_read = False; - if (env_read) return; - - env_read = True; - - value = getenv("_AWT_MAX_POLL_TIMEOUT"); - if (value != NULL) { - AWT_MAX_POLL_TIMEOUT = atoi(value); - if (AWT_MAX_POLL_TIMEOUT == 0) { - AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; - } - } - curPollTimeout = AWT_MAX_POLL_TIMEOUT/2; - - value = getenv("_AWT_FLUSH_TIMEOUT"); - if (value != NULL) { - AWT_FLUSH_TIMEOUT = atoi(value); - if (AWT_FLUSH_TIMEOUT == 0) { - AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT; - } - } - - value = getenv("_AWT_POLL_TRACING"); - if (value != NULL) { - tracing = atoi(value); - } - - value = getenv("_AWT_STATIC_POLL_TIMEOUT"); - if (value != NULL) { - static_poll_timeout = atoi(value); - } - if (static_poll_timeout != 0) { - curPollTimeout = static_poll_timeout; - } - - // non-blocking poll() - value = getenv("_AWT_POLL_ALG"); - if (value != NULL) { - tmp_poll_alg = atoi(value); - switch(tmp_poll_alg) { - case AWT_POLL_FALSE: - case AWT_POLL_AGING_SLOW: - case AWT_POLL_AGING_FAST: - awt_poll_alg = tmp_poll_alg; - break; - default: - PRINT("Unknown value of _AWT_POLL_ALG, assuming Slow Aging Algorithm by default"); - awt_poll_alg = AWT_POLL_AGING_SLOW; - break; - } - } -} - -/** - * Returns the amount of milliseconds similar to System.currentTimeMillis() - */ -static jlong -awtJNI_TimeMillis(void) -{ - struct timeval t; - - gettimeofday(&t, 0); - - return jlong_add(jlong_mul(jint_to_jlong(t.tv_sec), jint_to_jlong(1000)), - jint_to_jlong(t.tv_usec / 1000)); -} - -/** - * Updates curPollTimeout according to the aging algorithm. - * @param timeout_control Either TIMEOUT_TIMEDOUT or TIMEOUT_EVENTS - */ -static void update_poll_timeout(int timeout_control) { - PRINT2("tout: %d\n", timeout_control); - - // If static_poll_timeout is set, curPollTimeout has the fixed value - if (static_poll_timeout != 0) return; - - // Update it otherwise - - switch(awt_poll_alg) { - case AWT_POLL_AGING_SLOW: - if (timeout_control == TIMEOUT_TIMEDOUT) { - /* add 1/4 (plus 1, in case the division truncates to 0) */ - curPollTimeout += ((curPollTimeout>>2) + 1); - curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout); - } else if (timeout_control == TIMEOUT_EVENTS) { - /* subtract 1/4 (plus 1, in case the division truncates to 0) */ - if (curPollTimeout > 0) { - curPollTimeout -= ((curPollTimeout>>2) + 1); - curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout); - } - } - break; - case AWT_POLL_AGING_FAST: - if (timeout_control == TIMEOUT_TIMEDOUT) { - curPollTimeout += ((curPollTimeout>>2) + 1); - curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout); - if((int)curPollTimeout > AWT_POLL_THRESHOLD || (int)curPollTimeout == AWT_POLL_BLOCK) - curPollTimeout = AWT_POLL_BLOCK; - } else if (timeout_control == TIMEOUT_EVENTS) { - curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, 1); - } - break; - } -} - -/* - * Gets the best timeout for the next call to poll(). - * - * @param nextTaskTime -1, if there are no tasks; next time when - * timeout task needs to be run, in millis(of currentTimeMillis) - */ -static uint32_t get_poll_timeout(jlong nextTaskTime) -{ - uint32_t ret_timeout = 0; - uint32_t timeout; - uint32_t taskTimeout; - uint32_t flushTimeout; - - jlong curTime = awtJNI_TimeMillis(); - timeout = curPollTimeout; - switch(awt_poll_alg) { - case AWT_POLL_AGING_SLOW: - case AWT_POLL_AGING_FAST: - taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime)); - flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT; - - PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime); - - // Adjust timeout to flush_time and task_time - ret_timeout = min(flushTimeout, min(taskTimeout, timeout)); - if((int)curPollTimeout == AWT_POLL_BLOCK) - ret_timeout = AWT_POLL_BLOCK; - break; - - case AWT_POLL_FALSE: - ret_timeout = (nextTaskTime > curTime) ? - (nextTaskTime - curTime) : - ((nextTaskTime == -1) ? -1 : 0); - break; - } - - return ret_timeout; - -} /* get_poll_timeout() */ - -/* - * Waits for X events to appear on the pipe. Returns only when - * it is likely (but not definite) that there are events waiting to - * be processed. - * - * This routine also flushes the outgoing X queue, when the - * awt_next_flush_time has been reached. - * - * If fdAWTPipe is greater or equal than zero the routine also - * checks if there are events pending on the putback queue. - */ -void -waitForEvents(JNIEnv *env, jlong nextTaskTime) { - if (performPoll(env, nextTaskTime) - && (awt_next_flush_time > 0) - && (awtJNI_TimeMillis() >= awt_next_flush_time)) { - - XFlush(awt_display); - awt_last_flush_time = awt_next_flush_time; - awt_next_flush_time = 0LL; - } -} /* waitForEvents() */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) { - waitForEvents(env, nextTaskTime); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1toolkit_1init (JNIEnv *env, jclass class) { - awt_MainThread = pthread_self(); - - awt_pipe_init(); - readEnv(); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1output_1flush (JNIEnv *env, jclass class) { - awt_output_flush(); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_wakeup_1poll (JNIEnv *env, jclass class) { - wakeUp(); -} - -/* - * Polls both the X pipe and our AWT utility pipe. Returns - * when there is data on one of the pipes, or the operation times - * out. - * - * Not all Xt events come across the X pipe (e.g., timers - * and alternate inputs), so we must time out every now and - * then to check the Xt event queue. - * - * The fdAWTPipe will be empty when this returns. - */ -static Boolean -performPoll(JNIEnv *env, jlong nextTaskTime) { - static Bool pollFdsInited = False; - static char read_buf[AWT_POLL_BUFSIZE + 1]; /* dummy buf to empty pipe */ - - uint32_t timeout = get_poll_timeout(nextTaskTime); - int32_t result; - - if (!pollFdsInited) { - pollFds[0].fd = ConnectionNumber(awt_display); - pollFds[0].events = POLLRDNORM; - pollFds[0].revents = 0; - - pollFds[1].fd = AWT_READPIPE; - pollFds[1].events = POLLRDNORM; - pollFds[1].revents = 0; - pollFdsInited = True; - } else { - pollFds[0].revents = 0; - pollFds[1].revents = 0; - } - - AWT_NOFLUSH_UNLOCK(); - - /* ACTUALLY DO THE POLL() */ - if (timeout == 0) { - // be sure other threads get a chance - if (!awtJNI_ThreadYield(env)) { - return FALSE; - } - } - - if (tracing) poll_sleep_time = awtJNI_TimeMillis(); - result = poll( pollFds, 2, (int32_t) timeout ); - if (tracing) poll_wakeup_time = awtJNI_TimeMillis(); - PRINT("%d of %d, res: %d\n", (int)(poll_wakeup_time-poll_sleep_time), (int)timeout, result); - - AWT_LOCK(); - if (result == 0) { - /* poll() timed out -- update timeout value */ - update_poll_timeout(TIMEOUT_TIMEDOUT); - PRINT2("performPoll(): TIMEOUT_TIMEDOUT curPollTimeout = %d \n", curPollTimeout); - } - if (pollFds[1].revents) { - int count; - PRINT("Woke up\n"); - /* There is data on the AWT pipe - empty it */ - do { - count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE ); - } while (count == AWT_POLL_BUFSIZE ); - PRINT2("performPoll(): data on the AWT pipe: curPollTimeout = %d \n", curPollTimeout); - } - if (pollFds[0].revents) { - // Events in X pipe - update_poll_timeout(TIMEOUT_EVENTS); - PRINT2("performPoll(): TIMEOUT_EVENTS curPollTimeout = %d \n", curPollTimeout); - } - return TRUE; - -} /* performPoll() */ - -/** - * Schedules next auto-flush event or performs forced flush depending - * on the time of the previous flush. - */ -void awt_output_flush() { - if (awt_next_flush_time == 0) { - JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - - jlong curTime = awtJNI_TimeMillis(); // current time - jlong l_awt_last_flush_time = awt_last_flush_time; // last time we flushed queue - jlong next_flush_time = l_awt_last_flush_time + AWT_FLUSH_TIMEOUT; - - if (curTime >= next_flush_time) { - // Enough time passed from last flush - PRINT("f1\n"); - AWT_LOCK(); - XFlush(awt_display); - awt_last_flush_time = curTime; - AWT_NOFLUSH_UNLOCK(); - } else { - awt_next_flush_time = next_flush_time; - PRINT("f2\n"); - wakeUp(); - } - } -} - - -/** - * Wakes-up poll() in performPoll - */ -static void wakeUp() { - static char wakeUp_char = 'p'; - if (!isMainThread() && awt_pipe_inited) { - write ( AWT_WRITEPIPE, &wakeUp_char, 1 ); - } -} - - -/* ========================== End poll section ================================= */ - -/* - * Class: java_awt_KeyboardFocusManager - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_KeyboardFocusManager_initIDs - (JNIEnv *env, jclass cls) -{ -} - -/* - * Class: sun_awt_X11_XToolkit - * Method: getEnv - * Signature: (Ljava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XToolkit_getEnv -(JNIEnv *env , jclass clazz, jstring key) { - char *ptr = NULL; - const char *keystr = NULL; - jstring ret = NULL; - - keystr = JNU_GetStringPlatformChars(env, key, NULL); - if (keystr) { - ptr = getenv(keystr); - if (ptr) { - ret = JNU_NewStringPlatform(env, (const char *) ptr); - } - JNU_ReleaseStringPlatformChars(env, key, (const char*)keystr); - } - return ret; -} - -#ifdef __linux__ -void print_stack(void) -{ - void *array[10]; - size_t size; - char **strings; - size_t i; - - size = backtrace (array, 10); - strings = backtrace_symbols (array, size); - - fprintf (stderr, "Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) - fprintf (stderr, "%s\n", strings[i]); - - free (strings); -} -#endif - -Window get_xawt_root_shell(JNIEnv *env) { - static jclass classXRootWindow = NULL; - static jmethodID methodGetXRootWindow = NULL; - static Window xawt_root_shell = None; - - if (xawt_root_shell == None){ - if (classXRootWindow == NULL){ - jclass cls_tmp = (*env)->FindClass(env, "sun/awt/X11/XRootWindow"); - if (!JNU_IsNull(env, cls_tmp)) { - classXRootWindow = (jclass)(*env)->NewGlobalRef(env, cls_tmp); - (*env)->DeleteLocalRef(env, cls_tmp); - } - } - if( classXRootWindow != NULL) { - methodGetXRootWindow = (*env)->GetStaticMethodID(env, classXRootWindow, "getXRootWindow", "()J"); - } - if( classXRootWindow != NULL && methodGetXRootWindow !=NULL ) { - xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow); - } - if ((*env)->ExceptionCheck(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - } - return xawt_root_shell; -} - -/* - * Old, compatibility, backdoor for DT. This is a different - * implementation. It keeps the signature, but acts on - * awt_root_shell, not the frame passed as an argument. Note, that - * the code that uses the old backdoor doesn't work correctly with - * gnome session proxy that checks for WM_COMMAND when the window is - * firts mapped, because DT code calls this old backdoor *after* the - * frame is shown or it would get NPE with old AWT (previous - * implementation of this backdoor) otherwise. Old style session - * managers (e.g. CDE) that check WM_COMMAND only during session - * checkpoint should work fine, though. - * - * NB: The function name looks deceptively like a JNI native method - * name. It's not! It's just a plain function. - */ - -JNIEXPORT void JNICALL -Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this, - jobject frame, jstring jcommand) -{ - const char *command; - XTextProperty text_prop; - char *c[1]; - int32_t status; - Window xawt_root_window; - - AWT_LOCK(); - xawt_root_window = get_xawt_root_shell(env); - - if ( xawt_root_window == None ) { - AWT_UNLOCK(); - JNU_ThrowNullPointerException(env, "AWT root shell is unrealized"); - return; - } - - command = (char *) JNU_GetStringPlatformChars(env, jcommand, NULL); - if (command != NULL) { - c[0] = (char *)command; - status = XmbTextListToTextProperty(awt_display, c, 1, - XStdICCTextStyle, &text_prop); - - if (status == Success || status > 0) { - XSetTextProperty(awt_display, xawt_root_window, - &text_prop, XA_WM_COMMAND); - if (text_prop.value != NULL) - XFree(text_prop.value); - } - JNU_ReleaseStringPlatformChars(env, jcommand, command); - } - AWT_UNLOCK(); -} - - -/* - * New DT backdoor to set WM_COMMAND. New code should use this - * backdoor and call it *before* the first frame is shown so that - * gnome session proxy can correctly handle it. - * - * NB: The function name looks deceptively like a JNI native method - * name. It's not! It's just a plain function. - */ -JNIEXPORT void JNICALL -Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray) -{ - jsize length; - char ** array; - XTextProperty text_prop; - int status; - Window xawt_root_window; - - AWT_LOCK(); - xawt_root_window = get_xawt_root_shell(env); - - if (xawt_root_window == None) { - AWT_UNLOCK(); - JNU_ThrowNullPointerException(env, "AWT root shell is unrealized"); - return; - } - - array = stringArrayToNative(env, jarray, &length); - - if (array != NULL) { - status = XmbTextListToTextProperty(awt_display, array, length, - XStdICCTextStyle, &text_prop); - if (status < 0) { - switch (status) { - case XNoMemory: - JNU_ThrowOutOfMemoryError(env, - "XmbTextListToTextProperty: XNoMemory"); - break; - case XLocaleNotSupported: - JNU_ThrowInternalError(env, - "XmbTextListToTextProperty: XLocaleNotSupported"); - break; - case XConverterNotFound: - JNU_ThrowNullPointerException(env, - "XmbTextListToTextProperty: XConverterNotFound"); - break; - default: - JNU_ThrowInternalError(env, - "XmbTextListToTextProperty: unknown error"); - } - } else { - XSetTextProperty(awt_display, xawt_root_window, - &text_prop, XA_WM_COMMAND); - } - - if (text_prop.value != NULL) - XFree(text_prop.value); - - freeNativeStringArray(array, length); - } - AWT_UNLOCK(); -} - -/* - * Class: java_awt_TrayIcon - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs(JNIEnv *env , jclass clazz) -{ -} - - -/* - * Class: java_awt_Cursor - * Method: finalizeImpl - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_Cursor_finalizeImpl(JNIEnv *env, jclass clazz, jlong pData) -{ - Cursor xcursor; - - xcursor = (Cursor)pData; - if (xcursor != None) { - AWT_LOCK(); - XFreeCursor(awt_display, xcursor); - AWT_UNLOCK(); - } -} - - -/* - * Class: sun_awt_X11_XToolkit - * Method: getNumberOfButtonsImpl - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XToolkit_getNumberOfButtonsImpl -(JNIEnv * env, jobject cls){ - if (num_buttons == 0) { - num_buttons = getNumButtons(); - } - return num_buttons; -} - -int32_t getNumButtons() { - int32_t major_opcode, first_event, first_error; - int32_t xinputAvailable; - int32_t numDevices, devIdx, clsIdx; - XDeviceInfo* devices; - XDeviceInfo* aDevice; - XButtonInfo* bInfo; - int32_t local_num_buttons = 0; - - /* 4700242: - * If XTest is asked to press a non-existant mouse button - * (i.e. press Button3 on a system configured with a 2-button mouse), - * then a crash may happen. To avoid this, we use the XInput - * extension to query for the number of buttons on the XPointer, and check - * before calling XTestFakeButtonEvent(). - */ - xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error); - if (xinputAvailable) { - DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d", - major_opcode, first_event, first_error); - devices = XListInputDevices(awt_display, &numDevices); - for (devIdx = 0; devIdx < numDevices; devIdx++) { - aDevice = &(devices[devIdx]); -#ifdef IsXExtensionPointer - if (aDevice->use == IsXExtensionPointer) { - for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) { - if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) { - bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx])); - local_num_buttons = bInfo->num_buttons; - DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons); - break; - } - } - break; - } -#endif - if (local_num_buttons <= 0 ) { - if (aDevice->use == IsXPointer) { - for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) { - if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) { - bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx])); - local_num_buttons = bInfo->num_buttons; - DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons); - break; - } - } - break; - } - } - } - - XFreeDeviceList(devices); - } - else { - DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons); - } - if (local_num_buttons == 0 ) { - local_num_buttons = 3; - } - - return local_num_buttons; -} - -/* - * Class: sun_awt_X11_XWindowPeer - * Method: getJvmPID - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindowPeer_getJvmPID -(JNIEnv *env, jclass cls) -{ - /* Return the JVM's PID. */ - return getpid(); -} - -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 1024 /* Overestimated */ -#endif - -/* - * Class: sun_awt_X11_XWindowPeer - * Method: getLocalHostname - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XWindowPeer_getLocalHostname -(JNIEnv *env, jclass cls) -{ - /* Return the machine's FQDN. */ - char hostname[HOST_NAME_MAX + 1]; - if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) { - hostname[HOST_NAME_MAX] = '\0'; - jstring res = (*env)->NewStringUTF(env, hostname); - return res; - } - - return (jstring)NULL; -} diff --git a/app/src/main/jni/awt_xawt/xawt/XWindow.c b/app/src/main/jni/awt_xawt/xawt/XWindow.c deleted file mode 100644 index 8baa40efa..000000000 --- a/app/src/main/jni/awt_xawt/xawt/XWindow.c +++ /dev/null @@ -1,1290 +0,0 @@ -/* - * Copyright (c) 2002, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* Note that the contents of this file were taken from canvas.c - * in the old motif-based AWT. - */ - -#ifdef HEADLESS - #error This file should not be included in headless library -#endif - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "sun_awt_X11_XWindow.h" - -#include "awt_p.h" -#include "awt_GraphicsEnv.h" -#include "awt_AWTEvent.h" - -#define XK_KATAKANA -#include /* standard X keysyms */ -#include /* DEC vendor-specific */ -#include /* Sun vendor-specific */ -#include /* Apollo (HP) vendor-specific */ -/* - * #include HP vendor-specific - * I checked HPkeysym.h into the workspace because although - * I think it will ship with X11R6.4.2 (and later) on Linux, - * it doesn't seem to be in Solaris 9 Update 2. - * - * This is done not only for the hp keysyms, but also to - * give us the osf keysyms that are also defined in HPkeysym.h. - * However, HPkeysym.h is missing a couple of osf keysyms, - * so I have #defined them below. - */ -#include "HPkeysym.h" /* HP vendor-specific */ - -#include "java_awt_event_KeyEvent.h" -#include "java_awt_event_InputEvent.h" -#include "java_awt_event_MouseEvent.h" -#include "java_awt_event_MouseWheelEvent.h" -#include "java_awt_AWTEvent.h" - -/* - * Two osf keys are not defined in standard keysym.h, - * /Xm/VirtKeys.h, or HPkeysym.h, so I added them below. - * I found them in /usr/openwin/lib/X11/XKeysymDB - */ -#ifndef osfXK_Prior -#define osfXK_Prior 0x1004FF55 -#endif -#ifndef osfXK_Next -#define osfXK_Next 0x1004FF56 -#endif - -jfieldID windowID; -jfieldID drawStateID; -jfieldID targetID; -jfieldID graphicsConfigID; - -extern jobject currentX11InputMethodInstance; -extern Boolean awt_x11inputmethod_lookupString(XKeyPressedEvent *, KeySym *); -Boolean awt_UseType4Patch = False; -/* how about HEADLESS */ -Boolean awt_ServerDetected = False; -Boolean awt_XKBDetected = False; -Boolean awt_IsXsun = False; -Boolean awt_UseXKB = False; - -typedef struct KEYMAP_ENTRY { - jint awtKey; - KeySym x11Key; - Boolean mapsToUnicodeChar; - jint keyLocation; -} KeymapEntry; - -/* NB: XK_R? keysyms are for Type 4 keyboards. - * The corresponding XK_F? keysyms are for Type 5 - * - * Note: this table must be kept in sorted order, since it is traversed - * according to both Java keycode and X keysym. There are a number of - * keycodes that map to more than one corresponding keysym, and we need - * to choose the right one. Unfortunately, there are some keysyms that - * can map to more than one keycode, depending on what kind of keyboard - * is in use (e.g. F11 and F12). - */ - -KeymapEntry keymapTable[] = -{ - {java_awt_event_KeyEvent_VK_A, XK_a, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_B, XK_b, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_C, XK_c, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_D, XK_d, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_E, XK_e, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F, XK_f, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_G, XK_g, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_H, XK_h, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_I, XK_i, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_J, XK_j, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_K, XK_k, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_L, XK_l, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_M, XK_m, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_N, XK_n, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_O, XK_o, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_P, XK_p, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_Q, XK_q, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_R, XK_r, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_S, XK_s, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_T, XK_t, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_U, XK_u, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_V, XK_v, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_W, XK_w, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_X, XK_x, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_Y, XK_y, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_Z, XK_z, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* TTY Function keys */ - {java_awt_event_KeyEvent_VK_BACK_SPACE, XK_BackSpace, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_TAB, XK_Tab, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_TAB, XK_ISO_Left_Tab, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CLEAR, XK_Clear, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ENTER, XK_Return, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ENTER, XK_Linefeed, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAUSE, XK_Pause, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAUSE, XK_F21, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAUSE, XK_R1, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_SCROLL_LOCK, XK_Scroll_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_SCROLL_LOCK, XK_F23, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_SCROLL_LOCK, XK_R3, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ESCAPE, XK_Escape, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Other vendor-specific versions of TTY Function keys */ - {java_awt_event_KeyEvent_VK_BACK_SPACE, osfXK_BackSpace, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CLEAR, osfXK_Clear, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ESCAPE, osfXK_Escape, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Modifier keys */ - {java_awt_event_KeyEvent_VK_SHIFT, XK_Shift_L, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_LEFT}, - {java_awt_event_KeyEvent_VK_SHIFT, XK_Shift_R, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_RIGHT}, - {java_awt_event_KeyEvent_VK_CONTROL, XK_Control_L, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_LEFT}, - {java_awt_event_KeyEvent_VK_CONTROL, XK_Control_R, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_RIGHT}, - {java_awt_event_KeyEvent_VK_ALT, XK_Alt_L, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_LEFT}, - {java_awt_event_KeyEvent_VK_ALT, XK_Alt_R, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_RIGHT}, - {java_awt_event_KeyEvent_VK_META, XK_Meta_L, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_LEFT}, - {java_awt_event_KeyEvent_VK_META, XK_Meta_R, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_RIGHT}, - {java_awt_event_KeyEvent_VK_CAPS_LOCK, XK_Caps_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CAPS_LOCK, XK_Shift_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Misc Functions */ - {java_awt_event_KeyEvent_VK_PRINTSCREEN, XK_Print, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PRINTSCREEN, XK_F22, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PRINTSCREEN, XK_R2, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CANCEL, XK_Cancel, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_HELP, XK_Help, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_NUM_LOCK, XK_Num_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - - /* Other vendor-specific versions of Misc Functions */ - {java_awt_event_KeyEvent_VK_CANCEL, osfXK_Cancel, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_HELP, osfXK_Help, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Rectangular Navigation Block */ - {java_awt_event_KeyEvent_VK_HOME, XK_Home, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_HOME, XK_R7, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, XK_Page_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, XK_Prior, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, XK_R9, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_Page_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_Next, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_R15, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_END, XK_End, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_END, XK_R13, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_INSERT, XK_Insert, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DELETE, XK_Delete, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Keypad equivalents of Rectangular Navigation Block */ - {java_awt_event_KeyEvent_VK_HOME, XK_KP_Home, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, XK_KP_Page_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, XK_KP_Prior, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_KP_Page_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_KP_Next, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_END, XK_KP_End, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_INSERT, XK_KP_Insert, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_DELETE, XK_KP_Delete, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - - /* Other vendor-specific Rectangular Navigation Block */ - {java_awt_event_KeyEvent_VK_PAGE_UP, osfXK_PageUp, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_UP, osfXK_Prior, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, osfXK_PageDown, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PAGE_DOWN, osfXK_Next, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_END, osfXK_EndLine, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_INSERT, osfXK_Insert, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DELETE, osfXK_Delete, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Triangular Navigation Block */ - {java_awt_event_KeyEvent_VK_LEFT, XK_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UP, XK_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_RIGHT, XK_Right, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DOWN, XK_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Keypad equivalents of Triangular Navigation Block */ - {java_awt_event_KeyEvent_VK_KP_LEFT, XK_KP_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_KP_UP, XK_KP_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_KP_RIGHT, XK_KP_Right, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_KP_DOWN, XK_KP_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - - /* Other vendor-specific Triangular Navigation Block */ - {java_awt_event_KeyEvent_VK_LEFT, osfXK_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UP, osfXK_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_RIGHT, osfXK_Right, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DOWN, osfXK_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Remaining Cursor control & motion */ - {java_awt_event_KeyEvent_VK_BEGIN, XK_Begin, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_BEGIN, XK_KP_Begin, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - - {java_awt_event_KeyEvent_VK_0, XK_0, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_1, XK_1, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_2, XK_2, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_3, XK_3, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_4, XK_4, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_5, XK_5, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_6, XK_6, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_7, XK_7, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_8, XK_8, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_9, XK_9, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_SPACE, XK_space, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_EXCLAMATION_MARK, XK_exclam, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_QUOTEDBL, XK_quotedbl, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_NUMBER_SIGN, XK_numbersign, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DOLLAR, XK_dollar, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_AMPERSAND, XK_ampersand, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_QUOTE, XK_apostrophe, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_LEFT_PARENTHESIS, XK_parenleft, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_RIGHT_PARENTHESIS, XK_parenright, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ASTERISK, XK_asterisk, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PLUS, XK_plus, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_COMMA, XK_comma, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_MINUS, XK_minus, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PERIOD, XK_period, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_SLASH, XK_slash, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_COLON, XK_colon, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_SEMICOLON, XK_semicolon, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_LESS, XK_less, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_EQUALS, XK_equal, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_GREATER, XK_greater, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_AT, XK_at, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_OPEN_BRACKET, XK_bracketleft, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_BACK_SLASH, XK_backslash, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CLOSE_BRACKET, XK_bracketright, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CIRCUMFLEX, XK_asciicircum, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UNDERSCORE, XK_underscore, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_BACK_QUOTE, XK_grave, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_BRACELEFT, XK_braceleft, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_BRACERIGHT, XK_braceright, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_INVERTED_EXCLAMATION_MARK, XK_exclamdown, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Remaining Numeric Keypad Keys */ - {java_awt_event_KeyEvent_VK_NUMPAD0, XK_KP_0, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD1, XK_KP_1, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD2, XK_KP_2, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD3, XK_KP_3, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD4, XK_KP_4, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD5, XK_KP_5, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD6, XK_KP_6, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD7, XK_KP_7, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD8, XK_KP_8, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_NUMPAD9, XK_KP_9, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_SPACE, XK_KP_Space, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_TAB, XK_KP_Tab, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_ENTER, XK_KP_Enter, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_EQUALS, XK_KP_Equal, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_EQUALS, XK_R4, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_MULTIPLY, XK_KP_Multiply, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_MULTIPLY, XK_F26, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_MULTIPLY, XK_R6, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_ADD, XK_KP_Add, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_SEPARATOR, XK_KP_Separator, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_SUBTRACT, XK_KP_Subtract, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_SUBTRACT, XK_F24, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_DECIMAL, XK_KP_Decimal, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_DIVIDE, XK_KP_Divide, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_DIVIDE, XK_F25, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - {java_awt_event_KeyEvent_VK_DIVIDE, XK_R5, TRUE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD}, - - /* Function Keys */ - {java_awt_event_KeyEvent_VK_F1, XK_F1, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F2, XK_F2, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F3, XK_F3, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F4, XK_F4, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F5, XK_F5, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F6, XK_F6, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F7, XK_F7, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F8, XK_F8, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F9, XK_F9, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F10, XK_F10, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F11, XK_F11, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F12, XK_F12, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Sun vendor-specific version of F11 and F12 */ - {java_awt_event_KeyEvent_VK_F11, SunXK_F36, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_F12, SunXK_F37, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* X11 keysym names for input method related keys don't always - * match keytop engravings or Java virtual key names, so here we - * only map constants that we've found on real keyboards. - */ - /* Type 5c Japanese keyboard: kakutei */ - {java_awt_event_KeyEvent_VK_ACCEPT, XK_Execute, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - /* Type 5c Japanese keyboard: henkan */ - {java_awt_event_KeyEvent_VK_CONVERT, XK_Kanji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - /* Type 5c Japanese keyboard: nihongo */ - {java_awt_event_KeyEvent_VK_INPUT_METHOD_ON_OFF, XK_Henkan_Mode, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - /* VK_KANA_LOCK is handled separately because it generates the - * same keysym as ALT_GRAPH in spite of its different behavior. - */ - - {java_awt_event_KeyEvent_VK_ALL_CANDIDATES, XK_Zen_Koho, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ALPHANUMERIC, XK_Eisu_Shift, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ALPHANUMERIC, XK_Eisu_toggle, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CODE_INPUT, XK_Kanji_Bangou, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_FULL_WIDTH, XK_Zenkaku, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_HALF_WIDTH, XK_Hankaku, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_HIRAGANA, XK_Hiragana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_JAPANESE_HIRAGANA, XK_Hiragana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_KATAKANA, XK_Katakana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_JAPANESE_KATAKANA, XK_Katakana, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_JAPANESE_ROMAN, XK_Romaji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_KANA, XK_Kana_Shift, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_KANA_LOCK, XK_Kana_Lock, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_KANJI, XK_Kanji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_NONCONVERT, XK_Muhenkan, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PREVIOUS_CANDIDATE, XK_Mae_Koho, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ROMAN_CHARACTERS, XK_Romaji, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_COMPOSE, XK_Multi_key, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_ALT_GRAPH, XK_ISO_Level3_Shift, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Editing block */ - {java_awt_event_KeyEvent_VK_AGAIN, XK_Redo, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_AGAIN, XK_L2, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UNDO, XK_Undo, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UNDO, XK_L4, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_COPY, XK_L6, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PASTE, XK_L8, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CUT, XK_L10, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_FIND, XK_Find, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_FIND, XK_L9, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PROPS, XK_L3, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_STOP, XK_L1, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Sun vendor-specific versions for editing block */ - {java_awt_event_KeyEvent_VK_AGAIN, SunXK_Again, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UNDO, SunXK_Undo, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_COPY, SunXK_Copy, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PASTE, SunXK_Paste, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CUT, SunXK_Cut, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_FIND, SunXK_Find, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PROPS, SunXK_Props, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_STOP, SunXK_Stop, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Apollo (HP) vendor-specific versions for editing block */ - {java_awt_event_KeyEvent_VK_COPY, apXK_Copy, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CUT, apXK_Cut, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PASTE, apXK_Paste, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Other vendor-specific versions for editing block */ - {java_awt_event_KeyEvent_VK_COPY, osfXK_Copy, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_CUT, osfXK_Cut, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_PASTE, osfXK_Paste, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_UNDO, osfXK_Undo, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Dead key mappings (for European keyboards) */ - {java_awt_event_KeyEvent_VK_DEAD_GRAVE, XK_dead_grave, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_ACUTE, XK_dead_acute, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX, XK_dead_circumflex, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_TILDE, XK_dead_tilde, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_MACRON, XK_dead_macron, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_BREVE, XK_dead_breve, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_ABOVEDOT, XK_dead_abovedot, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_DIAERESIS, XK_dead_diaeresis, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_ABOVERING, XK_dead_abovering, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_DOUBLEACUTE, XK_dead_doubleacute, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CARON, XK_dead_caron, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CEDILLA, XK_dead_cedilla, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_OGONEK, XK_dead_ogonek, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_IOTA, XK_dead_iota, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_VOICED_SOUND, XK_dead_voiced_sound, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_SEMIVOICED_SOUND, XK_dead_semivoiced_sound, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Sun vendor-specific dead key mappings (for European keyboards) */ - {java_awt_event_KeyEvent_VK_DEAD_GRAVE, SunXK_FA_Grave, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX, SunXK_FA_Circum, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_TILDE, SunXK_FA_Tilde, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_ACUTE, SunXK_FA_Acute, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_DIAERESIS, SunXK_FA_Diaeresis, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CEDILLA, SunXK_FA_Cedilla, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* DEC vendor-specific dead key mappings (for European keyboards) */ - {java_awt_event_KeyEvent_VK_DEAD_ABOVERING, DXK_ring_accent, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX, DXK_circumflex_accent, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CEDILLA, DXK_cedilla_accent, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_ACUTE, DXK_acute_accent, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_GRAVE, DXK_grave_accent, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_TILDE, DXK_tilde, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_DIAERESIS, DXK_diaeresis, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - /* Other vendor-specific dead key mappings (for European keyboards) */ - {java_awt_event_KeyEvent_VK_DEAD_ACUTE, hpXK_mute_acute, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_GRAVE, hpXK_mute_grave, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_CIRCUMFLEX, hpXK_mute_asciicircum, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_DIAERESIS, hpXK_mute_diaeresis, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - {java_awt_event_KeyEvent_VK_DEAD_TILDE, hpXK_mute_asciitilde, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD}, - - {java_awt_event_KeyEvent_VK_UNDEFINED, NoSymbol, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN} -}; - -static Boolean -keyboardHasKanaLockKey() -{ - static Boolean haveResult = FALSE; - static Boolean result = FALSE; - - int32_t minKeyCode, maxKeyCode, keySymsPerKeyCode; - KeySym *keySyms, *keySymsStart, keySym; - int32_t i; - int32_t kanaCount = 0; - - // Solaris doesn't let you swap keyboards without rebooting, - // so there's no need to check for the kana lock key more than once. - if (haveResult) { - return result; - } - - // There's no direct way to determine whether the keyboard has - // a kana lock key. From available keyboard mapping tables, it looks - // like only keyboards with the kana lock key can produce keysyms - // for kana characters. So, as an indirect test, we check for those. - XDisplayKeycodes(awt_display, &minKeyCode, &maxKeyCode); - keySyms = XGetKeyboardMapping(awt_display, minKeyCode, maxKeyCode - minKeyCode + 1, &keySymsPerKeyCode); - keySymsStart = keySyms; - for (i = 0; i < (maxKeyCode - minKeyCode + 1) * keySymsPerKeyCode; i++) { - keySym = *keySyms++; - if ((keySym & 0xff00) == 0x0400) { - kanaCount++; - } - } - XFree(keySymsStart); - - // use a (somewhat arbitrary) minimum so we don't get confused by a stray function key - result = kanaCount > 10; - haveResult = TRUE; - return result; -} - -static void -keysymToAWTKeyCode(KeySym x11Key, jint *keycode, Boolean *mapsToUnicodeChar, - jint *keyLocation) -{ - int32_t i; - - // Solaris uses XK_Mode_switch for both the non-locking AltGraph - // and the locking Kana key, but we want to keep them separate for - // KeyEvent. - if (x11Key == XK_Mode_switch && keyboardHasKanaLockKey()) { - *keycode = java_awt_event_KeyEvent_VK_KANA_LOCK; - *mapsToUnicodeChar = FALSE; - *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN; - return; - } - - for (i = 0; - keymapTable[i].awtKey != java_awt_event_KeyEvent_VK_UNDEFINED; - i++) - { - if (keymapTable[i].x11Key == x11Key) { - *keycode = keymapTable[i].awtKey; - *mapsToUnicodeChar = keymapTable[i].mapsToUnicodeChar; - *keyLocation = keymapTable[i].keyLocation; - return; - } - } - - *keycode = java_awt_event_KeyEvent_VK_UNDEFINED; - *mapsToUnicodeChar = FALSE; - *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN; - - DTRACE_PRINTLN1("keysymToAWTKeyCode: no key mapping found: keysym = 0x%x", x11Key); -} - -KeySym -awt_getX11KeySym(jint awtKey) -{ - int32_t i; - - if (awtKey == java_awt_event_KeyEvent_VK_KANA_LOCK && keyboardHasKanaLockKey()) { - return XK_Mode_switch; - } - - for (i = 0; keymapTable[i].awtKey != 0; i++) { - if (keymapTable[i].awtKey == awtKey) { - return keymapTable[i].x11Key; - } - } - - DTRACE_PRINTLN1("awt_getX11KeySym: no key mapping found: awtKey = 0x%x", awtKey); - return NoSymbol; -} - -/* Called from handleKeyEvent. The purpose of this function is - * to check for a list of vendor-specific keysyms, most of which - * have values greater than 0xFFFF. Most of these keys don't map - * to unicode characters, but some do. - * - * For keys that don't map to unicode characters, the keysym - * is irrelevant at this point. We set the keysym to zero - * to ensure that the switch statement immediately below - * this function call (in adjustKeySym) won't incorrectly act - * on them after the high bits are stripped off. - * - * For keys that do map to unicode characters, we change the keysym - * to the equivalent that is < 0xFFFF - */ -static void -handleVendorKeySyms(XEvent *event, KeySym *keysym) -{ - KeySym originalKeysym = *keysym; - - switch (*keysym) { - /* Apollo (HP) vendor-specific from */ - case apXK_Copy: - case apXK_Cut: - case apXK_Paste: - /* DEC vendor-specific from */ - case DXK_ring_accent: /* syn usldead_ring */ - case DXK_circumflex_accent: - case DXK_cedilla_accent: /* syn usldead_cedilla */ - case DXK_acute_accent: - case DXK_grave_accent: - case DXK_tilde: - case DXK_diaeresis: - /* Sun vendor-specific from */ - case SunXK_FA_Grave: - case SunXK_FA_Circum: - case SunXK_FA_Tilde: - case SunXK_FA_Acute: - case SunXK_FA_Diaeresis: - case SunXK_FA_Cedilla: - case SunXK_F36: /* Labeled F11 */ - case SunXK_F37: /* Labeled F12 */ - case SunXK_Props: - case SunXK_Copy: - case SunXK_Open: - case SunXK_Paste: - case SunXK_Cut: - /* Other vendor-specific from HPkeysym.h */ - case hpXK_mute_acute: /* syn usldead_acute */ - case hpXK_mute_grave: /* syn usldead_grave */ - case hpXK_mute_asciicircum: /* syn usldead_asciicircum */ - case hpXK_mute_diaeresis: /* syn usldead_diaeresis */ - case hpXK_mute_asciitilde: /* syn usldead_asciitilde */ - case osfXK_Copy: - case osfXK_Cut: - case osfXK_Paste: - case osfXK_PageUp: - case osfXK_PageDown: - case osfXK_EndLine: - case osfXK_Clear: - case osfXK_Left: - case osfXK_Up: - case osfXK_Right: - case osfXK_Down: - case osfXK_Prior: - case osfXK_Next: - case osfXK_Insert: - case osfXK_Undo: - case osfXK_Help: - *keysym = 0; - break; - /* - * The rest DO map to unicode characters, so translate them - */ - case osfXK_BackSpace: - *keysym = XK_BackSpace; - break; - case osfXK_Escape: - *keysym = XK_Escape; - break; - case osfXK_Cancel: - *keysym = XK_Cancel; - break; - case osfXK_Delete: - *keysym = XK_Delete; - break; - default: - break; - } - - if (originalKeysym != *keysym) { - DTRACE_PRINTLN3("%s originalKeysym=0x%x, keysym=0x%x", - "In handleVendorKeySyms:", originalKeysym, *keysym); - } -} - -/* Called from handleKeyEvent. - * The purpose of this function is to adjust the keysym and XEvent - * keycode for a key event. This is basically a conglomeration of - * bugfixes that require these adjustments. - * Note that none of the keysyms in this function are less than 256. - */ -static void -adjustKeySym(XEvent *event, KeySym *keysym) -{ - KeySym originalKeysym = *keysym; - KeyCode originalKeycode = event->xkey.keycode; - - /* We have seen bits set in the high two bytes on Linux, - * which prevents this switch statement from executing - * correctly. Strip off the high order bits. - */ - *keysym &= 0x0000FFFF; - - switch (*keysym) { - case XK_ISO_Left_Tab: /* shift-tab on Linux */ - *keysym = XK_Tab; - break; - case XK_KP_Decimal: - *keysym = '.'; - break; - case XK_KP_Add: - *keysym = '+'; - break; - case XK_F24: /* NumLock off */ - case XK_KP_Subtract: /* NumLock on */ - *keysym = '-'; - break; - case XK_F25: /* NumLock off */ - case XK_KP_Divide: /* NumLock on */ - *keysym = '/'; - break; - case XK_F26: /* NumLock off */ - case XK_KP_Multiply: /* NumLock on */ - *keysym = '*'; - break; - case XK_KP_Equal: - *keysym = '='; - break; - case XK_KP_0: - *keysym = '0'; - break; - case XK_KP_1: - *keysym = '1'; - break; - case XK_KP_2: - *keysym = '2'; - break; - case XK_KP_3: - *keysym = '3'; - break; - case XK_KP_4: - *keysym = '4'; - break; - case XK_KP_5: - *keysym = '5'; - break; - case XK_KP_6: - *keysym = '6'; - break; - case XK_KP_7: - *keysym = '7'; - break; - case XK_KP_8: - *keysym = '8'; - break; - case XK_KP_9: - *keysym = '9'; - break; - case XK_KP_Left: /* Bug 4350175 */ - *keysym = XK_Left; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Up: - *keysym = XK_Up; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Right: - *keysym = XK_Right; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Down: - *keysym = XK_Down; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Home: - *keysym = XK_Home; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_End: - *keysym = XK_End; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Page_Up: - *keysym = XK_Page_Up; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Page_Down: - *keysym = XK_Page_Down; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Begin: - *keysym = XK_Begin; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Insert: - *keysym = XK_Insert; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Delete: - *keysym = XK_Delete; - event->xkey.keycode = XKeysymToKeycode(awt_display, *keysym); - break; - case XK_KP_Enter: - *keysym = XK_Linefeed; - event->xkey.keycode = XKeysymToKeycode(awt_display, XK_Return); - break; - default: - break; - } - - if (originalKeysym != *keysym) { - DTRACE_PRINTLN2("In adjustKeySym: originalKeysym=0x%x, keysym=0x%x", - originalKeysym, *keysym); - } - if (originalKeycode != event->xkey.keycode) { - DTRACE_PRINTLN2("In adjustKeySym: originalKeycode=0x%x, keycode=0x%x", - originalKeycode, event->xkey.keycode); - } -} - -/* - * What a sniffer sez? - * Xsun and Xorg if NumLock is on do two thing different: - * keep Keypad key in different places of keysyms array and - * ignore/obey "ModLock is ShiftLock", so we should choose. - * People say, it's right to use behavior and not Vendor tags to decide. - * Maybe. But why these tags were invented, then? - * TODO: use behavior, not tags. Maybe. - */ -static Boolean -isXsunServer(XEvent *event) { - if( awt_ServerDetected ) return awt_IsXsun; - if( (strncmp( ServerVendor( event->xkey.display ), "Sun Microsystems, Inc.", 22) != 0) && - (strncmp( ServerVendor( event->xkey.display ), "Oracle Corporation", 18) != 0) ) - { - awt_ServerDetected = True; - awt_IsXsun = False; - return False; - } - // Now, it's Sun. It still may be Xorg though, eg on Solaris 10, x86. - // Today (2005), VendorRelease of Xorg is a Big Number unlike Xsun. - if( VendorRelease( event->xkey.display ) > 10000 ) { - awt_ServerDetected = True; - awt_IsXsun = False; - return False; - } - awt_ServerDetected = True; - awt_IsXsun = True; - return True; -} -/* - * +kb or -kb ? - */ -static Boolean -isXKBenabled(Display *display) { - int mop, beve, berr; - if( !awt_XKBDetected ) { - /* - * NB: TODO: hope it will return False if XkbIgnoreExtension was called! - */ - awt_UseXKB = XQueryExtension(display, "XKEYBOARD", &mop, &beve, &berr); - awt_XKBDetected = True; - } - return awt_UseXKB; -} - -/* - * Map a keycode to the corresponding keysym. - * This replaces the deprecated X11 function XKeycodeToKeysym - */ -KeySym -keycodeToKeysym(Display *display, KeyCode keycode, int index) { - static int min_kc = -1; - static int max_kc; - if (min_kc == -1) { - (void) XDisplayKeycodes(display, &min_kc, &max_kc); - } - if (keycode < min_kc || keycode > max_kc || index < 0) { - return NoSymbol; - } - int num_syms; - KeySym *key_syms = XGetKeyboardMapping(display, keycode, 1, &num_syms); - if (index >= num_syms) { - XFree(key_syms); - return NoSymbol; - } - KeySym ks = key_syms[index]; - XFree(key_syms); - return ks; -} - -static Boolean -isKPevent(XEvent *event) -{ - /* - * Xlib manual, ch 12.7 says, as a first rule for choice of keysym: - * The numlock modifier is on and the second KeySym is a keypad KeySym. In this case, - * if the Shift modifier is on, or if the Lock modifier is on and is interpreted as ShiftLock, - * then the first KeySym is used, otherwise the second KeySym is used. - * - * However, Xsun server does ignore ShiftLock and always takes 3-rd element from an array. - * - * So, is it a keypad keysym? - */ - Boolean bsun = isXsunServer( event ); - Boolean bxkb = isXKBenabled( event->xkey.display ); - return IsKeypadKey( keycodeToKeysym(event->xkey.display, event->xkey.keycode,(bsun && !bxkb ? 2 : 1) ) ); -} -static void -dumpKeysymArray(XEvent *event) { - printf(" 0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 0)); - printf(" 0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 1)); - printf(" 0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2)); - printf(" 0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 3)); -} -/* - * In a next redesign, get rid of this code altogether. - * - */ -static void -handleKeyEventWithNumLockMask_New(XEvent *event, KeySym *keysym) -{ - KeySym originalKeysym = *keysym; - if( !isKPevent( event ) ) { - return; - } - if( isXsunServer( event ) && !awt_UseXKB) { - if( (event->xkey.state & ShiftMask) ) { // shift modifier is on - *keysym = keycodeToKeysym(event->xkey.display, - event->xkey.keycode, 3); - }else { - *keysym = keycodeToKeysym(event->xkey.display, - event->xkey.keycode, 2); - } - } else { - if( (event->xkey.state & ShiftMask) || // shift modifier is on - ((event->xkey.state & LockMask) && // lock modifier is on - (awt_ModLockIsShiftLock)) ) { // it is interpreted as ShiftLock - *keysym = keycodeToKeysym(event->xkey.display, - event->xkey.keycode, 0); - }else{ - *keysym = keycodeToKeysym(event->xkey.display, - event->xkey.keycode, 1); - } - } -} - -/* Called from handleKeyEvent. - * The purpose of this function is to make some adjustments to keysyms - * that have been found to be necessary when the NumLock mask is set. - * They come from various bug fixes and rearchitectures. - * This function is meant to be called when - * (event->xkey.state & awt_NumLockMask) is TRUE. - */ -static void -handleKeyEventWithNumLockMask(XEvent *event, KeySym *keysym) -{ - KeySym originalKeysym = *keysym; - -#if !defined(__linux__) && !defined(MACOSX) - /* The following code on Linux will cause the keypad keys - * not to echo on JTextField when the NumLock is on. The - * keysyms will be 0, because the last parameter 2 is not defined. - * See Xlib Programming Manual, O'Reilly & Associates, Section - * 9.1.5 "Other Keyboard-handling Routines", "The meaning of - * the keysym list beyond the first two (unmodified, Shift or - * Shift Lock) is not defined." - */ - - /* Translate again with NumLock as modifier. */ - /* ECH - I wonder why we think that NumLock corresponds to 2? - On Linux, we've seen xmodmap -pm yield mod2 as NumLock, - but I don't know that it will be for every configuration. - Perhaps using the index (modn in awt_MToolkit.c:setup_modifier_map) - would be more correct. - */ - *keysym = keycodeToKeysym(event->xkey.display, - event->xkey.keycode, 2); - if (originalKeysym != *keysym) { - DTRACE_PRINTLN3("%s originalKeysym=0x%x, keysym=0x%x", - "In handleKeyEventWithNumLockMask ifndef linux:", - originalKeysym, *keysym); - } -#endif - - /* Note: the XK_R? key assignments are for Type 4 kbds */ - switch (*keysym) { - case XK_R13: - *keysym = XK_KP_1; - break; - case XK_R14: - *keysym = XK_KP_2; - break; - case XK_R15: - *keysym = XK_KP_3; - break; - case XK_R10: - *keysym = XK_KP_4; - break; - case XK_R11: - *keysym = XK_KP_5; - break; - case XK_R12: - *keysym = XK_KP_6; - break; - case XK_R7: - *keysym = XK_KP_7; - break; - case XK_R8: - *keysym = XK_KP_8; - break; - case XK_R9: - *keysym = XK_KP_9; - break; - case XK_KP_Insert: - *keysym = XK_KP_0; - break; - case XK_KP_Delete: - *keysym = XK_KP_Decimal; - break; - case XK_R4: - *keysym = XK_KP_Equal; /* Type 4 kbd */ - break; - case XK_R5: - *keysym = XK_KP_Divide; - break; - case XK_R6: - *keysym = XK_KP_Multiply; - break; - /* - * Need the following keysym changes for Linux key releases. - * Sometimes the modifier state gets messed up, so we get a - * KP_Left when we should get a KP_4, for example. - * XK_KP_Insert and XK_KP_Delete were already handled above. - */ - case XK_KP_Left: - *keysym = XK_KP_4; - break; - case XK_KP_Up: - *keysym = XK_KP_8; - break; - case XK_KP_Right: - *keysym = XK_KP_6; - break; - case XK_KP_Down: - *keysym = XK_KP_2; - break; - case XK_KP_Home: - *keysym = XK_KP_7; - break; - case XK_KP_End: - *keysym = XK_KP_1; - break; - case XK_KP_Page_Up: - *keysym = XK_KP_9; - break; - case XK_KP_Page_Down: - *keysym = XK_KP_3; - break; - case XK_KP_Begin: - *keysym = XK_KP_5; - break; - default: - break; - } - - if (originalKeysym != *keysym) { - DTRACE_PRINTLN3("%s originalKeysym=0x%x, keysym=0x%x", - "In handleKeyEventWithNumLockMask:", originalKeysym, *keysym); - } -} - -/* This function is called as the keyChar parameter of a call to - * awt_post_java_key_event. It depends on being called after adjustKeySym. - * - * This function just handles a few values where we know that the - * keysym is not the same as the unicode value. For values that - * we don't handle explicitly, we just cast the keysym to a jchar. - * Most of the real mapping work that gets the correct keysym is handled - * in the mapping table, adjustKeySym, etc. - * - * XXX - * Maybe we should enumerate the keysyms for which we have a mapping - * in the keyMap, but that don't map to unicode chars, and return - * CHAR_UNDEFINED? Then use the buffer value from XLookupString - * instead of the keysym as the keychar when posting. Then we don't - * need to test using mapsToUnicodeChar. That way, we would post keyTyped - * for all the chars that generate unicode chars, including LATIN2-4, etc. - * Note: what does the buffer from XLookupString contain when - * the character is a non-printable unicode character like Cancel or Delete? - */ -jchar -keySymToUnicodeCharacter(KeySym keysym) { - jchar unicodeValue = (jchar) keysym; - - switch (keysym) { - case XK_BackSpace: - case XK_Tab: - case XK_Linefeed: - case XK_Escape: - case XK_Delete: - /* Strip off highorder bits defined in xkeysymdef.h - * I think doing this converts them to values that - * we can cast to jchars and use as java keychars. - */ - unicodeValue = (jchar) (keysym & 0x007F); - break; - case XK_Return: - unicodeValue = (jchar) 0x000a; /* the unicode char for Linefeed */ - break; - case XK_Cancel: - unicodeValue = (jchar) 0x0018; /* the unicode char for Cancel */ - break; - default: - break; - } - - if (unicodeValue != (jchar)keysym) { - DTRACE_PRINTLN3("%s originalKeysym=0x%x, keysym=0x%x", - "In keysymToUnicode:", keysym, unicodeValue); - } - - return unicodeValue; -} - - -void -awt_post_java_key_event(JNIEnv *env, jobject peer, jint id, - jlong when, jint keyCode, jchar keyChar, jint keyLocation, jint state, XEvent * event) -{ - JNU_CallMethodByName(env, NULL, peer, "postKeyEvent", "(IJICIIJI)V", id, - when, keyCode, keyChar, keyLocation, state, ptr_to_jlong(event), (jint)sizeof(XEvent)); -} /* awt_post_java_key_event() */ - - - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XWindow_getAWTKeyCodeForKeySym(JNIEnv *env, jclass clazz, jint keysym) { - jint keycode = java_awt_event_KeyEvent_VK_UNDEFINED; - Boolean mapsToUnicodeChar; - jint keyLocation; - keysymToAWTKeyCode(keysym, &keycode, &mapsToUnicodeChar, &keyLocation); - return keycode; -} - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XWindow_haveCurrentX11InputMethodInstance -(JNIEnv *env, jobject object) { - /*printf("Java_sun_awt_X11_XWindow_haveCurrentX11InputMethodInstance: %s\n", (currentX11InputMethodInstance==NULL? "NULL":" notnull")); - */ - return currentX11InputMethodInstance != NULL ? JNI_TRUE : JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XWindow_x11inputMethodLookupString -(JNIEnv *env, jobject object, jlong event, jlongArray keysymArray) { - KeySym keysym = NoSymbol; - Boolean boo; - /* keysymArray (and testbuf[]) have dimension 2 because we put there two - * perhaps different values of keysyms. - * XXX: not anymore at the moment, but I'll still keep them as arrays - * for a while. If in the course of testing we will be satisfied with - * a current single result from awt_x11inputmethod_lookupString, we'll - * change this. - */ - jlong testbuf[2]; - - testbuf[1]=0; - - boo = awt_x11inputmethod_lookupString((XKeyPressedEvent*)jlong_to_ptr(event), &keysym); - testbuf[0] = keysym; - - (*env)->SetLongArrayRegion(env, keysymArray, 0, 2, (jlong *)(testbuf)); - return boo ? JNI_TRUE : JNI_FALSE; -} - - -extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; - -/* - * Class: Java_sun_awt_X11_XWindow_getNativeColor - * Method: getNativeColor - * Signature (Ljava/awt/Color;Ljava/awt/GraphicsConfiguration;)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindow_getNativeColor -(JNIEnv *env, jobject this, jobject color, jobject gc_object) { - AwtGraphicsConfigDataPtr adata; - /* fire warning because JNU_GetLongFieldAsPtr casts jlong to (void *) */ - adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, gc_object, x11GraphicsConfigIDs.aData); - return awtJNI_GetColorForVis(env, color, adata); -} - -/* syncTopLevelPos() is necessary to insure that the window manager has in - * fact moved us to our final position relative to the reParented WM window. - * We have noted a timing window which our shell has not been moved so we - * screw up the insets thinking they are 0,0. Wait (for a limited period of - * time to let the WM hava a chance to move us - */ -void syncTopLevelPos( Display *d, Window w, XWindowAttributes *winAttr ) { - int32_t i = 0; - do { - XGetWindowAttributes( d, w, winAttr ); - /* Sometimes we get here before the WM has updated the - ** window data struct with the correct position. Loop - ** until we get a non-zero position. - */ - if ((winAttr->x != 0) || (winAttr->y != 0)) { - break; - } - else { - /* What we really want here is to sync with the WM, - ** but there's no explicit way to do this, so we - ** call XSync for a delay. - */ - XSync(d, False); - } - } while (i++ < 50); -} - -static Window getTopWindow(Window win, Window *rootWin) -{ - Window root=None, current_window=win, parent=None, *ignore_children=NULL; - Window prev_window=None; - unsigned int ignore_uint=0; - Status status = 0; - - if (win == None) return None; - do { - status = XQueryTree(awt_display, - current_window, - &root, - &parent, - &ignore_children, - &ignore_uint); - XFree(ignore_children); - if (status == 0) return None; - prev_window = current_window; - current_window = parent; - } while (parent != root); - *rootWin = root; - return prev_window; -} - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XWindow_getTopWindow -(JNIEnv *env, jclass clazz, jlong win, jlong rootWin) { - return getTopWindow((Window) win, (Window*) jlong_to_ptr(rootWin)); -} - -static void -getWMInsets -(Window window, int *left, int *top, int *right, int *bottom, int *border) { - // window is event->xreparent.window - Window topWin = None, rootWin = None, containerWindow = None; - XWindowAttributes winAttr, topAttr; - int screenX, screenY; - topWin = getTopWindow(window, &rootWin); - syncTopLevelPos(awt_display, topWin, &topAttr); - // (screenX, screenY) is (0,0) of the reparented window - // converted to screen coordinates. - XTranslateCoordinates(awt_display, window, rootWin, - 0,0, &screenX, &screenY, &containerWindow); - *left = screenX - topAttr.x - topAttr.border_width; - *top = screenY - topAttr.y - topAttr.border_width; - XGetWindowAttributes(awt_display, window, &winAttr); - *right = topAttr.width - ((winAttr.width) + *left); - *bottom = topAttr.height - ((winAttr.height) + *top); - *border = topAttr.border_width; -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWMInsets -(JNIEnv *env, jclass clazz, jlong window, jlong left, jlong top, jlong right, jlong bottom, jlong border) { - getWMInsets((Window) window, - (int*) jlong_to_ptr(left), - (int*) jlong_to_ptr(top), - (int*) jlong_to_ptr(right), - (int*) jlong_to_ptr(bottom), - (int*) jlong_to_ptr(border)); -} - -static void -getWindowBounds -(Window window, int *x, int *y, int *width, int *height) { - XWindowAttributes winAttr; - XSync(awt_display, False); - XGetWindowAttributes(awt_display, window, &winAttr); - *x = winAttr.x; - *y = winAttr.y; - *width = winAttr.width; - *height = winAttr.height; -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWindowBounds -(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) { - getWindowBounds((Window) window, (int*) jlong_to_ptr(x), (int*) jlong_to_ptr(y), - (int*) jlong_to_ptr(width), (int*) jlong_to_ptr(height)); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_setSizeHints -(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) { - XSizeHints *size_hints = XAllocSizeHints(); - size_hints->flags = USPosition | PPosition | PSize; - size_hints->x = (int)x; - size_hints->y = (int)y; - size_hints->width = (int)width; - size_hints->height = (int)height; - XSetWMNormalHints(awt_display, (Window)window, size_hints); - XFree((char*)size_hints); -} - - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XWindow_initIDs - (JNIEnv *env, jclass clazz) -{ - char *ptr = NULL; - windowID = (*env)->GetFieldID(env, clazz, "window", "J"); - CHECK_NULL(windowID); - targetID = (*env)->GetFieldID(env, clazz, "target", "Ljava/awt/Component;"); - CHECK_NULL(targetID); - graphicsConfigID = (*env)->GetFieldID(env, clazz, "graphicsConfig", "Lsun/awt/X11GraphicsConfig;"); - CHECK_NULL(graphicsConfigID); - drawStateID = (*env)->GetFieldID(env, clazz, "drawState", "I"); - CHECK_NULL(drawStateID); - ptr = getenv("_AWT_USE_TYPE4_PATCH"); - if( ptr != NULL && ptr[0] != 0 ) { - if( strncmp("true", ptr, 4) == 0 ) { - awt_UseType4Patch = True; - }else if( strncmp("false", ptr, 5) == 0 ) { - awt_UseType4Patch = False; - } - } -} - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XWindow_getKeySymForAWTKeyCode(JNIEnv* env, jclass clazz, jint keycode) { - return awt_getX11KeySym(keycode); -} diff --git a/app/src/main/jni/awt_xawt/xawt/XlibWrapper.c b/app/src/main/jni/awt_xawt/xawt/XlibWrapper.c deleted file mode 100644 index 50b476d47..000000000 --- a/app/src/main/jni/awt_xawt/xawt/XlibWrapper.c +++ /dev/null @@ -1,2361 +0,0 @@ -/* - * Copyright (c) 2002, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "sun_awt_X11_XlibWrapper.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include "utility/rect.h" - -#include - -// From XWindow.c -extern KeySym keycodeToKeysym(Display *display, KeyCode keycode, int index); - -#if defined(DEBUG) -static jmethodID lockIsHeldMID = NULL; - -static void -CheckHaveAWTLock(JNIEnv *env) -{ - if (lockIsHeldMID == NULL) { - if (tkClass == NULL) return; - lockIsHeldMID = - (*env)->GetStaticMethodID(env, tkClass, - "isAWTLockHeldByCurrentThread", "()Z"); - if (lockIsHeldMID == NULL) return; - } - if (!(*env)->CallStaticBooleanMethod(env, tkClass, lockIsHeldMID)) { - JNU_ThrowInternalError(env, "Current thread does not hold AWT_LOCK!"); - } -} - -#define AWT_CHECK_HAVE_LOCK() \ - do { \ - CheckHaveAWTLock(env); \ - if ((*env)->ExceptionCheck(env)) { \ - return; \ - } \ - } while (0); \ - -#define AWT_CHECK_HAVE_LOCK_RETURN(ret) \ - do { \ - CheckHaveAWTLock(env); \ - if ((*env)->ExceptionCheck(env)) { \ - return (ret); \ - } \ - } while (0); \ - -#else -#define AWT_CHECK_HAVE_LOCK() -#define AWT_CHECK_HAVE_LOCK_RETURN(ret) -#endif - -void freeNativeStringArray(char **array, jsize length) { - int i; - if (array == NULL) { - return; - } - for (i = 0; i < length; i++) { - free(array[i]); - } - free(array); -} - -char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length) { - Bool err = FALSE; - char ** strings; - int index, str_index = 0; - jsize length = (*env)->GetArrayLength(env, array); - - if (length == 0) { - return NULL; - } - - strings = (char**) calloc(length, sizeof (char*)); - - if (strings == NULL) { - JNU_ThrowOutOfMemoryError(env, ""); - return NULL; - } - - for (index = 0; index < length; index++) { - jstring str = (*env)->GetObjectArrayElement(env, array, index); - if (str != NULL) { - const char * str_char = JNU_GetStringPlatformChars(env, str, NULL); - if (str_char != NULL) { - char * dup_str = strdup(str_char); - if (dup_str != NULL) { - strings[str_index++] = dup_str; - } else { - JNU_ThrowOutOfMemoryError(env, ""); - err = TRUE; - } - JNU_ReleaseStringPlatformChars(env, str, str_char); - } else { - err = TRUE; - } - (*env)->DeleteLocalRef(env, str); - if (err) { - break; - } - } - } - - if (err) { - freeNativeStringArray(strings, str_index); - strings = NULL; - str_index = -1; - } - *ret_length = str_index; - - return strings; -} - -/* - * Class: XlibWrapper - * Method: XOpenDisplay - * Signature: (J)J - */ - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XOpenDisplay -(JNIEnv *env, jclass clazz, jlong display_name) -{ - Display *dp; - AWT_CHECK_HAVE_LOCK_RETURN(0); - dp = XOpenDisplay((char *) jlong_to_ptr(display_name)); - - return ptr_to_jlong(dp); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XCloseDisplay(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK(); - XCloseDisplay((Display*) jlong_to_ptr(display)); -} - -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XDisplayString(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XDisplayString((Display*) jlong_to_ptr(display))); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XSetCloseDownMode(JNIEnv *env, jclass clazz, - jlong display, jint mode) { - AWT_CHECK_HAVE_LOCK(); - XSetCloseDownMode((Display*) jlong_to_ptr(display), (int)mode); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DefaultScreen - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DefaultScreen (JNIEnv *env, jclass clazz, jlong display) { - - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) DefaultScreen((Display *) jlong_to_ptr(display)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: ScreenOfDisplay - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_ScreenOfDisplay(JNIEnv *env, jclass clazz, jlong display, jlong screen_number) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(ScreenOfDisplay((Display *) jlong_to_ptr(display), - screen_number)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DoesBackingStore - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_DoesBackingStore(JNIEnv *env, jclass clazz, jlong screen) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jint) DoesBackingStore((Screen*) jlong_to_ptr(screen)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DisplayWidth - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidth -(JNIEnv *env, jclass clazz, jlong display, jlong screen) { - - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) DisplayWidth((Display *) jlong_to_ptr(display),screen); - -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DisplayWidthMM - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayWidthMM -(JNIEnv *env, jclass clazz, jlong display, jlong screen) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) DisplayWidthMM((Display *) jlong_to_ptr(display),screen); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DisplayHeight - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeight -(JNIEnv *env, jclass clazz, jlong display, jlong screen) { - - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) DisplayHeight((Display *) jlong_to_ptr(display),screen); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: DisplayHeightMM - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_DisplayHeightMM -(JNIEnv *env, jclass clazz, jlong display, jlong screen) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) DisplayHeightMM((Display *) jlong_to_ptr(display),screen); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: RootWindow - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_RootWindow -(JNIEnv *env , jclass clazz, jlong display, jlong screen_number) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) RootWindow((Display *) jlong_to_ptr(display), screen_number); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: ScreenCount - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_ScreenCount -(JNIEnv *env , jclass clazz, jlong display) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ScreenCount((Display *) jlong_to_ptr(display)); -} - - -/* - * Class: XlibWrapper - * Method: XCreateWindow - * Signature: (JJIIIIIIJJJJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateWindow - (JNIEnv *env, jclass clazz, jlong display, jlong window, - jint x, jint y, jint w, jint h , jint border_width, jint depth, - jlong wclass, jlong visual, jlong valuemask, jlong attributes) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XCreateWindow((Display *) jlong_to_ptr(display),(Window) window, x, y, w, h, - border_width, depth, wclass, (Visual *) jlong_to_ptr(visual), - valuemask, (XSetWindowAttributes *) jlong_to_ptr(attributes)); - -} - -/* - * Class: XlibWrapper - * Method: XConvertCase - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConvertCase - (JNIEnv *env, jclass clazz, jlong keysym, - jlong keysym_lowercase, jlong keysym_uppercase) -{ - AWT_CHECK_HAVE_LOCK(); - XConvertCase(keysym, (jlong_to_ptr(keysym_lowercase)), - (jlong_to_ptr(keysym_uppercase))); -} - - -/* - * Class: XlibWrapper - * Method: XMapWindow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - AWT_CHECK_HAVE_LOCK(); - XMapWindow( (Display *)jlong_to_ptr(display),(Window) window); - -} - -/* - * Class: XlibWrapper - * Method: XMapRaised - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMapRaised -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - AWT_CHECK_HAVE_LOCK(); - XMapRaised( (Display *)jlong_to_ptr(display),(Window) window); - -} - -/* - * Class: XlibWrapper - * Method: XRaiseWindow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRaiseWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - - AWT_CHECK_HAVE_LOCK(); - XRaiseWindow( (Display *)jlong_to_ptr(display),(Window) window); - -} - -/* - * Class: XlibWrapper - * Method: XLowerWindow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XLowerWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - - AWT_CHECK_HAVE_LOCK(); - XLowerWindow( (Display *)jlong_to_ptr(display),(Window) window); - -} - -/* - * Class: XlibWrapper - * Method: XRestackWindows - * Signature: (JJI)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRestackWindows -(JNIEnv *env, jclass clazz, jlong display, jlong windows, jint length) -{ - - AWT_CHECK_HAVE_LOCK(); - XRestackWindows( (Display *) jlong_to_ptr(display), (Window *) jlong_to_ptr(windows), length); - -} - -/* - * Class: XlibWrapper - * Method: XConfigureWindow - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XConfigureWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong value_mask, - jlong values) -{ - AWT_CHECK_HAVE_LOCK(); - XConfigureWindow((Display*)jlong_to_ptr(display), (Window)window, - (unsigned int)value_mask, (XWindowChanges*)jlong_to_ptr(values)); -} - -/* - * Class: XlibWrapper - * Method: XSetInputFocus - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - - AWT_CHECK_HAVE_LOCK(); - XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, CurrentTime); - -} -/* - * Class: XlibWrapper - * Method: XSetInputFocus2 - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetInputFocus2 -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong time) -{ - - AWT_CHECK_HAVE_LOCK(); - XSetInputFocus( (Display *)jlong_to_ptr(display),(Window) window, RevertToPointerRoot, time); - -} - -/* - * Class: XlibWrapper - * Method: XGetInputFocus - * Signature: (JJ)V - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetInputFocus -(JNIEnv *env, jclass clazz, jlong display) -{ - - Window focusOwner; - int revert_to; - AWT_CHECK_HAVE_LOCK_RETURN(0); - XGetInputFocus( (Display *)jlong_to_ptr(display), &focusOwner, &revert_to); - return focusOwner; -} - - -/* - * Class: XlibWrapper - * Method: XDestroyWindow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDestroyWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - AWT_CHECK_HAVE_LOCK(); - XDestroyWindow( (Display *)jlong_to_ptr(display),(Window) window); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGrabPointer -(JNIEnv *env, jclass clazz, jlong display, jlong window, - jint owner_events, jint event_mask, jint pointer_mode, - jint keyboard_mode, jlong confine_to, jlong cursor, jlong time) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XGrabPointer( (Display *)jlong_to_ptr(display), (Window) window, - (Bool) owner_events, (unsigned int) event_mask, (int) pointer_mode, - (int) keyboard_mode, (Window) confine_to, (Cursor) cursor, (Time) time); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabPointer -(JNIEnv *env, jclass clazz, jlong display, jlong time) -{ - AWT_CHECK_HAVE_LOCK(); - XUngrabPointer( (Display *)jlong_to_ptr(display), (Time) time); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGrabKeyboard -(JNIEnv *env, jclass clazz, jlong display, jlong window, - jint owner_events, jint pointer_mode, - jint keyboard_mode, jlong time) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XGrabKeyboard( (Display *)jlong_to_ptr(display), (Window) window, - (Bool) owner_events, (int) pointer_mode, - (int) keyboard_mode, (Time) time); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUngrabKeyboard -(JNIEnv *env, jclass clazz, jlong display, jlong time) -{ - AWT_CHECK_HAVE_LOCK(); - XUngrabKeyboard( (Display *)jlong_to_ptr(display), (Time) time); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XGrabServer(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK(); - XGrabServer((Display*)jlong_to_ptr(display)); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XUngrabServer(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK(); - XUngrabServer((Display*)jlong_to_ptr(display)); - /* Workaround for bug 5039226 */ - XSync((Display*)jlong_to_ptr(display), False); -} - -/* - * Class: XlibWrapper - * Method: XUnmapWindow - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XUnmapWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - - AWT_CHECK_HAVE_LOCK(); - XUnmapWindow( (Display *)jlong_to_ptr(display),(Window) window); - -} - - - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSelectInput -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong mask) -{ - AWT_CHECK_HAVE_LOCK(); - XSelectInput((Display *) jlong_to_ptr(display), (Window) window, mask); -} - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEvents -(JNIEnv *env, jclass clazz, jlong display, jlong device, jlong bits_to_change, - jlong values_for_bits) -{ - AWT_CHECK_HAVE_LOCK(); - XkbSelectEvents((Display *) jlong_to_ptr(display), (unsigned int)device, - (unsigned long)bits_to_change, - (unsigned long)values_for_bits); -} -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSelectEventDetails -(JNIEnv *env, jclass clazz, jlong display, jlong device, jlong event_type, - jlong bits_to_change, jlong values_for_bits) -{ - AWT_CHECK_HAVE_LOCK(); - XkbSelectEventDetails((Display *) jlong_to_ptr(display), (unsigned int)device, - (unsigned int) event_type, - (unsigned long)bits_to_change, - (unsigned long)values_for_bits); -} -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbQueryExtension -(JNIEnv *env, jclass clazz, jlong display, jlong opcode_rtrn, jlong event_rtrn, - jlong error_rtrn, jlong major_in_out, jlong minor_in_out) -{ - Bool status; - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - status = XkbQueryExtension((Display *) jlong_to_ptr(display), - (int *) jlong_to_ptr(opcode_rtrn), - (int *) jlong_to_ptr(event_rtrn), - (int *) jlong_to_ptr(error_rtrn), - (int *) jlong_to_ptr(major_in_out), - (int *) jlong_to_ptr(minor_in_out)); - return status ? JNI_TRUE : JNI_FALSE; -} -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbLibraryVersion -(JNIEnv *env, jclass clazz, jlong lib_major_in_out, jlong lib_minor_in_out) -{ - Bool status; - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - *((int *)jlong_to_ptr(lib_major_in_out)) = XkbMajorVersion; - *((int *)jlong_to_ptr(lib_minor_in_out)) = XkbMinorVersion; - status = XkbLibraryVersion((int *)jlong_to_ptr(lib_major_in_out), - (int *)jlong_to_ptr(lib_minor_in_out)); - return status ? JNI_TRUE : JNI_FALSE; -} - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetMap -(JNIEnv *env, jclass clazz, jlong display, jlong which, jlong device_spec) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) XkbGetMap( (Display *) jlong_to_ptr(display), - (unsigned int) which, - (unsigned int) device_spec); -} -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XkbGetUpdatedMap -(JNIEnv *env, jclass clazz, jlong display, jlong which, jlong xkb) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) XkbGetUpdatedMap( (Display *) jlong_to_ptr(display), - (unsigned int) which, - (XkbDescPtr) jlong_to_ptr(xkb)); -} -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbFreeKeyboard -(JNIEnv *env, jclass clazz, jlong xkb, jlong which, jboolean free_all) -{ - AWT_CHECK_HAVE_LOCK(); - XkbFreeKeyboard(jlong_to_ptr(xkb), (unsigned int)which, free_all); -} -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XkbTranslateKeyCode -(JNIEnv *env, jclass clazz, jlong xkb, jint keycode, jlong mods, jlong mods_rtrn, jlong keysym_rtrn) -{ - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - Bool b; - b = XkbTranslateKeyCode((XkbDescPtr)xkb, (unsigned int)keycode, (unsigned int)mods, - (unsigned int *)jlong_to_ptr(mods_rtrn), - (KeySym *)jlong_to_ptr(keysym_rtrn)); - //printf("native, input: keycode:0x%0X; mods:0x%0X\n", keycode, mods); - //printf("native, output: keysym:0x%0X; mods:0x%0X\n", - // *(unsigned int *)jlong_to_ptr(keysym_rtrn), - // *(unsigned int *)jlong_to_ptr(mods_rtrn)); - return b ? JNI_TRUE : JNI_FALSE; -} -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XkbSetDetectableAutoRepeat -(JNIEnv *env, jclass clazz, jlong display, jboolean detectable) -{ - AWT_CHECK_HAVE_LOCK(); - XkbSetDetectableAutoRepeat((Display *) jlong_to_ptr(display), detectable, NULL); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XNextEvent - * Signature: (JJ)V - */ - - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XNextEvent -(JNIEnv *env, jclass clazz, jlong display, jlong ptr) -{ - AWT_CHECK_HAVE_LOCK(); - XNextEvent( (Display *) jlong_to_ptr(display), jlong_to_ptr(ptr)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XMaskEvent - * Signature: (JJJ)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMaskEvent - (JNIEnv *env, jclass clazz, jlong display, jlong event_mask, jlong event_return) -{ - AWT_CHECK_HAVE_LOCK(); - XMaskEvent( (Display *) jlong_to_ptr(display), event_mask, (XEvent *) jlong_to_ptr(event_return)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XWindowEvent - * Signature: (JJJJ)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XWindowEvent - (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong event_mask, jlong event_return) -{ - AWT_CHECK_HAVE_LOCK(); - XWindowEvent( (Display *) jlong_to_ptr(display), (Window)window, event_mask, (XEvent *) jlong_to_ptr(event_return)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFilterEvent - * Signature: (JJ)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XFilterEvent -(JNIEnv *env, jclass clazz, jlong ptr, jlong window) -{ - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - return (jboolean) XFilterEvent((XEvent *) jlong_to_ptr(ptr), (Window) window); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSupportsLocale - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XSupportsLocale -(JNIEnv *env, jclass clazz) -{ - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - return (jboolean)XSupportsLocale(); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetLocaleModifiers - * Signature: (Ljava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XSetLocaleModifiers -(JNIEnv *env, jclass clazz, jstring jstr) -{ - char * modifier_list = NULL; - char * ret = NULL; - - if (!JNU_IsNull(env, jstr)) { - modifier_list = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); - CHECK_NULL_RETURN(modifier_list, NULL); - } - - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - if (modifier_list) { - ret = XSetLocaleModifiers(modifier_list); - JNU_ReleaseStringPlatformChars(env, jstr, (const char *) modifier_list); - } else { - ret = XSetLocaleModifiers(""); - } - - return (ret != NULL ? JNU_NewStringPlatform(env, ret): NULL); -} - - -/* - * Class: sun_awt_X11_wrappers_XlibWrapper - * Method: XPeekEvent - * Signature: (JJ)V - */ - - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XPeekEvent -(JNIEnv *env, jclass clazz, jlong display, jlong ptr) -{ - AWT_CHECK_HAVE_LOCK(); - XPeekEvent((Display *) jlong_to_ptr(display),jlong_to_ptr(ptr)); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XMoveResizeWindow - * Signature: (JJIIII)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveResizeWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jint x , jint y , jint width, jint height) { - - AWT_CHECK_HAVE_LOCK(); - XMoveResizeWindow( (Display *) jlong_to_ptr(display), (Window) window, x, y, width, height); - -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XResizeWindow - * Signature: (JJII)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XResizeWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) -{ - AWT_CHECK_HAVE_LOCK(); - XResizeWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XMoveWindow - * Signature: (JJII)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XMoveWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jint width, jint height) -{ - AWT_CHECK_HAVE_LOCK(); - XMoveWindow( (Display *) jlong_to_ptr(display),(Window) window,width,height); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetWindowBackground - * Signature: (JJJ)V - */ - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWindowBackground -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong background_pixel) { - - AWT_CHECK_HAVE_LOCK(); - XSetWindowBackground((Display *) jlong_to_ptr(display),window,background_pixel); - -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFlush - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFlush -(JNIEnv *env, jclass clazz, jlong display) { - - AWT_CHECK_HAVE_LOCK(); - XFlush((Display *)jlong_to_ptr(display)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSync - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSync -(JNIEnv *env, jclass clazz, jlong display, jint discard) { - - AWT_CHECK_HAVE_LOCK(); - XSync((Display *) jlong_to_ptr(display), discard); - -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XTranslateCoordinates -(JNIEnv *env, jclass clazz, jlong display, jlong src_w, jlong dest_w, - jlong src_x, jlong src_y, jlong dest_x_return, jlong dest_y_return, - jlong child_return) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XTranslateCoordinates( (Display *) jlong_to_ptr(display), src_w, dest_w, - src_x, src_y, - (int *) jlong_to_ptr(dest_x_return), - (int *) jlong_to_ptr(dest_y_return), - (Window *) jlong_to_ptr(child_return)); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued -(JNIEnv *env, jclass clazz, jlong display, jint mode) { - - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XEventsQueued((Display *) jlong_to_ptr(display), mode); - -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: SetProperty - * Signature: (JJJLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_SetProperty -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom, jstring jstr) { - char *cname; - XTextProperty tp; - int32_t status; - - /* - In case there are direct support of UTF-8 declared, use UTF-8 strings. - */ - if (!JNU_IsNull(env, jstr)) { -#ifdef X_HAVE_UTF8_STRING - cname = (char *) (*env)->GetStringUTFChars(env, jstr, JNI_FALSE); -#else - cname = (char *) JNU_GetStringPlatformChars(env, jstr, NULL); -#endif - CHECK_NULL(cname); - } else { - cname = ""; - } - - - AWT_CHECK_HAVE_LOCK(); - -#ifdef X_HAVE_UTF8_STRING - status = Xutf8TextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, - XStdICCTextStyle, &tp); -#else - status = XmbTextListToTextProperty((Display *)jlong_to_ptr(display), &cname, 1, - XStdICCTextStyle, &tp); -#endif - - - if (status == Success || status > 0) { - XChangeProperty((Display *)jlong_to_ptr(display), window, atom, tp.encoding, tp.format, PropModeReplace, tp.value, tp.nitems); - if (tp.value != NULL) { - XFree(tp.value); - } - } - - if (!JNU_IsNull(env, jstr)) { -#ifdef X_HAVE_UTF8_STRING - (*env)->ReleaseStringUTFChars(env, jstr, (const char *) cname); -#else - JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); -#endif - } -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XChangeProperty - * Signature: (JJJJJJJJJJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyImpl( - JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, - jlong type, jint format, jint mode, jlong data, jint nelements) -{ - AWT_CHECK_HAVE_LOCK(); - XChangeProperty((Display*) jlong_to_ptr(display), (Window) window, (Atom) property, - (Atom) type, format, mode, (unsigned char*) jlong_to_ptr(data), - nelements); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XChangePropertyS - * Signature: (JJJJJJJJJLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangePropertyS( - JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, - jlong type, jint format, jint mode, jstring value) -{ - jboolean iscopy; - AWT_CHECK_HAVE_LOCK(); - const char * chars = JNU_GetStringPlatformChars(env, value, &iscopy); - CHECK_NULL(chars); - XChangeProperty((Display*)jlong_to_ptr(display), window, (Atom)property, - (Atom)type, format, mode, (unsigned char*)chars, strlen(chars)); - if (iscopy) { - JNU_ReleaseStringPlatformChars(env, value, chars); - } -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetWindowProperty - * Signature: (JJJJJJJJJJJ)J; - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowProperty -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong property, jlong long_offset, - jlong long_length, jlong delete, jlong req_type, jlong actual_type, - jlong actual_format, jlong nitems_ptr, jlong bytes_after, jlong data_ptr) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XGetWindowProperty((Display*) jlong_to_ptr(display), window, property, long_offset, long_length, - delete, (Atom) req_type, (Atom*) jlong_to_ptr(actual_type), - (int *) jlong_to_ptr(actual_format), (unsigned long *) jlong_to_ptr(nitems_ptr), - (unsigned long*) jlong_to_ptr(bytes_after), (unsigned char**) jlong_to_ptr(data_ptr)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: GetProperty - * Signature: (JJJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_GetProperty -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) -{ - /* Request status */ - int status; - - /* Returns of XGetWindowProperty */ - Atom actual_type; - int actual_format; - unsigned long nitems; - unsigned long bytes_after; - unsigned char * string; - jstring res = NULL; - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - status = XGetWindowProperty((Display*)jlong_to_ptr(display), window, - atom, 0, 0xFFFF, False, XA_STRING, - &actual_type, &actual_format, &nitems, &bytes_after, - &string); - - if (status != Success || string == NULL) { - return NULL; - } - - if (actual_type == XA_STRING && actual_format == 8) { - res = JNU_NewStringPlatform(env,(char*) string); - } - XFree(string); - return res; -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: InternAtom - * Signature: (JLjava/lang/String;I)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_InternAtom -(JNIEnv *env, jclass clazz, jlong display, jstring jstr, jint ife) { - - char *cname; - unsigned long atom; - - AWT_CHECK_HAVE_LOCK_RETURN(0); - - if (!JNU_IsNull(env, jstr)) { - cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); - CHECK_NULL_RETURN(cname, 0); - } else { - cname = ""; - } - - atom = XInternAtom((Display *) jlong_to_ptr(display), cname, ife); - - if (!JNU_IsNull(env, jstr)) { - JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); - } - - return (jlong) atom; - -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XCreateFontCursor -(JNIEnv *env, jclass clazz, jlong display, jint shape) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XCreateFontCursor((Display *) jlong_to_ptr(display), (int) shape); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XCreatePixmapCursor - * Signature: (JJJJJII)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreatePixmapCursor -(JNIEnv *env , jclass clazz, jlong display, jlong source, jlong mask, jlong fore, jlong back, jint x , jint y) { - - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong) XCreatePixmapCursor((Display *) jlong_to_ptr(display), (Pixmap) source, (Pixmap) mask, - (XColor *) jlong_to_ptr(fore), (XColor *) jlong_to_ptr(back), x, y); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XQueryBestCursor - * Signature: (JJIIJJ)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryBestCursor -(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jlong width_return, jlong height_return) { - - Status status; - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - status = XQueryBestCursor((Display *) jlong_to_ptr(display), (Drawable) drawable, width,height, - (unsigned int *) jlong_to_ptr(width_return), (unsigned int *) jlong_to_ptr(height_return)); - - if (status == 0) return JNI_FALSE; - else return JNI_TRUE; -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFreeCursor - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreeCursor -(JNIEnv *env, jclass clazz, jlong display, jlong cursor) { - - AWT_CHECK_HAVE_LOCK(); - XFreeCursor( (Display *) jlong_to_ptr(display), (Cursor) cursor); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XQueryPointer - * Signature: (JJJJJJJJJ)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryPointer -(JNIEnv *env, jclass clazz, jlong display, jlong w, jlong root_return, jlong child_return, jlong root_x_return , jlong root_y_return, jlong win_x_return, jlong win_y_return, jlong mask_return) { - - Bool b; - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - b = XQueryPointer((Display *) jlong_to_ptr(display), - (Window) w, (Window *) jlong_to_ptr(root_return), (Window *) jlong_to_ptr(child_return), - (int *) jlong_to_ptr(root_x_return), (int *) jlong_to_ptr(root_y_return), - (int *) jlong_to_ptr(win_x_return), (int *) jlong_to_ptr(win_y_return), - (unsigned int *) jlong_to_ptr(mask_return)); - - return b ? JNI_TRUE : JNI_FALSE; -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XChangeWindowAttributes - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XChangeWindowAttributes -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong valuemask, jlong attributes) { - - AWT_CHECK_HAVE_LOCK(); - XChangeWindowAttributes((Display *) jlong_to_ptr(display), (Window) window, (unsigned long) valuemask, - (XSetWindowAttributes *) jlong_to_ptr(attributes)); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetTransientFor - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetTransientFor -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong transient_for_window) -{ - AWT_CHECK_HAVE_LOCK(); - XSetTransientForHint((Display *) jlong_to_ptr(display), window, transient_for_window); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetWMHints - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMHints -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) -{ - AWT_CHECK_HAVE_LOCK(); - XSetWMHints((Display *) jlong_to_ptr(display), window, (XWMHints *) jlong_to_ptr(hints)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetWMHints - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMHints -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) -{ - XWMHints * get_hints; - AWT_CHECK_HAVE_LOCK(); - get_hints = XGetWMHints((Display*)jlong_to_ptr(display), window); - if (get_hints != NULL) { - memcpy(jlong_to_ptr(hints), get_hints, sizeof(XWMHints)); - XFree(get_hints); - } else { - memset(jlong_to_ptr(hints), 0, sizeof(XWMHints)); - } -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetPointerMapping - * Signature: (JJI)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetPointerMapping -(JNIEnv *env, jclass clazz, jlong display, jlong map, jint buttonNumber) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XGetPointerMapping((Display*)jlong_to_ptr(display), (unsigned char*) jlong_to_ptr(map), buttonNumber); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetDefault - * Signature: (JJI)I - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XGetDefault -(JNIEnv *env, jclass clazz, jlong display, jstring program, jstring option) -{ - char * c_program = NULL; - char * c_option = NULL; - char * c_res = NULL; - - if (!JNU_IsNull(env, program)) { - c_program = (char *)JNU_GetStringPlatformChars(env, program, NULL); - } - CHECK_NULL_RETURN(c_program, NULL); - - if (!JNU_IsNull(env, option)) { - c_option = (char *)JNU_GetStringPlatformChars(env, option, NULL); - } - - if (c_option == NULL) { - JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); - return NULL; - } - - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - c_res = XGetDefault((Display*)jlong_to_ptr(display), c_program, c_option); - // The strings returned by XGetDefault() are owned by Xlib and - // should not be modified or freed by the client. - - JNU_ReleaseStringPlatformChars(env, program, (const char *) c_program); - JNU_ReleaseStringPlatformChars(env, option, (const char *) c_option); - - if (c_res != NULL) { - return JNU_NewStringPlatform(env, c_res); - } else { - return NULL; - } -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: getScreenOfWindow - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_getScreenOfWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - XWindowAttributes attrs; - memset(&attrs, 0, sizeof(attrs)); - AWT_CHECK_HAVE_LOCK_RETURN(0); - XGetWindowAttributes((Display *) jlong_to_ptr(display), window, &attrs); - return ptr_to_jlong(attrs.screen); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XScreenNumberOfScreen - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XScreenNumberOfScreen -(JNIEnv *env, jclass clazz, jlong screen) -{ - AWT_CHECK_HAVE_LOCK_RETURN(-1); - if(jlong_to_ptr(screen) == NULL) { - return -1; - } - return XScreenNumberOfScreen((Screen*) jlong_to_ptr(screen)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XIconifyWindow - * Signature: (JJJ)V - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XIconifyWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong screenNumber) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XIconifyWindow((Display*) jlong_to_ptr(display), window, screenNumber); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFree - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFree -(JNIEnv *env, jclass clazz, jlong ptr) -{ - AWT_CHECK_HAVE_LOCK(); - XFree(jlong_to_ptr(ptr)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFree - * Signature: (J)V - */ -JNIEXPORT jbyteArray JNICALL Java_sun_awt_X11_XlibWrapper_getStringBytes -(JNIEnv *env, jclass clazz, jlong str_ptr) -{ - unsigned char * str = (unsigned char*) jlong_to_ptr(str_ptr); - long length = strlen((char*)str); - jbyteArray res = (*env)->NewByteArray(env, length); - CHECK_NULL_RETURN(res, NULL); - (*env)->SetByteArrayRegion(env, res, 0, length, - (const signed char*) str); - return res; -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: ServerVendor - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_ServerVendor -(JNIEnv *env, jclass clazz, jlong display) -{ - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - return JNU_NewStringPlatform(env, ServerVendor((Display*)jlong_to_ptr(display))); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: VendorRelease - * Signature: (J)I; - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_VendorRelease -(JNIEnv *env, jclass clazz, jlong display) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return VendorRelease((Display*)jlong_to_ptr(display)); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: IsXsunKPBehavior - * Signature: (J)Z; - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsXsunKPBehavior -(JNIEnv *env, jclass clazz, jlong display) -{ - // Xsun without XKB uses keysymarray[2] keysym to determine if it is KP event. - // Otherwise, it is [1] or sometimes [0]. - // This sniffer first tries to determine what is a keycode for XK_KP_7 - // using XKeysymToKeycode; - // second, in which place in the keysymarray is XK_KP_7 - // using XKeycodeToKeysym. - int kc7; - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - kc7 = XKeysymToKeycode((Display*)jlong_to_ptr(display), XK_KP_7); - if( !kc7 ) { - // keycode is not defined. Why, it's a reduced keyboard perhaps: - // report arbitrarily false. - return JNI_FALSE; - } else { - long ks2 = keycodeToKeysym((Display*)jlong_to_ptr(display), kc7, 2); - if( ks2 == XK_KP_7 ) { - //XXX If some Xorg server would put XK_KP_7 in keysymarray[2] as well, - //XXX for yet unknown to me reason, the sniffer would lie. - return JNI_TRUE; - }else{ - return JNI_FALSE; - } - } -} - - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsSunKeyboard -(JNIEnv *env, jclass clazz, jlong display) -{ - int xx; - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - xx = XKeysymToKeycode((Display*)jlong_to_ptr(display), SunXK_F37); - return (!xx) ? JNI_FALSE : JNI_TRUE; -} - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard -(JNIEnv *env, jclass clazz, jlong display) -{ - int xx; - static jboolean result = JNI_FALSE; - - int32_t minKeyCode, maxKeyCode, keySymsPerKeyCode; - KeySym *keySyms, *keySymsStart, keySym; - int32_t i; - int32_t kanaCount = 0; - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - - // There's no direct way to determine whether the keyboard has - // a kana lock key. From available keyboard mapping tables, it looks - // like only keyboards with the kana lock key can produce keysyms - // for kana characters. So, as an indirect test, we check for those. - XDisplayKeycodes((Display*)jlong_to_ptr(display), &minKeyCode, &maxKeyCode); - keySyms = XGetKeyboardMapping((Display*)jlong_to_ptr(display), minKeyCode, maxKeyCode - minKeyCode + 1, &keySymsPerKeyCode); - keySymsStart = keySyms; - for (i = 0; i < (maxKeyCode - minKeyCode + 1) * keySymsPerKeyCode; i++) { - keySym = *keySyms++; - if ((keySym & 0xff00) == 0x0400) { - kanaCount++; - } - } - XFree(keySymsStart); - - // use a (somewhat arbitrary) minimum so we don't get confused by a stray function key - result = kanaCount > 10; - return result ? JNI_TRUE : JNI_FALSE; -} - -JavaVM* jvm = NULL; -static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) { - JNIEnv * env; - // First call the native synthetic error handler declared in "awt_util.h" file. - if (current_native_xerror_handler != NULL) { - current_native_xerror_handler(dpy, event); - } - if (jvm != NULL) { - env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); - if (env) { - return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", - "globalErrorHandler", "(JJ)I", ptr_to_jlong(dpy), ptr_to_jlong(event)).i; - } - } - return 0; -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: SetToolkitErrorHandler - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_SetToolkitErrorHandler -(JNIEnv *env, jclass clazz) -{ - if ((*env)->GetJavaVM(env, &jvm) < 0) { - return 0; - } - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XSetErrorHandler(ToolkitErrorHandler)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetErrorHandler - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetErrorHandler -(JNIEnv *env, jclass clazz, jlong handler) -{ - AWT_CHECK_HAVE_LOCK(); - XSetErrorHandler((XErrorHandler) jlong_to_ptr(handler)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: CallErrorHandler - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_CallErrorHandler -(JNIEnv *env, jclass clazz, jlong handler, jlong display, jlong event_ptr) -{ - return (*(XErrorHandler)jlong_to_ptr(handler))((Display*) jlong_to_ptr(display), (XErrorEvent*) jlong_to_ptr(event_ptr)); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: PrintXErrorEvent - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_PrintXErrorEvent -(JNIEnv *env, jclass clazz, jlong display, jlong event_ptr) -{ - char msg[128]; - char buf[128]; - - XErrorEvent* err = (XErrorEvent *)jlong_to_ptr(event_ptr); - - XGetErrorText((Display *)jlong_to_ptr(display), err->error_code, msg, sizeof(msg)); - jio_fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid, err->serial); - jio_snprintf(buf, sizeof(buf), "%d", err->request_code); - XGetErrorDatabaseText((Display *)jlong_to_ptr(display), "XRequest", buf, "Unknown", msg, sizeof(msg)); - jio_fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg); - if (err->request_code > 128) { - jio_fprintf(stderr, "Minor opcode %d\n", err->minor_code); - } -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XInternAtoms - * Signature: (J[Ljava/lang/String;ZJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XInternAtoms -(JNIEnv *env, jclass clazz, jlong display, jobjectArray names_arr, jboolean only_if_exists, jlong atoms) -{ - int status = 0; - AWT_CHECK_HAVE_LOCK_RETURN(0); - jsize length; - char** names = stringArrayToNative(env, names_arr, &length); - if (names) { - status = XInternAtoms((Display*)jlong_to_ptr(display), names, length, only_if_exists, (Atom*) jlong_to_ptr(atoms)); - freeNativeStringArray(names, length); - } - return status; -} - - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetWindowAttributes - * Signature: (JJJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWindowAttributes -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong attr_ptr) -{ - jint status; - AWT_CHECK_HAVE_LOCK_RETURN(0); - memset((XWindowAttributes*) jlong_to_ptr(attr_ptr), 0, sizeof(XWindowAttributes)); - status = XGetWindowAttributes((Display*)jlong_to_ptr(display), window, (XWindowAttributes*) jlong_to_ptr(attr_ptr)); - return status; -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetGeometry - * Signature: (JJJJJJJJJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetGeometry -(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong root_return, - jlong x_return, jlong y_return, jlong width_return, jlong height_return, - jlong border_width_return, jlong depth_return) -{ - jint status; - AWT_CHECK_HAVE_LOCK_RETURN(0); - status = XGetGeometry((Display *)jlong_to_ptr(display), - (Drawable)drawable, (Window *)jlong_to_ptr(root_return), - (int *)jlong_to_ptr(x_return), (int *)jlong_to_ptr(y_return), - (unsigned int *)jlong_to_ptr(width_return), (unsigned int *)jlong_to_ptr(height_return), - (unsigned int *)jlong_to_ptr(border_width_return), - (unsigned int *)jlong_to_ptr(depth_return)); - return status; -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetWMNormalHints - * Signature: (JJJJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XGetWMNormalHints -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints, jlong supplied_return) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XGetWMNormalHints((Display*) jlong_to_ptr(display), - window, - (XSizeHints*) jlong_to_ptr(hints), - (long*) jlong_to_ptr(supplied_return)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetWMNormalHints - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetWMNormalHints -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong hints) -{ - AWT_CHECK_HAVE_LOCK(); - XSetWMNormalHints((Display*) jlong_to_ptr(display), window, (XSizeHints*) jlong_to_ptr(hints)); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XDeleteProperty - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XDeleteProperty -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom) -{ - AWT_CHECK_HAVE_LOCK(); - XDeleteProperty((Display*) jlong_to_ptr(display), window, (Atom)atom); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSendEvent - * Signature: (JJZJJ)V - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XSendEvent -(JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean propagate, jlong event_mask, jlong event) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XSendEvent((Display*) jlong_to_ptr(display), - window, - propagate==JNI_TRUE?True:False, - (long) event_mask, - (XEvent*) jlong_to_ptr(event)); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XQueryTree - * Signature: (JJJJJJ)I - */ -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XQueryTree -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong root_return, jlong parent_return, jlong children_return, jlong nchildren_return) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XQueryTree((Display*) jlong_to_ptr(display), - window, - (Window *) jlong_to_ptr(root_return), - (Window*) jlong_to_ptr(parent_return), - (Window**) jlong_to_ptr(children_return), - (unsigned int*) jlong_to_ptr(nchildren_return)); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: memcpy - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_memcpy -(JNIEnv *env, jclass clazz, jlong dest_ptr, jlong src_ptr, jlong length) -{ - memcpy(jlong_to_ptr(dest_ptr), jlong_to_ptr(src_ptr), length); -} - - -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetMinMaxHints -(JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y, jint width, jint height, jlong flags) { - XSizeHints * hints; - AWT_CHECK_HAVE_LOCK(); - hints = XAllocSizeHints(); - hints->flags = flags; - hints->width = width; - hints->min_width = width; - hints->max_width = width; - hints->height = height; - hints->min_height = height; - hints->max_height = height; - hints->x = x; - hints->y = y; - XSetWMNormalHints((Display*) jlong_to_ptr(display), window, hints); - XFree(hints); -} - - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XGetVisualInfo -(JNIEnv *env, jclass clazz, jlong display, jlong vinfo_mask, jlong vinfo_template, - jlong nitems_return) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XGetVisualInfo((Display*) jlong_to_ptr(display), - (long) vinfo_mask, - (XVisualInfo*) jlong_to_ptr(vinfo_template), - (int*) jlong_to_ptr(nitems_return))); -} - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XAllocSizeHints - (JNIEnv *env, jclass clazz) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XAllocSizeHints()); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XIconifyWindow - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XBell -(JNIEnv *env, jclass clazz, jlong display, jint percent) -{ - AWT_CHECK_HAVE_LOCK(); - XBell((Display*)jlong_to_ptr(display), percent); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XAllocColor - * Signature: (JJJ)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XAllocColor -(JNIEnv *env, jclass clazz, jlong display , jlong colormap, jlong xcolor) { - - Status status; - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - status = XAllocColor((Display *) jlong_to_ptr(display), (Colormap) colormap, (XColor *) jlong_to_ptr(xcolor)); - - if (status == 0) return JNI_FALSE; - else return JNI_TRUE; -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XCreateBitmapFromData - * Signature: (JJJII)J - */ -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XCreateBitmapFromData -(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong data, jint width, jint height) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - - return (jlong) XCreateBitmapFromData((Display *) jlong_to_ptr(display), (Drawable) drawable, - (char *) jlong_to_ptr(data), width, height); -} - - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XFreePixmap - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XFreePixmap -(JNIEnv *env, jclass clazz, jlong display, jlong pixmap) { - AWT_CHECK_HAVE_LOCK(); - XFreePixmap((Display *)jlong_to_ptr(display), (Pixmap) pixmap); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XReparentWindow - * Signature: (JJJII)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XReparentWindow -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong parent, jint x, jint y) { - AWT_CHECK_HAVE_LOCK(); - XReparentWindow((Display*)jlong_to_ptr(display), window, parent, x, y); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XConvertSelection - * Signature: (JJJJJJ)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XConvertSelection(JNIEnv *env, jclass clazz, - jlong display, jlong selection, - jlong target, jlong property, - jlong requestor, jlong time) { - AWT_CHECK_HAVE_LOCK(); - XConvertSelection((Display*)jlong_to_ptr(display), selection, target, property, requestor, - time); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XSetSelectionOwner - * Signature: (JJJJ)V - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XSetSelectionOwner(JNIEnv *env, jclass clazz, - jlong display, jlong selection, - jlong owner, jlong time) { - AWT_CHECK_HAVE_LOCK(); - XSetSelectionOwner((Display*)jlong_to_ptr(display), selection, owner, time); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetSelectionOwner - * Signature: (JJ)J - */ -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XGetSelectionOwner(JNIEnv *env, jclass clazz, - jlong display, jlong selection) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return (jlong)XGetSelectionOwner((Display*)jlong_to_ptr(display), selection); -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XGetAtomName - * Signature: (JJ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_sun_awt_X11_XlibWrapper_XGetAtomName(JNIEnv *env, jclass clazz, - jlong display, jlong atom) -{ - jstring string = NULL; - char* name; - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - name = (char*) XGetAtomName((Display*)jlong_to_ptr(display), atom); - - if (name == NULL) { - fprintf(stderr, "Atom was %d\n", (int)atom); - JNU_ThrowNullPointerException(env, "Failed to retrieve atom name."); - return NULL; - } - - string = (*env)->NewStringUTF(env, (const char *)name); - - XFree(name); - - return string; -} - -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XMaxRequestSize - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XMaxRequestSize(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XMaxRequestSize((Display*) jlong_to_ptr(display)); -} - -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XAllocWMHints(JNIEnv *env, jclass clazz) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XAllocWMHints()); -} - -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XCreatePixmap(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jint width, jint height, jint depth) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XCreatePixmap((Display*)jlong_to_ptr(display), (Drawable)drawable, width, height, depth); -} -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XCreateImage - (JNIEnv *env, jclass clazz, jlong display, jlong visual_ptr, - jint depth, jint format, jint offset, jlong data, jint width, - jint height, jint bitmap_pad, jint bytes_per_line) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XCreateImage((Display*) jlong_to_ptr(display), (Visual*) jlong_to_ptr(visual_ptr), - depth, format, offset, (char*) jlong_to_ptr(data), - width, height, bitmap_pad, bytes_per_line)); -} -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XCreateGC - (JNIEnv *env, jclass clazz, jlong display, jlong drawable, - jlong valuemask, jlong values) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XCreateGC((Display*) jlong_to_ptr(display), (Drawable)drawable, valuemask, (XGCValues*) jlong_to_ptr(values))); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XDestroyImage(JNIEnv *env, jclass clazz, jlong image) -{ - XImage *img = (XImage*) jlong_to_ptr(image); - AWT_CHECK_HAVE_LOCK(); - - // Fix for bug 4903671 : - // We should be careful to not double free the memory pointed to data - // Since we use unsafe to allocate it, we should use unsafe to free it. - // So we should NULL the data pointer before calling XDestroyImage so - // that X does not free the pointer for us. - img->data = NULL; - XDestroyImage(img); -} -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XPutImage(JNIEnv *env, jclass clazz, jlong display, jlong drawable, jlong gc, jlong image, jint src_x, jint src_y, jint dest_x, jint dest_y, jint width, jint height) -{ - AWT_CHECK_HAVE_LOCK(); - XPutImage((Display*)jlong_to_ptr(display), (Drawable)drawable, (GC) jlong_to_ptr(gc), (XImage*) jlong_to_ptr(image), src_x, src_y, - dest_x, dest_y, width, height); -} -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XFreeGC(JNIEnv *env, jclass clazz, jlong display, jlong gc) -{ - AWT_CHECK_HAVE_LOCK(); - XFreeGC((Display*) jlong_to_ptr(display), (GC) jlong_to_ptr(gc)); -} -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XSetWindowBackgroundPixmap(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong pixmap) -{ - AWT_CHECK_HAVE_LOCK(); - XSetWindowBackgroundPixmap((Display*) jlong_to_ptr(display), (Window)window, (Pixmap)pixmap); -} -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XClearWindow(JNIEnv *env, jclass clazz, jlong display, jlong window) -{ - AWT_CHECK_HAVE_LOCK(); - XClearWindow((Display*) jlong_to_ptr(display), (Window)window); -} - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XlibWrapper_XGetIconSizes(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong ret_sizes, jlong ret_count) -{ - XIconSize** psize = (XIconSize**) jlong_to_ptr(ret_sizes); - int * pcount = (int *) jlong_to_ptr(ret_count); - Status res; - AWT_CHECK_HAVE_LOCK_RETURN(0); - res = XGetIconSizes((Display*) jlong_to_ptr(display), (Window)window, psize, pcount); - return res; -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeQueryExtension - (JNIEnv *env, jclass clazz, jlong display, jlong major_version_return, - jlong minor_version_return) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeQueryExtension((Display*) jlong_to_ptr(display), (int *) jlong_to_ptr(major_version_return), - (int *) jlong_to_ptr(minor_version_return)); -} - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_XQueryExtension - (JNIEnv *env, jclass clazz, jlong display, jstring jstr, jlong mop_return, - jlong feve_return, jlong err_return) -{ - char *cname; - Boolean bu; - if (!JNU_IsNull(env, jstr)) { - cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); - CHECK_NULL_RETURN(cname, JNI_FALSE); - } else { - cname = ""; - } - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - bu = XQueryExtension((Display*) jlong_to_ptr(display), cname, (int *) jlong_to_ptr(mop_return), - (int *) jlong_to_ptr(feve_return), (int *) jlong_to_ptr(err_return)); - if (!JNU_IsNull(env, jstr)) { - JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); - } - return bu ? JNI_TRUE : JNI_FALSE; -} - -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKeypadKey - (JNIEnv *env, jclass clazz, jlong keysym) -{ - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - if(IsKeypadKey(keysym)) { - return JNI_TRUE; - } - return JNI_FALSE; -} - -JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XdbeAllocateBackBufferName - (JNIEnv *env, jclass clazz, jlong display, jlong window, jint swap_action) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeAllocateBackBufferName((Display*) jlong_to_ptr(display), (Window) window, - (XdbeSwapAction) swap_action); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeDeallocateBackBufferName - (JNIEnv *env, jclass clazz, jlong display, jlong buffer) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeDeallocateBackBufferName((Display*) jlong_to_ptr(display), (XdbeBackBuffer) buffer); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeBeginIdiom - (JNIEnv *env, jclass clazz, jlong display) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeBeginIdiom((Display*) jlong_to_ptr(display)); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeEndIdiom - (JNIEnv *env, jclass clazz, jlong display) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeEndIdiom((Display*) jlong_to_ptr(display)); -} - -JNIEXPORT jint JNICALL Java_sun_awt_X11_XlibWrapper_XdbeSwapBuffers - (JNIEnv *env, jclass clazz, jlong display, jlong swap_info, jint num_windows) -{ - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XdbeSwapBuffers((Display*) jlong_to_ptr(display), (XdbeSwapInfo *) jlong_to_ptr(swap_info), num_windows); -} -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XQueryKeymap -(JNIEnv *env, jclass clazz, jlong display, jlong vector) -{ - - AWT_CHECK_HAVE_LOCK(); - XQueryKeymap( (Display *) jlong_to_ptr(display), (char *) jlong_to_ptr(vector)); -} - -// XKeycodeToKeysym is deprecated but for compatibility we keep the API. -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz, - jlong display, jint keycode, - jint index) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return keycodeToKeysym((Display*)jlong_to_ptr(display), (unsigned int)keycode, (int)index); -} - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XlibWrapper_XkbGetEffectiveGroup(JNIEnv *env, jclass clazz, - jlong display) { - XkbStateRec sr; - AWT_CHECK_HAVE_LOCK_RETURN(0); - memset(&sr, 0, sizeof(XkbStateRec)); - XkbGetState((Display*) jlong_to_ptr(display), XkbUseCoreKbd, &sr); -// printf("-------------------------------------VVVV\n"); -// printf(" group:0x%0X\n",sr.group); -// printf(" base_group:0x%0X\n",sr.base_group); -// printf(" latched_group:0x%0X\n",sr.latched_group); -// printf(" locked_group:0x%0X\n",sr.locked_group); -// printf(" mods:0x%0X\n",sr.mods); -// printf(" base_mods:0x%0X\n",sr.base_mods); -// printf(" latched_mods:0x%0X\n",sr.latched_mods); -// printf(" locked_mods:0x%0X\n",sr.locked_mods); -// printf(" compat_state:0x%0X\n",sr.compat_state); -// printf(" grab_mods:0x%0X\n",sr.grab_mods); -// printf(" compat_grab_mods:0x%0X\n",sr.compat_grab_mods); -// printf(" lookup_mods:0x%0X\n",sr.lookup_mods); -// printf(" compat_lookup_mods:0x%0X\n",sr.compat_lookup_mods); -// printf(" ptr_buttons:0x%0X\n",sr.ptr_buttons); -// printf("-------------------------------------^^^^\n"); - return (jint)(sr.group); -} -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XkbKeycodeToKeysym(JNIEnv *env, jclass clazz, - jlong display, jint keycode, - jint group, jint level) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XkbKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (unsigned int)group, (unsigned int)level); -} - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XlibWrapper_XKeysymToKeycode(JNIEnv *env, jclass clazz, - jlong display, jlong keysym) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return XKeysymToKeycode((Display*) jlong_to_ptr(display), (KeySym)keysym); -} - -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_XGetModifierMapping(JNIEnv *env, jclass clazz, - jlong display) { - AWT_CHECK_HAVE_LOCK_RETURN(0); - return ptr_to_jlong(XGetModifierMapping((Display*) jlong_to_ptr(display))); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XFreeModifiermap(JNIEnv *env, jclass clazz, - jlong keymap) { - AWT_CHECK_HAVE_LOCK(); - XFreeModifiermap((XModifierKeymap*) jlong_to_ptr(keymap)); -} -/* - * Class: sun_awt_X11_XlibWrapper - * Method: XRefreshKeyboardMapping - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XRefreshKeyboardMapping -(JNIEnv *env, jclass clazz, jlong event_ptr) -{ - AWT_CHECK_HAVE_LOCK(); - XRefreshKeyboardMapping((XMappingEvent*) jlong_to_ptr(event_ptr)); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XChangeActivePointerGrab(JNIEnv *env, jclass clazz, - jlong display, jint mask, - jlong cursor, jlong time) { - AWT_CHECK_HAVE_LOCK(); - XChangeActivePointerGrab((Display*)jlong_to_ptr(display), (unsigned int)mask, - (Cursor)cursor, (Time)time); -} - -/******************* Secondary loop support ************************************/ -#define AWT_SECONDARY_LOOP_TIMEOUT 250 - -static Bool exitSecondaryLoop = True; - -/* - * This predicate procedure allows the Toolkit thread to process specific events - * while it is blocked waiting for the event dispatch thread to process - * a SunDropTargetEvent. We need this to prevent deadlock when the client code - * processing SunDropTargetEvent sets or gets the contents of the system - * clipboard/selection. In this case the event dispatch thread waits for the - * Toolkit thread to process PropertyNotify or SelectionNotify events. - */ -static Bool -secondary_loop_event(Display* dpy, XEvent* event, XPointer xawt_root_window) { - return ( - event->type == SelectionNotify || - event->type == SelectionClear || - event->type == PropertyNotify || - (event->type == ConfigureNotify - && event->xany.window == *(Window*) xawt_root_window) - ) ? True : False; -} - - -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11_XlibWrapper_XNextSecondaryLoopEvent(JNIEnv *env, jclass clazz, - jlong display, jlong ptr) { - uint32_t timeout = 1; - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - exitSecondaryLoop = False; - Window xawt_root_window = get_xawt_root_shell(env); - - while (!exitSecondaryLoop) { - if (XCheckIfEvent((Display*) jlong_to_ptr(display), - (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, (XPointer) &xawt_root_window)) { - return JNI_TRUE; - } - timeout = (timeout < AWT_SECONDARY_LOOP_TIMEOUT) ? (timeout << 1) : AWT_SECONDARY_LOOP_TIMEOUT; - AWT_WAIT(timeout); - } - return JNI_FALSE; -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_ExitSecondaryLoop(JNIEnv *env, jclass clazz) { - DASSERT(!exitSecondaryLoop); - AWT_CHECK_HAVE_LOCK(); - exitSecondaryLoop = True; - AWT_NOTIFY_ALL(); -} -/*******************************************************************************/ - -JNIEXPORT jobjectArray JNICALL -Java_sun_awt_X11_XlibWrapper_XTextPropertyToStringList(JNIEnv *env, - jclass clazz, - jbyteArray bytes, - jlong encodingAtom) { - XTextProperty tp; - jbyte *value; - - char** strings = (char **)NULL; - int32_t nstrings = 0; - jobjectArray ret = NULL; - int32_t i; - jsize len; - jboolean isCopy = JNI_FALSE; - static jclass stringClass = NULL; - jclass stringClassLocal = NULL; - - AWT_CHECK_HAVE_LOCK_RETURN(NULL); - - if (JNU_IsNull(env, stringClass)) { - stringClassLocal = (*env)->FindClass(env, "java/lang/String"); - - if ((*env)->ExceptionCheck(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - DASSERT(False); - } - - if (JNU_IsNull(env, stringClassLocal)) { - return NULL; - } - - stringClass = (*env)->NewGlobalRef(env, stringClassLocal); /* never freed! */ - (*env)->DeleteLocalRef(env, stringClassLocal); - - if (JNU_IsNull(env, stringClass)) { - JNU_ThrowOutOfMemoryError(env, ""); - return NULL; - } - } - - /* - * If the length of the byte array is 0 just return a null - */ - len = (*env)->GetArrayLength(env, bytes); - if (len == 0) { - return (*env)->NewObjectArray(env, 0, stringClass, NULL); - } - - value = (*env)->GetByteArrayElements(env, bytes, &isCopy); - if (JNU_IsNull(env, value)) { - return NULL; - } - - tp.encoding = encodingAtom; - tp.value = (unsigned char *)value; - tp.nitems = len; - tp.format = 8; - - /* - * Convert the byte stream into a list of X11 strings - */ - if (XTextPropertyToStringList(&tp, &strings, &nstrings) == 0) { - (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); - return NULL; - } - - (*env)->ReleaseByteArrayElements(env, bytes, value, JNI_ABORT); - - if (nstrings == 0) { - return (*env)->NewObjectArray(env, 0, stringClass, NULL); - } - - ret = (*env)->NewObjectArray(env, nstrings, stringClass, NULL); - - if ((*env)->ExceptionCheck(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - goto wayout; - } - - if (JNU_IsNull(env, ret)) { - goto wayout; - } - - for (i = 0; i < nstrings; i++) { - jstring string = (*env)->NewStringUTF(env, - (const char *)strings[i]); - if ((*env)->ExceptionCheck(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - goto wayout; - } - - if (JNU_IsNull(env, string)) { - goto wayout; - } - - (*env)->SetObjectArrayElement(env, ret, i, string); - - if ((*env)->ExceptionCheck(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - goto wayout; - } - - (*env)->DeleteLocalRef(env, string); - } - - wayout: - /* - * Clean up and return - */ - XFreeStringList(strings); - return ret; -} - - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_XPutBackEvent(JNIEnv *env, - jclass clazz, - jlong display, - jlong event) { - XPutBackEvent((Display*)jlong_to_ptr(display), (XEvent*) jlong_to_ptr(event)); -} - -JNIEXPORT jlong JNICALL -Java_sun_awt_X11_XlibWrapper_getAddress(JNIEnv *env, - jclass clazz, - jobject o) { - return ptr_to_jlong(o); -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_copyIntArray(JNIEnv *env, - jclass clazz, - jlong dest, jobject array, jint size) { - jboolean isCopy = JNI_FALSE; - jint * ints = (*env)->GetIntArrayElements(env, array, &isCopy); - memcpy(jlong_to_ptr(dest), ints, size); - if (isCopy) { - (*env)->ReleaseIntArrayElements(env, array, ints, JNI_ABORT); - } -} - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_copyLongArray(JNIEnv *env, - jclass clazz, - jlong dest, jobject array, jint size) { - jboolean isCopy = JNI_FALSE; - jlong * longs = (*env)->GetLongArrayElements(env, array, &isCopy); - memcpy(jlong_to_ptr(dest), longs, size); - if (isCopy) { - (*env)->ReleaseLongArrayElements(env, array, longs, JNI_ABORT); - } -} - -JNIEXPORT jint JNICALL -Java_sun_awt_X11_XlibWrapper_XSynchronize(JNIEnv *env, jclass clazz, jlong display, jboolean onoff) -{ - return (jint) XSynchronize((Display*)jlong_to_ptr(display), (onoff == JNI_TRUE ? True : False)); -} - -JNIEXPORT jboolean JNICALL -Java_sun_awt_X11_XlibWrapper_XShapeQueryExtension -(JNIEnv *env, jclass clazz, jlong display, jlong event_base_return, jlong error_base_return) -{ - Bool status; - - AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE); - - status = XShapeQueryExtension((Display *)jlong_to_ptr(display), - (int *)jlong_to_ptr(event_base_return), (int *)jlong_to_ptr(error_base_return)); - return status ? JNI_TRUE : JNI_FALSE; -} - -/* - * Class: XlibWrapper - * Method: SetRectangularShape - */ - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_SetRectangularShape -(JNIEnv *env, jclass clazz, jlong display, jlong window, - jint x1, jint y1, jint x2, jint y2, - jobject region) -{ - AWT_CHECK_HAVE_LOCK(); - - // If all the params are zeros, the shape must be simply reset. - // Otherwise, the shape may be not rectangular. - if (region || x1 || x2 || y1 || y2) { - XRectangle rects[256]; - XRectangle *pRect = rects; - - int numrects = RegionToYXBandedRectangles(env, x1, y1, x2, y2, region, - &pRect, 256); - - XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeClip, 0, 0, pRect, numrects, ShapeSet, YXBanded); - XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeBounding, 0, 0, pRect, numrects, ShapeSet, YXBanded); - - if (pRect != rects) { - free(pRect); - } - } else { - // Reset the shape to a rectangular form. - XShapeCombineMask((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeClip, 0, 0, None, ShapeSet); - XShapeCombineMask((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeBounding, 0, 0, None, ShapeSet); - } -} - -/* - * Class: XlibWrapper - * Method: SetZOrder - */ - -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_SetZOrder -(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong above) -{ - unsigned int value_mask = CWStackMode; - - XWindowChanges wc; - wc.sibling = (Window)jlong_to_ptr(above); - - AWT_CHECK_HAVE_LOCK(); - - if (above == 0) { - wc.stack_mode = Above; - } else { - wc.stack_mode = Below; - value_mask |= CWSibling; - } - - XConfigureWindow((Display *)jlong_to_ptr(display), - (Window)jlong_to_ptr(window), - value_mask, &wc ); -} - -/* - * Class: XlibWrapper - * Method: SetBitmapShape - */ -JNIEXPORT void JNICALL -Java_sun_awt_X11_XlibWrapper_SetBitmapShape -(JNIEnv *env, jclass clazz, jlong display, jlong window, - jint width, jint height, jintArray bitmap) -{ - jsize len; - jint *values; - jboolean isCopy = JNI_FALSE; - size_t worstBufferSize = (size_t)((width / 2 + 1) * height); - RECT_T * pRect; - int numrects; - - if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) { - return; - } - - AWT_CHECK_HAVE_LOCK(); - - len = (*env)->GetArrayLength(env, bitmap); - if (len == 0 || len < width * height) { - return; - } - - values = (*env)->GetIntArrayElements(env, bitmap, &isCopy); - if (JNU_IsNull(env, values)) { - return; - } - - pRect = (RECT_T *)SAFE_SIZE_ARRAY_ALLOC(malloc, worstBufferSize, sizeof(RECT_T)); - if (!pRect) { - return; - } - - /* Note: the values[0] and values[1] are supposed to contain the width - * and height (see XIconInfo.getIntData() for details). So, we do +2. - */ - numrects = BitmapToYXBandedRectangles(32, (int)width, (int)height, - (unsigned char *)(values + 2), pRect); - - XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeClip, 0, 0, pRect, numrects, ShapeSet, YXBanded); - XShapeCombineRectangles((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window), - ShapeBounding, 0, 0, pRect, numrects, ShapeSet, YXBanded); - - free(pRect); - - (*env)->ReleaseIntArrayElements(env, bitmap, values, JNI_ABORT); -} diff --git a/app/src/main/jni/awt_xawt/xawt/awt_Desktop.c b/app/src/main/jni/awt_xawt/xawt/awt_Desktop.c deleted file mode 100644 index 96acfb59d..000000000 --- a/app/src/main/jni/awt_xawt/xawt/awt_Desktop.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2005, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "jni_util.h" -#include "gtk_interface.h" -#include "gnome_interface.h" - -static gboolean gtk_has_been_loaded = FALSE; -static gboolean gnome_has_been_loaded = FALSE; - -/* - * Class: sun_awt_X11_XDesktopPeer - * Method: init - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init - (JNIEnv *env, jclass cls, jint version, jboolean verbose) -{ - - if (gtk_has_been_loaded || gnome_has_been_loaded) { - return JNI_TRUE; - } - - if (gtk_load(env, version, verbose) && gtk->show_uri_load(env)) { - gtk_has_been_loaded = TRUE; - return JNI_TRUE; - } else if (gnome_load()) { - gnome_has_been_loaded = TRUE; - return JNI_TRUE; - } - - return JNI_FALSE; -} - -/* - * Class: sun_awt_X11_XDesktopPeer - * Method: gnome_url_show - * Signature: (Ljava/lang/[B;)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show - (JNIEnv *env, jobject obj, jbyteArray url_j) -{ - gboolean success = FALSE; - const gchar* url_c; - - url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL); - if (url_c == NULL) { - if (!(*env)->ExceptionCheck(env)) { - JNU_ThrowOutOfMemoryError(env, 0); - } - return JNI_FALSE; - } - - if (gtk_has_been_loaded) { - gtk->gdk_threads_enter(); - success = gtk->gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL); - gtk->gdk_threads_leave(); - } else if (gnome_has_been_loaded) { - success = (*gnome_url_show)(url_c, NULL); - } - - (*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0); - - return success ? JNI_TRUE : JNI_FALSE; -} diff --git a/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.c b/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.c deleted file mode 100644 index 9b415476f..000000000 --- a/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jvm_md.h" -#include -#include - -#include "jni_util.h" -#include "awt_Taskbar.h" - - -extern JavaVM *jvm; - -#define NO_SYMBOL_EXCEPTION 1 - -#define UNITY_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("unity", "9") -#define UNITY_LIB JNI_LIB_NAME("unity") - -static jmp_buf j; - -static void *unity_libhandle = NULL; - -static DbusmenuMenuitem* menu = NULL; -UnityLauncherEntry* entry = NULL; - -static jclass jTaskbarCls = NULL; -static jmethodID jTaskbarCallback = NULL; -static jmethodID jMenuItemGetLabel = NULL; - -GList* globalRefs = NULL; - -static void* dl_symbol(const char* name) { - void* result = dlsym(unity_libhandle, name); - if (!result) - longjmp(j, NO_SYMBOL_EXCEPTION); - - return result; -} - -static gboolean unity_load() { - unity_libhandle = dlopen(UNITY_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL); - if (unity_libhandle == NULL) { - unity_libhandle = dlopen(UNITY_LIB, RTLD_LAZY | RTLD_LOCAL); - if (unity_libhandle == NULL) { - return FALSE; - } - } - if (setjmp(j) == 0) { - fp_unity_launcher_entry_get_for_desktop_file = dl_symbol("unity_launcher_entry_get_for_desktop_file"); - fp_unity_launcher_entry_set_count = dl_symbol("unity_launcher_entry_set_count"); - fp_unity_launcher_entry_set_count_visible = dl_symbol("unity_launcher_entry_set_count_visible"); - fp_unity_launcher_entry_set_urgent = dl_symbol("unity_launcher_entry_set_urgent"); - fp_unity_launcher_entry_set_progress = dl_symbol("unity_launcher_entry_set_progress"); - fp_unity_launcher_entry_set_progress_visible = dl_symbol("unity_launcher_entry_set_progress_visible"); - - fp_dbusmenu_menuitem_new = dl_symbol("dbusmenu_menuitem_new"); - fp_dbusmenu_menuitem_property_set = dl_symbol("dbusmenu_menuitem_property_set"); - fp_dbusmenu_menuitem_property_set_int = dl_symbol("dbusmenu_menuitem_property_set_int"); - fp_dbusmenu_menuitem_property_get_int = dl_symbol("dbusmenu_menuitem_property_get_int"); - fp_dbusmenu_menuitem_property_set = dl_symbol("dbusmenu_menuitem_property_set"); - fp_dbusmenu_menuitem_child_append = dl_symbol("dbusmenu_menuitem_child_append"); - fp_dbusmenu_menuitem_child_delete = dl_symbol("dbusmenu_menuitem_child_delete"); - fp_dbusmenu_menuitem_take_children = dl_symbol("dbusmenu_menuitem_take_children"); - fp_dbusmenu_menuitem_foreach = dl_symbol("dbusmenu_menuitem_foreach"); - fp_unity_launcher_entry_set_quicklist = dl_symbol("unity_launcher_entry_set_quicklist"); - fp_unity_launcher_entry_get_quicklist = dl_symbol("unity_launcher_entry_get_quicklist"); - } else { - dlclose(unity_libhandle); - unity_libhandle = NULL; - return FALSE; - } - return TRUE; -} - -void callback(DbusmenuMenuitem* mi, guint ts, jobject data) { - JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2); - (*env)->CallStaticVoidMethod(env, jTaskbarCls, jTaskbarCallback, data); -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: init - * Signature: (Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XTaskbarPeer_init -(JNIEnv *env, jclass cls, jstring jname, jint version, jboolean verbose) { - jclass clazz; - - jTaskbarCls = (*env)->NewGlobalRef(env, cls); - - CHECK_NULL_RETURN(jTaskbarCallback = - (*env)->GetStaticMethodID(env, cls, "menuItemCallback", "(Ljava/awt/MenuItem;)V"), JNI_FALSE); - CHECK_NULL_RETURN( - clazz = (*env)->FindClass(env, "java/awt/MenuItem"), JNI_FALSE); - CHECK_NULL_RETURN( - jMenuItemGetLabel = (*env)->GetMethodID(env, clazz, "getLabel", "()Ljava/lang/String;"), JNI_FALSE); - - if (gtk_load(env, version, verbose) && unity_load()) { - const gchar* name = (*env)->GetStringUTFChars(env, jname, NULL); - if (name) { - entry = fp_unity_launcher_entry_get_for_desktop_file(name); - (*env)->ReleaseStringUTFChars(env, jname, name); - return JNI_TRUE; - } - } - return JNI_FALSE; -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: runloop - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_runloop -(JNIEnv *env, jclass cls) { - gtk->gdk_threads_enter(); - gtk->gtk_main(); - gtk->gdk_threads_leave(); -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: setBadge - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setBadge -(JNIEnv *env, jobject obj, jlong value, jboolean visible) { - gtk->gdk_threads_enter(); - fp_unity_launcher_entry_set_count(entry, value); - fp_unity_launcher_entry_set_count_visible(entry, visible); - DbusmenuMenuitem* m; - if (m = fp_unity_launcher_entry_get_quicklist(entry)) { - fp_unity_launcher_entry_set_quicklist(entry, m); - } - gtk->gdk_threads_leave(); -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: setUrgent - * Signature: (Z)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setUrgent -(JNIEnv *env, jobject obj, jboolean urgent) { - gtk->gdk_threads_enter(); - fp_unity_launcher_entry_set_urgent(entry, urgent); - DbusmenuMenuitem* m; - if (m = fp_unity_launcher_entry_get_quicklist(entry)) { - fp_unity_launcher_entry_set_quicklist(entry, m); - } - gtk->gdk_threads_leave(); -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: updateProgress - * Signature: (DZ)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_updateProgress -(JNIEnv *env, jobject obj, jdouble value, jboolean visible) { - gtk->gdk_threads_enter(); - fp_unity_launcher_entry_set_progress(entry, value); - fp_unity_launcher_entry_set_progress_visible(entry, visible); - DbusmenuMenuitem* m; - if (m = fp_unity_launcher_entry_get_quicklist(entry)) { - fp_unity_launcher_entry_set_quicklist(entry, m); - } - gtk->gdk_threads_leave(); -} - -void deleteGlobalRef(gpointer data) { - JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2); - (*env)->DeleteGlobalRef(env, data); -} - -void fill_menu(JNIEnv *env, jobjectArray items) { - int index; - jsize length = (*env)->GetArrayLength(env, items); - for (index = 0; index < length; index++) { - jobject elem = (*env)->GetObjectArrayElement(env, items, index); - if ((*env)->ExceptionCheck(env)) { - break; - } - elem = (*env)->NewGlobalRef(env, elem); - - globalRefs = gtk->g_list_append(globalRefs, elem); - - jstring jlabel = (jstring) (*env)->CallObjectMethod(env, elem, jMenuItemGetLabel); - if (!(*env)->ExceptionCheck(env) && jlabel) { - const gchar* label = (*env)->GetStringUTFChars(env, jlabel, NULL); - if (label) { - DbusmenuMenuitem* mi = fp_dbusmenu_menuitem_new(); - if (!strcmp(label, "-")) { - fp_dbusmenu_menuitem_property_set(mi, "type", "separator"); - } else { - fp_dbusmenu_menuitem_property_set(mi, "label", label); - } - - (*env)->ReleaseStringUTFChars(env, jlabel, label); - fp_dbusmenu_menuitem_child_append(menu, mi); - gtk->g_signal_connect_data(mi, "item_activated", - G_CALLBACK(callback), elem, NULL, 0); - } - } - } -} - -/* - * Class: sun_awt_X11_XTaskbarPeer - * Method: setNativeMenu - * Signature: ([Ljava/awt/MenuItem;)V - */ -JNIEXPORT void JNICALL Java_sun_awt_X11_XTaskbarPeer_setNativeMenu -(JNIEnv *env, jobject obj, jobjectArray items) { - - gtk->gdk_threads_enter(); - - if (!menu) { - menu = fp_dbusmenu_menuitem_new(); - fp_unity_launcher_entry_set_quicklist(entry, menu); - } - - GList* list = fp_dbusmenu_menuitem_take_children(menu); - gtk->g_list_free_full(list, gtk->g_object_unref); - - gtk->g_list_free_full(globalRefs, deleteGlobalRef); - globalRefs = NULL; - - if (items) { - fill_menu(env, items); - } - - gtk->gdk_threads_leave(); -} diff --git a/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.h b/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.h deleted file mode 100644 index 0a574615d..000000000 --- a/app/src/main/jni/awt_xawt/xawt/awt_Taskbar.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifndef AWT_TASKBAR_H -#define AWT_TASKBAR_H - -#include "gtk_interface.h" - -typedef void UnityLauncherEntry; -typedef void DbusmenuMenuitem; - -static UnityLauncherEntry* (*fp_unity_launcher_entry_get_for_desktop_file) (const gchar* desktop_file); - -static void (*fp_unity_launcher_entry_set_count) (UnityLauncherEntry* self, gint64 value); -static void (*fp_unity_launcher_entry_set_count_visible) (UnityLauncherEntry* self, gboolean value); - -static void (*fp_unity_launcher_entry_set_urgent) (UnityLauncherEntry* self, gboolean value); - -static void (*fp_unity_launcher_entry_set_progress) (UnityLauncherEntry* self, gdouble value); -static void (*fp_unity_launcher_entry_set_progress_visible) (UnityLauncherEntry* self, gboolean value); - - -static DbusmenuMenuitem* (*fp_dbusmenu_menuitem_new) (void); -static gboolean (*fp_dbusmenu_menuitem_property_set) (DbusmenuMenuitem* mi, const gchar* property, const gchar* value); -static gboolean (*fp_dbusmenu_menuitem_property_set_int) (DbusmenuMenuitem * mi, const gchar * property, const gint value); -static gint (*fp_dbusmenu_menuitem_property_get_int) (const DbusmenuMenuitem * mi, const gchar * property); -static gboolean (*fp_dbusmenu_menuitem_child_append) (DbusmenuMenuitem* mi, DbusmenuMenuitem* child); -static gboolean (*fp_dbusmenu_menuitem_child_delete) (DbusmenuMenuitem * mi, DbusmenuMenuitem * child); -static GList * (*fp_dbusmenu_menuitem_take_children) (DbusmenuMenuitem * mi); -static void (*fp_dbusmenu_menuitem_foreach) (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); -static void (*fp_unity_launcher_entry_set_quicklist) (UnityLauncherEntry* self, DbusmenuMenuitem* value); -static DbusmenuMenuitem* (*fp_unity_launcher_entry_get_quicklist) (UnityLauncherEntry* self); - - -#endif /* AWT_TASKBAR_H */ - diff --git a/app/src/main/jni/awt_xawt/xawt/gnome_interface.c b/app/src/main/jni/awt_xawt/xawt/gnome_interface.c deleted file mode 100644 index 46c96e136..000000000 --- a/app/src/main/jni/awt_xawt/xawt/gnome_interface.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2013, 2015, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include "gnome_interface.h" - -GNOME_URL_SHOW_TYPE *gnome_url_show = NULL; - -gboolean gnome_load() { - void *vfs_handle; - void *gnome_handle; - const char *errmsg; - GNOME_VFS_INIT_TYPE *gnome_vfs_init; - - // trying to open the gnomevfs. VERSIONED_JNI_LIB_NAME - // macros formats the library name in a system specific manner - // see jdk/src/solaris/javavm/export/jvm_md.h for more details - vfs_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnomevfs-2", "0"), RTLD_LAZY); - if (vfs_handle == NULL) { - // if we cannot load the library using a version assumed by JNI - // we are trying to load the library without a version suffix - vfs_handle = dlopen(JNI_LIB_NAME("gnomevfs-2"), RTLD_LAZY); - if (vfs_handle == NULL) { - #ifdef DEBUG - fprintf(stderr, "can not load libgnomevfs-2.so\n"); - #endif - return FALSE; - } - } - dlerror(); /* Clear errors */ - gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init"); - if (gnome_vfs_init == NULL){ - #ifdef DEBUG - fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n"); - #endif - return FALSE; - } - if ((errmsg = dlerror()) != NULL) { - #ifdef DEBUG - fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg); - #endif - return FALSE; - } - // call gonme_vfs_init() - (*gnome_vfs_init)(); - - gnome_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnome-2", "0"), RTLD_LAZY); - if (gnome_handle == NULL) { - gnome_handle = dlopen(JNI_LIB_NAME("gnome-2"), RTLD_LAZY); - if (gnome_handle == NULL) { - #ifdef DEBUG - fprintf(stderr, "can not load libgnome-2.so\n"); - #endif - return FALSE; - } - } - dlerror(); /* Clear errors */ - gnome_url_show = (GNOME_URL_SHOW_TYPE*)dlsym(gnome_handle, "gnome_url_show"); - if ((errmsg = dlerror()) != NULL) { - #ifdef DEBUG - fprintf(stderr, "can not find symble gnome_url_show\n"); - #endif - return FALSE; - } - return TRUE; -} diff --git a/app/src/main/jni/awt_xawt/xawt/gnome_interface.h b/app/src/main/jni/awt_xawt/xawt/gnome_interface.h deleted file mode 100644 index 86ea796ba..000000000 --- a/app/src/main/jni/awt_xawt/xawt/gnome_interface.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2013, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#ifndef _GNOME_INTERFACE_H -#define _GNOME_INTERFACE_H -#include "gtk_interface.h" -#include -#include -#include - -typedef gboolean (GNOME_URL_SHOW_TYPE)(const char *, void **); -typedef gboolean (GNOME_VFS_INIT_TYPE)(void); - -extern GNOME_URL_SHOW_TYPE *gnome_url_show; -gboolean gnome_load(); - -#endif /* !_GNOME_INTERFACE_H */ diff --git a/app/src/main/jni/egl_bridge.c b/app/src/main/jni/egl_bridge.c index e9813d152..722e3006f 100644 --- a/app/src/main/jni/egl_bridge.c +++ b/app/src/main/jni/egl_bridge.c @@ -19,9 +19,9 @@ struct PotatoBridge { ANativeWindow* androidWindow; void* androidDisplay; - void* eglContext; - void* eglDisplay; - void* eglSurface; + EGLContext* eglContext; + EGLDisplay eglDisplay; + EGLSurface eglSurface; /* void* eglSurfaceRead; void* eglSurfaceDraw; @@ -98,7 +98,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* eglBindAPI(EGL_OPENGL_ES_API); - potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, EGL_NO_CONTEXT, ctx_attribs); + potatoBridge.eglContext = &eglCreateContext(potatoBridge.eglDisplay, config, EGL_NO_CONTEXT, ctx_attribs); if (!potatoBridge.eglContext) { printf("Error: eglCreateContext failed\n"); return JNI_FALSE; @@ -107,7 +107,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* // test eglQueryContext() { EGLint val; - eglQueryContext(potatoBridge.eglDisplay, potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val); + eglQueryContext(potatoBridge.eglDisplay, *potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val); assert(val == 2); } @@ -133,12 +133,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* */ printf("EGLBridge: Making current\n"); printf("EGLContext=%p, EGLDisplay=%p, EGLSurface=%p\n", - potatoBridge.eglContext, + *potatoBridge.eglContext, potatoBridge.eglDisplay, potatoBridge.eglSurface ); - EGLBoolean success = eglMakeCurrent(potatoBridge.eglDisplay, potatoBridge.eglSurface, potatoBridge.eglSurface, potatoBridge.eglContext); + EGLBoolean success = eglMakeCurrent(potatoBridge.eglDisplay, potatoBridge.eglSurface, potatoBridge.eglSurface, *potatoBridge.eglContext); if (success == EGL_FALSE) { printf("Error: eglMakeCurrent() failed: %p\n", eglGetError()); }