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