jdk/src/solaris/classes/sun/awt/X11/XDnDDragSourceProtocol.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 439 3488710b02f8
child 2802 d05a9dcc8296
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
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 java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * XDragSourceProtocol implementation for XDnD protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class XDnDDragSourceProtocol extends XDragSourceProtocol {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final Logger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        Logger.getLogger("sun.awt.X11.xembed.xdnd.XDnDDragSourceProtocol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected XDnDDragSourceProtocol(XDragSourceProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super(listener);
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 XDnDDragSourceProtocol(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.XDnD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Performs protocol-specific drag initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @returns true if the initialized successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected void initializeDragImpl(int actions, Transferable contents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                         Map formatMap, long[] formats)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
      throws InvalidDnDOperationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        IllegalArgumentException, XException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        long window = XDragSourceProtocol.getDragSourceWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        long data = Native.allocateLongArray(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int action_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if ((actions & DnDConstants.ACTION_COPY) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                Native.putLong(data, action_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                               XDnDConstants.XA_XdndActionCopy.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                action_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if ((actions & DnDConstants.ACTION_MOVE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                Native.putLong(data, action_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                               XDnDConstants.XA_XdndActionMove.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                action_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if ((actions & DnDConstants.ACTION_LINK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                Native.putLong(data, action_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                               XDnDConstants.XA_XdndActionLink.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                action_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            XDnDConstants.XA_XdndActionList.setAtomData(window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                                        XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                                        data, action_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   106
                XToolkit.saved_error.get_error_code() != XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                throw new XException("Cannot write XdndActionList property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        data = Native.allocateLongArray(formats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            Native.put(data, formats);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            XDnDConstants.XA_XdndTypeList.setAtomData(window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                                      XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                      data, formats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   127
                XToolkit.saved_error.get_error_code() != XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                throw new XException("Cannot write XdndActionList property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (!XDnDConstants.XDnDSelection.setOwner(contents, formatMap, formats,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   137
                                                  XConstants.CurrentTime)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new InvalidDnDOperationException("Cannot acquire selection ownership");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private boolean processXdndStatus(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        int action = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /* Ignore XDnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (xclient.get_data(0) != getTargetWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if ((xclient.get_data(1) & XDnDConstants.XDND_ACCEPT_DROP_FLAG) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            /* This feature is new in XDnD version 2, but we can use it as XDnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
               compliance only requires supporting version 3 and up. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            action = XDnDConstants.getJavaActionForXDnDAction(xclient.get_data(4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        getProtocolListener().handleDragReply(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private boolean processXdndFinished(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /* Ignore XDnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (xclient.get_data(0) != getTargetWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (getTargetProtocolVersion() >= 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            boolean success = (xclient.get_data(1) & XDnDConstants.XDND_ACCEPT_DROP_FLAG) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            int action = XDnDConstants.getJavaActionForXDnDAction(xclient.get_data(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            getProtocolListener().handleDragFinished(success, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            getProtocolListener().handleDragFinished();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        finalizeDrop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public boolean processClientMessage(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (xclient.get_message_type() == XDnDConstants.XA_XdndStatus.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return processXdndStatus(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        } else if (xclient.get_message_type() == XDnDConstants.XA_XdndFinished.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return processXdndFinished(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public TargetWindowInfo getTargetWindowInfo(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        WindowPropertyGetter wpg1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            new WindowPropertyGetter(window, XDnDConstants.XA_XdndAware, 0, 1,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   196
                                     false, XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int status = wpg1.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   200
        if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            wpg1.getData() != 0 && wpg1.getActualType() == XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            int targetVersion = (int)Native.getLong(wpg1.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            wpg1.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (targetVersion >= XDnDConstants.XDND_MIN_PROTOCOL_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                long proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                int protocolVersion =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    targetVersion < XDnDConstants.XDND_PROTOCOL_VERSION ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    targetVersion : XDnDConstants.XDND_PROTOCOL_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                WindowPropertyGetter wpg2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    new WindowPropertyGetter(window, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                             0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    status = wpg2.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   220
                    if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        wpg2.getData() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        wpg2.getActualType() == XAtom.XA_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        proxy = Native.getLong(wpg2.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    wpg2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                if (proxy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    WindowPropertyGetter wpg3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        new WindowPropertyGetter(proxy, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                                 0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        status = wpg3.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   238
                        if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                            wpg3.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                            wpg3.getActualType() != XAtom.XA_WINDOW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            Native.getLong(wpg3.getData()) != proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            WindowPropertyGetter wpg4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                new WindowPropertyGetter(proxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                                         XDnDConstants.XA_XdndAware,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                                         0, 1, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   249
                                                         XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                status = wpg4.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   254
                                if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                    wpg4.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                    wpg4.getActualType() != XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                    proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                wpg4.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        wpg3.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                return new TargetWindowInfo(proxy, protocolVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            wpg1.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void sendEnterMessage(long[] formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                 int sourceAction, int sourceActions, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        assert formats != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   286
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            msg.set_message_type(XDnDConstants.XA_XdndEnter.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            msg.set_data(0, XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            long data1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                getTargetProtocolVersion() << XDnDConstants.XDND_PROTOCOL_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            data1 |= formats.length > 3 ? XDnDConstants.XDND_DATA_TYPES_BIT : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            msg.set_data(1, data1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            msg.set_data(2, formats.length > 0 ? formats[0] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            msg.set_data(3, formats.length > 1 ? formats[1] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            msg.set_data(4, formats.length > 2 ? formats[2] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                   getTargetProxyWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   300
                                   false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public void sendMoveMessage(int xRoot, int yRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                int sourceAction, int sourceActions, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   314
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            msg.set_message_type(XDnDConstants.XA_XdndPosition.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            msg.set_data(0, XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            msg.set_data(1, 0); /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            msg.set_data(2, xRoot << 16 | yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            msg.set_data(3, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            msg.set_data(4, XDnDConstants.getXDnDActionForJavaAction(sourceAction));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                   getTargetProxyWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   325
                                   false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public void sendLeaveMessage(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   338
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            msg.set_message_type(XDnDConstants.XA_XdndLeave.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            msg.set_data(0, XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            msg.set_data(1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            msg.set_data(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            msg.set_data(3, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            msg.set_data(4, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                   getTargetProxyWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   349
                                   false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void sendDropMessage(int xRoot, int yRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                int sourceAction, int sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        assert getTargetWindow() != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   364
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            msg.set_window(getTargetWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            msg.set_message_type(XDnDConstants.XA_XdndDrop.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            msg.set_data(0, XDragSourceProtocol.getDragSourceWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            msg.set_data(1, 0); /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            msg.set_data(2, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            msg.set_data(3, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            msg.set_data(4, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                   getTargetProxyWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   375
                                   false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                   msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public boolean processProxyModeEvent(XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                         long sourceWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (xclient.get_message_type() == XDnDConstants.XA_XdndStatus.getAtom() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            xclient.get_message_type() == XDnDConstants.XA_XdndFinished.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (xclient.get_message_type() == XDnDConstants.XA_XdndFinished.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                XDragSourceContextPeer.setProxyModeSourceWindow(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // This can happen if the drag operation started in the XEmbed server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // In this case there is no need to forward it elsewhere, we should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // process it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (xclient.get_window() == sourceWindow) {
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
            if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                logger.finest("        sourceWindow=" + sourceWindow +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                              " get_window=" + xclient.get_window() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                              " xclient=" + xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            xclient.set_data(0, xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            xclient.set_window(sourceWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            XlibWrapper.XSendEvent(XToolkit.getDisplay(), sourceWindow,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   409
                                   false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                   xclient.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // TODO: register this runnable with XDnDSelection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // XdndSelection ownership lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
}