0N/A/*
6447N/A * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.awt.datatransfer.Transferable;
0N/A
0N/Aimport java.awt.dnd.DnDConstants;
0N/Aimport java.awt.dnd.InvalidDnDOperationException;
0N/A
0N/Aimport java.util.Map;
0N/A
0N/A/**
0N/A * An abstract class for drag protocols on X11 systems.
0N/A * Contains protocol-independent drag source code.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Aabstract class XDragSourceProtocol {
0N/A private final XDragSourceProtocolListener listener;
0N/A
0N/A private boolean initialized = false;
0N/A
0N/A private long targetWindow = 0;
0N/A private long targetProxyWindow = 0;
0N/A private int targetProtocolVersion = 0;
0N/A private long targetWindowMask = 0;
0N/A
0N/A // Always use the XAWT root window as the drag source window.
0N/A static long getDragSourceWindow() {
0N/A return XWindow.getXAWTRootWindow().getWindow();
0N/A }
0N/A
0N/A protected XDragSourceProtocol(XDragSourceProtocolListener listener) {
0N/A if (listener == null) {
0N/A throw new NullPointerException("Null XDragSourceProtocolListener");
0N/A }
0N/A this.listener = listener;
0N/A }
0N/A
0N/A protected final XDragSourceProtocolListener getProtocolListener() {
0N/A return listener;
0N/A }
0N/A
0N/A /**
0N/A * Returns the protocol name. The protocol name cannot be null.
0N/A */
0N/A public abstract String getProtocolName();
0N/A
0N/A /**
0N/A * Initalizes a drag operation with the specified supported drop actions,
0N/A * contents and data formats.
0N/A *
0N/A * @param actions a bitwise mask of <code>DnDConstants</code> that represent
0N/A * the supported drop actions.
0N/A * @param contents the contents for the drag operation.
0N/A * @param formats an array of Atoms that represent the supported data formats.
0N/A * @param formats an array of Atoms that represent the supported data formats.
0N/A * @throws InvalidDnDOperationException if a drag operation is already
0N/A * initialized.
0N/A * @throws IllegalArgumentException if some argument has invalid value.
0N/A * @throws XException if some X call failed.
0N/A */
0N/A public final void initializeDrag(int actions, Transferable contents,
0N/A Map formatMap, long[] formats)
0N/A throws InvalidDnDOperationException,
0N/A IllegalArgumentException, XException {
0N/A XToolkit.awtLock();
0N/A try {
0N/A try {
0N/A if (initialized) {
0N/A throw new InvalidDnDOperationException("Already initialized");
0N/A }
0N/A
0N/A initializeDragImpl(actions, contents, formatMap, formats);
0N/A
0N/A initialized = true;
0N/A } finally {
0N/A if (!initialized) {
0N/A cleanup();
0N/A }
0N/A }
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /* The caller must hold AWT_LOCK. */
0N/A protected abstract void initializeDragImpl(int actions,
0N/A Transferable contents,
0N/A Map formatMap, long[] formats)
0N/A throws InvalidDnDOperationException, IllegalArgumentException, XException;
0N/A
0N/A /**
0N/A * Terminates the current drag operation (if any) and resets the internal
0N/A * state of this object.
0N/A *
0N/A * @throws XException if some X call failed.
0N/A */
0N/A public void cleanup() {
0N/A initialized = false;
0N/A cleanupTargetInfo();
0N/A }
0N/A
0N/A /**
0N/A * Clears the information on the current drop target.
0N/A *
0N/A * @throws XException if some X call failed.
0N/A */
0N/A public void cleanupTargetInfo() {
0N/A targetWindow = 0;
0N/A targetProxyWindow = 0;
0N/A targetProtocolVersion = 0;
0N/A }
0N/A
0N/A /**
0N/A * Processes the specified client message event.
0N/A *
0N/A * @returns true if the event was successfully processed.
0N/A */
0N/A public abstract boolean processClientMessage(XClientMessageEvent xclient)
0N/A throws XException;
0N/A
0N/A /* The caller must hold AWT_LOCK. */
0N/A public final boolean attachTargetWindow(long window, long time) {
0N/A assert XToolkit.isAWTLockHeldByCurrentThread();
0N/A
0N/A TargetWindowInfo info = getTargetWindowInfo(window);
0N/A if (info == null) {
0N/A return false;
0N/A } else {
0N/A targetWindow = window;
0N/A targetProxyWindow = info.getProxyWindow();
0N/A targetProtocolVersion = info.getProtocolVersion();
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A /* The caller must hold AWT_LOCK. */
0N/A public abstract TargetWindowInfo getTargetWindowInfo(long window);
0N/A
0N/A /* The caller must hold AWT_LOCK. */
0N/A public abstract void sendEnterMessage(long[] formats, int sourceAction,
0N/A int sourceActions, long time);
0N/A /* The caller must hold AWT_LOCK. */
0N/A public abstract void sendMoveMessage(int xRoot, int yRoot,
0N/A int sourceAction, int sourceActions,
0N/A long time);
0N/A /* The caller must hold AWT_LOCK. */
0N/A public abstract void sendLeaveMessage(long time);
0N/A
0N/A /* The caller must hold AWT_LOCK. */
0N/A protected abstract void sendDropMessage(int xRoot, int yRoot,
0N/A int sourceAction, int sourceActions,
0N/A long time);
0N/A
0N/A public final void initiateDrop(int xRoot, int yRoot,
0N/A int sourceAction, int sourceActions,
0N/A long time) {
0N/A XWindowAttributes wattr = new XWindowAttributes();
0N/A try {
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
0N/A targetWindow, wattr.pData);
0N/A
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((status == 0) ||
6447N/A ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
0N/A throw new XException("XGetWindowAttributes failed");
0N/A }
0N/A
0N/A targetWindowMask = wattr.get_your_event_mask();
0N/A } finally {
0N/A wattr.dispose();
0N/A }
0N/A
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A XlibWrapper.XSelectInput(XToolkit.getDisplay(), targetWindow,
0N/A targetWindowMask |
216N/A XConstants.StructureNotifyMask);
0N/A
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A
6447N/A if ((XErrorHandlerUtil.saved_error != null) &&
6447N/A (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
0N/A throw new XException("XSelectInput failed");
0N/A }
0N/A
0N/A sendDropMessage(xRoot, yRoot, sourceAction, sourceActions, time);
0N/A }
0N/A
0N/A protected final void finalizeDrop() {
6447N/A XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
0N/A XlibWrapper.XSelectInput(XToolkit.getDisplay(), targetWindow,
0N/A targetWindowMask);
6447N/A XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
0N/A }
0N/A
0N/A public abstract boolean processProxyModeEvent(XClientMessageEvent xclient,
0N/A long sourceWindow);
0N/A
0N/A protected final long getTargetWindow() {
0N/A return targetWindow;
0N/A }
0N/A
0N/A protected final long getTargetProxyWindow() {
0N/A if (targetProxyWindow != 0) {
0N/A return targetProxyWindow;
0N/A } else {
0N/A return targetWindow;
0N/A }
0N/A }
0N/A
0N/A protected final int getTargetProtocolVersion() {
0N/A return targetProtocolVersion;
0N/A }
0N/A
0N/A public static class TargetWindowInfo {
0N/A private final long proxyWindow;
0N/A private final int protocolVersion;
0N/A public TargetWindowInfo(long proxy, int version) {
0N/A proxyWindow = proxy;
0N/A protocolVersion = version;
0N/A }
0N/A public long getProxyWindow() {
0N/A return proxyWindow;
0N/A }
0N/A public int getProtocolVersion() {
0N/A return protocolVersion;
0N/A }
0N/A }
0N/A}