GetStCmap.c revision 1ab64890
1/* $Xorg: GetStCmap.c,v 1.4 2001/02/09 02:03:33 xorgcvs Exp $ */ 2 3/*********************************************************** 4 5Copyright 1987, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27 28Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 29 30 All Rights Reserved 31 32Permission to use, copy, modify, and distribute this software and its 33documentation for any purpose and without fee is hereby granted, 34provided that the above copyright notice appear in all copies and that 35both that copyright notice and this permission notice appear in 36supporting documentation, and that the name of Digital not be 37used in advertising or publicity pertaining to distribution of the 38software without specific, written prior permission. 39 40DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 41ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 42DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 43ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 44WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 45ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 46SOFTWARE. 47 48******************************************************************/ 49 50#ifdef HAVE_CONFIG_H 51#include <config.h> 52#endif 53#include <X11/Xlibint.h> 54#include <X11/Xutil.h> 55#include "Xatomtype.h" 56#include <X11/Xatom.h> 57 58/* 59 * WARNING 60 * 61 * This is a pre-ICCCM routine. It must not reference any of the new fields 62 * in the XStandardColormap structure. 63 */ 64 65Status XGetStandardColormap ( 66 Display *dpy, 67 Window w, 68 XStandardColormap *cmap, 69 Atom property) /* XA_RGB_BEST_MAP, etc. */ 70{ 71 Status stat; /* return value */ 72 XStandardColormap *stdcmaps; /* will get malloced value */ 73 int nstdcmaps; /* count of above */ 74 75 stat = XGetRGBColormaps (dpy, w, &stdcmaps, &nstdcmaps, property); 76 if (stat) { 77 XStandardColormap *use; 78 79 if (nstdcmaps > 1) { 80 VisualID vid; 81 Screen *sp = _XScreenOfWindow (dpy, w); 82 int i; 83 84 if (!sp) { 85 if (stdcmaps) Xfree ((char *) stdcmaps); 86 return False; 87 } 88 vid = sp->root_visual->visualid; 89 90 for (i = 0; i < nstdcmaps; i++) { 91 if (stdcmaps[i].visualid == vid) break; 92 } 93 94 if (i == nstdcmaps) { /* not found */ 95 Xfree ((char *) stdcmaps); 96 return False; 97 } 98 use = &stdcmaps[i]; 99 } else { 100 use = stdcmaps; 101 } 102 103 /* 104 * assign only those fields which were in the pre-ICCCM version 105 */ 106 cmap->colormap = use->colormap; 107 cmap->red_max = use->red_max; 108 cmap->red_mult = use->red_mult; 109 cmap->green_max = use->green_max; 110 cmap->green_mult = use->green_mult; 111 cmap->blue_max = use->blue_max; 112 cmap->blue_mult = use->blue_mult; 113 cmap->base_pixel = use->base_pixel; 114 115 Xfree ((char *) stdcmaps); /* don't need alloced memory */ 116 } 117 return stat; 118} 119