| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1989, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included |
| 12 |
in all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 |
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
|
| 22 |
Except as contained in this notice, the name of The Open Group shall |
| 23 |
not be used in advertising or otherwise to promote the sale, use or |
| 24 |
other dealings in this Software without prior written authorization |
| 25 |
from The Open Group. |
| 26 |
|
| 27 |
*/ |
| 28 |
|
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include <config.h> |
| 32 |
#endif |
| 33 |
#include <nx-X11/Xlibint.h> |
| 34 |
#include <nx-X11/Xutil.h> |
| 35 |
#include "Xatomtype.h" |
| 36 |
#include <nx-X11/Xatom.h> |
| 37 |
|
| 38 |
void XSetRGBColormaps ( |
| 39 |
Display *dpy, |
| 40 |
Window w, |
| 41 |
XStandardColormap *cmaps, |
| 42 |
int count, |
| 43 |
Atom property) /* XA_RGB_BEST_MAP, etc. */ |
| 44 |
{ |
| 45 |
register int i; /* iterator variable */ |
| 46 |
register xPropStandardColormap *map; /* tmp variable, data in prop */ |
| 47 |
register XStandardColormap *cmap; /* tmp variable, user data */ |
| 48 |
xPropStandardColormap *data, tmpdata; /* scratch data */ |
| 49 |
int mode = PropModeReplace; /* for partial writes */ |
| 50 |
Bool alloced_scratch_space; /* do we need to free? */ |
| 51 |
|
| 52 |
|
| 53 |
if (count < 1) return; |
| 54 |
|
| 55 |
/* |
| 56 |
* if doing more than one, allocate scratch space for it |
| 57 |
*/ |
| 58 |
if ((count > 1) && ((data = ((xPropStandardColormap *) |
| 59 |
Xmalloc(count*sizeof(xPropStandardColormap)))) |
| 60 |
!= NULL)) { |
| 61 |
alloced_scratch_space = True; |
| 62 |
} else { |
| 63 |
data = &tmpdata; |
| 64 |
alloced_scratch_space = False; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/* |
| 69 |
* Do the iteration. If using temp space put out each part of the prop; |
| 70 |
* otherwise, wait until the end and blast it all at once. |
| 71 |
*/ |
| 72 |
for (i = count, map = data, cmap = cmaps; i > 0; i--, cmap++) { |
| 73 |
map->colormap = cmap->colormap; |
| 74 |
map->red_max = cmap->red_max; |
| 75 |
map->red_mult = cmap->red_mult; |
| 76 |
map->green_max = cmap->green_max; |
| 77 |
map->green_mult = cmap->green_mult; |
| 78 |
map->blue_max = cmap->blue_max; |
| 79 |
map->blue_mult = cmap->blue_mult; |
| 80 |
map->base_pixel = cmap->base_pixel; |
| 81 |
map->visualid = cmap->visualid; |
| 82 |
map->killid = cmap->killid; |
| 83 |
|
| 84 |
if (alloced_scratch_space) { |
| 85 |
map++; |
| 86 |
} else { |
| 87 |
XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32, mode, |
| 88 |
(unsigned char *) data, |
| 89 |
NumPropStandardColormapElements); |
| 90 |
mode = PropModeAppend; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if (alloced_scratch_space) { |
| 95 |
XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32, |
| 96 |
PropModeReplace, (unsigned char *) data, |
| 97 |
(int) (count * NumPropStandardColormapElements)); |
| 98 |
Xfree (data); |
| 99 |
} |
| 100 |
} |