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 #if defined _MSC_VER 25 #pragma warning(push, 1) 26 #endif 27 #include <windows.h> 28 #if defined _MSC_VER 29 #pragma warning(pop) 30 #endif 31 32 #include "jawt.h" 33 34 #if defined _MSC_VER 35 #pragma warning(push, 1) 36 #endif 37 #include "jawt_md.h" 38 #if defined _MSC_VER 39 #pragma warning(pop) 40 #endif 41 42 #define SYSTEM_WIN32 1 43 #define SYSTEM_WIN16 2 44 #define SYSTEM_JAVA 3 45 #define SYSTEM_OS2 4 46 #define SYSTEM_MAC 5 47 #define SYSTEM_XWINDOW 6 48 49 #define OLD_PROC_KEY "oldwindowproc" 50 51 static LRESULT APIENTRY OpenOfficeWndProc( HWND , UINT , WPARAM , LPARAM ); 52 53 54 55 /* type must be something like java/lang/RuntimeException 56 */ 57 static void ThrowException(JNIEnv * env, char const * type, char const * msg) { 58 jclass c; 59 (*env)->ExceptionClear(env); 60 c = (*env)->FindClass(env, type); 61 if (c == NULL) { 62 (*env)->ExceptionClear(env); 63 (*env)->FatalError( 64 env, "JNI FindClass failed"); 65 } 66 if ((*env)->ThrowNew(env, c, msg) != 0) { 67 (*env)->ExceptionClear(env); 68 (*env)->FatalError(env, "JNI ThrowNew failed"); 69 } 70 } 71 72 73 /*****************************************************************************/ 74 /* 75 * Class: com_sun_star_comp_beans_LocalOfficeWindow 76 * Method: getNativeWindowSystemType 77 * Signature: ()I 78 */ 79 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType 80 (JNIEnv * env, jobject obj_this) 81 { 82 (void) env; // unused 83 (void) obj_this; // unused 84 return (SYSTEM_WIN32); 85 } 86 87 88 /*****************************************************************************/ 89 /* 90 * Class: com_sun_star_comp_beans_LocalOfficeWindow 91 * Method: getNativeWindow 92 * Signature: ()J 93 */ 94 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow 95 (JNIEnv * env, jobject obj_this) 96 { 97 jboolean result; 98 jint lock; 99 100 JAWT awt; 101 JAWT_DrawingSurface* ds; 102 JAWT_DrawingSurfaceInfo* dsi; 103 JAWT_Win32DrawingSurfaceInfo* dsi_win; 104 HDC hdc; 105 HWND hWnd; 106 LONG hFuncPtr; 107 108 /* Get the AWT */ 109 awt.version = JAWT_VERSION_1_3; 110 result = JAWT_GetAWT(env, &awt); 111 if (result == JNI_FALSE) 112 ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed"); 113 114 /* Get the drawing surface */ 115 if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) 116 return 0L; 117 118 /* Lock the drawing surface */ 119 lock = ds->Lock(ds); 120 if ( (lock & JAWT_LOCK_ERROR) != 0) 121 ThrowException(env, "java/lang/RuntimeException", 122 "Could not get AWT drawing surface."); 123 124 /* Get the drawing surface info */ 125 dsi = ds->GetDrawingSurfaceInfo(ds); 126 127 /* Get the platform-specific drawing info */ 128 dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; 129 130 hdc = dsi_win->hdc; 131 132 hWnd = dsi_win->hwnd; 133 134 /* Free the drawing surface info */ 135 ds->FreeDrawingSurfaceInfo(dsi); 136 /* Unlock the drawing surface */ 137 ds->Unlock(ds); 138 /* Free the drawing surface */ 139 awt.FreeDrawingSurface(ds); 140 141 /* Register own window procedure 142 Do it one times only! Otherwhise 143 multiple instances will be registered 144 and calls on such construct produce 145 a stack overflow. 146 */ 147 if (GetProp( hWnd, OLD_PROC_KEY )==0) 148 { 149 hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)OpenOfficeWndProc ); 150 SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr ); 151 } 152 153 return ((jlong)hWnd); 154 } 155 156 157 static LRESULT APIENTRY OpenOfficeWndProc( 158 HWND hWnd, 159 UINT uMsg, 160 WPARAM wParam, 161 LPARAM lParam) 162 { 163 switch(uMsg) 164 { 165 case WM_PARENTNOTIFY: { 166 if (wParam == WM_CREATE) { 167 RECT rect; 168 HWND hChild = (HWND) lParam; 169 170 GetClientRect(hWnd, &rect); 171 172 SetWindowPos(hChild, 173 NULL, 174 rect.left, 175 rect.top, 176 rect.right - rect.left, 177 rect.bottom - rect.top, 178 SWP_NOZORDER); 179 } 180 break; 181 } 182 case WM_SIZE: { 183 WORD newHeight = HIWORD(lParam); 184 WORD newWidth = LOWORD(lParam); 185 HWND hChild = GetWindow(hWnd, GW_CHILD); 186 187 if (hChild != NULL) { 188 SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER); 189 } 190 break; 191 } 192 } 193 194 #if defined _MSC_VER 195 #pragma warning(push) 196 #pragma warning(disable: 4152) /* function/data pointer conversion: */ 197 #endif 198 return CallWindowProc(GetProp(hWnd, OLD_PROC_KEY), 199 hWnd, uMsg, wParam, lParam); 200 #if defined _MSC_VER 201 #pragma warning(pop) 202 #endif 203 } 204 205 206 207 208 209 210 211 212 213 214