jpayne@69: /* jpayne@69: * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. jpayne@69: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jpayne@69: * jpayne@69: * This code is free software; you can redistribute it and/or modify it jpayne@69: * under the terms of the GNU General Public License version 2 only, as jpayne@69: * published by the Free Software Foundation. Oracle designates this jpayne@69: * particular file as subject to the "Classpath" exception as provided jpayne@69: * by Oracle in the LICENSE file that accompanied this code. jpayne@69: * jpayne@69: * This code is distributed in the hope that it will be useful, but WITHOUT jpayne@69: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jpayne@69: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jpayne@69: * version 2 for more details (a copy is included in the LICENSE file that jpayne@69: * accompanied this code). jpayne@69: * jpayne@69: * You should have received a copy of the GNU General Public License version jpayne@69: * 2 along with this work; if not, write to the Free Software Foundation, jpayne@69: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jpayne@69: * jpayne@69: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jpayne@69: * or visit www.oracle.com if you need additional information or have any jpayne@69: * questions. jpayne@69: */ jpayne@69: jpayne@69: #ifndef _JAVASOFT_JAWT_H_ jpayne@69: #define _JAVASOFT_JAWT_H_ jpayne@69: jpayne@69: #include "jni.h" jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * AWT native interface. jpayne@69: * jpayne@69: * The AWT native interface allows a native C or C++ application a means jpayne@69: * by which to access native structures in AWT. This is to facilitate moving jpayne@69: * legacy C and C++ applications to Java and to target the needs of the jpayne@69: * developers who need to do their own native rendering to canvases jpayne@69: * for performance or other reasons. jpayne@69: * jpayne@69: * Conversely it also provides mechanisms for an application which already jpayne@69: * has a native window to provide that to AWT for AWT rendering. jpayne@69: * jpayne@69: * Since every platform may be different in its native data structures jpayne@69: * and APIs for windowing systems the application must necessarily jpayne@69: * provided per-platform source and compile and deliver per-platform jpayne@69: * native code to use this API. jpayne@69: * jpayne@69: * These interfaces are not part of the Java SE specification and jpayne@69: * a VM is not required to implement this API. However it is strongly jpayne@69: * recommended that all implementations which support headful AWT jpayne@69: * also support these interfaces. jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * AWT Native Drawing Surface (JAWT_DrawingSurface). jpayne@69: * jpayne@69: * For each platform, there is a native drawing surface structure. This jpayne@69: * platform-specific structure can be found in jawt_md.h. It is recommended jpayne@69: * that additional platforms follow the same model. It is also recommended jpayne@69: * that VMs on all platforms support the existing structures in jawt_md.h. jpayne@69: * jpayne@69: ******************* jpayne@69: * EXAMPLE OF USAGE: jpayne@69: ******************* jpayne@69: * jpayne@69: * In Win32, a programmer wishes to access the HWND of a canvas to perform jpayne@69: * native rendering into it. The programmer has declared the paint() method jpayne@69: * for their canvas subclass to be native: jpayne@69: * jpayne@69: * jpayne@69: * MyCanvas.java: jpayne@69: * jpayne@69: * import java.awt.*; jpayne@69: * jpayne@69: * public class MyCanvas extends Canvas { jpayne@69: * jpayne@69: * static { jpayne@69: * System.loadLibrary("mylib"); jpayne@69: * } jpayne@69: * jpayne@69: * public native void paint(Graphics g); jpayne@69: * } jpayne@69: * jpayne@69: * jpayne@69: * myfile.c: jpayne@69: * jpayne@69: * #include "jawt_md.h" jpayne@69: * #include jpayne@69: * jpayne@69: * JNIEXPORT void JNICALL jpayne@69: * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics) jpayne@69: * { jpayne@69: * JAWT awt; jpayne@69: * JAWT_DrawingSurface* ds; jpayne@69: * JAWT_DrawingSurfaceInfo* dsi; jpayne@69: * JAWT_Win32DrawingSurfaceInfo* dsi_win; jpayne@69: * jboolean result; jpayne@69: * jint lock; jpayne@69: * jpayne@69: * // Get the AWT. Request version 9 to access features in that release. jpayne@69: * awt.version = JAWT_VERSION_9; jpayne@69: * result = JAWT_GetAWT(env, &awt); jpayne@69: * assert(result != JNI_FALSE); jpayne@69: * jpayne@69: * // Get the drawing surface jpayne@69: * ds = awt.GetDrawingSurface(env, canvas); jpayne@69: * assert(ds != NULL); jpayne@69: * jpayne@69: * // Lock the drawing surface jpayne@69: * lock = ds->Lock(ds); jpayne@69: * assert((lock & JAWT_LOCK_ERROR) == 0); jpayne@69: * jpayne@69: * // Get the drawing surface info jpayne@69: * dsi = ds->GetDrawingSurfaceInfo(ds); jpayne@69: * jpayne@69: * // Get the platform-specific drawing info jpayne@69: * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; jpayne@69: * jpayne@69: * ////////////////////////////// jpayne@69: * // !!! DO PAINTING HERE !!! // jpayne@69: * ////////////////////////////// jpayne@69: * jpayne@69: * // Free the drawing surface info jpayne@69: * ds->FreeDrawingSurfaceInfo(dsi); jpayne@69: * jpayne@69: * // Unlock the drawing surface jpayne@69: * ds->Unlock(ds); jpayne@69: * jpayne@69: * // Free the drawing surface jpayne@69: * awt.FreeDrawingSurface(ds); jpayne@69: * } jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * JAWT_Rectangle jpayne@69: * Structure for a native rectangle. jpayne@69: */ jpayne@69: typedef struct jawt_Rectangle { jpayne@69: jint x; jpayne@69: jint y; jpayne@69: jint width; jpayne@69: jint height; jpayne@69: } JAWT_Rectangle; jpayne@69: jpayne@69: struct jawt_DrawingSurface; jpayne@69: jpayne@69: /* jpayne@69: * JAWT_DrawingSurfaceInfo jpayne@69: * Structure for containing the underlying drawing information of a component. jpayne@69: */ jpayne@69: typedef struct jawt_DrawingSurfaceInfo { jpayne@69: /* jpayne@69: * Pointer to the platform-specific information. This can be safely jpayne@69: * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a jpayne@69: * JAWT_X11DrawingSurfaceInfo on Linux and Solaris. On Mac OS X this is a jpayne@69: * pointer to a NSObject that conforms to the JAWT_SurfaceLayers jpayne@69: * protocol. See jawt_md.h for details. jpayne@69: */ jpayne@69: void* platformInfo; jpayne@69: /* Cached pointer to the underlying drawing surface */ jpayne@69: struct jawt_DrawingSurface* ds; jpayne@69: /* Bounding rectangle of the drawing surface */ jpayne@69: JAWT_Rectangle bounds; jpayne@69: /* Number of rectangles in the clip */ jpayne@69: jint clipSize; jpayne@69: /* Clip rectangle array */ jpayne@69: JAWT_Rectangle* clip; jpayne@69: } JAWT_DrawingSurfaceInfo; jpayne@69: jpayne@69: #define JAWT_LOCK_ERROR 0x00000001 jpayne@69: #define JAWT_LOCK_CLIP_CHANGED 0x00000002 jpayne@69: #define JAWT_LOCK_BOUNDS_CHANGED 0x00000004 jpayne@69: #define JAWT_LOCK_SURFACE_CHANGED 0x00000008 jpayne@69: jpayne@69: /* jpayne@69: * JAWT_DrawingSurface jpayne@69: * Structure for containing the underlying drawing information of a component. jpayne@69: * All operations on a JAWT_DrawingSurface MUST be performed from the same jpayne@69: * thread as the call to GetDrawingSurface. jpayne@69: */ jpayne@69: typedef struct jawt_DrawingSurface { jpayne@69: /* jpayne@69: * Cached reference to the Java environment of the calling thread. jpayne@69: * If Lock(), Unlock(), GetDrawingSurfaceInfo() or jpayne@69: * FreeDrawingSurfaceInfo() are called from a different thread, jpayne@69: * this data member should be set before calling those functions. jpayne@69: */ jpayne@69: JNIEnv* env; jpayne@69: /* Cached reference to the target object */ jpayne@69: jobject target; jpayne@69: /* jpayne@69: * Lock the surface of the target component for native rendering. jpayne@69: * When finished drawing, the surface must be unlocked with jpayne@69: * Unlock(). This function returns a bitmask with one or more of the jpayne@69: * following values: jpayne@69: * jpayne@69: * JAWT_LOCK_ERROR - When an error has occurred and the surface could not jpayne@69: * be locked. jpayne@69: * jpayne@69: * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed. jpayne@69: * jpayne@69: * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed. jpayne@69: * jpayne@69: * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed jpayne@69: */ jpayne@69: jint (JNICALL *Lock) jpayne@69: (struct jawt_DrawingSurface* ds); jpayne@69: /* jpayne@69: * Get the drawing surface info. jpayne@69: * The value returned may be cached, but the values may change if jpayne@69: * additional calls to Lock() or Unlock() are made. jpayne@69: * Lock() must be called before this can return a valid value. jpayne@69: * Returns NULL if an error has occurred. jpayne@69: * When finished with the returned value, FreeDrawingSurfaceInfo must be jpayne@69: * called. jpayne@69: */ jpayne@69: JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo) jpayne@69: (struct jawt_DrawingSurface* ds); jpayne@69: /* jpayne@69: * Free the drawing surface info. jpayne@69: */ jpayne@69: void (JNICALL *FreeDrawingSurfaceInfo) jpayne@69: (JAWT_DrawingSurfaceInfo* dsi); jpayne@69: /* jpayne@69: * Unlock the drawing surface of the target component for native rendering. jpayne@69: */ jpayne@69: void (JNICALL *Unlock) jpayne@69: (struct jawt_DrawingSurface* ds); jpayne@69: } JAWT_DrawingSurface; jpayne@69: jpayne@69: /* jpayne@69: * JAWT jpayne@69: * Structure for containing native AWT functions. jpayne@69: */ jpayne@69: typedef struct jawt { jpayne@69: /* jpayne@69: * Version of this structure. This must always be set before jpayne@69: * calling JAWT_GetAWT(). It affects the functions returned. jpayne@69: * Must be one of the known pre-defined versions. jpayne@69: */ jpayne@69: jint version; jpayne@69: /* jpayne@69: * Return a drawing surface from a target jobject. This value jpayne@69: * may be cached. jpayne@69: * Returns NULL if an error has occurred. jpayne@69: * Target must be a java.awt.Component (should be a Canvas jpayne@69: * or Window for native rendering). jpayne@69: * FreeDrawingSurface() must be called when finished with the jpayne@69: * returned JAWT_DrawingSurface. jpayne@69: */ jpayne@69: JAWT_DrawingSurface* (JNICALL *GetDrawingSurface) jpayne@69: (JNIEnv* env, jobject target); jpayne@69: /* jpayne@69: * Free the drawing surface allocated in GetDrawingSurface. jpayne@69: */ jpayne@69: void (JNICALL *FreeDrawingSurface) jpayne@69: (JAWT_DrawingSurface* ds); jpayne@69: /* jpayne@69: * Since 1.4 jpayne@69: * Locks the entire AWT for synchronization purposes jpayne@69: */ jpayne@69: void (JNICALL *Lock)(JNIEnv* env); jpayne@69: /* jpayne@69: * Since 1.4 jpayne@69: * Unlocks the entire AWT for synchronization purposes jpayne@69: */ jpayne@69: void (JNICALL *Unlock)(JNIEnv* env); jpayne@69: /* jpayne@69: * Since 1.4 jpayne@69: * Returns a reference to a java.awt.Component from a native jpayne@69: * platform handle. On Windows, this corresponds to an HWND; jpayne@69: * on Solaris and Linux, this is a Drawable. For other platforms, jpayne@69: * see the appropriate machine-dependent header file for a description. jpayne@69: * The reference returned by this function is a local jpayne@69: * reference that is only valid in this environment. jpayne@69: * This function returns a NULL reference if no component could be jpayne@69: * found with matching platform information. jpayne@69: */ jpayne@69: jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo); jpayne@69: jpayne@69: /** jpayne@69: * Since 9 jpayne@69: * Creates a java.awt.Frame placed in a native container. Container is jpayne@69: * referenced by the native platform handle. For example on Windows this jpayne@69: * corresponds to an HWND. For other platforms, see the appropriate jpayne@69: * machine-dependent header file for a description. The reference returned jpayne@69: * by this function is a local reference that is only valid in this jpayne@69: * environment. This function returns a NULL reference if no frame could be jpayne@69: * created with matching platform information. jpayne@69: */ jpayne@69: jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo); jpayne@69: jpayne@69: /** jpayne@69: * Since 9 jpayne@69: * Moves and resizes the embedded frame. The new location of the top-left jpayne@69: * corner is specified by x and y parameters relative to the native parent jpayne@69: * component. The new size is specified by width and height. jpayne@69: * jpayne@69: * The embedded frame should be created by CreateEmbeddedFrame() method, or jpayne@69: * this function will not have any effect. jpayne@69: * jpayne@69: * java.awt.Component.setLocation() and java.awt.Component.setBounds() for jpayne@69: * EmbeddedFrame really don't move it within the native parent. These jpayne@69: * methods always locate the embedded frame at (0, 0) for backward jpayne@69: * compatibility. To allow moving embedded frames this method was jpayne@69: * introduced, and it works just the same way as setLocation() and jpayne@69: * setBounds() for usual, non-embedded components. jpayne@69: * jpayne@69: * Using usual get/setLocation() and get/setBounds() together with this new jpayne@69: * method is not recommended. jpayne@69: */ jpayne@69: void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame, jpayne@69: jint x, jint y, jint w, jint h); jpayne@69: /** jpayne@69: * Since 9 jpayne@69: * Synthesize a native message to activate or deactivate an EmbeddedFrame jpayne@69: * window depending on the value of parameter doActivate, if "true" jpayne@69: * activates the window; otherwise, deactivates the window. jpayne@69: * jpayne@69: * The embedded frame should be created by CreateEmbeddedFrame() method, or jpayne@69: * this function will not have any effect. jpayne@69: */ jpayne@69: void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env, jpayne@69: jobject embeddedFrame, jboolean doActivate); jpayne@69: } JAWT; jpayne@69: jpayne@69: /* jpayne@69: * Get the AWT native structure. This function returns JNI_FALSE if jpayne@69: * an error occurs. jpayne@69: */ jpayne@69: _JNI_IMPORT_OR_EXPORT_ jpayne@69: jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt); jpayne@69: jpayne@69: /* jpayne@69: * Specify one of these constants as the JAWT.version jpayne@69: * Specifying an earlier version will limit the available functions to jpayne@69: * those provided in that earlier version of JAWT. jpayne@69: * See the "Since" note on each API. Methods with no "Since" jpayne@69: * may be presumed to be present in JAWT_VERSION_1_3. jpayne@69: */ jpayne@69: #define JAWT_VERSION_1_3 0x00010003 jpayne@69: #define JAWT_VERSION_1_4 0x00010004 jpayne@69: #define JAWT_VERSION_1_7 0x00010007 jpayne@69: #define JAWT_VERSION_9 0x00090000 jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } /* extern "C" */ jpayne@69: #endif jpayne@69: jpayne@69: #endif /* !_JAVASOFT_JAWT_H_ */