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