Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XCustomCursor.java
32288 views
/*1* Copyright (c) 2003, 2008, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import sun.awt.X11CustomCursor;28import java.awt.*;2930/**31* A class to encapsulate a custom image-based cursor.32*33* @see Component#setCursor34* @author Thomas Ball35* @author Bino George36*/37public class XCustomCursor extends X11CustomCursor {3839public XCustomCursor(Image cursor, Point hotSpot, String name)40throws IndexOutOfBoundsException {41super(cursor, hotSpot, name);42}4344/**45* Returns the supported cursor size46*/47static Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {4849// Fix for bug 4212593 The Toolkit.createCustomCursor does not50// check absence of the image of cursor51// We use XQueryBestCursor which accepts unsigned ints to obtain52// the largest cursor size that could be dislpayed53//Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight));54Dimension d;5556XToolkit.awtLock();57try {58long display = XToolkit.getDisplay();59long root_window = XlibWrapper.RootWindow(display,60XlibWrapper.DefaultScreen(display));6162XlibWrapper.XQueryBestCursor(display,root_window, Math.abs(preferredWidth),Math.abs(preferredHeight),XlibWrapper.larg1,XlibWrapper.larg2);63d = new Dimension(XlibWrapper.unsafe.getInt(XlibWrapper.larg1),XlibWrapper.unsafe.getInt(XlibWrapper.larg2));64}65finally {66XToolkit.awtUnlock();67}68return d;69}7071protected void createCursor(byte[] xorMask, byte[] andMask,72int width, int height,73int fcolor, int bcolor,74int xHotSpot, int yHotSpot)75{76XToolkit.awtLock();77try {78long display = XToolkit.getDisplay();79long root_window = XlibWrapper.RootWindow(display,80XlibWrapper.DefaultScreen(display));8182long colormap = XToolkit.getDefaultXColormap();83XColor fore_color = new XColor();8485fore_color.set_flags((byte) (XConstants.DoRed | XConstants.DoGreen | XConstants.DoBlue));86fore_color.set_red((short)(((fcolor >> 16) & 0x000000ff) << 8));87fore_color.set_green((short) (((fcolor >> 8) & 0x000000ff) << 8));88fore_color.set_blue((short)(((fcolor >> 0) & 0x000000ff) << 8));8990XlibWrapper.XAllocColor(display,colormap,fore_color.pData);919293XColor back_color = new XColor();94back_color.set_flags((byte) (XConstants.DoRed | XConstants.DoGreen | XConstants.DoBlue));9596back_color.set_red((short) (((bcolor >> 16) & 0x000000ff) << 8));97back_color.set_green((short) (((bcolor >> 8) & 0x000000ff) << 8));98back_color.set_blue((short) (((bcolor >> 0) & 0x000000ff) << 8));99100XlibWrapper.XAllocColor(display,colormap,back_color.pData);101102103long nativeXorMask = Native.toData(xorMask);104long source = XlibWrapper.XCreateBitmapFromData(display,root_window,nativeXorMask,width,height);105106long nativeAndMask = Native.toData(andMask);107long mask = XlibWrapper.XCreateBitmapFromData(display,root_window,nativeAndMask,width,height);108109long cursor = XlibWrapper.XCreatePixmapCursor(display,source,mask,fore_color.pData,back_color.pData,xHotSpot,yHotSpot);110111XlibWrapper.unsafe.freeMemory(nativeXorMask);112XlibWrapper.unsafe.freeMemory(nativeAndMask);113XlibWrapper.XFreePixmap(display,source);114XlibWrapper.XFreePixmap(display,mask);115back_color.dispose();116fore_color.dispose();117118XGlobalCursorManager.setPData(this,cursor);119}120finally {121XToolkit.awtUnlock();122}123124}125}126127128