home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-13  |  8.1 KB  |  297 lines

  1. /* $XConsortium: mfbwindow.c,v 5.8 89/09/13 18:58:36 rws Exp $ */
  2. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  3. /***********************************************************
  4. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #include "X.h"
  28. #include "scrnintstr.h"
  29. #include "windowstr.h"
  30. #include "mfb.h"
  31. #include "mistruct.h"
  32. #include "regionstr.h"
  33.  
  34. extern WindowPtr *WindowTable;
  35.  
  36. Bool
  37. mfbCreateWindow(pWin)
  38.     register WindowPtr pWin;
  39. {
  40.     register mfbPrivWin *pPrivWin;
  41.  
  42.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  43.     pPrivWin->pRotatedBorder = NullPixmap;
  44.     pPrivWin->pRotatedBackground = NullPixmap;
  45.     pPrivWin->fastBackground = FALSE;
  46.     pPrivWin->fastBorder = FALSE;
  47.  
  48.     return (TRUE);
  49. }
  50.  
  51. /* This always returns true, because Xfree can't fail.  It might be possible
  52.  * on some devices for Destroy to fail */
  53. Bool 
  54. mfbDestroyWindow(pWin)
  55.     WindowPtr pWin;
  56. {
  57.     register mfbPrivWin *pPrivWin;
  58.  
  59.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  60.  
  61.     if (pPrivWin->pRotatedBorder)
  62.     mfbDestroyPixmap(pPrivWin->pRotatedBorder);
  63.     if (pPrivWin->pRotatedBackground)
  64.     mfbDestroyPixmap(pPrivWin->pRotatedBackground);
  65.     return (TRUE);
  66. }
  67.  
  68. /*ARGSUSED*/
  69. Bool mfbMapWindow(pWindow)
  70.     WindowPtr pWindow;
  71. {
  72.     return (TRUE);
  73. }
  74.  
  75. /* (x, y) is the upper left corner of the window on the screen 
  76.    do we really need to pass this?  (is it a;ready in pWin->absCorner?)
  77.    we only do the rotation for pixmaps that are 32 bits wide (padded
  78. or otherwise.)
  79.    mfbChangeWindowAttributes() has already put a copy of the pixmap
  80. in pPrivWin->pRotated*
  81. */
  82.  
  83. /*ARGSUSED*/
  84. Bool 
  85. mfbPositionWindow(pWin, x, y)
  86.     register WindowPtr pWin;
  87.     int x, y;
  88. {
  89.     register mfbPrivWin *pPrivWin;
  90.     int    reset = 0;
  91.  
  92.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  93.     if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
  94.     {
  95.     mfbXRotatePixmap(pPrivWin->pRotatedBackground,
  96.              pWin->drawable.x - pPrivWin->oldRotate.x);
  97.     mfbYRotatePixmap(pPrivWin->pRotatedBackground,
  98.              pWin->drawable.y - pPrivWin->oldRotate.y);
  99.     reset = 1;
  100.     }
  101.  
  102.     if (!pWin->borderIsPixel && pPrivWin->fastBorder)
  103.     {
  104.     mfbXRotatePixmap(pPrivWin->pRotatedBorder,
  105.              pWin->drawable.x - pPrivWin->oldRotate.x);
  106.     mfbYRotatePixmap(pPrivWin->pRotatedBorder,
  107.              pWin->drawable.y - pPrivWin->oldRotate.y);
  108.     reset = 1;
  109.     }
  110.     if (reset)
  111.     {
  112.     pPrivWin->oldRotate.x = pWin->drawable.x;
  113.     pPrivWin->oldRotate.y = pWin->drawable.y;
  114.     }
  115.  
  116.     /* This is the "wrong" fix to the right problem, but it doesn't really
  117.      * cost very much.  When the window is moved, we need to invalidate any
  118.      * RotatedPixmap that exists in any GC currently validated against this
  119.      * window.
  120.      */
  121.     pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  122.  
  123.     /* Again, we have no failure modes indicated by any of the routines
  124.      * we've called, so we have to assume it worked */
  125.     return (TRUE);
  126. }
  127.  
  128. /*ARGSUSED*/
  129. Bool 
  130. mfbUnmapWindow(pWindow)
  131.     WindowPtr pWindow;
  132. {
  133.     return (TRUE);
  134. }
  135.  
  136. /* UNCLEAN!
  137.    this code calls the bitblt helper code directly.
  138.  
  139.    mfbCopyWindow copies only the parts of the destination that are
  140. visible in the source.
  141. */
  142.  
  143.  
  144. void 
  145. mfbCopyWindow(pWin, ptOldOrg, prgnSrc)
  146.     WindowPtr pWin;
  147.     DDXPointRec ptOldOrg;
  148.     RegionPtr prgnSrc;
  149. {
  150.     DDXPointPtr pptSrc;
  151.     register DDXPointPtr ppt;
  152.     RegionPtr prgnDst;
  153.     register BoxPtr pbox;
  154.     register int dx, dy;
  155.     register int i, nbox;
  156.     WindowPtr pwinRoot;
  157.  
  158.     pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
  159.  
  160.     prgnDst = (* pWin->drawable.pScreen->RegionCreate)(NULL, 1);
  161.  
  162.     dx = ptOldOrg.x - pWin->drawable.x;
  163.     dy = ptOldOrg.y - pWin->drawable.y;
  164.     (* pWin->drawable.pScreen->TranslateRegion)(prgnSrc, -dx, -dy);
  165.     (* pWin->drawable.pScreen->Intersect)(prgnDst, &pWin->borderClip, prgnSrc);
  166.  
  167.     pbox = REGION_RECTS(prgnDst);
  168.     nbox = REGION_NUM_RECTS(prgnDst);
  169.     if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
  170.     return;
  171.     ppt = pptSrc;
  172.  
  173.     for (i=nbox; --i >= 0; ppt++, pbox++)
  174.     {
  175.     ppt->x = pbox->x1 + dx;
  176.     ppt->y = pbox->y1 + dy;
  177.     }
  178.  
  179.     mfbDoBitblt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
  180.         GXcopy, prgnDst, pptSrc);
  181.     DEALLOCATE_LOCAL(pptSrc);
  182.     (* pWin->drawable.pScreen->RegionDestroy)(prgnDst);
  183. }
  184.  
  185.  
  186.  
  187. /* swap in correct PaintWindow* routine.  If we can use a fast output
  188. routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
  189. of it in devPrivate.
  190. */
  191. Bool
  192. mfbChangeWindowAttributes(pWin, mask)
  193.     register WindowPtr pWin;
  194.     register unsigned long mask;
  195. {
  196.     register unsigned long index;
  197.     register mfbPrivWin *pPrivWin;
  198.  
  199.     pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
  200.     while(mask)
  201.     {
  202.     index = lowbit (mask);
  203.     mask &= ~index;
  204.     switch(index)
  205.     {
  206. #ifdef NOTDEF
  207.       case CWBackingStore:
  208.           if (pWin->backingStore != NotUseful)
  209.           {
  210.           miInitBackingStore(pWin, mfbSaveAreas, mfbRestoreAreas, (void (*)()) 0);
  211.           }
  212.           else
  213.           {
  214.           miFreeBackingStore(pWin);
  215.           }
  216.           /*
  217.            * XXX: The changing of the backing-store status of a window
  218.            * is serious enough to warrant a validation, since otherwise
  219.            * the backing-store stuff won't work.
  220.            */
  221.           pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  222.           break;
  223. #endif
  224.  
  225.       case CWBackPixmap:
  226.           if (pWin->backgroundState == None)
  227.           {
  228.           pPrivWin->fastBackground = FALSE;
  229.           }
  230.           else if (pWin->backgroundState == ParentRelative)
  231.           {
  232.           pPrivWin->fastBackground = FALSE;
  233.           }
  234.           else if ((pWin->background.pixmap->drawable.width <= 32) &&
  235.                !(pWin->background.pixmap->drawable.width &
  236.              (pWin->background.pixmap->drawable.width - 1)))
  237.           {
  238.           mfbCopyRotatePixmap(pWin->background.pixmap,
  239.                       &pPrivWin->pRotatedBackground,
  240.                       pWin->drawable.x,
  241.                       pWin->drawable.y);
  242.           if (pPrivWin->pRotatedBackground)
  243.           {
  244.               pPrivWin->fastBackground = TRUE;
  245.               pPrivWin->oldRotate.x = pWin->drawable.x;
  246.               pPrivWin->oldRotate.y = pWin->drawable.y;
  247.           }
  248.           else
  249.           {
  250.               pPrivWin->fastBackground = FALSE;
  251.           }
  252.           }
  253.           else
  254.           {
  255.           pPrivWin->fastBackground = FALSE;
  256.           }
  257.           break;
  258.  
  259.       case CWBackPixel:
  260.           pPrivWin->fastBackground = FALSE;
  261.           break;
  262.  
  263.       case CWBorderPixmap:
  264.           if ((pWin->border.pixmap->drawable.width <= 32) &&
  265.           !(pWin->border.pixmap->drawable.width &
  266.             (pWin->border.pixmap->drawable.width - 1)))
  267.           {
  268.           mfbCopyRotatePixmap(pWin->border.pixmap,
  269.                       &pPrivWin->pRotatedBorder,
  270.                       pWin->drawable.x,
  271.                       pWin->drawable.y);
  272.           if (pPrivWin->pRotatedBorder)
  273.           {
  274.               pPrivWin->fastBorder = TRUE;
  275.               pPrivWin->oldRotate.x = pWin->drawable.x;
  276.               pPrivWin->oldRotate.y = pWin->drawable.y;
  277.           }
  278.           else
  279.           {
  280.               pPrivWin->fastBorder = FALSE;
  281.           }
  282.           }
  283.           else
  284.           {
  285.           pPrivWin->fastBorder = FALSE;
  286.           }
  287.           break;
  288.         case CWBorderPixel:
  289.           pPrivWin->fastBorder = FALSE;
  290.           break;
  291.     }
  292.     }
  293.     /* Again, we have no failure modes indicated by any of the routines
  294.      * we've called, so we have to assume it worked */
  295.     return (TRUE);
  296. }
  297.