/*
 * Copyright 1990 by Baylor College of Medicine ALL RIGHTS RESERVED. 
 *
 * This program is subject to a license agreement between 
 * Baylor College of Medicine and MIT. Any use inconsistent with
 * said license and any use by persons other than the faculty, 
 * students and staff at MIT or any use on a computer not operated 
 * as part of the Athena Computing Environment (ACE) is expressly 
 * prohibited.
 */
/****************************************************************
 * File: create_bmaps.c
 * Date: 05/06/91
 *
 * Description:
 *   This file creates all the bitmaps need for the VNS library.
 *   Some of the pixmaps are stored in the program context, while
 *   others are created as images and installed using the pixmap
 *   caching routines provided in Motif.
 *
 * Revisions:
 ****************************************************************/
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/cursorfont.h>

#include "VnsP.h"

/****************************************************************
 *             Exported Pixmaps
 ****************************************************************/

XImage *exit_image;
XImage *home_image;
XImage *link_here_image;
XImage *link_here_image_rev;
XImage *return_image;
XImage *return_image_rev;
XImage *tunnel_image;
XImage *tunnel_image_rev;
XImage *stack_image;
XImage *stack_image_rev;

Pixmap stipp_bits;
Pixmap link_bitmap;
Pixmap dlink_bitmap;
Pixmap badlink_bitmap;
Pixmap link_here_bitmap;
Pixmap link_here_bitmap_s;
Pixmap action_link_bitmap;
Pixmap qmark_bitmap;
Pixmap page_bitmap;

/****************************************************************
 *             Private Functions
 ****************************************************************/

/* Creates a bitmap from standard bitmap data */
static
Pixmap
make_bitmap(dpy,data,width,height)
	Display *dpy;
	char *data;
	int width;
	int height;
{
	return XCreateBitmapFromData(dpy,
		DefaultRootWindow(dpy),
		data,(unsigned)width,(unsigned)height);
}

/* Creates a bitmap from standard bitmap data */
static
Pixmap
make_bw_bitpmap(dpy,data,width,height)
	Display *dpy;
	char *data;
	int width;
	int height;
{
	return XCreatePixmapFromBitmapData(dpy,
		DefaultRootWindow(dpy),
		data,(unsigned)width,(unsigned)height,
		BlackPixel(dpy,DefaultScreen(dpy)),
		WhitePixel(dpy,DefaultScreen(dpy)),
		DefaultDepth(dpy,DefaultScreen(dpy)));
}

static
XImage *
make_image(dpy,data,width,height)
	Display *dpy;
	char *data;
	int width;
	int height;
{
        XImage *image = XCreateImage(dpy,(Visual *)CopyFromParent,1,
                XYBitmap,0,data,(unsigned)width,(unsigned)height,8,0);
        image->byte_order = image->bitmap_bit_order = LSBFirst;
        return image;
}

/****************************************************************
 *             MACROS
 ****************************************************************/

/* Handy macro for bitmaps */
#define CREATE_IMAGE(NAME) \
	make_image(dpy,NAME/**/_bits,NAME/**/_width,NAME/**/_height)

/* Handy macro for bitmaps */
#define CREATE_BMAP(NAME) \
	make_bitmap(dpy,NAME/**/_bits,NAME/**/_width,NAME/**/_height)

/* Handy macro for bitmaps */
#define CREATE_BW_PMAP(NAME) \
	make_bw_bitpmap(dpy,NAME/**/_bits,NAME/**/_width,NAME/**/_height)

/****************************************************************
 *             Public Functions
 ****************************************************************/

PUBLIC
void
install_images(dpy)
	Display *dpy;
{
#include <exit.xbm>
#include <go_home.xbm>
#include <link_here.xbm>
#include <link_here_rev.xbm>
#include <go_return.xbm>
#include <go_return_rev.xbm>
#include <tunnel.xbm>
#include <tunnel_rev.xbm>
#include <stack.xbm>
#include <stack_rev.xbm>

	/* create images */
	exit_image = CREATE_IMAGE(exit);
	home_image = CREATE_IMAGE(go_home);
	link_here_image = CREATE_IMAGE(link_here);
	link_here_image_rev = CREATE_IMAGE(link_here_rev);
	return_image = CREATE_IMAGE(go_return);
	return_image_rev = CREATE_IMAGE(go_return_rev);
	tunnel_image = CREATE_IMAGE(tunnel);
	tunnel_image_rev = CREATE_IMAGE(tunnel_rev);
	stack_image = CREATE_IMAGE(stack);
	stack_image_rev = CREATE_IMAGE(stack_rev);

	/* install images */
	XmInstallImage(exit_image,"exit");
	XmInstallImage(home_image,"home");
	XmInstallImage(link_here_image,"link_here");
	XmInstallImage(link_here_image_rev,"link_here_rev");
	XmInstallImage(return_image,"return");
	XmInstallImage(return_image_rev,"return_rev");
	XmInstallImage(tunnel_image,"tunnel");
	XmInstallImage(tunnel_image_rev,"tunnel_rev");
	XmInstallImage(stack_image,"stack");
	XmInstallImage(stack_image_rev,"stack_rev");
}

PUBLIC
void
uninstall_images(dpy)
	Display *dpy;
{
	/* uninstall images */
	XmUninstallImage(exit_image);
	XmUninstallImage(home_image);
	XmUninstallImage(link_here_image);
	XmUninstallImage(link_here_image_rev);
	XmUninstallImage(return_image);
	XmUninstallImage(return_image_rev);
	XmUninstallImage(tunnel_image);
	XmUninstallImage(tunnel_image_rev);
	XmUninstallImage(stack_image);
	XmUninstallImage(stack_image_rev);

	/* destroy images */
	XDestroyImage(exit_image);
	XDestroyImage(home_image);
	XDestroyImage(link_here_image);
	XDestroyImage(link_here_image_rev);
	XDestroyImage(return_image);
	XDestroyImage(return_image_rev);
	XDestroyImage(tunnel_image);
	XDestroyImage(tunnel_image_rev);
	XDestroyImage(stack_image);
	XDestroyImage(stack_image_rev);
}

PUBLIC
void
create_bmaps(dpy)
	Display *dpy;
{
	static int init_flag = 0;

#include <page.xbm>

#include <link_here.xbm>

#include <link.xbm>
#include <dlink.xbm>
#include <badlink.xbm>
#include <action.xbm>
#include <qmark.xbm>

	if (init_flag == 1) return;
	init_flag = 1;

	page_bitmap = CREATE_BMAP(page);

	/* link bitmaps */
	link_bitmap = CREATE_BW_PMAP(link);
	dlink_bitmap = CREATE_BW_PMAP(dlink);
	badlink_bitmap = CREATE_BW_PMAP(badlink);

	/* action link bitmaps */
	action_link_bitmap = CREATE_BW_PMAP(action);
	qmark_bitmap = CREATE_BW_PMAP(qmark);

	install_images(dpy);
}
