1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * A DLL which is loaded by Java applications to handle communication
  28  * between Java VMs purposes of Accessbility.
  29  */
  30 
  31 #include <windows.h>
  32 #include <jni.h>
  33 
  34 #include "AccessBridgePackages.h"
  35 #include "AccessBridgeATInstance.h"
  36 #include "AccessBridgeJavaEntryPoints.h"
  37 
  38 #ifndef __JavaAccessBridge_H__
  39 #define __JavaAccessBridge_H__
  40 
  41 
  42 extern "C" {
  43         BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason,
  44                             LPVOID lpvReserved);
  45         void AppendToCallOutput(char *s);
  46         BOOL APIENTRY AccessBridgeDialogProc(HWND hDlg, UINT message,
  47                                              UINT wParam, LONG lParam);
  48 }
  49 
  50 /**
  51  * The JavaAccessBridge class.  The core of the Windows AT AccessBridge dll
  52  */
  53 class JavaAccessBridge {
  54 // for debugging
  55 public:
  56 // for debugging
  57     HINSTANCE windowsInstance;
  58     HWND dialogWindow;
  59     AccessBridgeATInstance *ATs;
  60     JavaVM *javaVM;
  61     JNIEnv *windowsThreadJNIEnv;    // for calls initiated from Windows
  62     AccessBridgeJavaEntryPoints *javaThreadEntryPoints;
  63     AccessBridgeJavaEntryPoints *windowsThreadEntryPoints;
  64     jobject javaThreadABObject;     // for calls initiated from Java
  65     jobject windowsThreadABObject;  // for calls initiated from Windows
  66 
  67 public:
  68     JavaAccessBridge(HINSTANCE hInstance);
  69     ~JavaAccessBridge();
  70     void javaRun(JNIEnv *env, jobject obj);
  71     BOOL initWindow();
  72 
  73     // IPC with the Java AccessBridge DLL
  74     void postHelloToWindowsDLLMsg(HWND destHwnd);
  75     LRESULT MemoryMappedFileCreated(HWND srcHwnd, char *filename);
  76 
  77     void sendPackage(char *buffer, int bufsize, HWND destHwnd);
  78     void sendJavaEventPackage(char *buffer, int bufsize, long type);
  79     void sendAccessibilityEventPackage(char *buffer, int bufsize, long type);
  80     BOOL sendMemoryPackage(char *buffer, long bufsize, HWND destWindow);
  81     LRESULT processPackage(char *buffer, int bufsize);
  82     BOOL receiveMemoryPackage(HWND srcWindow, long bufsize);
  83     void WindowsATDestroyed(HWND ATBridgeDLLWindow);
  84 
  85     // Java VM object memory management
  86     void releaseJavaObject(jobject object);
  87 
  88     // Event handling methods
  89     void addJavaEventNotification(jlong type, HWND DLLwindow);
  90     void removeJavaEventNotification(jlong type, HWND DLLwindow);
  91     void addAccessibilityEventNotification(jlong type, HWND DLLwindow);
  92     void removeAccessibilityEventNotification(jlong type, HWND DLLwindow);
  93 
  94     // Event firing methods
  95 /*
  96     void firePropertyChange(JNIEnv *env, jobject callingObj,
  97                             jobject propertyChangeEvent,
  98                             jobject source, jstring propertyName,
  99                             jstring oldValue, jstring newValue);
 100 */
 101 
 102     void javaShutdown(JNIEnv *env, jobject callingObj);
 103 
 104     void fireFocusGained(JNIEnv *env, jobject callingObj,
 105                          jobject focusEvent, jobject source);
 106     void fireFocusLost(JNIEnv *env, jobject callingObj,
 107                        jobject focusEvent,jobject source);
 108     void fireCaretUpdate(JNIEnv *env, jobject callingObj,
 109                          jobject caretEvent, jobject source);
 110     void fireMouseClicked(JNIEnv *env, jobject callingObj,
 111                           jobject mouseEvent, jobject source);
 112     void fireMouseEntered(JNIEnv *env, jobject callingObj,
 113                           jobject mouseEvent, jobject source);
 114     void fireMouseExited(JNIEnv *env, jobject callingObj,
 115                          jobject mouseEvent, jobject source);
 116     void fireMousePressed(JNIEnv *env, jobject callingObj,
 117                           jobject mouseEvent, jobject source);
 118     void fireMouseReleased(JNIEnv *env, jobject callingObj,
 119                            jobject mouseEvent, jobject source);
 120     void fireMenuCanceled(JNIEnv *env, jobject callingObj,
 121                           jobject menuEvent, jobject source);
 122     void fireMenuDeselected(JNIEnv *env, jobject callingObj,
 123                             jobject menuEvent, jobject source);
 124     void fireMenuSelected(JNIEnv *env, jobject callingObj,
 125                           jobject menuEvent, jobject source);
 126     void firePopupMenuCanceled(JNIEnv *env, jobject callingObj,
 127                                jobject popupMenuEvent, jobject source);
 128     void firePopupMenuWillBecomeInvisible(JNIEnv *env, jobject callingObj,
 129                                           jobject popupMenuEvent, jobject source);
 130     void firePopupMenuWillBecomeVisible(JNIEnv *env, jobject callingObj,
 131                                         jobject popupMenuEvent, jobject source);
 132 
 133     void firePropertyCaretChange(JNIEnv *env, jobject callingObj,
 134                                  jobject event, jobject source,
 135                                  jint oldValue, jint newValue);
 136     void firePropertyDescriptionChange(JNIEnv *env, jobject callingObj,
 137                                        jobject event, jobject source,
 138                                        jstring oldValue, jstring newValue);
 139     void firePropertyNameChange(JNIEnv *env, jobject callingObj,
 140                                 jobject event, jobject source,
 141                                 jstring oldValue, jstring newValue);
 142     void firePropertySelectionChange(JNIEnv *env, jobject callingObj,
 143                                      jobject event, jobject source);
 144     void firePropertyStateChange(JNIEnv *env, jobject callingObj,
 145                                  jobject event, jobject source,
 146                                  jstring oldValue, jstring newValue);
 147     void firePropertyTextChange(JNIEnv *env, jobject callingObj,
 148                                 jobject event, jobject source);
 149     void firePropertyValueChange(JNIEnv *env, jobject callingObj,
 150                                  jobject event, jobject source,
 151                                  jstring oldValue, jstring newValue);
 152     void firePropertyVisibleDataChange(JNIEnv *env, jobject callingObj,
 153                                        jobject event, jobject source);
 154     void firePropertyChildChange(JNIEnv *env, jobject callingObj,
 155                                  jobject event, jobject source,
 156                                  jobject oldValue, jobject newValue);
 157    void firePropertyActiveDescendentChange(JNIEnv *env, jobject callingObj,
 158                                            jobject event, jobject source,
 159                                            jobject oldValue, jobject newValue);
 160 
 161    void firePropertyTableModelChange(JNIEnv *env, jobject callingObj,
 162                                      jobject event, jobject source,
 163                                      jstring oldValue, jstring newValue);
 164 };
 165 
 166 
 167 #endif