11ab64890Smrg/***********************************************************
21ab64890Smrg
31ab64890SmrgCopyright 1987, 1998  The Open Group
41ab64890Smrg
51ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its
61ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that
71ab64890Smrgthe above copyright notice appear in all copies and that both that
81ab64890Smrgcopyright notice and this permission notice appear in supporting
91ab64890Smrgdocumentation.
101ab64890Smrg
111ab64890SmrgThe above copyright notice and this permission notice shall be included in
121ab64890Smrgall copies or substantial portions of the Software.
131ab64890Smrg
141ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
151ab64890SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
161ab64890SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
171ab64890SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
181ab64890SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
191ab64890SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
201ab64890Smrg
211ab64890SmrgExcept as contained in this notice, the name of The Open Group shall not be
221ab64890Smrgused in advertising or otherwise to promote the sale, use or other dealings
231ab64890Smrgin this Software without prior written authorization from The Open Group.
241ab64890Smrg
251ab64890Smrg
261ab64890SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
271ab64890Smrg
281ab64890Smrg                        All Rights Reserved
291ab64890Smrg
3061b2299dSmrgPermission to use, copy, modify, and distribute this software and its
3161b2299dSmrgdocumentation for any purpose and without fee is hereby granted,
321ab64890Smrgprovided that the above copyright notice appear in all copies and that
3361b2299dSmrgboth that copyright notice and this permission notice appear in
341ab64890Smrgsupporting documentation, and that the name of Digital not be
351ab64890Smrgused in advertising or publicity pertaining to distribution of the
3661b2299dSmrgsoftware without specific, written prior permission.
371ab64890Smrg
381ab64890SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
391ab64890SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
401ab64890SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
411ab64890SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
421ab64890SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
431ab64890SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
441ab64890SmrgSOFTWARE.
451ab64890Smrg
461ab64890Smrg******************************************************************/
471ab64890Smrg
481ab64890Smrg#ifdef HAVE_CONFIG_H
491ab64890Smrg#include <config.h>
501ab64890Smrg#endif
511ab64890Smrg#include <X11/Xlibint.h>
521ab64890Smrg#include <X11/Xutil.h>
531ab64890Smrg#include "Xatomtype.h"
541ab64890Smrg#include <X11/Xatom.h>
551ab64890Smrg
561ab64890Smrg/*
571ab64890Smrg * 				    WARNING
5861b2299dSmrg *
591ab64890Smrg * This is a pre-ICCCM routine.  It must not reference any of the new fields
601ab64890Smrg * in the XStandardColormap structure.
611ab64890Smrg */
621ab64890Smrg
631ab64890SmrgStatus XGetStandardColormap (
641ab64890Smrg    Display *dpy,
651ab64890Smrg    Window w,
661ab64890Smrg    XStandardColormap *cmap,
671ab64890Smrg    Atom property)		/* XA_RGB_BEST_MAP, etc. */
681ab64890Smrg{
691ab64890Smrg    Status stat;			/* return value */
701ab64890Smrg    XStandardColormap *stdcmaps;	/* will get malloced value */
711ab64890Smrg    int nstdcmaps;			/* count of above */
721ab64890Smrg
731ab64890Smrg    stat = XGetRGBColormaps (dpy, w, &stdcmaps, &nstdcmaps, property);
741ab64890Smrg    if (stat) {
751ab64890Smrg	XStandardColormap *use;
761ab64890Smrg
771ab64890Smrg	if (nstdcmaps > 1) {
781ab64890Smrg	    VisualID vid;
791ab64890Smrg	    Screen *sp = _XScreenOfWindow (dpy, w);
801ab64890Smrg	    int i;
811ab64890Smrg
821ab64890Smrg	    if (!sp) {
830f8248bfSmrg		Xfree (stdcmaps);
841ab64890Smrg		return False;
851ab64890Smrg	    }
861ab64890Smrg	    vid = sp->root_visual->visualid;
871ab64890Smrg
881ab64890Smrg	    for (i = 0; i < nstdcmaps; i++) {
891ab64890Smrg		if (stdcmaps[i].visualid == vid) break;
901ab64890Smrg	    }
911ab64890Smrg
921ab64890Smrg	    if (i == nstdcmaps) {	/* not found */
93818534a1Smrg		Xfree (stdcmaps);
941ab64890Smrg		return False;
951ab64890Smrg	    }
961ab64890Smrg	    use = &stdcmaps[i];
971ab64890Smrg	} else {
981ab64890Smrg	    use = stdcmaps;
991ab64890Smrg	}
10061b2299dSmrg
1011ab64890Smrg	/*
1021ab64890Smrg	 * assign only those fields which were in the pre-ICCCM version
1031ab64890Smrg	 */
1041ab64890Smrg	cmap->colormap	 = use->colormap;
1051ab64890Smrg	cmap->red_max	 = use->red_max;
1061ab64890Smrg	cmap->red_mult	 = use->red_mult;
1071ab64890Smrg	cmap->green_max	 = use->green_max;
1081ab64890Smrg	cmap->green_mult = use->green_mult;
1091ab64890Smrg	cmap->blue_max	 = use->blue_max;
1101ab64890Smrg	cmap->blue_mult	 = use->blue_mult;
1111ab64890Smrg	cmap->base_pixel = use->base_pixel;
1121ab64890Smrg
113d7c63e31Smrg	Xfree (stdcmaps);	/* don't need allocated memory */
1141ab64890Smrg    }
1151ab64890Smrg    return stat;
1161ab64890Smrg}
117