0N/A/*
6447N/A * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.awt.dnd.DnDConstants;
0N/A
0N/Aimport java.nio.ByteOrder;
0N/A
0N/Aimport java.util.Arrays;
0N/A
0N/Aimport sun.misc.Unsafe;
0N/A
0N/A/**
0N/A * Motif DnD protocol global constants and convenience routines.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Aclass MotifDnDConstants {
94N/A // utility class can not be instantiated
94N/A private MotifDnDConstants() {}
0N/A // Note that offsets in all native structures below do not depend on the
0N/A // architecture.
0N/A private static final Unsafe unsafe = XlibWrapper.unsafe;
0N/A static final XAtom XA_MOTIF_ATOM_0 = XAtom.get("_MOTIF_ATOM_0");
0N/A static final XAtom XA_MOTIF_DRAG_WINDOW = XAtom.get("_MOTIF_DRAG_WINDOW");
0N/A static final XAtom XA_MOTIF_DRAG_TARGETS = XAtom.get("_MOTIF_DRAG_TARGETS");
0N/A static final XAtom XA_MOTIF_DRAG_INITIATOR_INFO =
0N/A XAtom.get("_MOTIF_DRAG_INITIATOR_INFO");
0N/A static final XAtom XA_MOTIF_DRAG_RECEIVER_INFO =
0N/A XAtom.get("_MOTIF_DRAG_RECEIVER_INFO");
0N/A static final XAtom XA_MOTIF_DRAG_AND_DROP_MESSAGE =
0N/A XAtom.get("_MOTIF_DRAG_AND_DROP_MESSAGE");
0N/A static final XAtom XA_XmTRANSFER_SUCCESS =
0N/A XAtom.get("XmTRANSFER_SUCCESS");
0N/A static final XAtom XA_XmTRANSFER_FAILURE =
0N/A XAtom.get("XmTRANSFER_FAILURE");
94N/A static final XSelection MotifDnDSelection = new XSelection(XA_MOTIF_ATOM_0);
0N/A
0N/A public static final byte MOTIF_DND_PROTOCOL_VERSION = 0;
0N/A
0N/A /* Supported protocol styles */
0N/A public static final int MOTIF_PREFER_PREREGISTER_STYLE = 2;
0N/A public static final int MOTIF_PREFER_DYNAMIC_STYLE = 4;
0N/A public static final int MOTIF_DYNAMIC_STYLE = 5;
0N/A public static final int MOTIF_PREFER_RECEIVER_STYLE = 6;
0N/A
0N/A /* Info structure sizes */
0N/A public static final int MOTIF_INITIATOR_INFO_SIZE = 8;
0N/A public static final int MOTIF_RECEIVER_INFO_SIZE = 16;
0N/A
0N/A /* Sender/reason message masks */
0N/A public static final byte MOTIF_MESSAGE_REASON_MASK = (byte)0x7F;
0N/A public static final byte MOTIF_MESSAGE_SENDER_MASK = (byte)0x80;
0N/A public static final byte MOTIF_MESSAGE_FROM_RECEIVER = (byte)0x80;
0N/A public static final byte MOTIF_MESSAGE_FROM_INITIATOR = (byte)0;
0N/A
0N/A /* Message flags masks and shifts */
0N/A public static final int MOTIF_DND_ACTION_MASK = 0x000F;
0N/A public static final int MOTIF_DND_ACTION_SHIFT = 0;
0N/A public static final int MOTIF_DND_STATUS_MASK = 0x00F0;
0N/A public static final int MOTIF_DND_STATUS_SHIFT = 4;
0N/A public static final int MOTIF_DND_ACTIONS_MASK = 0x0F00;
0N/A public static final int MOTIF_DND_ACTIONS_SHIFT = 8;
0N/A
0N/A /* message type constants */
0N/A public static final byte TOP_LEVEL_ENTER = 0;
0N/A public static final byte TOP_LEVEL_LEAVE = 1;
0N/A public static final byte DRAG_MOTION = 2;
0N/A public static final byte DROP_SITE_ENTER = 3;
0N/A public static final byte DROP_SITE_LEAVE = 4;
0N/A public static final byte DROP_START = 5;
0N/A public static final byte DROP_FINISH = 6;
0N/A public static final byte DRAG_DROP_FINISH = 7;
0N/A public static final byte OPERATION_CHANGED = 8;
0N/A
0N/A /* drop action constants */
0N/A public static final int MOTIF_DND_NOOP = 0;
0N/A public static final int MOTIF_DND_MOVE = 1 << 0;
0N/A public static final int MOTIF_DND_COPY = 1 << 1;
0N/A public static final int MOTIF_DND_LINK = 1 << 2;
0N/A
0N/A /* drop site status constants */
0N/A public static final byte MOTIF_NO_DROP_SITE = (byte)1;
0N/A public static final byte MOTIF_INVALID_DROP_SITE = (byte)2;
0N/A public static final byte MOTIF_VALID_DROP_SITE = (byte)3;
0N/A
0N/A private static long readMotifWindow() throws XException {
0N/A long defaultScreenNumber = XlibWrapper.DefaultScreen(XToolkit.getDisplay());
0N/A long defaultRootWindow =
0N/A XlibWrapper.RootWindow(XToolkit.getDisplay(), defaultScreenNumber);
0N/A
0N/A long motifWindow = 0;
0N/A
0N/A WindowPropertyGetter wpg = new WindowPropertyGetter(defaultRootWindow,
0N/A XA_MOTIF_DRAG_WINDOW,
0N/A 0, 1,
0N/A false,
216N/A XConstants.AnyPropertyType);
0N/A try {
1216N/A int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A
216N/A if (status == XConstants.Success &&
0N/A wpg.getData() != 0 &&
0N/A wpg.getActualType() == XAtom.XA_WINDOW &&
0N/A wpg.getActualFormat() == 32 &&
0N/A wpg.getNumberOfItems() == 1) {
0N/A long data = wpg.getData();
0N/A // XID is CARD32.
0N/A motifWindow = Native.getLong(data);
0N/A }
0N/A
0N/A return motifWindow;
0N/A } finally {
0N/A wpg.dispose();
0N/A }
0N/A }
0N/A
0N/A private static long createMotifWindow() throws XException {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A long defaultScreenNumber =
0N/A XlibWrapper.DefaultScreen(XToolkit.getDisplay());
0N/A long defaultRootWindow =
0N/A XlibWrapper.RootWindow(XToolkit.getDisplay(), defaultScreenNumber);
0N/A
0N/A long motifWindow = 0;
0N/A
0N/A long displayString = XlibWrapper.XDisplayString(XToolkit.getDisplay());
0N/A
0N/A if (displayString == 0) {
0N/A throw new XException("XDisplayString returns NULL");
0N/A }
0N/A
0N/A long newDisplay = XlibWrapper.XOpenDisplay(displayString);
0N/A
0N/A if (newDisplay == 0) {
0N/A throw new XException("XOpenDisplay returns NULL");
0N/A }
0N/A
0N/A XlibWrapper.XGrabServer(newDisplay);
0N/A
0N/A try {
216N/A XlibWrapper.XSetCloseDownMode(newDisplay, (int)XConstants.RetainPermanent);
0N/A
0N/A XSetWindowAttributes xwa = new XSetWindowAttributes();
0N/A
0N/A try {
0N/A xwa.set_override_redirect(true);
216N/A xwa.set_event_mask(XConstants.PropertyChangeMask);
0N/A
0N/A motifWindow = XlibWrapper.XCreateWindow(newDisplay, defaultRootWindow,
0N/A -10, -10, 1, 1, 0, 0,
216N/A XConstants.InputOnly,
216N/A XConstants.CopyFromParent,
216N/A (XConstants.CWOverrideRedirect |
216N/A XConstants.CWEventMask),
0N/A xwa.pData);
0N/A
0N/A if (motifWindow == 0) {
0N/A throw new XException("XCreateWindow returns NULL");
0N/A }
0N/A
0N/A XlibWrapper.XMapWindow(newDisplay, motifWindow);
0N/A
0N/A long data = Native.allocateLongArray(1);
0N/A
0N/A try {
0N/A Native.putLong(data, motifWindow);
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
0N/A defaultRootWindow,
0N/A XA_MOTIF_DRAG_WINDOW.getAtom(),
0N/A XAtom.XA_WINDOW, 32,
216N/A XConstants.PropModeReplace,
0N/A data, 1);
0N/A
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A throw new XException("Cannot write motif drag window handle.");
0N/A }
0N/A
0N/A return motifWindow;
0N/A } finally {
0N/A unsafe.freeMemory(data);
0N/A }
0N/A } finally {
0N/A xwa.dispose();
0N/A }
0N/A } finally {
0N/A XlibWrapper.XUngrabServer(newDisplay);
0N/A XlibWrapper.XCloseDisplay(newDisplay);
0N/A }
0N/A }
0N/A
0N/A private static long getMotifWindow() throws XException {
0N/A /*
0N/A * Note: it is unsafe to cache the motif drag window handle, as another
0N/A * client can change the _MOTIF_DRAG_WINDOW property on the root, the handle
0N/A * becomes out-of-sync and all subsequent drag operations will fail.
0N/A */
0N/A long motifWindow = readMotifWindow();
0N/A if (motifWindow == 0) {
0N/A motifWindow = createMotifWindow();
0N/A }
0N/A return motifWindow;
0N/A }
0N/A
0N/A public static final class Swapper {
94N/A // utility class can not be instantiated
94N/A private Swapper() {}
94N/A
0N/A public static short swap(short s) {
0N/A return (short)(((s & 0xFF00) >>> 8) | ((s & 0xFF) << 8));
0N/A }
0N/A public static int swap(int i) {
0N/A return ((i & 0xFF000000) >>> 24) | ((i & 0x00FF0000) >>> 8) |
0N/A ((i & 0x0000FF00) << 8) | ((i & 0x000000FF) << 24);
0N/A }
0N/A
0N/A public static short getShort(long data, byte order) {
0N/A short s = unsafe.getShort(data);
0N/A if (order != MotifDnDConstants.getByteOrderByte()) {
0N/A return swap(s);
0N/A } else {
0N/A return s;
0N/A }
0N/A }
0N/A public static int getInt(long data, byte order) {
0N/A int i = unsafe.getInt(data);
0N/A if (order != MotifDnDConstants.getByteOrderByte()) {
0N/A return swap(i);
0N/A } else {
0N/A return i;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * DragBSI.h:
0N/A *
0N/A * typedef struct {
0N/A * BYTE byte_order;
0N/A * BYTE protocol_version;
0N/A * CARD16 num_target_lists B16;
0N/A * CARD32 heap_offset B32;
0N/A * } xmMotifTargetsPropertyRec;
0N/A */
0N/A private static long[][] getTargetListTable(long motifWindow)
0N/A throws XException {
0N/A
0N/A WindowPropertyGetter wpg = new WindowPropertyGetter(motifWindow,
0N/A XA_MOTIF_DRAG_TARGETS,
0N/A 0, 100000L,
0N/A false,
0N/A XA_MOTIF_DRAG_TARGETS.getAtom());
0N/A try {
1216N/A int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A
216N/A if (status != XConstants.Success
0N/A || wpg.getActualType() != XA_MOTIF_DRAG_TARGETS.getAtom()
0N/A || wpg.getData() == 0) {
0N/A
0N/A return null;
0N/A }
0N/A
0N/A long data = wpg.getData();
0N/A
0N/A if (unsafe.getByte(data + 1) != MOTIF_DND_PROTOCOL_VERSION) {
0N/A return null;
0N/A }
0N/A
0N/A boolean swapNeeded = unsafe.getByte(data + 0) != getByteOrderByte();
0N/A
0N/A short numTargetLists = unsafe.getShort(data + 2);
0N/A
0N/A if (swapNeeded) {
0N/A numTargetLists = Swapper.swap(numTargetLists);
0N/A }
0N/A
0N/A long[][] table = new long[numTargetLists][];
0N/A ByteOrder byteOrder = ByteOrder.nativeOrder();
0N/A if (swapNeeded) {
0N/A byteOrder = (byteOrder == ByteOrder.LITTLE_ENDIAN) ?
0N/A ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
0N/A }
0N/A
0N/A long bufptr = data + 8;
0N/A for (short i = 0; i < numTargetLists; i++) {
0N/A short numTargets = unsafe.getShort(bufptr);
0N/A bufptr += 2;
0N/A if (swapNeeded) {
0N/A numTargets = Swapper.swap(numTargets);
0N/A }
0N/A
0N/A table[i] = new long[numTargets];
0N/A
0N/A for (short j = 0; j < numTargets; j++) {
0N/A // NOTE: cannot use Unsafe.getInt(), since it crashes on
0N/A // Solaris/Sparc if the address is not a multiple of 4.
0N/A int target = 0;
0N/A if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
0N/A for (int idx = 0; idx < 4; idx++) {
0N/A target |= (unsafe.getByte(bufptr + idx) << 8*idx)
0N/A & (0xFF << 8*idx);
0N/A }
0N/A } else {
0N/A for (int idx = 0; idx < 4; idx++) {
0N/A target |= (unsafe.getByte(bufptr + idx) << 8*(3-idx))
0N/A & (0xFF << 8*(3-idx));
0N/A }
0N/A }
0N/A // NOTE: don't need to swap, since we read it in the proper
0N/A // order already.
0N/A table[i][j] = target;
0N/A bufptr += 4;
0N/A }
0N/A }
0N/A return table;
0N/A } finally {
0N/A wpg.dispose();
0N/A }
0N/A }
0N/A
0N/A private static void putTargetListTable(long motifWindow, long[][] table)
0N/A throws XException {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A int tableSize = 8; /* The size of leading xmMotifTargetsPropertyRec. */
0N/A
0N/A for (int i = 0; i < table.length; i++) {
0N/A tableSize += table[i].length * 4 + 2;
0N/A }
0N/A
0N/A long data = unsafe.allocateMemory(tableSize);
0N/A
0N/A try {
0N/A // BYTE byte_order;
0N/A unsafe.putByte(data + 0, getByteOrderByte());
0N/A // BYTE protocol_version;
0N/A unsafe.putByte(data + 1, MOTIF_DND_PROTOCOL_VERSION);
0N/A // CARD16 num_target_lists B16;
0N/A unsafe.putShort(data + 2, (short)table.length);
0N/A // CARD32 heap_offset B32;
0N/A unsafe.putInt(data + 4, tableSize);
0N/A
0N/A long bufptr = data + 8;
0N/A
0N/A for (int i = 0; i < table.length; i++) {
0N/A unsafe.putShort(bufptr, (short)table[i].length);
0N/A bufptr += 2;
0N/A
0N/A for (int j = 0; j < table[i].length; j++) {
0N/A int target = (int)table[i][j];
0N/A // NOTE: cannot use Unsafe.putInt(), since it crashes on
0N/A // Solaris/Sparc if the address is not a multiple of 4.
0N/A if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
0N/A for (int idx = 0; idx < 4; idx++) {
0N/A byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
0N/A unsafe.putByte(bufptr + idx, b);
0N/A }
0N/A } else {
0N/A for (int idx = 0; idx < 4; idx++) {
0N/A byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
0N/A unsafe.putByte(bufptr + (3-idx), b);
0N/A }
0N/A }
0N/A bufptr += 4;
0N/A }
0N/A }
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
0N/A motifWindow,
0N/A XA_MOTIF_DRAG_TARGETS.getAtom(),
0N/A XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
216N/A XConstants.PropModeReplace,
0N/A data, tableSize);
0N/A
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A
0N/A // Create a new motif window and retry.
0N/A motifWindow = createMotifWindow();
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
0N/A motifWindow,
0N/A XA_MOTIF_DRAG_TARGETS.getAtom(),
0N/A XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
216N/A XConstants.PropModeReplace,
0N/A data, tableSize);
0N/A
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A throw new XException("Cannot write motif drag targets property.");
0N/A }
0N/A }
0N/A } finally {
0N/A unsafe.freeMemory(data);
0N/A }
0N/A }
0N/A
0N/A static int getIndexForTargetList(long[] formats) throws XException {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A if (formats.length > 0) {
0N/A // Make a defensive copy.
0N/A formats = (long[])formats.clone();
0N/A
0N/A Arrays.sort(formats);
0N/A }
0N/A
0N/A // NOTE: getMotifWindow() should never be called if the server is
0N/A // grabbed. This will lock up the application as it grabs the server
0N/A // itself.
0N/A // Since we don't grab the server before getMotifWindow(), another
0N/A // client might replace motif window after we read it from the root, but
0N/A // before we grab the server.
0N/A // We cannot resolve this problem, but we believe that this scenario is
0N/A // very unlikely to happen.
0N/A long motifWindow = getMotifWindow();
0N/A
0N/A XlibWrapper.XGrabServer(XToolkit.getDisplay());
0N/A
0N/A try {
0N/A long[][] table = getTargetListTable(motifWindow);
0N/A
0N/A if (table != null) {
0N/A for (int i = 0; i < table.length; i++) {
0N/A boolean equals = true;
0N/A if (table[i].length == formats.length) {
0N/A for (int j = 0; j < table[i].length; j++) {
0N/A if (table[i][j] != formats[j]) {
0N/A equals = false;
0N/A break;
0N/A }
0N/A }
0N/A } else {
0N/A equals = false;
0N/A }
0N/A
0N/A if (equals) {
0N/A XlibWrapper.XUngrabServer(XToolkit.getDisplay());
0N/A return i;
0N/A }
0N/A }
0N/A } else {
0N/A // Create a new table.
0N/A // The first two entries must always be the same.
0N/A // (see DragBS.c)
0N/A table = new long[2][];
0N/A table[0] = new long[] { 0 };
0N/A table[1] = new long[] { XAtom.XA_STRING };
0N/A }
0N/A
0N/A /* Index not found - expand the targets table. */
0N/A long[][] new_table = new long[table.length + 1][];
0N/A
0N/A /* Copy the old contents to the new table. */
0N/A for (int i = 0; i < table.length; i++) {
0N/A new_table[i] = table[i];
0N/A }
0N/A
0N/A /* Fill in the new entry */
0N/A new_table[new_table.length - 1] = formats;
0N/A
0N/A putTargetListTable(motifWindow, new_table);
0N/A
0N/A return new_table.length - 1;
0N/A } finally {
0N/A XlibWrapper.XUngrabServer(XToolkit.getDisplay());
0N/A }
0N/A }
0N/A
0N/A static long[] getTargetListForIndex(int index) {
0N/A long motifWindow = getMotifWindow();
0N/A long[][] table = getTargetListTable(motifWindow);
0N/A
0N/A if (index < 0 || index >= table.length) {
0N/A return new long[0];
0N/A } else {
0N/A return table[index];
0N/A }
0N/A }
0N/A
0N/A static byte getByteOrderByte() {
0N/A // 'l' - for little endian, 'B' - for big endian.
0N/A return ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ?
0N/A (byte)0x6C : (byte)0x42;
0N/A }
0N/A
0N/A static void writeDragInitiatorInfoStruct(long window, int index) throws XException {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A long structData = unsafe.allocateMemory(MOTIF_INITIATOR_INFO_SIZE);
0N/A
0N/A try {
0N/A // BYTE byte_order
0N/A unsafe.putByte(structData, getByteOrderByte());
0N/A // BYTE protocol_version
0N/A unsafe.putByte(structData + 1, MOTIF_DND_PROTOCOL_VERSION);
0N/A // CARD16 protocol_version
0N/A unsafe.putShort(structData + 2, (short)index);
0N/A // CARD32 icc_handle
0N/A unsafe.putInt(structData + 4, (int)XA_MOTIF_ATOM_0.getAtom());
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
0N/A XA_MOTIF_ATOM_0.getAtom(),
0N/A XA_MOTIF_DRAG_INITIATOR_INFO.getAtom(),
216N/A 8, XConstants.PropModeReplace,
0N/A structData, MOTIF_INITIATOR_INFO_SIZE);
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A throw new XException("Cannot write drag initiator info");
0N/A }
0N/A } finally {
0N/A unsafe.freeMemory(structData);
0N/A }
0N/A }
0N/A
0N/A static void writeDragReceiverInfoStruct(long window) throws XException {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
0N/A long data = unsafe.allocateMemory(dataSize);
0N/A
0N/A try {
0N/A unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
0N/A unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
0N/A unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
0N/A unsafe.putByte(data + 3, (byte)0); /* pad */
0N/A unsafe.putInt(data + 4, (int)window); /* proxy window */
0N/A unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
0N/A unsafe.putShort(data + 10, (short)0); /* pad */
0N/A unsafe.putInt(data + 12, dataSize);
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
0N/A XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
0N/A XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
216N/A 8, XConstants.PropModeReplace,
0N/A data, dataSize);
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A throw new XException("Cannot write Motif receiver info property");
0N/A }
0N/A } finally {
0N/A unsafe.freeMemory(data);
0N/A }
0N/A }
0N/A
0N/A public static int getMotifActionsForJavaActions(int javaActions) {
0N/A int motifActions = MOTIF_DND_NOOP;
0N/A
0N/A if ((javaActions & DnDConstants.ACTION_MOVE) != 0) {
0N/A motifActions |= MOTIF_DND_MOVE;
0N/A }
0N/A if ((javaActions & DnDConstants.ACTION_COPY) != 0) {
0N/A motifActions |= MOTIF_DND_COPY;
0N/A }
0N/A if ((javaActions & DnDConstants.ACTION_LINK) != 0) {
0N/A motifActions |= MOTIF_DND_LINK;
0N/A }
0N/A
0N/A return motifActions;
0N/A }
0N/A
0N/A public static int getJavaActionsForMotifActions(int motifActions) {
0N/A int javaActions = DnDConstants.ACTION_NONE;
0N/A
0N/A if ((motifActions & MOTIF_DND_MOVE) != 0) {
0N/A javaActions |= DnDConstants.ACTION_MOVE;
0N/A }
0N/A if ((motifActions & MOTIF_DND_COPY) != 0) {
0N/A javaActions |= DnDConstants.ACTION_COPY;
0N/A }
0N/A if ((motifActions & MOTIF_DND_LINK) != 0) {
0N/A javaActions |= DnDConstants.ACTION_LINK;
0N/A }
0N/A
0N/A return javaActions;
0N/A }
0N/A}