/*
(c) Copyright 1988-1994 Microsoft Corporation.

Microsoft Bars&Pipes Professional Source Code License

This License governs use of the accompanying Software.  
Microsoft hopes you find this Software useful.

You are licensed to do anything you want with the Software. 

In return, we simply require that you agree:

1.      Not to remove any copyright notices from the Software.

2.      That the Software comes "as is", with no warranties.  
        None whatsoever. This means no implied warranty of merchantability or 
        fitness for a particular purpose or any warranty of non-infringement.  
        Also, you must pass this disclaimer on whenever you distribute the Software.

3.      That we will not be liable for any of those types of damages known as indirect, 
        special, consequential, or incidental related to the Software or this License, 
        to the maximum extent the law permits. Also, you must pass this limitation of 
        liability on whenever you distribute the Software.

4.      That if you sue anyone over patents that you think may apply to the Software 
        for that person’s use of the Software, your license to the Software ends automatically.

5.      That the patent rights Microsoft is licensing only apply to the Software, 
        not to any derivatives you make.

6.      That your rights under the License end automatically if you breach this in any way.
*/

#include "/CompilerSpecific.h"
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <graphics/gfxbase.h>
#include "/v.h"

static struct Window *Owin;
extern char version[];
extern char username[];
extern char serialno[];

static void prcenter(struct Window *win,short y,char *str)
{
  short sl;

  sl=strlen(str);
  Move(win->RPort,(win->Width-TextLength(win->RPort,str,sl))>>1,y);
  Text(win->RPort,str,sl);
}

void openopener(struct Screen *scr)
{
  struct TextFont *f;
  struct Screen mscr;
  char buf[80];
  struct NewWindow nw;
  short pen1,pen2;
  memset(&nw,0,sizeof(nw));
  nw.DetailPen=nw.BlockPen=-1;
  if(scr==NULL)
  {
    nw.Type=WBENCHSCREEN;
    nw.Screen=NULL;
    GetScreenData(&mscr,sizeof(struct Screen),WBENCHSCREEN,0);
    scr=&mscr;
    pen1=1;
    pen2=2;
  }
  else
  {
    nw.Type=CUSTOMSCREEN;
    nw.Screen=scr;
    pen1=2;
    pen2=0;
    nw.Flags=ACTIVATE|BORDERLESS;
  }
  f=GfxBase->DefaultFont;
  nw.Width=56*f->tf_XSize;
#ifdef DEMO
  nw.Height=7*f->tf_YSize;
#else
  nw.Height=11*f->tf_YSize;
#endif
  nw.LeftEdge=(scr->Width-nw.Width)>>1;
  nw.TopEdge=(scr->Height-nw.Height)>>1;
  nw.MinWidth=nw.MaxWidth=nw.Width;
  nw.MinHeight=nw.MaxHeight=nw.Height;
//  nw.IDCMPFlags=MOUSEBUTTONS|RAWKEY;
  Owin=OpenWindow(&nw);
  if(Owin)
  {
    SetFont(Owin->RPort,f);
    if(pen1==1)
    {
      SetRast(Owin->RPort,pen1);
      RefreshWindowFrame(Owin);
    }
    else
        EmbossRequestOn(Owin,NULL);
    SetAPen(Owin->RPort,pen2);
    SetDrMd(Owin->RPort,JAM1);
    prcenter(Owin,f->tf_YSize + f->tf_Baseline,version+6);
    prcenter(Owin,f->tf_YSize*3 + f->tf_Baseline,"© 1991,1994 The Blue Ribbon SoundWorks, Ltd.");
#ifdef DEMO
    prcenter(Owin,f->tf_YSize*5 + f->tf_Baseline,"Demo Version - Call (404)315-0212 to place your order!");
#else
#ifdef ENGLISH
    prcenter(Owin,f->tf_YSize*5 + f->tf_Baseline,"This copy licensed to:");
#endif
#ifdef GERMAN
    prcenter(Owin,f->tf_YSize*5 + f->tf_Baseline,"Diese Lizenzkopie gehört:");
#endif
    prcenter(Owin,f->tf_YSize*7 + f->tf_Baseline,username+6);
    sprintf(buf,"Serial #: %s",serialno+6);
    prcenter(Owin,f->tf_YSize*9 + f->tf_Baseline,buf);
#endif
  }
}

void openbadserial(void)
{
  struct TextFont *f;
  struct Screen mscr,*scr;
  struct NewWindow nw;
  struct IntuiMessage *msg;
  short done;

  memset(&nw,0,sizeof(nw));
  nw.DetailPen=nw.BlockPen=-1;
  nw.Type=WBENCHSCREEN;
  nw.Screen=NULL;
  GetScreenData(&mscr,sizeof(struct Screen),WBENCHSCREEN,0);
  scr=&mscr;
  f=GfxBase->DefaultFont;
  nw.Width=54*f->tf_XSize;
  nw.Height=9*f->tf_YSize;
  nw.LeftEdge=(scr->Width-nw.Width)>>1;
  nw.TopEdge=(scr->Height-nw.Height)>>1;
  nw.MinWidth=nw.MaxWidth=nw.Width;
  nw.MinHeight=nw.MaxHeight=nw.Height;
  nw.IDCMPFlags=MOUSEBUTTONS|RAWKEY;
  nw.Flags=ACTIVATE;
  Owin=OpenWindow(&nw);
  if(Owin)
  {
    SetRast(Owin->RPort,1);
    RefreshWindowFrame(Owin);
    SetAPen(Owin->RPort,2);
    SetDrMd(Owin->RPort,JAM1);
    prcenter(Owin,f->tf_YSize + f->tf_Baseline,version+6);
#ifdef ENGLISH
    prcenter(Owin,f->tf_YSize*3 + f->tf_Baseline,"© 1991,1994 The Blue Ribbon SoundWorks, Ltd.");
    prcenter(Owin,f->tf_YSize*5 + f->tf_Baseline,"You must run the Install program");
    prcenter(Owin,f->tf_YSize*7 + f->tf_Baseline,"before running Bars&Pipes Pro 2.5.");
#endif
#ifdef GERMAN
    prcenter(Owin,f->tf_YSize*3 + f->tf_Baseline,"© 1991,1992 The Blue Ribbon SoundWorks, Ltd.");
    prcenter(Owin,f->tf_YSize*5 + f->tf_Baseline,"Sie mÜssen das Install-Programm");
    prcenter(Owin,f->tf_YSize*7 + f->tf_Baseline,"starten und dann Bars&Pipes Pro 2.0.");
#endif
    for(done=0;done==0;)
    {
      WaitPort(Owin->UserPort);
      msg=(struct IntuiMessage *)GetMsg(Owin->UserPort);
      if((msg->Class==MOUSEBUTTONS && msg->Code==SELECTDOWN) || msg->Class==RAWKEY)
          done=1;
      ReplyMsg((struct Message *)msg);
    }
    CloseWindow(Owin);
  }
}

void openerwait(void)
{
  struct IntuiMessage *msg;
  short done;

  if(Owin)
  {
    ModifyIDCMP(Owin,MOUSEBUTTONS|RAWKEY);
    for(done=0;done==0;)
    {
      WaitPort(Owin->UserPort);
      msg=(struct IntuiMessage *)GetMsg(Owin->UserPort);
      if((msg->Class==MOUSEBUTTONS && msg->Code==SELECTDOWN) || msg->Class==RAWKEY)
          done=1;
      ReplyMsg((struct Message *)msg);
    }
  }
}

void closeopener(void)
{
  if(Owin)
      CloseWindow(Owin);
}

char *toolnamelist = "s:tools";
char *accessnamelist = "s:accessories";
