merge the formfield patch from ooo-build
[ooovba.git] / bean / native / win32 / com_sun_star_comp_beans_LocalOfficeWindow.c
blobd3cbb9e2e1881710af2001a1ddd2be742778ee01
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 #if defined _MSC_VER
32 #pragma warning(push, 1)
33 #endif
34 #include <windows.h>
35 #if defined _MSC_VER
36 #pragma warning(pop)
37 #endif
39 #include "jawt.h"
41 #if defined _MSC_VER
42 #pragma warning(push, 1)
43 #endif
44 #include "jawt_md.h"
45 #if defined _MSC_VER
46 #pragma warning(pop)
47 #endif
49 #define SYSTEM_WIN32 1
50 #define SYSTEM_WIN16 2
51 #define SYSTEM_JAVA 3
52 #define SYSTEM_OS2 4
53 #define SYSTEM_MAC 5
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) {
65 jclass c;
66 (*env)->ExceptionClear(env);
67 c = (*env)->FindClass(env, type);
68 if (c == NULL) {
69 (*env)->ExceptionClear(env);
70 (*env)->FatalError(
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
84 * Signature: ()I
86 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
87 (JNIEnv * env, jobject obj_this)
89 (void) env; // unused
90 (void) obj_this; // unused
91 return (SYSTEM_WIN32);
95 /*****************************************************************************/
97 * Class: com_sun_star_comp_beans_LocalOfficeWindow
98 * Method: getNativeWindow
99 * Signature: ()J
101 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
102 (JNIEnv * env, jobject obj_this)
104 jboolean result;
105 jint lock;
107 JAWT awt;
108 JAWT_DrawingSurface* ds;
109 JAWT_DrawingSurfaceInfo* dsi;
110 JAWT_Win32DrawingSurfaceInfo* dsi_win;
111 HDC hdc;
112 HWND hWnd;
113 LONG hFuncPtr;
115 /* Get the AWT */
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)
123 return 0L;
125 /* Lock the drawing surface */
126 lock = ds->Lock(ds);
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;
137 hdc = dsi_win->hdc;
139 hWnd = dsi_win->hwnd;
141 /* Free the drawing surface info */
142 ds->FreeDrawingSurfaceInfo(dsi);
143 /* Unlock the drawing surface */
144 ds->Unlock(ds);
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
152 a stack overflow.
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(
165 HWND hWnd,
166 UINT uMsg,
167 WPARAM wParam,
168 LPARAM lParam)
170 switch(uMsg)
172 case WM_PARENTNOTIFY: {
173 if (wParam == WM_CREATE) {
174 RECT rect;
175 HWND hChild = (HWND) lParam;
177 GetClientRect(hWnd, &rect);
179 SetWindowPos(hChild,
180 NULL,
181 rect.left,
182 rect.top,
183 rect.right - rect.left,
184 rect.bottom - rect.top,
185 SWP_NOZORDER);
187 break;
189 case WM_SIZE: {
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);
197 break;
201 #if defined _MSC_VER
202 #pragma warning(push)
203 #pragma warning(disable: 4152) /* function/data pointer conversion: */
204 #endif
205 return CallWindowProc(GetProp(hWnd, OLD_PROC_KEY),
206 hWnd, uMsg, wParam, lParam);
207 #if defined _MSC_VER
208 #pragma warning(pop)
209 #endif