Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
jawt.h357 linesDownload Raw Back to include
1/*2 * Copyright (c) 1999, 2017, 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 it6 * under the terms of the GNU General Public License version 2 only, as7 * published by the Free Software Foundation.  Oracle designates this8 * particular file as subject to the "Classpath" exception as provided9 * 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 WITHOUT12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License14 * version 2 for more details (a copy is included in the LICENSE file that15 * accompanied this code).16 *17 * You should have received a copy of the GNU General Public License version18 * 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 USA22 * or visit www.oracle.com if you need additional information or have any23 * questions.24 */25 26#ifndef _JAVASOFT_JAWT_H_27#define _JAVASOFT_JAWT_H_28 29#include "jni.h"30 31#ifdef __cplusplus32extern "C" {33#endif34 35/*36 * AWT native interface.37 *38 * The AWT native interface allows a native C or C++ application a means39 * by which to access native structures in AWT.  This is to facilitate moving40 * legacy C and C++ applications to Java and to target the needs of the41 * developers who need to do their own native rendering to canvases42 * for performance or other reasons.43 *44 * Conversely it also provides mechanisms for an application which already45 * has a native window to provide that to AWT for AWT rendering.46 *47 * Since every platform may be different in its native data structures48 * and APIs for windowing systems the application must necessarily49 * provided per-platform source and compile and deliver per-platform50 * native code  to use this API.51 *52 * These interfaces are not part of the Java SE specification and53 * a VM is not required to implement this API. However it is strongly54 * recommended that all implementations which support headful AWT55 * also support these interfaces.56 *57 */58 59/*60 * AWT Native Drawing Surface (JAWT_DrawingSurface).61 *62 * For each platform, there is a native drawing surface structure.  This63 * platform-specific structure can be found in jawt_md.h.  It is recommended64 * that additional platforms follow the same model.  It is also recommended65 * that VMs on all platforms support the existing structures in jawt_md.h.66 *67 *******************68 * EXAMPLE OF USAGE:69 *******************70 *71 * In Win32, a programmer wishes to access the HWND of a canvas to perform72 * native rendering into it.  The programmer has declared the paint() method73 * for their canvas subclass to be native:74 *75 *76 * MyCanvas.java:77 *78 * import java.awt.*;79 *80 * public class MyCanvas extends Canvas {81 *82 *     static {83 *         System.loadLibrary("mylib");84 *     }85 *86 *     public native void paint(Graphics g);87 * }88 *89 *90 * myfile.c:91 *92 * #include "jawt_md.h"93 * #include <assert.h>94 *95 * JNIEXPORT void JNICALL96 * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)97 * {98 *     JAWT awt;99 *     JAWT_DrawingSurface* ds;100 *     JAWT_DrawingSurfaceInfo* dsi;101 *     JAWT_Win32DrawingSurfaceInfo* dsi_win;102 *     jboolean result;103 *     jint lock;104 *105 *     // Get the AWT. Request version 9 to access features in that release.106 *     awt.version = JAWT_VERSION_9;107 *     result = JAWT_GetAWT(env, &awt);108 *     assert(result != JNI_FALSE);109 *110 *     // Get the drawing surface111 *     ds = awt.GetDrawingSurface(env, canvas);112 *     assert(ds != NULL);113 *114 *     // Lock the drawing surface115 *     lock = ds->Lock(ds);116 *     assert((lock & JAWT_LOCK_ERROR) == 0);117 *118 *     // Get the drawing surface info119 *     dsi = ds->GetDrawingSurfaceInfo(ds);120 *121 *     // Get the platform-specific drawing info122 *     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;123 *124 *     //////////////////////////////125 *     // !!! DO PAINTING HERE !!! //126 *     //////////////////////////////127 *128 *     // Free the drawing surface info129 *     ds->FreeDrawingSurfaceInfo(dsi);130 *131 *     // Unlock the drawing surface132 *     ds->Unlock(ds);133 *134 *     // Free the drawing surface135 *     awt.FreeDrawingSurface(ds);136 * }137 *138 */139 140/*141 * JAWT_Rectangle142 * Structure for a native rectangle.143 */144typedef struct jawt_Rectangle {145    jint x;146    jint y;147    jint width;148    jint height;149} JAWT_Rectangle;150 151struct jawt_DrawingSurface;152 153/*154 * JAWT_DrawingSurfaceInfo155 * Structure for containing the underlying drawing information of a component.156 */157typedef struct jawt_DrawingSurfaceInfo {158    /*159     * Pointer to the platform-specific information.  This can be safely160     * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a161     * JAWT_X11DrawingSurfaceInfo on Linux and Solaris. On Mac OS X this is a162     * pointer to a NSObject that conforms to the JAWT_SurfaceLayers163     * protocol. See jawt_md.h for details.164     */165    void* platformInfo;166    /* Cached pointer to the underlying drawing surface */167    struct jawt_DrawingSurface* ds;168    /* Bounding rectangle of the drawing surface */169    JAWT_Rectangle bounds;170    /* Number of rectangles in the clip */171    jint clipSize;172    /* Clip rectangle array */173    JAWT_Rectangle* clip;174} JAWT_DrawingSurfaceInfo;175 176#define JAWT_LOCK_ERROR                 0x00000001177#define JAWT_LOCK_CLIP_CHANGED          0x00000002178#define JAWT_LOCK_BOUNDS_CHANGED        0x00000004179#define JAWT_LOCK_SURFACE_CHANGED       0x00000008180 181/*182 * JAWT_DrawingSurface183 * Structure for containing the underlying drawing information of a component.184 * All operations on a JAWT_DrawingSurface MUST be performed from the same185 * thread as the call to GetDrawingSurface.186 */187typedef struct jawt_DrawingSurface {188    /*189     * Cached reference to the Java environment of the calling thread.190     * If Lock(), Unlock(), GetDrawingSurfaceInfo() or191     * FreeDrawingSurfaceInfo() are called from a different thread,192     * this data member should be set before calling those functions.193     */194    JNIEnv* env;195    /* Cached reference to the target object */196    jobject target;197    /*198     * Lock the surface of the target component for native rendering.199     * When finished drawing, the surface must be unlocked with200     * Unlock().  This function returns a bitmask with one or more of the201     * following values:202     *203     * JAWT_LOCK_ERROR - When an error has occurred and the surface could not204     * be locked.205     *206     * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.207     *208     * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.209     *210     * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed211     */212    jint (JNICALL *Lock)213        (struct jawt_DrawingSurface* ds);214    /*215     * Get the drawing surface info.216     * The value returned may be cached, but the values may change if217     * additional calls to Lock() or Unlock() are made.218     * Lock() must be called before this can return a valid value.219     * Returns NULL if an error has occurred.220     * When finished with the returned value, FreeDrawingSurfaceInfo must be221     * called.222     */223    JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)224        (struct jawt_DrawingSurface* ds);225    /*226     * Free the drawing surface info.227     */228    void (JNICALL *FreeDrawingSurfaceInfo)229        (JAWT_DrawingSurfaceInfo* dsi);230    /*231     * Unlock the drawing surface of the target component for native rendering.232     */233    void (JNICALL *Unlock)234        (struct jawt_DrawingSurface* ds);235} JAWT_DrawingSurface;236 237/*238 * JAWT239 * Structure for containing native AWT functions.240 */241typedef struct jawt {242    /*243     * Version of this structure.  This must always be set before244     * calling JAWT_GetAWT(). It affects the functions returned.245     * Must be one of the known pre-defined versions.246     */247    jint version;248    /*249     * Return a drawing surface from a target jobject.  This value250     * may be cached.251     * Returns NULL if an error has occurred.252     * Target must be a java.awt.Component (should be a Canvas253     * or Window for native rendering).254     * FreeDrawingSurface() must be called when finished with the255     * returned JAWT_DrawingSurface.256     */257    JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)258        (JNIEnv* env, jobject target);259    /*260     * Free the drawing surface allocated in GetDrawingSurface.261     */262    void (JNICALL *FreeDrawingSurface)263        (JAWT_DrawingSurface* ds);264    /*265     * Since 1.4266     * Locks the entire AWT for synchronization purposes267     */268    void (JNICALL *Lock)(JNIEnv* env);269    /*270     * Since 1.4271     * Unlocks the entire AWT for synchronization purposes272     */273    void (JNICALL *Unlock)(JNIEnv* env);274    /*275     * Since 1.4276     * Returns a reference to a java.awt.Component from a native277     * platform handle.  On Windows, this corresponds to an HWND;278     * on Solaris and Linux, this is a Drawable.  For other platforms,279     * see the appropriate machine-dependent header file for a description.280     * The reference returned by this function is a local281     * reference that is only valid in this environment.282     * This function returns a NULL reference if no component could be283     * found with matching platform information.284     */285    jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);286 287    /**288     * Since 9289     * Creates a java.awt.Frame placed in a native container. Container is290     * referenced by the native platform handle. For example on Windows this291     * corresponds to an HWND. For other platforms, see the appropriate292     * machine-dependent header file for a description. The reference returned293     * by this function is a local reference that is only valid in this294     * environment. This function returns a NULL reference if no frame could be295     * created with matching platform information.296     */297    jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo);298 299    /**300     * Since 9301     * Moves and resizes the embedded frame. The new location of the top-left302     * corner is specified by x and y parameters relative to the native parent303     * component. The new size is specified by width and height.304     *305     * The embedded frame should be created by CreateEmbeddedFrame() method, or306     * this function will not have any effect.307     *308     * java.awt.Component.setLocation() and java.awt.Component.setBounds() for309     * EmbeddedFrame really don't move it within the native parent. These310     * methods always locate the embedded frame at (0, 0) for backward311     * compatibility. To allow moving embedded frames this method was312     * introduced, and it works just the same way as setLocation() and313     * setBounds() for usual, non-embedded components.314     *315     * Using usual get/setLocation() and get/setBounds() together with this new316     * method is not recommended.317     */318    void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame,319            jint x, jint y, jint w, jint h);320    /**321     * Since 9322     * Synthesize a native message to activate or deactivate an EmbeddedFrame323     * window depending on the value of parameter doActivate, if "true"324     * activates the window; otherwise, deactivates the window.325     *326     * The embedded frame should be created by CreateEmbeddedFrame() method, or327     * this function will not have any effect.328     */329    void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env,330            jobject embeddedFrame, jboolean doActivate);331} JAWT;332 333/*334 * Get the AWT native structure.  This function returns JNI_FALSE if335 * an error occurs.336 */337_JNI_IMPORT_OR_EXPORT_338jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);339 340/*341 * Specify one of these constants as the JAWT.version342 * Specifying an earlier version will limit the available functions to343 * those provided in that earlier version of JAWT.344 * See the "Since" note on each API. Methods with no "Since"345 * may be presumed to be present in JAWT_VERSION_1_3.346 */347#define JAWT_VERSION_1_3 0x00010003348#define JAWT_VERSION_1_4 0x00010004349#define JAWT_VERSION_1_7 0x00010007350#define JAWT_VERSION_9 0x00090000351 352#ifdef __cplusplus353} /* extern "C" */354#endif355 356#endif /* !_JAVASOFT_JAWT_H_ */357 
codekingpro/portable-devtools · Team Ai