/*************************************************************************/
/*                                                                       */
/* C-Beispielprogramm für die Get-It ( Diskettenmagazin der AIT-UG )     */
/*                                                                       */
/* Kurs 2 : IDCMP-Demo                                                   */
/* Datum : 10.1.89                                                       */
/*                                                                       */
/* Keine Copyrights irgendwelcher Art auf die folgenden Zeilen.          */
/*                                                                       */
/*************************************************************************/

#include <intuition/intuition.h>

char Nachricht[][50] =
{ "intuition.library läßt sich nicht öffnen !\n",
  "Fenster läßt sich nicht öffnen !\n"
};

struct IntuitionBase *IntuitionBase = NULL;

struct NewWindow NeuFenster =
{ 50,40,
  540,176,
  0,1,
  CLOSEWINDOW,
  WINDOWCLOSE | ACTIVATE | RMBTRAP | WINDOWSIZING,
  NULL,
  NULL,
  " Fenster ( einen Augenblick ! )",
  NULL,
  NULL,
  50,60,
  600,200,
  WBENCHSCREEN
};

struct Window *Fenster = NULL;

main()
{ IntuitionBase = OpenLibrary ( "intuition.library",0 );
  if ( IntuitionBase == NULL )
    notaus ( Nachricht[0] );

  Fenster = OpenWindow( &NeuFenster );
  if ( Fenster == NULL )
    notaus ( Nachricht[1] );

  SetWindowTitles ( Fenster,"Abbruch jederzeit mit CLOSEGADGET !",-1 );
  Delay ( 150 );

  Warte ( " Rechten Mausknopf, dann weiter !",MOUSEBUTTONS,MENUUP );
  Warte ( " Taste b, dann weiter !",RAWKEY,0x35 );
  Warte ( " Diskette einlegen, dann weiter !",DISKINSERTED,0 );
  Warte ( " Fenstergröße ändern, dann weiter !",NEWSIZE,0 );
  Warte ( " Fenster inaktivieren, dann Schluß !",INACTIVEWINDOW,0 );
  notaus( NULL );
}

notaus ( txt )
char *txt;
{ if ( txt != NULL )
    printf ( txt );
  if ( Fenster != NULL )
    CloseWindow ( Fenster );
  if ( IntuitionBase != NULL )
    CloseLibrary ( IntuitionBase );
  if ( txt != NULL )
    exit ( 100 );
  exit ( 0 );
}

Warte ( string,ereignis,art )
char *string;
ULONG ereignis;
USHORT art;
{ struct IntuiMessage *mess;
  ULONG class;
  USHORT code;
  BOOL aus;

  SetWindowTitles ( Fenster,string,-1 );
  Delay ( 10 );
  ModifyIDCMP ( Fenster, CLOSEWINDOW | ereignis );

  do
  { Wait ( 1 << Fenster->UserPort->mp_SigBit );
    mess = GetMsg ( Fenster->UserPort );
    class = mess->Class;
    code = mess->Code;
    ReplyMsg ( mess );
    if ( ereignis == class && art == 0 )
      art = code;
    aus = code == art || class == CLOSEWINDOW;
  } while ( !aus );
  if ( class == CLOSEWINDOW )
    notaus ( NULL );
}
