jdk/src/solaris/classes/sun/awt/X11/MotifDnDDragSourceProtocol.java
author anthony
Tue, 18 Mar 2008 16:19:03 +0300
changeset 129 f995b9c9c5fa
parent 2 90ce3da70b43
child 439 3488710b02f8
permissions -rw-r--r--
6589527: Window and Frame instances can hide their "Applet Warning" Summary: Additional constraints have been added for the setBounds() operation. Reviewed-by: son, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.dnd.DnDConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * XDragSourceProtocol implementation for Motif DnD protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class MotifDnDDragSourceProtocol extends XDragSourceProtocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    implements XEventDispatcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private long targetEnterServerTime = XlibWrapper.CurrentTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected MotifDnDDragSourceProtocol(XDragSourceProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Creates an instance associated with the specified listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @throws NullPointerException if listener is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static XDragSourceProtocol createInstance(XDragSourceProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return new MotifDnDDragSourceProtocol(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public String getProtocolName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return XDragAndDropProtocols.MotifDnD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected void initializeDragImpl(int actions, Transferable contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                      Map formatMap, long[] formats)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      throws InvalidDnDOperationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        IllegalArgumentException, XException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        long window = XDragSourceProtocol.getDragSourceWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        /* Write the Motif DnD initiator info on the root XWindow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            int index = MotifDnDConstants.getIndexForTargetList(formats);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            MotifDnDConstants.writeDragInitiatorInfoStruct(window, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } catch (XException xe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw xe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (InvalidDnDOperationException idoe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw idoe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (!MotifDnDConstants.MotifDnDSelection.setOwner(contents, formatMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                                          formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                                          XlibWrapper.CurrentTime)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new InvalidDnDOperationException("Cannot acquire selection ownership");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Processes the specified client message event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @returns true if the event was successfully processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public boolean processClientMessage(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        byte origin = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            MotifDnDConstants.MOTIF_MESSAGE_SENDER_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        byte byteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        boolean swapNeeded = byteOrder != MotifDnDConstants.getByteOrderByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        int action = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* Only receiver messages should be handled. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (origin != MotifDnDConstants.MOTIF_MESSAGE_FROM_RECEIVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        case MotifDnDConstants.DROP_SITE_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        case MotifDnDConstants.DROP_SITE_LEAVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        case MotifDnDConstants.DRAG_MOTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        case MotifDnDConstants.OPERATION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // Unknown reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int t = unsafe.getInt(data + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (swapNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            t = MotifDnDConstants.Swapper.swap(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        long time = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /* Discard events from the previous receiver. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (targetEnterServerTime == XlibWrapper.CurrentTime ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            time < targetEnterServerTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (reason != MotifDnDConstants.DROP_SITE_LEAVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            short flags = unsafe.getShort(data + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (swapNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                flags = MotifDnDConstants.Swapper.swap(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            byte status = (byte)((flags & MotifDnDConstants.MOTIF_DND_STATUS_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                MotifDnDConstants.MOTIF_DND_STATUS_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            byte motif_action = (byte)((flags & MotifDnDConstants.MOTIF_DND_ACTION_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                MotifDnDConstants.MOTIF_DND_ACTION_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (status == MotifDnDConstants.MOTIF_VALID_DROP_SITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                action = MotifDnDConstants.getJavaActionsForMotifActions(motif_action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                action = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            short tx = unsafe.getShort(data + 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            short ty = unsafe.getShort(data + 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (swapNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                tx = MotifDnDConstants.Swapper.swap(tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                ty = MotifDnDConstants.Swapper.swap(ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            x = tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            y = ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        getProtocolListener().handleDragReply(action, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public TargetWindowInfo getTargetWindowInfo(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            new WindowPropertyGetter(window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                     MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                     0, 0xFFFF, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                     XlibWrapper.AnyPropertyType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            int status = wpg.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             * DragICCI.h:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             * typedef struct _xmDragReceiverInfoStruct{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             *     BYTE byte_order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             *     BYTE protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
             *     BYTE drag_protocol_style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             *     BYTE pad1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             *     CARD32       proxy_window B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             *     CARD16       num_drop_sites B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             *     CARD16       pad2 B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
             *     CARD32       heap_offset B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             * } xmDragReceiverInfoStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (status == (int)XlibWrapper.Success && wpg.getData() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                wpg.getNumberOfItems() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                long data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                byte byteOrderByte = unsafe.getByte(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                byte dragProtocolStyle = unsafe.getByte(data + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                switch (dragProtocolStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                case MotifDnDConstants.MOTIF_PREFER_PREREGISTER_STYLE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                case MotifDnDConstants.MOTIF_PREFER_DYNAMIC_STYLE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                case MotifDnDConstants.MOTIF_DYNAMIC_STYLE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                case MotifDnDConstants.MOTIF_PREFER_RECEIVER_STYLE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    int proxy = unsafe.getInt(data + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        proxy = MotifDnDConstants.Swapper.swap(proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    int protocolVersion = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    return new TargetWindowInfo(proxy, protocolVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    // Unsupported protocol style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void sendEnterMessage(long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                 int sourceAction, int sourceActions, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        assert formats != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        targetEnterServerTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            msg.set_type(XlibWrapper.ClientMessage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            msg.set_format(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            msg.set_message_type(MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            long data = msg.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            int flags =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceAction) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                 MotifDnDConstants.MOTIF_DND_ACTION_SHIFT) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceActions) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                 MotifDnDConstants.MOTIF_DND_ACTIONS_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            unsafe.putByte(data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                           (byte)(MotifDnDConstants.TOP_LEVEL_ENTER |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                  MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            unsafe.putByte(data + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                           MotifDnDConstants.getByteOrderByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            unsafe.putShort(data + 2, (short)flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            unsafe.putInt(data + 4, (int)time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            unsafe.putInt(data + 8, (int)XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            unsafe.putInt(data + 12, (int)MotifDnDConstants.XA_MOTIF_ATOM_0.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                   getTargetProxyWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                   false, XlibWrapper.NoEventMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public void sendMoveMessage(int xRoot, int yRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                int sourceAction, int sourceActions, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            msg.set_type(XlibWrapper.ClientMessage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            msg.set_format(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            msg.set_message_type(MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            long data = msg.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            int flags =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceAction) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                 MotifDnDConstants.MOTIF_DND_ACTION_SHIFT) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceActions) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                 MotifDnDConstants.MOTIF_DND_ACTIONS_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            unsafe.putByte(data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                           (byte)(MotifDnDConstants.DRAG_MOTION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                  MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            unsafe.putByte(data + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                           MotifDnDConstants.getByteOrderByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            unsafe.putShort(data + 2, (short)flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            unsafe.putInt(data + 4, (int)time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            unsafe.putShort(data + 8, (short)xRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            unsafe.putShort(data + 10, (short)yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                   getTargetProxyWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                   false, XlibWrapper.NoEventMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void sendLeaveMessage(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            msg.set_type(XlibWrapper.ClientMessage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            msg.set_format(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            msg.set_message_type(MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            long data = msg.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            unsafe.putByte(data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                           (byte)(MotifDnDConstants.TOP_LEVEL_LEAVE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                  MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            unsafe.putByte(data + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                           MotifDnDConstants.getByteOrderByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            unsafe.putShort(data + 2, (short)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            unsafe.putInt(data + 4, (int)time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            unsafe.putInt(data + 8, (int)XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                   getTargetProxyWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                   false, XlibWrapper.NoEventMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    protected void sendDropMessage(int xRoot, int yRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                   int sourceAction, int sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                   long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * Motif drop sites expect TOP_LEVEL_LEAVE before DROP_START.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        sendLeaveMessage(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            msg.set_type(XlibWrapper.ClientMessage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            msg.set_format(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            msg.set_message_type(MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            long data = msg.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            int flags =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceAction) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                 MotifDnDConstants.MOTIF_DND_ACTION_SHIFT) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                (MotifDnDConstants.getMotifActionsForJavaActions(sourceActions) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                 MotifDnDConstants.MOTIF_DND_ACTIONS_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            unsafe.putByte(data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                           (byte)(MotifDnDConstants.DROP_START |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                  MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            unsafe.putByte(data + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                           MotifDnDConstants.getByteOrderByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            unsafe.putShort(data + 2, (short)flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            unsafe.putInt(data + 4, (int)time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            unsafe.putShort(data + 8, (short)xRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            unsafe.putShort(data + 10, (short)yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            unsafe.putInt(data + 12, (int)MotifDnDConstants.XA_MOTIF_ATOM_0.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            unsafe.putInt(data + 16, (int)XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                   getTargetProxyWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                   false, XlibWrapper.NoEventMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public boolean processProxyModeEvent(XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                         long sourceWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        // Motif DnD for XEmbed is not implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void cleanupTargetInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        super.cleanupTargetInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        targetEnterServerTime = XlibWrapper.CurrentTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        switch (ev.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        case XlibWrapper.SelectionRequest:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            XSelectionRequestEvent xsre = ev.get_xselectionrequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            long atom = xsre.get_selection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (atom == MotifDnDConstants.XA_MOTIF_ATOM_0.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                long target = xsre.get_target();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                if (target == MotifDnDConstants.XA_XmTRANSFER_SUCCESS.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    getProtocolListener().handleDragFinished(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                } else if (target == MotifDnDConstants.XA_XmTRANSFER_FAILURE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    getProtocolListener().handleDragFinished(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}