jw项目windows环境软件安装
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
12 KiB

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