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

Print this page


   1 /*
   2  * Copyright (c) 2003, 2008, 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


 173 
 174                 motifWindow = XlibWrapper.XCreateWindow(newDisplay, defaultRootWindow,
 175                                                         -10, -10, 1, 1, 0, 0,
 176                                                         XConstants.InputOnly,
 177                                                         XConstants.CopyFromParent,
 178                                                         (XConstants.CWOverrideRedirect |
 179                                                          XConstants.CWEventMask),
 180                                                         xwa.pData);
 181 
 182                 if (motifWindow == 0) {
 183                     throw new XException("XCreateWindow returns NULL");
 184                 }
 185 
 186                 XlibWrapper.XMapWindow(newDisplay, motifWindow);
 187 
 188                 long data = Native.allocateLongArray(1);
 189 
 190                 try {
 191                     Native.putLong(data, motifWindow);
 192 
 193                     XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 194                     XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 195                                                 defaultRootWindow,
 196                                                 XA_MOTIF_DRAG_WINDOW.getAtom(),
 197                                                 XAtom.XA_WINDOW, 32,
 198                                                 XConstants.PropModeReplace,
 199                                                 data, 1);
 200 
 201                     XToolkit.RESTORE_XERROR_HANDLER();
 202 
 203                     if (XToolkit.saved_error != null &&
 204                         XToolkit.saved_error.get_error_code() != XConstants.Success) {
 205                         throw new XException("Cannot write motif drag window handle.");
 206                     }
 207 
 208                     return motifWindow;
 209                 } finally {
 210                     unsafe.freeMemory(data);
 211                 }
 212             } finally {
 213                 xwa.dispose();
 214             }
 215         } finally {
 216             XlibWrapper.XUngrabServer(newDisplay);
 217             XlibWrapper.XCloseDisplay(newDisplay);
 218         }
 219     }
 220 
 221     private static long getMotifWindow() throws XException {
 222         /*
 223          * Note: it is unsafe to cache the motif drag window handle, as another
 224          * client can change the _MOTIF_DRAG_WINDOW property on the root, the handle


 377 
 378                 for (int j = 0; j < table[i].length; j++) {
 379                     int target = (int)table[i][j];
 380                     // NOTE: cannot use Unsafe.putInt(), since it crashes on
 381                     // Solaris/Sparc if the address is not a multiple of 4.
 382                     if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
 383                         for (int idx = 0; idx < 4; idx++) {
 384                             byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
 385                             unsafe.putByte(bufptr + idx, b);
 386                         }
 387                     } else {
 388                         for (int idx = 0; idx < 4; idx++) {
 389                             byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
 390                             unsafe.putByte(bufptr + (3-idx), b);
 391                         }
 392                     }
 393                     bufptr += 4;
 394                 }
 395             }
 396 
 397             XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 398             XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 399                                         motifWindow,
 400                                         XA_MOTIF_DRAG_TARGETS.getAtom(),
 401                                         XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
 402                                         XConstants.PropModeReplace,
 403                                         data, tableSize);
 404 
 405             XToolkit.RESTORE_XERROR_HANDLER();
 406 
 407             if (XToolkit.saved_error != null &&
 408                 XToolkit.saved_error.get_error_code() != XConstants.Success) {
 409 
 410                 // Create a new motif window and retry.
 411                 motifWindow = createMotifWindow();
 412 
 413                 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 414                 XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 415                                             motifWindow,
 416                                             XA_MOTIF_DRAG_TARGETS.getAtom(),
 417                                             XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
 418                                             XConstants.PropModeReplace,
 419                                             data, tableSize);
 420 
 421                 XToolkit.RESTORE_XERROR_HANDLER();
 422 
 423                 if (XToolkit.saved_error != null &&
 424                     XToolkit.saved_error.get_error_code() != XConstants.Success) {
 425                     throw new XException("Cannot write motif drag targets property.");
 426                 }
 427             }
 428         } finally {
 429             unsafe.freeMemory(data);
 430         }
 431     }
 432 
 433     static int getIndexForTargetList(long[] formats) throws XException {
 434         assert XToolkit.isAWTLockHeldByCurrentThread();
 435 
 436         if (formats.length > 0) {
 437             // Make a defensive copy.
 438             formats = (long[])formats.clone();
 439 
 440             Arrays.sort(formats);
 441         }
 442 
 443         // NOTE: getMotifWindow() should never be called if the server is
 444         // grabbed. This will lock up the application as it grabs the server


 517         // 'l' - for little endian, 'B' - for big endian.
 518         return ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ?
 519             (byte)0x6C : (byte)0x42;
 520     }
 521 
 522     static void writeDragInitiatorInfoStruct(long window, int index) throws XException {
 523         assert XToolkit.isAWTLockHeldByCurrentThread();
 524 
 525         long structData = unsafe.allocateMemory(MOTIF_INITIATOR_INFO_SIZE);
 526 
 527         try {
 528             // BYTE byte_order
 529             unsafe.putByte(structData, getByteOrderByte());
 530             // BYTE protocol_version
 531             unsafe.putByte(structData + 1, MOTIF_DND_PROTOCOL_VERSION);
 532             // CARD16 protocol_version
 533             unsafe.putShort(structData + 2, (short)index);
 534             // CARD32 icc_handle
 535             unsafe.putInt(structData + 4, (int)XA_MOTIF_ATOM_0.getAtom());
 536 
 537             XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 538             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
 539                                         XA_MOTIF_ATOM_0.getAtom(),
 540                                         XA_MOTIF_DRAG_INITIATOR_INFO.getAtom(),
 541                                         8, XConstants.PropModeReplace,
 542                                         structData, MOTIF_INITIATOR_INFO_SIZE);
 543             XToolkit.RESTORE_XERROR_HANDLER();
 544 
 545             if (XToolkit.saved_error != null &&
 546                 XToolkit.saved_error.get_error_code() != XConstants.Success) {
 547                 throw new XException("Cannot write drag initiator info");
 548             }
 549         } finally {
 550             unsafe.freeMemory(structData);
 551         }
 552     }
 553 
 554     static void writeDragReceiverInfoStruct(long window) throws XException {
 555         assert XToolkit.isAWTLockHeldByCurrentThread();
 556 
 557         int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
 558         long data = unsafe.allocateMemory(dataSize);
 559 
 560         try {
 561             unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
 562             unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
 563             unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
 564             unsafe.putByte(data + 3, (byte)0); /* pad */
 565             unsafe.putInt(data + 4, (int)window); /* proxy window */
 566             unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
 567             unsafe.putShort(data + 10, (short)0); /* pad */
 568             unsafe.putInt(data + 12, dataSize);
 569 
 570             XToolkit.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 571             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
 572                                         XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 573                                         XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 574                                         8, XConstants.PropModeReplace,
 575                                         data, dataSize);
 576             XToolkit.RESTORE_XERROR_HANDLER();
 577 
 578             if (XToolkit.saved_error != null &&
 579                 XToolkit.saved_error.get_error_code() != XConstants.Success) {
 580                 throw new XException("Cannot write Motif receiver info property");
 581             }
 582         } finally {
 583             unsafe.freeMemory(data);
 584         }
 585     }
 586 
 587     public static int getMotifActionsForJavaActions(int javaActions) {
 588         int motifActions = MOTIF_DND_NOOP;
 589 
 590         if ((javaActions & DnDConstants.ACTION_MOVE) != 0) {
 591             motifActions |= MOTIF_DND_MOVE;
 592         }
 593         if ((javaActions & DnDConstants.ACTION_COPY) != 0) {
 594             motifActions |= MOTIF_DND_COPY;
 595         }
 596         if ((javaActions & DnDConstants.ACTION_LINK) != 0) {
 597             motifActions |= MOTIF_DND_LINK;
 598         }
 599 
   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


 173 
 174                 motifWindow = XlibWrapper.XCreateWindow(newDisplay, defaultRootWindow,
 175                                                         -10, -10, 1, 1, 0, 0,
 176                                                         XConstants.InputOnly,
 177                                                         XConstants.CopyFromParent,
 178                                                         (XConstants.CWOverrideRedirect |
 179                                                          XConstants.CWEventMask),
 180                                                         xwa.pData);
 181 
 182                 if (motifWindow == 0) {
 183                     throw new XException("XCreateWindow returns NULL");
 184                 }
 185 
 186                 XlibWrapper.XMapWindow(newDisplay, motifWindow);
 187 
 188                 long data = Native.allocateLongArray(1);
 189 
 190                 try {
 191                     Native.putLong(data, motifWindow);
 192 
 193                     XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 194                     XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 195                                                 defaultRootWindow,
 196                                                 XA_MOTIF_DRAG_WINDOW.getAtom(),
 197                                                 XAtom.XA_WINDOW, 32,
 198                                                 XConstants.PropModeReplace,
 199                                                 data, 1);
 200 
 201                     XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 202 
 203                     if ((XErrorHandlerUtil.saved_error != null) &&
 204                         (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 205                         throw new XException("Cannot write motif drag window handle.");
 206                     }
 207 
 208                     return motifWindow;
 209                 } finally {
 210                     unsafe.freeMemory(data);
 211                 }
 212             } finally {
 213                 xwa.dispose();
 214             }
 215         } finally {
 216             XlibWrapper.XUngrabServer(newDisplay);
 217             XlibWrapper.XCloseDisplay(newDisplay);
 218         }
 219     }
 220 
 221     private static long getMotifWindow() throws XException {
 222         /*
 223          * Note: it is unsafe to cache the motif drag window handle, as another
 224          * client can change the _MOTIF_DRAG_WINDOW property on the root, the handle


 377 
 378                 for (int j = 0; j < table[i].length; j++) {
 379                     int target = (int)table[i][j];
 380                     // NOTE: cannot use Unsafe.putInt(), since it crashes on
 381                     // Solaris/Sparc if the address is not a multiple of 4.
 382                     if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
 383                         for (int idx = 0; idx < 4; idx++) {
 384                             byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
 385                             unsafe.putByte(bufptr + idx, b);
 386                         }
 387                     } else {
 388                         for (int idx = 0; idx < 4; idx++) {
 389                             byte b = (byte)((target & (0xFF << (8*idx))) >> (8*idx));
 390                             unsafe.putByte(bufptr + (3-idx), b);
 391                         }
 392                     }
 393                     bufptr += 4;
 394                 }
 395             }
 396 
 397             XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 398             XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 399                                         motifWindow,
 400                                         XA_MOTIF_DRAG_TARGETS.getAtom(),
 401                                         XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
 402                                         XConstants.PropModeReplace,
 403                                         data, tableSize);
 404 
 405             XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 406 
 407             if ((XErrorHandlerUtil.saved_error != null) &&
 408                 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 409 
 410                 // Create a new motif window and retry.
 411                 motifWindow = createMotifWindow();
 412 
 413                 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 414                 XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
 415                                             motifWindow,
 416                                             XA_MOTIF_DRAG_TARGETS.getAtom(),
 417                                             XA_MOTIF_DRAG_TARGETS.getAtom(), 8,
 418                                             XConstants.PropModeReplace,
 419                                             data, tableSize);
 420 
 421                 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 422 
 423                 if ((XErrorHandlerUtil.saved_error != null) &&
 424                     (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 425                     throw new XException("Cannot write motif drag targets property.");
 426                 }
 427             }
 428         } finally {
 429             unsafe.freeMemory(data);
 430         }
 431     }
 432 
 433     static int getIndexForTargetList(long[] formats) throws XException {
 434         assert XToolkit.isAWTLockHeldByCurrentThread();
 435 
 436         if (formats.length > 0) {
 437             // Make a defensive copy.
 438             formats = (long[])formats.clone();
 439 
 440             Arrays.sort(formats);
 441         }
 442 
 443         // NOTE: getMotifWindow() should never be called if the server is
 444         // grabbed. This will lock up the application as it grabs the server


 517         // 'l' - for little endian, 'B' - for big endian.
 518         return ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ?
 519             (byte)0x6C : (byte)0x42;
 520     }
 521 
 522     static void writeDragInitiatorInfoStruct(long window, int index) throws XException {
 523         assert XToolkit.isAWTLockHeldByCurrentThread();
 524 
 525         long structData = unsafe.allocateMemory(MOTIF_INITIATOR_INFO_SIZE);
 526 
 527         try {
 528             // BYTE byte_order
 529             unsafe.putByte(structData, getByteOrderByte());
 530             // BYTE protocol_version
 531             unsafe.putByte(structData + 1, MOTIF_DND_PROTOCOL_VERSION);
 532             // CARD16 protocol_version
 533             unsafe.putShort(structData + 2, (short)index);
 534             // CARD32 icc_handle
 535             unsafe.putInt(structData + 4, (int)XA_MOTIF_ATOM_0.getAtom());
 536 
 537             XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 538             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
 539                                         XA_MOTIF_ATOM_0.getAtom(),
 540                                         XA_MOTIF_DRAG_INITIATOR_INFO.getAtom(),
 541                                         8, XConstants.PropModeReplace,
 542                                         structData, MOTIF_INITIATOR_INFO_SIZE);
 543             XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 544 
 545             if ((XErrorHandlerUtil.saved_error != null) &&
 546                 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 547                 throw new XException("Cannot write drag initiator info");
 548             }
 549         } finally {
 550             unsafe.freeMemory(structData);
 551         }
 552     }
 553 
 554     static void writeDragReceiverInfoStruct(long window) throws XException {
 555         assert XToolkit.isAWTLockHeldByCurrentThread();
 556 
 557         int dataSize = MotifDnDConstants.MOTIF_RECEIVER_INFO_SIZE;
 558         long data = unsafe.allocateMemory(dataSize);
 559 
 560         try {
 561             unsafe.putByte(data, MotifDnDConstants.getByteOrderByte()); /* byte order */
 562             unsafe.putByte(data + 1, MotifDnDConstants.MOTIF_DND_PROTOCOL_VERSION); /* protocol version */
 563             unsafe.putByte(data + 2, (byte)MotifDnDConstants.MOTIF_DYNAMIC_STYLE); /* protocol style */
 564             unsafe.putByte(data + 3, (byte)0); /* pad */
 565             unsafe.putInt(data + 4, (int)window); /* proxy window */
 566             unsafe.putShort(data + 8, (short)0); /* num_drop_sites */
 567             unsafe.putShort(data + 10, (short)0); /* pad */
 568             unsafe.putInt(data + 12, dataSize);
 569 
 570             XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
 571             XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
 572                                         XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 573                                         XA_MOTIF_DRAG_RECEIVER_INFO.getAtom(),
 574                                         8, XConstants.PropModeReplace,
 575                                         data, dataSize);
 576             XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
 577 
 578             if ((XErrorHandlerUtil.saved_error != null) &&
 579                 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
 580                 throw new XException("Cannot write Motif receiver info property");
 581             }
 582         } finally {
 583             unsafe.freeMemory(data);
 584         }
 585     }
 586 
 587     public static int getMotifActionsForJavaActions(int javaActions) {
 588         int motifActions = MOTIF_DND_NOOP;
 589 
 590         if ((javaActions & DnDConstants.ACTION_MOVE) != 0) {
 591             motifActions |= MOTIF_DND_MOVE;
 592         }
 593         if ((javaActions & DnDConstants.ACTION_COPY) != 0) {
 594             motifActions |= MOTIF_DND_COPY;
 595         }
 596         if ((javaActions & DnDConstants.ACTION_LINK) != 0) {
 597             motifActions |= MOTIF_DND_LINK;
 598         }
 599