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 .
21 #pragma warning(push, 1)
28 #define JAWT_GetAWT hidden_JAWT_GetAWT
33 #pragma warning(push, 1)
35 /* When cross-compiling to Windows we don't have any Windows JDK
36 * available. Copying this short snippet from win32/jawt_md.h can
37 * surely not be against its license. The intent is to enable
38 * interoperation with real Oracle Java after all. We leave out the
39 * informative comments that might have "artistic merit" and be more
40 * copyrightable. Use this also for native Windows compilation for
43 typedef struct jawt_Win32DrawingSurfaceInfo
{
51 } JAWT_Win32DrawingSurfaceInfo
;
53 JNIIMPORT
unsigned char JNICALL
JAWT_GetAWT(JNIEnv
*, JAWT
*);
58 #define SYSTEM_WIN32 1
60 #define OLD_PROC_KEY "oldwindowproc"
62 static LRESULT APIENTRY
OpenOfficeWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
64 /* type must be something like java/lang/RuntimeException
66 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
68 (*env
)->ExceptionClear(env
);
69 c
= (*env
)->FindClass(env
, type
);
71 (*env
)->ExceptionClear(env
);
73 env
, "JNI FindClass failed");
75 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
76 (*env
)->ExceptionClear(env
);
77 (*env
)->FatalError(env
, "JNI ThrowNew failed");
82 /*****************************************************************************/
84 * Class: com_sun_star_comp_beans_LocalOfficeWindow
85 * Method: getNativeWindowSystemType
88 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
89 (JNIEnv
* env
, jobject obj_this
)
92 (void) obj_this
; // unused
97 /*****************************************************************************/
99 * Class: com_sun_star_comp_beans_LocalOfficeWindow
100 * Method: getNativeWindow
103 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
104 (JNIEnv
* env
, jobject obj_this
)
110 JAWT_DrawingSurface
* ds
;
111 JAWT_DrawingSurfaceInfo
* dsi
;
112 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
117 awt
.version
= JAWT_VERSION_1_3
;
118 result
= JAWT_GetAWT(env
, &awt
);
119 if (result
== JNI_FALSE
)
120 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
122 /* Get the drawing surface */
123 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
126 /* Lock the drawing surface */
128 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
129 ThrowException(env
, "java/lang/RuntimeException",
130 "Could not get AWT drawing surface.");
132 /* Get the drawing surface info */
133 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
135 /* Get the platform-specific drawing info */
136 dsi_win
= (JAWT_Win32DrawingSurfaceInfo
*)dsi
->platformInfo
;
138 hWnd
= dsi_win
->hwnd
;
140 /* Free the drawing surface info */
141 ds
->FreeDrawingSurfaceInfo(dsi
);
142 /* Unlock the drawing surface */
144 /* Free the drawing surface */
145 awt
.FreeDrawingSurface(ds
);
147 /* Register own window procedure
148 Do it one times only! Otherwhise
149 multiple instances will be registered
150 and calls on such construct produce
153 if (GetProp( hWnd
, OLD_PROC_KEY
)==0)
155 hFuncPtr
= SetWindowLongPtr( hWnd
, GWLP_WNDPROC
, (LONG_PTR
)OpenOfficeWndProc
);
156 SetProp( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
163 static LRESULT APIENTRY
OpenOfficeWndProc(
171 case WM_PARENTNOTIFY
: {
172 if (wParam
== WM_CREATE
) {
174 HWND hChild
= (HWND
) lParam
;
176 GetClientRect(hWnd
, &rect
);
182 rect
.right
- rect
.left
,
183 rect
.bottom
- rect
.top
,
189 WORD newHeight
= HIWORD(lParam
);
190 WORD newWidth
= LOWORD(lParam
);
191 HWND hChild
= GetWindow(hWnd
, GW_CHILD
);
193 if (hChild
!= NULL
) {
194 SetWindowPos(hChild
, NULL
, 0, 0, newWidth
, newHeight
, SWP_NOZORDER
);
201 #pragma warning(push)
202 #pragma warning(disable: 4152) /* function/data pointer conversion: */
204 return CallWindowProc(GetProp(hWnd
, OLD_PROC_KEY
),
205 hWnd
, uMsg
, wParam
, lParam
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */