4 Copyright 1987, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of The Open Group shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
33 #include <X11/Xlibint.h>
34 #include <X11/Xutil.h>
35 #include "Xatomtype.h"
36 #include <X11/Xatom.h>
38 Status XGetRGBColormaps (
41 XStandardColormap **stdcmap, /* RETURN */
42 int *count, /* RETURN */
43 Atom property) /* XA_RGB_BEST_MAP, etc. */
45 register int i; /* iterator variable */
46 xPropStandardColormap *data = NULL; /* data read in from prop */
47 Atom actual_type; /* how the prop was actually stored */
48 int actual_format; /* ditto */
49 unsigned long leftover; /* how much was left over */
50 unsigned long nitems; /* number of 32bits read */
51 int ncmaps; /* number of structs this makes */
52 Bool old_style = False; /* if was too short */
53 VisualID def_visual = None; /* visual to use if prop too short */
54 XStandardColormap *cmaps; /* return value */
57 if (XGetWindowProperty (dpy, w, property, 0L, 1000000L, False,
58 XA_RGB_COLOR_MAP, &actual_type, &actual_format,
59 &nitems, &leftover, (unsigned char **)&data)
63 /* if wrong type or format, or too small for us, then punt */
64 if ((actual_type != XA_RGB_COLOR_MAP) || (actual_format != 32) ||
65 (nitems < OldNumPropStandardColormapElements)) {
66 if (data) Xfree ((char *) data);
71 * See how many properties were found; if pre-ICCCM then assume
72 * default visual and a kill id of 1.
74 if (nitems < NumPropStandardColormapElements) {
77 if (nitems < (NumPropStandardColormapElements - 1)) {
78 Screen *sp = _XScreenOfWindow (dpy, w);
81 if (data) Xfree ((char *) data);
84 def_visual = sp->root_visual->visualid;
88 * make sure we have an integral number of colormaps
90 ncmaps = (nitems / NumPropStandardColormapElements);
91 if ((((unsigned long) ncmaps) * NumPropStandardColormapElements) !=
93 if (data) Xfree ((char *) data);
102 cmaps = (XStandardColormap *) Xmalloc (ncmaps *
103 sizeof (XStandardColormap));
105 if (data) Xfree ((char *) data);
111 * and fill it in, handling compatibility with pre-ICCCM short stdcmaps
114 register XStandardColormap *map;
115 register xPropStandardColormap *prop;
117 for (i = ncmaps, map = cmaps, prop = data; i > 0; i--, map++, prop++) {
118 map->colormap = prop->colormap;
119 map->red_max = prop->red_max;
120 map->red_mult = prop->red_mult;
121 map->green_max = prop->green_max;
122 map->green_mult = prop->green_mult;
123 map->blue_max = prop->blue_max;
124 map->blue_mult = prop->blue_mult;
125 map->base_pixel = prop->base_pixel;
126 map->visualid = (def_visual ? def_visual : prop->visualid);
127 map->killid = (old_style ? None : prop->killid);
130 Xfree ((char *) data);