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>
31 #include <sal/types.h>
33 #define SYSTEM_XWINDOW 6
36 /* type must be something like java/lang/RuntimeException
38 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
40 (*env
)->ExceptionClear(env
);
41 c
= (*env
)->FindClass(env
, type
);
43 (*env
)->ExceptionClear(env
);
45 env
, "JNI FindClass failed");
47 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
48 (*env
)->ExceptionClear(env
);
49 (*env
)->FatalError(env
, "JNI ThrowNew failed");
53 /*****************************************************************************/
55 * Class: com_sun_star_comp_beans_LocalOfficeWindow
56 * Method: getNativeWindowSystemType
59 SAL_DLLPUBLIC_EXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
60 (JNIEnv
* env
, jobject obj_this
)
62 (void) env
; /* avoid warning about unused parameter */
63 (void) obj_this
; /* avoid warning about unused parameter */
64 return SYSTEM_XWINDOW
;
68 /*****************************************************************************/
70 * Class: com_sun_star_beans_LocalOfficeWindow
71 * Method: getNativeWindow
74 SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
75 (JNIEnv
* env
, jobject obj_this
)
81 JAWT_DrawingSurface
* ds
;
82 JAWT_DrawingSurfaceInfo
* dsi
;
83 JAWT_X11DrawingSurfaceInfo
* dsi_x11
;
88 awt
.version
= JAWT_VERSION_1_3
;
89 result
= JAWT_GetAWT(env
, &awt
);
91 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
93 /* Get the drawing surface */
94 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
97 /* Lock the drawing surface */
99 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
100 ThrowException(env
, "java/lang/RuntimeException",
101 "Could not get AWT drawing surface.");
103 /* Get the drawing surface info */
104 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
106 /* Get the platform-specific drawing info */
107 dsi_x11
= (JAWT_X11DrawingSurfaceInfo
*)dsi
->platformInfo
;
109 drawable
= dsi_x11
->drawable
;
111 /* Free the drawing surface info */
112 ds
->FreeDrawingSurfaceInfo(dsi
);
113 /* Unlock the drawing surface */
115 /* Free the drawing surface */
116 awt
.FreeDrawingSurface(ds
);
118 return (jlong
)drawable
;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */