/* mainsub.c
Needed vars, routines from old main file.

Also, routines from xstuff{?}.c
*/

/* Don't compile anything if its not needed. */
/* Yes ! compile, since we choose the palette option at run time.
 *  #ifdef XIMAGE_PALETTE 
 * gbourhis Feb 93.
 */
#include <stdio.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/Shell.h>

#include <X11/StringDefs.h>
#ifdef XtSpecificationRelease
/*R4 or later */
#include <X11/Xaw/Box.h>
#else
#include <X11/Box.h>
#endif

#include <Xw/Xw.h>
#include <Xw/BBoard.h>
#include <Xw/SRaster.h>

#include "ximage.h"
/*#include "xi_buttons.h"*/
/*#include "ximage.icon"*/
#include "gr_com.h"

int	expand = 1;

Widget toplevel;	/* The top dude of everything ...really everything..*/
Widget toplevelform;	/* The top composite widget, parent of all the shells*/
Display *myDpy;

char  *dtmPortId = (char *) 0;

/*
extern void ETDirReturn();
extern void ETRetOpen();
extern void ETJumpToYDimDialog();
extern void ETJumpToOk();
XtActionsRec XIactionTable[] = {{"ETDirReturn",ETDirReturn},
				{"ETRetOpen",ETRetOpen},
				{"ETJumpToYDimDialog",ETJumpToYDimDialog},
				{"ETJumpToOk",ETJumpToOk}};

static XtResource resources[]= {
		{ "installCMap","InstallCMap",XtRBoolean,sizeof(Boolean),
		XtOffset(XIResourcesPtr,installCMap), 
		XtRBoolean, False }
	};

XIResources appResources;
*/
Boolean defStaticVisual;


extern	Widget toplevel;
extern	void ClosePaletteBox();

Widget	b[BUTTON_TABLE_SIZE];		/* Buttons */
static	char whoWroteMe[]="\nNCSA XImage written by Dave Thompson\nContour&Shade routines written by Dave Whittington\n";


initximage(wid)
Widget wid;
{
Arg		arglist[10];
Cardinal	i=0;
char		buff[128];
char		buff2[256];
Display		*dpy;
int		screen;
Visual		*myVis;


	dpy    = XtDisplay(wid);
	screen = DefaultScreen(dpy);
	myDpy = dpy;
	/* I'm guessing here. */
	toplevel = gr_topLevel;
	toplevelform = gr_topWin.shell;
	/*****************************/
	{
	Visual *vis;
	vis = DefaultVisual(dpy,screen);
	if (vis->class == StaticColor)
		defStaticVisual=TRUE;
	else
		defStaticVisual=FALSE;
	}

/*	if (! InitPalette(dpy))*/
	if (! InitPalette(wid))
		exit(0);
/*	if (! InitPalEntry(dpy))
		exit(0);
*/
/*	Init_Ctrl_Window(toplevel);*/

	/* Print the Display Info*/

  if (8 == DisplayPlanes(dpy,screen)) /* perfectionism at it's wosrt*/
    sprintf(buff,"Display is an %d plane %%s with %d entries in Colormap\n",
			DisplayPlanes(dpy,screen),XDisplayCells(dpy,screen));
  else
    sprintf(buff,"Display is a %d plane %%s with %d entries in Colormap\n",
			DisplayPlanes(dpy,screen),XDisplayCells(dpy,screen));

	myVis = gr_GetVisual(dpy, DefaultScreen(dpy));
	switch (myVis->class) {
		case StaticGray:
			sprintf(buff2,buff,"StaticGray");
			break;
		case GrayScale:
			sprintf(buff2,buff,"GrayScale");
			break;
		case StaticColor:
			sprintf(buff2,buff,"StaticColor");
			break;
		case PseudoColor:
			sprintf(buff2,buff,"PseudoColor");
			break;
		case TrueColor:
			sprintf(buff2,buff,"TrueColor");
			break;
		case DirectColor:
			sprintf(buff2,buff,"DirectColor");
			break;
		}
	gr_TextMsgOut(buff2);
        /* printf("initximage returns\n"); */
} /* Initialize() */


/****************** All that's left of xstuff.c **************************/
Widget MakeRasterImage(shellName,parent,x,y,image,cmap,callBackProc,cbp_param)
char		*shellName;
Widget		parent;
int		x,y;
XImage		*image;
Colormap	cmap;		/* added by gbourhis Jan 93 */
XtCallbackProc	callBackProc;
caddr_t		cbp_param;
{
        Widget	w;
	Arg	argList[10];
	Cardinal i=0;

	XtSetArg(argList[i],XtNx,x);	i++;
	XtSetArg(argList[i],XtNy,y);	i++;
	XtSetArg(argList[i],XtNsRimage,image);	i++;
	XtSetArg(argList[i],XtNinvertOnSelect,False);	i++;

	/* create the widget unmanaged. gbourhis Jan 93 */
	w = XtCreateWidget(shellName,XwsrasterWidgetClass,
				parent,argList,i);
	if (callBackProc)
		XtAddCallback(w,"select",callBackProc,cbp_param);

#ifdef XtSpecificationRelease
	/* use the intrinsics to set the colormap. gbourhis Jan 93 */
	i = 0;
	XtSetArg(argList[i],XtNcolormap, cmap); i++;
	XtSetValues(w, argList, i);
#endif /* XtSpecificationRelease */

	XtManageChild(w);	/* gbourhis Jan 93 */

	return(w);

} /* MakeRasterImage() */
/* #endif XIMAGE_PALETTE*/
