1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
40 #include "NativeView.h"
42 #define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0;}
44 #define SYSTEM_WIN32 1
45 #define SYSTEM_WIN16 2
49 #define SYSTEM_XWINDOW 6
51 // property name to register own window procedure on hwnd
52 #define OLD_PROC_KEY "oldwindowproc"
53 // signature of this window procedure
54 static LRESULT APIENTRY
NativeViewWndProc( HWND
, UINT
, WPARAM
, LPARAM
);
56 /*****************************************************************************
59 * Method : getNativeWindowSystemType
61 * Description: returns an identifier for the current operating system
63 JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
64 (JNIEnv
* env
, jobject obj_this
)
69 /*****************************************************************************
72 * Method : getNativeWindow
74 * Description: returns the native systemw window handle of this object
76 JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
77 (JNIEnv
* env
, jobject obj_this
)
82 JAWT_DrawingSurface
* ds
;
83 JAWT_DrawingSurfaceInfo
* dsi
;
84 JAWT_Win32DrawingSurfaceInfo
* dsi_win
;
90 awt
.version
= JAWT_VERSION_1_3
;
91 result
= JAWT_GetAWT(env
, &awt
);
92 MY_ASSERT(result
!=JNI_FALSE
,"wrong jawt version");
94 /* Get the drawing surface */
95 if ((ds
= awt
.GetDrawingSurface(env
, obj_this
)) == NULL
)
98 /* Lock the drawing surface */
100 MY_ASSERT((lock
& JAWT_LOCK_ERROR
)==0,"can't lock the drawing surface");
102 /* Get the drawing surface info */
103 dsi
= ds
->GetDrawingSurfaceInfo(ds
);
105 /* Get the platform-specific drawing info */
106 dsi_win
= (JAWT_Win32DrawingSurfaceInfo
*)dsi
->platformInfo
;
108 hWnd
= dsi_win
->hwnd
;
110 /* Free the drawing surface info */
111 ds
->FreeDrawingSurfaceInfo(dsi
);
112 /* Unlock the drawing surface */
114 /* Free the drawing surface */
115 awt
.FreeDrawingSurface(ds
);
117 /* Register own window procedure
118 Do it one times only! Otherwise
119 multiple instances will be registered
120 and calls on such construct produce
123 if (GetProp( hWnd
, OLD_PROC_KEY
)==0)
125 hFuncPtr
= SetWindowLongPtr( hWnd
, GWLP_WNDPROC
, (LONG_PTR
)NativeViewWndProc
);
126 SetProp( hWnd
, OLD_PROC_KEY
, (HANDLE
)hFuncPtr
);
132 /*****************************************************************************
135 * Method : NativeViewWndProc
137 * Description: registered window handler to intercept window messages between
138 * java and office process
140 static LRESULT APIENTRY
NativeViewWndProc(
141 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
145 /* resize new created child window to fill out the java window complete */
146 if (uMsg
==WM_PARENTNOTIFY
)
148 if (wParam
== WM_CREATE
)
151 HWND hChild
= (HWND
) lParam
;
153 GetClientRect(hWnd
, &rect
);
159 rect
.right
- rect
.left
,
160 rect
.bottom
- rect
.top
,
164 /* handle normal resize events */
165 else if(uMsg
==WM_SIZE
)
167 WORD newHeight
= HIWORD(lParam
);
168 WORD newWidth
= LOWORD(lParam
);
169 HWND hChild
= GetWindow(hWnd
, GW_CHILD
);
172 SetWindowPos(hChild
, NULL
, 0, 0, newWidth
, newHeight
, SWP_NOZORDER
);
175 /* forward request to original handler which is intercepted by this window procedure */
176 hFuncPtr
= GetProp(hWnd
, OLD_PROC_KEY
);
177 MY_ASSERT(hFuncPtr
,"lost original window proc handler");
178 return CallWindowProc( hFuncPtr
, hWnd
, uMsg
, wParam
, lParam
);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */