home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / lib / PEXlib / pl_escape.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  3.7 KB  |  161 lines

  1. /* $XConsortium: pl_escape.c,v 1.4 92/07/16 11:05:44 mor Exp $ */
  2.  
  3. /************************************************************************
  4. Copyright 1992 by the Massachusetts Institute of Technology
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, distribute, and sell this software and its
  9. documentation for any purpose is hereby granted without fee, provided that
  10. the above copyright notice appear in all copies and that both that
  11. copyright notice and this permission notice appear in supporting
  12. documentation, and that the name of M.I.T. not be used in advertising or
  13. publicity pertaining to distribution of the software without specific,
  14. written prior permission.  M.I.T. makes no representations about the
  15. suitability of this software for any purpose.  It is provided "as is"
  16. without express or implied warranty.
  17. *************************************************************************/
  18.  
  19. #include "PEXlib.h"
  20. #include "PEXlibint.h"
  21.  
  22.  
  23. void
  24. PEXEscape (display, escapeID, escapeDataSize, escapeData)
  25.  
  26. INPUT Display        *display;
  27. INPUT unsigned long      escapeID;
  28. INPUT int        escapeDataSize;
  29. INPUT char        *escapeData;
  30.  
  31. {
  32.     pexEscapeReq        *req;
  33.  
  34.  
  35.     /*
  36.      * Lock around the critical section, for multithreading.
  37.      */
  38.  
  39.     LockDisplay (display);
  40.  
  41.  
  42.     /*
  43.      * Put the request in the X request buffer.
  44.      */
  45.  
  46.     PEXGetReqExtra (Escape, escapeDataSize, req);
  47.     req->escapeID = escapeID;
  48.  
  49.     COPY_AREA ((char *) escapeData, ((char *) &req[1]), escapeDataSize);
  50.  
  51.  
  52.     /*
  53.      * Done, so unlock and check for synchronous-ness.
  54.      */
  55.  
  56.     UnlockDisplay (display);
  57.     PEXSyncHandle (display);
  58. }
  59.  
  60.  
  61. char *
  62. PEXEscapeWithReply (display, escapeID, escapeDataSize,
  63.     escapeData, escapeOutDataSize)
  64.  
  65. INPUT Display        *display;
  66. INPUT unsigned long      escapeID;
  67. INPUT int        escapeDataSize;
  68. INPUT char        *escapeData;
  69. OUTPUT unsigned long    *escapeOutDataSize;
  70.  
  71. {
  72.     pexEscapeWithReplyReq        *req;
  73.     pexEscapeWithReplyReply        rep;
  74.     char                *escRepData, *pescRepData;
  75.  
  76.  
  77.     /*
  78.      * Lock around the critical section, for multithreading.
  79.      */
  80.  
  81.     LockDisplay (display);
  82.  
  83.  
  84.     /*
  85.      * Put the request in the X request buffer and get a reply.
  86.      */
  87.  
  88.     PEXGetReqExtra (EscapeWithReply, escapeDataSize, req);
  89.     req->escapeID = escapeID;
  90.  
  91.     COPY_AREA ((char *) escapeData, ((char *) &req[1]), escapeDataSize);
  92.  
  93.     if (_XReply (display, &rep, 0, xFalse) == 0)
  94.     {
  95.         UnlockDisplay (display);
  96.         PEXSyncHandle (display);
  97.     *escapeOutDataSize = 0;
  98.         return (NULL);               /* return an error */
  99.     }
  100.  
  101.     *escapeOutDataSize = 20 + (rep.length << 2);
  102.  
  103.  
  104.     /*
  105.      * Allocate a buffer for the reply escape data
  106.      */
  107.  
  108.     escRepData = pescRepData = PEXAllocBuf ((unsigned) *escapeOutDataSize);
  109.  
  110.     COPY_AREA ((char *) rep.escape_specific, escRepData, 20);
  111.     escRepData += 20;
  112.  
  113.     if (rep.length)
  114.     _XRead (display, escRepData, (long) (rep.length << 2));
  115.  
  116.  
  117.     /*
  118.      * Done, so unlock and check for synchronous-ness.
  119.      */
  120.  
  121.     UnlockDisplay (display);
  122.     PEXSyncHandle (display);
  123.  
  124.     return (pescRepData);
  125. }
  126.  
  127.  
  128. void PEXSetEchoColor (display, renderer, color_type, color)
  129.  
  130. INPUT Display        *display;
  131. INPUT PEXRenderer    renderer;
  132. INPUT int        color_type;
  133. INPUT PEXColor        *color;
  134.  
  135. {
  136.     PEXEchoColorData    escapeData;
  137.     int            escapeSize;
  138.  
  139.  
  140.     /*
  141.      * Fill in the escape record.
  142.      */
  143.  
  144.     escapeData.fp_format = PEXGetProtocolFloatFormat (display);
  145.     escapeData.renderer = renderer;
  146.     escapeData.echo_color.type = color_type;
  147.  
  148.     COPY_AREA ((char *) color, (char *) &(escapeData.echo_color.value),
  149.     GetColorSize (color_type));
  150.  
  151.  
  152.     /*
  153.      * Generate the escape.
  154.      */
  155.  
  156.     escapeSize = sizeof (PEXEchoColorData) - AdjustSizeFromType (color_type);
  157.  
  158.     PEXEscape (display, PEXEscapeSetEchoColor, escapeSize,
  159.         (char *) &escapeData);
  160. }
  161.