1*984c6370SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*984c6370SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*984c6370SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*984c6370SAndrew Rist * distributed with this work for additional information
6*984c6370SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*984c6370SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*984c6370SAndrew Rist * "License"); you may not use this file except in compliance
9*984c6370SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*984c6370SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*984c6370SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*984c6370SAndrew Rist * software distributed under the License is distributed on an
15*984c6370SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*984c6370SAndrew Rist * KIND, either express or implied. See the License for the
17*984c6370SAndrew Rist * specific language governing permissions and limitations
18*984c6370SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*984c6370SAndrew Rist *************************************************************/
21*984c6370SAndrew Rist
22*984c6370SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifdef WNT
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <windows.h>
27cdf0e10cSrcweir // property name to register own window procedure on hwnd
28cdf0e10cSrcweir #define OLD_PROC_KEY "oldwindowproc"
29cdf0e10cSrcweir // signature of this window procedure
30cdf0e10cSrcweir static LRESULT APIENTRY NativeViewWndProc( HWND , UINT , WPARAM , LPARAM );
31cdf0e10cSrcweir
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "jawt.h"
35cdf0e10cSrcweir #include "jawt_md.h"
36cdf0e10cSrcweir #include "NativeView.h"
37cdf0e10cSrcweir
38cdf0e10cSrcweir #define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
39cdf0e10cSrcweir
40cdf0e10cSrcweir #define SYSTEM_WIN32 1
41cdf0e10cSrcweir #define SYSTEM_WIN16 2
42cdf0e10cSrcweir #define SYSTEM_JAVA 3
43cdf0e10cSrcweir #define SYSTEM_OS2 4
44cdf0e10cSrcweir #define SYSTEM_MAC 5
45cdf0e10cSrcweir #define SYSTEM_XWINDOW 6
46cdf0e10cSrcweir
47cdf0e10cSrcweir /*****************************************************************************
48cdf0e10cSrcweir *
49cdf0e10cSrcweir * Class : NativeView
50cdf0e10cSrcweir * Method : getNativeWindowSystemType
51cdf0e10cSrcweir * Signature : ()I
52cdf0e10cSrcweir * Description: returns an identifier for the current operating system
53cdf0e10cSrcweir */
Java_embeddedobj_test_NativeView_getNativeWindowSystemType(JNIEnv * env,jobject obj_this)54cdf0e10cSrcweir JNIEXPORT jint JNICALL Java_embeddedobj_test_NativeView_getNativeWindowSystemType
55cdf0e10cSrcweir (JNIEnv * env, jobject obj_this)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir return (SYSTEM_WIN32);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
60cdf0e10cSrcweir /*****************************************************************************
61cdf0e10cSrcweir *
62cdf0e10cSrcweir * Class : NativeView
63cdf0e10cSrcweir * Method : getNativeWindow
64cdf0e10cSrcweir * Signature : ()J
65cdf0e10cSrcweir * Description: returns the native systemw window handle of this object
66cdf0e10cSrcweir */
Java_embeddedobj_test_NativeView_getNativeWindow(JNIEnv * env,jobject obj_this)67cdf0e10cSrcweir JNIEXPORT jlong JNICALL Java_embeddedobj_test_NativeView_getNativeWindow
68cdf0e10cSrcweir (JNIEnv * env, jobject obj_this)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir jboolean result ;
71cdf0e10cSrcweir jint lock ;
72cdf0e10cSrcweir JAWT awt ;
73cdf0e10cSrcweir JAWT_DrawingSurface* ds ;
74cdf0e10cSrcweir JAWT_DrawingSurfaceInfo* dsi ;
75cdf0e10cSrcweir JAWT_Win32DrawingSurfaceInfo* dsi_win ;
76cdf0e10cSrcweir jlong drawable;
77cdf0e10cSrcweir
78cdf0e10cSrcweir #if 0
79cdf0e10cSrcweir LONG hFuncPtr;
80cdf0e10cSrcweir #endif
81cdf0e10cSrcweir
82cdf0e10cSrcweir /* Get the AWT */
83cdf0e10cSrcweir awt.version = JAWT_VERSION_1_3;
84cdf0e10cSrcweir result = JAWT_GetAWT(env, &awt);
85cdf0e10cSrcweir MY_ASSERT(result!=JNI_FALSE,"wrong jawt version");
86cdf0e10cSrcweir
87cdf0e10cSrcweir /* Get the drawing surface */
88cdf0e10cSrcweir if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
89cdf0e10cSrcweir return 0L;
90cdf0e10cSrcweir
91cdf0e10cSrcweir /* Lock the drawing surface */
92cdf0e10cSrcweir lock = ds->Lock(ds);
93cdf0e10cSrcweir MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
94cdf0e10cSrcweir
95cdf0e10cSrcweir /* Get the drawing surface info */
96cdf0e10cSrcweir dsi = ds->GetDrawingSurfaceInfo(ds);
97cdf0e10cSrcweir
98cdf0e10cSrcweir /* Get the platform-specific drawing info */
99cdf0e10cSrcweir #ifdef WNT
100cdf0e10cSrcweir dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
101cdf0e10cSrcweir drawable = (jlong)dsi_win->hwnd;
102cdf0e10cSrcweir #else
103cdf0e10cSrcweir dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
104cdf0e10cSrcweir drawable = (jlong)dsi_x11->drawable;
105cdf0e10cSrcweir #endif
106cdf0e10cSrcweir
107cdf0e10cSrcweir /* Free the drawing surface info */
108cdf0e10cSrcweir ds->FreeDrawingSurfaceInfo(dsi);
109cdf0e10cSrcweir /* Unlock the drawing surface */
110cdf0e10cSrcweir ds->Unlock(ds);
111cdf0e10cSrcweir /* Free the drawing surface */
112cdf0e10cSrcweir awt.FreeDrawingSurface(ds);
113cdf0e10cSrcweir
114cdf0e10cSrcweir #if 0
115cdf0e10cSrcweir /* Register own window procedure
116cdf0e10cSrcweir Do it one times only! Otherwhise
117cdf0e10cSrcweir multiple instances will be registered
118cdf0e10cSrcweir and calls on such construct produce
119cdf0e10cSrcweir a stack overflow.
120cdf0e10cSrcweir */
121cdf0e10cSrcweir
122cdf0e10cSrcweir if (GetProp( (HWND)drawable, OLD_PROC_KEY )==0)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir hFuncPtr = SetWindowLong( (HWND)drawable, GWL_WNDPROC, (DWORD)NativeViewWndProc );
125cdf0e10cSrcweir SetProp( (HWND)drawable, OLD_PROC_KEY, (HANDLE)hFuncPtr );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir #endif
128cdf0e10cSrcweir
129cdf0e10cSrcweir return drawable;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir #if 0
133cdf0e10cSrcweir /*****************************************************************************
134cdf0e10cSrcweir *
135cdf0e10cSrcweir * Class : -
136cdf0e10cSrcweir * Method : NativeViewWndProc
137cdf0e10cSrcweir * Signature : -
138cdf0e10cSrcweir * Description: registered window handler to intercept window messages between
139cdf0e10cSrcweir * java and office process
140cdf0e10cSrcweir */
141cdf0e10cSrcweir static LRESULT APIENTRY NativeViewWndProc(
142cdf0e10cSrcweir HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir HANDLE hFuncPtr;
145cdf0e10cSrcweir
146cdf0e10cSrcweir /* resize new created child window to fill out the java window complete */
147cdf0e10cSrcweir if (uMsg==WM_PARENTNOTIFY)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir if (wParam == WM_CREATE)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir RECT rect;
152cdf0e10cSrcweir HWND hChild = (HWND) lParam;
153cdf0e10cSrcweir
154cdf0e10cSrcweir GetClientRect(hWnd, &rect);
155cdf0e10cSrcweir
156cdf0e10cSrcweir SetWindowPos(hChild,
157cdf0e10cSrcweir NULL,
158cdf0e10cSrcweir rect.left,
159cdf0e10cSrcweir rect.top,
160cdf0e10cSrcweir rect.right - rect.left,
161cdf0e10cSrcweir rect.bottom - rect.top,
162cdf0e10cSrcweir SWP_NOZORDER);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir /* handle normal resize events */
166cdf0e10cSrcweir else if(uMsg==WM_SIZE)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir WORD newHeight = HIWORD(lParam);
169cdf0e10cSrcweir WORD newWidth = LOWORD(lParam);
170cdf0e10cSrcweir HWND hChild = GetWindow(hWnd, GW_CHILD);
171cdf0e10cSrcweir
172cdf0e10cSrcweir if (hChild != NULL)
173cdf0e10cSrcweir SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir /* forward request to original handler which is intercepted by this window procedure */
177cdf0e10cSrcweir hFuncPtr = GetProp(hWnd, OLD_PROC_KEY);
178cdf0e10cSrcweir MY_ASSERT(hFuncPtr,"lost original window proc handler");
179cdf0e10cSrcweir return CallWindowProc( hFuncPtr, hWnd, uMsg, wParam, lParam);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir #endif
182cdf0e10cSrcweir
183