Print this page
Added gradle and cmake project
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/windows/native/libawt/windows/awt.h
+++ new/src/java.desktop/windows/native/libawt/windows/awt.h
1 1 /*
2 2 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 #ifndef _AWT_H_
27 27 #define _AWT_H_
28 28
29 29 #ifndef _WIN32_WINNT
30 30 #define _WIN32_WINNT 0x0600
31 31 #endif
32 32
33 33 #ifndef _WIN32_IE
34 34 #define _WIN32_IE 0x0600
35 35 #endif
36 36
37 37 //#ifndef NTDDI_VERSION
38 38 //#define NTDDI_VERSION NTDDI_LONGHORN
39 39 //#endif
40 40
41 41 #include "stdhdrs.h"
42 42 #include "alloc.h"
43 43 #include "awt_Debug.h"
44 44
45 45 extern COLORREF DesktopColor2RGB(int colorIndex);
46 46
47 47 class AwtObject;
48 48 typedef AwtObject* PDATA;
49 49
50 50 #define JNI_IS_TRUE(obj) ((obj) ? JNI_TRUE : JNI_FALSE)
51 51
52 52 #define JNI_CHECK_NULL_GOTO(obj, msg, where) { \
53 53 if (obj == NULL) { \
54 54 env->ExceptionClear(); \
55 55 JNU_ThrowNullPointerException(env, msg); \
56 56 goto where; \
57 57 } \
58 58 }
59 59
60 60 #define JNI_CHECK_NULL_RETURN(obj, msg) { \
61 61 if (obj == NULL) { \
62 62 env->ExceptionClear(); \
63 63 JNU_ThrowNullPointerException(env, msg); \
64 64 return; \
65 65 } \
66 66 }
67 67
68 68 #define JNI_CHECK_PEER_CREATION_RETURN(peer) { \
69 69 if (peer == NULL ) { \
70 70 return; \
71 71 } \
72 72 pData = JNI_GET_PDATA(peer); \
73 73 if (pData == NULL) { \
74 74 return; \
75 75 } \
76 76 }
77 77
78 78 #define JNI_CHECK_NULL_RETURN_NULL(obj, msg) { \
79 79 if (obj == NULL) { \
80 80 env->ExceptionClear(); \
81 81 JNU_ThrowNullPointerException(env, msg); \
82 82 return 0; \
83 83 } \
84 84 }
85 85
86 86 #define JNI_CHECK_NULL_RETURN_VAL(obj, msg, val) { \
87 87 if (obj == NULL) { \
88 88 env->ExceptionClear(); \
89 89 JNU_ThrowNullPointerException(env, msg); \
90 90 return val; \
91 91 } \
92 92 }
93 93
94 94 /**
95 95 * This macros must be used under SyncCall or on the Toolkit thread.
96 96 */
97 97 #define JNI_CHECK_PEER_GOTO(peer, where) { \
98 98 JNI_CHECK_NULL_GOTO(peer, "peer", where); \
99 99 pData = JNI_GET_PDATA(peer); \
100 100 if (pData == NULL) { \
101 101 THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
102 102 goto where; \
103 103 } \
104 104 }
105 105
106 106 /**
107 107 * This macros must be used under SyncCall or on the Toolkit thread.
108 108 */
109 109 #define JNI_CHECK_PEER_RETURN(peer) { \
110 110 JNI_CHECK_NULL_RETURN(peer, "peer"); \
111 111 pData = JNI_GET_PDATA(peer); \
112 112 if (pData == NULL) { \
113 113 THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
114 114 return; \
115 115 } \
116 116 }
117 117
118 118 /**
119 119 * This macros must be used under SyncCall or on the Toolkit thread.
120 120 */
121 121 #define JNI_CHECK_PEER_RETURN_NULL(peer) { \
122 122 JNI_CHECK_NULL_RETURN_NULL(peer, "peer"); \
123 123 pData = JNI_GET_PDATA(peer); \
124 124 if (pData == NULL) { \
125 125 THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
126 126 return 0; \
127 127 } \
128 128 }
129 129
130 130 /**
131 131 * This macros must be used under SyncCall or on the Toolkit thread.
132 132 */
133 133 #define JNI_CHECK_PEER_RETURN_VAL(peer, val) { \
134 134 JNI_CHECK_NULL_RETURN_VAL(peer, "peer", val); \
135 135 pData = JNI_GET_PDATA(peer); \
136 136 if (pData == NULL) { \
137 137 THROW_NULL_PDATA_IF_NOT_DESTROYED(peer); \
138 138 return val; \
139 139 } \
140 140 }
141 141
142 142 #define THROW_NULL_PDATA_IF_NOT_DESTROYED(peer) { \
143 143 jboolean destroyed = JNI_GET_DESTROYED(peer); \
144 144 if (destroyed != JNI_TRUE) { \
145 145 env->ExceptionClear(); \
146 146 JNU_ThrowNullPointerException(env, "null pData"); \
147 147 } \
148 148 }
149 149
150 150 #define JNI_GET_PDATA(peer) (PDATA) env->GetLongField(peer, AwtObject::pDataID)
151 151 #define JNI_GET_DESTROYED(peer) env->GetBooleanField(peer, AwtObject::destroyedID)
152 152
153 153 #define JNI_SET_PDATA(peer, data) env->SetLongField(peer, \
154 154 AwtObject::pDataID, \
155 155 (jlong)data)
156 156 #define JNI_SET_DESTROYED(peer) env->SetBooleanField(peer, \
157 157 AwtObject::destroyedID, \
158 158 JNI_TRUE)
159 159 /* /NEW JNI */
160 160
161 161 /*
162 162 * IS_WIN64 returns TRUE on 64-bit Itanium
163 163 */
164 164 #if defined (_WIN64)
165 165 #define IS_WIN64 TRUE
166 166 #else
167 167 #define IS_WIN64 FALSE
168 168 #endif
169 169
170 170 /*
171 171 * IS_WIN2000 returns TRUE on 2000, XP and Vista
172 172 * IS_WINXP returns TRUE on XP and Vista
173 173 * IS_WINVISTA returns TRUE on Vista
174 174 */
175 175 #define IS_WIN2000 (LOBYTE(LOWORD(::GetVersion())) >= 5)
176 176 #define IS_WINXP ((IS_WIN2000 && HIBYTE(LOWORD(::GetVersion())) >= 1) || LOBYTE(LOWORD(::GetVersion())) > 5)
177 177 #define IS_WINVISTA (LOBYTE(LOWORD(::GetVersion())) >= 6)
178 178 #define IS_WIN8 ( \
179 179 (IS_WINVISTA && (HIBYTE(LOWORD(::GetVersion())) >= 2)) || \
180 180 (LOBYTE(LOWORD(::GetVersion())) > 6))
181 181
182 182 #define IS_WINVER_ATLEAST(maj, min) \
183 183 ((maj) < LOBYTE(LOWORD(::GetVersion())) || \
↓ open down ↓ |
183 lines elided |
↑ open up ↑ |
184 184 (maj) == LOBYTE(LOWORD(::GetVersion())) && \
185 185 (min) <= HIBYTE(LOWORD(::GetVersion())))
186 186
187 187 /*
188 188 * macros to crack a LPARAM into two ints -- used for signed coordinates,
189 189 * such as with mouse messages.
190 190 */
191 191 #define LO_INT(l) ((int)(short)(l))
192 192 #define HI_INT(l) ((int)(short)(((DWORD)(l) >> 16) & 0xFFFF))
193 193
194 -extern JavaVM *jvm;
194 +extern "C" JavaVM *jvm;
195 195
196 196 // Platform encoding is Unicode (UTF-16), re-define JNU_ functions
197 197 // to proper JNI functions.
198 198 #define JNU_NewStringPlatform(env, x) env->NewString(reinterpret_cast<const jchar*>(x), static_cast<jsize>(_tcslen(x)))
199 199 #define JNU_GetStringPlatformChars(env, x, y) reinterpret_cast<LPCWSTR>(env->GetStringChars(x, y))
200 200 #define JNU_ReleaseStringPlatformChars(env, x, y) env->ReleaseStringChars(x, reinterpret_cast<const jchar*>(y))
201 201
202 202 /*
203 203 * Itanium symbols needed for 64-bit compilation.
204 204 * These are defined in winuser.h in the August 2001 MSDN update.
205 205 */
206 206 #ifndef GCLP_HBRBACKGROUND
207 207 #ifdef _WIN64
208 208 #error Macros for GetClassLongPtr, etc. are for 32-bit windows only
209 209 #endif /* !_WIN64 */
210 210 #define GetClassLongPtr GetClassLong
211 211 #define SetClassLongPtr SetClassLong
212 212 #define GCLP_HBRBACKGROUND GCL_HBRBACKGROUND
213 213 #define GCLP_HCURSOR GCL_HCURSOR
214 214 #define GCLP_HICON GCL_HICON
215 215 #define GCLP_HICONSM GCL_HICONSM
216 216 #define GCLP_HMODULE GCL_HMODULE
217 217 #define GCLP_MENUNAME GCL_MENUNAME
218 218 #define GCLP_WNDPROC GCL_WNDPROC
219 219 #define GetWindowLongPtr GetWindowLong
220 220 #define SetWindowLongPtr SetWindowLong
221 221 #define GWLP_WNDPROC GWL_WNDPROC
222 222 #define GWLP_HINSTANCE GWL_HINSTANCE
223 223 #define GWLP_HWNDPARENT GWL_HWNDPARENT
224 224 #define GWLP_ID GWL_ID
225 225 #define GWLP_USERDATA GWL_USERDATA
226 226 #define DWLP_DLGPROC DWL_DLGPROC
227 227 #define DWLP_MSGRESULT DWL_MSGRESULT
228 228 #define DWLP_USER DWL_USER
229 229 #endif /* !GCLP_HBRBACKGROUND */
230 230
231 231 /*
232 232 * macros for saving and restoring FPU control word
233 233 * NOTE: float.h must be defined if using these macros
234 234 */
235 235 #define SAVE_CONTROLWORD \
236 236 unsigned int fpu_cw = _control87(0, 0);
237 237
238 238 #define RESTORE_CONTROLWORD \
239 239 if (_control87(0, 0) != fpu_cw) { \
240 240 _control87(fpu_cw, 0xffffffff); \
241 241 }
242 242
243 243 /*
244 244 * checks if the current thread is/isn't the toolkit thread
245 245 */
246 246 #if defined(DEBUG)
247 247 #define CHECK_IS_TOOLKIT_THREAD() \
248 248 if (GetCurrentThreadId() != AwtToolkit::MainThread()) \
249 249 { JNU_ThrowInternalError(env,"Operation is not permitted on non-toolkit thread!\n"); }
250 250 #define CHECK_ISNOT_TOOLKIT_THREAD() \
251 251 if (GetCurrentThreadId() == AwtToolkit::MainThread()) \
252 252 { JNU_ThrowInternalError(env,"Operation is not permitted on toolkit thread!\n"); }
253 253 #else
254 254 #define CHECK_IS_TOOLKIT_THREAD()
255 255 #define CHECK_ISNOT_TOOLKIT_THREAD()
256 256 #endif
257 257
258 258
259 259 struct EnvHolder
260 260 {
261 261 JavaVM *m_pVM;
262 262 JNIEnv *m_env;
263 263 bool m_isOwner;
264 264 EnvHolder(
265 265 JavaVM *pVM,
266 266 LPCSTR name = "COM holder",
267 267 jint ver = JNI_VERSION_1_2)
268 268 : m_pVM(pVM),
269 269 m_env((JNIEnv *)JNU_GetEnv(pVM, ver)),
270 270 m_isOwner(false)
271 271 {
272 272 if (NULL == m_env) {
273 273 JavaVMAttachArgs attachArgs;
274 274 attachArgs.version = ver;
275 275 attachArgs.name = const_cast<char *>(name);
276 276 attachArgs.group = NULL;
277 277 jint status = m_pVM->AttachCurrentThread(
278 278 (void**)&m_env,
279 279 &attachArgs);
280 280 m_isOwner = (NULL!=m_env);
281 281 }
282 282 }
283 283 ~EnvHolder() {
284 284 if (m_isOwner) {
285 285 m_pVM->DetachCurrentThread();
286 286 }
287 287 }
288 288 operator bool() const { return NULL!=m_env; }
289 289 bool operator !() const { return NULL==m_env; }
290 290 operator JNIEnv*() const { return m_env; }
291 291 JNIEnv* operator ->() const { return m_env; }
292 292 };
293 293
294 294 template <class T>
295 295 class JLocalRef {
296 296 JNIEnv* m_env;
297 297 T m_localJRef;
298 298
299 299 public:
300 300 JLocalRef(JNIEnv* env, T localJRef = NULL)
301 301 : m_env(env),
302 302 m_localJRef(localJRef)
303 303 {}
304 304 T Detach() {
305 305 T ret = m_localJRef;
306 306 m_localJRef = NULL;
307 307 return ret;
308 308 }
309 309 void Attach(T newValue) {
310 310 if (m_localJRef) {
311 311 m_env->DeleteLocalRef((jobject)m_localJRef);
312 312 }
313 313 m_localJRef = newValue;
314 314 }
315 315
316 316 operator T() { return m_localJRef; }
317 317 operator bool() { return NULL!=m_localJRef; }
318 318 bool operator !() { return NULL==m_localJRef; }
319 319
320 320 ~JLocalRef() {
321 321 if (m_localJRef) {
322 322 m_env->DeleteLocalRef((jobject)m_localJRef);
323 323 }
324 324 }
325 325 };
326 326
327 327 typedef JLocalRef<jobject> JLObject;
328 328 typedef JLocalRef<jstring> JLString;
329 329 typedef JLocalRef<jclass> JLClass;
330 330
331 331 /*
332 332 * Class to encapsulate the extraction of the java string contents
333 333 * into a buffer and the cleanup of the buffer
334 334 */
335 335 class JavaStringBuffer
336 336 {
337 337 protected:
338 338 LPWSTR m_pStr;
339 339 jsize m_dwSize;
340 340 LPWSTR getNonEmptyString() {
341 341 return (NULL==m_pStr)
342 342 ? L""
343 343 : m_pStr;
344 344 }
345 345
346 346 public:
347 347 JavaStringBuffer(jsize cbTCharCount) {
348 348 m_dwSize = cbTCharCount;
349 349 m_pStr = (0 == m_dwSize)
350 350 ? NULL
351 351 : (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
352 352 }
353 353
354 354 JavaStringBuffer(JNIEnv *env, jstring text) {
355 355 m_dwSize = (NULL == text)
356 356 ? 0
357 357 : env->GetStringLength(text);
358 358 if (0 == m_dwSize) {
359 359 m_pStr = NULL;
360 360 } else {
361 361 m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
362 362 env->GetStringRegion(text, 0, m_dwSize, reinterpret_cast<jchar *>(m_pStr));
363 363 m_pStr[m_dwSize] = 0;
364 364 }
365 365 }
366 366
367 367
368 368 ~JavaStringBuffer() {
369 369 free(m_pStr);
370 370 }
371 371
372 372 void Resize(jsize cbTCharCount) {
373 373 m_dwSize = cbTCharCount;
374 374 //It is ok to have non-null terminated string here.
375 375 //The function is used only for space reservation in staff buffer for
376 376 //followed data copying process. And that is the reason why we ignore
377 377 //the special case m_dwSize==0 here.
378 378 m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc, m_pStr, m_dwSize+1, sizeof(WCHAR) );
379 379 }
380 380 //we are in UNICODE now, so LPWSTR:=:LPTSTR
381 381 operator LPWSTR() { return getNonEmptyString(); }
382 382 operator LPARAM() { return (LPARAM)getNonEmptyString(); }
383 383 void *GetData() { return (void *)getNonEmptyString(); }
384 384 jsize GetSize() { return m_dwSize; }
385 385 };
386 386
387 387
388 388 #endif /* _AWT_H_ */
↓ open down ↓ |
184 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX