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