Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / test / Container1 / nativelib / nativeview.c
blob8f5e4c7ad5e8e479f3787652073e54e56b2ddd9e
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 #ifdef WNT
22 #include <windows.h>
23 // property name to register own window procedure on hwnd
24 #define OLD_PROC_KEY "oldwindowproc"
25 // signature of this window procedure
26 static LRESULT APIENTRY NativeViewWndProc( HWND , UINT , WPARAM , LPARAM );
28 #endif
30 #include "jawt.h"
31 #include "jawt_md.h"
32 #include "NativeView.h"
34 #define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
36 #define SYSTEM_WIN32 1
37 #define SYSTEM_WIN16 2
38 #define SYSTEM_JAVA 3
39 #define SYSTEM_MAC 5
40 #define SYSTEM_XWINDOW 6
42 /*****************************************************************************
44 * Class : NativeView
45 * Method : getNativeWindowSystemType
46 * Signature : ()I
47 * Description: returns an identifier for the current operating system
49 JNIEXPORT jint JNICALL Java_embeddedobj_test_NativeView_getNativeWindowSystemType
50 (JNIEnv * env, jobject obj_this)
52 return (SYSTEM_WIN32);
55 /*****************************************************************************
57 * Class : NativeView
58 * Method : getNativeWindow
59 * Signature : ()J
60 * Description: returns the native systemw window handle of this object
62 JNIEXPORT jlong JNICALL Java_embeddedobj_test_NativeView_getNativeWindow
63 (JNIEnv * env, jobject obj_this)
65 jboolean result ;
66 jint lock ;
67 JAWT awt ;
68 JAWT_DrawingSurface* ds ;
69 JAWT_DrawingSurfaceInfo* dsi ;
70 #ifdef WNT
71 JAWT_Win32DrawingSurfaceInfo* dsi_win ;
72 #else
73 // FIXME: Where is dsi_x11 defined?
74 // Added below because I'm guessing this test breaks
76 // JAWT_X11DrawingSurfaceInfo*dsi_x11 ;
77 #endif
78 jlong drawable;
80 /* Get the AWT */
81 awt.version = JAWT_VERSION_1_3;
82 result = JAWT_GetAWT(env, &awt);
83 MY_ASSERT(result!=JNI_FALSE,"wrong jawt version");
85 /* Get the drawing surface */
86 if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
87 return 0L;
89 /* Lock the drawing surface */
90 lock = ds->Lock(ds);
91 MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
93 /* Get the drawing surface info */
94 dsi = ds->GetDrawingSurfaceInfo(ds);
96 /* Get the platform-specific drawing info */
97 #ifdef WNT
98 dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
99 drawable = (jlong)dsi_win->hwnd;
100 #else
101 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
102 drawable = (jlong)dsi_x11->drawable;
103 #endif
105 /* Free the drawing surface info */
106 ds->FreeDrawingSurfaceInfo(dsi);
107 /* Unlock the drawing surface */
108 ds->Unlock(ds);
109 /* Free the drawing surface */
110 awt.FreeDrawingSurface(ds);
112 return drawable;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */