Get the style color and number just once
[LibreOffice.git] / bean / native / unix / com_sun_star_comp_beans_LocalOfficeWindow.c
blob9e534e2262d930f8d2969ef5baea18517e6667a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Intrinsic.h>
26 // to deal with gcc specific attribute "externally_visible" used in
27 // /usr/lib/jvm/java-11-openjdk-armhf/include/linux/jni_md.h:35
28 // via /usr/lib/jvm/java-11-openjdk-armhf/include/jni.h
29 #if defined __clang__
30 #pragma clang diagnostic push
31 #pragma clang diagnostic ignored "-Wunknown-attributes"
32 #endif
33 #include <jni.h>
35 #include <jawt_md.h>
36 #include <jawt.h>
37 #if defined __clang__
38 #pragma clang diagnostic pop
39 #endif
41 #include <sal/types.h>
43 #define SYSTEM_XWINDOW 6
46 /* type must be something like java/lang/RuntimeException
48 static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
49 jclass c;
50 (*env)->ExceptionClear(env);
51 c = (*env)->FindClass(env, type);
52 if (c == NULL) {
53 (*env)->ExceptionClear(env);
54 (*env)->FatalError(
55 env, "JNI FindClass failed");
57 if ((*env)->ThrowNew(env, c, msg) != 0) {
58 (*env)->ExceptionClear(env);
59 (*env)->FatalError(env, "JNI ThrowNew failed");
63 /*****************************************************************************/
65 * Class: com_sun_star_comp_beans_LocalOfficeWindow
66 * Method: getNativeWindowSystemType
67 * Signature: ()I
69 SAL_DLLPUBLIC_EXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
70 (JNIEnv * env, jobject obj_this)
72 (void) env; /* avoid warning about unused parameter */
73 (void) obj_this; /* avoid warning about unused parameter */
74 return SYSTEM_XWINDOW;
78 /*****************************************************************************/
80 * Class: com_sun_star_beans_LocalOfficeWindow
81 * Method: getNativeWindow
82 * Signature: ()J
84 SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
85 (JNIEnv * env, jobject obj_this)
87 jboolean result;
88 jint lock;
90 JAWT awt;
91 JAWT_DrawingSurface* ds;
92 JAWT_DrawingSurfaceInfo* dsi;
93 JAWT_X11DrawingSurfaceInfo* dsi_x11;
95 Drawable drawable;
97 /* Get the AWT */
98 awt.version = JAWT_VERSION_1_3;
99 result = JAWT_GetAWT(env, &awt);
100 if (!result)
101 ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
103 /* Get the drawing surface */
104 ds = awt.GetDrawingSurface(env, obj_this);
105 if (ds == NULL)
106 return 0;
108 /* Lock the drawing surface */
109 lock = ds->Lock(ds);
110 if ( (lock & JAWT_LOCK_ERROR) != 0)
111 ThrowException(env, "java/lang/RuntimeException",
112 "Could not get AWT drawing surface.");
114 /* Get the drawing surface info */
115 dsi = ds->GetDrawingSurfaceInfo(ds);
117 /* Get the platform-specific drawing info */
118 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
120 drawable = dsi_x11->drawable;
122 /* Free the drawing surface info */
123 ds->FreeDrawingSurfaceInfo(dsi);
124 /* Unlock the drawing surface */
125 ds->Unlock(ds);
126 /* Free the drawing surface */
127 awt.FreeDrawingSurface(ds);
129 return (jlong)drawable;
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */