jdk/src/solaris/classes/sun/awt/X11/MotifDnDDropTargetProtocol.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 22584 eed64ee05369
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 17679
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
    23
 * questions.
2
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 sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * XDropTargetProtocol implementation for Motif DnD protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class MotifDnDDropTargetProtocol extends XDropTargetProtocol {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private long sourceWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private long sourceWindowMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int sourceProtocolVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private int sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private long[] sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private long sourceAtom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int userAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int sourceX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int sourceY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private XWindow targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private boolean topLevelLeavePostponed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected MotifDnDDropTargetProtocol(XDropTargetProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Creates an instance associated with the specified listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @throws NullPointerException if listener is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static XDropTargetProtocol createInstance(XDropTargetProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return new MotifDnDDropTargetProtocol(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public String getProtocolName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return XDragAndDropProtocols.MotifDnD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public void registerDropTarget(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        MotifDnDConstants.writeDragReceiverInfoStruct(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void unregisterDropTarget(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        MotifDnDConstants.XA_MOTIF_ATOM_0.DeleteProperty(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void registerEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        boolean overriden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        long proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        long newProxy = XDropTargetRegistry.getDnDProxyWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        long data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            new WindowPropertyGetter(embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                     MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                     0, 0xFFFF, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   102
                                     XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   105
            status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             * DragICCI.h:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
             * typedef struct _xmDragReceiverInfoStruct{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
             *     BYTE byte_order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
             *     BYTE protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
             *     BYTE drag_protocol_style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             *     BYTE pad1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
             *     CARD32       proxy_window B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
             *     CARD16       num_drop_sites B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             *     CARD16       pad2 B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             *     CARD32       heap_offset B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
             * } xmDragReceiverInfoStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             */
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 17679
diff changeset
   121
            if (status == XConstants.Success && wpg.getData() != 0 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                wpg.getNumberOfItems() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                overriden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                dataSize = wpg.getNumberOfItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                byte byteOrderByte = unsafe.getByte(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    int tproxy = unsafe.getInt(data + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        tproxy = MotifDnDConstants.Swapper.swap(tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    proxy = tproxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (proxy == newProxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    // Embedder already registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    int tproxy = (int)newProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        tproxy = MotifDnDConstants.Swapper.swap(tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    unsafe.putInt(data + 4, tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                data = unsafe.allocateMemory(dataSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                unsafe.putByte(data + 3, (byte)0); /* pad */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                unsafe.putInt(data + 4, (int)newProxy); /* proxy window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                unsafe.putShort(data + 10, (short)0); /* pad */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                unsafe.putInt(data + 12, dataSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   165
            XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                        MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                        MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   169
                                        8, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                        data, dataSize);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   171
            XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   173
            if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   174
                (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                throw new XException("Cannot write Motif receiver info property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (!overriden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                data = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        putEmbedderRegistryEntry(embedder, overriden, version, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public void unregisterEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        EmbedderRegistryEntry entry = getEmbedderRegistryEntry(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (entry.isOverriden()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                new WindowPropertyGetter(embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                         MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                         0, 0xFFFF, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   204
                                         XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   207
                status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                 * DragICCI.h:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                 * typedef struct _xmDragReceiverInfoStruct{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                 *     BYTE     byte_order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                 *     BYTE     protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                 *     BYTE     drag_protocol_style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                 *     BYTE     pad1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                 *     CARD32   proxy_window B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                 *     CARD16   num_drop_sites B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                 *     CARD16   pad2 B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                 *     CARD32   heap_offset B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                 * } xmDragReceiverInfoStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                 */
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 17679
diff changeset
   223
                if (status == XConstants.Success && wpg.getData() != 0 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    wpg.getNumberOfItems() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    long data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    byte byteOrderByte = unsafe.getByte(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    int tproxy = (int)entry.getProxy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    if (MotifDnDConstants.getByteOrderByte() != byteOrderByte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        tproxy = MotifDnDConstants.Swapper.swap(tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    unsafe.putInt(data + 4, tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   239
                    XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                                MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                                MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   243
                                                8, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                                data, dataSize);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   245
                    XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   247
                    if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   248
                        (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        throw new XException("Cannot write Motif receiver info property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.DeleteProperty(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Gets and stores in the registry the embedder's Motif DnD drop site info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * from the embedded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public void registerEmbeddedDropSite(long embedded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        boolean overriden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        int version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        long proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            new WindowPropertyGetter(embedded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                     MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                     0, 0xFFFF, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   276
                                     XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   279
            status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
             * DragICCI.h:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
             * typedef struct _xmDragReceiverInfoStruct{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
             *     BYTE byte_order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
             *     BYTE protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
             *     BYTE drag_protocol_style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
             *     BYTE pad1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
             *     CARD32       proxy_window B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
             *     CARD16       num_drop_sites B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
             *     CARD16       pad2 B16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             *     CARD32       heap_offset B32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
             * } xmDragReceiverInfoStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
             */
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 17679
diff changeset
   295
            if (status == XConstants.Success && wpg.getData() != 0 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                wpg.getNumberOfItems() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                overriden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                long data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                byte byteOrderByte = unsafe.getByte(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    int tproxy = unsafe.getInt(data + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        tproxy = MotifDnDConstants.Swapper.swap(tproxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    proxy = tproxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        putEmbedderRegistryEntry(embedded, overriden, version, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public boolean isProtocolSupported(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            new WindowPropertyGetter(window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                     MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                     0, 0xFFFF, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   325
                                     XConstants.AnyPropertyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   328
            int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 17679
diff changeset
   330
            if (status == XConstants.Success && wpg.getData() != 0 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                wpg.getNumberOfItems() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private boolean processTopLevelEnter(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (targetXWindow != null || sourceWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (!(XToolkit.windowToXWindow(xclient.get_window()) instanceof XWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            && getEmbedderRegistryEntry(xclient.get_window()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        long source_win = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        long source_win_mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int protocol_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        long property_atom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        long[] formats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            source_win = MotifDnDConstants.Swapper.getInt(data + 8, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            property_atom = MotifDnDConstants.Swapper.getInt(data + 12, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        /* Extract the available data types. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                new WindowPropertyGetter(source_win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                         XAtom.get(property_atom),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                         0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                         false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                         MotifDnDConstants.XA_MOTIF_DRAG_INITIATOR_INFO.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   378
                int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   380
                if (status == XConstants.Success && wpg.getData() != 0 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    wpg.getActualType() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    MotifDnDConstants.XA_MOTIF_DRAG_INITIATOR_INFO.getAtom() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    wpg.getActualFormat() == 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    wpg.getNumberOfItems() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    MotifDnDConstants.MOTIF_INITIATOR_INFO_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    long data = wpg.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    byte propertyByteOrder = unsafe.getByte(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    protocol_version = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    if (protocol_version !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    int index =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        MotifDnDConstants.Swapper.getShort(data + 2, propertyByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    formats = MotifDnDConstants.getTargetListForIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    formats = new long[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * Select for StructureNotifyMask to receive DestroyNotify in case of source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * crash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        try {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   415
            XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                                          source_win, wattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   419
            XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   421
            if ((status == 0) ||
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   422
                ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   423
                (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                throw new XException("XGetWindowAttributes failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            source_win_mask = wattr.get_your_event_mask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   432
        XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        XlibWrapper.XSelectInput(XToolkit.getDisplay(), source_win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                 source_win_mask |
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   435
                                 XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   437
        XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   439
        if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
   440
            (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            throw new XException("XSelectInput failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        sourceWindow = source_win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        sourceWindowMask = source_win_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        sourceProtocolVersion = protocol_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * TOP_LEVEL_ENTER doesn't communicate the list of supported actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         * They are provided in DRAG_MOTION.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        sourceFormats = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        sourceAtom = property_atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private boolean processDragMotion(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        byte eventReason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                  MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        short flags = MotifDnDConstants.Swapper.getShort(data + 2, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        int motif_action = (flags & MotifDnDConstants.MOTIF_DND_ACTION_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            MotifDnDConstants.MOTIF_DND_ACTION_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        int motif_actions = (flags & MotifDnDConstants.MOTIF_DND_ACTIONS_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            MotifDnDConstants.MOTIF_DND_ACTIONS_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        int java_action = MotifDnDConstants.getJavaActionsForMotifActions(motif_action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        int java_actions = MotifDnDConstants.getJavaActionsForMotifActions(motif_actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        /* Append source window id to the event data, so that we can send the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
           response properly. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            int win = (int)sourceWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (eventByteOrder != MotifDnDConstants.getByteOrderByte()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                win = MotifDnDConstants.Swapper.swap(win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            unsafe.putInt(data + 12, win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        XWindow xwindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            XBaseWindow xbasewindow = XToolkit.windowToXWindow(xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (eventReason == MotifDnDConstants.OPERATION_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            /* OPERATION_CHANGED event doesn't provide coordinates, so we use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
               previously stored position and component ref. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            x = sourceX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            y = sourceY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                xwindow = targetXWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            x = MotifDnDConstants.Swapper.getShort(data + 8, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            y = MotifDnDConstants.Swapper.getShort(data + 10, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                long receiver =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    XDropTargetRegistry.getRegistry().getEmbeddedDropSite(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        xclient.get_window(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                if (receiver != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    XBaseWindow xbasewindow = XToolkit.windowToXWindow(receiver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (xwindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                Point p = xwindow.toLocal(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                notifyProtocolListener(targetXWindow, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                       DnDConstants.ACTION_NONE, java_actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                       xclient, MouseEvent.MOUSE_EXITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            int java_event_id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (targetXWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                java_event_id = MouseEvent.MOUSE_ENTERED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                java_event_id = MouseEvent.MOUSE_DRAGGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            notifyProtocolListener(xwindow, x, y, java_action, java_actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                   xclient, java_event_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        sourceActions = java_actions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        userAction = java_action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        sourceX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        sourceY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        targetXWindow = xwindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    private boolean processTopLevelLeave(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        long source_win = MotifDnDConstants.Swapper.getInt(data + 8, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        /* Ignore Motif DnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (source_win != sourceWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         * Postpone upcall to java, so that we can abort it in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         * if drop immediatelly follows (see BugTraq ID 4395290).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * Send a dummy ClientMessage event to guarantee that a postponed java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * upcall will be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        topLevelLeavePostponed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            long proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
             * If this is an embedded drop site, the event should go to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
             * awt_root_window as this is a proxy for all embedded drop sites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
             * Otherwise the event should go to the event->window, as we don't use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
             * proxies for normal drop sites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            if (getEmbedderRegistryEntry(xclient.get_window()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                proxy = XDropTargetRegistry.getDnDProxyWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                proxy = xclient.get_window();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            XClientMessageEvent dummy = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   593
                dummy.set_type(XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                dummy.set_window(xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                dummy.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                dummy.set_message_type(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                dummy.set_data(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                dummy.set_data(1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                dummy.set_data(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                dummy.set_data(3, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                dummy.set_data(4, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   603
                                       proxy, false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                       dummy.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                dummy.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private boolean processDropStart(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        long source_win =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            MotifDnDConstants.Swapper.getInt(data + 16, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        /* Ignore Motif DnD messages from all other windows. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if (source_win != sourceWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        long property_atom =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            MotifDnDConstants.Swapper.getInt(data + 12, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        short flags =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            MotifDnDConstants.Swapper.getShort(data + 2, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        int motif_action = (flags & MotifDnDConstants.MOTIF_DND_ACTION_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            MotifDnDConstants.MOTIF_DND_ACTION_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        int motif_actions = (flags & MotifDnDConstants.MOTIF_DND_ACTIONS_MASK) >>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            MotifDnDConstants.MOTIF_DND_ACTIONS_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        int java_action = MotifDnDConstants.getJavaActionsForMotifActions(motif_action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        int java_actions = MotifDnDConstants.getJavaActionsForMotifActions(motif_actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        int x = MotifDnDConstants.Swapper.getShort(data + 8, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        int y = MotifDnDConstants.Swapper.getShort(data + 10, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        XWindow xwindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            XBaseWindow xbasewindow = XToolkit.windowToXWindow(xclient.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if (xwindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            long receiver =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                XDropTargetRegistry.getRegistry().getEmbeddedDropSite(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    xclient.get_window(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (receiver != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                XBaseWindow xbasewindow = XToolkit.windowToXWindow(receiver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                if (xbasewindow instanceof XWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    xwindow = (XWindow)xbasewindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (xwindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            Point p = xwindow.toLocal(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (xwindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            notifyProtocolListener(xwindow, x, y, java_action, java_actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                   xclient, MouseEvent.MOUSE_RELEASED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        } else if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            notifyProtocolListener(targetXWindow, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                   DnDConstants.ACTION_NONE, java_actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                   xclient, MouseEvent.MOUSE_EXITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    public int getMessageType(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return UNKNOWN_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                             MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        case MotifDnDConstants.TOP_LEVEL_ENTER :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return ENTER_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        case MotifDnDConstants.DRAG_MOTION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        case MotifDnDConstants.OPERATION_CHANGED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            return MOTION_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        case MotifDnDConstants.TOP_LEVEL_LEAVE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            return LEAVE_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        case MotifDnDConstants.DROP_START :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            return DROP_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return UNKNOWN_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    protected boolean processClientMessageImpl(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            if (topLevelLeavePostponed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                topLevelLeavePostponed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        byte origin = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            MotifDnDConstants.MOTIF_MESSAGE_SENDER_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if (topLevelLeavePostponed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            topLevelLeavePostponed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (reason != MotifDnDConstants.DROP_START) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                cleanup();
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
        /* Only initiator messages should be handled. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (origin != MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        case MotifDnDConstants.TOP_LEVEL_ENTER :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return processTopLevelEnter(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        case MotifDnDConstants.DRAG_MOTION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        case MotifDnDConstants.OPERATION_CHANGED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return processDragMotion(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        case MotifDnDConstants.TOP_LEVEL_LEAVE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            return processTopLevelLeave(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        case MotifDnDConstants.DROP_START :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            return processDropStart(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * Currently we don't synthesize enter/leave messages for Motif DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * protocol. See comments in XDropTargetProtocol.postProcessClientMessage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    protected void sendEnterMessageToToplevel(long win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                              XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        throw new Error("UNIMPLEMENTED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    protected void sendLeaveMessageToToplevel(long win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                              XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        throw new Error("UNIMPLEMENTED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public boolean forwardEventToEmbedded(long embedded, long ctxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                          int eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        // UNIMPLEMENTED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    public boolean isXEmbedSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public boolean sendResponse(long ctxt, int eventID, int action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        byte origin = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            MotifDnDConstants.MOTIF_MESSAGE_SENDER_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        byte response_reason = (byte)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        /* Only initiator messages should be handled. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (origin != MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        case MotifDnDConstants.TOP_LEVEL_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        case MotifDnDConstants.TOP_LEVEL_LEAVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            /* Receiver shouldn't rely to these messages. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        case MotifDnDConstants.DRAG_MOTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            switch (eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                response_reason = MotifDnDConstants.DROP_SITE_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                response_reason = MotifDnDConstants.DRAG_MOTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                response_reason = MotifDnDConstants.DROP_SITE_LEAVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        case MotifDnDConstants.OPERATION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        case MotifDnDConstants.DROP_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            response_reason = reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            // Unknown reason. Shouldn't get here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   824
            msg.set_type(XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            msg.set_window(MotifDnDConstants.Swapper.getInt(data + 12, eventByteOrder));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            msg.set_format(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            msg.set_message_type(MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            long responseData = msg.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            unsafe.putByte(responseData, (byte)(response_reason |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                           MotifDnDConstants.MOTIF_MESSAGE_FROM_RECEIVER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            unsafe.putByte(responseData + 1, MotifDnDConstants.getByteOrderByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            int response_flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            if (response_reason != MotifDnDConstants.DROP_SITE_LEAVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                short flags = MotifDnDConstants.Swapper.getShort(data + 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                                                 eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                byte dropSiteStatus = (action == DnDConstants.ACTION_NONE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    MotifDnDConstants.MOTIF_INVALID_DROP_SITE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    MotifDnDConstants.MOTIF_VALID_DROP_SITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                /* Clear action and drop site status bits. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                response_flags = flags &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    ~MotifDnDConstants.MOTIF_DND_ACTION_MASK &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    ~MotifDnDConstants.MOTIF_DND_STATUS_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                /* Fill in new action and drop site status. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                response_flags |=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    MotifDnDConstants.getMotifActionsForJavaActions(action) <<
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    MotifDnDConstants.MOTIF_DND_ACTION_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                response_flags |=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    dropSiteStatus << MotifDnDConstants.MOTIF_DND_STATUS_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                response_flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            unsafe.putShort(responseData + 2, (short)response_flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            /* Write time stamp. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            int time = MotifDnDConstants.Swapper.getInt(data + 4, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            unsafe.putInt(responseData + 4, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            /* Write coordinates. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            if (response_reason != MotifDnDConstants.DROP_SITE_LEAVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                short x = MotifDnDConstants.Swapper.getShort(data + 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                                             eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                short y = MotifDnDConstants.Swapper.getShort(data + 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                                             eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                unsafe.putShort(responseData + 8, x); // x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                unsafe.putShort(responseData + 10, y); // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                unsafe.putShort(responseData + 8, (short)0); // x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                unsafe.putShort(responseData + 10, (short)0); // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                       msg.get_window(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 117
diff changeset
   881
                                       false, XConstants.NoEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                       msg.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public Object getData(long ctxt, long format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
      throws IllegalArgumentException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        byte origin = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            MotifDnDConstants.MOTIF_MESSAGE_SENDER_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (origin != MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            throw new IOException("Cannot get data: corrupted context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        long selatom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        switch (reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        case MotifDnDConstants.DRAG_MOTION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        case MotifDnDConstants.OPERATION_CHANGED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            selatom = sourceAtom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        case MotifDnDConstants.DROP_START :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            selatom = MotifDnDConstants.Swapper.getInt(data + 12, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            throw new IOException("Cannot get data: invalid message reason");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        if (selatom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            throw new IOException("Cannot get data: drag source property atom unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
7495
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   931
        long time_stamp = MotifDnDConstants.Swapper.getInt(data + 4, eventByteOrder) & 0xffffffffL;
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   932
                          // with correction of (32-bit unsigned to 64-bit signed) implicit conversion.
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   933
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        XAtom selectionAtom = XAtom.get(selatom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        XSelection selection = XSelection.getSelection(selectionAtom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (selection == null) {
117
766ae458aaf1 6538066: XSelection should be more passive
son
parents: 2
diff changeset
   938
            selection = new XSelection(selectionAtom);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        return selection.getData(format, time_stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public boolean sendDropDone(long ctxt, boolean success, int dropAction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (xclient.get_message_type() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        long data = xclient.get_data();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        byte reason = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            MotifDnDConstants.MOTIF_MESSAGE_REASON_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        byte origin = (byte)(unsafe.getByte(data) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            MotifDnDConstants.MOTIF_MESSAGE_SENDER_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        byte eventByteOrder = unsafe.getByte(data + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (origin != MotifDnDConstants.MOTIF_MESSAGE_FROM_INITIATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            return false;
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 (reason != MotifDnDConstants.DROP_START) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
7495
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   967
        long time_stamp = MotifDnDConstants.Swapper.getInt(data + 4, eventByteOrder) & 0xffffffffL;
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   968
                          // with correction of (32-bit unsigned to 64-bit signed) implicit conversion.
f807f6b93084 6578041: Drag & Drop from Motif to Java does not work.
dmeetry
parents: 5506
diff changeset
   969
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        long sel_atom = MotifDnDConstants.Swapper.getInt(data + 12, eventByteOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        long status_atom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if (success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            status_atom = MotifDnDConstants.XA_XmTRANSFER_SUCCESS.getAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            status_atom = MotifDnDConstants.XA_XmTRANSFER_FAILURE.getAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            XlibWrapper.XConvertSelection(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                          sel_atom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                                          status_atom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                                          MotifDnDConstants.XA_MOTIF_ATOM_0.getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                                          XWindow.getXAWTRootWindow().getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                                          time_stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
             * Flush the buffer to guarantee that the drop completion event is sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
             * to the source before the method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        /* Trick to prevent cleanup() from posting dragExit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        /* Cannot do cleanup before the drop finishes as we may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
           source protocol version to send drop finished message. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public final long getSourceWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        return sourceWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * Reset the state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    public void cleanup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        // Clear the reference to this protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        XDropTargetEventProcessor.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        if (targetXWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            notifyProtocolListener(targetXWindow, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                   DnDConstants.ACTION_NONE, sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                                   null, MouseEvent.MOUSE_EXITED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        if (sourceWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            try {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
  1027
                XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                                         sourceWindowMask);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 7495
diff changeset
  1030
                XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        sourceWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        sourceWindowMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        sourceProtocolVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        sourceAtom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        userAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        sourceX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        sourceY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        targetXWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        topLevelLeavePostponed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public boolean isDragOverComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return targetXWindow != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    private void notifyProtocolListener(XWindow xwindow, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                                        int dropAction, int actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                        XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                                        int eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        long nativeCtxt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        // Make a copy of the passed XClientMessageEvent structure, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        // the original structure can be freed before this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        // SunDropTargetEvent is dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        if (xclient != null) {
117
766ae458aaf1 6538066: XSelection should be more passive
son
parents: 2
diff changeset
  1063
            int size = XClientMessageEvent.getSize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            nativeCtxt = unsafe.allocateMemory(size + 4 * Native.getLongSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            unsafe.copyMemory(xclient.pData, nativeCtxt, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        getProtocolListener().handleDropTargetNotification(xwindow, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                                                           dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                                           actions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                                           sourceFormats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                                                           nativeCtxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                                                           eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
}