jpayne@69
|
1 /*
|
jpayne@69
|
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
|
jpayne@69
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jpayne@69
|
4 *
|
jpayne@69
|
5 * This code is free software; you can redistribute it and/or modify it
|
jpayne@69
|
6 * under the terms of the GNU General Public License version 2 only, as
|
jpayne@69
|
7 * published by the Free Software Foundation. Oracle designates this
|
jpayne@69
|
8 * particular file as subject to the "Classpath" exception as provided
|
jpayne@69
|
9 * by Oracle in the LICENSE file that accompanied this code.
|
jpayne@69
|
10 *
|
jpayne@69
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
|
jpayne@69
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jpayne@69
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jpayne@69
|
14 * version 2 for more details (a copy is included in the LICENSE file that
|
jpayne@69
|
15 * accompanied this code).
|
jpayne@69
|
16 *
|
jpayne@69
|
17 * You should have received a copy of the GNU General Public License version
|
jpayne@69
|
18 * 2 along with this work; if not, write to the Free Software Foundation,
|
jpayne@69
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jpayne@69
|
20 *
|
jpayne@69
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jpayne@69
|
22 * or visit www.oracle.com if you need additional information or have any
|
jpayne@69
|
23 * questions.
|
jpayne@69
|
24 */
|
jpayne@69
|
25
|
jpayne@69
|
26 #ifndef _JAVASOFT_JAWT_H_
|
jpayne@69
|
27 #define _JAVASOFT_JAWT_H_
|
jpayne@69
|
28
|
jpayne@69
|
29 #include "jni.h"
|
jpayne@69
|
30
|
jpayne@69
|
31 #ifdef __cplusplus
|
jpayne@69
|
32 extern "C" {
|
jpayne@69
|
33 #endif
|
jpayne@69
|
34
|
jpayne@69
|
35 /*
|
jpayne@69
|
36 * AWT native interface.
|
jpayne@69
|
37 *
|
jpayne@69
|
38 * The AWT native interface allows a native C or C++ application a means
|
jpayne@69
|
39 * by which to access native structures in AWT. This is to facilitate moving
|
jpayne@69
|
40 * legacy C and C++ applications to Java and to target the needs of the
|
jpayne@69
|
41 * developers who need to do their own native rendering to canvases
|
jpayne@69
|
42 * for performance or other reasons.
|
jpayne@69
|
43 *
|
jpayne@69
|
44 * Conversely it also provides mechanisms for an application which already
|
jpayne@69
|
45 * has a native window to provide that to AWT for AWT rendering.
|
jpayne@69
|
46 *
|
jpayne@69
|
47 * Since every platform may be different in its native data structures
|
jpayne@69
|
48 * and APIs for windowing systems the application must necessarily
|
jpayne@69
|
49 * provided per-platform source and compile and deliver per-platform
|
jpayne@69
|
50 * native code to use this API.
|
jpayne@69
|
51 *
|
jpayne@69
|
52 * These interfaces are not part of the Java SE specification and
|
jpayne@69
|
53 * a VM is not required to implement this API. However it is strongly
|
jpayne@69
|
54 * recommended that all implementations which support headful AWT
|
jpayne@69
|
55 * also support these interfaces.
|
jpayne@69
|
56 *
|
jpayne@69
|
57 */
|
jpayne@69
|
58
|
jpayne@69
|
59 /*
|
jpayne@69
|
60 * AWT Native Drawing Surface (JAWT_DrawingSurface).
|
jpayne@69
|
61 *
|
jpayne@69
|
62 * For each platform, there is a native drawing surface structure. This
|
jpayne@69
|
63 * platform-specific structure can be found in jawt_md.h. It is recommended
|
jpayne@69
|
64 * that additional platforms follow the same model. It is also recommended
|
jpayne@69
|
65 * that VMs on all platforms support the existing structures in jawt_md.h.
|
jpayne@69
|
66 *
|
jpayne@69
|
67 *******************
|
jpayne@69
|
68 * EXAMPLE OF USAGE:
|
jpayne@69
|
69 *******************
|
jpayne@69
|
70 *
|
jpayne@69
|
71 * In Win32, a programmer wishes to access the HWND of a canvas to perform
|
jpayne@69
|
72 * native rendering into it. The programmer has declared the paint() method
|
jpayne@69
|
73 * for their canvas subclass to be native:
|
jpayne@69
|
74 *
|
jpayne@69
|
75 *
|
jpayne@69
|
76 * MyCanvas.java:
|
jpayne@69
|
77 *
|
jpayne@69
|
78 * import java.awt.*;
|
jpayne@69
|
79 *
|
jpayne@69
|
80 * public class MyCanvas extends Canvas {
|
jpayne@69
|
81 *
|
jpayne@69
|
82 * static {
|
jpayne@69
|
83 * System.loadLibrary("mylib");
|
jpayne@69
|
84 * }
|
jpayne@69
|
85 *
|
jpayne@69
|
86 * public native void paint(Graphics g);
|
jpayne@69
|
87 * }
|
jpayne@69
|
88 *
|
jpayne@69
|
89 *
|
jpayne@69
|
90 * myfile.c:
|
jpayne@69
|
91 *
|
jpayne@69
|
92 * #include "jawt_md.h"
|
jpayne@69
|
93 * #include <assert.h>
|
jpayne@69
|
94 *
|
jpayne@69
|
95 * JNIEXPORT void JNICALL
|
jpayne@69
|
96 * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)
|
jpayne@69
|
97 * {
|
jpayne@69
|
98 * JAWT awt;
|
jpayne@69
|
99 * JAWT_DrawingSurface* ds;
|
jpayne@69
|
100 * JAWT_DrawingSurfaceInfo* dsi;
|
jpayne@69
|
101 * JAWT_Win32DrawingSurfaceInfo* dsi_win;
|
jpayne@69
|
102 * jboolean result;
|
jpayne@69
|
103 * jint lock;
|
jpayne@69
|
104 *
|
jpayne@69
|
105 * // Get the AWT. Request version 9 to access features in that release.
|
jpayne@69
|
106 * awt.version = JAWT_VERSION_9;
|
jpayne@69
|
107 * result = JAWT_GetAWT(env, &awt);
|
jpayne@69
|
108 * assert(result != JNI_FALSE);
|
jpayne@69
|
109 *
|
jpayne@69
|
110 * // Get the drawing surface
|
jpayne@69
|
111 * ds = awt.GetDrawingSurface(env, canvas);
|
jpayne@69
|
112 * assert(ds != NULL);
|
jpayne@69
|
113 *
|
jpayne@69
|
114 * // Lock the drawing surface
|
jpayne@69
|
115 * lock = ds->Lock(ds);
|
jpayne@69
|
116 * assert((lock & JAWT_LOCK_ERROR) == 0);
|
jpayne@69
|
117 *
|
jpayne@69
|
118 * // Get the drawing surface info
|
jpayne@69
|
119 * dsi = ds->GetDrawingSurfaceInfo(ds);
|
jpayne@69
|
120 *
|
jpayne@69
|
121 * // Get the platform-specific drawing info
|
jpayne@69
|
122 * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
|
jpayne@69
|
123 *
|
jpayne@69
|
124 * //////////////////////////////
|
jpayne@69
|
125 * // !!! DO PAINTING HERE !!! //
|
jpayne@69
|
126 * //////////////////////////////
|
jpayne@69
|
127 *
|
jpayne@69
|
128 * // Free the drawing surface info
|
jpayne@69
|
129 * ds->FreeDrawingSurfaceInfo(dsi);
|
jpayne@69
|
130 *
|
jpayne@69
|
131 * // Unlock the drawing surface
|
jpayne@69
|
132 * ds->Unlock(ds);
|
jpayne@69
|
133 *
|
jpayne@69
|
134 * // Free the drawing surface
|
jpayne@69
|
135 * awt.FreeDrawingSurface(ds);
|
jpayne@69
|
136 * }
|
jpayne@69
|
137 *
|
jpayne@69
|
138 */
|
jpayne@69
|
139
|
jpayne@69
|
140 /*
|
jpayne@69
|
141 * JAWT_Rectangle
|
jpayne@69
|
142 * Structure for a native rectangle.
|
jpayne@69
|
143 */
|
jpayne@69
|
144 typedef struct jawt_Rectangle {
|
jpayne@69
|
145 jint x;
|
jpayne@69
|
146 jint y;
|
jpayne@69
|
147 jint width;
|
jpayne@69
|
148 jint height;
|
jpayne@69
|
149 } JAWT_Rectangle;
|
jpayne@69
|
150
|
jpayne@69
|
151 struct jawt_DrawingSurface;
|
jpayne@69
|
152
|
jpayne@69
|
153 /*
|
jpayne@69
|
154 * JAWT_DrawingSurfaceInfo
|
jpayne@69
|
155 * Structure for containing the underlying drawing information of a component.
|
jpayne@69
|
156 */
|
jpayne@69
|
157 typedef struct jawt_DrawingSurfaceInfo {
|
jpayne@69
|
158 /*
|
jpayne@69
|
159 * Pointer to the platform-specific information. This can be safely
|
jpayne@69
|
160 * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
|
jpayne@69
|
161 * JAWT_X11DrawingSurfaceInfo on Linux and Solaris. On Mac OS X this is a
|
jpayne@69
|
162 * pointer to a NSObject that conforms to the JAWT_SurfaceLayers
|
jpayne@69
|
163 * protocol. See jawt_md.h for details.
|
jpayne@69
|
164 */
|
jpayne@69
|
165 void* platformInfo;
|
jpayne@69
|
166 /* Cached pointer to the underlying drawing surface */
|
jpayne@69
|
167 struct jawt_DrawingSurface* ds;
|
jpayne@69
|
168 /* Bounding rectangle of the drawing surface */
|
jpayne@69
|
169 JAWT_Rectangle bounds;
|
jpayne@69
|
170 /* Number of rectangles in the clip */
|
jpayne@69
|
171 jint clipSize;
|
jpayne@69
|
172 /* Clip rectangle array */
|
jpayne@69
|
173 JAWT_Rectangle* clip;
|
jpayne@69
|
174 } JAWT_DrawingSurfaceInfo;
|
jpayne@69
|
175
|
jpayne@69
|
176 #define JAWT_LOCK_ERROR 0x00000001
|
jpayne@69
|
177 #define JAWT_LOCK_CLIP_CHANGED 0x00000002
|
jpayne@69
|
178 #define JAWT_LOCK_BOUNDS_CHANGED 0x00000004
|
jpayne@69
|
179 #define JAWT_LOCK_SURFACE_CHANGED 0x00000008
|
jpayne@69
|
180
|
jpayne@69
|
181 /*
|
jpayne@69
|
182 * JAWT_DrawingSurface
|
jpayne@69
|
183 * Structure for containing the underlying drawing information of a component.
|
jpayne@69
|
184 * All operations on a JAWT_DrawingSurface MUST be performed from the same
|
jpayne@69
|
185 * thread as the call to GetDrawingSurface.
|
jpayne@69
|
186 */
|
jpayne@69
|
187 typedef struct jawt_DrawingSurface {
|
jpayne@69
|
188 /*
|
jpayne@69
|
189 * Cached reference to the Java environment of the calling thread.
|
jpayne@69
|
190 * If Lock(), Unlock(), GetDrawingSurfaceInfo() or
|
jpayne@69
|
191 * FreeDrawingSurfaceInfo() are called from a different thread,
|
jpayne@69
|
192 * this data member should be set before calling those functions.
|
jpayne@69
|
193 */
|
jpayne@69
|
194 JNIEnv* env;
|
jpayne@69
|
195 /* Cached reference to the target object */
|
jpayne@69
|
196 jobject target;
|
jpayne@69
|
197 /*
|
jpayne@69
|
198 * Lock the surface of the target component for native rendering.
|
jpayne@69
|
199 * When finished drawing, the surface must be unlocked with
|
jpayne@69
|
200 * Unlock(). This function returns a bitmask with one or more of the
|
jpayne@69
|
201 * following values:
|
jpayne@69
|
202 *
|
jpayne@69
|
203 * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
|
jpayne@69
|
204 * be locked.
|
jpayne@69
|
205 *
|
jpayne@69
|
206 * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
|
jpayne@69
|
207 *
|
jpayne@69
|
208 * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
|
jpayne@69
|
209 *
|
jpayne@69
|
210 * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
|
jpayne@69
|
211 */
|
jpayne@69
|
212 jint (JNICALL *Lock)
|
jpayne@69
|
213 (struct jawt_DrawingSurface* ds);
|
jpayne@69
|
214 /*
|
jpayne@69
|
215 * Get the drawing surface info.
|
jpayne@69
|
216 * The value returned may be cached, but the values may change if
|
jpayne@69
|
217 * additional calls to Lock() or Unlock() are made.
|
jpayne@69
|
218 * Lock() must be called before this can return a valid value.
|
jpayne@69
|
219 * Returns NULL if an error has occurred.
|
jpayne@69
|
220 * When finished with the returned value, FreeDrawingSurfaceInfo must be
|
jpayne@69
|
221 * called.
|
jpayne@69
|
222 */
|
jpayne@69
|
223 JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)
|
jpayne@69
|
224 (struct jawt_DrawingSurface* ds);
|
jpayne@69
|
225 /*
|
jpayne@69
|
226 * Free the drawing surface info.
|
jpayne@69
|
227 */
|
jpayne@69
|
228 void (JNICALL *FreeDrawingSurfaceInfo)
|
jpayne@69
|
229 (JAWT_DrawingSurfaceInfo* dsi);
|
jpayne@69
|
230 /*
|
jpayne@69
|
231 * Unlock the drawing surface of the target component for native rendering.
|
jpayne@69
|
232 */
|
jpayne@69
|
233 void (JNICALL *Unlock)
|
jpayne@69
|
234 (struct jawt_DrawingSurface* ds);
|
jpayne@69
|
235 } JAWT_DrawingSurface;
|
jpayne@69
|
236
|
jpayne@69
|
237 /*
|
jpayne@69
|
238 * JAWT
|
jpayne@69
|
239 * Structure for containing native AWT functions.
|
jpayne@69
|
240 */
|
jpayne@69
|
241 typedef struct jawt {
|
jpayne@69
|
242 /*
|
jpayne@69
|
243 * Version of this structure. This must always be set before
|
jpayne@69
|
244 * calling JAWT_GetAWT(). It affects the functions returned.
|
jpayne@69
|
245 * Must be one of the known pre-defined versions.
|
jpayne@69
|
246 */
|
jpayne@69
|
247 jint version;
|
jpayne@69
|
248 /*
|
jpayne@69
|
249 * Return a drawing surface from a target jobject. This value
|
jpayne@69
|
250 * may be cached.
|
jpayne@69
|
251 * Returns NULL if an error has occurred.
|
jpayne@69
|
252 * Target must be a java.awt.Component (should be a Canvas
|
jpayne@69
|
253 * or Window for native rendering).
|
jpayne@69
|
254 * FreeDrawingSurface() must be called when finished with the
|
jpayne@69
|
255 * returned JAWT_DrawingSurface.
|
jpayne@69
|
256 */
|
jpayne@69
|
257 JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)
|
jpayne@69
|
258 (JNIEnv* env, jobject target);
|
jpayne@69
|
259 /*
|
jpayne@69
|
260 * Free the drawing surface allocated in GetDrawingSurface.
|
jpayne@69
|
261 */
|
jpayne@69
|
262 void (JNICALL *FreeDrawingSurface)
|
jpayne@69
|
263 (JAWT_DrawingSurface* ds);
|
jpayne@69
|
264 /*
|
jpayne@69
|
265 * Since 1.4
|
jpayne@69
|
266 * Locks the entire AWT for synchronization purposes
|
jpayne@69
|
267 */
|
jpayne@69
|
268 void (JNICALL *Lock)(JNIEnv* env);
|
jpayne@69
|
269 /*
|
jpayne@69
|
270 * Since 1.4
|
jpayne@69
|
271 * Unlocks the entire AWT for synchronization purposes
|
jpayne@69
|
272 */
|
jpayne@69
|
273 void (JNICALL *Unlock)(JNIEnv* env);
|
jpayne@69
|
274 /*
|
jpayne@69
|
275 * Since 1.4
|
jpayne@69
|
276 * Returns a reference to a java.awt.Component from a native
|
jpayne@69
|
277 * platform handle. On Windows, this corresponds to an HWND;
|
jpayne@69
|
278 * on Solaris and Linux, this is a Drawable. For other platforms,
|
jpayne@69
|
279 * see the appropriate machine-dependent header file for a description.
|
jpayne@69
|
280 * The reference returned by this function is a local
|
jpayne@69
|
281 * reference that is only valid in this environment.
|
jpayne@69
|
282 * This function returns a NULL reference if no component could be
|
jpayne@69
|
283 * found with matching platform information.
|
jpayne@69
|
284 */
|
jpayne@69
|
285 jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
|
jpayne@69
|
286
|
jpayne@69
|
287 /**
|
jpayne@69
|
288 * Since 9
|
jpayne@69
|
289 * Creates a java.awt.Frame placed in a native container. Container is
|
jpayne@69
|
290 * referenced by the native platform handle. For example on Windows this
|
jpayne@69
|
291 * corresponds to an HWND. For other platforms, see the appropriate
|
jpayne@69
|
292 * machine-dependent header file for a description. The reference returned
|
jpayne@69
|
293 * by this function is a local reference that is only valid in this
|
jpayne@69
|
294 * environment. This function returns a NULL reference if no frame could be
|
jpayne@69
|
295 * created with matching platform information.
|
jpayne@69
|
296 */
|
jpayne@69
|
297 jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo);
|
jpayne@69
|
298
|
jpayne@69
|
299 /**
|
jpayne@69
|
300 * Since 9
|
jpayne@69
|
301 * Moves and resizes the embedded frame. The new location of the top-left
|
jpayne@69
|
302 * corner is specified by x and y parameters relative to the native parent
|
jpayne@69
|
303 * component. The new size is specified by width and height.
|
jpayne@69
|
304 *
|
jpayne@69
|
305 * The embedded frame should be created by CreateEmbeddedFrame() method, or
|
jpayne@69
|
306 * this function will not have any effect.
|
jpayne@69
|
307 *
|
jpayne@69
|
308 * java.awt.Component.setLocation() and java.awt.Component.setBounds() for
|
jpayne@69
|
309 * EmbeddedFrame really don't move it within the native parent. These
|
jpayne@69
|
310 * methods always locate the embedded frame at (0, 0) for backward
|
jpayne@69
|
311 * compatibility. To allow moving embedded frames this method was
|
jpayne@69
|
312 * introduced, and it works just the same way as setLocation() and
|
jpayne@69
|
313 * setBounds() for usual, non-embedded components.
|
jpayne@69
|
314 *
|
jpayne@69
|
315 * Using usual get/setLocation() and get/setBounds() together with this new
|
jpayne@69
|
316 * method is not recommended.
|
jpayne@69
|
317 */
|
jpayne@69
|
318 void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame,
|
jpayne@69
|
319 jint x, jint y, jint w, jint h);
|
jpayne@69
|
320 /**
|
jpayne@69
|
321 * Since 9
|
jpayne@69
|
322 * Synthesize a native message to activate or deactivate an EmbeddedFrame
|
jpayne@69
|
323 * window depending on the value of parameter doActivate, if "true"
|
jpayne@69
|
324 * activates the window; otherwise, deactivates the window.
|
jpayne@69
|
325 *
|
jpayne@69
|
326 * The embedded frame should be created by CreateEmbeddedFrame() method, or
|
jpayne@69
|
327 * this function will not have any effect.
|
jpayne@69
|
328 */
|
jpayne@69
|
329 void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env,
|
jpayne@69
|
330 jobject embeddedFrame, jboolean doActivate);
|
jpayne@69
|
331 } JAWT;
|
jpayne@69
|
332
|
jpayne@69
|
333 /*
|
jpayne@69
|
334 * Get the AWT native structure. This function returns JNI_FALSE if
|
jpayne@69
|
335 * an error occurs.
|
jpayne@69
|
336 */
|
jpayne@69
|
337 _JNI_IMPORT_OR_EXPORT_
|
jpayne@69
|
338 jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);
|
jpayne@69
|
339
|
jpayne@69
|
340 /*
|
jpayne@69
|
341 * Specify one of these constants as the JAWT.version
|
jpayne@69
|
342 * Specifying an earlier version will limit the available functions to
|
jpayne@69
|
343 * those provided in that earlier version of JAWT.
|
jpayne@69
|
344 * See the "Since" note on each API. Methods with no "Since"
|
jpayne@69
|
345 * may be presumed to be present in JAWT_VERSION_1_3.
|
jpayne@69
|
346 */
|
jpayne@69
|
347 #define JAWT_VERSION_1_3 0x00010003
|
jpayne@69
|
348 #define JAWT_VERSION_1_4 0x00010004
|
jpayne@69
|
349 #define JAWT_VERSION_1_7 0x00010007
|
jpayne@69
|
350 #define JAWT_VERSION_9 0x00090000
|
jpayne@69
|
351
|
jpayne@69
|
352 #ifdef __cplusplus
|
jpayne@69
|
353 } /* extern "C" */
|
jpayne@69
|
354 #endif
|
jpayne@69
|
355
|
jpayne@69
|
356 #endif /* !_JAVASOFT_JAWT_H_ */
|