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 .
20 #if !defined WIN32_LEAN_AND_MEAN
21 # define WIN32_LEAN_AND_MEAN
27 #pragma warning(disable : 4201) /* nonstandard extension used: nameless struct/union */
34 #define SYSTEM_WIN32 1
36 #define OLD_PROC_KEY L"oldwindowproc"
38 static LRESULT APIENTRY
OpenOfficeWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
40 /* type must be something like java/lang/RuntimeException
42 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
44 (*env
)->ExceptionClear(env
);
45 c
= (*env
)->FindClass(env
, type
);
47 (*env
)->ExceptionClear(env
);
49 env
, "JNI FindClass failed");
51 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
52 (*env
)->ExceptionClear(env
);
53 (*env
)->FatalError(env
, "JNI ThrowNew failed");
58 /*****************************************************************************/
60 * Class: com_sun_star_comp_beans_LocalOfficeWindow
61 * Method: getNativeWindowSystemType
64 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
65 (JNIEnv
* env
, jobject obj_this
)
68 (void) obj_this
; // unused
73 /*****************************************************************************/
75 * Class: com_sun_star_comp_beans_LocalOfficeWindow
76 * Method: getNativeWindow
79 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
80 (JNIEnv
* env
, jobject obj_this
)
86 JAWT_DrawingSurface
* ds
;
87 JAWT_DrawingSurfaceInfo
* dsi
;
88 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
93 awt
.version
= JAWT_VERSION_1_3
;
94 result
= JAWT_GetAWT(env
, &awt
);
95 if (result
== JNI_FALSE
)
96 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
98 /* Get the drawing surface */
99 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
102 /* Lock the drawing surface */
104 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
105 ThrowException(env
, "java/lang/RuntimeException",
106 "Could not get AWT drawing surface.");
108 /* Get the drawing surface info */
109 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
111 /* Get the platform-specific drawing info */
112 dsi_win
= (JAWT_Win32DrawingSurfaceInfo
*)dsi
->platformInfo
;
114 hWnd
= dsi_win
->hwnd
;
116 /* Free the drawing surface info */
117 ds
->FreeDrawingSurfaceInfo(dsi
);
118 /* Unlock the drawing surface */
120 /* Free the drawing surface */
121 awt
.FreeDrawingSurface(ds
);
123 /* Register own window procedure
124 Do it one times only! Otherwise
125 multiple instances will be registered
126 and calls on such construct produce
129 if (GetPropW( hWnd
, OLD_PROC_KEY
)==NULL
)
131 hFuncPtr
= SetWindowLongPtrW( hWnd
, GWLP_WNDPROC
, (LONG_PTR
)OpenOfficeWndProc
);
132 SetPropW( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
139 static LRESULT APIENTRY
OpenOfficeWndProc(
147 case WM_PARENTNOTIFY
: {
148 if (wParam
== WM_CREATE
) {
150 HWND hChild
= (HWND
) lParam
;
152 GetClientRect(hWnd
, &rect
);
158 rect
.right
- rect
.left
,
159 rect
.bottom
- rect
.top
,
165 WORD newHeight
= HIWORD(lParam
);
166 WORD newWidth
= LOWORD(lParam
);
167 HWND hChild
= GetWindow(hWnd
, GW_CHILD
);
169 if (hChild
!= NULL
) {
170 SetWindowPos(hChild
, NULL
, 0, 0, newWidth
, newHeight
, SWP_NOZORDER
);
177 #pragma warning(push)
178 #pragma warning(disable: 4152) /* function/data pointer conversion: */
180 return CallWindowProcW(GetPropW(hWnd
, OLD_PROC_KEY
),
181 hWnd
, uMsg
, wParam
, lParam
);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */