1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/* +-------------------------------------------------------------------+ */
/* | Copyright 1993, David Koblas (koblas@netcom.com) | */
/* | | */
/* | Permission to use, copy, modify, and to distribute this software | */
/* | and its documentation for any purpose is hereby granted without | */
/* | fee, provided that the above copyright notice appear in all | */
/* | copies and that both that copyright notice and this permission | */
/* | notice appear in supporting documentation. There is no | */
/* | representations about the suitability of this software for | */
/* | any purpose. this software is provided "as is" without express | */
/* | or implied warranty. | */
/* | | */
/* +-------------------------------------------------------------------+ */
/* $Id: typeConvert.c,v 1.17 2005/03/20 20:15:32 demailly Exp $ */
#include <X11/IntrinsicP.h>
#include <X11/CoreP.h>
#include <X11/StringDefs.h>
#include "palette.h"
#include "misc.h"
static Boolean
newCvtStringToPixel(Display * dpy, XrmValuePtr args,
Cardinal * nargs, XrmValuePtr from, XrmValuePtr to,
XtPointer junk)
{
Screen *screen;
Colormap cmap;
Palette *map;
String name = (String) (from->addr);
Boolean isReverse = False;
XColor scol, ecol;
static Pixel op;
if (*nargs != 2)
return False;
screen = *((Screen **) args[0].addr);
cmap = *((Colormap *) args[1].addr);
if (strcmp(name, XtDefaultBackground) == 0)
name = isReverse ? "black" : "white";
else if (strcmp(name, XtDefaultForeground) == 0)
name = isReverse ? "white" : "black";
if ((map = PaletteFindDpy(dpy, cmap)) == NULL) {
/*
** Not a "mapped" window, use standard X
*/
if (XAllocNamedColor(dpy, cmap, name, &scol, &ecol) == 0) {
if (XParseColor(dpy, cmap, name, &scol) == 0)
return False;
if (XAllocColor(dpy, cmap, &scol) == 0)
return False;
}
#if 0
printf("name = %s match = %d %d %d screen = %d %d %d\n",
name, ecol.red / 256, ecol.green / 256, ecol.blue / 256,
scol.red / 256, scol.green / 256, scol.blue / 256);
#endif
op = scol.pixel;
} else {
if (XLookupColor(dpy, map->cmap, name, &scol, &ecol) == 0 &&
XParseColor(dpy, map->cmap, name, &scol) == 0)
return False;
#if 0
printf("name = %s match = %d %d %d screen = %d %d %d\n",
name, ecol.red / 256, ecol.green / 256, ecol.blue / 256,
scol.red / 256, scol.green / 256, scol.blue / 256);
#endif
op = PaletteAlloc(map, &scol);
}
if (to->addr == NULL) {
to->addr = (XtPointer) & op;
} else {
if (to->size < sizeof(Pixel))
return False;
memcpy(to->addr, &op, sizeof(Pixel));
}
to->size = sizeof(Pixel);
return True;
}
void
InitTypeConverters(void)
{
static XtConvertArgRec colorArgs[] =
{
{XtWidgetBaseOffset,
(XtPointer) XtOffsetOf(WidgetRec, core.screen),
sizeof(Screen *)},
{XtWidgetBaseOffset,
(XtPointer) XtOffsetOf(WidgetRec, core.colormap),
sizeof(Colormap)},
};
XtSetTypeConverter(XtRString, XtRPixel,
(XtTypeConverter) newCvtStringToPixel,
colorArgs, XtNumber(colorArgs),
XtCacheRefCount, NULL);
}
|