xref: /AOO41X/main/bean/native/win32/com_sun_star_comp_beans_LocalOfficeWindow.c (revision 9478c1a8c809f638c9fa3416d5dd33249e1ccdce)
1*9478c1a8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9478c1a8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9478c1a8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9478c1a8SAndrew Rist  * distributed with this work for additional information
6*9478c1a8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9478c1a8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9478c1a8SAndrew Rist  * "License"); you may not use this file except in compliance
9*9478c1a8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9478c1a8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9478c1a8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9478c1a8SAndrew Rist  * software distributed under the License is distributed on an
15*9478c1a8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9478c1a8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9478c1a8SAndrew Rist  * specific language governing permissions and limitations
18*9478c1a8SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9478c1a8SAndrew Rist  *************************************************************/
21*9478c1a8SAndrew Rist 
22*9478c1a8SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #if defined _MSC_VER
25cdf0e10cSrcweir #pragma warning(push, 1)
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir #include <windows.h>
28cdf0e10cSrcweir #if defined _MSC_VER
29cdf0e10cSrcweir #pragma warning(pop)
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "jawt.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #if defined _MSC_VER
35cdf0e10cSrcweir #pragma warning(push, 1)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include "jawt_md.h"
38cdf0e10cSrcweir #if defined _MSC_VER
39cdf0e10cSrcweir #pragma warning(pop)
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define SYSTEM_WIN32   1
43cdf0e10cSrcweir #define SYSTEM_WIN16   2
44cdf0e10cSrcweir #define SYSTEM_JAVA    3
45cdf0e10cSrcweir #define SYSTEM_OS2     4
46cdf0e10cSrcweir #define SYSTEM_MAC     5
47cdf0e10cSrcweir #define SYSTEM_XWINDOW 6
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #define OLD_PROC_KEY "oldwindowproc"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir static LRESULT APIENTRY OpenOfficeWndProc( HWND , UINT , WPARAM , LPARAM );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /* type must be something like java/lang/RuntimeException
56cdf0e10cSrcweir  */
ThrowException(JNIEnv * env,char const * type,char const * msg)57cdf0e10cSrcweir static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
58cdf0e10cSrcweir     jclass c;
59cdf0e10cSrcweir     (*env)->ExceptionClear(env);
60cdf0e10cSrcweir     c = (*env)->FindClass(env, type);
61cdf0e10cSrcweir     if (c == NULL) {
62cdf0e10cSrcweir         (*env)->ExceptionClear(env);
63cdf0e10cSrcweir         (*env)->FatalError(
64cdf0e10cSrcweir             env, "JNI FindClass failed");
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir     if ((*env)->ThrowNew(env, c, msg) != 0) {
67cdf0e10cSrcweir         (*env)->ExceptionClear(env);
68cdf0e10cSrcweir         (*env)->FatalError(env, "JNI ThrowNew failed");
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir /*****************************************************************************/
74cdf0e10cSrcweir /*
75cdf0e10cSrcweir  * Class:     com_sun_star_comp_beans_LocalOfficeWindow
76cdf0e10cSrcweir  * Method:    getNativeWindowSystemType
77cdf0e10cSrcweir  * Signature: ()I
78cdf0e10cSrcweir  */
Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType(JNIEnv * env,jobject obj_this)79cdf0e10cSrcweir JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
80cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     (void) env; // unused
83cdf0e10cSrcweir     (void) obj_this; // unused
84cdf0e10cSrcweir     return (SYSTEM_WIN32);
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /*****************************************************************************/
89cdf0e10cSrcweir /*
90cdf0e10cSrcweir  * Class:     com_sun_star_comp_beans_LocalOfficeWindow
91cdf0e10cSrcweir  * Method:    getNativeWindow
92cdf0e10cSrcweir  * Signature: ()J
93cdf0e10cSrcweir  */
Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow(JNIEnv * env,jobject obj_this)94cdf0e10cSrcweir JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
95cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	jboolean result;
98cdf0e10cSrcweir 	jint lock;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	JAWT awt;
101cdf0e10cSrcweir 	JAWT_DrawingSurface* ds;
102cdf0e10cSrcweir 	JAWT_DrawingSurfaceInfo* dsi;
103cdf0e10cSrcweir 	JAWT_Win32DrawingSurfaceInfo* dsi_win;
104cdf0e10cSrcweir 	HDC hdc;
105cdf0e10cSrcweir 	HWND hWnd;
106cdf0e10cSrcweir     LONG hFuncPtr;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	/* Get the AWT */
109cdf0e10cSrcweir 	awt.version = JAWT_VERSION_1_3;
110cdf0e10cSrcweir 	result = JAWT_GetAWT(env, &awt);
111cdf0e10cSrcweir 	if (result == JNI_FALSE)
112cdf0e10cSrcweir         ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 								/* Get the drawing surface */
115cdf0e10cSrcweir 	if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
116cdf0e10cSrcweir 		return 0L;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	/* Lock the drawing surface */
119cdf0e10cSrcweir 	lock = ds->Lock(ds);
120cdf0e10cSrcweir 	if ( (lock & JAWT_LOCK_ERROR) != 0)
121cdf0e10cSrcweir         ThrowException(env, "java/lang/RuntimeException",
122cdf0e10cSrcweir                        "Could not get AWT drawing surface.");
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	/* Get the drawing surface info */
125cdf0e10cSrcweir 	dsi = ds->GetDrawingSurfaceInfo(ds);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	/* Get the platform-specific drawing info */
128cdf0e10cSrcweir 	dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	hdc = dsi_win->hdc;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	hWnd = dsi_win->hwnd;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	/* Free the drawing surface info */
135cdf0e10cSrcweir 	ds->FreeDrawingSurfaceInfo(dsi);
136cdf0e10cSrcweir 	/* Unlock the drawing surface */
137cdf0e10cSrcweir 	ds->Unlock(ds);
138cdf0e10cSrcweir 	/* Free the drawing surface */
139cdf0e10cSrcweir 	awt.FreeDrawingSurface(ds);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     /* Register own window procedure
142cdf0e10cSrcweir        Do it one times only! Otherwhise
143cdf0e10cSrcweir        multiple instances will be registered
144cdf0e10cSrcweir        and calls on such construct produce
145cdf0e10cSrcweir        a stack overflow.
146cdf0e10cSrcweir      */
147cdf0e10cSrcweir     if (GetProp( hWnd, OLD_PROC_KEY )==0)
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)OpenOfficeWndProc );
150cdf0e10cSrcweir         SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr );
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	return ((jlong)hWnd);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
OpenOfficeWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)157cdf0e10cSrcweir static LRESULT APIENTRY OpenOfficeWndProc(
158cdf0e10cSrcweir 	HWND hWnd,
159cdf0e10cSrcweir 	UINT uMsg,
160cdf0e10cSrcweir 	WPARAM wParam,
161cdf0e10cSrcweir 	LPARAM lParam)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     switch(uMsg)
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir 		case WM_PARENTNOTIFY: {
166cdf0e10cSrcweir 			if (wParam == WM_CREATE) {
167cdf0e10cSrcweir 				RECT rect;
168cdf0e10cSrcweir 				HWND hChild = (HWND) lParam;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 				GetClientRect(hWnd, &rect);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 				SetWindowPos(hChild,
173cdf0e10cSrcweir 							 NULL,
174cdf0e10cSrcweir 							 rect.left,
175cdf0e10cSrcweir 							 rect.top,
176cdf0e10cSrcweir 							 rect.right - rect.left,
177cdf0e10cSrcweir 							 rect.bottom - rect.top,
178cdf0e10cSrcweir 							 SWP_NOZORDER);
179cdf0e10cSrcweir 			}
180cdf0e10cSrcweir 			break;
181cdf0e10cSrcweir 		}
182cdf0e10cSrcweir 		case WM_SIZE: {
183cdf0e10cSrcweir 			WORD newHeight = HIWORD(lParam);
184cdf0e10cSrcweir 			WORD newWidth = LOWORD(lParam);
185cdf0e10cSrcweir 			HWND hChild = GetWindow(hWnd, GW_CHILD);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 			if (hChild != NULL) {
188cdf0e10cSrcweir 				SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
189cdf0e10cSrcweir 			}
190cdf0e10cSrcweir 			break;
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir #if defined _MSC_VER
195cdf0e10cSrcweir #pragma warning(push)
196cdf0e10cSrcweir #pragma warning(disable: 4152) /* function/data pointer conversion: */
197cdf0e10cSrcweir #endif
198cdf0e10cSrcweir 	return CallWindowProc(GetProp(hWnd, OLD_PROC_KEY),
199cdf0e10cSrcweir 						  hWnd, uMsg, wParam, lParam);
200cdf0e10cSrcweir #if defined _MSC_VER
201cdf0e10cSrcweir #pragma warning(pop)
202cdf0e10cSrcweir #endif
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214