1 /*************************************************************************
3 * $RCSfile: nativeview.c,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:42:03 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
45 #include "NativeView.h"
47 #define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
49 #define SYSTEM_WIN32 1
50 #define SYSTEM_WIN16 2
54 #define SYSTEM_XWINDOW 6
56 // property name to register own window procedure on hwnd
57 #define OLD_PROC_KEY "oldwindowproc"
58 // signature of this window procedure
59 static LRESULT APIENTRY
NativeViewWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
61 /*****************************************************************************
64 * Method : getNativeWindowSystemType
66 * Description: returns an identifier for the current operating system
68 JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
69 (JNIEnv
* env
, jobject obj_this
)
71 return (SYSTEM_WIN32
);
74 /*****************************************************************************
77 * Method : getNativeWindow
79 * Description: returns the native systemw window handle of this object
81 JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
82 (JNIEnv
* env
, jobject obj_this
)
87 JAWT_DrawingSurface
* ds
;
88 JAWT_DrawingSurfaceInfo
* dsi
;
89 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
95 awt
.version
= JAWT_VERSION_1_3
;
96 result
= JAWT_GetAWT(env
, &awt
);
97 MY_ASSERT(result
!=JNI_FALSE
,"wrong jawt version");
99 /* Get the drawing surface */
100 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
103 /* Lock the drawing surface */
105 MY_ASSERT((lock
& JAWT_LOCK_ERROR
)==0,"can't lock the drawing surface");
107 /* Get the drawing surface info */
108 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
110 /* Get the platform-specific drawing info */
111 dsi_win
= (JAWT_Win32DrawingSurfaceInfo
*)dsi
->platformInfo
;
113 hWnd
= dsi_win
->hwnd
;
115 /* Free the drawing surface info */
116 ds
->FreeDrawingSurfaceInfo(dsi
);
117 /* Unlock the drawing surface */
119 /* Free the drawing surface */
120 awt
.FreeDrawingSurface(ds
);
122 /* Register own window procedure
123 Do it one times only! Otherwhise
124 multiple instances will be registered
125 and calls on such construct produce
128 if (GetProp( hWnd
, OLD_PROC_KEY
)==0)
130 hFuncPtr
= SetWindowLong( hWnd
, GWL_WNDPROC
, (DWORD
)NativeViewWndProc
);
131 SetProp( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
134 return ((jlong
)hWnd
);
137 /*****************************************************************************
140 * Method : NativeViewWndProc
142 * Description: registered window handler to intercept window messages between
143 * java and office process
145 static LRESULT APIENTRY
NativeViewWndProc(
146 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
150 /* resize new created child window to fill out the java window complete */
151 if (uMsg
==WM_PARENTNOTIFY
)
153 if (wParam
== WM_CREATE
)
156 HWND hChild
= (HWND
) lParam
;
158 GetClientRect(hWnd
, &rect
);
164 rect
.right
- rect
.left
,
165 rect
.bottom
- rect
.top
,
169 /* handle normal resize events */
170 else if(uMsg
==WM_SIZE
)
172 WORD newHeight
= HIWORD(lParam
);
173 WORD newWidth
= LOWORD(lParam
);
174 HWND hChild
= GetWindow(hWnd
, GW_CHILD
);
177 SetWindowPos(hChild
, NULL
, 0, 0, newWidth
, newHeight
, SWP_NOZORDER
);
180 /* forward request to original handler which is intercepted by this window procedure */
181 hFuncPtr
= GetProp(hWnd
, OLD_PROC_KEY
);
182 MY_ASSERT(hFuncPtr
,"lost original window proc handler");
183 return CallWindowProc( hFuncPtr
, hWnd
, uMsg
, wParam
, lParam
);