/*************************************************************************/
/* Autor      : RTA                                                      */
/* Computer   : Amiga                                                    */
/* Sprache    : Ansi C                                                   */
/* Compiler   : SAS C-Compiler Version 5.1a                              */
/* Dateiname  : window.c                                                 */
/* Projekt    : OnlineHelp                                               */
/* Erstellt am: 10 Nov 1991,12:48                                        */
/*************************************************************************/

#include "online.h"

/*************************************************************************/
/*                    Schließt das OnlineHelp Window                     */
/*************************************************************************/
void closewin()
{
	/* Schließe den CON Message und Port */
  	if(conwritemsg)
   	{
   	CloseDevice(conwritemsg);
   	DeleteStdIO(conwritemsg);
   	conwritemsg=NULL;
   	}
  	if(conwriteport)
  		{
      DeletePort(conwriteport);
      conwriteport=NULL;
      }

	/* Setzte ProcessPtr zurück und schließe das Window */
   if(mywindow)
  		{
	   myprocess->pr_WindowPtr=(APTR)oldwindow;
      CloseWindow(mywindow);
      mywindow=NULL;
      myscreen=NULL;
      }
}

/*************************************************************************/
/*                     Öffnet das OnlineHelp Window                      */
/*************************************************************************/
BOOL openwin()
{
static BYTE     titelspeicher[100];

struct NewWindow new_window = {
  47,78,528,50,0,1,
  NEWSIZE+GADGETUP+CLOSEWINDOW+RAWKEY,
  WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SMART_REFRESH+ACTIVATE,
  NULL,NULL,
  NULL,NULL,NULL,
  480,60,640,200,CUSTOMSCREEN };


#define NEWWINDOW   new_window

	if(mywindow)return(TRUE);

   sprintf(titelspeicher,"OnlineHelp %s Copyright by Ralph-Thomas Außem Alle Rechte vorbehalten",VERSION);

	if(!myscreen) myscreen=IntuitionBase->ActiveScreen;
   maxx               = myscreen->Width;
   maxy               = myscreen->Height;

   NEWWINDOW.Screen   = myscreen;
   NEWWINDOW.Width    = winwidth;
   NEWWINDOW.Height   = winheight;
   NEWWINDOW.MaxWidth = maxx;
   NEWWINDOW.MaxHeight= maxy;
	NEWWINDOW.Title	 =	errortext.nodocs;

	if((wintop>=winheight) || (winleft>=winwidth))   Center(&NEWWINDOW,0,0);
	else {NEWWINDOW.LeftEdge=winleft;NEWWINDOW.TopEdge=wintop;}

   if(!(mywindow=(struct Window *)OpenWindow(&NEWWINDOW)))
   	{
   	SimpleRequest(errortext.nowindow);
   	return(FALSE);
   	}

   SetWindowTitles(mywindow,(char *)-1L,titelspeicher);

	myprocess    = (struct Process *)FindTask(0L);
	oldwindow    = (APTR)myprocess->pr_WindowPtr;
	myprocess->pr_WindowPtr = (APTR)mywindow;

   /* Öffnen des Console Devices => Löschen des Bildschirmes */
   if(!opencon()) closeall(NULL);

	return(TRUE);
}