1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/Intrinsic.h>
27 
28 #include "jni.h"
29 
30 // Workaround for problematic IBM JDK 1.6.0 on ppc
31 #ifndef _JNI_IMPORT_OR_EXPORT_
32 #define _JNI_IMPORT_OR_EXPORT_
33 #endif
34 
35 #include "jawt_md.h"
36 #include "jawt.h"
37 
38 
39 #define SYSTEM_WIN32   1
40 #define SYSTEM_WIN16   2
41 #define SYSTEM_JAVA    3
42 #define SYSTEM_OS2     4
43 #define SYSTEM_MAC     5
44 #define SYSTEM_XWINDOW 6
45 
46 
47 /* type must be something like java/lang/RuntimeException
48  */
ThrowException(JNIEnv * env,char const * type,char const * msg)49 static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
50     jclass c;
51     (*env)->ExceptionClear(env);
52     c = (*env)->FindClass(env, type);
53     if (c == NULL) {
54         (*env)->ExceptionClear(env);
55         (*env)->FatalError(
56             env, "JNI FindClass failed");
57     }
58     if ((*env)->ThrowNew(env, c, msg) != 0) {
59         (*env)->ExceptionClear(env);
60         (*env)->FatalError(env, "JNI ThrowNew failed");
61     }
62 }
63 
64 /*****************************************************************************/
65 /*
66  * Class:     com_sun_star_comp_beans_LocalOfficeWindow
67  * Method:    getNativeWindowSystemType
68  * Signature: ()I
69  */
Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType(JNIEnv * env,jobject obj_this)70 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
71   (JNIEnv * env, jobject obj_this)
72 {
73     (void) env; /* avoid warning about unused parameter */
74     (void) obj_this; /* avoid warning about unused parameter */
75     return (SYSTEM_XWINDOW);
76 }
77 
78 
79 /*****************************************************************************/
80 /*
81  * Class:     com_sun_star_beans_LocalOfficeWindow
82  * Method:    getNativeWindow
83  * Signature: ()J
84  */
Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow(JNIEnv * env,jobject obj_this)85 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
86   (JNIEnv * env, jobject obj_this)
87 {
88 	jboolean result;
89 	jint lock;
90 
91 	JAWT awt;
92 	JAWT_DrawingSurface* ds;
93 	JAWT_DrawingSurfaceInfo* dsi;
94 	JAWT_X11DrawingSurfaceInfo* dsi_x11;
95 
96 	Drawable drawable;
97 	Display* display;
98 
99 	/* Get the AWT */
100 	awt.version = JAWT_VERSION_1_3;
101 	result = JAWT_GetAWT(env, &awt);
102 	if (result == JNI_FALSE)
103         ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
104 
105 								/* Get the drawing surface */
106 	if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
107 		return 0L;
108 
109 	/* Lock the drawing surface */
110 	lock = ds->Lock(ds);
111 	if ( (lock & JAWT_LOCK_ERROR) != 0)
112         ThrowException(env, "java/lang/RuntimeException",
113                        "Could not get AWT drawing surface.");
114 
115 	/* Get the drawing surface info */
116 	dsi = ds->GetDrawingSurfaceInfo(ds);
117 
118 	/* Get the platform-specific drawing info */
119 	dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
120 
121 	drawable = dsi_x11->drawable;
122 	display  = dsi_x11->display;
123 
124 	/* Free the drawing surface info */
125 	ds->FreeDrawingSurfaceInfo(dsi);
126 	/* Unlock the drawing surface */
127 	ds->Unlock(ds);
128 	/* Free the drawing surface */
129 	awt.FreeDrawingSurface(ds);
130 
131 	return ((jlong)drawable);
132 }
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144