/***************************************************************************/
/*                                                                         */
/*	    window.c  -  v. 1.0  - 1.7.88  -  Antonio Ferrillo             */
/*                                                                         */
/*           funzioni di gestione di finestre sotto Intuition              */
/*                                                                         */ 
/*           versione Aztec 3.4  Lattice-compatibile                       */
/*                                                                         */
/***************************************************************************/ 

  #include <functions.h> /* rimuovere questa linea se si usano 
                            i compilatori Lattice  v. 3.XX  */

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

  static struct  Window  *a_window[] = {NULL, NULL, NULL, NULL};
  static struct  NewWindow   NewWindow[4];

/*--------------------------------------------------------------------------
-  int
-  Window_Open(wn,widen,le,te,wi,he,dp,bp,mode,sn)
- 
-     FUNZIONE  : apertura di finestra : e' possibile aprire fino a 4 finestre
-                 contemporaneamente
- 
-     ARGOMENTI : int wn;      - (valore = da 1 a 4)  numero della
-                                finestra da aprire.
-
-                 char *widen; - stringa col nome della finestra 
-                   
-                 int le;      - (valore da 0 a 589 dipendente dalla 
-                                risoluzione orizzontale dello schermo)
-                                distanza dal bordo sinistro dello schermo
-                   
-                 int te;      - (valore da 0 a 480 dipendente dalla
-                                risoluzione verticale dello schermo)
-                                distanza dal top dello schermo
-
-                 int wi;      - (valore da 50 a 640 dipendente dalla
-                                risoluzione orizzontale dello schermo)
-                                larghezza della finestra
-                   
-                 int he;      - (valore da 0 a 512 dipendente dalla
-                                risoluzione verticale dello schermo) 
-                                altezza della finestra
-
-                 int dp;      - (valore da 0 a 31 dipendente dal numero
-                                dei bit-planes dello schermo) detail pen  
-                   
-                 int bp;      - (valore da 0 a 31 dipendente dal numero
-                                dei bit-planes dello schermo) block pen 
-                   
-                   primi 8 colori approssimativi : 0 -  blu,   1 - bianco,
-                                       2 - nero,   3 - giallo, 4 - azzurro,
-                                       5 - rosso,  6 - verde,  7 - bianco                                    
-                  
-                 int sn;      - numero dello schermo sul quale deve 
-                                essere aperta la finestra (se uguale a NULL
-                                la finestra viene aperta sullo schermo
-                                del Workbench)
-
-      RITORNO   : TRUE se l'apertura e' andata a buon fine
-                  FALSE se e' sopravvenuto un errore
- 
-      NOTE      : richiede precedente apertura di intuition.library.
-                  ricordarsi di chiudere la finestra a fine
-                  lavoro mediante la Window_Close.
----------------------------------------------------------------------------*/

  int
  Window_Open(wn,widen,le,te,wi,he,dp,bp,sn)

  int     wn;
  char    *widen;
  int     le;
  int     te;
  int     wi;
  int     he;
  int     dp;
  int     bp;
  int     sn;

  {
    struct Screen *Screen_Addr();
 
    if(wn < 1 || wn > 4) return(FALSE);
    if(le < 0 || (le + wi) > 640) return(FALSE);
    if(te < 0 || (te + he) > 512) return(FALSE);
    if(dp < 0 || dp > 31) return(FALSE);
    if(bp < 0 || bp > 31) return(FALSE);
  
    if(a_window[wn-1] != NULL) return(FALSE);
  
    wn -= 1;

    NewWindow[wn].LeftEdge    = le;
    NewWindow[wn].TopEdge     = te;
    NewWindow[wn].Width       = wi;
    NewWindow[wn].Height      = he;
    NewWindow[wn].DetailPen   = dp;
    NewWindow[wn].BlockPen    = bp;
    NewWindow[wn].Title       = (UBYTE *)widen;

    NewWindow[wn].Flags       =   ACTIVATE
                                | SMART_REFRESH
                                | REPORTMOUSE
                                | WINDOWCLOSE 
                                | WINDOWDRAG
                                | WINDOWDEPTH 
                                | WINDOWSIZING;

    NewWindow[wn].IDCMPFlags  =   CLOSEWINDOW 
                                | REFRESHWINDOW 
                                | GADGETDOWN
                                | GADGETUP 
                                | MOUSEBUTTONS
                                | MOUSEMOVE  
                                | REQCLEAR 
                                | SELECTDOWN 
                                | SELECTUP
                                | ACTIVEWINDOW 
                                | MENUPICK;
    NewWindow[wn].Type        = ((sn == NULL) ? WBENCHSCREEN : CUSTOMSCREEN);
    NewWindow[wn].FirstGadget = NULL;
    NewWindow[wn].CheckMark   = NULL;
    NewWindow[wn].Screen      = (sn == NULL) ? NULL : Screen_Addr(sn);
    NewWindow[wn].BitMap      = NULL;
    NewWindow[wn].MinWidth    = 50;
    NewWindow[wn].MinHeight   = 25;
    NewWindow[wn].MaxWidth    = wi;
    NewWindow[wn].MaxHeight   = he;

    a_window[wn] =  (struct Window *) OpenWindow(&NewWindow[wn]);
   
    if (a_window[wn] == NULL) return(FALSE);

    return(TRUE);
  }


/*---------------------------------------------------------------------------        
-    struct Window *
-    Window_Addr(wn)
-      
-      FUNZIONE  : restituisce l'indirizzo della finestra wn
-                  oppure FALSE in caso di errore
-       
-      ARGOMENTI : int wn;  - (valore da 1 a 4) numero della finestra  
---------------------------------------------------------------------------*/                  

  struct  Window  *
  Window_Addr(wn)
  int     wn;
  {
    if (wn < 1 || wn > 4) return(FALSE);
    if (a_window[wn-1] == NULL) return(FALSE);
      return(a_window[wn-1]);
  }

 

/*---------------------------------------------------------------------------
-    int
-    Window_Close(wn)
-
-        FUNZIONE  : chiusura della finestra
-
-        ARGOMENTI : int wn; - (valore da 1 a 4) numero della finestra  
---------------------------------------------------------------------------*/

  int
  Window_Close(wn)
  int   wn;
  {
    if (wn < 1 || wn > 4) return(FALSE);
    if (a_window[wn - 1] == NULL) return(FALSE);
            CloseWindow(a_window[wn - 1]);
            return(TRUE);
  }

