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