// Return a database of default settings XrmDatabase app_defaults(Display *display) { static XrmDatabase db = NULL; if (db != NULL) return db; // Add builtin fallback defaults. int i = 0; while (ddd_fallback_resources[i] != 0) XrmPutLineResource(&db, ddd_fallback_resources[i++]); // Add app-defaults file, overriding fallback defaults. static String app_name = 0; static String app_class = 0; if (app_name == 0) XtGetApplicationNameAndClass(display, &app_name, &app_class); String app_defaults_file = XtResolvePathname(display, NULL, app_class, NULL, NULL, NULL, 0, NULL); if (app_defaults_file != NULL) { XrmDatabase db2 = XrmGetFileDatabase(app_defaults_file); if (db2 != 0) XrmMergeDatabases(db2, &db); } return db; }
// locate bitmap // this mimics XmGetPixmap's efforts to locate a path static String locateBitmap(Display *display, const _XtString basename) { SubstitutionRec subst; subst.match = 'B'; subst.substitution = CONST_CAST(char*,basename); return XtResolvePathname( display, // the display we use "bitmaps", // %T = bitmaps String(0), // %N = application class name "", // %S = "" (suffix) PATH.chars(), // path to use &subst, 1, // %B = basename XtFilePredicate(0)); // no checking for valid bitmap }
static void CombineAppUserDefaults( Display *dpy, XrmDatabase *pdb) { char* filename; char* path; Boolean deallocate = False; if (!(path = getenv("XUSERFILESEARCHPATH"))) { char *old_path; char homedir[PATH_MAX]; GetRootDirName(homedir, PATH_MAX); if (!(old_path = getenv("XAPPLRESDIR"))) { char *path_default = "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N"; if (!(path = ALLOCATE_LOCAL(6*strlen(homedir) + strlen(path_default)))) _XtAllocError(NULL); sprintf( path, path_default, homedir, homedir, homedir, homedir, homedir, homedir ); } else { char *path_default = "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N"; if (!(path = ALLOCATE_LOCAL( 6*strlen(old_path) + 2*strlen(homedir) + strlen(path_default)))) _XtAllocError(NULL); sprintf(path, path_default, old_path, old_path, old_path, homedir, old_path, old_path, old_path, homedir ); } deallocate = True; } filename = XtResolvePathname(dpy, NULL, NULL, NULL, path, NULL, 0, NULL); if (filename) { (void)XrmCombineFileDatabase(filename, pdb, False); XtFree(filename); } if (deallocate) DEALLOCATE_LOCAL(path); }
static void CombineAppUserDefaults( Display *dpy, XrmDatabase *pdb) { char* filename; char* path = NULL; Boolean deallocate = False; if (!(path = getenv("XUSERFILESEARCHPATH"))) { #if !defined(WIN32) || !defined(__MINGW32__) char *old_path; char homedir[PATH_MAX]; GetRootDirName(homedir, PATH_MAX); if (!(old_path = getenv("XAPPLRESDIR"))) { XtAsprintf(&path, "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N", homedir, homedir, homedir, homedir, homedir, homedir); } else { XtAsprintf(&path, "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N", old_path, old_path, old_path, homedir, old_path, old_path, old_path, homedir); } deallocate = True; #endif } filename = XtResolvePathname(dpy, NULL, NULL, NULL, path, NULL, 0, NULL); if (filename) { (void)XrmCombineFileDatabase(filename, pdb, False); XtFree(filename); } if (deallocate) XtFree(path); }
/* * Almost the same as XmGetPixmap() above, but this time the programmer can * even control the depth of the pixmap she/he wants. */ extern Pixmap XmGetPixmapByDepth(Screen *screen, char *image_name, Pixel foreground, Pixel background, int depth) { LTPixmapDescRec PixmapDesc; LTPixmapDesc PixmapValue; LTImageValue ImageDesc; int image_depth; char *pathname_to_pixmap; unsigned int bitmap_width, bitmap_height; int x_hot, y_hot; XImage *image; Pixmap new_pix, tmp, mask; GC gc; XGCValues values; #ifdef NONSTANDARD_CONVERTERS XpmColorSymbol xpm_colour_symbols[3]; XpmAttributes xpm_attrib; #endif /* NONSTANDARD_CONVERTERS */ values.foreground = foreground; values.background = background; if (PixmapCache == NULL) { LTSetupPixmapCache(); } if (image_name == NULL) { return XmUNSPECIFIED_PIXMAP; } /* * First, we check the pixmap cache to see if such a pixmap is already * there. Therefore we fill in a pixmap description but only use the * first set of fields in the description structure. The second set will * contain information about the pixmap, if a pixmap, as described by the * first set, is already in the cache. */ PixmapDesc.image_name = image_name; PixmapDesc.screen = screen; PixmapDesc.foreground = foreground; PixmapDesc.background = background; PixmapDesc.depth = depth; if (_LTHashTableLookupItem(PixmapCache, (LTHashItemID) & PixmapDesc, (LTHashItemValue *) & PixmapValue)) { /* * There's a pixmap in the cache so we use it and increment its * reference count. */ (PixmapValue->ref_count)++; #if 0 DEBUGOUT(_LtDebug0(__FILE__, NULL, "XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p, refcnt %d\n", screen, image_name, DisplayOfScreen(screen), foreground, background, depth, PixmapValue->pixmap, PixmapValue->ref_count)); #endif return PixmapValue->pixmap; } /* * Okay, we had no luck. Now check the image cache. */ ImageDesc = LTGetImageFromCache(image_name); if (ImageDesc != NULL) { /* * A match from the image cache. Now create the pixmap, add it to * the cache, and return it. */ image = ImageDesc->image; if (image->format == XYBitmap) { image_depth = 1; } else { image_depth = image->depth; } /* create the pixmap */ new_pix = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen), depth, image->width, image->height); tmp = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen), depth, image->width, image->height); gc = XCreateGC(DisplayOfScreen(screen), tmp, 0, NULL); /* move the image information into a temporary pixmap */ XPutImage(DisplayOfScreen(screen), tmp, gc, image, 0, 0, 0, 0, image->width, image->height); XFreeGC(DisplayOfScreen(screen), gc); values.foreground = background; values.background = foreground; gc = XCreateGC(DisplayOfScreen(screen), new_pix, GCForeground | GCBackground, &values); if (image_depth == 1) { XCopyPlane(DisplayOfScreen(screen), tmp, new_pix, gc, 0, 0, image->width, image->height, 0, 0, 1); } else { XCopyArea(DisplayOfScreen(screen), tmp, new_pix, gc, 0, 0, image->width, image->height, 0, 0); } XFreeGC(DisplayOfScreen(screen), gc); /* add the pixmap to the cache */ _LTAddPixmapToCache(image_name, new_pix, screen, foreground, background, depth, image->width, image->height, ImageDesc->hot_x, ImageDesc->hot_y); DEBUGOUT(_LtDebug0(__FILE__, NULL, "XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p new\n", screen, image_name, DisplayOfScreen(screen), foreground, background, depth, new_pix)); return new_pix; } /* since it wasn't in either cache, we search for the file */ /* make sure the search path is there */ if (!_search_path) { _LTCreateSearchPath(); } if (image_name[0] == '/') /* an absolute pathname */ { pathname_to_pixmap = XtNewString(image_name); } else { SubstitutionRec subs[1]; subs[0].match = 'B'; subs[0].substitution = XtNewString(image_name); pathname_to_pixmap = XtResolvePathname(DisplayOfScreen(screen), "bitmaps", NULL, NULL, _search_path, subs, 1, NULL); XtFree(subs[0].substitution); } /* this breaks if X isn't where it's supposed to be. Don't dump core, * just return */ if (pathname_to_pixmap == NULL || strlen(pathname_to_pixmap) == 0) { return XmUNSPECIFIED_PIXMAP; } DEBUGOUT(_LtDebug(__FILE__, NULL, "pathname found is %s\n", pathname_to_pixmap)); /* * For 1.2 converting XPMs to pixmaps is an extension (standard * Motif dosen't read XPMs until version 2) so only do it if * NONSTANDARD_CONVERTERS is defined */ #ifdef NONSTANDARD_CONVERTERS /* Try for an XPM file, then a bitmap */ /* Set up symbolic names for foreground & background colours */ xpm_colour_symbols[0].name = "background"; xpm_colour_symbols[0].value = 0; xpm_colour_symbols[0].pixel = background ; xpm_colour_symbols[1].name = "foreground"; xpm_colour_symbols[1].value = 0; xpm_colour_symbols[1].pixel = foreground ; xpm_colour_symbols[2].name = NULL; xpm_colour_symbols[2].value = "None"; xpm_colour_symbols[2].pixel = background ; xpm_attrib.colorsymbols = xpm_colour_symbols; xpm_attrib.numsymbols = XtNumber(xpm_colour_symbols); xpm_attrib.depth = depth; xpm_attrib.closeness = 40000; xpm_attrib.valuemask = ( XpmSize | XpmReturnPixels | XpmColorSymbols | XpmCloseness | XpmDepth ); if (XpmReadFileToPixmap(DisplayOfScreen(screen), RootWindowOfScreen(screen), pathname_to_pixmap, &new_pix, &mask, &xpm_attrib) == XpmSuccess) { /* add the pixmap to the cache */ _LTAddPixmapToCache(image_name, new_pix, screen, foreground, background, depth, xpm_attrib.width, xpm_attrib.height, xpm_attrib.x_hotspot, xpm_attrib.y_hotspot); } else #endif /* NONSTANDARD_CONVERTERS */ if (XReadBitmapFile(DisplayOfScreen(screen), RootWindowOfScreen(screen), pathname_to_pixmap, &bitmap_width, &bitmap_height, &tmp, &x_hot, &y_hot) == BitmapSuccess) { new_pix = _XmAllocScratchPixmap((XmScreen)XmGetXmScreen(screen), depth, bitmap_width, bitmap_height); gc = XCreateGC(DisplayOfScreen(screen), new_pix, GCForeground | GCBackground, &values); XCopyPlane(DisplayOfScreen(screen), tmp, new_pix, gc, 0, 0, bitmap_width, bitmap_height, 0, 0, 1); XFreeGC(DisplayOfScreen(screen), gc); /* add the pixmap to the cache */ _LTAddPixmapToCache(image_name, new_pix, screen, foreground, background, depth, bitmap_width, bitmap_height, 0, 0 /* FIX ME! hot_x, hot_y! */ ); } else { _XmWarning(NULL, "Couldn't load the pixmap %s.\n", pathname_to_pixmap); new_pix = XmUNSPECIFIED_PIXMAP; } XtFree(pathname_to_pixmap); DEBUGOUT(_LtDebug0(__FILE__, NULL, "XmGetPixmapByDepth(scr %p, %s, dpy %p, fg %p, bg %p, d %d) -> %p new2\n", screen, image_name, DisplayOfScreen(screen), foreground, background, depth, new_pix)); return new_pix; }
XrmDatabase XtScreenDatabase( Screen *screen) { int scrno; Bool doing_def; XrmDatabase db, olddb; XtPerDisplay pd; Status do_fallback; char *scr_resources; Display *dpy = DisplayOfScreen(screen); DPY_TO_APPCON(dpy); LOCK_APP(app); LOCK_PROCESS; if (screen == DefaultScreenOfDisplay(dpy)) { scrno = DefaultScreen(dpy); doing_def = True; } else { scrno = XScreenNumberOfScreen(screen); doing_def = False; } pd = _XtGetPerDisplay(dpy); if ((db = pd->per_screen_db[scrno])) { UNLOCK_PROCESS; UNLOCK_APP(app); return (doing_def ? XrmGetDatabase(dpy) : db); } scr_resources = XScreenResourceString(screen); if (ScreenCount(dpy) == 1) { db = pd->cmd_db; pd->cmd_db = NULL; } else { db = CopyDB(pd->cmd_db); } { /* Environment defaults */ char filenamebuf[PATH_MAX]; char *filename; if (!(filename = getenv("XENVIRONMENT"))) { int len; #ifdef __MINGW32__ const char *slashDotXdefaultsDash = "/Xdefaults-"; #else const char *slashDotXdefaultsDash = "/.Xdefaults-"; #endif (void) GetRootDirName(filename = filenamebuf, PATH_MAX - strlen (slashDotXdefaultsDash) - 1); (void) strcat(filename, slashDotXdefaultsDash); len = strlen(filename); GetHostname (filename+len, PATH_MAX-len); } (void)XrmCombineFileDatabase(filename, &db, False); } if (scr_resources) { /* Screen defaults */ XrmCombineDatabase(XrmGetStringDatabase(scr_resources), &db, False); XFree(scr_resources); } /* Server or host defaults */ if (!pd->server_db) CombineUserDefaults(dpy, &db); else { (void) XrmCombineDatabase(pd->server_db, &db, False); pd->server_db = NULL; } if (!db) db = XrmGetStringDatabase(""); pd->per_screen_db[scrno] = db; olddb = XrmGetDatabase(dpy); /* set database now, for XtResolvePathname to use */ XrmSetDatabase(dpy, db); CombineAppUserDefaults(dpy, &db); do_fallback = 1; { /* System app-defaults */ char *filename; if ((filename = XtResolvePathname(dpy, "app-defaults", NULL, NULL, NULL, NULL, 0, NULL))) { do_fallback = !XrmCombineFileDatabase(filename, &db, False); XtFree(filename); } } /* now restore old database, if need be */ if (!doing_def) XrmSetDatabase(dpy, olddb); if (do_fallback && pd->appContext->fallback_resources) { /* Fallback defaults */ XrmDatabase fdb = NULL; String *res; for (res = pd->appContext->fallback_resources; *res; res++) XrmPutLineResource(&fdb, *res); (void)XrmCombineDatabase(fdb, &db, False); } UNLOCK_PROCESS; UNLOCK_APP(app); return db; }
static Boolean create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen) { static Boolean first_time = True; static Window rootWindow; static XpmColorSymbol color[5] = { {"none", "none", 0}, {"iconColor1", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"selectColor", NULL, 0} }; static int screenNum; static Pixmap tools_map; static Pixmap tools_mask; static Pixmap shade_map; static Pixmap shade_mask; int status = 0; XpmAttributes attr; Pixmap map; Pixmap mask; static String pixmap_file_path = NULL; /* note: never free()d */ ASSERT(iconidx >= 0, "index must be positive"); if (first_time) { /* FIXME: We use a dummy window here to get the correct depth/visual for the pixmap creation (cant use globals.widgets.top_level since it's not realized yet and realizing it now would result in wrong dimensions) ... */ Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, XtNdepth, G_depth, XtNvisual, G_visual, XtNcolormap, G_colormap, XtNmappedWhenManaged, False, NULL); XtRealizeWidget(dummy); /* note: doesn't pop it up */ rootWindow = XtWindow(dummy); screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level)); ASSERT(rootWindow != 0, ""); XtVaGetValues(parent, XmNbackground, &color[BACKGROUND].pixel, XmNforeground, &color[FOREGROUND].pixel, XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel, XmNtopShadowColor, &color[TOP_SHADOW].pixel, XmNhighlightColor, &color[HIGHLIGHT].pixel, NULL); /* try to locate the XPM file with the toolbar pixmaps */ pixmap_file_path = XtResolvePathname(DISP, "pixmaps", resource.toolbar_pixmap_file, (String)NULL, /* suffix */ (String)NULL, /* use default path */ (Substitution)NULL, /* substitutions */ 0, /* number of substitutions */ (XtFilePredicate)NULL); /* return True iff file exists */ TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file, kpse_program_text_format, 0); TRACE_GUI((stderr, "pixmap file search via kpse_find_file: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap.")); } } } /* Setup the color subsititution table */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; /* Create the "sensitive" pixmap */ if (!tools_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &tools_map, &tools_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &tools_map, &tools_mask, &attr); } } else status = XpmSuccess; map = tools_map; mask = tools_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } XpmFreeAttributes(&attr); if (map != 0) { static GC back_gc, bots_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[BACKGROUND].pixel; back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); gcvalues.foreground = color[BOTTOM_SHADOW].pixel; bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); /* Create the "sensitive" pixmap. */ *sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx != -1) XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); else XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); /* Create the "insensitive" pixmap. */ if (insen != NULL) { Pixmap map; Pixmap mask; attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.color_key = XPM_MONO; attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; if (!shade_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &shade_map, &shade_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &shade_map, &shade_mask, &attr); } } else status = XpmSuccess; map = shade_map; mask = shade_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } if (mask != 0) { static GC tops_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[TOP_SHADOW].pixel; tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask); XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1); *insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1, PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); } XpmFreeAttributes(&attr); } } first_time = False; return True; }
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; }
static int check_xkeysymdb(Display *display, bool verbose) { if (verbose) { (void) xlibdir(display, verbose); } if (verbose) { std::cout << "Checking for XKeysymDB... "; std::cout.flush(); } String me, my_class; XtGetApplicationNameAndClass(display, &me, &my_class); string xkeysymdb; { const _XtString s = getenv("XKEYSYMDB"); if (s != 0) xkeysymdb = s; } if (xkeysymdb.empty()) { String s = XtResolvePathname(display, "", "XKeysymDB", "", (String)0, Substitution(0), 0, XtFilePredicate(0)); if (s != 0) xkeysymdb = s; XtFree(s); } if (!xkeysymdb.empty()) { if (verbose) { std::cout << xkeysymdb << "\n"; std::cout.flush(); } // Fix it now static string env; env = "XKEYSYMDB=" + xkeysymdb; putenv(CONST_CAST(char*,env.chars())); return 0; // Okay } if (xlibdir(display) != 0) { string path = string(xlibdir(display)) + "/XKeysymDB"; if (is_file(path)) { if (verbose) { std::cout << path << "\n" << "Note: this is not the default path compiled into " << me << ".\n" << " To avoid having " << me << " determine this setting each time it is started,\n" << " please set the XKEYSYMDB " << "environment variable to\n" << " " << quote(path) << ".\n"; std::cout.flush(); } // Fix it static string env; env = "XKEYSYMDB=" + path; putenv(CONST_CAST(char*,env.chars())); return 0; } }