Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/bridge/JAWTAccessBridge.cpp
32287 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* A DLL which is loaded by Java applications and used to map27* between Java applications and native Win32 window handles.28*/2930#include "com_sun_java_accessibility_AccessBridge.h" // programatically generated by JNI3132#include <windows.h>33#include <stdio.h>3435#include <jawt.h>36#include <win32/jawt_md.h>3738// ---------------------------------------------------------------------------3940extern "C" {41/**42* DllMain - where Windows executables will load/unload us43*44*/45BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) {4647return TRUE;48}495051/*52* Map a HWND to a Java component53*54* Class: com_sun_java_accessibility_AccessBridge55* Method: jawtGetComponentFromNativeWindowHandle56* Signature: (I)Ljava/awt/Component;57*/58JNIEXPORT jobject JNICALL59Java_com_sun_java_accessibility_AccessBridge_jawtGetComponentFromNativeWindowHandle60(JNIEnv *env, jobject callingObj, jint windowHandle) {6162JAWT awt;63jboolean result;64jobject component = (jobject)0;6566// Get the AWT67awt.version = JAWT_VERSION_1_4;68result = JAWT_GetAWT(env, &awt);69if (result == JNI_FALSE) {70return (jobject)0;71}7273// Get the component74return awt.GetComponent(env, (void *)windowHandle);75}767778/*79* Map a Java component to a HWND80*81* Class: com_sun_java_accessibility_AccessBridge82* Method: jawtGetNativeWindowHandleFromComponent83* Signature: (Ljava/awt/Component;)I84*/85JNIEXPORT jint JNICALL86Java_com_sun_java_accessibility_AccessBridge_jawtGetNativeWindowHandleFromComponent87(JNIEnv *env, jobject callingObj, jobject component)88{8990JAWT awt;91JAWT_DrawingSurface* ds;92JAWT_DrawingSurfaceInfo* dsi;93JAWT_Win32DrawingSurfaceInfo* dsi_win;94jboolean result;95// jint lock;96jint windowHandle = -1;9798// Get the AWT99awt.version = JAWT_VERSION_1_4;100result = JAWT_GetAWT(env, &awt);101if (result == JNI_FALSE) {102return -1;103}104105// Get the drawing surface106ds = awt.GetDrawingSurface(env, component);107if (ds == NULL) {108return -1;109}110111/*112* Should not be necessary.113*114// Lock the drawing surface115lock = ds->Lock(ds);116if ((lock & JAWT_LOCK_ERROR) != 0) {117return -1;118}119*/120121// Get the drawing surface info122dsi = ds->GetDrawingSurfaceInfo(ds);123124// Get the platform-specific drawing info125dsi_win = (JAWT_Win32DrawingSurfaceInfo *)dsi->platformInfo;126127// Get the window handle128windowHandle = (jint)dsi_win->hwnd;129130// Free the drawing surface info131ds->FreeDrawingSurfaceInfo(dsi);132133/*134// Unlock the drawing surface135ds->Unlock(ds);136*/137138// Free the drawing surface139awt.FreeDrawingSurface(ds);140141return windowHandle;142}143}144145146