#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include <X11/Xatom.h>
Status XGetRGBColormaps (
Display *dpy,
Window w,
XStandardColormap **stdcmap,
int *count,
Atom property)
{
register int i;
xPropStandardColormap *data = NULL;
Atom actual_type;
int actual_format;
unsigned long leftover;
unsigned long nitems;
int ncmaps;
Bool old_style = False;
VisualID def_visual = None;
XStandardColormap *cmaps;
if (XGetWindowProperty (dpy, w, property, 0L, 1000000L, False,
XA_RGB_COLOR_MAP, &actual_type, &actual_format,
&nitems, &leftover, (unsigned char **)&data)
!= Success)
return False;
if ((actual_type != XA_RGB_COLOR_MAP) || (actual_format != 32) ||
(nitems < OldNumPropStandardColormapElements)) {
if (data) Xfree ((char *) data);
return False;
}
if (nitems < NumPropStandardColormapElements) {
ncmaps = 1;
old_style = True;
if (nitems < (NumPropStandardColormapElements - 1)) {
Screen *sp = _XScreenOfWindow (dpy, w);
if (!sp) {
if (data) Xfree ((char *) data);
return False;
}
def_visual = sp->root_visual->visualid;
}
} else {
ncmaps = (nitems / NumPropStandardColormapElements);
if ((((unsigned long) ncmaps) * NumPropStandardColormapElements) !=
nitems) {
if (data) Xfree ((char *) data);
return False;
}
}
cmaps = (XStandardColormap *) Xmalloc (ncmaps *
sizeof (XStandardColormap));
if (!cmaps) {
if (data) Xfree ((char *) data);
return False;
}
{
register XStandardColormap *map;
register xPropStandardColormap *prop;
for (i = ncmaps, map = cmaps, prop = data; i > 0; i--, map++, prop++) {
map->colormap = prop->colormap;
map->red_max = prop->red_max;
map->red_mult = prop->red_mult;
map->green_max = prop->green_max;
map->green_mult = prop->green_mult;
map->blue_max = prop->blue_max;
map->blue_mult = prop->blue_mult;
map->base_pixel = prop->base_pixel;
map->visualid = (def_visual ? def_visual : prop->visualid);
map->killid = (old_style ? None : prop->killid);
}
}
Xfree ((char *) data);
*stdcmap = cmaps;
*count = ncmaps;
return True;
}