/*
 * 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: del_page.c
 * Date: 04/26/91
 *
 * Description:
 *   This file contains the delete page popup dialog box.
 *
 * Revisions:
 ****************************************************************/
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/MessageB.h>
#include <X11/StringDefs.h>
#include <malloc.h>

#include <VList.h>

#include "VtP.h"

typedef struct
{
	Widget pop;
	int (*cb)();
	XtPointer args;
} LocalInfo;

/* Delete Button callback.  Destroys popup and executes function */
/*ARGSUSED*/
static
void
sel_delete(wd,info)
	Widget wd;
	LocalInfo *info;
{
	int (*cb)() = info->cb;
	XtPointer args = info->args;

	XtDestroyWidget(info->pop);
	cb(args,TRUE);
}

/* Kepp Button callback.  Destroys popup and executes function */
/*ARGSUSED*/
static
void
sel_keep(wd,info)
	Widget wd;
	LocalInfo *info;
{
	int (*cb)() = info->cb;
	XtPointer args = info->args;

	XtDestroyWidget(info->pop);
	cb(args,FALSE);
}

/* Cancel callback.  Just destroys widget */
/*ARGSUSED*/
static
void
sel_cancel(wd,info)
	Widget wd;
	LocalInfo *info;
{
	XtDestroyWidget(info->pop);
}

/* Destroy callback */
/*ARGSUSED*/
static
void
sel_destroy(wd,info)
	Widget wd;
	LocalInfo *info;
{
	free((char *)info);
}

PUBLIC
void
VtDeletePage(parent,msg,callback,data)
	Widget parent;
	char *msg;
	int (*callback)();
	XtPointer data;
{
	LocalInfo *info = (LocalInfo *)malloc(sizeof *info);
	Widget pop,delete,keep,cancel;
	XmString xm_msg;
	XmString xm_ok;
	XmString xm_cancel;
	XmString xm_help;
	Arg args[10];
	int n;

	xm_msg = XmStringCreateLtoR(msg,XmSTRING_DEFAULT_CHARSET);
	xm_ok = XmStringCreateLtoR("Delete Links",XmSTRING_DEFAULT_CHARSET);
	xm_cancel = XmStringCreateLtoR("Keep Links",XmSTRING_DEFAULT_CHARSET);
	xm_help = XmStringCreateLtoR("Cancel",XmSTRING_DEFAULT_CHARSET);

	n = 0;
	XtSetArg(args[n],XmNdialogStyle,XmDIALOG_APPLICATION_MODAL); n++;
	XtSetArg(args[n],XmNokLabelString,xm_ok); n++;
	XtSetArg(args[n],XmNcancelLabelString,xm_cancel); n++;
	XtSetArg(args[n],XmNhelpLabelString,xm_help); n++;
	XtSetArg(args[n],XmNmessageString,xm_msg); n++;
	XtSetArg(args[n],XmNdefaultButtonType,XmDIALOG_HELP_BUTTON); n++;
	pop = XmCreateQuestionDialog(parent,"Delete Page",args,n);

	XmStringFree(xm_msg);
	XmStringFree(xm_ok);
	XmStringFree(xm_cancel);
	XmStringFree(xm_help);

	XtAddCallback(pop,XmNdestroyCallback,sel_destroy,(XtPointer)info);

	delete = XmMessageBoxGetChild(pop,XmDIALOG_OK_BUTTON);
	keep = XmMessageBoxGetChild(pop,XmDIALOG_CANCEL_BUTTON);
	cancel = XmMessageBoxGetChild(pop,XmDIALOG_HELP_BUTTON);
	XtAddCallback(delete,XmNactivateCallback,sel_delete,(XtPointer)info);
	XtAddCallback(keep,XmNactivateCallback,sel_keep,(XtPointer)info);
	XtAddCallback(cancel,XmNactivateCallback,sel_cancel,(XtPointer)info);

	info->pop = pop;
	info->cb = callback;
	info->args = data;

	XtManageChild(pop);
}
