Pixmap FindBitmap(char *name, unsigned int *widthp, unsigned int *heightp) { char *bigname; Pixmap pm; if (!name) return None; /* * Generate a full pathname if any special prefix characters (such as ~) * are used. If the bigname is different from name, bigname will need to * be freed. */ bigname = ExpandFilename(name); if (!bigname) return None; /* * look along bitmapFilePath resource same as toolkit clients */ pm = XmuLocateBitmapFile(ScreenOfDisplay(dpy, Scr->screen), bigname, NULL, 0, (int *)widthp, (int *)heightp, &HotX, &HotY); if (pm == None && Scr->IconDirectory && bigname[0] != '/') { if (bigname != name) free(bigname); /* * Attempt to find icon in old IconDirectory (now obsolete) */ bigname = (char *)malloc(strlen(name) + strlen(Scr->IconDirectory) + 2); if (!bigname) { fprintf(stderr, "%s: unable to allocate memory for \"%s/%s\"\n", ProgramName, Scr->IconDirectory, name); return None; } (void)sprintf(bigname, "%s/%s", Scr->IconDirectory, name); if (XReadBitmapFile(dpy, Scr->Root, bigname, widthp, heightp, &pm, &HotX, &HotY) != BitmapSuccess) { pm = None; } } if (bigname != name) free(bigname); #ifdef DEBUG if (pm == None) { fprintf(stderr, "%s: unable to find bitmap \"%s\"\n", ProgramName, name); } #endif return pm; }
IconRec readIcon(Widget shell, char *name) { Window win = DefaultRootWindow(dpy); Screen *scrn = XtScreen(shell); IconRec icon; char fullname[MAXPATHLEN]; int x, y; XpmAttributes attr; static XpmColorSymbol none_color = { NULL, "None", (Pixel) 0 }; none_color.pixel = winInfo.background; /* first search for xpm icons: */ attr.valuemask = XpmReturnPixels | XpmColorSymbols | XpmCloseness; attr.colorsymbols = &none_color; attr.numsymbols = 1; attr.closeness = CLOSENESS; if (XpmReadFileToPixmap(dpy, win, searchPath(fullname, resources.pixmap_path, name), &icon.bm, &icon.mask, &attr) == XpmSuccess) { icon.width = attr.width; icon.height = attr.height; return icon; } icon.mask = None; /* now search along *bitmapPath: */ if (XReadBitmapFile(dpy, win, searchPath(fullname, resources.bitmap_path, name), &attr.width, &attr.height, &icon.bm, &x, &y) == BitmapSuccess) { icon.width = attr.width; icon.height = attr.height; } /* finally search bitmap in standard locations (*bitmapFilePath): */ else icon.bm = XmuLocateBitmapFile(scrn, name, NULL, 0, (int *)&icon.width, (int *)&icon.height, &x, &y); return icon; }
/*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); }
/* ARGSUSED */ static Boolean _XawCvtStringToPixmap(Display *dpy, XrmValuePtr args, Cardinal *nargs, XrmValuePtr from, XrmValuePtr to, XtPointer *data) { static Pixmap pixmap; Window win; XpmAttributes attr; XpmColorSymbol colors[1]; if (*nargs != 3) XtAppErrorMsg(XtDisplayToApplicationContext(dpy), "_XawCvtStringToPixmap", "wrongParameters", "XtToolkitError", "_XawCvtStringToPixmap needs screen, colormap, and background_pixel", (String *) NULL, (Cardinal *) NULL); if (strcmp(from->addr, "None") == 0) { pixmap = None; DONE(Pixmap, &pixmap); return (True); } if (strcmp(from->addr, "ParentRelative") == 0) { pixmap = ParentRelative; DONE(Pixmap, &pixmap); return (True); } win = RootWindowOfScreen(*((Screen **) args[0].addr)); attr.colormap = *((Colormap *) args[1].addr); attr.closeness = 32768; /* might help on 8-bpp displays? */ attr.valuemask = XpmColormap | XpmCloseness; colors[0].name = NULL; colors[0].value = "none"; colors[0].pixel = *((Pixel *) args[2].addr); attr.colorsymbols = colors; attr.numsymbols = 1; attr.valuemask |= XpmColorSymbols; if (XpmReadFileToPixmap(dpy, win, (String) from->addr, &pixmap, NULL, &attr) != XpmSuccess) { if ((pixmap = XmuLocateBitmapFile(*((Screen **) args[0].addr), (char *)from->addr, NULL, 0, NULL, NULL, NULL, NULL)) == None) { XtDisplayStringConversionWarning(dpy, (String) from->addr, XtRPixmap); return (False); } } if (to->addr == NULL) to->addr = (XtPointer) & pixmap; else { if (to->size < sizeof(Pixmap)) { to->size = sizeof(Pixmap); XtDisplayStringConversionWarning(dpy, (String) from->addr, XtRPixmap); return (False); } *((Pixmap *) to->addr) = pixmap; } to->size = sizeof(Pixmap); return (True); }
_XvicImageSetStringCursor( XvicImageWidget iw, char *name) #endif /* _NO_PROTO */ { Display *dpy; char source_name[xvicPATH_MAX], mask_name[xvicPATH_MAX]; int source_char, mask_char, fields; Font source_font, mask_font; XrmValue fromString, toFont; Boolean success; #ifndef NO_XMU int i; unsigned int shape; Pixmap source, mask; int xhot, yhot; int len; #endif dpy = XtDisplay((Widget)iw); /* Check for font name/glyph index form */ if (strncmp(FONTSPECIFIER, name, strlen(FONTSPECIFIER)) == 0) { fields = sscanf(name, "FONT %s %d %s %d", source_name, &source_char, mask_name, &mask_char); if (fields < 2 || fields > 4) { XtAppWarningMsg(XtWidgetToApplicationContext((Widget)iw), "BadCursorString", "XvicImage", "XvicImageWidgetError", "Invalid format for Cursor string resource, cursor ignored", (String *)NULL, (Cardinal *)NULL); return; } fromString.addr = source_name; fromString.size = strlen(source_name) + 1; #if XtSpecificationRelease <= 4 XtConvert((Widget)iw, XtRString, &fromString, XtRFont, &toFont); success = (toFont.addr != NULL); if (success) source_font = *(Font *)toFont.addr; #else toFont.addr = (XtPointer) &source_font; toFont.size = sizeof(Font); success = XtConvertAndStore((Widget)iw, XtRString, &fromString, XtRFont, &toFont); #endif if (!success) { XtAppWarningMsg(XtWidgetToApplicationContext((Widget)iw), "BadCursorFont", "XvicImage", "XvicImageWidgetError", "Invalid font for Cursor string resource, cursor ignored", (String *)NULL, (Cardinal *)NULL); return; } switch (fields) { case 2: /* defaulted mask font & char */ mask_font = None; /* thus there is no mask, really */ mask_char = 0; 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; #if XtSpecificationRelease <= 4 XtConvert((Widget)iw, XtRString, &fromString, XtRFont, &toFont); success = (toFont.addr != NULL); if (success) mask_font = *(Font *)toFont.addr; #else toFont.addr = (XtPointer) &mask_font; toFont.size = sizeof(Font); success = XtConvertAndStore((Widget)iw, XtRString, &fromString, XtRFont, &toFont); #endif if (!success) { XtAppWarningMsg(XtWidgetToApplicationContext((Widget)iw), "BadCursorMaskFont", "XvicImage", "XvicImageWidgetError", "Invalid mask font for Cursor string resource, cursor ignored", (String *)NULL, (Cardinal *)NULL); return; } } _XvicImageSetGlyphCursor(iw, source_font, mask_font, source_char, mask_char); /*!!!! Do we need to free fonts here???? !!!!*/ return; } #ifdef NO_XMU if (strcmp(name, DEFAULT_CURSOR) == 0) { _XvicImageSetFontCursor(iw, DEFAULT_CURSOR_SHAPE); /* default value */ return; } XtAppWarningMsg(XtWidgetToApplicationContext((Widget)iw), "BadCursorString", "XvicImage", "XvicImageWidgetError", "Invalid format for Cursor string resource, cursor ignored", (String *)NULL, (Cardinal *)NULL); return; #else /* Xmu is available */ /* Check for cursor shape name */ shape = XmuCursorNameToIndex(name); if (shape != -1) { _XvicImageSetFontCursor(iw, shape); return; } /* Check for bitmap file name */ source = XmuLocateBitmapFile(XtScreen((Widget)iw), name, mask_name, (sizeof mask_name) - 4, NULL, NULL, &xhot, &yhot); if (source == None) { XtAppWarningMsg(XtWidgetToApplicationContext((Widget)iw), "BadCursorString", "XvicImage", "XvicImageWidgetError", "Invalid format for Cursor string resource, cursor ignored", (String *)NULL, (Cardinal *)NULL); return; } len = strlen (mask_name); for (i = 0; i < 2; i++) { strcpy (mask_name + len, i == 0 ? "Mask" : "msk"); mask = XmuLocateBitmapFile (XtScreen((Widget)iw), mask_name, NULL, 0, NULL, NULL, NULL, NULL); if (mask != None) break; } _XvicImageSetPixmapCursor(iw, source, mask, xhot, yhot); XFreePixmap(XtDisplay((Widget)iw), source); if (mask != None) XFreePixmap(XtDisplay((Widget)iw), mask); return; #endif }