jdk/src/solaris/classes/sun/awt/X11/XDnDDropTargetProtocol.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.Point;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * XDropTargetProtocol implementation for XDnD protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class XDnDDropTargetProtocol extends XDropTargetProtocol {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final Logger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        Logger.getLogger("sun.awt.X11.xembed.xdnd.XDnDDropTargetProtocol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private long sourceWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private long sourceWindowMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int sourceProtocolVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private long[] sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private boolean trackSourceActions = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private int userAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int sourceX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private int sourceY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private XWindow targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // XEmbed stuff.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private long prevCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean overXEmbedClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected XDnDDropTargetProtocol(XDropTargetProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        super(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Creates an instance associated with the specified listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @throws NullPointerException if listener is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static XDropTargetProtocol createInstance(XDropTargetProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return new XDnDDropTargetProtocol(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public String getProtocolName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return XDragAndDropProtocols.XDnD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public void registerDropTarget(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        long data = Native.allocateLongArray(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            Native.putLong(data, 0, XDnDConstants.XDND_PROTOCOL_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            XDnDConstants.XA_XdndAware.setAtomData(window, XAtom.XA_ATOM, data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    96
                XToolkit.saved_error.get_error_code() != XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                throw new XException("Cannot write XdndAware property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void unregisterDropTarget(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        XDnDConstants.XA_XdndAware.DeleteProperty(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void registerEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        boolean overriden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        long proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        long newProxy = XDropTargetRegistry.getDnDProxyWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        WindowPropertyGetter wpg1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            new WindowPropertyGetter(embedder, XDnDConstants.XA_XdndAware, 0, 1,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   122
                                     false, XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            status = wpg1.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   127
            if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                wpg1.getData() != 0 && wpg1.getActualType() == XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                overriden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                version = (int)Native.getLong(wpg1.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            wpg1.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /* XdndProxy is not supported for prior to XDnD version 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (overriden && version >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            WindowPropertyGetter wpg2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                new WindowPropertyGetter(embedder, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                         0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                status = wpg2.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   146
                if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    wpg2.getData() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    wpg2.getActualType() == XAtom.XA_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    proxy = Native.getLong(wpg2.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                wpg2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (proxy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                WindowPropertyGetter wpg3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    new WindowPropertyGetter(proxy, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                             0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    status = wpg3.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   164
                    if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        wpg3.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        wpg3.getActualType() != XAtom.XA_WINDOW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                        Native.getLong(wpg3.getData()) != proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        WindowPropertyGetter wpg4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                            new WindowPropertyGetter(proxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                                     XDnDConstants.XA_XdndAware,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                                     0, 1, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   175
                                                     XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            status = wpg4.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   180
                            if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                wpg4.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                wpg4.getActualType() != XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            wpg4.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    wpg3.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (proxy == newProxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // Embedder already registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        long data = Native.allocateLongArray(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            Native.putLong(data, 0, XDnDConstants.XDND_PROTOCOL_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            /* The proxy window must have the XdndAware set, as XDnD protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
               prescribes to check the proxy window for XdndAware. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            XDnDConstants.XA_XdndAware.setAtomData(newProxy, XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                                   data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   215
                XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                throw new XException("Cannot write XdndAware property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            Native.putLong(data, 0, newProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            /* The proxy window must have the XdndProxy set to point to itself.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            XDnDConstants.XA_XdndProxy.setAtomData(newProxy, XAtom.XA_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                                   data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   229
                XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                throw new XException("Cannot write XdndProxy property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            Native.putLong(data, 0, XDnDConstants.XDND_PROTOCOL_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            XDnDConstants.XA_XdndAware.setAtomData(embedder, XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                   data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   242
                XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                throw new XException("Cannot write XdndAware property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            Native.putLong(data, 0, newProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            XDnDConstants.XA_XdndProxy.setAtomData(embedder, XAtom.XA_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                                   data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   255
                XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                throw new XException("Cannot write XdndProxy property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        putEmbedderRegistryEntry(embedder, overriden, version, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void unregisterEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        EmbedderRegistryEntry entry = getEmbedderRegistryEntry(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (entry.isOverriden()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            long data = Native.allocateLongArray(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                Native.putLong(data, 0, entry.getVersion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                XDnDConstants.XA_XdndAware.setAtomData(embedder, XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                                       data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   288
                    XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    throw new XException("Cannot write XdndAware property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                Native.putLong(data, 0, (int)entry.getProxy());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                XDnDConstants.XA_XdndProxy.setAtomData(embedder, XAtom.XA_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                                       data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                if (XToolkit.saved_error != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    XToolkit.saved_error.get_error_code() !=
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   301
                    XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    throw new XException("Cannot write XdndProxy property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            XDnDConstants.XA_XdndAware.DeleteProperty(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            XDnDConstants.XA_XdndProxy.DeleteProperty(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
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
     * Gets and stores in the registry the embedder's XDnD drop site info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * from the embedded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public void registerEmbeddedDropSite(long embedded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        boolean overriden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        long proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        long newProxy = XDropTargetRegistry.getDnDProxyWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        WindowPropertyGetter wpg1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            new WindowPropertyGetter(embedded, XDnDConstants.XA_XdndAware, 0, 1,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   329
                                     false, XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            status = wpg1.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   334
            if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                wpg1.getData() != 0 && wpg1.getActualType() == XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                overriden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                version = (int)Native.getLong(wpg1.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            wpg1.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        /* XdndProxy is not supported for prior to XDnD version 4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (overriden && version >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            WindowPropertyGetter wpg2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                new WindowPropertyGetter(embedded, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                         0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                status = wpg2.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   353
                if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    wpg2.getData() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    wpg2.getActualType() == XAtom.XA_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    proxy = Native.getLong(wpg2.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                wpg2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (proxy != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                WindowPropertyGetter wpg3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    new WindowPropertyGetter(proxy, XDnDConstants.XA_XdndProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                             0, 1, false, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    status = wpg3.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   371
                    if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        wpg3.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        wpg3.getActualType() != XAtom.XA_WINDOW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        Native.getLong(wpg3.getData()) != proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        WindowPropertyGetter wpg4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                            new WindowPropertyGetter(proxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                                                     XDnDConstants.XA_XdndAware,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                                     0, 1, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   382
                                                     XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                            status = wpg4.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   387
                            if (status != XConstants.Success ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                wpg4.getData() == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                wpg4.getActualType() != XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                            wpg4.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    wpg3.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        putEmbedderRegistryEntry(embedded, overriden, version, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public boolean isProtocolSupported(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        WindowPropertyGetter wpg1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            new WindowPropertyGetter(window, XDnDConstants.XA_XdndAware, 0, 1,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   411
                                     false, XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            int status = wpg1.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   416
            if (status == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                wpg1.getData() != 0 && wpg1.getActualType() == XAtom.XA_ATOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            wpg1.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private boolean processXdndEnter(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        long source_win = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        long source_win_mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int protocol_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int actions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        boolean track = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        long[] formats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (getSourceWindow() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (!(XToolkit.windowToXWindow(xclient.get_window()) instanceof XWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            && getEmbedderRegistryEntry(xclient.get_window()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (xclient.get_message_type() != XDnDConstants.XA_XdndEnter.getAtom()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        protocol_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            (int)((xclient.get_data(1) & XDnDConstants.XDND_PROTOCOL_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                  XDnDConstants.XDND_PROTOCOL_SHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        /* XDnD compliance only requires supporting version 3 and up. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (protocol_version < XDnDConstants.XDND_MIN_PROTOCOL_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        /* Ignore the source if the protocol version is higher than we support. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (protocol_version > XDnDConstants.XDND_PROTOCOL_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        source_win = xclient.get_data(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        /* Extract the list of supported actions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (protocol_version < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            /* Prior to XDnD version 2 only COPY action was supported. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            actions = DnDConstants.ACTION_COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                new WindowPropertyGetter(source_win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                         XDnDConstants.XA_XdndActionList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                         0, 0xFFFF, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                         XAtom.XA_ATOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                wpg.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (wpg.getActualType() == XAtom.XA_ATOM &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    wpg.getActualFormat() == 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    long data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    for (int i = 0; i < wpg.getNumberOfItems(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        actions |=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                            XDnDConstants.getJavaActionForXDnDAction(Native.getLong(data, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                     * According to XDnD protocol, XdndActionList is optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                     * If XdndActionList is not set we try to guess which actions are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                     * supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    actions = DnDConstants.ACTION_COPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    track = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        /* Extract the available data types. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if ((xclient.get_data(1) & XDnDConstants.XDND_DATA_TYPES_BIT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                new WindowPropertyGetter(source_win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                         XDnDConstants.XA_XdndTypeList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                         0, 0xFFFF, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                         XAtom.XA_ATOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                wpg.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                if (wpg.getActualType() == XAtom.XA_ATOM &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    wpg.getActualFormat() == 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    formats = Native.toLongs(wpg.getData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                             wpg.getNumberOfItems());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    formats = new long[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            int countFormats = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            long[] formats3 = new long[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                long j;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   526
                if ((j = xclient.get_data(2 + i)) != XConstants.None) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    formats3[countFormats++] = j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            formats = new long[countFormats];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            System.arraycopy(formats3, 0, formats, 0, countFormats);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * Select for StructureNotifyMask to receive DestroyNotify in case of source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * crash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            XToolkit.WITH_XERROR_HANDLER(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                                          source_win, wattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (status == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   552
                 XToolkit.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                throw new XException("XGetWindowAttributes failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            source_win_mask = wattr.get_your_event_mask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        XToolkit.WITH_XERROR_HANDLER(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        XlibWrapper.XSelectInput(XToolkit.getDisplay(), source_win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                 source_win_mask |
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   564
                                 XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   569
            XToolkit.saved_error.get_error_code() != XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throw new XException("XSelectInput failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        sourceWindow = source_win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        sourceWindowMask = source_win_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        sourceProtocolVersion = protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        sourceActions = actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        sourceFormats = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        trackSourceActions = track;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    private boolean processXdndPosition(XClientMessageEvent xclient) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   584
        long time_stamp = (int)XConstants.CurrentTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        long xdnd_action = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        int java_action = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        /* Ignore XDnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (sourceWindow != xclient.get_data(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        XWindow xwindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            XBaseWindow xbasewindow = XToolkit.windowToXWindow(xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        x = (int)(xclient.get_data(2) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        y = (int)(xclient.get_data(2) & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            long receiver =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                XDropTargetRegistry.getRegistry().getEmbeddedDropSite(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    xclient.get_window(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (receiver != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                XBaseWindow xbasewindow = XToolkit.windowToXWindow(receiver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (xwindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            /* Translate mouse position from root coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
               to the target window coordinates. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            Point p = xwindow.toLocal(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        /* Time stamp - new in XDnD version 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (sourceProtocolVersion > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            time_stamp = xclient.get_data(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        /* User action - new in XDnD version 2. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        if (sourceProtocolVersion > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            xdnd_action = xclient.get_data(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            /* The default action is XdndActionCopy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            xdnd_action = XDnDConstants.XA_XdndActionCopy.getAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        java_action = XDnDConstants.getJavaActionForXDnDAction(xdnd_action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        if (trackSourceActions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            sourceActions |= java_action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                notifyProtocolListener(targetXWindow, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                       DnDConstants.ACTION_NONE, xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                       MouseEvent.MOUSE_EXITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            int java_event_id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            if (targetXWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                java_event_id = MouseEvent.MOUSE_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                java_event_id = MouseEvent.MOUSE_DRAGGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            notifyProtocolListener(xwindow, x, y, java_action, xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                   java_event_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        userAction = java_action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        sourceX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        sourceY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        targetXWindow = xwindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    private boolean processXdndLeave(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        /* Ignore XDnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (sourceWindow != xclient.get_data(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private boolean processXdndDrop(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        /* Ignore XDnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (sourceWindow != xclient.get_data(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            notifyProtocolListener(targetXWindow, sourceX, sourceY, userAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                   xclient, MouseEvent.MOUSE_RELEASED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public int getMessageType(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        long messageType = xclient.get_message_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        if (messageType == XDnDConstants.XA_XdndEnter.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return ENTER_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        } else if (messageType == XDnDConstants.XA_XdndPosition.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return MOTION_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        } else if (messageType == XDnDConstants.XA_XdndLeave.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return LEAVE_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        } else if (messageType == XDnDConstants.XA_XdndDrop.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            return DROP_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return UNKNOWN_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    protected boolean processClientMessageImpl(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        long messageType = xclient.get_message_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (messageType == XDnDConstants.XA_XdndEnter.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            return processXdndEnter(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        } else if (messageType == XDnDConstants.XA_XdndPosition.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            return processXdndPosition(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        } else if (messageType == XDnDConstants.XA_XdndLeave.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return processXdndLeave(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        } else if (messageType == XDnDConstants.XA_XdndDrop.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return processXdndDrop(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    protected void sendEnterMessageToToplevel(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                              XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        long data1 = sourceProtocolVersion << XDnDConstants.XDND_PROTOCOL_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        if (sourceFormats != null && sourceFormats.length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            data1 |= XDnDConstants.XDND_DATA_TYPES_BIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        long data2 = sourceFormats.length > 0 ? sourceFormats[0] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        long data3 = sourceFormats.length > 1 ? sourceFormats[1] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        long data4 = sourceFormats.length > 2 ? sourceFormats[2] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        sendEnterMessageToToplevelImpl(toplevel, xclient.get_data(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                       data1, data2, data3, data4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    private void sendEnterMessageToToplevelImpl(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                                                long sourceWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                                long data1, long data2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                                                long data3, long data4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        XClientMessageEvent enter = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   751
            enter.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            enter.set_window(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            enter.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            enter.set_message_type(XDnDConstants.XA_XdndEnter.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            /* XID of the source window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            enter.set_data(0, sourceWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            enter.set_data(1, data1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            enter.set_data(2, data2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            enter.set_data(3, data3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            enter.set_data(4, data4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            forwardClientMessageToToplevel(toplevel, enter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            enter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    protected void sendLeaveMessageToToplevel(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                              XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        sendLeaveMessageToToplevelImpl(toplevel, xclient.get_data(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    protected void sendLeaveMessageToToplevelImpl(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                                                  long sourceWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        XClientMessageEvent leave = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   777
            leave.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            leave.set_window(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            leave.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            leave.set_message_type(XDnDConstants.XA_XdndLeave.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            /* XID of the source window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            leave.set_data(0, sourceWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            leave.set_data(1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            forwardClientMessageToToplevel(toplevel, leave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            leave.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public boolean sendResponse(long ctxt, int eventID, int action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            XDnDConstants.XA_XdndPosition.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (eventID == MouseEvent.MOUSE_EXITED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            action = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   807
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            msg.set_window(xclient.get_data(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            msg.set_message_type(XDnDConstants.XA_XdndStatus.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            /* target window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            msg.set_data(0, xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            long flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            if (action != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                flags |= XDnDConstants.XDND_ACCEPT_DROP_FLAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            msg.set_data(1, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            /* specify an empty rectangle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            msg.set_data(2, 0); /* x, y */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            msg.set_data(3, 0); /* w, h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            /* action accepted by the target */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            msg.set_data(4, XDnDConstants.getXDnDActionForJavaAction(action));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                       xclient.get_data(0),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   829
                                       false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                                       msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public Object getData(long ctxt, long format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
      throws IllegalArgumentException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        long message_type = xclient.get_message_type();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   845
        long time_stamp = XConstants.CurrentTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        // NOTE: we assume that the source supports at least version 1, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        // can use the time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        if (message_type == XDnDConstants.XA_XdndPosition.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            // X server time is an unsigned 32-bit number!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            time_stamp = xclient.get_data(3) & 0xFFFFFFFFL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        } else if (message_type == XDnDConstants.XA_XdndDrop.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            // X server time is an unsigned 32-bit number!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            time_stamp = xclient.get_data(2) & 0xFFFFFFFFL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return XDnDConstants.XDnDSelection.getData(format, time_stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public boolean sendDropDone(long ctxt, boolean success, int dropAction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            XDnDConstants.XA_XdndDrop.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * The XDnD protocol recommends that the target requests the special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * target DELETE in case if the drop action is XdndActionMove.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (dropAction == DnDConstants.ACTION_MOVE && success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            long time_stamp = xclient.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            long xdndSelectionAtom =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                XDnDConstants.XDnDSelection.getSelectionAtom().getAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                XlibWrapper.XConvertSelection(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                              xdndSelectionAtom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                              XAtom.get("DELETE").getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                                              XAtom.get("XAWT_SELECTION").getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                              XWindow.getXAWTRootWindow().getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                              time_stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   895
            msg.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            msg.set_window(xclient.get_data(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            msg.set_message_type(XDnDConstants.XA_XdndFinished.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            msg.set_data(0, xclient.get_window()); /* target window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            msg.set_data(1, 0); /* flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            /* specify an empty rectangle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            msg.set_data(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            if (sourceProtocolVersion >= 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                if (success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    msg.set_data(1, XDnDConstants.XDND_ACCEPT_DROP_FLAG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                /* action performed by the target */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                msg.set_data(2, XDnDConstants.getXDnDActionForJavaAction(dropAction));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            msg.set_data(3, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            msg.set_data(4, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                       xclient.get_data(0),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   917
                                       false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                                       msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * Flush the buffer to guarantee that the drop completion event is sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         * to the source before the method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        /* Trick to prevent cleanup() from posting dragExit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        /* Cannot do cleanup before the drop finishes as we may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
           source protocol version to send drop finished message. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    public final long getSourceWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return sourceWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * Reset the state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    public void cleanup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        // Clear the reference to this protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        XDropTargetEventProcessor.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            notifyProtocolListener(targetXWindow, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                                   DnDConstants.ACTION_NONE, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                   MouseEvent.MOUSE_EXITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if (sourceWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                XToolkit.WITH_XERROR_HANDLER(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                         sourceWindowMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        sourceWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        sourceWindowMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        sourceProtocolVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        trackSourceActions = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        userAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        sourceX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        sourceY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    public boolean isDragOverComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        return targetXWindow != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    public void adjustEventForForwarding(XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                                         EmbedderRegistryEntry entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        /* Adjust the event to match the XDnD protocol version. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        int version = entry.getVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        if (xclient.get_message_type() == XDnDConstants.XA_XdndEnter.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            int min_version = sourceProtocolVersion < version ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                sourceProtocolVersion : version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            long data1 = min_version << XDnDConstants.XDND_PROTOCOL_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (sourceFormats != null && sourceFormats.length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                data1 |= XDnDConstants.XDND_DATA_TYPES_BIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                logger.finest("         "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                              + " entryVersion=" + version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                              + " sourceProtocolVersion=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                              sourceProtocolVersion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                              + " sourceFormats.length=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                              (sourceFormats != null ? sourceFormats.length : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            xclient.set_data(1, data1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    private void notifyProtocolListener(XWindow xwindow, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                                        int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                                        XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                                        int eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        long nativeCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        // Make a copy of the passed XClientMessageEvent structure, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        // the original structure can be freed before this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        // SunDropTargetEvent is dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        if (xclient != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            int size = new XClientMessageEvent(nativeCtxt).getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            nativeCtxt = unsafe.allocateMemory(size + 4 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            unsafe.copyMemory(xclient.pData, nativeCtxt, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            long data1 = sourceProtocolVersion << XDnDConstants.XDND_PROTOCOL_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            if (sourceFormats != null && sourceFormats.length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                data1 |= XDnDConstants.XDND_DATA_TYPES_BIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            // Append information from the latest XdndEnter event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            Native.putLong(nativeCtxt + size, data1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            Native.putLong(nativeCtxt + size + Native.getLongSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                           sourceFormats.length > 0 ? sourceFormats[0] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            Native.putLong(nativeCtxt + size + 2 * Native.getLongSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                           sourceFormats.length > 1 ? sourceFormats[1] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            Native.putLong(nativeCtxt + size + 3 * Native.getLongSize(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                           sourceFormats.length > 2 ? sourceFormats[2] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        getProtocolListener().handleDropTargetNotification(xwindow, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                                           dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                                                           sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                                                           sourceFormats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                                                           nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                                           eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * The methods/fields defined below are executed/accessed only on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * The methods/fields defined below are executed/accessed only on the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * dispatch thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public boolean forwardEventToEmbedded(long embedded, long ctxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                                          int eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            logger.finest("        ctxt=" + ctxt +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                          " type=" + (ctxt != 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                                      getMessageType(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                          XClientMessageEvent(ctxt)) : 0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                          " prevCtxt=" + prevCtxt +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                          " prevType=" + (prevCtxt != 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                      getMessageType(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                          XClientMessageEvent(prevCtxt)) : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        if ((ctxt == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
             getMessageType(new XClientMessageEvent(ctxt)) == UNKNOWN_MESSAGE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            (prevCtxt == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
             getMessageType(new XClientMessageEvent(prevCtxt)) == UNKNOWN_MESSAGE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        // The size of XClientMessageEvent structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        int size = XClientMessageEvent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (ctxt != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            if (!overXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                long data1 = Native.getLong(ctxt + size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                long data2 = Native.getLong(ctxt + size + Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                long data3 = Native.getLong(ctxt + size + 2 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                long data4 = Native.getLong(ctxt + size + 3 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    logger.finest("         1 "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                                  + " embedded=" + embedded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                                  + " source=" + xclient.get_data(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                                  + " data1=" + data1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                  + " data2=" + data2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                                  + " data3=" + data3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                                  + " data4=" + data4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                // Copy XdndTypeList from source to proxy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                if ((data1 & XDnDConstants.XDND_DATA_TYPES_BIT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                    WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                        new WindowPropertyGetter(xclient.get_data(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                                 XDnDConstants.XA_XdndTypeList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                                 0, 0xFFFF, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                                 XAtom.XA_ATOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                        wpg.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                        if (wpg.getActualType() == XAtom.XA_ATOM &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                            wpg.getActualFormat() == 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                                XToolkit.WITH_XERROR_HANDLER(XWM.VerifyChangePropertyHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                                XDnDConstants.XA_XdndTypeList.setAtomData(xclient.get_window(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                                                                          XAtom.XA_ATOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                                                                          wpg.getData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                                                                          wpg.getNumberOfItems());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                                XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                                if (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1122
                                    XToolkit.saved_error.get_error_code() != XConstants.Success) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                                    if (logger.isLoggable(Level.WARNING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                                        logger.warning("Cannot set XdndTypeList on the proxy window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                            if (logger.isLoggable(Level.WARNING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                                logger.warning("Cannot read XdndTypeList from the source window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                        wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                XDragSourceContextPeer.setProxyModeSourceWindow(xclient.get_data(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                sendEnterMessageToToplevelImpl(embedded, xclient.get_window(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                               data1, data2, data3, data4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                overXEmbedClient = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                logger.finest("         2 "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                              + " embedded=" + embedded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                              + " xclient=" + xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            /* Make a copy of the original event, since we are going to modify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
               event while it still can be referenced from other Java events. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                XClientMessageEvent copy = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                unsafe.copyMemory(xclient.pData, copy.pData, copy.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                copy.set_data(0, xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                forwardClientMessageToToplevel(embedded, copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        if (eventID == MouseEvent.MOUSE_EXITED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            if (overXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                if (ctxt != 0 || prevCtxt != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                    // Last chance to send XdndLeave to the XEmbed client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    XClientMessageEvent xclient = ctxt != 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                        new XClientMessageEvent(ctxt) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        new XClientMessageEvent(prevCtxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                    sendLeaveMessageToToplevelImpl(embedded, xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                overXEmbedClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                // We have to clear the proxy mode source window here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                // when the drag exits the XEmbedCanvasPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                // NOTE: at this point the XEmbed client still might have some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                // drag notifications to process and it will send responses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                // us. With the proxy mode source window cleared we won't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                // able to forward these responses to the actual source. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                // not a problem if the drag operation was initiated in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                // JVM. However, if it was initiated in another processes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                // responses will be lost. We bear with it for now, as it seems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                // there is no other reliable point to clear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                XDragSourceContextPeer.setProxyModeSourceWindow(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        if (eventID == MouseEvent.MOUSE_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            overXEmbedClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        if (prevCtxt != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            unsafe.freeMemory(prevCtxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            prevCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        if (ctxt != 0 && overXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            prevCtxt = unsafe.allocateMemory(size + 4 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            unsafe.copyMemory(ctxt, prevCtxt, size + 4 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    public boolean isXEmbedSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
}