// we use logo.xpm as the Application icon void setIcon (void) { int rv; Pixmap pixmap = 0; Pixmap mask = 0; XpmAttributes attrib; XWMHints *h = XGetWMHints (dpy, aboutWindow); XWMHints wm_hints; Bool got_hints = h != 0; attrib.valuemask = 0; rv = XCreatePixmapFromData (dpy, aboutWindow, about_icon_xpm, &pixmap, &mask, &attrib); if (rv != XpmSuccess) { fprintf (stderr, "Failed to read xpm file: %s\n", XpmGetErrorString (rv)); return; } if (!got_hints) { h = &wm_hints; h->flags = 0; } h->icon_pixmap = pixmap; h->icon_mask = mask; h->flags |= IconPixmapHint | IconMaskHint; XSetWMHints (dpy, aboutWindow, h); if (got_hints) XFree ((char *) h); }
static ani_image *name2image(Widget w, char *name) { XpmAttributes xa; ani_image *i; int err; char b[1024]; char tmpfile[1024]; Display *display = XtDisplay(w); Window ani_win = XRootWindowOfScreen(XtScreen(w)); static char *mowitz_data; if (!mowitz_data) mowitz_data = getenv("MOWITZ_DATA"); if (!mowitz_data) mowitz_data = MOWITZ_DATA; if (!XtIsRealized(w)) return NULL; #if 0 /* FIXME */ sprintf(tmpfile, "%s/siagimage.xpm", siag_tmpdir); #else sprintf(tmpfile, "%s/siagimage.xpm", "/tmp"); #endif if (!name) return NULL; for (i = i_list; i; i = i->next) { if (!strcmp(name, i->filename)) return i; } /* didn't find it; try loading */ sprintf(b, "%s/any2xpm %s > %s", mowitz_data, name, tmpfile); system(b); i = (ani_image *)MwMalloc(sizeof(ani_image)); xa.closeness = 40000; xa.exactColors = FALSE; xa.valuemask = XpmCloseness | XpmExactColors; err = XpmReadFileToPixmap(display, ani_win, tmpfile, &(i->pixmap), &(i->mask), &xa); if (err != XpmSuccess) { MwFree(i); fprintf(stderr, "XpmReadFileToPixmap returns %s\n", XpmGetErrorString(err)); return NULL; } remove(tmpfile); i->filename = MwStrdup(name); i->next = i_list; i_list = i; return i; }
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; }