00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <X11/Xlib.h>
00037 #include <X11/Xatom.h>
00038 #include <X11/Xutil.h>
00039 #include <X11/Xmu/StdCmap.h>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 Status
00072 XmuVisualStandardColormaps(Display *dpy, int screen, VisualID visualid,
00073 unsigned int depth, Bool replace, Bool retain)
00074
00075
00076
00077
00078
00079
00080
00081
00082 {
00083 Status status;
00084 int n;
00085 long vinfo_mask;
00086 XVisualInfo vinfo_template, *vinfo;
00087
00088 status = 0;
00089 vinfo_template.screen = screen;
00090 vinfo_template.visualid = visualid;
00091 vinfo_template.depth = depth;
00092 vinfo_mask = VisualScreenMask | VisualIDMask | VisualDepthMask;
00093 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
00094 return 0;
00095
00096 if (vinfo->colormap_size <= 2) {
00097
00098 XFree((char *) vinfo);
00099 return 1;
00100 }
00101
00102 switch (vinfo->class)
00103 {
00104 case PseudoColor:
00105 case DirectColor:
00106 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00107 XA_RGB_DEFAULT_MAP, replace,retain);
00108 if (!status) break;
00109
00110 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00111 XA_RGB_GRAY_MAP, replace, retain);
00112 if (!status) {
00113 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00114 break;
00115 }
00116
00117 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00118 XA_RGB_RED_MAP, replace, retain);
00119 if (!status) {
00120 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00121 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
00122 break;
00123 }
00124
00125 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00126 XA_RGB_GREEN_MAP, replace, retain);
00127 if (!status) {
00128 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00129 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
00130 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
00131 break;
00132 }
00133
00134 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00135 XA_RGB_BLUE_MAP, replace, retain);
00136 if (!status) {
00137 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00138 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
00139 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
00140 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
00141 break;
00142 }
00143
00144
00145 case StaticColor:
00146 case TrueColor:
00147
00148 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00149 XA_RGB_BEST_MAP, replace, retain);
00150 if (!status && (vinfo->class == PseudoColor ||
00151 vinfo->class == DirectColor)) {
00152 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00153 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP);
00154 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP);
00155 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP);
00156 XmuDeleteStandardColormap(dpy, screen, XA_RGB_BLUE_MAP);
00157 }
00158 break;
00159
00160
00161 case GrayScale:
00162 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00163 XA_RGB_DEFAULT_MAP, replace,
00164 retain);
00165 if (! status) break;
00166
00167
00168 case StaticGray:
00169
00170 status = XmuLookupStandardColormap(dpy, screen, visualid, depth,
00171 XA_RGB_GRAY_MAP, replace, retain);
00172 if (! status && vinfo->class == GrayScale) {
00173 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
00174 break;
00175 }
00176 }
00177
00178 XFree((char *) vinfo);
00179 return status;
00180 }