/*
 *      XCountdown - X version of the popular Channel 4 quiz show
 *
 * This software comes with NO warranty whatsoever. I therefore take no
 * responsibility for any damages, losses or problems caused through use
 * or misuse of this program.
 *
 * I hereby grant permission for this program to be freely copied and
 * distributed by any means, provided no charge is made for it.
 *
 * Matthew Chapman, csuoq@csv.warwick.ac.uk
 *    June 1995.
 */

/* mess.c - simple message routines */

#include "xcountdown.h"
#include "globals.h"

void DoMess(char *mess,int delay);
void ClearMess();
Boolean IsClear(void);
void WaitForMess(void);

static Boolean waiting=False;
static int len=0;

/* displays a message, after waiting for a previous one to clear, if required */
void DoMess(char *mess,int delay)
{
    while (waiting)
	ProcessEvent();
		
    if ((int)strlen(mess)>0)
    {
	XawTextBlock txt;
	int i;
	char *blk="";
		
	waiting=True;
	/* clear previous message if required */
	if (len>0)
	{
	    txt.firstPos=0;
	    txt.format=FMT8BIT;
	    txt.length=strlen(blk);
	    txt.ptr=blk;
	    for (i=0; i<NP; i++)
		XawTextReplace(richard[i],0,len,&txt);
	}
	/* show message on all displays */
	txt.firstPos=0;
	txt.format=FMT8BIT;
	txt.length=strlen(mess);
	len=txt.length;
	txt.ptr=mess;
	for (i=0; i<NP; i++)
	    XawTextReplace(richard[i],0,0,&txt);
    }
    XtAppAddTimeOut(app_context,delay,ClearMess,NULL);
}

/* mark the message as done, but don't clear it - it stays until replaced */
void ClearMess()
{
    waiting=False;
}

/* returns True if there are no active messages, else False */
Boolean IsClear()
{
    return(!waiting);
}

/* wait until the current message clears */
void WaitForMess()
{
    while(waiting)
	ProcessEvent();
}
