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