jdk/src/solaris/classes/sun/awt/X11/XDropTargetProtocol.java
author yan
Tue, 28 Apr 2009 13:41:11 -0700
changeset 2660 3c98e01dcbcf
parent 439 3488710b02f8
child 3938 ef327bd847c0
child 4191 ca8d3ef845c8
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * An abstract class for drop protocols on X11 systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Contains protocol-independent drop target code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
abstract class XDropTargetProtocol {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final Logger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        Logger.getLogger("sun.awt.X11.xembed.xdnd.XDropTargetProtocol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final XDropTargetProtocolListener listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static final int EMBEDDER_ALREADY_REGISTERED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int UNKNOWN_MESSAGE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final int ENTER_MESSAGE   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int MOTION_MESSAGE  = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int LEAVE_MESSAGE   = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int DROP_MESSAGE    = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected XDropTargetProtocol(XDropTargetProtocolListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            throw new NullPointerException("Null XDropTargetProtocolListener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.listener = listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected final XDropTargetProtocolListener getProtocolListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return listener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Returns the protocol name. The protocol name cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public abstract String getProtocolName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public abstract void registerDropTarget(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public abstract void unregisterDropTarget(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public abstract void registerEmbedderDropSite(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public abstract void unregisterEmbedderDropSite(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public abstract void registerEmbeddedDropSite(long embedded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public final void unregisterEmbeddedDropSite(long embedded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        removeEmbedderRegistryEntry(embedded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public abstract boolean isProtocolSupported(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public abstract int getMessageType(XClientMessageEvent xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public final boolean processClientMessage(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int type = getMessageType(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        boolean processed = processClientMessageImpl(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        postProcessClientMessage(xclient, processed, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return processed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* The caller must hold AWT_LOCK. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected abstract boolean processClientMessageImpl(XClientMessageEvent xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Forwards a drag notification to the embedding toplevel modifying the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * to match the protocol version supported by the toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The caller must hold AWT_LOCK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns True if the event is sent, False otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected final boolean forwardClientMessageToToplevel(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                           XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        EmbedderRegistryEntry entry = getEmbedderRegistryEntry(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            logger.log(Level.FINEST, "        entry={0}", new Object[] {entry});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // Window not registered as an embedder for this protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            logger.log(Level.FINEST, "        entry.isOverriden()={0}", new Object[] {entry.isOverriden()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // Window didn't have an associated drop site, so there is no need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // to forward the message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (!entry.isOverriden()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        adjustEventForForwarding(xclient, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        long proxy = entry.getProxy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            logger.log(Level.FINEST, "        proxy={0} toplevel={1}", new Object[] {proxy, toplevel});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (proxy == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            proxy = toplevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        xclient.set_window(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            XlibWrapper.XSendEvent(XToolkit.getDisplay(), proxy, false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   152
                                   XConstants.NoEventMask, xclient.pData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* True iff the previous notification was MotionEvent and it was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
       forwarded to the browser. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private boolean motionPassedAlong = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected abstract void sendEnterMessageToToplevel(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                                       XClientMessageEvent xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected abstract void sendLeaveMessageToToplevel(long toplevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                                       XClientMessageEvent xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private void postProcessClientMessage(XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                          boolean processed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                          int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        long toplevel = xclient.get_window();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (getEmbedderRegistryEntry(toplevel) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
             * This code forwards drag notifications to the browser according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
             * following rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
             *  - the messages that we failed to process are always forwarded to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             *    browser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
             *  - MotionEvents and DropEvents are forwarded if and only if the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             *    is not over a plugin window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             *  - XDnD: EnterEvents and LeaveEvents are never forwarded, instead, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             *    send synthesized EnterEvents or LeaveEvents when the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             *    respectively exits or enters plugin windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             *  - Motif DnD: EnterEvents and LeaveEvents are always forwarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
             * Synthetic EnterEvents and LeaveEvents are needed, because the XDnD drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             * site implemented Netscape 6.2 has a nice feature: when it receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             * the first XdndPosition it continuously sends XdndStatus messages to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
             * the source (every 100ms) until the drag terminates or leaves the drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             * site. When the mouse is dragged over plugin window embedded in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             * browser frame, these XdndStatus messages are mixed with the XdndStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             * messages sent from the plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
             * For Motif DnD, synthetic events cause Motif warnings being displayed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             * so these events are always forwarded. However, Motif DnD drop site in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             * Netscape 6.2 is implemented in the same way, so there could be similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             * problems if the drag source choose Motif DnD for communication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (!processed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                forwardClientMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                boolean motifProtocol =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    xclient.get_message_type() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    MotifDnDConstants.XA_MOTIF_DRAG_AND_DROP_MESSAGE.getAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                case XDropTargetProtocol.MOTION_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    if (!isDragOverComponent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        if (!motionPassedAlong && !motifProtocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            sendEnterMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        forwardClientMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        motionPassedAlong = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        if (motionPassedAlong && !motifProtocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                            sendLeaveMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        motionPassedAlong = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                case XDropTargetProtocol.DROP_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    if (!isDragOverComponent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        forwardClientMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    motionPassedAlong = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                case XDropTargetProtocol.ENTER_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                case XDropTargetProtocol.LEAVE_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    if (motifProtocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        forwardClientMessageToToplevel(toplevel, xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    motionPassedAlong = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public abstract boolean sendResponse(long ctxt, int eventID, int action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Retrieves the data from the drag source in the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param ctxt a pointer to the XClientMessageEvent structure for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *             protocol's drop message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param format the format in which the data should be retrieved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws IllegalArgumentException if ctxt doesn't point to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *         XClientMessageEvent structure for this protocol's drop message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws IOException if data retrieval failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public abstract Object getData(long ctxt, long format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      throws IllegalArgumentException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public abstract boolean sendDropDone(long ctxt, boolean success,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                         int dropAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public abstract long getSourceWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public abstract void cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public abstract boolean isDragOverComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void adjustEventForForwarding(XClientMessageEvent xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        EmbedderRegistryEntry entry) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public abstract boolean forwardEventToEmbedded(long embedded, long ctxt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                                   int eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns true if the XEmbed protocol prescribes that an XEmbed server must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * support this DnD protocol for drop sites associated with XEmbed clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public abstract boolean isXEmbedSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    protected static final class EmbedderRegistryEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        private final boolean overriden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        private final int version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        private final long proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        EmbedderRegistryEntry(boolean overriden, int version, long proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            this.overriden = overriden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            this.version = version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            this.proxy = proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        public boolean isOverriden() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return overriden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        public int getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        public long getProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /* Access to HashMap is synchronized on this XDropTargetProtocol instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private final HashMap embedderRegistry = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    protected final void putEmbedderRegistryEntry(long embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                                  boolean overriden,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                                  int version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                                  long proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            embedderRegistry.put(Long.valueOf(embedder),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                 new EmbedderRegistryEntry(overriden, version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                                           proxy));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    protected final EmbedderRegistryEntry getEmbedderRegistryEntry(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                (EmbedderRegistryEntry)embedderRegistry.get(Long.valueOf(embedder));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected final void removeEmbedderRegistryEntry(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        synchronized (this) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   320
            embedderRegistry.remove(Long.valueOf(embedder));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}