Path: blob/master/test/jdk/java/awt/JAWT/myfile.cpp
41149 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <windows.h>24#include "MyCanvas.h"25#include "jawt_md.h"2627/*28* Class: MyCanvas29* Method: paint30* Signature: (Ljava/awt/Graphics;)V31*/3233extern "C" {3435JNIEXPORT void JNICALL Java_MyCanvas_paint36(JNIEnv* env, jobject canvas, jobject graphics)37{38/* Get the AWT */39JAWT awt;40awt.version = JAWT_VERSION_1_4;41if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {42printf("AWT Not found\n");43return;44}4546/* Lock the AWT */47awt.Lock(env);4849/* Unlock the AWT */50awt.Unlock(env);5152/* Get the drawing surface */53JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas);54if (ds == NULL) {55printf("NULL drawing surface\n");56return;57}5859/* Lock the drawing surface */60jint lock = ds->Lock(ds);61printf("Lock value %d\n", (int)lock);62if((lock & JAWT_LOCK_ERROR) != 0) {63printf("Error locking surface\n");64return;65}6667/* Get the drawing surface info */68JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds);69if (dsi == NULL) {70printf("Error getting surface info\n");71ds->Unlock(ds);72return;73}7475/* Get the platform-specific drawing info */76JAWT_Win32DrawingSurfaceInfo* dsi_win =77(JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;7879/* Now paint */80PAINTSTRUCT ps;81/* Do not use the HDC returned from BeginPaint()!! */82::BeginPaint(dsi_win->hwnd, &ps);83HBRUSH hbrush = (HBRUSH)::GetStockObject(BLACK_BRUSH);84RECT rect;85rect.left = 5;86rect.top = 5;87rect.right = 95;88rect.bottom = 95;89::FillRect(dsi_win->hdc, &rect, hbrush);90::EndPaint(dsi_win->hwnd, &ps);9192jobject ref = awt.GetComponent(env, (void*)(dsi_win->hwnd));93if (!env->IsSameObject(ref, canvas)) {94printf("Error! Different objects!\n");95}9697/* Free the drawing surface info */98ds->FreeDrawingSurfaceInfo(dsi);99100/* Unlock the drawing surface */101ds->Unlock(ds);102103/* Free the drawing surface */104awt.FreeDrawingSurface(ds);105}106107}108109110