src/solaris/classes/sun/awt/X11/MotifDnDDropTargetProtocol.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 145                 {
 146                     int tproxy = (int)newProxy;
 147                     if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
 148                         tproxy = MotifDnDConstants.Swapper.swap(tproxy);
 149                     }
 150                     unsafe.putInt(data + 4, tproxy);
 151                 }
 152             } else {
 153                 data = unsafe.allocateMemory(dataSize);
 154 
 155                 unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
 156                 unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
 157                 unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
 158                 unsafe.putByte(data + 3, (byte)0); /* pad */
 159                 unsafe.putInt(data + 4, (int)newProxy); /* proxy window */
 160                 unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
 161                 unsafe.putShort(data + 10, (short)0); /* pad */
 162                 unsafe.putInt(data + 12, dataSize);
 163             }
 164 
 165             XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 166             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
 167                                         MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 168                                         MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 169                                         8, XConstants.PropModeReplace,
 170                                         data, dataSize);
 171             XToolkit.RESTORE_XERROR_HANDLER();
 172 
 173             if (XToolkit.saved_error != null &&
 174                 XToolkit.saved_error.get_error_code() != XConstants.Success) {
 175                 throw new XException("Cannot write Motif receiver info property");
 176             }
 177         } finally {
 178             if (!overriden) {
 179                 unsafe.freeMemory(data);
 180                 data = 0;
 181             }
 182             wpg.dispose();
 183         }
 184 
 185         putEmbedderRegistryEntry(embedder, overriden, version, proxy);
 186     }
 187 
 188     public void unregisterEmbedderDropSite(long embedder) {
 189         assert XToolkit.isAWTLockHeldByCurrentThread();
 190 
 191         EmbedderRegistryEntry entry = getEmbedderRegistryEntry(embedder);
 192 
 193         if (entry == null) {
 194             return;


 219                  *     CARD16   pad2 B16;
 220                  *     CARD32   heap_offset B32;
 221                  * } xmDragReceiverInfoStruct;
 222                  */
 223                 if (status == (int)XConstants.Success && wpg.getData() != 0 &&
 224                     wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
 225                     wpg.getNumberOfItems() >=
 226                     MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
 227 
 228                     int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
 229                     long data = wpg.getData();
 230                     byte byteOrderByte = unsafe.getByte(data);
 231 
 232                     int tproxy = (int)entry.getProxy();
 233                     if (MotifDnDConstants.getByteOrderByte() != byteOrderByte) {
 234                         tproxy = MotifDnDConstants.Swapper.swap(tproxy);
 235                     }
 236 
 237                     unsafe.putInt(data + 4, tproxy);
 238 
 239                     XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 240                     XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
 241                                                 MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 242                                                 MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 243                                                 8, XConstants.PropModeReplace,
 244                                                 data, dataSize);
 245                     XToolkit.RESTORE_XERROR_HANDLER();
 246 
 247                     if (XToolkit.saved_error != null &&
 248                         XToolkit.saved_error.get_error_code() != XConstants.Success) {
 249                         throw new XException("Cannot write Motif receiver info property");
 250                     }
 251                 }
 252             } finally {
 253                 wpg.dispose();
 254             }
 255         } else {
 256             MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.DeleteProperty(embedder);
 257         }
 258     }
 259 
 260     /*
 261      * Gets and stores in the registry the embedder's Motif DnD drop site info
 262      * from the embedded.
 263      */
 264     public void registerEmbeddedDropSite(long embedded) {
 265         assert XToolkit.isAWTLockHeldByCurrentThread();
 266 
 267         boolean overriden = false;
 268         int version = 0;


 395                     }
 396 
 397                     int index =
 398                         MotifDnDConstants.Swapper.getShort(data + 2, propertyByteOrder);
 399 
 400                     formats = MotifDnDConstants.getTargetListForIndex(index);
 401                 } else {
 402                     formats = new long[0];
 403                 }
 404             } finally {
 405                 wpg.dispose();
 406             }
 407         }
 408 
 409         /*
 410          * Select for StructureNotifyMask to receive DestroyNotify in case of source
 411          * crash.
 412          */
 413         XWindowAttributes wattr = new XWindowAttributes();
 414         try {
 415             XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 416             int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
 417                                                           source_win, wattr.pData);
 418 
 419             XToolkit.RESTORE_XERROR_HANDLER();
 420 
 421             if (status == 0 ||
 422                 (XToolkit.saved_error != null &&
 423                  XToolkit.saved_error.get_error_code() != XConstants.Success)) {
 424                 throw new XException("XGetWindowAttributes failed");
 425             }
 426 
 427             source_win_mask = wattr.get_your_event_mask();
 428         } finally {
 429             wattr.dispose();
 430         }
 431 
 432         XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 433         XlibWrapper.XSelectInput(XToolkit.getDisplay(), source_win,
 434                                  source_win_mask |
 435                                  XConstants.StructureNotifyMask);
 436 
 437         XToolkit.RESTORE_XERROR_HANDLER();
 438 
 439         if (XToolkit.saved_error != null &&
 440             XToolkit.saved_error.get_error_code() != XConstants.Success) {
 441             throw new XException("XSelectInput failed");
 442         }
 443 
 444         sourceWindow = source_win;
 445         sourceWindowMask = source_win_mask;
 446         sourceProtocolVersion = protocol_version;
 447         /*
 448          * TOP_LEVEL_ENTER doesn't communicate the list of supported actions
 449          * They are provided in DRAG_MOTION.
 450          */
 451         sourceActions = DnDConstants.ACTION_NONE;
 452         sourceFormats = formats;
 453         sourceAtom = property_atom;
 454 
 455         return true;
 456     }
 457 
 458     private boolean processDragMotion(XClientMessageEvent xclient) {
 459         long data = xclient.get_data();
 460         byte eventByteOrder = unsafe.getByte(data + 1);


1007     public final long getSourceWindow() {
1008         return sourceWindow;
1009     }
1010 
1011     /**
1012      * Reset the state of the object.
1013      */
1014     public void cleanup() {
1015         // Clear the reference to this protocol.
1016         XDropTargetEventProcessor.reset();
1017 
1018         if (targetXWindow != null) {
1019             notifyProtocolListener(targetXWindow, 0, 0,
1020                                    DnDConstants.ACTION_NONE, sourceActions,
1021                                    null, MouseEvent.MOUSE_EXITED);
1022         }
1023 
1024         if (sourceWindow != 0) {
1025             XToolkit.awtLock();
1026             try {
1027                 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
1028                 XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
1029                                          sourceWindowMask);
1030                 XToolkit.RESTORE_XERROR_HANDLER();
1031             } finally {
1032                 XToolkit.awtUnlock();
1033             }
1034         }
1035 
1036         sourceWindow = 0;
1037         sourceWindowMask = 0;
1038         sourceProtocolVersion = 0;
1039         sourceActions = DnDConstants.ACTION_NONE;
1040         sourceFormats = null;
1041         sourceAtom = 0;
1042         userAction = DnDConstants.ACTION_NONE;
1043         sourceX = 0;
1044         sourceY = 0;
1045         targetXWindow = null;
1046         topLevelLeavePostponed = false;
1047     }
1048 
1049     public boolean isDragOverComponent() {
1050         return targetXWindow != null;


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 145                 {
 146                     int tproxy = (int)newProxy;
 147                     if (byteOrderByte != MotifDnDConstants.getByteOrderByte()) {
 148                         tproxy = MotifDnDConstants.Swapper.swap(tproxy);
 149                     }
 150                     unsafe.putInt(data + 4, tproxy);
 151                 }
 152             } else {
 153                 data = unsafe.allocateMemory(dataSize);
 154 
 155                 unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
 156                 unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
 157                 unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
 158                 unsafe.putByte(data + 3, (byte)0); /* pad */
 159                 unsafe.putInt(data + 4, (int)newProxy); /* proxy window */
 160                 unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
 161                 unsafe.putShort(data + 10, (short)0); /* pad */
 162                 unsafe.putInt(data + 12, dataSize);
 163             }
 164 
 165             XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 166             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
 167                                         MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 168                                         MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 169                                         8, XConstants.PropModeReplace,
 170                                         data, dataSize);
 171             XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 172 
 173             if ((XErrorHandlerUtil.saved_error != null) &&
 174                 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 175                 throw new XException("Cannot write Motif receiver info property");
 176             }
 177         } finally {
 178             if (!overriden) {
 179                 unsafe.freeMemory(data);
 180                 data = 0;
 181             }
 182             wpg.dispose();
 183         }
 184 
 185         putEmbedderRegistryEntry(embedder, overriden, version, proxy);
 186     }
 187 
 188     public void unregisterEmbedderDropSite(long embedder) {
 189         assert XToolkit.isAWTLockHeldByCurrentThread();
 190 
 191         EmbedderRegistryEntry entry = getEmbedderRegistryEntry(embedder);
 192 
 193         if (entry == null) {
 194             return;


 219                  *     CARD16   pad2 B16;
 220                  *     CARD32   heap_offset B32;
 221                  * } xmDragReceiverInfoStruct;
 222                  */
 223                 if (status == (int)XConstants.Success && wpg.getData() != 0 &&
 224                     wpg.getActualType() != 0 && wpg.getActualFormat() == 8 &&
 225                     wpg.getNumberOfItems() >=
 226                     MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE) {
 227 
 228                     int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
 229                     long data = wpg.getData();
 230                     byte byteOrderByte = unsafe.getByte(data);
 231 
 232                     int tproxy = (int)entry.getProxy();
 233                     if (MotifDnDConstants.getByteOrderByte() != byteOrderByte) {
 234                         tproxy = MotifDnDConstants.Swapper.swap(tproxy);
 235                     }
 236 
 237                     unsafe.putInt(data + 4, tproxy);
 238 
 239                     XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 240                     XlibWrapper.XChangeProperty(XToolkit.getDisplay(), embedder,
 241                                                 MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 242                                                 MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 243                                                 8, XConstants.PropModeReplace,
 244                                                 data, dataSize);
 245                     XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 246 
 247                     if ((XErrorHandlerUtil.saved_error != null) &&
 248                         (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 249                         throw new XException("Cannot write Motif receiver info property");
 250                     }
 251                 }
 252             } finally {
 253                 wpg.dispose();
 254             }
 255         } else {
 256             MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.DeleteProperty(embedder);
 257         }
 258     }
 259 
 260     /*
 261      * Gets and stores in the registry the embedder's Motif DnD drop site info
 262      * from the embedded.
 263      */
 264     public void registerEmbeddedDropSite(long embedded) {
 265         assert XToolkit.isAWTLockHeldByCurrentThread();
 266 
 267         boolean overriden = false;
 268         int version = 0;


 395                     }
 396 
 397                     int index =
 398                         MotifDnDConstants.Swapper.getShort(data + 2, propertyByteOrder);
 399 
 400                     formats = MotifDnDConstants.getTargetListForIndex(index);
 401                 } else {
 402                     formats = new long[0];
 403                 }
 404             } finally {
 405                 wpg.dispose();
 406             }
 407         }
 408 
 409         /*
 410          * Select for StructureNotifyMask to receive DestroyNotify in case of source
 411          * crash.
 412          */
 413         XWindowAttributes wattr = new XWindowAttributes();
 414         try {
 415             XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 416             int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
 417                                                           source_win, wattr.pData);
 418 
 419             XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 420 
 421             if ((status == 0) ||
 422                 ((XErrorHandlerUtil.saved_error != null) &&
 423                 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
 424                 throw new XException("XGetWindowAttributes failed");
 425             }
 426 
 427             source_win_mask = wattr.get_your_event_mask();
 428         } finally {
 429             wattr.dispose();
 430         }
 431 
 432         XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
 433         XlibWrapper.XSelectInput(XToolkit.getDisplay(), source_win,
 434                                  source_win_mask |
 435                                  XConstants.StructureNotifyMask);
 436 
 437         XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 438 
 439         if ((XErrorHandlerUtil.saved_error != null) &&
 440             (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 441             throw new XException("XSelectInput failed");
 442         }
 443 
 444         sourceWindow = source_win;
 445         sourceWindowMask = source_win_mask;
 446         sourceProtocolVersion = protocol_version;
 447         /*
 448          * TOP_LEVEL_ENTER doesn't communicate the list of supported actions
 449          * They are provided in DRAG_MOTION.
 450          */
 451         sourceActions = DnDConstants.ACTION_NONE;
 452         sourceFormats = formats;
 453         sourceAtom = property_atom;
 454 
 455         return true;
 456     }
 457 
 458     private boolean processDragMotion(XClientMessageEvent xclient) {
 459         long data = xclient.get_data();
 460         byte eventByteOrder = unsafe.getByte(data + 1);


1007     public final long getSourceWindow() {
1008         return sourceWindow;
1009     }
1010 
1011     /**
1012      * Reset the state of the object.
1013      */
1014     public void cleanup() {
1015         // Clear the reference to this protocol.
1016         XDropTargetEventProcessor.reset();
1017 
1018         if (targetXWindow != null) {
1019             notifyProtocolListener(targetXWindow, 0, 0,
1020                                    DnDConstants.ACTION_NONE, sourceActions,
1021                                    null, MouseEvent.MOUSE_EXITED);
1022         }
1023 
1024         if (sourceWindow != 0) {
1025             XToolkit.awtLock();
1026             try {
1027                 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
1028                 XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
1029                                          sourceWindowMask);
1030                 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
1031             } finally {
1032                 XToolkit.awtUnlock();
1033             }
1034         }
1035 
1036         sourceWindow = 0;
1037         sourceWindowMask = 0;
1038         sourceProtocolVersion = 0;
1039         sourceActions = DnDConstants.ACTION_NONE;
1040         sourceFormats = null;
1041         sourceAtom = 0;
1042         userAction = DnDConstants.ACTION_NONE;
1043         sourceX = 0;
1044         sourceY = 0;
1045         targetXWindow = null;
1046         topLevelLeavePostponed = false;
1047     }
1048 
1049     public boolean isDragOverComponent() {
1050         return targetXWindow != null;