//##ex mcpp:cppc -gs -o OpenWindowTags p:pLib/MainCode.o -pc OpenWindowTags.c p:pLib/StdIO.o -l pOSxA -l pOSStub -l pOS -l List

/*\
*** 31.01.1997, Michael Christoph, proDAD
*** Example:
\*/

#define INTUI_V36_NAMES_ONLY

#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

BOOL pOS_CmpDoubleClick(_R_A0 const struct pOS_DoubleKlick* just,_R_A1 const struct pOS_DoubleKlick*)
{return(FALSE);}

#ifdef LATTICE
int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
int chkabort(void) { return(0); }  /* really */
#endif

UBYTE *vers = "$VER: OpenWindowTags 1.0 (31.01.1997) (proDAD, Michael Christoph)";

#define MY_WIN_LEFT   (20)
#define MY_WIN_TOP    (10)
#define MY_WIN_WIDTH  (300)
#define MY_WIN_HEIGHT (110)

void handle_window_events(struct Window *);

#ifdef __pOS__
struct pOS_IntuiDevice  *gb_IntuiBase;
struct pOS_GfxBase      *gb_GfxBase;      /*** wird zusätzlich benötigt ***/
struct pOS_UtilityBase  *gb_UtilityBase;  /*** wird zusätzlich benötigt ***/
#else
struct Library *IntuitionBase;
#endif

struct TagItem win_tags[] =
{
    {WA_Left,       MY_WIN_LEFT},
    {WA_Top,        MY_WIN_TOP},
    {WA_Width,      MY_WIN_WIDTH},
    {WA_Height,     MY_WIN_HEIGHT},
    {WA_CloseGadget,TRUE},
    {WA_IDCMP,      IDCMP_CLOSEWINDOW},
    {TAG_DONE, NULL},
};

/*
** Open a simple window using OpenWindowTagList()
*/
VOID main(int argc, char **argv)
{
  struct Window *win;

/* these calls are only valid if we have Intuition version 37 or greater */
#ifdef __pOS__
  if(gb_UtilityBase=(struct pOS_UtilityBase *) pOS_OpenLibrary("pUtility.library",0))
  {
  if(gb_GfxBase=(struct pOS_GfxBase *) pOS_OpenLibrary("pGraphics.library",0))
  {
  if(gb_IntuiBase=(struct pOS_IntuiDevice*) pOS_OpenLibrary("pIntui.library",0))
#else
  if(IntuitionBase = OpenLibrary("intuition.library",37))
#endif
  {
    win = OpenWindowTagList(NULL,win_tags);
    if (win==NULL)
    {
        /* window failed to open */
    }
    else
    {
        /* window successfully opened here */
        handle_window_events(win);

        CloseWindow(win);
    }
#ifdef __pOS__
    pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
#else
    CloseLibrary((struct Library *)IntuitionBase);
#endif
  }
#ifdef __pOS__
  pOS_CloseLibrary((struct pOS_Library*)gb_GfxBase);
  }
  pOS_CloseLibrary((struct pOS_Library*)gb_UtilityBase);
  }
#endif
}

/* Normally this routine would contain an event loop like the one given
** in the chapter "Intuition Input and Output Methods".  Here we just
** wait for any messages we requested to appear at the Window's port.
*/
VOID handle_window_events(struct Window *win)
{
  WaitPort(win->UserPort);
}
