XtPointer XmeTraitGet(XtPointer obj, XrmQuark name) { XtPointer trait; XmTraitEntryRec entry; entry.obj = obj; entry.name = name; _XmProcessLock(); trait = _XmGetHashEntry(TraitTable, &entry); _XmProcessUnlock(); return(trait); }
String XmGetIconFileName( Screen *screen, String imageInstanceName, String imageClassName, String hostPrefix, unsigned int size) { Display *display = DisplayOfScreen(screen); String fileName = NULL; String names[2]; String names_w_size[2]; XmConst char *bPath, *iPath; Cardinal i; Boolean useColor; Boolean useMask; Boolean useIconFileCache; Boolean absolute = 0; XtFilePredicate testFileFunc; String homedir = NULL ; static String iconPath = NULL; static String bmPath = NULL; static XmHashTable iconNameCache = NULL; char stackString[MAX_DIR_PATH_LEN]; #define B_SUB 0 #define P_SUB 1 #define M_SUB 2 #define H_SUB 3 SubstitutionRec iconSubs[] = { {'B', NULL}, /* bitmap name */ {'P', NULL}, /* alternate bitmap name BC */ {'M', NULL}, /* magnitude */ {'H', NULL}, /* host prefix */ }; XtAppContext app; app = XtDisplayToApplicationContext(display); _XmAppLock(app); /* start by asking some screen state */ (void)XmeGetIconControlInfo(screen, &useMask, /* not used here */ &useColor, &useIconFileCache); _XmProcessLock(); /* generate the icon paths once per application: iconPath and bmPath */ if (!iconNameCache) { Boolean junkBoolean; iconNameCache = _XmAllocHashTable(100, CompareIconNames, HashIconName); cacheList.numDirs = cacheList.maxDirs = 0; cacheList.dirs = NULL; homedir = XmeGetHomeDirName(); strcpy(stackString, homedir) ; if (useColor) { iconPath = _XmOSInitPath(NULL, "XMICONSEARCHPATH", &junkBoolean); } else { iconPath = _XmOSInitPath(NULL, "XMICONBMSEARCHPATH", &junkBoolean); } /* 1.2 path as a fallback */ bmPath = _XmOSInitPath(NULL, "XBMLANGPATH", &junkBoolean); } switch (size) { case XmTINY_ICON_SIZE: iconSubs[M_SUB].substitution = ".t"; break; case XmSMALL_ICON_SIZE: iconSubs[M_SUB].substitution = ".s"; break; case XmMEDIUM_ICON_SIZE: iconSubs[M_SUB].substitution = ".m"; break; case XmLARGE_ICON_SIZE: iconSubs[M_SUB].substitution = ".l"; break; case XmUNSPECIFIED_ICON_SIZE: iconSubs[M_SUB].substitution = NULL; break; } iconSubs[H_SUB].substitution = hostPrefix; if (useIconFileCache) testFileFunc = TestIconFile; else testFileFunc = NULL; names[0] = imageInstanceName; names[1] = imageClassName; names_w_size[0] = names_w_size[1] = (String)NULL; /** loop over the two names */ for (i = 0; i < 2; i++) { if (names[i] == NULL) continue; if ((absolute = _XmOSAbsolutePathName(names[i], &names[i], stackString)) != FALSE) { iPath = ABSOLUTE_IPATH; bPath = ABSOLUTE_PATH; } else { iPath = iconPath; bPath = bmPath; } iconSubs[B_SUB].substitution = names[i]; iconSubs[P_SUB].substitution = names[i]; /* need to add size suffix if size is specified */ if (size != XmUNSPECIFIED_ICON_SIZE) { int basenameLen = strlen(names[i]); int sizeLen = strlen(iconSubs[M_SUB].substitution); char * ext_name = XtMalloc(basenameLen + sizeLen + 1); /* XmosP.h takes care of bcopy translation */ memmove(&ext_name[0], names[i], basenameLen); memmove(&ext_name[basenameLen], iconSubs[M_SUB].substitution, sizeLen); ext_name[basenameLen + sizeLen] = '\0'; names_w_size[i] = ext_name; } else names_w_size[i] = NULL; /* * try to see if its already in the image cache */ if (_XmInImageCache(names[i])) fileName = XtNewString(names[i]); /* * optimization to check all expansions in cache */ if (!fileName) { DtIconNameEntry iNameEntry; DtIconNameEntryRec iNameData ; iNameData.key_name = (names_w_size[i])?names_w_size[i]:names[i]; iNameEntry = (DtIconNameEntry) _XmGetHashEntry(iconNameCache, (XmHashKey)&iNameData); if (iNameEntry) { int dirLen, leafLen; dirLen = strlen(iNameEntry->dirName); leafLen = strlen(iNameEntry->leafName); fileName = XtMalloc(dirLen + leafLen + 2); memmove(&fileName[0], iNameEntry->dirName, dirLen); #ifdef FIX_1427 if (dirLen == 0) { memmove(&fileName[dirLen], iNameEntry->leafName, leafLen); fileName[dirLen + leafLen] = '\0'; } else { #endif fileName[dirLen] = '/'; memmove(&fileName[dirLen + 1], iNameEntry->leafName, leafLen); fileName[dirLen + leafLen + 1] = '\0'; #ifdef FIX_1427 } #endif } } if (fileName) { /* * CDExc20823 (memory leak): free names_w_size[i] * if it is not NULL. * NOTE: This code could be reorganized to do * _XmInImageCache() at the top of this loop * so we could avoid unnecessary malloc's for * names_w_size, but I wanted to minimize the * code impact of this defect for now. */ for (i = 0; i < 2; i++) { if (names_w_size[i] != (String)NULL) XtFree(names_w_size[i]); } _XmProcessUnlock(); _XmAppUnlock(app); return fileName; } /******************************* * first try XPM and then XBM ******************************/ fileName = XtResolvePathname(display, "icons", NULL, NULL, iPath, iconSubs, XtNumber(iconSubs), (XtFilePredicate) testFileFunc); if (fileName == NULL) { fileName = XtResolvePathname(display, "bitmaps", NULL, NULL, bPath, iconSubs, XtNumber(iconSubs), (XtFilePredicate) testFileFunc); } if (fileName) break; } _XmProcessUnlock(); if (fileName && !absolute) { /* register it in name cache */ DtIconNameEntry iNameEntry; String name_used = (names_w_size[i])? names_w_size[i] : names[i] ; /** alloc a icon cache entry **/ iNameEntry = (DtIconNameEntry) XtMalloc(sizeof(DtIconNameEntryRec)); iNameEntry->key_name = XtNewString(name_used); #ifndef XTHREADS if (useIconFileCache) { iNameEntry->dirName = XtNewString(GdirName); iNameEntry->leafName = XtNewString(GleafName); } else #endif { String dirName; String filePtr; String suffixPtr; int dirNameLen; _XmOSFindPathParts(fileName, &filePtr, &suffixPtr); if (fileName == filePtr) dirNameLen = 0; else { /* take the slash into account */ dirNameLen = filePtr - fileName - 1; } dirName = (String)XtMalloc(dirNameLen + 1); strncpy(dirName, fileName, dirNameLen); dirName[dirNameLen] = '\0'; iNameEntry->dirName = dirName; iNameEntry->leafName = XtNewString(filePtr); } _XmProcessLock(); _XmAddHashEntry(iconNameCache, (XmHashKey)iNameEntry, (XtPointer)iNameEntry); _XmProcessUnlock(); } /* * CDExc20823 (memory leak): free names_w_size[i] if not NULL. */ for (i = 0; i < 2; i++) { if (names_w_size[i] != (String)NULL) XtFree(names_w_size[i]); } _XmAppUnlock(app); return fileName; }