0N/A/*
2362N/A * Copyright (c) 2003, 2008, 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
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/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,
2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.util.Iterator;
0N/A
0N/A/**
0N/A * This class is a registry for the supported drag and drop protocols.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Afinal class XDropTargetEventProcessor {
0N/A private static final XDropTargetEventProcessor theInstance =
0N/A new XDropTargetEventProcessor();
0N/A private static boolean active = false;
0N/A
0N/A // The current drop protocol.
0N/A private XDropTargetProtocol protocol = null;
0N/A
0N/A private XDropTargetEventProcessor() {}
0N/A
0N/A private boolean doProcessEvent(XEvent ev) {
0N/A if (ev.get_type() == (int)XConstants.DestroyNotify &&
0N/A protocol != null &&
0N/A ev.get_xany().get_window() == protocol.getSourceWindow()) {
0N/A protocol.cleanup();
0N/A protocol = null;
0N/A return false;
0N/A }
0N/A
0N/A if (ev.get_type() == (int)XConstants.PropertyNotify) {
0N/A XPropertyEvent xproperty = ev.get_xproperty();
0N/A if (xproperty.get_atom() ==
0N/A MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom()) {
0N/A
0N/A XDropTargetRegistry.getRegistry().updateEmbedderDropSite(xproperty.get_window());
0N/A }
0N/A }
0N/A
0N/A if (ev.get_type() != (int)XConstants.ClientMessage) {
0N/A return false;
0N/A }
0N/A
0N/A boolean processed = false;
0N/A XClientMessageEvent xclient = ev.get_xclient();
0N/A
0N/A XDropTargetProtocol curProtocol = protocol;
0N/A
0N/A if (protocol != null) {
0N/A if (protocol.getMessageType(xclient) !=
0N/A XDropTargetProtocol.UNKNOWN_MESSAGE) {
0N/A processed = protocol.processClientMessage(xclient);
0N/A } else {
0N/A protocol = null;
0N/A }
0N/A }
0N/A
0N/A if (protocol == null) {
0N/A Iterator dropTargetProtocols =
0N/A XDragAndDropProtocols.getDropTargetProtocols();
0N/A
0N/A while (dropTargetProtocols.hasNext()) {
0N/A XDropTargetProtocol dropTargetProtocol =
0N/A (XDropTargetProtocol)dropTargetProtocols.next();
0N/A // Don't try to process it again with the current protocol.
0N/A if (dropTargetProtocol == curProtocol) {
0N/A continue;
0N/A }
0N/A
0N/A if (dropTargetProtocol.getMessageType(xclient) ==
0N/A XDropTargetProtocol.UNKNOWN_MESSAGE) {
0N/A continue;
0N/A }
0N/A
0N/A protocol = dropTargetProtocol;
0N/A processed = protocol.processClientMessage(xclient);
0N/A break;
0N/A }
0N/A }
0N/A
0N/A return processed;
0N/A }
0N/A
0N/A static void reset() {
0N/A theInstance.protocol = null;
0N/A }
0N/A
0N/A static void activate() {
0N/A active = true;
0N/A }
0N/A
0N/A // Fix for 4915454 - do not call doProcessEvent() until the first drop
0N/A // target is registered to avoid premature loading of DnD protocol
0N/A // classes.
0N/A static boolean processEvent(XEvent ev) {
0N/A return active ? theInstance.doProcessEvent(ev) : false;
0N/A }
0N/A}
0N/A