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 : #include "comp_LocalOfficeWindow.h"
33 :
34 : #define SYSTEM_XWINDOW 6
35 :
36 :
37 : /* type must be something like java/lang/RuntimeException
38 : */
39 0 : static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
40 : jclass c;
41 0 : (*env)->ExceptionClear(env);
42 0 : c = (*env)->FindClass(env, type);
43 0 : if (c == NULL) {
44 0 : (*env)->ExceptionClear(env);
45 0 : (*env)->FatalError(
46 : env, "JNI FindClass failed");
47 : }
48 0 : if ((*env)->ThrowNew(env, c, msg) != 0) {
49 0 : (*env)->ExceptionClear(env);
50 0 : (*env)->FatalError(env, "JNI ThrowNew failed");
51 : }
52 0 : }
53 :
54 : /*****************************************************************************/
55 : /*
56 : * Class: com_sun_star_comp_beans_LocalOfficeWindow
57 : * Method: getNativeWindowSystemType
58 : * Signature: ()I
59 : */
60 0 : SAL_DLLPUBLIC_EXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
61 : (JNIEnv * env, jobject obj_this)
62 : {
63 : (void) env; /* avoid warning about unused parameter */
64 : (void) obj_this; /* avoid warning about unused parameter */
65 0 : return (SYSTEM_XWINDOW);
66 : }
67 :
68 :
69 : /*****************************************************************************/
70 : /*
71 : * Class: com_sun_star_beans_LocalOfficeWindow
72 : * Method: getNativeWindow
73 : * Signature: ()J
74 : */
75 0 : SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
76 : (JNIEnv * env, jobject obj_this)
77 : {
78 : jboolean result;
79 : jint lock;
80 :
81 : JAWT awt;
82 : JAWT_DrawingSurface* ds;
83 : JAWT_DrawingSurfaceInfo* dsi;
84 : JAWT_X11DrawingSurfaceInfo* dsi_x11;
85 :
86 : Drawable drawable;
87 :
88 : /* Get the AWT */
89 0 : awt.version = JAWT_VERSION_1_3;
90 0 : result = JAWT_GetAWT(env, &awt);
91 0 : if (result == JNI_FALSE)
92 0 : ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
93 :
94 : /* Get the drawing surface */
95 0 : if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
96 0 : return 0L;
97 :
98 : /* Lock the drawing surface */
99 0 : lock = ds->Lock(ds);
100 0 : if ( (lock & JAWT_LOCK_ERROR) != 0)
101 0 : ThrowException(env, "java/lang/RuntimeException",
102 : "Could not get AWT drawing surface.");
103 :
104 : /* Get the drawing surface info */
105 0 : dsi = ds->GetDrawingSurfaceInfo(ds);
106 :
107 : /* Get the platform-specific drawing info */
108 0 : dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
109 :
110 0 : drawable = dsi_x11->drawable;
111 :
112 : /* Free the drawing surface info */
113 0 : ds->FreeDrawingSurfaceInfo(dsi);
114 : /* Unlock the drawing surface */
115 0 : ds->Unlock(ds);
116 : /* Free the drawing surface */
117 0 : awt.FreeDrawingSurface(ds);
118 :
119 0 : return ((jlong)drawable);
120 : }
121 :
122 :
123 :
124 :
125 :
126 :
127 :
128 :
129 :
130 :
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|