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)
29 #define JAWT_GetAWT hidden_JAWT_GetAWT
34 #pragma warning(push, 1)
36 /* When cross-compiling to Windows we don't have any Windows JDK
37 * available. Copying this short snippet from win32/jawt_md.h can
38 * surely not be against its license. The intent is to enable
39 * interoperation with real Oracle Java after all. We leave out the
40 * informative comments that might have "artistic merit" and be more
41 * copyrightable. Use this also for native Windows compilation for
44 typedef struct jawt_Win32DrawingSurfaceInfo
{
52 } JAWT_Win32DrawingSurfaceInfo
;
54 extern __declspec(dllimport
) unsigned char __stdcall
JAWT_GetAWT(JNIEnv
*, JAWT
*);
59 #define SYSTEM_WIN32 1
61 #define OLD_PROC_KEY "oldwindowproc"
63 static LRESULT APIENTRY
OpenOfficeWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
65 /* type must be something like java/lang/RuntimeException
67 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
69 (*env
)->ExceptionClear(env
);
70 c
= (*env
)->FindClass(env
, type
);
72 (*env
)->ExceptionClear(env
);
74 env
, "JNI FindClass failed");
76 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
77 (*env
)->ExceptionClear(env
);
78 (*env
)->FatalError(env
, "JNI ThrowNew failed");
83 /*****************************************************************************/
85 * Class: com_sun_star_comp_beans_LocalOfficeWindow
86 * Method: getNativeWindowSystemType
89 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
90 (JNIEnv
* env
, jobject obj_this
)
93 (void) obj_this
; // unused
94 return (SYSTEM_WIN32
);
98 /*****************************************************************************/
100 * Class: com_sun_star_comp_beans_LocalOfficeWindow
101 * Method: getNativeWindow
104 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
105 (JNIEnv
* env
, jobject obj_this
)
111 JAWT_DrawingSurface
* ds
;
112 JAWT_DrawingSurfaceInfo
* dsi
;
113 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
118 awt
.version
= JAWT_VERSION_1_3
;
119 result
= JAWT_GetAWT(env
, &awt
);
120 if (result
== JNI_FALSE
)
121 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
123 /* Get the drawing surface */
124 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
127 /* Lock the drawing surface */
129 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
130 ThrowException(env
, "java/lang/RuntimeException",
131 "Could not get AWT drawing surface.");
133 /* Get the drawing surface info */
134 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
136 /* Get the platform-specific drawing info */
137 dsi_win
= (JAWT_Win32DrawingSurfaceInfo
*)dsi
->platformInfo
;
139 hWnd
= dsi_win
->hwnd
;
141 /* Free the drawing surface info */
142 ds
->FreeDrawingSurfaceInfo(dsi
);
143 /* Unlock the drawing surface */
145 /* Free the drawing surface */
146 awt
.FreeDrawingSurface(ds
);
148 /* Register own window procedure
149 Do it one times only! Otherwhise
150 multiple instances will be registered
151 and calls on such construct produce
154 if (GetProp( hWnd
, OLD_PROC_KEY
)==0)
156 hFuncPtr
= SetWindowLongPtr( hWnd
, GWLP_WNDPROC
, (LONG_PTR
)OpenOfficeWndProc
);
157 SetProp( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
160 return ((jlong
)(LONG
)hWnd
);
164 static LRESULT APIENTRY
OpenOfficeWndProc(
172 case WM_PARENTNOTIFY
: {
173 if (wParam
== WM_CREATE
) {
175 HWND hChild
= (HWND
) lParam
;
177 GetClientRect(hWnd
, &rect
);
183 rect
.right
- rect
.left
,
184 rect
.bottom
- rect
.top
,
190 WORD newHeight
= HIWORD(lParam
);
191 WORD newWidth
= LOWORD(lParam
);
192 HWND hChild
= GetWindow(hWnd
, GW_CHILD
);
194 if (hChild
!= NULL
) {
195 SetWindowPos(hChild
, NULL
, 0, 0, newWidth
, newHeight
, SWP_NOZORDER
);
202 #pragma warning(push)
203 #pragma warning(disable: 4152) /* function/data pointer conversion: */
205 return CallWindowProc(GetProp(hWnd
, OLD_PROC_KEY
),
206 hWnd
, uMsg
, wParam
, lParam
);
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */