/* version 2.37
 */
#ifndef __UTILS_H
#define __UTILS_H

#include <intuition/intuition.h>
#include <devices/timer.h>
#include <exec/ports.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <libraries/notifyintuition.h>
#include <workbench/startup.h>
#include <intuition/classes.h>


#define ERRORNOMEM  1
#define ERRORNOPORT 2
#define ERRORUNKNOWNCMD 3
#define OK         -1

#define TITLE          "BackClock V3.2"
#define VERSION_STRING "\0$VER: " TITLE " (15.08.99)"
#define VERSION        32 // for prefs prog
/* max width
 */
#define MAXH       1000


struct RGB {
  /* for compatibility
    */
  UWORD R,
        G,
        B,
        pad ;
  ULONG reg ;
} ;
/* the color used
 */
#define NUM_LED_COLORS 2 // number of colors for the leds
#define COL_LBG    0     // background
#define COL_LFG    1     // foreground

#define NUM_COLORS 7
#define COL_SEC    0
#define COL_MIN    1
#define COL_HEU    2
#define COL_TIC    3
#define COL_BAC    4
#define COL_MPO    5
#define COL_BLA    6

/* IDCMP and FLAGS as you see it :) 
 */
#define IDCMP IDCMP_CHANGEWINDOW|IDCMP_NEWSIZE|IDCMP_MOUSEBUTTONS|IDCMP_ACTIVEWINDOW|IDCMP_INACTIVEWINDOW
#define WFLG  WFLG_BACKDROP|WFLG_BORDERLESS
/* the workbench title
 */
#define TXT_SCRTITLE "BackClock"

struct specWin {
  ULONG posX,                  // X pos
        posY,                  // Y pos     window
        width,                 // width
        height ;               // height
  struct RGB cmap[NUM_COLORS] ; // colors
  UWORD  fill ;                 // fill background ?
  UWORD  filln ;                // fill arrows ?
  UWORD  drawsec ;              // draw seconds arrow ?
  UWORD  drawsha ;              // draw shadow ?
  UWORD  drawmpo ;              // draw middle point ?
  /* new in 3.1
   */
  WORD   OffXS,                 // shadow offset (X & Y, can be + / -)
         OffYS ;
  UWORD  Slength ;              // shadow distance
  UWORD  leds ;                 // show leds
  /* new in 3.2
   */
  struct RGB lcmap[NUM_LED_COLORS] ; // color map for leds

  UWORD  future[7] ;           // for future use
} ;

struct prjSt {
  struct Window * win ;                   // filled by OpenWindow()
  struct DateStamp * date ;               // internal date format
  char   datestr[10] ;                    // ascii date
  UWORD  heu ;                                                                                          // heure
  UWORD  min ;                                                                                          // minute
  UWORD  sec ;                                                                                          // secondes
  struct timerequest * treq ;                   // I/O request for timer.device
  struct MsgPort     * trport ;                 // port rply timer
  UWORD  timerok ;                                                                           // ouverture timer ok
  struct IntNotifyRequest * Notify ;            // request for notify
  struct MsgPort          * notifyPort ;        // port reply notify
  struct specWin backWin ;
  ULONG  lastError ;
  struct Screen   * wb ;                          // lock to WB
  struct RastPort * RP1 ;                       // tmp rp 1
  struct RastPort * RP2 ;                       // tmp rp 2
  struct TmpRas   * tmpras ;                    // tmpras vertice
  struct AreaInfo * ai ;
  struct ClassLibrary * imlib ;                 // the led.image library
  struct Image        * im ;                    // the leds
} ;
struct backMsg {
  struct Message execmsg ;
  ULONG Class ; 
  APTR  ptrPrj ; // pointeur sur prj à retourner lors d'un BC_GetPrj
  LONG  error ;  // contient l'erreur de retour (or the version on BC_GetVersion)
} ;

/* class of messages
 * new for 3.1 don't use 16 bits msb (used for version check)
 */
#define BC_Quit          0x00000001 // recu demande d'arret externe
#define BC_GetPrj        0x00000002 // recu l'envoi adresse prj
#define BC_Refresh       0x00000003 // recu demande de rafraichissement
#define BC_SaveConf      0x00000004 // reçu demande de sauvegarde prefs
#define BC_UseConf       0x00000005 // reçu demande d'utiliser nouvelle prefs
#define BC_SetWindow     0x00000006 // pos & taille window changées
#define BC_RefreshColors 0x00000007 // colors changed



typedef struct prjSt idWin ;

// proto  
idWin * init(struct WBArg *) ;
void close(idWin *) ;
void getDate(idWin *) ;
void writeDate(idWin *) ;
__asm __saveds DateToByte(register __a0 char *, register __a1 idWin *) ;
void initwin(idWin * prj) ;
void processwin(idWin* prj) ;
void effacer(idWin * prj) ;
void retracer(idWin * prj) ;
void runtimer(idWin * prj,long) ;
void setArgs(idWin * prj, LONG * args) ;
int exists() ;
void ez_req(UBYTE *, UBYTE *, UBYTE *, APTR) ;
#endif
