1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: com_sun_star_comp_beans_LocalOfficeWindow.c,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #pragma warning(push, 1)
42 #pragma warning(push, 1)
49 #define SYSTEM_WIN32 1
50 #define SYSTEM_WIN16 2
54 #define SYSTEM_XWINDOW 6
56 #define OLD_PROC_KEY "oldwindowproc"
58 static LRESULT APIENTRY
OpenOfficeWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
62 /* type must be something like java/lang/RuntimeException
64 static void ThrowException(JNIEnv
* env
, char const * type
, char const * msg
) {
66 (*env
)->ExceptionClear(env
);
67 c
= (*env
)->FindClass(env
, type
);
69 (*env
)->ExceptionClear(env
);
71 env
, "JNI FindClass failed");
73 if ((*env
)->ThrowNew(env
, c
, msg
) != 0) {
74 (*env
)->ExceptionClear(env
);
75 (*env
)->FatalError(env
, "JNI ThrowNew failed");
80 /*****************************************************************************/
82 * Class: com_sun_star_comp_beans_LocalOfficeWindow
83 * Method: getNativeWindowSystemType
86 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
87 (JNIEnv
* env
, jobject obj_this
)
90 (void) obj_this
; // unused
91 return (SYSTEM_WIN32
);
95 /*****************************************************************************/
97 * Class: com_sun_star_comp_beans_LocalOfficeWindow
98 * Method: getNativeWindow
101 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
102 (JNIEnv
* env
, jobject obj_this
)
108 JAWT_DrawingSurface
* ds
;
109 JAWT_DrawingSurfaceInfo
* dsi
;
110 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
116 awt
.version
= JAWT_VERSION_1_3
;
117 result
= JAWT_GetAWT(env
, &awt
);
118 if (result
== JNI_FALSE
)
119 ThrowException(env
, "java/lang/RuntimeException", "JAWT_GetAWT failed");
121 /* Get the drawing surface */
122 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
125 /* Lock the drawing surface */
127 if ( (lock
& JAWT_LOCK_ERROR
) != 0)
128 ThrowException(env
, "java/lang/RuntimeException",
129 "Could not get AWT drawing surface.");
131 /* Get the drawing surface info */
132 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
134 /* Get the platform-specific drawing info */
135 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
= SetWindowLong( hWnd
, GWL_WNDPROC
, (DWORD
)OpenOfficeWndProc
);
157 SetProp( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
160 return ((jlong
)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
);