home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcCmap.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  6KB  |  198 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /* $Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcCmap.c,v 9.4 89/06/08 20:21:10 jeff Exp $ */
  25. /* $Source: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcCmap.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcCmap.c,v 9.4 89/06/08 20:21:10 jeff Exp $" ;
  29. #endif
  30.  
  31. /*
  32.  *  Colormap routines for IBM ppc section.
  33.  *  T. Paquin 7/87
  34.  */
  35. #define NEED_EVENTS
  36.  
  37. #include "X.h"
  38. #include "Xproto.h"
  39. #include "resource.h"
  40. #include "misc.h"
  41. #include "scrnintstr.h"
  42. #include "screenint.h"
  43. #include "colormapst.h"
  44. #include "colormap.h"
  45. #include "pixmapstr.h"
  46.  
  47. #include "OScompiler.h"
  48. #include "ppc.h"
  49. #include "ibmTrace.h"
  50.  
  51. Bool
  52. ppcCreateColormapNoop( pmap )
  53.     ColormapPtr pmap;
  54.     {
  55.     return TRUE;
  56.     }
  57. void
  58. ppcStoreColors( pmap, ndef, pdefs )
  59. register ColormapPtr pmap ;
  60. register int ndef ;
  61. register xColorItem *pdefs ;
  62. {
  63. /* check to see if talking to current colormap, IF SO THEN INSTALL */
  64.    register void (*fnp)() ;
  65.    register int i ;
  66.    int this_is_installed ;
  67.    ppcScrnPrivPtr ppcPriv = (ppcScrnPriv *) (pmap->pScreen->devPrivate) ;
  68.  
  69.    this_is_installed = ( pmap == ppcPriv->InstalledColormap ) ;
  70.  
  71.    for ( fnp = ppcPriv->setColor ; ndef-- ; pdefs++ ) {
  72.     /* first, resolve colors into possible colors */
  73.     (*pmap->pScreen->ResolveColor)(    &(pdefs->red),
  74.                     &(pdefs->green),
  75.                     &(pdefs->blue),
  76.                     pmap->pVisual ) ;
  77.     if ( ( i = pdefs->pixel ) > pmap->pVisual->ColormapEntries )
  78.         ErrorF("ppcStoreColors: Bad pixel number\n") ;
  79.     else {
  80.         /* remember that the index to red is really the entry number */
  81.         pmap->red[i].co.local.red   = pdefs->red ;
  82.         pmap->red[i].co.local.green = pdefs->green ;
  83.         pmap->red[i].co.local.blue  = pdefs->blue ;
  84.         if ( this_is_installed )
  85.                 (*fnp)( i, pdefs->red, pdefs->green, pdefs->blue,
  86.                 pmap->pVisual ) ;
  87.     }
  88.     }
  89.  
  90.     return ;
  91. }
  92.  
  93. int
  94. ppcListInstalledColormaps( pScreen, pCmapList )
  95. register ScreenPtr pScreen ;
  96. register Colormap *pCmapList ;
  97. {
  98.        if ( ( (ppcScrnPriv *) pScreen->devPrivate)->InstalledColormap ) {
  99.         *pCmapList = ((ppcScrnPriv *) 
  100.                 (pScreen->devPrivate))->InstalledColormap->mid ;
  101.         return 1 ;
  102.     }
  103.     else {
  104.         *pCmapList = 0 ;
  105.         return 0 ;
  106.     }
  107.     /*NOTREACHED*/
  108. }
  109.  
  110. void
  111. ppcInstallColormap( pColormap ) 
  112. register ColormapPtr pColormap ;
  113. {
  114.    register int i ;
  115.    register void (*fnp)() ;
  116.    ppcScrnPrivPtr devPriv ;
  117.    ScreenPtr pScreen = pColormap->pScreen ;
  118.  
  119. TRACE( ( "ppcInstallColormap(pColormap=x%x)", pColormap ) ) ;
  120.  
  121.    if ( !pColormap ) /* Re-Install of NULL map ?? */
  122.     return ;
  123.  
  124.    devPriv = (ppcScrnPriv *) pScreen->devPrivate ;
  125.    fnp = devPriv->setColor ;
  126.    for ( i = pColormap->pVisual->ColormapEntries ; i-- ;  )
  127.     (*fnp)( i,
  128.         pColormap->red[i].co.local.red,
  129.         pColormap->red[i].co.local.green,
  130.         pColormap->red[i].co.local.blue,
  131.         pColormap->pVisual ) ;
  132.  
  133.    if ( devPriv->InstalledColormap != pColormap ) {
  134.     if ( devPriv->InstalledColormap ) /* Remember it may not exist */
  135.         WalkTree( pScreen, TellLostMap,
  136.               &(devPriv->InstalledColormap->mid) ) ;
  137.     devPriv->InstalledColormap = pColormap ;
  138.     WalkTree( pScreen, TellGainedMap, &(pColormap->mid) ) ;
  139.  
  140.     /* RecolorCursor --- * Added 9/28/87  T Paquin
  141.      *
  142.      * I know there is a RecolorCursor in the Screen structure, but
  143.      * It requires a pCurs pointer, which we do not have here.  Therefore,
  144.      * a ppcScreenPrivate function will be called with a pScreen parameter.
  145.      * At worst, the private function will return.  At second worst,
  146.      * it will have remembered the pCurs, and will call miRecolorCursor.
  147.      * At best, it will have remembered the cursor's FG and BG rgb values
  148.      * (which it has if it has saved the pCurs pointer)
  149.      * and will cause the cursor's colors to match the best available in
  150.      * the colormap we just finished installing.
  151.      * miRecolorCursor is a dog and calls code you had already in
  152.      * DisplayCursor (as well as Realize/Unrealize) anyway.
  153.      */
  154.     (* devPriv->RecolorCursor)( pColormap ) ;
  155.     }
  156.  
  157.    return ;
  158. }
  159.  
  160. void
  161. ppcUninstallColormap( pColormap ) 
  162. register ColormapPtr pColormap ;
  163. {
  164.    register ColormapPtr pCmap ;
  165.  
  166.    TRACE( ( "ppcUninstallColormap(pColormap=x%x)\n", pColormap ) ) ;
  167.  
  168.    pCmap = (ColormapPtr) LookupIDByType( pColormap->pScreen->defColormap,
  169.                    RT_COLORMAP ) ;
  170.    if ( pCmap != pColormap ) /* never uninstall the default map */
  171.     (* pColormap->pScreen->InstallColormap)( pCmap ) ;
  172.  
  173.    return ;
  174. }
  175.  
  176. /* WARNING WARNING WARNING
  177.  *
  178.  * THIS IS ONLY HERE FOR USE WHILE A SCREEN IS UNAVAILABLE.  We don't
  179.  * want the case where someone has stolen the screen but my alive (and
  180.  * nicely-not-drawing) server wants to do an alloc color on an installed
  181.  * colormap.
  182.  */
  183.  
  184. void
  185. ppcUninstallDefaultColormap( pScreen )
  186.     register ScreenPtr pScreen ;
  187. {
  188. ColormapPtr pCmap ;
  189.  
  190.     pCmap = (ColormapPtr) LookupIDByType( pScreen->defColormap, 
  191.                         RT_COLORMAP ) ;
  192.  
  193.        ((ppcScrnPriv *) pScreen->devPrivate)->InstalledColormap = 0 ;
  194.  
  195.     WalkTree( pScreen, TellLostMap, &(pCmap->mid) ) ;
  196.     return ;
  197. }
  198.