Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / odk / examples / DevelopersGuide / OfficeDev / DesktopEnvironment / nativelib / windows / nativeview.c
blob2de998c694756d0188d378d3353a2f515c611f35
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
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 *************************************************************************/
36 #include <windows.h>
38 #include "jawt.h"
39 #include "jawt_md.h"
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
46 #define SYSTEM_JAVA 3
47 #define SYSTEM_OS2 4
48 #define SYSTEM_MAC 5
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 /*****************************************************************************
58 * Class : NativeView
59 * Method : getNativeWindowSystemType
60 * Signature : ()I
61 * Description: returns an identifier for the current operating system
63 JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
64 (JNIEnv * env, jobject obj_this)
66 return SYSTEM_WIN32;
69 /*****************************************************************************
71 * Class : NativeView
72 * Method : getNativeWindow
73 * Signature : ()J
74 * Description: returns the native systemw window handle of this object
76 JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
77 (JNIEnv * env, jobject obj_this)
79 jboolean result ;
80 jint lock ;
81 JAWT awt ;
82 JAWT_DrawingSurface* ds ;
83 JAWT_DrawingSurfaceInfo* dsi ;
84 JAWT_Win32DrawingSurfaceInfo* dsi_win ;
85 HDC hdc ;
86 HWND hWnd ;
87 LONG hFuncPtr;
89 /* Get the AWT */
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)
96 return 0;
98 /* Lock the drawing surface */
99 lock = ds->Lock(ds);
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;
107 hdc = dsi_win->hdc;
108 hWnd = dsi_win->hwnd;
110 /* Free the drawing surface info */
111 ds->FreeDrawingSurfaceInfo(dsi);
112 /* Unlock the drawing surface */
113 ds->Unlock(ds);
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
121 a stack overflow.
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 );
129 return (jlong)hWnd;
132 /*****************************************************************************
134 * Class : -
135 * Method : NativeViewWndProc
136 * Signature : -
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)
143 HANDLE hFuncPtr;
145 /* resize new created child window to fill out the java window complete */
146 if (uMsg==WM_PARENTNOTIFY)
148 if (wParam == WM_CREATE)
150 RECT rect;
151 HWND hChild = (HWND) lParam;
153 GetClientRect(hWnd, &rect);
155 SetWindowPos(hChild,
156 NULL,
157 rect.left,
158 rect.top,
159 rect.right - rect.left,
160 rect.bottom - rect.top,
161 SWP_NOZORDER);
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);
171 if (hChild != NULL)
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: */