1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
23 #include <X11/Xutil.h>
24 #include <X11/Intrinsic.h>
28 // Workaround for problematic IBM JDK 1.6.0 on ppc
29 #ifndef _JNI_IMPORT_OR_EXPORT_
30 #define _JNI_IMPORT_OR_EXPORT_
36 #include "sal/types.h"
38 #define SYSTEM_XWINDOW 6
41 /* type must be something like java/lang/RuntimeException
43 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
45 (*env
)->ExceptionClear(env
);
46 c
= (*env
)->FindClass(env
, type
);
48 (*env
)->ExceptionClear(env
);
50 env
, "JNI FindClass failed");
52 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
53 (*env
)->ExceptionClear(env
);
54 (*env
)->FatalError(env
, "JNI ThrowNew failed");
58 /*****************************************************************************/
60 * Class: com_sun_star_comp_beans_LocalOfficeWindow
61 * Method: getNativeWindowSystemType
64 SAL_DLLPUBLIC_EXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
65 (JNIEnv
* env
, jobject obj_this
)
67 (void) env
; /* avoid warning about unused parameter */
68 (void) obj_this
; /* avoid warning about unused parameter */
69 return (SYSTEM_XWINDOW
);
73 /*****************************************************************************/
75 * Class: com_sun_star_beans_LocalOfficeWindow
76 * Method: getNativeWindow
79 SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
80 (JNIEnv
* env
, jobject obj_this
)
86 JAWT_DrawingSurface
* ds
;
87 JAWT_DrawingSurfaceInfo
* dsi
;
88 JAWT_X11DrawingSurfaceInfo
* dsi_x11
;
93 awt
.version
= JAWT_VERSION_1_3
;
94 result
= JAWT_GetAWT(env
, &awt
);
95 if (result
== JNI_FALSE
)
96 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
98 /* Get the drawing surface */
99 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
102 /* Lock the drawing surface */
104 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
105 ThrowException(env
, "java/lang/RuntimeException",
106 "Could not get AWT drawing surface.");
108 /* Get the drawing surface info */
109 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
111 /* Get the platform-specific drawing info */
112 dsi_x11
= (JAWT_X11DrawingSurfaceInfo
*)dsi
->platformInfo
;
114 drawable
= dsi_x11
->drawable
;
116 /* Free the drawing surface info */
117 ds
->FreeDrawingSurfaceInfo(dsi
);
118 /* Unlock the drawing surface */
120 /* Free the drawing surface */
121 awt
.FreeDrawingSurface(ds
);
123 return ((jlong
)drawable
);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */