tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / bean / native / win32 / com_sun_star_comp_beans_LocalOfficeWindow.c
blob7f29160250e6b927cd4c1f31868f6d79775f4241
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #if !defined WIN32_LEAN_AND_MEAN
21 # define WIN32_LEAN_AND_MEAN
22 #endif
23 #include <windows.h>
25 #if defined _MSC_VER
26 #pragma warning(push)
27 #pragma warning(disable : 4201) /* nonstandard extension used: nameless struct/union */
28 #endif
29 #include <jawt_md.h>
30 #if defined _MSC_VER
31 #pragma warning(pop)
32 #endif
34 #define SYSTEM_WIN32 1
36 #define OLD_PROC_KEY L"oldwindowproc"
38 static LRESULT APIENTRY OpenOfficeWndProc( HWND , UINT , WPARAM , LPARAM );
40 /* type must be something like java/lang/RuntimeException
42 static void ThrowException(JNIEnv * env, char const * type, char const * msg) {
43 jclass c;
44 (*env)->ExceptionClear(env);
45 c = (*env)->FindClass(env, type);
46 if (c == NULL) {
47 (*env)->ExceptionClear(env);
48 (*env)->FatalError(
49 env, "JNI FindClass failed");
51 if ((*env)->ThrowNew(env, c, msg) != 0) {
52 (*env)->ExceptionClear(env);
53 (*env)->FatalError(env, "JNI ThrowNew failed");
58 /*****************************************************************************/
60 * Class: com_sun_star_comp_beans_LocalOfficeWindow
61 * Method: getNativeWindowSystemType
62 * Signature: ()I
64 JNIEXPORT jint JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindowSystemType
65 (JNIEnv * env, jobject obj_this)
67 (void) env; // unused
68 (void) obj_this; // unused
69 return SYSTEM_WIN32;
73 /*****************************************************************************/
75 * Class: com_sun_star_comp_beans_LocalOfficeWindow
76 * Method: getNativeWindow
77 * Signature: ()J
79 JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow
80 (JNIEnv * env, jobject obj_this)
82 jboolean result;
83 jint lock;
85 JAWT awt;
86 JAWT_DrawingSurface* ds;
87 JAWT_DrawingSurfaceInfo* dsi;
88 JAWT_Win32DrawingSurfaceInfo* dsi_win;
89 HWND hWnd;
90 LONG_PTR hFuncPtr;
92 /* Get the AWT */
93 awt.version = JAWT_VERSION_1_3;
94 result = JAWT_GetAWT(env, &awt);
95 if (result == JNI_FALSE)
96 ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed");
98 /* Get the drawing surface */
99 if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
100 return 0;
102 /* Lock the drawing surface */
103 lock = ds->Lock(ds);
104 if ( (lock & JAWT_LOCK_ERROR) != 0)
105 ThrowException(env, "java/lang/RuntimeException",
106 "Could not get AWT drawing surface.");
108 /* Get the drawing surface info */
109 dsi = ds->GetDrawingSurfaceInfo(ds);
111 /* Get the platform-specific drawing info */
112 dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
114 hWnd = dsi_win->hwnd;
116 /* Free the drawing surface info */
117 ds->FreeDrawingSurfaceInfo(dsi);
118 /* Unlock the drawing surface */
119 ds->Unlock(ds);
120 /* Free the drawing surface */
121 awt.FreeDrawingSurface(ds);
123 /* Register own window procedure
124 Do it one times only! Otherwise
125 multiple instances will be registered
126 and calls on such construct produce
127 a stack overflow.
129 if (GetPropW( hWnd, OLD_PROC_KEY )==NULL)
131 hFuncPtr = SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (LONG_PTR)OpenOfficeWndProc );
132 SetPropW( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr );
135 return (jlong)hWnd;
139 static LRESULT APIENTRY OpenOfficeWndProc(
140 HWND hWnd,
141 UINT uMsg,
142 WPARAM wParam,
143 LPARAM lParam)
145 switch(uMsg)
147 case WM_PARENTNOTIFY: {
148 if (wParam == WM_CREATE) {
149 RECT rect;
150 HWND hChild = (HWND) lParam;
152 GetClientRect(hWnd, &rect);
154 SetWindowPos(hChild,
155 NULL,
156 rect.left,
157 rect.top,
158 rect.right - rect.left,
159 rect.bottom - rect.top,
160 SWP_NOZORDER);
162 break;
164 case WM_SIZE: {
165 WORD newHeight = HIWORD(lParam);
166 WORD newWidth = LOWORD(lParam);
167 HWND hChild = GetWindow(hWnd, GW_CHILD);
169 if (hChild != NULL) {
170 SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
172 break;
176 #if defined _MSC_VER
177 #pragma warning(push)
178 #pragma warning(disable: 4152) /* function/data pointer conversion: */
179 #endif
180 return CallWindowProcW(GetPropW(hWnd, OLD_PROC_KEY),
181 hWnd, uMsg, wParam, lParam);
182 #if defined _MSC_VER
183 #pragma warning(pop)
184 #endif
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */