xref: /AOO41X/main/embeddedobj/test/Container1/nativelib/nativeview.c (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  *************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifdef WNT
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <windows.h>
31*cdf0e10cSrcweir // property name to register own window procedure on hwnd
32*cdf0e10cSrcweir #define OLD_PROC_KEY "oldwindowproc"
33*cdf0e10cSrcweir // signature of this window procedure
34*cdf0e10cSrcweir static LRESULT APIENTRY NativeViewWndProc( HWND , UINT , WPARAM , LPARAM );
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "jawt.h"
39*cdf0e10cSrcweir #include "jawt_md.h"
40*cdf0e10cSrcweir #include "NativeView.h"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define SYSTEM_WIN32   1
45*cdf0e10cSrcweir #define SYSTEM_WIN16   2
46*cdf0e10cSrcweir #define SYSTEM_JAVA    3
47*cdf0e10cSrcweir #define SYSTEM_OS2     4
48*cdf0e10cSrcweir #define SYSTEM_MAC     5
49*cdf0e10cSrcweir #define SYSTEM_XWINDOW 6
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /*****************************************************************************
52*cdf0e10cSrcweir  *
53*cdf0e10cSrcweir  * Class      : NativeView
54*cdf0e10cSrcweir  * Method     : getNativeWindowSystemType
55*cdf0e10cSrcweir  * Signature  : ()I
56*cdf0e10cSrcweir  * Description: returns an identifier for the current operating system
57*cdf0e10cSrcweir  */
58*cdf0e10cSrcweir JNIEXPORT jint JNICALL Java_embeddedobj_test_NativeView_getNativeWindowSystemType
59*cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this)
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     return (SYSTEM_WIN32);
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir /*****************************************************************************
65*cdf0e10cSrcweir  *
66*cdf0e10cSrcweir  * Class      : NativeView
67*cdf0e10cSrcweir  * Method     : getNativeWindow
68*cdf0e10cSrcweir  * Signature  : ()J
69*cdf0e10cSrcweir  * Description: returns the native systemw window handle of this object
70*cdf0e10cSrcweir  */
71*cdf0e10cSrcweir JNIEXPORT jlong JNICALL Java_embeddedobj_test_NativeView_getNativeWindow
72*cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this)
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     jboolean                      result  ;
75*cdf0e10cSrcweir     jint                          lock    ;
76*cdf0e10cSrcweir     JAWT                          awt     ;
77*cdf0e10cSrcweir     JAWT_DrawingSurface*          ds      ;
78*cdf0e10cSrcweir     JAWT_DrawingSurfaceInfo*      dsi     ;
79*cdf0e10cSrcweir     JAWT_Win32DrawingSurfaceInfo* dsi_win ;
80*cdf0e10cSrcweir 	jlong						  drawable;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir #if 0
83*cdf0e10cSrcweir 	LONG						  hFuncPtr;
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	/* Get the AWT */
87*cdf0e10cSrcweir 	awt.version = JAWT_VERSION_1_3;
88*cdf0e10cSrcweir     result      = JAWT_GetAWT(env, &awt);
89*cdf0e10cSrcweir     MY_ASSERT(result!=JNI_FALSE,"wrong jawt version");
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     /* Get the drawing surface */
92*cdf0e10cSrcweir 	if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
93*cdf0e10cSrcweir 		return 0L;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	/* Lock the drawing surface */
96*cdf0e10cSrcweir 	lock = ds->Lock(ds);
97*cdf0e10cSrcweir     MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	/* Get the drawing surface info */
100*cdf0e10cSrcweir 	dsi = ds->GetDrawingSurfaceInfo(ds);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	/* Get the platform-specific drawing info */
103*cdf0e10cSrcweir #ifdef WNT
104*cdf0e10cSrcweir 	dsi_win  = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
105*cdf0e10cSrcweir     drawable = (jlong)dsi_win->hwnd;
106*cdf0e10cSrcweir #else
107*cdf0e10cSrcweir     dsi_x11  = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
108*cdf0e10cSrcweir 	drawable = (jlong)dsi_x11->drawable;
109*cdf0e10cSrcweir #endif
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	/* Free the drawing surface info */
112*cdf0e10cSrcweir 	ds->FreeDrawingSurfaceInfo(dsi);
113*cdf0e10cSrcweir 	/* Unlock the drawing surface */
114*cdf0e10cSrcweir 	ds->Unlock(ds);
115*cdf0e10cSrcweir 	/* Free the drawing surface */
116*cdf0e10cSrcweir 	awt.FreeDrawingSurface(ds);
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir #if 0
119*cdf0e10cSrcweir     /* Register own window procedure
120*cdf0e10cSrcweir        Do it one times only! Otherwhise
121*cdf0e10cSrcweir        multiple instances will be registered
122*cdf0e10cSrcweir        and calls on such construct produce
123*cdf0e10cSrcweir        a stack overflow.
124*cdf0e10cSrcweir      */
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     if (GetProp( (HWND)drawable, OLD_PROC_KEY )==0)
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         hFuncPtr = SetWindowLong( (HWND)drawable, GWL_WNDPROC, (DWORD)NativeViewWndProc );
129*cdf0e10cSrcweir         SetProp( (HWND)drawable, OLD_PROC_KEY, (HANDLE)hFuncPtr );
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir #endif
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     return drawable;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir #if 0
137*cdf0e10cSrcweir /*****************************************************************************
138*cdf0e10cSrcweir  *
139*cdf0e10cSrcweir  * Class      : -
140*cdf0e10cSrcweir  * Method     : NativeViewWndProc
141*cdf0e10cSrcweir  * Signature  : -
142*cdf0e10cSrcweir  * Description: registered window handler to intercept window messages between
143*cdf0e10cSrcweir  *              java and office process
144*cdf0e10cSrcweir  */
145*cdf0e10cSrcweir static LRESULT APIENTRY NativeViewWndProc(
146*cdf0e10cSrcweir     HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     HANDLE hFuncPtr;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     /* resize new created child window to fill out the java window complete */
151*cdf0e10cSrcweir     if (uMsg==WM_PARENTNOTIFY)
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         if (wParam == WM_CREATE)
154*cdf0e10cSrcweir         {
155*cdf0e10cSrcweir             RECT rect;
156*cdf0e10cSrcweir             HWND hChild = (HWND) lParam;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir             GetClientRect(hWnd, &rect);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             SetWindowPos(hChild,
161*cdf0e10cSrcweir                         NULL,
162*cdf0e10cSrcweir                         rect.left,
163*cdf0e10cSrcweir                         rect.top,
164*cdf0e10cSrcweir                         rect.right - rect.left,
165*cdf0e10cSrcweir                         rect.bottom - rect.top,
166*cdf0e10cSrcweir                         SWP_NOZORDER);
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir     /* handle normal resize events */
170*cdf0e10cSrcweir     else if(uMsg==WM_SIZE)
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         WORD newHeight = HIWORD(lParam);
173*cdf0e10cSrcweir         WORD newWidth  = LOWORD(lParam);
174*cdf0e10cSrcweir         HWND hChild    = GetWindow(hWnd, GW_CHILD);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         if (hChild != NULL)
177*cdf0e10cSrcweir             SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     /* forward request to original handler which is intercepted by this window procedure */
181*cdf0e10cSrcweir     hFuncPtr = GetProp(hWnd, OLD_PROC_KEY);
182*cdf0e10cSrcweir     MY_ASSERT(hFuncPtr,"lost original window proc handler");
183*cdf0e10cSrcweir     return CallWindowProc( hFuncPtr, hWnd, uMsg, wParam, lParam);
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir #endif
186*cdf0e10cSrcweir 
187