Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <X11/Xlib.h>
23 : #include <X11/Xutil.h>
24 : #include <X11/Intrinsic.h>
25 :
26 : #include "jni.h"
27 :
28 : #include "jawt_md.h"
29 : #include "jawt.h"
30 :
31 : #include "sal/types.h"
32 :
33 : #define SYSTEM_XWINDOW 6
34 :
35 :
36 : /* type must be something like java/lang/RuntimeException
37 : */
38 0 : static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
39 : jclass c;
40 0 : (*env)->ExceptionClear(env);
41 0 : c = (*env)->FindClass(env, type);
42 0 : if (c == NULL) {
43 0 : (*env)->ExceptionClear(env);
44 0 : (*env)->FatalError(
45 : env, "JNI FindClass failed");
46 : }
47 0 : if ((*env)->ThrowNew(env, c, msg) != 0) {
48 0 : (*env)->ExceptionClear(env);
49 0 : (*env)->FatalError(env, "JNI ThrowNew failed");
50 : }
51 0 : }
52 :
53 : /*****************************************************************************/
54 : /*
55 : * Class: com_sun_star_comp_beans_LocalOfficeWindow
56 : * Method: getNativeWindowSystemType
57 : * Signature: ()I
58 : */
59 0 : SAL_DLLPUBLIC_EXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
60 : (JNIEnv * env, jobject obj_this)
61 : {
62 : (void) env; /* avoid warning about unused parameter */
63 : (void) obj_this; /* avoid warning about unused parameter */
64 0 : return (SYSTEM_XWINDOW);
65 : }
66 :
67 :
68 : /*****************************************************************************/
69 : /*
70 : * Class: com_sun_star_beans_LocalOfficeWindow
71 : * Method: getNativeWindow
72 : * Signature: ()J
73 : */
74 0 : SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
75 : (JNIEnv * env, jobject obj_this)
76 : {
77 : jboolean result;
78 : jint lock;
79 :
80 : JAWT awt;
81 : JAWT_DrawingSurface* ds;
82 : JAWT_DrawingSurfaceInfo* dsi;
83 : JAWT_X11DrawingSurfaceInfo* dsi_x11;
84 :
85 : Drawable drawable;
86 :
87 : /* Get the AWT */
88 0 : awt.version = JAWT_VERSION_1_3;
89 0 : result = JAWT_GetAWT(env, &awt);
90 0 : if (result == JNI_FALSE)
91 0 : ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
92 :
93 : /* Get the drawing surface */
94 0 : if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
95 0 : return 0L;
96 :
97 : /* Lock the drawing surface */
98 0 : lock = ds->Lock(ds);
99 0 : if ( (lock & JAWT_LOCK_ERROR) != 0)
100 0 : ThrowException(env, "java/lang/RuntimeException",
101 : "Could not get AWT drawing surface.");
102 :
103 : /* Get the drawing surface info */
104 0 : dsi = ds->GetDrawingSurfaceInfo(ds);
105 :
106 : /* Get the platform-specific drawing info */
107 0 : dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
108 :
109 0 : drawable = dsi_x11->drawable;
110 :
111 : /* Free the drawing surface info */
112 0 : ds->FreeDrawingSurfaceInfo(dsi);
113 : /* Unlock the drawing surface */
114 0 : ds->Unlock(ds);
115 : /* Free the drawing surface */
116 0 : awt.FreeDrawingSurface(ds);
117 :
118 0 : return ((jlong)drawable);
119 : }
120 :
121 :
122 :
123 :
124 :
125 :
126 :
127 :
128 :
129 :
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|