1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <X11/Xlib.h> 29 #include <X11/Xutil.h> 30 #include <X11/Intrinsic.h> 31 32 #include "jni.h" 33 34 // Workaround for problematic IBM JDK 1.6.0 on ppc 35 #ifndef _JNI_IMPORT_OR_EXPORT_ 36 #define _JNI_IMPORT_OR_EXPORT_ 37 #endif 38 39 #include "jawt_md.h" 40 #include "jawt.h" 41 42 43 #define SYSTEM_WIN32 1 44 #define SYSTEM_WIN16 2 45 #define SYSTEM_JAVA 3 46 #define SYSTEM_OS2 4 47 #define SYSTEM_MAC 5 48 #define SYSTEM_XWINDOW 6 49 50 51 /* type must be something like java/lang/RuntimeException 52 */ 53 static void ThrowException(JNIEnv * env, char const * type, char const * msg) { 54 jclass c; 55 (*env)->ExceptionClear(env); 56 c = (*env)->FindClass(env, type); 57 if (c == NULL) { 58 (*env)->ExceptionClear(env); 59 (*env)->FatalError( 60 env, "JNI FindClass failed"); 61 } 62 if ((*env)->ThrowNew(env, c, msg) != 0) { 63 (*env)->ExceptionClear(env); 64 (*env)->FatalError(env, "JNI ThrowNew failed"); 65 } 66 } 67 68 /*****************************************************************************/ 69 /* 70 * Class: com_sun_star_comp_beans_LocalOfficeWindow 71 * Method: getNativeWindowSystemType 72 * Signature: ()I 73 */ 74 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType 75 (JNIEnv * env, jobject obj_this) 76 { 77 (void) env; /* avoid warning about unused parameter */ 78 (void) obj_this; /* avoid warning about unused parameter */ 79 return (SYSTEM_XWINDOW); 80 } 81 82 83 /*****************************************************************************/ 84 /* 85 * Class: com_sun_star_beans_LocalOfficeWindow 86 * Method: getNativeWindow 87 * Signature: ()J 88 */ 89 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow 90 (JNIEnv * env, jobject obj_this) 91 { 92 jboolean result; 93 jint lock; 94 95 JAWT awt; 96 JAWT_DrawingSurface* ds; 97 JAWT_DrawingSurfaceInfo* dsi; 98 JAWT_X11DrawingSurfaceInfo* dsi_x11; 99 100 Drawable drawable; 101 Display* display; 102 103 /* Get the AWT */ 104 awt.version = JAWT_VERSION_1_3; 105 result = JAWT_GetAWT(env, &awt); 106 if (result == JNI_FALSE) 107 ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed"); 108 109 /* Get the drawing surface */ 110 if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) 111 return 0L; 112 113 /* Lock the drawing surface */ 114 lock = ds->Lock(ds); 115 if ( (lock & JAWT_LOCK_ERROR) != 0) 116 ThrowException(env, "java/lang/RuntimeException", 117 "Could not get AWT drawing surface."); 118 119 /* Get the drawing surface info */ 120 dsi = ds->GetDrawingSurfaceInfo(ds); 121 122 /* Get the platform-specific drawing info */ 123 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; 124 125 drawable = dsi_x11->drawable; 126 display = dsi_x11->display; 127 128 /* Free the drawing surface info */ 129 ds->FreeDrawingSurfaceInfo(dsi); 130 /* Unlock the drawing surface */ 131 ds->Unlock(ds); 132 /* Free the drawing surface */ 133 awt.FreeDrawingSurface(ds); 134 135 return ((jlong)drawable); 136 } 137 138 139 140 141 142 143 144 145 146 147 148