/*	Copyright_xwin.cpp
 *
 *		Copyright display routines (stubs)
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XApplication.h>
#include <XDraw.h>
#include <XWindow.h>
#include <XDataUtil.h>

#include <time.h>
#include <sys/times.h>

/************************************************************************/
/*																		*/
/*	Globals																*/
/*																		*/
/************************************************************************/

static clock_t		GTimer;
static Window		GCopyWindow;

/************************************************************************/
/*																		*/
/*	Temporary copyright window											*/
/*																		*/
/************************************************************************/

/*	XGAppCore::OpenCopyright
 *
 *		Open the copyright window
 */

void XGAppCore::OpenCopyright(void)
{
	void *data;
	Rect r;
	XSetWindowAttributes attrib;
	Point size;
	int i;
	GC gc;
	struct tms buf;
	
	/*
	 *	Get the bitmap
	 */
	
	data = ::GetResourceData('bmap',128);
	if (data == NULL) return;				// does it exist?
	size = GetBitmapSize(128);
	r.left = 0;
	r.top = 0;
	i = DefaultScreen(_GDisplay);
	r.right = DisplayWidth(_GDisplay,i);
	r.bottom = DisplayHeight(_GDisplay,i);

	r.left = (r.right - size.h) / 2;
	r.right = r.left + size.h;
	r.top = (r.bottom - size.v) / 2;
	r.bottom = r.top + size.v;
	
	/*
	 *	Pop open the window
	 */
	
	attrib.event_mask = KeyPressMask |
						ButtonPressMask |
						ButtonReleaseMask |
						EnterWindowMask |
						LeaveWindowMask |
						PointerMotionMask |
						ExposureMask |
						StructureNotifyMask |
						ColormapChangeMask;
	attrib.override_redirect = true;
	GCopyWindow = ::XCreateWindow(_GDisplay,
							  DefaultRootWindow(_GDisplay),
							  r.left,
							  r.top,
							  r.right-r.left,
							  r.bottom-r.top,
							  0,
							  CopyFromParent,
							  InputOutput,
							  CopyFromParent,
							  CWEventMask | CWOverrideRedirect,
							  &attrib);
	::XMapRaised(_GDisplay,GCopyWindow);
	
	/*
	 *	Now draw the contents into a created graphics context
	 */
	
	gc = ::XCreateGC(_GDisplay,GCopyWindow,0,NULL);
	::DrawXBitmap(_GDisplay,GCopyWindow,gc,128,0,0);
	::XFreeGC(_GDisplay,gc);
	::XFlush(_GDisplay);
	
	/*
	 *	And store the current time
	 */
	
	GTimer = times(&buf) + CLK_TCK * 2;
}

/*	XGAppCore::CloseCopyright
 *
 *		Delay and then close. This guarentees a minimum 2 second delay
 */

void XGAppCore::CloseCopyright(void)
{
	struct tms buf;
	while (GTimer > times(&buf)) ;
	
	::XDestroyWindow(_GDisplay,GCopyWindow);
}

/*	XGAppCore::ShowCopyright
 *
 *		Show the copyright and wait until mouse or keyboard events
 */

void XGAppCore::ShowCopyright(void)
{
}
