//========================================= // CreateCursorFromName //----------------------------------------- Cursor CreateCursorFromName(Display* dpy, const char* name) { XColor fg, bg; int i; Font fid; char* fore_color = NULL; char* back_color = NULL; fg = NameToXColor(dpy, fore_color, BlackPixel(dpy, screen)); bg = NameToXColor(dpy, back_color, WhitePixel(dpy, screen)); i = XmuCursorNameToIndex(name); if (i == -1) return (Cursor) 0; fid = XLoadFont (dpy, "cursor"); if (!fid) return (Cursor) 0; return XCreateGlyphCursor(dpy, fid, fid, i, i+1, &fg, &bg); }
//========================================= // CreateCursorFromName //----------------------------------------- Cursor CreateCursorFromName (Display* dpy,char *name) { XColor fg, bg; int i; Font fid; fg = NameToXColor (dpy,fore_color, BlackPixel(dpy, screen)); bg = NameToXColor (dpy,back_color, WhitePixel(dpy, screen)); #if 0 if (reverse) { temp = fg; fg = bg; bg = temp; } #endif i = XmuCursorNameToIndex (name); if (i == -1) return (Cursor) 0; fid = XLoadFont (dpy, "cursor"); if (!fid) return (Cursor) 0; return XCreateGlyphCursor ( dpy, fid, fid, i, i+1, &fg, &bg ); }
/*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); }
_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 }