blob: 9cd7e32516e75caeeb6b94a0f1c6ceddf2ac6d56 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2002 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25/*
26 * Implements the native code for the java.awt.AWTEvent class
27 * and all of the classes in the java.awt.event package.
28 *
29 * THIS FILE DOES NOT IMPLEMENT ANY OF THE OBSOLETE java.awt.Event
30 * CLASS. SEE awt_Event.[ch] FOR THAT CLASS' IMPLEMENTATION.
31 */
32
33#ifdef HEADLESS
34 #error This file should not be included in headless library
35#endif
36
37#include "awt_p.h"
38#include "java_awt_AWTEvent.h"
39#include "java_awt_event_InputEvent.h"
40#include "java_awt_event_KeyEvent.h"
41#include "jni_util.h"
42
43#include "canvas.h"
44#include "awt_AWTEvent.h"
45#include "awt_Component.h"
46
47struct AWTEventIDs awtEventIDs;
48struct InputEventIDs inputEventIDs;
49struct KeyEventIDs keyEventIDs;
50struct MComponentPeerIDs mComponentPeerIDs;
51
52JNIEXPORT void JNICALL
53Java_java_awt_AWTEvent_initIDs(JNIEnv *env, jclass cls)
54{
55 awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B");
56 awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z");
57 awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I");
58}
59
60JNIEXPORT void JNICALL
61Java_java_awt_event_InputEvent_initIDs(JNIEnv *env, jclass cls)
62{
63 inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I");
64}
65
66JNIEXPORT void JNICALL
67Java_java_awt_event_KeyEvent_initIDs(JNIEnv *env, jclass cls)
68{
69 keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I");
70 keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C");
71}
72#ifndef XAWT
73JNIEXPORT void JNICALL
74Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self,
75 jobject newSource)
76{
77 jbyteArray bdata;
78
79 AWT_LOCK();
80
81 bdata = (jbyteArray)(*env)->GetObjectField(env, self, awtEventIDs.bdata);
82
83 if (bdata != NULL) {
84 XEvent *xev;
85 Window w;
86 jboolean dummy;
87
88 /* get the widget out of the peer newSource */
89 struct ComponentData *cdata = (struct ComponentData *)
90 JNU_GetLongFieldAsPtr(env, newSource, mComponentPeerIDs.pData);
91 if (JNU_IsNull(env, cdata) || (cdata == NULL) ||
92 ((cdata->widget != NULL) && (XtIsObject(cdata->widget)) &&
93 (cdata->widget->core.being_destroyed))) {
94 JNU_ThrowNullPointerException(env, "null widget");
95 AWT_UNLOCK();
96 return;
97 }
98
99 /* get the Window out of the widget */
100 w = XtWindow(cdata->widget);
101
102 if (w == None) {
103 JNU_ThrowNullPointerException(env, "null window");
104 AWT_UNLOCK();
105 return;
106 }
107
108 /* reset the filed in the event */
109 xev = (XEvent *)(*env)->GetPrimitiveArrayCritical(env, bdata, &dummy);
110 if (xev == NULL) {
111 JNU_ThrowNullPointerException(env, "null data");
112 AWT_UNLOCK();
113 return;
114 }
115 xev->xany.window = w;
116 (*env)->ReleasePrimitiveArrayCritical(env, bdata, (void *)xev, 0);
117 }
118
119 AWT_UNLOCK();
120}
121#else
122JNIEXPORT void JNICALL
123Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self,
124 jobject newSource)
125{
126
127}
128
129#endif