/*ARGSUSED*/ static Boolean _XawCvtStringToPixmap(Display *dpy, XrmValue *args, Cardinal *num_args, XrmValue *fromVal, XrmValue *toVal, XtPointer *converter_data) { XawPixmap *xaw_pixmap; Pixmap pixmap; Screen *screen; Colormap colormap; int depth; String name; if (*num_args != 3) { XtAppWarningMsg(XtDisplayToApplicationContext(dpy), XtNwrongParameters, "cvtStringToPixmap", XtCToolkitError, "String to Pixmap conversion needs screen, " "colormap, and depth arguments", NULL, NULL); return (False); } screen = *(Screen **)args[0].addr; colormap = *(Colormap *)args[1].addr; depth = *(int *)args[2].addr; name = (String)(fromVal[0].addr); if (XmuCompareISOLatin1(name, "None") == 0) pixmap = None; else if (XmuCompareISOLatin1(name, "ParentRelative") == 0) pixmap = ParentRelative; else if (XmuCompareISOLatin1(name, "XtUnspecifiedPixmap") == 0) pixmap = XtUnspecifiedPixmap; else { xaw_pixmap = XawLoadPixmap(name, screen, colormap, depth); if (!xaw_pixmap) { XtDisplayStringConversionWarning(dpy, (String)fromVal->addr, XtRPixmap); toVal->addr = (XtPointer)XtUnspecifiedPixmap; toVal->size = sizeof(Pixmap); return (False); } else pixmap = xaw_pixmap->pixmap; } done(Pixmap, pixmap); }
/*ARGSUSED*/ Boolean XmuCvtStringToShapeStyle(Display *dpy, XrmValue *args, Cardinal *num_args, XrmValue *from, XrmValue *toVal, XtPointer *data) { String name = (String)from->addr; if (XmuCompareISOLatin1(name, XtERectangle) == 0) done(int, XmuShapeRectangle); if (XmuCompareISOLatin1(name, XtEOval) == 0) done(int, XmuShapeOval); if (XmuCompareISOLatin1(name, XtEEllipse) == 0) done(int, XmuShapeEllipse); if (XmuCompareISOLatin1(name, XtERoundedRectangle) == 0) done(int, XmuShapeRoundedRectangle); XtDisplayStringConversionWarning(dpy, name, XtRShapeStyle); return (False); }
static Bool GradientLoader(XawParams *params, Screen *screen, Colormap colormap, int depth, Pixmap *pixmap_return, Pixmap *mask_return, Dimension *width_return, Dimension *height_return) { double ired, igreen, iblue, red, green, blue; XColor start, end, color; XGCValues values; GC gc; double i, inc, x, y, xend, yend; Pixmap pixmap; XawArgVal *argval; int orientation, dimension, steps; char *value; if (XmuCompareISOLatin1(params->name, "vertical") == 0) orientation = VERTICAL; else if (XmuCompareISOLatin1(params->name, "horizontal") == 0) orientation = HORIZONTAL; else return (False); if ((argval = XawFindArgVal(params, "dimension")) != NULL && argval->value) { dimension = atoi(argval->value); if (dimension <= 0) return (False); } else dimension = 50; if ((argval = XawFindArgVal(params, "steps")) != NULL && argval->value) { steps = atoi(argval->value); if (steps <= 0) return (False); } else steps = dimension; steps = XawMin(steps, dimension); value = NULL; if ((argval = XawFindArgVal(params, "start")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &start, &color)) return (False); else if (!value) { start.pixel = WhitePixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &start); } value = NULL; if ((argval = XawFindArgVal(params, "end")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &end, &color)) return (False); else if (!value) { end.pixel = BlackPixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &end); } if ((pixmap = XCreatePixmap(DisplayOfScreen(screen), RootWindowOfScreen(screen), orientation == VERTICAL ? 1 : dimension, orientation == VERTICAL ? dimension : 1, depth)) == 0) return (False); ired = (double)(end.red - start.red) / (double)steps; igreen = (double)(end.green - start.green) / (double)steps; iblue = (double)(end.blue - start.blue) / (double)steps; red = color.red = start.red; green = color.green = start.green; blue = color.blue = start.blue; inc = (double)dimension / (double)steps; gc = XCreateGC(DisplayOfScreen(screen), pixmap, 0, &values); x = y = 0.0; if (orientation == VERTICAL) { xend = 1; yend = 0; } else { xend = 0; yend = 1; } color.flags = DoRed | DoGreen | DoBlue; XSetForeground(DisplayOfScreen(screen), gc, start.pixel); for (i = 0.0; i < dimension; i += inc) { if ((int)color.red != (int)red || (int)color.green != (int)green || (int)color.blue != (int)blue) { XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); color.red = (unsigned short)red; color.green = (unsigned short)green; color.blue = (unsigned short)blue; if (!XAllocColor(DisplayOfScreen(screen), colormap, &color)) { XFreePixmap(DisplayOfScreen(screen), pixmap); return (False); } XSetForeground(DisplayOfScreen(screen), gc, color.pixel); if (orientation == VERTICAL) y = yend; else x = xend; } red += ired; green += igreen; blue += iblue; if (orientation == VERTICAL) yend += inc; else xend += inc; } XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); *pixmap_return = pixmap; *mask_return = None; *width_return = orientation == VERTICAL ? 1 : dimension; *height_return = orientation == VERTICAL ? dimension : 1; XFreeGC(DisplayOfScreen(screen), gc); return (True); }
/*ARGSUSED*/ void XmuCvtStringToCursor(XrmValuePtr args, Cardinal *num_args, XrmValuePtr fromVal, XrmValuePtr toVal) { static Cursor cursor; /* static for cvt magic */ char *name = (char *)fromVal->addr; Screen *screen; register int i; char maskname[PATH_MAX]; Pixmap source, mask = 0; /* XXX - make fg/bg resources */ static XColor bgColor = {0, 0xffff, 0xffff, 0xffff}; static XColor fgColor = {0, 0, 0, 0}; int xhot, yhot; int len; if (*num_args != 1) XtErrorMsg("wrongParameters","cvtStringToCursor","XtToolkitError", "String to cursor conversion needs screen argument", (String *)NULL, (Cardinal *)NULL); if (XmuCompareISOLatin1(name, "None") == 0) { cursor = None; done(&cursor, Cursor); return; } screen = *((Screen **) args[0].addr); if (0 == strncmp(FONTSPECIFIER, name, strlen(FONTSPECIFIER))) { char source_name[PATH_MAX], mask_name[PATH_MAX]; int source_char, mask_char, fields = 0; Font source_font, mask_font; XrmValue fromString, toFont; XrmValue cvtArg; Boolean success; Display *dpy = DisplayOfScreen(screen); char *strspec = NULL; int strspeclen; #ifdef XMU_KLUDGE Cardinal num; #endif strspeclen = strlen("FONT %s %d %s %d") + 21; strspec = XtMalloc(strspeclen); if (strspec != NULL) { snprintf(strspec, strspeclen, "FONT %%%lds %%d %%%lds %%d", (unsigned long)sizeof(source_name) - 1, (unsigned long)sizeof(mask_name) - 1); fields = sscanf(name, strspec, source_name, &source_char, mask_name, &mask_char); XtFree(strspec); } if (fields < 2) { XtStringConversionWarning(name, XtRCursor); return; } fromString.addr = source_name; fromString.size = strlen(source_name) + 1; toFont.addr = (XPointer) &source_font; toFont.size = sizeof(Font); cvtArg.addr = (XPointer) &dpy; cvtArg.size = sizeof(Display *); /* XXX using display of screen argument as message display */ #ifdef XMU_KLUDGE /* XXX Sacrifice caching */ num = 1; success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString, &toFont, NULL); #else success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg, (Cardinal)1, &fromString, &toFont, NULL); #endif if (!success) { XtStringConversionWarning(name, XtRCursor); return; } switch (fields) { case 2: /* defaulted mask font & char */ mask_font = source_font; mask_char = source_char; break; case 3: /* defaulted mask font */ mask_font = source_font; mask_char = atoi(mask_name); break; case 4: /* specified mask font & char */ fromString.addr = mask_name; fromString.size = strlen(mask_name) + 1; toFont.addr = (XPointer) &mask_font; toFont.size = sizeof(Font); /* XXX using display of screen argument as message display */ #ifdef XMU_KLUDGE /* XXX Sacrifice caching */ num = 1; success = XtCvtStringToFont(dpy, &cvtArg, &num, &fromString, &toFont, NULL); #else success = XtCallConverter(dpy, XtCvtStringToFont, &cvtArg, (Cardinal)1, &fromString, &toFont, NULL); #endif if (!success) { XtStringConversionWarning(name, XtRCursor); return; } } cursor = XCreateGlyphCursor( DisplayOfScreen(screen), source_font, mask_font, source_char, mask_char, &fgColor, &bgColor ); done(&cursor, Cursor); return; } i = XmuCursorNameToIndex (name); if (i != -1) { cursor = XCreateFontCursor (DisplayOfScreen(screen), i); done(&cursor, Cursor); return; } if ((source = XmuLocateBitmapFile (screen, name, maskname, (sizeof maskname) - 4, NULL, NULL, &xhot, &yhot)) == None) { XtStringConversionWarning (name, XtRCursor); cursor = None; done(&cursor, Cursor); return; } len = strlen (maskname); for (i = 0; i < 2; i++) { strcpy (maskname + len, i == 0 ? "Mask" : "msk"); if ((mask = XmuLocateBitmapFile (screen, maskname, NULL, 0, NULL, NULL, NULL, NULL)) != None) break; } cursor = XCreatePixmapCursor( DisplayOfScreen(screen), source, mask, &fgColor, &bgColor, xhot, yhot ); XFreePixmap( DisplayOfScreen(screen), source ); if (mask != None) XFreePixmap( DisplayOfScreen(screen), mask ); done(&cursor, Cursor); }