home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / pgc / pgcCmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  4.4 KB  |  174 lines

  1. /*
  2.  * $XConsortium: pgcCmap.c,v 1.2 91/07/16 13:11:53 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM 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. #define NEED_EVENTS
  28.  
  29. #include "X.h"
  30. #include "Xproto.h"
  31. #include "resource.h"
  32. #include "misc.h"
  33. #include "scrnintstr.h"
  34. #include "screenint.h"
  35. #include "colormapst.h"
  36. #include "colormap.h"
  37. #include "pixmapstr.h"
  38.  
  39. #include "ibmTrace.h"
  40.  
  41. #include "pgc.h"
  42.  
  43. extern pgcScreenRec pgcScreenInfo[] ; 
  44.  
  45. void
  46. pgcStoreColors( pmap, ndef, pdefs )
  47. register ColormapPtr pmap ;
  48. register int ndef ;
  49. register xColorItem *pdefs ;
  50. {
  51.    register void (*fnp)() ;
  52.    register int i ;
  53.    int this_is_installed ;
  54.    int index ;
  55.    pgcScreenPtr pPGCScreen ;
  56.  
  57.    index = pmap->pScreen->myNum ;
  58.    pPGCScreen = &pgcScreenInfo[index] ;
  59.  
  60.    this_is_installed = ( pmap == pPGCScreen->InstalledColormap ) ;
  61.  
  62.    for ( fnp = pPGCScreen->setColor ; ndef-- ; pdefs++ ) {
  63.     /* first, resolve colors into possible colors */
  64.     (*pmap->pScreen->ResolveColor)(    &(pdefs->red),
  65.                     &(pdefs->green),
  66.                     &(pdefs->blue),
  67.                     pmap->pVisual ) ;
  68.     if ( ( i = pdefs->pixel ) > pmap->pVisual->ColormapEntries )
  69.         ErrorF("pgcStoreColors: Bad pixel number\n") ;
  70.     else {
  71.         /* remember that the index to red is really the entry number */
  72.         pmap->red[i].co.local.red   = pdefs->red ;
  73.         pmap->red[i].co.local.green = pdefs->green ;
  74.         pmap->red[i].co.local.blue  = pdefs->blue ;
  75.         if ( this_is_installed )
  76.                (*fnp)( i, pdefs->red, pdefs->green, pdefs->blue, index);
  77.     }
  78.     }
  79.  
  80.     return ;
  81. }
  82.  
  83. int
  84. pgcListInstalledColormaps( pScreen, pCmapList )
  85. register ScreenPtr pScreen ;
  86. register Colormap *pCmapList ;
  87. {
  88.    int index ;
  89.    pgcScreenPtr pPGCScreen ;
  90.  
  91.    index = pScreen->myNum ;
  92.    pPGCScreen = &pgcScreenInfo[index] ;
  93.  
  94.        if ( pPGCScreen->InstalledColormap ) {
  95.                 *pCmapList = pPGCScreen->InstalledColormap->mid ;
  96.         return 1 ;
  97.     }
  98.     else {
  99.         *pCmapList = 0 ;
  100.         return 0 ;
  101.     }
  102.     /*NOTREACHED*/
  103. }
  104.  
  105. void
  106. pgcInstallColormap( pColormap ) 
  107. register ColormapPtr pColormap ;
  108. {
  109.    register int i ;
  110.    register void (*fnp)() ;
  111.    int index ;
  112.    pgcScreenPtr pPGCScreen ;
  113.    ScreenPtr pScreen = pColormap->pScreen ;
  114.  
  115.    TRACE( ( "pgcInstallColormap(pColormap=x%x)", pColormap ) ) ;
  116.  
  117.    index = pScreen->myNum ;
  118.    pPGCScreen = &pgcScreenInfo[index] ;
  119.  
  120.    if ( !pColormap ) /* Re-Install of NULL map ?? */
  121.     return ;
  122.  
  123.    fnp = pPGCScreen->setColor ;
  124.  
  125.    for ( i = pColormap->pVisual->ColormapEntries ; i-- ;  )
  126.     (*fnp)( i,
  127.         pColormap->red[i].co.local.red,
  128.         pColormap->red[i].co.local.green,
  129.         pColormap->red[i].co.local.blue,
  130.         index ) ;
  131.  
  132.    if ( pPGCScreen->InstalledColormap != pColormap ) {
  133.     if ( pPGCScreen->InstalledColormap ) /* Remember it may not exist */
  134.         WalkTree( pScreen, TellLostMap,
  135.               &(pPGCScreen->InstalledColormap->mid) ) ;
  136.     pPGCScreen->InstalledColormap = pColormap ;
  137.     WalkTree( pScreen, TellGainedMap, &(pColormap->mid) ) ;
  138.  
  139.     }
  140.  
  141.    return ;
  142. }
  143.  
  144. void
  145. pgcUninstallColormap( pColormap ) 
  146. register ColormapPtr pColormap ;
  147. {
  148.    register ColormapPtr pCmap ;
  149.  
  150.    TRACE( ( "pgcUninstallColormap(pColormap=x%x)\n", pColormap ) ) ;
  151.  
  152.    pCmap = (ColormapPtr) LookupIDByType( pColormap->pScreen->defColormap,
  153.                    RT_COLORMAP ) ;
  154.    if ( pCmap != pColormap ) /* never uninstall the default map */
  155.     (* pColormap->pScreen->InstallColormap)( pCmap ) ;
  156.  
  157.    return ;
  158. }
  159.  
  160. pgcRefreshColormaps(pScreen)
  161. ScreenPtr pScreen ;
  162. {
  163.    ColormapPtr pCmap ;
  164.    int index ;
  165.    pgcScreenPtr pPGCScreen ;
  166.  
  167.    index = pScreen->myNum ;
  168.    pPGCScreen = &pgcScreenInfo[index] ;
  169.  
  170.    pCmap = pPGCScreen->InstalledColormap ;
  171.    pgcInstallColormap(pCmap);
  172.  
  173. }
  174.