3 Copyright 1989, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * Author: Donna Converse, MIT X Consortium
37 #include <X11/Xatom.h>
38 #include <X11/Xutil.h>
39 #include <X11/Xmu/StdCmap.h>
42 * To create all of the appropriate standard colormaps for a given visual on
43 * a given screen, use XmuVisualStandardColormaps.
45 * Define all appropriate standard colormap properties for the given visual.
46 * If replace is true, any previous definition will be removed.
47 * If retain is true, new properties will be retained for the duration of
48 * the server session. Return 0 on failure, non-zero on success.
49 * On failure, no new properties will be defined, and, old ones may have
50 * been removed if replace was True.
52 * Not all standard colormaps are meaningful to all visual classes. This
53 * routine will check and define the following properties for the following
54 * classes, provided that the size of the colormap is not too small.
56 * DirectColor and PseudoColor
64 * TrueColor and StaticColor
67 * GrayScale and StaticGray
72 XmuVisualStandardColormaps(Display *dpy, int screen, VisualID visualid,
73 unsigned int depth, Bool replace, Bool retain)
75 * dpy - specifies server connection
76 * screen - specifies screen number
77 * visualid - specifies the visual
78 * depth - specifies the visual
79 * replace specifies - whether to replace
80 * retain - specifies whether to retain
86 XVisualInfo vinfo_template, *vinfo;
89 vinfo_template.screen = screen;
90 vinfo_template.visualid = visualid;
91 vinfo_template.depth = depth;
92 vinfo_mask = VisualScreenMask | VisualIDMask | VisualDepthMask;
93 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
96 if (vinfo->colormap_size <= 2) {
97 /* Monochrome visuals have no standard maps; considered successful */
98 XFree((char *) vinfo);
102 switch (vinfo->class)
106 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
107 XA_RGB_DEFAULT_MAP, replace,retain);
110 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
111 XA_RGB_GRAY_MAP, replace, retain);
113 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
117 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
118 XA_RGB_RED_MAP, replace, retain);
120 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
121 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
125 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
126 XA_RGB_GREEN_MAP, replace, retain);
128 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
129 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
130 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
134 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
135 XA_RGB_BLUE_MAP, replace, retain);
137 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
138 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
139 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
140 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
148 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
149 XA_RGB_BEST_MAP, replace, retain);
150 if (!status && (vinfo->class == PseudoColor ||
151 vinfo->class == DirectColor)) {
152 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
153 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
154 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
155 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
156 XmuDeleteStandardColormap(dpy, screen, XA_RGB_BLUE_MAP);
159 /* the end for PseudoColor, DirectColor, StaticColor, and TrueColor */
162 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
163 XA_RGB_DEFAULT_MAP, replace,
170 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
171 XA_RGB_GRAY_MAP, replace, retain);
172 if (! status && vinfo->class == GrayScale) {
173 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
178 XFree((char *) vinfo);