[comp.windows.x] String to Pixmap Converter

ebina@URBANA.MCD.MOT.COM (Eric Bina) (06/06/90)

Well, I finally got tired of having this nice backgroundPixmap resource
that all my widgets inherit, and none of them use.

The following stuff is for a StringToPixmap converter which goes in libXmu
The converter assumes the string is a file name, and will look in all the
places that the current StringToBitmap converter looks to find the pixmap file.

The converter will read bitmap files in XBM format, and pixmap files in XPM
format.  I realize that is no standard for pixmap formats, but it is easy
to use your own favorite by replacing RdPixF.c with a function to read your
own pixmap format.

The Converter adds 2 new modules to libXmu:
RdPixF.c	A XmuReadPixmapFile routine for XPM format pixmap files.
		(pretty much straight from contrib/xpm.tar.Z)
StrToPmap.c	The actual converter.
		(Almost an exact copy of StrToBmap.c)

The Converter modifies 1 module and 2 header files in libXmu:
LocBitmap.c	A minor change to XmuLocatePixmapFile to have it call
		XmuReadPixmapFile.
Drawing.h	Declaration of the XmuReadPixmapFile function call, and
		some defines to support XPM format.
Converters.h	Declaration of the XmuCvtStringToPixmap function call.

As you can see, I pretty much just put together stuff that already existed
in a way I found useful. I hope someone else finds it useful as well.

Here is a sample code fragment that installs the converter immediately after
opening the display so that it will be available to all widgets later created.

/***Start Sample Code Fragment***/

XtAppContext	app;
Display		*dpy;
Screen		*screen
static XtConvertArgRec screenConvertArg[1];

main(argc, argv)
int argc;
char **argv;
{
	XtToolkitInitialize();
	app = XtCreateApplicationContext();
	dpy = XtOpenDisplay (app, NULL, "xsample", "XSample",
		NULL, 0, &argc, argv);
	screen = DefaultScreenOfDisplay(dpy);
	screenConvertArg[0].address_mode = XtAddress;
	screenConvertArg[0].address_id = (caddr_t)&screen;
	screenConvertArg[0].size = sizeof(Screen *);
	XtAppAddConverter(app, XtRString, XtRPixmap, XmuCvtStringToPixmap,
		screenConvertArg, XtNumber(screenConvertArg));

/* Go on to create your top level shell and widget tree */
/***End Sample Code Fragment***/


SHAR FILE OF LIBXMU MODULES ADDED/CHANGED
---- cut here ----
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Converters.h Drawing.h LocBitmap.c RdPixF.c StrToPmap.c
# Wrapped by ebina@ixch on Tue Jun  5 23:47:21 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Converters.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Converters.h'\"
else
echo shar: Extracting \"'Converters.h'\" \(6693 characters\)
sed "s/^X//" >'Converters.h' <<'END_OF_FILE'
X/*
X * $XConsortium: Converters.h,v 1.7 90/04/13 16:22:30 jim Exp $
X *
X * Copyright 1988 by the Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided 
X * that the above copyright notice appear in all copies and that both that 
X * copyright notice and this permission notice appear in supporting 
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific, 
X * written prior permission. M.I.T. makes no representations about the 
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * The X Window System is a Trademark of MIT.
X *
X * The interfaces described by this header file are for miscellaneous utilities
X * and are not part of the Xlib standard.
X */
X
X#ifndef _XMU_STRCONVERT_H_
X#define _XMU_STRCONVERT_H_
X
X#ifdef __cplusplus			/* do not leave open across includes */
Xextern "C" {					/* for C++ V2.0 */
X#endif
X
X/*
X * Converters - insert in alphabetical order
X */
X
X/******************************************************************************
X * XmuCvtFunctionToCallback
X */
Xextern void XmuCvtFunctionToCallback(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToBackingStore
X */
X#define XtNbackingStore "backingStore"
X#define XtCBackingStore "BackingStore"
X#define XtRBackingStore "BackingStore"
X#define XtEnotUseful "notUseful"
X#define XtEwhenMapped "whenMapped"
X#define XtEalways "always"
X#define XtEdefault "default"
Xextern void XmuCvtStringToBackingStore(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToCursor
X */
Xextern void XmuCvtStringToCursor(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
Xextern Boolean XmuCvtStringToColorCursor(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */,
X    XtPointer*		/* converter_data */
X#endif
X);
X
X#define XtRColorCursor "ColorCursor"
X#define XtNpointerColor "pointerColor"
X#define XtNpointerColorBackground "pointerColorBackground"
X
X
X/******************************************************************************
X * XmuCvtStringToGravity
X */
Xtypedef int XtGravity;
X
X#define XtRGravity "Gravity"
X#define XtEForget "forget"
X#define XtENorthWest "northwest"
X#define XtENorth "north"
X#define XtENorthEast "northeast"
X#define XtEWest "west"
X#define XtECenter "center"
X#define XtEEast "east"
X#define XtESouthWest "southwest"
X#define XtESouth "south"
X#define XtESouthEast "southeast"
X#define XtEStatic "static"
X#define XtEUnmap "unmap"
X
Xextern void XmuCvtStringToGravity (
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToJustify
X */
Xtypedef enum {
X    XtJustifyLeft,       /* justify text to left side of button   */
X    XtJustifyCenter,     /* justify text in center of button      */
X    XtJustifyRight       /* justify text to right side of button  */
X} XtJustify;
X#define XtEleft "left"
X#define XtEcenter "center"
X#define XtEright "right"
X#define XtEtop "top"
X#define XtEbottom "bottom"
X
Xextern void XmuCvtStringToJustify(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToLong
X */
X#define XtRLong "Long"
Xextern void XmuCvtStringToLong(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToOrientation
X */
Xtypedef enum {XtorientHorizontal, XtorientVertical} XtOrientation;
Xextern void XmuCvtStringToOrientation(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToBitmap
X */
Xextern void XmuCvtStringToBitmap(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToPixmap
X */
Xextern void XmuCvtStringToPixmap(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToShapeStyle; is XtTypeConverter (i.e. new style)
X * no conversion arguments, not particularly useful to cache the results.
X */
X
X#define XtRShapeStyle "ShapeStyle"
X#define XtERectangle "Rectangle"
X#define XtEOval "Oval"
X#define XtEEllipse "Ellipse"
X#define XtERoundedRectangle "RoundedRectangle"
X
X#define XmuShapeRectangle 1
X#define XmuShapeOval 2
X#define XmuShapeEllipse 3
X#define XmuShapeRoundedRectangle 4
X
Xextern Boolean XmuCvtStringToShapeStyle(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */,
X    XtPointer*		/* converter_data */
X#endif
X);
X
Xextern Boolean XmuReshapeWidget(
X#if NeedFunctionPrototypes
X    Widget	/* w */,
X    int		/* shape_style */,
X    int		/* corner_width */,
X    int		/* corner_height */
X#endif
X);
X
X/******************************************************************************
X * XmuCvtStringToWidget
X */
Xextern void XmuCvtStringToWidget(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X#ifdef __cplusplus
X}						/* for C++ V2.0 */
X#endif
X
X#endif /* _XMU_STRCONVERT_H_ */
END_OF_FILE
if test 6693 -ne `wc -c <'Converters.h'`; then
    echo shar: \"'Converters.h'\" unpacked with wrong size!
fi
# end of 'Converters.h'
fi
if test -f 'Drawing.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Drawing.h'\"
else
echo shar: Extracting \"'Drawing.h'\" \(4778 characters\)
sed "s/^X//" >'Drawing.h' <<'END_OF_FILE'
X/*
X * $XConsortium: Drawing.h,v 1.7 90/04/03 09:42:31 swick Exp $
X *
X * Copyright 1988 by the Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided 
X * that the above copyright notice appear in all copies and that both that 
X * copyright notice and this permission notice appear in supporting 
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific, 
X * written prior permission. M.I.T. makes no representations about the 
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * The X Window System is a Trademark of MIT.
X *
X * The interfaces described by this header file are for miscellaneous utilities
X * and are not part of the Xlib standard.
X */
X
X#ifndef _XMU_DRAWING_H_
X#define _XMU_DRAWING_H_
X
X#if NeedFunctionPrototypes
X#include <stdio.h>
X#if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
Xtypedef unsigned long Pixel;
X#endif
X#endif
X
X#ifdef __cplusplus			/* do not leave open across includes */
Xextern "C" {					/* for C++ V2.0 */
X#endif
X
Xvoid XmuDrawRoundedRectangle(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* draw */,
X    GC 		/* gc */,
X    int		/* x */,
X    int		/* y */,
X    int		/* w */,
X    int		/* h */,
X    int		/* ew */,
X    int		/* eh */
X#endif
X);
X
Xvoid XmuFillRoundedRectangle(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* draw */,
X    GC 		/* gc */,
X    int		/* x */,
X    int		/* y */,
X    int		/* w */,
X    int		/* h */,
X    int		/* ew */,
X    int		/* eh */
X#endif
X);
X
Xvoid XmuDrawLogo(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* drawable */,
X    GC		/* gcFore */,
X    GC		/* gcBack */,
X    int		/* x */,
X    int		/* y */,
X    unsigned int /* width */,
X    unsigned int /* height */
X#endif
X);
X
XPixmap XmuCreatePixmapFromBitmap(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    Drawable 		/* d */,
X    Pixmap 		/* bitmap */,
X    unsigned int	/* width */,
X    unsigned int	/* height */,
X    unsigned int	/* depth */,
X    unsigned long	/* fore */,
X    unsigned long	/* back */
X#endif
X);
X
XPixmap XmuCreateStippledPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    Pixel		/* fore */,
X    Pixel		/* back */,
X    unsigned int	/* depth */
X#endif
X);
X
Xvoid XmuReleaseStippledPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    Pixmap 		/* pixmap */
X#endif
X);
X
XPixmap XtGrayPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */
X#endif
X);
X
XPixmap XmuLocateBitmapFile(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    char*		/* name */,
X    char*		/* srcname_return */,
X    int 		/* srcnamelen */,
X    int*		/* width_return */,
X    int*		/* height_return, */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
XPixmap XmuLocatePixmapFile(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    char*		/* name */,
X    unsigned long	/* fore */,
X    unsigned long	/* back */,
X    unsigned int	/* depth */,
X    char*		/* srcname_return */,
X    int 		/* srcnamelen */,
X    int*		/* width_return */,
X    int*		/* height_return, */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
Xint XmuReadBitmapData(
X#if NeedFunctionPrototypes
X    FILE*		/* fstream */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    unsigned char**	/* datap_return */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
Xint XmuReadBitmapDataFromFile(
X#if NeedFunctionPrototypes
X    char*		/* filename */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    unsigned char**	/* datap_return */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
X/**** XmuReadPixmapFile **********************
X * stuff for xpm as a standard pixmap format *
X *********************************************/
Xint XmuReadPixmapFile(
X#if NeedFunctionPrototypes
X    Display*		/* display */,
X    Drawable		/* drawable */,
X    Colormap		/* Colormap */,
X    char*		/* filename */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    int			/* depth */,
X    Pixmap*		/* pixmap_return */
X#endif
X);
X
X#define XPM_FORMAT 1
X
X/* we keep the same codes as for Bitmap management */
X#ifndef _XUTIL_H_
X#include <X11/Xutil.h>
X#endif
X#define PixmapSuccess        BitmapSuccess 
X#define PixmapOpenFailed     BitmapOpenFailed
X#define PixmapFileInvalid    BitmapFileInvalid
X#define PixmapNoMemory       BitmapNoMemory
X/*********************************************/
X
X#ifdef __cplusplus
X}						/* for C++ V2.0 */
X#endif
X
X#endif /* _XMU_DRAWING_H_ */
END_OF_FILE
if test 4778 -ne `wc -c <'Drawing.h'`; then
    echo shar: \"'Drawing.h'\" unpacked with wrong size!
fi
# end of 'Drawing.h'
fi
if test -f 'LocBitmap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'LocBitmap.c'\"
else
echo shar: Extracting \"'LocBitmap.c'\" \(6509 characters\)
sed "s/^X//" >'LocBitmap.c' <<'END_OF_FILE'
X/*
X * $XConsortium: LocBitmap.c,v 1.6 90/03/23 11:09:29 rws Exp $
X *
X * Copyright 1989 Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific,
X * written prior permission.  M.I.T. makes no representations about the
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X * Author:  Jim Fulton, MIT X Consortium
X */
X
X#include <X11/Xlib.h>
X#include <X11/Xresource.h>
X#include <X11/Xutil.h>
X#include <X11/StringDefs.h>
X#include <sys/param.h>			/* get MAXPATHLEN if possible */
X#ifndef MAXPATHLEN
X#define MAXPATHLEN 256
X#endif
X#include <X11/Xmu/CvtCache.h>
X#include <X11/Xmu/Drawing.h>
X
X
X/*
X * XmuLocateBitmapFile - read a bitmap file using the normal defaults
X */
X
XPixmap XmuLocateBitmapFile (screen, name, srcname, srcnamelen,
X			    widthp, heightp, xhotp, yhotp)
X    Screen *screen;
X    char *name;
X    char *srcname;			/* RETURN */
X    int srcnamelen;
X    int *widthp, *heightp, *xhotp, *yhotp;  /* RETURN */
X{
X    return XmuLocatePixmapFile (screen, name, 
X				(unsigned long) 1, (unsigned long) 0,
X				(unsigned int) 1, srcname, srcnamelen,
X				widthp, heightp, xhotp, yhotp);
X}
X
X
X/*
X * version that reads pixmap data as well as bitmap data
X */
XPixmap XmuLocatePixmapFile (screen, name, fore, back, depth, 
X			    srcname, srcnamelen,
X			    widthp, heightp, xhotp, yhotp)
X    Screen *screen;
X    char *name;
X    unsigned long fore, back;
X    unsigned int depth;
X    char *srcname;			/* RETURN */
X    int srcnamelen;
X    int *widthp, *heightp, *xhotp, *yhotp;  /* RETURN */
X{
X    Display *dpy = DisplayOfScreen (screen);
X    Window root = RootWindowOfScreen (screen);
X    Bool try_plain_name = True;
X    XmuCvtCache *cache = _XmuCCLookupDisplay (dpy);
X    char **file_paths;
X    char filename[MAXPATHLEN];
X    unsigned int width, height;
X    int xhot, yhot;
X    int i;
X    static char **split_path_string();
X
X
X    /*
X     * look in cache for bitmap path
X     */
X    if (cache) {
X	if (!cache->string_to_bitmap.bitmapFilePath) {
X	    XrmName xrm_name[2];
X	    XrmClass xrm_class[2];
X	    XrmRepresentation rep_type;
X	    XrmValue value;
X
X	    xrm_name[0] = XrmStringToName ("bitmapFilePath");
X	    xrm_name[1] = NULL;
X	    xrm_class[0] = XrmStringToClass ("BitmapFilePath");
X	    xrm_class[1] = NULL;
X	    /*
X	     * XXX - warning, derefing Display * until XDisplayDatabase
X	     */
X	    if (!dpy->db) {
X		/* what a hack; need to initialize dpy->db */
X		(void) XGetDefault (dpy, "", "");
X	    }
X	    if (XrmQGetResource (dpy->db, xrm_name, xrm_class, 
X				 &rep_type, &value) &&
X		rep_type == XrmStringToQuark(XtRString)) {
X		cache->string_to_bitmap.bitmapFilePath = 
X		  split_path_string (value.addr);
X	    }
X	}
X	file_paths = cache->string_to_bitmap.bitmapFilePath;
X    }
X
X
X    /*
X     * Search order:
X     *    1.  name if it begins with / or ./
X     *    2.  "each prefix in file_paths"/name
X     *    3.  BITMAPDIR/name
X     *    4.  name if didn't begin with / or .
X     */
X
X#ifndef BITMAPDIR
X#define BITMAPDIR "/usr/include/X11/bitmaps"
X#endif
X
X    for (i = 1; i <= 4; i++) {
X	char *fn = filename;
X	Pixmap pixmap;
X	unsigned char *data;
X
X	switch (i) {
X	  case 1:
X	    if (!(name[0] == '/' || (name[0] == '.') && name[1] == '/')) 
X	      continue;
X	    fn = name;
X	    try_plain_name = False;
X	    break;
X	  case 2:
X	    if (file_paths && *file_paths) {
X		sprintf (filename, "%s/%s", *file_paths, name);
X		file_paths++;
X		i--;
X		break;
X	    }
X	    continue;
X	  case 3:
X	    sprintf (filename, "%s/%s", BITMAPDIR, name);
X	    break;
X	  case 4:
X	    if (!try_plain_name) continue;
X	    fn = name;
X	    break;
X	}
X
X	data = NULL;
X	pixmap = None;
X	if (XmuReadBitmapDataFromFile (fn, &width, &height, &data,
X				       &xhot, &yhot) == BitmapSuccess) {
X	    pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data,
X						  width, height,
X						  fore, back, depth);
X	    XFree ((char *)data);
X	}
X	else if (XmuReadPixmapFile (dpy, root,
X			DefaultColormap(dpy, DefaultScreen(dpy)), fn,
X			&width, &height, depth, &pixmap) == PixmapSuccess) {
X	    xhot = yhot = 0;
X	}
X
X	if (pixmap) {
X	    if (widthp) *widthp = (int)width;
X	    if (heightp) *heightp = (int)height;
X	    if (xhotp) *xhotp = xhot;
X	    if (yhotp) *yhotp = yhot;
X	    if (srcname && srcnamelen > 0) {
X		strncpy (srcname, fn, srcnamelen - 1);
X		srcname[srcnamelen - 1] = '\0';
X	    }
X	    return pixmap;
X	}
X    }
X
X    return None;
X}
X
X
X/*
X * split_path_string - split a colon-separated list into its constituent
X * parts; to release, free list[0] and list.
X */
Xstatic char **split_path_string (src)
X    register char *src;
X{
X    int nelems = 1;
X    register char *dst;
X    char **elemlist, **elem;
X
X    /* count the number of elements */
X    for (dst = src; *dst; dst++) if (*dst == ':') nelems++;
X
X    /* get memory for everything */
X    dst = (char *) malloc (dst - src + 1);
X    if (!dst) return NULL;
X    elemlist = (char **) calloc ((nelems + 1), sizeof (char *));
X    if (!elemlist) {
X	free (dst);
X	return NULL;
X    }
X
X    /* copy to new list and walk up nulling colons and setting list pointers */
X    strcpy (dst, src);
X    for (elem = elemlist, src = dst; *src; src++) {
X	if (*src == ':') {
X	    *elem++ = dst;
X	    *src = '\0';
X	    dst = src + 1;
X	}
X    }
X    *elem = dst;
X
X    return elemlist;
X}
X
X
Xvoid _XmuStringToBitmapInitCache (c)
X    register XmuCvtCache *c;
X{
X    c->string_to_bitmap.bitmapFilePath = NULL;
X}
X
Xvoid _XmuStringToBitmapFreeCache (c)
X    register XmuCvtCache *c;
X{
X    if (c->string_to_bitmap.bitmapFilePath) {
X	if (c->string_to_bitmap.bitmapFilePath[0]) 
X	  free (c->string_to_bitmap.bitmapFilePath[0]);
X	free ((char *) (c->string_to_bitmap.bitmapFilePath));
X    }
X}
END_OF_FILE
if test 6509 -ne `wc -c <'LocBitmap.c'`; then
    echo shar: \"'LocBitmap.c'\" unpacked with wrong size!
fi
# end of 'LocBitmap.c'
fi
if test -f 'RdPixF.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'RdPixF.c'\"
else
echo shar: Extracting \"'RdPixF.c'\" \(10065 characters\)
sed "s/^X//" >'RdPixF.c' <<'END_OF_FILE'
X
X/*
X * Copyright 1989 Consilium
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Consilium not be used in advertising
X * or publicity pertaining to distribution of the software without specific,
X * written prior permission.  Consilium makes no representations about the
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * Consilium DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
X * Consilium BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
X * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
X * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X * ---------------------------------------------------------------------------
X * WHO:    Richard Hess			CORP:	Consilium
X * TITLE:  Project Manager			VOICE:	[415] 691-6342
X *       [ User Interface Services ]	USNAIL:	640 Clyde Court
X * UUCP:   ...!uunet!cimshop!rhess		Mountain View, CA 94043
X * ---------------------------------------------------------------------------
X */
X
X/*****************************************************************************
X ****  Read/Write package for XPM file format (X PixMap) 
X ****
X ****  int    XmuReadPixmapFile(dpy, d, cmap, filename, w, h, depth, pixmap)
X ****
X ****  Daniel Dardailler - Bull RC (89/02/22) e-mail: daniel@mirsa.inria.fr
X *****************************************************************************
X ****  Version 2.0:  Read support for NAME_mono[] option...
X ****  Version 1.1:  extended chars_per_pixel support... [ Read, Create ]
X ****
X ****  Richard Hess - Consilium    (89/11/06) e-mail: ..!uunet!cimshop!rhess
X *****************************************************************************/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X
X#include <X11/Xmu/Drawing.h> /* PixmapOpenFailed, PixmapSuccess .. MAXPRINTABLE */
X
Xstatic char *getline();
X
Xtypedef struct _Cixel {
X     char c1,c2 ;
X   } Cixel ;                    /* 2 chars for one pixel value */
X
Xtypedef struct _CmapEntry {
X     Cixel cixel ;               
X     int red,green,blue ;
X   } CmapEntry ;                    
X
X
X#define MAXPRINTABLE 93             /* number of printable ascii chars 
X				       minus \ and " for string compat. */
X
Xstatic char * printable = " .XoO+@#$%&*=-;:?>,<1234567890qwertyuipasdfghjklzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|" ;
X           /* printable begin with a space, so in most case, due to
X	      my algorythm, when the number of different colors is
X	      less than MAXPRINTABLE, it will give a char follow by 
X	      "nothing" (a space) in the readable xpm file */
X
X  
X/**[ XmuReadPixmapFile ]********************************************************
X *
X *  Read a Pixmap file in an X Pixmap with specified depth and colormap...
X * (THIS VERSION SUPPORTS : '_mono[]' [ optional ] )
X * (THIS VERSION SUPPORTS : '_chars_per_pixel 1', '_chars_per_pixel 2')
X *****************************************************************************/
X
Xint XmuReadPixmapFile (display,d,
X		     colormap,filename,width,height,depth,pixmap)
X     Display *display;
X     Drawable d;
X     Colormap colormap ;
X     char *filename;
X     unsigned int *width, *height;       /* RETURNED */
X     int depth ;   
X     Pixmap *pixmap;                     /* RETURNED */
X{
X  GC Gc ;
X  XGCValues xgcv;
X
X  FILE *fstream;			/* handle on file  */
X  char linebuf[256] ;
X  char namebuf[256];
X  char type[256];
X  char name[256];
X
X  int ncolors ;
X
X  CmapEntry * cmap ;           
X  int * Tpixel ;
X
X  char c1, c2, c;
X  int red, green, blue ;
X  XColor xcolor ;
X  int i,j,p,n;
X  int cpp;
X  int mono = 0;
X  
X  if ((fstream = fopen(filename, "r")) == NULL) {
X    return PixmapOpenFailed;
X  }
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &p) != 3) 
X      || ((strcmp("_format",type)) && (strcmp("_paxformat",type)))
X      || (p != XPM_FORMAT)) 
X    return fatal("bad '#define NAME_format 1'"); 
X  else strcpy(name,namebuf);
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, width) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_width",type))) 
X	return fatal("bad '#define NAME_width n'");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, height) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_height",type))) 
X	return fatal("bad '#define NAME_height n'");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &ncolors) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_ncolors",type))) 
X	return fatal("bad '#define NAME_ncolors n'");
X
X  if (ncolors > (MAXPRINTABLE*MAXPRINTABLE)) 
X    return fatal("Too many different colors, version 1");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &cpp) != 3)
X      || (strcmp(name,namebuf)) || (cpp < 1) || (cpp > 2)
X      || (strcmp("_chars_per_pixel",type)))
X	return fatal("bad '#define NAME_chars_per_pixel n' [1][2]");
X
X  for (n=0; n<2 ; n++) {
X    if (n == 0) {
X      getline(linebuf,fstream);
X      if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X	  || (strcmp(name,namebuf))
X	  || (strcmp("_mono[]",type))) continue;
X      if (depth != 1) {
X	for (i=0; i<=ncolors ; i++) {
X	  getline(linebuf,fstream);
X	}
X	if (strncmp(linebuf, "} ;",3))
X	  return fatal("missing '} ;' in NAME_mono[]");
X	getline(linebuf,fstream);
X	continue;
X      }
X      mono = 1;
X    }
X    else {
X      if (mono) getline(linebuf, fstream);
X      if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X	  || (strcmp(name,namebuf))
X	  || (strcmp("_colors[]",type))) 
X	return fatal("bad 'static char * NAME_colors[] = {'");
X      if (mono) {
X	for (i=0; i<=ncolors ; i++) {
X	  getline(linebuf,fstream);
X	}
X	if (strncmp(linebuf, "} ;",3))
X	  return fatal("missing '} ;'");
X	continue;
X      }
X    }
X    cmap = (CmapEntry *) malloc(ncolors*sizeof(CmapEntry)) ;
X    Tpixel = (int *) malloc(ncolors*sizeof(int)) ;
X    if ((cmap == NULL) || (Tpixel == NULL))
X      return PixmapNoMemory ;
X    
X    getline(linebuf,fstream);
X    for (i=0; i<ncolors ; i++) {
X      switch (cpp)
X	{
X	case 1:
X	  if (sscanf(linebuf, "\"%c\" , \"%[^\"]%s",
X		     &c1,namebuf,type) != 3)
X	    return
X	      fatal("bad colormap entry : must be '\"c\" , \"colordef\",'"); 
X	  if (index(printable,c1)) {
X	    cmap[i].cixel.c1 = c1 ;
X	  } else
X	    return fatal("bad cixel value : must be printable");
X	  break;
X	case 2:
X	  if (sscanf(linebuf, "\"%c%c\" , \"%[^\"]%s",
X		     &c1,&c2,
X		     namebuf,type) != 4)
X	    return
X	      fatal("bad colormap entry : must be '\"cC\" , \"colordef\",'"); 
X	  if ((index(printable,c1)) &&
X	      (index(printable,c2))) {
X	    cmap[i].cixel.c1 = c1 ;
X	    cmap[i].cixel.c2 = c2 ;
X	  } else
X	    return fatal("bad cixel value : must be printable");
X	  break;
X	}
X      if (!XParseColor(display,colormap,namebuf,&xcolor))
X	return fatal("bad colordef specification : #RGB or colorname");
X      XAllocColor(display,colormap,&xcolor);
X      Tpixel[i] = xcolor.pixel ;
X      getline(linebuf,fstream);
X    }
X    if (strncmp(linebuf, "} ;",3))
X      return fatal("missing '} ;'");
X  }
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X      || (strcmp(name,namebuf))
X      || (strcmp("_pixels[]",type))) 
X	return fatal("bad 'static char * NAME_pixels[] = {'");
X
X  *pixmap = XCreatePixmap(display,d,*width,*height,depth);
X  Gc = XCreateGC(display,*pixmap,0,&xgcv);
X  
X  getline(linebuf,fstream);
X  j = 0 ;
X  while((j < *height) && strncmp(linebuf, "} ;",3))
X    {  
X      if (strlen(linebuf) < (cpp*(*width)+2)) 
X	return fatal("bad pixmap line length %d",strlen(linebuf));
X      switch (cpp)
X	{
X	case 1:
X	  for (i=1; i<=(*width) ; i++)
X	    {
X	      c1 = linebuf[i] ;
X	      for (p = 0 ; p < ncolors ; p++)
X		if (cmap[p].cixel.c1 == c1) break ;
X	      if (p != ncolors)
X		XSetForeground(display,Gc,Tpixel[p]);
X	      else 
X		return fatal("cixel \"%c\" not in previous colormap",c1);
X	      XDrawPoint(display,*pixmap,Gc,i-1,j) ;
X	    }
X	  break;
X	case 2:
X	  for (i=1; i<(2*(*width)) ; i+=2)
X	    {
X	      c1 = linebuf[i] ;
X	      c2 = linebuf[i+1] ;
X	      for (p = 0 ; p < ncolors ; p++)
X		if ((cmap[p].cixel.c1 == c1)&&(cmap[p].cixel.c2 == c2)) break ;
X	      if (p != ncolors)
X		XSetForeground(display,Gc,Tpixel[p]);
X	      else 
X		return fatal("cixel \"%c%c\" not in previous colormap",c1,c2);
X	      XDrawPoint(display,*pixmap,Gc,i/2,j) ;
X	    }
X	  break;
X	}
X      j++ ;
X      getline(linebuf,fstream);    
X    }
X
X  if (strncmp(linebuf, "} ;",3))
X    return fatal("missing '} ;'");
X
X  if (j != *height)
X    return fatal("%d too few pixmap line", *height - j);
X
X  free(cmap) ;
X  free(Tpixel) ;
X  fclose(fstream) ;
X  return PixmapSuccess ;
X}
X
X
X/****[ UTILITIES ]************************************************************
X * following routines are used in XmuReadPixmapFile() function 
X *****************************************************************************/
X
X/*
X * read the next line and jump blank lines 
X */
Xstatic char *
Xgetline(s,pF)
X     char * s ;
X     FILE * pF ;
X{
X    s = fgets(s,256,pF);
X
X    while (s) {
X	int len = strlen(s);
X	if (len && s[len-1] == '\015')
X	    s[--len] = '\0';
X	if (len==0) s = fgets(s,256,pF);
X	else break;
X    }
X    return(s);
X}
X	    
X
X/*
X * fatal message : return code, no exit 
X */
Xstatic int fatal(msg, p1, p2, p3, p4)
X    char *msg;
X{
X    fprintf(stderr,"\n");
X    fprintf(stderr, msg, p1, p2, p3, p4);
X    fprintf(stderr,"\n");
X    return PixmapFileInvalid ;
X}
X
X/****<eof>********************************************************************/
END_OF_FILE
if test 10065 -ne `wc -c <'RdPixF.c'`; then
    echo shar: \"'RdPixF.c'\" unpacked with wrong size!
fi
# end of 'RdPixF.c'
fi
if test -f 'StrToPmap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'StrToPmap.c'\"
else
echo shar: Extracting \"'StrToPmap.c'\" \(3230 characters\)
sed "s/^X//" >'StrToPmap.c' <<'END_OF_FILE'
X
X/***********************************************************
XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, 
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in 
Xsupporting documentation, and that the names of Digital or MIT not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.  
X
XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include	<X11/Intrinsic.h>
X#include	<X11/StringDefs.h>
X#include	<X11/Xmu/Converters.h>
X#include	<X11/Xmu/Drawing.h>
X
X
X/*
X * XmuConvertStringToPixmap:
X *
X * creates a default-depth-of-screen Pixmap suitable for background Pixmaps.
X * "string" represents a pixmap(xpm or xbm) filename which may be absolute,
X * or relative to the global resource bitmapFilePath, class
X * BitmapFilePath.  If the resource is not defined, the default
X * value is the build symbol BITMAPDIR.
X *
X * shares lots of code with XmuConvertStringToBitmap.  
X *
X * To use, include the following in your ClassInitialize procedure:
X
Xstatic XtConvertArgRec screenConvertArg[] = {
X    {XtBaseOffset, (caddr_t) XtOffset(Widget, core.screen), sizeof(Screen *)}
X};
X
X    XtAddConverter("String", "Pixmap", XmuCvtStringToPixmap,
X		   screenConvertArg, XtNumber(screenConvertArg));
X *
X */
X
X#define	done(address, type) \
X	{ (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t) address; }
X
X
X/*ARGSUSED*/
Xvoid XmuCvtStringToPixmap(args, num_args, fromVal, toVal)
X    XrmValuePtr args;
X    Cardinal    *num_args;
X    XrmValuePtr	fromVal;
X    XrmValuePtr	toVal;
X{
X    Screen *screen;
X    static Pixmap pixmap;		/* static for cvt magic */
X    char *name = (char *)fromVal->addr;
X
X    if (*num_args != 1)
X     XtErrorMsg("wrongParameters","cvtStringToPixmap","XtToolkitError",
X             "String to Pixmap conversion needs screen argument",
X              (String *)NULL, (Cardinal *)NULL);
X
X    if (strcmp(name, "None") == 0) {
X	pixmap = None;
X	done(&pixmap, Pixmap);
X	return;
X    }
X
X    if (strcmp(name, "ParentRelative") == 0) {
X	pixmap = ParentRelative;
X	done(&pixmap, Pixmap);
X	return;
X    }
X
X    screen = *((Screen **) args[0].addr);
X    pixmap = XmuLocatePixmapFile (screen, name,
X		BlackPixelOfScreen(screen), WhitePixelOfScreen(screen),
X		DefaultDepthOfScreen(screen),
X		NULL, 0, NULL, NULL, NULL, NULL);
X
X    if (pixmap != None) {
X	done (&pixmap, Pixmap);
X    } else {
X	XtStringConversionWarning (name, "Pixmap");
X	return;
X    }
X}
X
END_OF_FILE
if test 3230 -ne `wc -c <'StrToPmap.c'`; then
    echo shar: \"'StrToPmap.c'\" unpacked with wrong size!
fi
# end of 'StrToPmap.c'
fi
echo shar: End of shell archive.
exit 0
---- cut here ----


Of course, the previous is limited in that you have to add the converter to
the application program, or widget source.  It doesn't do anything for all those
clients you already have that you don't want to modify the source to.
Therefore, the following stuff makes the same converter, but makes it part of
the "standard" converters that are loaded by XtInitialize().

These files and changes all affect libXt.  The only major changes between this
and the previous converter is the lack of XmuCvtCache, and  thus the lack
of the bitmapFilePath resource.  I got around this by adding code to
read a environment variable BITMAPFILEPATH which is a colon separated list
of directories to search for bitmap and pixmap files.

The Converter adds 2 new modules to libXt:
RdPixF.c	A XtReadPixmapFile routine for XPM format pixmap files.
		(pretty much straight from contrib/xpm.tar.Z)
LocBitmap.c	Pretty much a copy of the file from libXmu except it is
		called XtLocatePixmapFile and calls XtReadPixmapFile

The Converter modifies 1 module and 1 header file in libXt:
Converters.c	Add the code for CvtStringToPixmap
		(almost identical to XmuCvtStringToPixmap)
Intrinsic.h	Declarations of the XtReadPixmapFile and XtLocatePixmapFile
		function calls, and some defines to support XPM format.

With these libXt changes you don't need any client code changes.  Just relink
your clients with the new libXt, and the converter is there.
Warning, while this will allow you to put backgroundPixmaps into almost all
the original X clients, most were not written with such backgrounds in mind
and probably won't work quite as you would like.




SHAR FILE OF LIBXT MODULES ADDED/CHANGED
---- cut here ----
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Converters.h Drawing.h LocBitmap.c RdPixF.c StrToPmap.c
# Wrapped by ebina@ixch on Tue Jun  5 23:47:21 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Converters.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Converters.h'\"
else
echo shar: Extracting \"'Converters.h'\" \(6693 characters\)
sed "s/^X//" >'Converters.h' <<'END_OF_FILE'
X/*
X * $XConsortium: Converters.h,v 1.7 90/04/13 16:22:30 jim Exp $
X *
X * Copyright 1988 by the Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided 
X * that the above copyright notice appear in all copies and that both that 
X * copyright notice and this permission notice appear in supporting 
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific, 
X * written prior permission. M.I.T. makes no representations about the 
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * The X Window System is a Trademark of MIT.
X *
X * The interfaces described by this header file are for miscellaneous utilities
X * and are not part of the Xlib standard.
X */
X
X#ifndef _XMU_STRCONVERT_H_
X#define _XMU_STRCONVERT_H_
X
X#ifdef __cplusplus			/* do not leave open across includes */
Xextern "C" {					/* for C++ V2.0 */
X#endif
X
X/*
X * Converters - insert in alphabetical order
X */
X
X/******************************************************************************
X * XmuCvtFunctionToCallback
X */
Xextern void XmuCvtFunctionToCallback(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToBackingStore
X */
X#define XtNbackingStore "backingStore"
X#define XtCBackingStore "BackingStore"
X#define XtRBackingStore "BackingStore"
X#define XtEnotUseful "notUseful"
X#define XtEwhenMapped "whenMapped"
X#define XtEalways "always"
X#define XtEdefault "default"
Xextern void XmuCvtStringToBackingStore(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToCursor
X */
Xextern void XmuCvtStringToCursor(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
Xextern Boolean XmuCvtStringToColorCursor(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */,
X    XtPointer*		/* converter_data */
X#endif
X);
X
X#define XtRColorCursor "ColorCursor"
X#define XtNpointerColor "pointerColor"
X#define XtNpointerColorBackground "pointerColorBackground"
X
X
X/******************************************************************************
X * XmuCvtStringToGravity
X */
Xtypedef int XtGravity;
X
X#define XtRGravity "Gravity"
X#define XtEForget "forget"
X#define XtENorthWest "northwest"
X#define XtENorth "north"
X#define XtENorthEast "northeast"
X#define XtEWest "west"
X#define XtECenter "center"
X#define XtEEast "east"
X#define XtESouthWest "southwest"
X#define XtESouth "south"
X#define XtESouthEast "southeast"
X#define XtEStatic "static"
X#define XtEUnmap "unmap"
X
Xextern void XmuCvtStringToGravity (
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToJustify
X */
Xtypedef enum {
X    XtJustifyLeft,       /* justify text to left side of button   */
X    XtJustifyCenter,     /* justify text in center of button      */
X    XtJustifyRight       /* justify text to right side of button  */
X} XtJustify;
X#define XtEleft "left"
X#define XtEcenter "center"
X#define XtEright "right"
X#define XtEtop "top"
X#define XtEbottom "bottom"
X
Xextern void XmuCvtStringToJustify(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToLong
X */
X#define XtRLong "Long"
Xextern void XmuCvtStringToLong(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToOrientation
X */
Xtypedef enum {XtorientHorizontal, XtorientVertical} XtOrientation;
Xextern void XmuCvtStringToOrientation(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToBitmap
X */
Xextern void XmuCvtStringToBitmap(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToPixmap
X */
Xextern void XmuCvtStringToPixmap(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X
X/******************************************************************************
X * XmuCvtStringToShapeStyle; is XtTypeConverter (i.e. new style)
X * no conversion arguments, not particularly useful to cache the results.
X */
X
X#define XtRShapeStyle "ShapeStyle"
X#define XtERectangle "Rectangle"
X#define XtEOval "Oval"
X#define XtEEllipse "Ellipse"
X#define XtERoundedRectangle "RoundedRectangle"
X
X#define XmuShapeRectangle 1
X#define XmuShapeOval 2
X#define XmuShapeEllipse 3
X#define XmuShapeRoundedRectangle 4
X
Xextern Boolean XmuCvtStringToShapeStyle(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */,
X    XtPointer*		/* converter_data */
X#endif
X);
X
Xextern Boolean XmuReshapeWidget(
X#if NeedFunctionPrototypes
X    Widget	/* w */,
X    int		/* shape_style */,
X    int		/* corner_width */,
X    int		/* corner_height */
X#endif
X);
X
X/******************************************************************************
X * XmuCvtStringToWidget
X */
Xextern void XmuCvtStringToWidget(
X#if NeedFunctionPrototypes
X    XrmValue*		/* args */,
X    Cardinal*		/* num_args */,
X    XrmValuePtr		/* fromVal */,
X    XrmValuePtr		/* toVal */
X#endif
X);
X
X#ifdef __cplusplus
X}						/* for C++ V2.0 */
X#endif
X
X#endif /* _XMU_STRCONVERT_H_ */
END_OF_FILE
if test 6693 -ne `wc -c <'Converters.h'`; then
    echo shar: \"'Converters.h'\" unpacked with wrong size!
fi
# end of 'Converters.h'
fi
if test -f 'Drawing.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Drawing.h'\"
else
echo shar: Extracting \"'Drawing.h'\" \(4778 characters\)
sed "s/^X//" >'Drawing.h' <<'END_OF_FILE'
X/*
X * $XConsortium: Drawing.h,v 1.7 90/04/03 09:42:31 swick Exp $
X *
X * Copyright 1988 by the Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided 
X * that the above copyright notice appear in all copies and that both that 
X * copyright notice and this permission notice appear in supporting 
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific, 
X * written prior permission. M.I.T. makes no representations about the 
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * The X Window System is a Trademark of MIT.
X *
X * The interfaces described by this header file are for miscellaneous utilities
X * and are not part of the Xlib standard.
X */
X
X#ifndef _XMU_DRAWING_H_
X#define _XMU_DRAWING_H_
X
X#if NeedFunctionPrototypes
X#include <stdio.h>
X#if ! defined(_XtIntrinsic_h) && ! defined(PIXEL_ALREADY_TYPEDEFED)
Xtypedef unsigned long Pixel;
X#endif
X#endif
X
X#ifdef __cplusplus			/* do not leave open across includes */
Xextern "C" {					/* for C++ V2.0 */
X#endif
X
Xvoid XmuDrawRoundedRectangle(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* draw */,
X    GC 		/* gc */,
X    int		/* x */,
X    int		/* y */,
X    int		/* w */,
X    int		/* h */,
X    int		/* ew */,
X    int		/* eh */
X#endif
X);
X
Xvoid XmuFillRoundedRectangle(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* draw */,
X    GC 		/* gc */,
X    int		/* x */,
X    int		/* y */,
X    int		/* w */,
X    int		/* h */,
X    int		/* ew */,
X    int		/* eh */
X#endif
X);
X
Xvoid XmuDrawLogo(
X#if NeedFunctionPrototypes
X    Display*	/* dpy */,
X    Drawable 	/* drawable */,
X    GC		/* gcFore */,
X    GC		/* gcBack */,
X    int		/* x */,
X    int		/* y */,
X    unsigned int /* width */,
X    unsigned int /* height */
X#endif
X);
X
XPixmap XmuCreatePixmapFromBitmap(
X#if NeedFunctionPrototypes
X    Display*		/* dpy */,
X    Drawable 		/* d */,
X    Pixmap 		/* bitmap */,
X    unsigned int	/* width */,
X    unsigned int	/* height */,
X    unsigned int	/* depth */,
X    unsigned long	/* fore */,
X    unsigned long	/* back */
X#endif
X);
X
XPixmap XmuCreateStippledPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    Pixel		/* fore */,
X    Pixel		/* back */,
X    unsigned int	/* depth */
X#endif
X);
X
Xvoid XmuReleaseStippledPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    Pixmap 		/* pixmap */
X#endif
X);
X
XPixmap XtGrayPixmap(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */
X#endif
X);
X
XPixmap XmuLocateBitmapFile(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    char*		/* name */,
X    char*		/* srcname_return */,
X    int 		/* srcnamelen */,
X    int*		/* width_return */,
X    int*		/* height_return, */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
XPixmap XmuLocatePixmapFile(
X#if NeedFunctionPrototypes
X    Screen*		/* screen */,
X    char*		/* name */,
X    unsigned long	/* fore */,
X    unsigned long	/* back */,
X    unsigned int	/* depth */,
X    char*		/* srcname_return */,
X    int 		/* srcnamelen */,
X    int*		/* width_return */,
X    int*		/* height_return, */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
Xint XmuReadBitmapData(
X#if NeedFunctionPrototypes
X    FILE*		/* fstream */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    unsigned char**	/* datap_return */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
Xint XmuReadBitmapDataFromFile(
X#if NeedFunctionPrototypes
X    char*		/* filename */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    unsigned char**	/* datap_return */,
X    int*		/* xhot_return */,
X    int*		/* yhot_return */
X#endif
X);
X
X/**** XmuReadPixmapFile **********************
X * stuff for xpm as a standard pixmap format *
X *********************************************/
Xint XmuReadPixmapFile(
X#if NeedFunctionPrototypes
X    Display*		/* display */,
X    Drawable		/* drawable */,
X    Colormap		/* Colormap */,
X    char*		/* filename */,
X    unsigned int*	/* width_return */,
X    unsigned int*	/* height_return */,
X    int			/* depth */,
X    Pixmap*		/* pixmap_return */
X#endif
X);
X
X#define XPM_FORMAT 1
X
X/* we keep the same codes as for Bitmap management */
X#ifndef _XUTIL_H_
X#include <X11/Xutil.h>
X#endif
X#define PixmapSuccess        BitmapSuccess 
X#define PixmapOpenFailed     BitmapOpenFailed
X#define PixmapFileInvalid    BitmapFileInvalid
X#define PixmapNoMemory       BitmapNoMemory
X/*********************************************/
X
X#ifdef __cplusplus
X}						/* for C++ V2.0 */
X#endif
X
X#endif /* _XMU_DRAWING_H_ */
END_OF_FILE
if test 4778 -ne `wc -c <'Drawing.h'`; then
    echo shar: \"'Drawing.h'\" unpacked with wrong size!
fi
# end of 'Drawing.h'
fi
if test -f 'LocBitmap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'LocBitmap.c'\"
else
echo shar: Extracting \"'LocBitmap.c'\" \(6509 characters\)
sed "s/^X//" >'LocBitmap.c' <<'END_OF_FILE'
X/*
X * $XConsortium: LocBitmap.c,v 1.6 90/03/23 11:09:29 rws Exp $
X *
X * Copyright 1989 Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific,
X * written prior permission.  M.I.T. makes no representations about the
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X * Author:  Jim Fulton, MIT X Consortium
X */
X
X#include <X11/Xlib.h>
X#include <X11/Xresource.h>
X#include <X11/Xutil.h>
X#include <X11/StringDefs.h>
X#include <sys/param.h>			/* get MAXPATHLEN if possible */
X#ifndef MAXPATHLEN
X#define MAXPATHLEN 256
X#endif
X#include <X11/Xmu/CvtCache.h>
X#include <X11/Xmu/Drawing.h>
X
X
X/*
X * XmuLocateBitmapFile - read a bitmap file using the normal defaults
X */
X
XPixmap XmuLocateBitmapFile (screen, name, srcname, srcnamelen,
X			    widthp, heightp, xhotp, yhotp)
X    Screen *screen;
X    char *name;
X    char *srcname;			/* RETURN */
X    int srcnamelen;
X    int *widthp, *heightp, *xhotp, *yhotp;  /* RETURN */
X{
X    return XmuLocatePixmapFile (screen, name, 
X				(unsigned long) 1, (unsigned long) 0,
X				(unsigned int) 1, srcname, srcnamelen,
X				widthp, heightp, xhotp, yhotp);
X}
X
X
X/*
X * version that reads pixmap data as well as bitmap data
X */
XPixmap XmuLocatePixmapFile (screen, name, fore, back, depth, 
X			    srcname, srcnamelen,
X			    widthp, heightp, xhotp, yhotp)
X    Screen *screen;
X    char *name;
X    unsigned long fore, back;
X    unsigned int depth;
X    char *srcname;			/* RETURN */
X    int srcnamelen;
X    int *widthp, *heightp, *xhotp, *yhotp;  /* RETURN */
X{
X    Display *dpy = DisplayOfScreen (screen);
X    Window root = RootWindowOfScreen (screen);
X    Bool try_plain_name = True;
X    XmuCvtCache *cache = _XmuCCLookupDisplay (dpy);
X    char **file_paths;
X    char filename[MAXPATHLEN];
X    unsigned int width, height;
X    int xhot, yhot;
X    int i;
X    static char **split_path_string();
X
X
X    /*
X     * look in cache for bitmap path
X     */
X    if (cache) {
X	if (!cache->string_to_bitmap.bitmapFilePath) {
X	    XrmName xrm_name[2];
X	    XrmClass xrm_class[2];
X	    XrmRepresentation rep_type;
X	    XrmValue value;
X
X	    xrm_name[0] = XrmStringToName ("bitmapFilePath");
X	    xrm_name[1] = NULL;
X	    xrm_class[0] = XrmStringToClass ("BitmapFilePath");
X	    xrm_class[1] = NULL;
X	    /*
X	     * XXX - warning, derefing Display * until XDisplayDatabase
X	     */
X	    if (!dpy->db) {
X		/* what a hack; need to initialize dpy->db */
X		(void) XGetDefault (dpy, "", "");
X	    }
X	    if (XrmQGetResource (dpy->db, xrm_name, xrm_class, 
X				 &rep_type, &value) &&
X		rep_type == XrmStringToQuark(XtRString)) {
X		cache->string_to_bitmap.bitmapFilePath = 
X		  split_path_string (value.addr);
X	    }
X	}
X	file_paths = cache->string_to_bitmap.bitmapFilePath;
X    }
X
X
X    /*
X     * Search order:
X     *    1.  name if it begins with / or ./
X     *    2.  "each prefix in file_paths"/name
X     *    3.  BITMAPDIR/name
X     *    4.  name if didn't begin with / or .
X     */
X
X#ifndef BITMAPDIR
X#define BITMAPDIR "/usr/include/X11/bitmaps"
X#endif
X
X    for (i = 1; i <= 4; i++) {
X	char *fn = filename;
X	Pixmap pixmap;
X	unsigned char *data;
X
X	switch (i) {
X	  case 1:
X	    if (!(name[0] == '/' || (name[0] == '.') && name[1] == '/')) 
X	      continue;
X	    fn = name;
X	    try_plain_name = False;
X	    break;
X	  case 2:
X	    if (file_paths && *file_paths) {
X		sprintf (filename, "%s/%s", *file_paths, name);
X		file_paths++;
X		i--;
X		break;
X	    }
X	    continue;
X	  case 3:
X	    sprintf (filename, "%s/%s", BITMAPDIR, name);
X	    break;
X	  case 4:
X	    if (!try_plain_name) continue;
X	    fn = name;
X	    break;
X	}
X
X	data = NULL;
X	pixmap = None;
X	if (XmuReadBitmapDataFromFile (fn, &width, &height, &data,
X				       &xhot, &yhot) == BitmapSuccess) {
X	    pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data,
X						  width, height,
X						  fore, back, depth);
X	    XFree ((char *)data);
X	}
X	else if (XmuReadPixmapFile (dpy, root,
X			DefaultColormap(dpy, DefaultScreen(dpy)), fn,
X			&width, &height, depth, &pixmap) == PixmapSuccess) {
X	    xhot = yhot = 0;
X	}
X
X	if (pixmap) {
X	    if (widthp) *widthp = (int)width;
X	    if (heightp) *heightp = (int)height;
X	    if (xhotp) *xhotp = xhot;
X	    if (yhotp) *yhotp = yhot;
X	    if (srcname && srcnamelen > 0) {
X		strncpy (srcname, fn, srcnamelen - 1);
X		srcname[srcnamelen - 1] = '\0';
X	    }
X	    return pixmap;
X	}
X    }
X
X    return None;
X}
X
X
X/*
X * split_path_string - split a colon-separated list into its constituent
X * parts; to release, free list[0] and list.
X */
Xstatic char **split_path_string (src)
X    register char *src;
X{
X    int nelems = 1;
X    register char *dst;
X    char **elemlist, **elem;
X
X    /* count the number of elements */
X    for (dst = src; *dst; dst++) if (*dst == ':') nelems++;
X
X    /* get memory for everything */
X    dst = (char *) malloc (dst - src + 1);
X    if (!dst) return NULL;
X    elemlist = (char **) calloc ((nelems + 1), sizeof (char *));
X    if (!elemlist) {
X	free (dst);
X	return NULL;
X    }
X
X    /* copy to new list and walk up nulling colons and setting list pointers */
X    strcpy (dst, src);
X    for (elem = elemlist, src = dst; *src; src++) {
X	if (*src == ':') {
X	    *elem++ = dst;
X	    *src = '\0';
X	    dst = src + 1;
X	}
X    }
X    *elem = dst;
X
X    return elemlist;
X}
X
X
Xvoid _XmuStringToBitmapInitCache (c)
X    register XmuCvtCache *c;
X{
X    c->string_to_bitmap.bitmapFilePath = NULL;
X}
X
Xvoid _XmuStringToBitmapFreeCache (c)
X    register XmuCvtCache *c;
X{
X    if (c->string_to_bitmap.bitmapFilePath) {
X	if (c->string_to_bitmap.bitmapFilePath[0]) 
X	  free (c->string_to_bitmap.bitmapFilePath[0]);
X	free ((char *) (c->string_to_bitmap.bitmapFilePath));
X    }
X}
END_OF_FILE
if test 6509 -ne `wc -c <'LocBitmap.c'`; then
    echo shar: \"'LocBitmap.c'\" unpacked with wrong size!
fi
# end of 'LocBitmap.c'
fi
if test -f 'RdPixF.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'RdPixF.c'\"
else
echo shar: Extracting \"'RdPixF.c'\" \(10065 characters\)
sed "s/^X//" >'RdPixF.c' <<'END_OF_FILE'
X
X/*
X * Copyright 1989 Consilium
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Consilium not be used in advertising
X * or publicity pertaining to distribution of the software without specific,
X * written prior permission.  Consilium makes no representations about the
X * suitability of this software for any purpose.  It is provided "as is"
X * without express or implied warranty.
X *
X * Consilium DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
X * Consilium BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
X * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
X * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X *
X * ---------------------------------------------------------------------------
X * WHO:    Richard Hess			CORP:	Consilium
X * TITLE:  Project Manager			VOICE:	[415] 691-6342
X *       [ User Interface Services ]	USNAIL:	640 Clyde Court
X * UUCP:   ...!uunet!cimshop!rhess		Mountain View, CA 94043
X * ---------------------------------------------------------------------------
X */
X
X/*****************************************************************************
X ****  Read/Write package for XPM file format (X PixMap) 
X ****
X ****  int    XmuReadPixmapFile(dpy, d, cmap, filename, w, h, depth, pixmap)
X ****
X ****  Daniel Dardailler - Bull RC (89/02/22) e-mail: daniel@mirsa.inria.fr
X *****************************************************************************
X ****  Version 2.0:  Read support for NAME_mono[] option...
X ****  Version 1.1:  extended chars_per_pixel support... [ Read, Create ]
X ****
X ****  Richard Hess - Consilium    (89/11/06) e-mail: ..!uunet!cimshop!rhess
X *****************************************************************************/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X
X#include <X11/Xmu/Drawing.h> /* PixmapOpenFailed, PixmapSuccess .. MAXPRINTABLE */
X
Xstatic char *getline();
X
Xtypedef struct _Cixel {
X     char c1,c2 ;
X   } Cixel ;                    /* 2 chars for one pixel value */
X
Xtypedef struct _CmapEntry {
X     Cixel cixel ;               
X     int red,green,blue ;
X   } CmapEntry ;                    
X
X
X#define MAXPRINTABLE 93             /* number of printable ascii chars 
X				       minus \ and " for string compat. */
X
Xstatic char * printable = " .XoO+@#$%&*=-;:?>,<1234567890qwertyuipasdfghjklzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|" ;
X           /* printable begin with a space, so in most case, due to
X	      my algorythm, when the number of different colors is
X	      less than MAXPRINTABLE, it will give a char follow by 
X	      "nothing" (a space) in the readable xpm file */
X
X  
X/**[ XmuReadPixmapFile ]********************************************************
X *
X *  Read a Pixmap file in an X Pixmap with specified depth and colormap...
X * (THIS VERSION SUPPORTS : '_mono[]' [ optional ] )
X * (THIS VERSION SUPPORTS : '_chars_per_pixel 1', '_chars_per_pixel 2')
X *****************************************************************************/
X
Xint XmuReadPixmapFile (display,d,
X		     colormap,filename,width,height,depth,pixmap)
X     Display *display;
X     Drawable d;
X     Colormap colormap ;
X     char *filename;
X     unsigned int *width, *height;       /* RETURNED */
X     int depth ;   
X     Pixmap *pixmap;                     /* RETURNED */
X{
X  GC Gc ;
X  XGCValues xgcv;
X
X  FILE *fstream;			/* handle on file  */
X  char linebuf[256] ;
X  char namebuf[256];
X  char type[256];
X  char name[256];
X
X  int ncolors ;
X
X  CmapEntry * cmap ;           
X  int * Tpixel ;
X
X  char c1, c2, c;
X  int red, green, blue ;
X  XColor xcolor ;
X  int i,j,p,n;
X  int cpp;
X  int mono = 0;
X  
X  if ((fstream = fopen(filename, "r")) == NULL) {
X    return PixmapOpenFailed;
X  }
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &p) != 3) 
X      || ((strcmp("_format",type)) && (strcmp("_paxformat",type)))
X      || (p != XPM_FORMAT)) 
X    return fatal("bad '#define NAME_format 1'"); 
X  else strcpy(name,namebuf);
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, width) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_width",type))) 
X	return fatal("bad '#define NAME_width n'");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, height) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_height",type))) 
X	return fatal("bad '#define NAME_height n'");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &ncolors) != 3)
X      || (strcmp(name,namebuf)) 
X      || (strcmp("_ncolors",type))) 
X	return fatal("bad '#define NAME_ncolors n'");
X
X  if (ncolors > (MAXPRINTABLE*MAXPRINTABLE)) 
X    return fatal("Too many different colors, version 1");
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "#define %[^_]%s %d", namebuf, type, &cpp) != 3)
X      || (strcmp(name,namebuf)) || (cpp < 1) || (cpp > 2)
X      || (strcmp("_chars_per_pixel",type)))
X	return fatal("bad '#define NAME_chars_per_pixel n' [1][2]");
X
X  for (n=0; n<2 ; n++) {
X    if (n == 0) {
X      getline(linebuf,fstream);
X      if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X	  || (strcmp(name,namebuf))
X	  || (strcmp("_mono[]",type))) continue;
X      if (depth != 1) {
X	for (i=0; i<=ncolors ; i++) {
X	  getline(linebuf,fstream);
X	}
X	if (strncmp(linebuf, "} ;",3))
X	  return fatal("missing '} ;' in NAME_mono[]");
X	getline(linebuf,fstream);
X	continue;
X      }
X      mono = 1;
X    }
X    else {
X      if (mono) getline(linebuf, fstream);
X      if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X	  || (strcmp(name,namebuf))
X	  || (strcmp("_colors[]",type))) 
X	return fatal("bad 'static char * NAME_colors[] = {'");
X      if (mono) {
X	for (i=0; i<=ncolors ; i++) {
X	  getline(linebuf,fstream);
X	}
X	if (strncmp(linebuf, "} ;",3))
X	  return fatal("missing '} ;'");
X	continue;
X      }
X    }
X    cmap = (CmapEntry *) malloc(ncolors*sizeof(CmapEntry)) ;
X    Tpixel = (int *) malloc(ncolors*sizeof(int)) ;
X    if ((cmap == NULL) || (Tpixel == NULL))
X      return PixmapNoMemory ;
X    
X    getline(linebuf,fstream);
X    for (i=0; i<ncolors ; i++) {
X      switch (cpp)
X	{
X	case 1:
X	  if (sscanf(linebuf, "\"%c\" , \"%[^\"]%s",
X		     &c1,namebuf,type) != 3)
X	    return
X	      fatal("bad colormap entry : must be '\"c\" , \"colordef\",'"); 
X	  if (index(printable,c1)) {
X	    cmap[i].cixel.c1 = c1 ;
X	  } else
X	    return fatal("bad cixel value : must be printable");
X	  break;
X	case 2:
X	  if (sscanf(linebuf, "\"%c%c\" , \"%[^\"]%s",
X		     &c1,&c2,
X		     namebuf,type) != 4)
X	    return
X	      fatal("bad colormap entry : must be '\"cC\" , \"colordef\",'"); 
X	  if ((index(printable,c1)) &&
X	      (index(printable,c2))) {
X	    cmap[i].cixel.c1 = c1 ;
X	    cmap[i].cixel.c2 = c2 ;
X	  } else
X	    return fatal("bad cixel value : must be printable");
X	  break;
X	}
X      if (!XParseColor(display,colormap,namebuf,&xcolor))
X	return fatal("bad colordef specification : #RGB or colorname");
X      XAllocColor(display,colormap,&xcolor);
X      Tpixel[i] = xcolor.pixel ;
X      getline(linebuf,fstream);
X    }
X    if (strncmp(linebuf, "} ;",3))
X      return fatal("missing '} ;'");
X  }
X
X  getline(linebuf,fstream);
X  if ((sscanf(linebuf, "static char * %[^_]%s = {",namebuf,type) != 2)
X      || (strcmp(name,namebuf))
X      || (strcmp("_pixels[]",type))) 
X	return fatal("bad 'static char * NAME_pixels[] = {'");
X
X  *pixmap = XCreatePixmap(display,d,*width,*height,depth);
X  Gc = XCreateGC(display,*pixmap,0,&xgcv);
X  
X  getline(linebuf,fstream);
X  j = 0 ;
X  while((j < *height) && strncmp(linebuf, "} ;",3))
X    {  
X      if (strlen(linebuf) < (cpp*(*width)+2)) 
X	return fatal("bad pixmap line length %d",strlen(linebuf));
X      switch (cpp)
X	{
X	case 1:
X	  for (i=1; i<=(*width) ; i++)
X	    {
X	      c1 = linebuf[i] ;
X	      for (p = 0 ; p < ncolors ; p++)
X		if (cmap[p].cixel.c1 == c1) break ;
X	      if (p != ncolors)
X		XSetForeground(display,Gc,Tpixel[p]);
X	      else 
X		return fatal("cixel \"%c\" not in previous colormap",c1);
X	      XDrawPoint(display,*pixmap,Gc,i-1,j) ;
X	    }
X	  break;
X	case 2:
X	  for (i=1; i<(2*(*width)) ; i+=2)
X	    {
X	      c1 = linebuf[i] ;
X	      c2 = linebuf[i+1] ;
X	      for (p = 0 ; p < ncolors ; p++)
X		if ((cmap[p].cixel.c1 == c1)&&(cmap[p].cixel.c2 == c2)) break ;
X	      if (p != ncolors)
X		XSetForeground(display,Gc,Tpixel[p]);
X	      else 
X		return fatal("cixel \"%c%c\" not in previous colormap",c1,c2);
X	      XDrawPoint(display,*pixmap,Gc,i/2,j) ;
X	    }
X	  break;
X	}
X      j++ ;
X      getline(linebuf,fstream);    
X    }
X
X  if (strncmp(linebuf, "} ;",3))
X    return fatal("missing '} ;'");
X
X  if (j != *height)
X    return fatal("%d too few pixmap line", *height - j);
X
X  free(cmap) ;
X  free(Tpixel) ;
X  fclose(fstream) ;
X  return PixmapSuccess ;
X}
X
X
X/****[ UTILITIES ]************************************************************
X * following routines are used in XmuReadPixmapFile() function 
X *****************************************************************************/
X
X/*
X * read the next line and jump blank lines 
X */
Xstatic char *
Xgetline(s,pF)
X     char * s ;
X     FILE * pF ;
X{
X    s = fgets(s,256,pF);
X
X    while (s) {
X	int len = strlen(s);
X	if (len && s[len-1] == '\015')
X	    s[--len] = '\0';
X	if (len==0) s = fgets(s,256,pF);
X	else break;
X    }
X    return(s);
X}
X	    
X
X/*
X * fatal message : return code, no exit 
X */
Xstatic int fatal(msg, p1, p2, p3, p4)
X    char *msg;
X{
X    fprintf(stderr,"\n");
X    fprintf(stderr, msg, p1, p2, p3, p4);
X    fprintf(stderr,"\n");
X    return PixmapFileInvalid ;
X}
X
X/****<eof>********************************************************************/
END_OF_FILE
if test 10065 -ne `wc -c <'RdPixF.c'`; then
    echo shar: \"'RdPixF.c'\" unpacked with wrong size!
fi
# end of 'RdPixF.c'
fi
if test -f 'StrToPmap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'StrToPmap.c'\"
else
echo shar: Extracting \"'StrToPmap.c'\" \(3230 characters\)
sed "s/^X//" >'StrToPmap.c' <<'END_OF_FILE'
X
X/***********************************************************
XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, 
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in 
Xsupporting documentation, and that the names of Digital or MIT not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.  
X
XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include	<X11/Intrinsic.h>
X#include	<X11/StringDefs.h>
X#include	<X11/Xmu/Converters.h>
X#include	<X11/Xmu/Drawing.h>
X
X
X/*
X * XmuConvertStringToPixmap:
X *
X * creates a default-depth-of-screen Pixmap suitable for background Pixmaps.
X * "string" represents a pixmap(xpm or xbm) filename which may be absolute,
X * or relative to the global resource bitmapFilePath, class
X * BitmapFilePath.  If the resource is not defined, the default
X * value is the build symbol BITMAPDIR.
X *
X * shares lots of code with XmuConvertStringToBitmap.  
X *
X * To use, include the following in your ClassInitialize procedure:
X
Xstatic XtConvertArgRec screenConvertArg[] = {
X    {XtBaseOffset, (caddr_t) XtOffset(Widget, core.screen), sizeof(Screen *)}
X};
X
X    XtAddConverter("String", "Pixmap", XmuCvtStringToPixmap,
X		   screenConvertArg, XtNumber(screenConvertArg));
X *
X */
X
X#define	done(address, type) \
X	{ (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t) address; }
X
X
X/*ARGSUSED*/
Xvoid XmuCvtStringToPixmap(args, num_args, fromVal, toVal)
X    XrmValuePtr args;
X    Cardinal    *num_args;
X    XrmValuePtr	fromVal;
X    XrmValuePtr	toVal;
X{
X    Screen *screen;
X    static Pixmap pixmap;		/* static for cvt magic */
X    char *name = (char *)fromVal->addr;
X
X    if (*num_args != 1)
X     XtErrorMsg("wrongParameters","cvtStringToPixmap","XtToolkitError",
X             "String to Pixmap conversion needs screen argument",
X              (String *)NULL, (Cardinal *)NULL);
X
X    if (strcmp(name, "None") == 0) {
X	pixmap = None;
X	done(&pixmap, Pixmap);
X	return;
X    }
X
X    if (strcmp(name, "ParentRelative") == 0) {
X	pixmap = ParentRelative;
X	done(&pixmap, Pixmap);
X	return;
X    }
X
X    screen = *((Screen **) args[0].addr);
X    pixmap = XmuLocatePixmapFile (screen, name,
X		BlackPixelOfScreen(screen), WhitePixelOfScreen(screen),
X		DefaultDepthOfScreen(screen),
X		NULL, 0, NULL, NULL, NULL, NULL);
X
X    if (pixmap != None) {
X	done (&pixmap, Pixmap);
X    } else {
X	XtStringConversionWarning (name, "Pixmap");
X	return;
X    }
X}
X
END_OF_FILE
if test 3230 -ne `wc -c <'StrToPmap.c'`; then
    echo shar: \"'StrToPmap.c'\" unpacked with wrong size!
fi
# end of 'StrToPmap.c'
fi
echo shar: End of shell archive.
exit 0
---- cut here ----



Finally, for a little amusement, relink all your clients with the libXt changes
described previously, then add the following line to your resources
*backgroundPixmap: None
Now start up all your usual favorite clients.  The result can be "amusing".


Have Fun, and of course please inform me of any bugs, enhancements, gripes, 
questions, bad karma, etc. etc. etc.

Eric Bina
ebina@urbana.mcd.mot.com