jdk/src/solaris/classes/sun/awt/X11/XDragSourceContextPeer.java
author anthony
Tue, 18 Mar 2008 16:19:03 +0300
changeset 129 f995b9c9c5fa
parent 2 90ce3da70b43
child 439 3488710b02f8
permissions -rw-r--r--
6589527: Window and Frame instances can hide their "Applet Warning" Summary: Additional constraints have been added for the setBounds() operation. Reviewed-by: son, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.datatransfer.Transferable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.dnd.DnDConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.dnd.DragGestureEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.ComponentAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.dnd.SunDragSourceContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.awt.dnd.SunDropTargetContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The XDragSourceContextPeer class is the class responsible for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the interaction between the XDnD/Motif DnD subsystem and Java drag sources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public final class XDragSourceContextPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    extends SunDragSourceContextPeer implements XDragSourceProtocolListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final Logger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        Logger.getLogger("sun.awt.X11.xembed.xdnd.XDragSourceContextPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* The events selected on the root window when the drag begins. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final int ROOT_EVENT_MASK = (int)XlibWrapper.ButtonMotionMask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        (int)XlibWrapper.KeyPressMask | (int)XlibWrapper.KeyReleaseMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /* The events to be delivered during grab. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final int GRAB_EVENT_MASK = (int)XlibWrapper.ButtonPressMask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        (int)XlibWrapper.ButtonMotionMask | (int)XlibWrapper.ButtonReleaseMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* The event mask of the root window before the drag operation starts. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private long rootEventMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean dndInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private boolean dragInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private long dragRootWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* The protocol chosen for the communication with the current drop target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private XDragSourceProtocol dragProtocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /* The drop action chosen by the current drop target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private int targetAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* The set of drop actions supported by the drag source. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* The drop action selected by the drag source based on the modifiers state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
       and the action selected by the current drop target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private int sourceAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* The data formats supported by the drag source for the current drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
       operation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private long[] sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* The XID of the root subwindow that contains the current target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private long targetRootSubwindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /* The pointer location. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private int xRoot = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private int yRoot = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /* Keyboard modifiers state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private int eventState = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /* XEmbed DnD support. We act as a proxy between source and target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private long proxyModeSourceWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /* The singleton instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final XDragSourceContextPeer theInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        new XDragSourceContextPeer(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private XDragSourceContextPeer(DragGestureEvent dge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super(dge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static XDragSourceProtocolListener getXDragSourceProtocolListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static XDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    theInstance.setTrigger(dge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected void startDrag(Transferable transferable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                             long[] formats, Map formatMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Component component = getTrigger().getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Component c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        XWindowPeer wpeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        for (c = component; c != null && !(c instanceof Window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             c = ComponentAccessor.getParent_NoClientCode(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (c instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            wpeer = (XWindowPeer)c.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (wpeer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new InvalidDnDOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                "Cannot find top-level for the drag source component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        long xcursor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        long rootWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        long dragWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        long timeStamp = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        /* Retrieve the X cursor for the drag operation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            Cursor cursor = getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (cursor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                xcursor = XGlobalCursorManager.getCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (proxyModeSourceWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                throw new InvalidDnDOperationException("Proxy drag in progress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (dndInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                throw new InvalidDnDOperationException("Drag in progress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            /* Determine the root window for the drag operation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            dragWindow = XWindow.getXAWTRootWindow().getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            timeStamp = XToolkit.getCurrentServerTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            int dropActions = getDragSourceContext().getSourceActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            while (dragProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    dragProtocol.initializeDrag(dropActions, transferable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                                formatMap, formats);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                } catch (XException xe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    throw (InvalidDnDOperationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        new InvalidDnDOperationException().initCause(xe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            /* Install X grabs. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                                              rootWindow, wattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    if (status == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        throw new InvalidDnDOperationException("XGetWindowAttributes failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    rootEventMask = wattr.get_your_event_mask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    XlibWrapper.XSelectInput(XToolkit.getDisplay(), rootWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                             rootEventMask | ROOT_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                XBaseWindow.ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                status = XlibWrapper.XGrabPointer(XToolkit.getDisplay(), rootWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                                  0, GRAB_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                                  XlibWrapper.GrabModeAsync,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                                  XlibWrapper.GrabModeAsync,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                                  XlibWrapper.None, xcursor, timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if (status != XlibWrapper.GrabSuccess) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    cleanup(timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    throwGrabFailureException("Cannot grab pointer", status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                status = XlibWrapper.XGrabKeyboard(XToolkit.getDisplay(), rootWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                                   XlibWrapper.GrabModeAsync,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                                   XlibWrapper.GrabModeAsync,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                                   timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (status != XlibWrapper.GrabSuccess) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    cleanup(timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    throwGrabFailureException("Cannot grab keyboard", status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            /* Update the global state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            dndInProgress = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            dragInProgress = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            dragRootWindow = rootWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            sourceActions = dropActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            sourceFormats = formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        /* This implementation doesn't use native context */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        setNativeContext(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public long getProxyModeSourceWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return proxyModeSourceWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private void setProxyModeSourceWindowImpl(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        proxyModeSourceWindow = window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static void setProxyModeSourceWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        theInstance.setProxyModeSourceWindowImpl(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * set cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void setCursor(Cursor c) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            super.setCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        long xcursor = XGlobalCursorManager.getCursor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (xcursor == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        XlibWrapper.XChangeActivePointerGrab(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                             GRAB_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                             xcursor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                             XlibWrapper.CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected boolean needsBogusExitBeforeDrop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private void throwGrabFailureException(String msg, int grabStatus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        String msgCause = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        switch (grabStatus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        case XlibWrapper.GrabNotViewable:  msgCause = "not viewable";    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        case XlibWrapper.AlreadyGrabbed:   msgCause = "already grabbed"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        case XlibWrapper.GrabInvalidTime:  msgCause = "invalid time";    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        case XlibWrapper.GrabFrozen:       msgCause = "grab frozen";     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        default:                           msgCause = "unknown failure"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        throw new InvalidDnDOperationException(msg + ": " + msgCause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * The caller must own awtLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void cleanup(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (dndInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                dragProtocol.sendLeaveMessage(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (targetAction != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                dragExit(xRoot, yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            dragDropFinished(false, DnDConstants.ACTION_NONE, xRoot, yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        while (dragProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                dragProtocol.cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            } catch (XException xe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                // Ignore the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        dndInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        dragInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        dragRootWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        sourceFormats = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        sourceActions = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        sourceAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        eventState = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        xRoot = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        yRoot = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        cleanupTargetInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        removeDnDGrab(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * The caller must own awtLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private void cleanupTargetInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        targetAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        dragProtocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        targetRootSubwindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private void removeDnDGrab(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        /* Restore the root event mask if it was changed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if ((rootEventMask | ROOT_EVENT_MASK) != rootEventMask &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            dragRootWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            XlibWrapper.XSelectInput(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                     dragRootWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                     rootEventMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        rootEventMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        dragRootWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    private boolean processClientMessage(XClientMessageEvent xclient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return dragProtocol.processClientMessage(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Updates the source action according to the specified state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @returns true if the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private boolean updateSourceAction(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        int action = SunDragSourceContextPeer.convertModifiersToDropAction(XWindow.getModifiers(state, 0, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                                                           sourceActions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (sourceAction == action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        sourceAction = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Returns the client window under the specified root subwindow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private static long findClientWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (XlibUtil.isTrueToplevelWindow(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        Set<Long> children = XlibUtil.getChildWindows(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        for (Long child : children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            long win = findClientWindow(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (win != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                return win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private void doUpdateTargetWindow(long subwindow, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        long clientWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        long proxyWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        XDragSourceProtocol protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        boolean isReceiver = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (subwindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            clientWindow = findClientWindow(subwindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (clientWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            while (dragProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (dragProtocol.attachTargetWindow(clientWindow, time)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    protocol = dragProtocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        /* Update the global state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        dragProtocol = protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        targetAction = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        targetRootSubwindow = subwindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    private void updateTargetWindow(XMotionEvent xmotion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int x = xmotion.get_x_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int y = xmotion.get_y_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        long time = xmotion.get_time();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        long subwindow = xmotion.get_subwindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         * If this event had occurred before the pointer was grabbed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         * query the server for the current root subwindow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (xmotion.get_window() != xmotion.get_root()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            XlibWrapper.XQueryPointer(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                      xmotion.get_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                      XlibWrapper.larg1,  // root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                      XlibWrapper.larg2,  // subwindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                      XlibWrapper.larg3,  // x_root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                      XlibWrapper.larg4,  // y_root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                      XlibWrapper.larg5,  // x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                                      XlibWrapper.larg6,  // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                      XlibWrapper.larg7); // modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            subwindow = Native.getLong(XlibWrapper.larg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (targetRootSubwindow != subwindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                dragProtocol.sendLeaveMessage(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                 * Neither Motif DnD nor XDnD provide a mean for the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                 * to notify the source that the pointer exits the drop site
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                 * that occupies the whole top level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                 * We detect this situation and post dragExit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (targetAction != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    dragExit(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            /* Update the global state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            doUpdateTargetWindow(subwindow, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                dragProtocol.sendEnterMessage(sourceFormats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                              sourceAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                              sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                              time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * DO NOT USE is_hint field of xmotion since it could not be set when we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * convert XKeyEvent or XButtonRelease to XMotionEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    private void processMouseMove(XMotionEvent xmotion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (!dragInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (xRoot != xmotion.get_x_root() || yRoot != xmotion.get_y_root()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            xRoot = xmotion.get_x_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            yRoot = xmotion.get_y_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            postDragSourceDragEvent(targetAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                    XWindow.getModifiers(xmotion.get_state(),0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                    xRoot, yRoot, DISPATCH_MOUSE_MOVED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (eventState != xmotion.get_state()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (updateSourceAction(xmotion.get_state()) && dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                postDragSourceDragEvent(targetAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                        XWindow.getModifiers(xmotion.get_state(),0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                        xRoot, yRoot, DISPATCH_CHANGED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            eventState = xmotion.get_state();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        updateTargetWindow(xmotion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (dragProtocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            dragProtocol.sendMoveMessage(xmotion.get_x_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                         xmotion.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                         sourceAction, sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                         xmotion.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private void processDrop(XButtonEvent xbutton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            dragProtocol.initiateDrop(xbutton.get_x_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                      xbutton.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                      sourceAction, sourceActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                      xbutton.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } catch (XException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            cleanup(xbutton.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    private boolean processProxyModeEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if (getProxyModeSourceWindow() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (ev.get_type() != (int)XlibWrapper.ClientMessage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (logger.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            logger.finest("        proxyModeSourceWindow=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                          getProxyModeSourceWindow() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                          " ev=" + ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        XClientMessageEvent xclient = ev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        while (dragProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            XDragSourceProtocol dragProtocol =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                (XDragSourceProtocol)dragProtocols.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            if (dragProtocol.processProxyModeEvent(xclient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                                   getProxyModeSourceWindow())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * The caller must own awtLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @returns true if the even was processed and shouldn't be passed along.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    private boolean doProcessEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (processProxyModeEvent(ev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (!dndInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        switch (ev.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        case XlibWrapper.ClientMessage: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            XClientMessageEvent xclient = ev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            return processClientMessage(xclient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        case XlibWrapper.DestroyNotify: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            XDestroyWindowEvent xde = ev.get_xdestroywindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            /* Target crashed during drop processing - cleanup. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (!dragInProgress &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                dragProtocol != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                xde.get_window() == dragProtocol.getTargetWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                cleanup(XlibWrapper.CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            /* Pass along */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (!dragInProgress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /* Process drag-only messages. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        switch (ev.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        case XlibWrapper.KeyRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        case XlibWrapper.KeyPress: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            XKeyEvent xkey = ev.get_xkey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            long keysym = XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                                       xkey.get_keycode(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            switch ((int)keysym) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            case (int)XKeySymConstants.XK_Escape: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                if (ev.get_type() == (int)XlibWrapper.KeyRelease) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    cleanup(xkey.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            case (int)XKeySymConstants.XK_Control_R:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            case (int)XKeySymConstants.XK_Control_L:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            case (int)XKeySymConstants.XK_Shift_R:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            case (int)XKeySymConstants.XK_Shift_L: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                XlibWrapper.XQueryPointer(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                                          xkey.get_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                          XlibWrapper.larg1,  // root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                          XlibWrapper.larg2,  // subwindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                          XlibWrapper.larg3,  // x_root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                          XlibWrapper.larg4,  // y_root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                          XlibWrapper.larg5,  // x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                          XlibWrapper.larg6,  // y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                          XlibWrapper.larg7); // modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                XMotionEvent xmotion = new XMotionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    xmotion.set_type(XlibWrapper.MotionNotify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    xmotion.set_serial(xkey.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    xmotion.set_send_event(xkey.get_send_event());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    xmotion.set_display(xkey.get_display());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    xmotion.set_window(xkey.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    xmotion.set_root(xkey.get_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    xmotion.set_subwindow(xkey.get_subwindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    xmotion.set_time(xkey.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    xmotion.set_x(xkey.get_x());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    xmotion.set_y(xkey.get_y());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    xmotion.set_x_root(xkey.get_x_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                    xmotion.set_y_root(xkey.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    xmotion.set_state((int)Native.getLong(XlibWrapper.larg7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    // we do not use this field, so it's unset for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    // xmotion.set_is_hint(???);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    xmotion.set_same_screen(xkey.get_same_screen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    //It's safe to use key event as motion event since we use only their common fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    processMouseMove(xmotion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    xmotion.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        case XlibWrapper.ButtonPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        case XlibWrapper.MotionNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            processMouseMove(ev.get_xmotion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        case XlibWrapper.ButtonRelease: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            XButtonEvent xbutton = ev.get_xbutton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
             * On some X servers it could happen that ButtonRelease coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
             * differ from the latest MotionNotify coordinates, so we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
             * process it as a mouse motion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            XMotionEvent xmotion = new XMotionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                xmotion.set_type(XlibWrapper.MotionNotify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                xmotion.set_serial(xbutton.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                xmotion.set_send_event(xbutton.get_send_event());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                xmotion.set_display(xbutton.get_display());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                xmotion.set_window(xbutton.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                xmotion.set_root(xbutton.get_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                xmotion.set_subwindow(xbutton.get_subwindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                xmotion.set_time(xbutton.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                xmotion.set_x(xbutton.get_x());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                xmotion.set_y(xbutton.get_y());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                xmotion.set_x_root(xbutton.get_x_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                xmotion.set_y_root(xbutton.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                xmotion.set_state(xbutton.get_state());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                // we do not use this field, so it's unset for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                // xmotion.set_is_hint(???);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                xmotion.set_same_screen(xbutton.get_same_screen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                //It's safe to use key event as motion event since we use only their common fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                processMouseMove(xmotion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                xmotion.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            if (xbutton.get_button() == XlibWrapper.Button1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    || xbutton.get_button() == XlibWrapper.Button2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                // drag is initiated with Button1 or Button2 pressed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                // ended on release of either of these buttons (as the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                // behavior was with our old Motif DnD-based implementation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                removeDnDGrab(xbutton.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                dragInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                if (dragProtocol != null && targetAction != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                     * ACTION_NONE indicates that either the drop target rejects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                     * drop or it haven't responded yet. The latter could happen in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                     * case of fast drag, slow target-server connection or slow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                     * drag notifications processing on the target side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    processDrop(xbutton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    cleanup(xbutton.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    static boolean processEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                return theInstance.doProcessEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            } catch (XException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /* XDragSourceProtocolListener implementation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public void handleDragReply(int action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        // NOTE: we have to use the current pointer location, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        // the target didn't specify the coordinates for the reply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        handleDragReply(action, xRoot, yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    public void handleDragReply(int action, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        // NOTE: we have to use the current modifiers state, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        // the target didn't specify the modifiers state for the reply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        handleDragReply(action, xRoot, yRoot, XWindow.getModifiers(eventState,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public void handleDragReply(int action, int x, int y, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (action == DnDConstants.ACTION_NONE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            targetAction != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            dragExit(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        } else if (action != DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            int type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (targetAction == DnDConstants.ACTION_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                type = SunDragSourceContextPeer.DISPATCH_ENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                type = SunDragSourceContextPeer.DISPATCH_MOTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            // Note that we use the modifiers state a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            postDragSourceDragEvent(action, modifiers, x, y, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        targetAction = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public void handleDragFinished() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        /* Assume that the drop was successful. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        handleDragFinished(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public void handleDragFinished(boolean success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        /* Assume that the performed drop action is the latest drop action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
           accepted by the drop target. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        handleDragFinished(true, targetAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public void handleDragFinished(boolean success, int action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        // NOTE: we have to use the current pointer location, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        // the target didn't specify the coordinates for the reply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        handleDragFinished(success, action, xRoot, yRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    public void handleDragFinished(boolean success, int action, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        dragDropFinished(success, action, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        dndInProgress = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        cleanup(XlibWrapper.CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
}