1 /* |
|
2 * Copyright 1995-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 #ifdef HEADLESS |
|
26 #error This file should not be included in headless library |
|
27 #endif |
|
28 |
|
29 #include "awt_p.h" |
|
30 #include "java_awt_Canvas.h" |
|
31 #include "sun_awt_motif_MCanvasPeer.h" |
|
32 #include "sun_awt_motif_MComponentPeer.h" |
|
33 #include "color.h" |
|
34 #include "canvas.h" |
|
35 #include "awt_util.h" |
|
36 |
|
37 #include "awt_Component.h" |
|
38 #include "awt_GraphicsEnv.h" |
|
39 |
|
40 #include <jni.h> |
|
41 #include <jni_util.h> |
|
42 #include "multi_font.h" |
|
43 |
|
44 extern struct MComponentPeerIDs mComponentPeerIDs; |
|
45 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; |
|
46 extern AwtGraphicsConfigDataPtr |
|
47 copyGraphicsConfigToPeer(JNIEnv *env, jobject this); |
|
48 struct CanvasIDs mCanvasIDs; |
|
49 |
|
50 /* |
|
51 * Class: sun_awt_motif_MCanvasPeer |
|
52 * Method: create |
|
53 * Signature: (Lsun/awt/motif/MComponentPeer;)V |
|
54 */ |
|
55 JNIEXPORT void JNICALL Java_sun_awt_motif_MCanvasPeer_create |
|
56 (JNIEnv * env, jobject this, jobject parent) |
|
57 { |
|
58 AwtGraphicsConfigDataPtr awtData; |
|
59 |
|
60 struct CanvasData *wdata; |
|
61 struct CanvasData *cdata; |
|
62 jobject globalRef = awtJNI_CreateAndSetGlobalRef(env, this); |
|
63 |
|
64 AWT_LOCK(); |
|
65 if (JNU_IsNull(env, parent)) { |
|
66 JNU_ThrowNullPointerException(env, "NullPointerException"); |
|
67 AWT_UNLOCK(); |
|
68 return; |
|
69 } |
|
70 |
|
71 cdata = (struct CanvasData *) |
|
72 JNU_GetLongFieldAsPtr(env, parent, mComponentPeerIDs.pData); |
|
73 if (cdata == NULL) { |
|
74 JNU_ThrowNullPointerException(env, "NullPointerException"); |
|
75 AWT_UNLOCK(); |
|
76 return; |
|
77 } |
|
78 |
|
79 wdata = ZALLOC(CanvasData); |
|
80 if (wdata == NULL) { |
|
81 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
82 AWT_UNLOCK(); |
|
83 return; |
|
84 } |
|
85 JNU_SetLongFieldFromPtr(env, this, mComponentPeerIDs.pData, wdata); |
|
86 |
|
87 awtData = copyGraphicsConfigToPeer(env, this); |
|
88 |
|
89 wdata->comp.widget = awt_canvas_create((XtPointer) globalRef, |
|
90 cdata->comp.widget, |
|
91 "", |
|
92 1, 1, False, NULL, awtData); |
|
93 XtVaSetValues(wdata->comp.widget, |
|
94 XmNinsertPosition, awt_util_insertCallback, |
|
95 NULL); |
|
96 |
|
97 /* Add an event handler so that we can track focus change requests |
|
98 which will be initiated by Motif in response to ButtonPress events */ |
|
99 |
|
100 wdata->flags = 0; |
|
101 wdata->shell = cdata->shell; |
|
102 |
|
103 AWT_UNLOCK(); |
|
104 } |
|
105 |
|
106 /* |
|
107 * Class: sun_awt_motif_MCanvasPeer |
|
108 * Method: resetTargetGC |
|
109 * Signature: ()V |
|
110 */ |
|
111 JNIEXPORT void JNICALL Java_sun_awt_motif_MCanvasPeer_resetTargetGC |
|
112 (JNIEnv * env, jobject this, jobject target) |
|
113 { |
|
114 (*env)->CallVoidMethod(env, target, mCanvasIDs.setGCFromPeerMID); |
|
115 } |
|
116 |
|
117 /* |
|
118 * Class: sun_awt_motif_MCanvasPeer |
|
119 * Method: initIDs |
|
120 * Signature: ()V |
|
121 */ |
|
122 JNIEXPORT void JNICALL Java_sun_awt_motif_MCanvasPeer_initIDs |
|
123 (JNIEnv * env, jclass cls) |
|
124 { |
|
125 jclass canvasCls = (*env)->FindClass(env, "java/awt/Canvas"); |
|
126 mCanvasIDs.setGCFromPeerMID = |
|
127 (*env)->GetMethodID(env, canvasCls, "setGCFromPeer","()V"); |
|
128 |
|
129 DASSERT(mCanvasIDs.setGCFromPeerMID); |
|
130 } |
|