/* Global gear for EngClock */


/************* Includes ************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <intuition/intuition.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <exec/devices.h>
#include <exec/execbase.h>
#include <exec/exec.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <clib/intuition_protos.h>
#include <libraries/diskfont.h>
#include <clib/diskfont_protos.h>
#include <graphics/scale.h>
#include <clib/graphics_protos.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/utility_protos.h>
//#include <proto/timer.h>
#include <clib/timer_protos.h>
#include <pragmas/timer_pragmas.h>
#include <utility/utility.h>
#include <utility/date.h>
#include <workbench/startup.h>
#include <clib/dos_protos.h>
#include <clib/gadtools_protos.h>
#include <datatypes/pictureclass.h>
#include <clib/commodities_protos.h>

/************** Defines ***************/

#define VERS 1  /* Current version of preferences file */

#define PREFS_FILE "s:EngClock.prefs"
#define GUIDECOMMAND "Amigaguide Engclock.guide"
#define ID "EngCPrefs"

/* Following for locale */
#define ENGLISH 1
#define FRENCH 2
#define SPANISH 3

/******** Global Variables *********/

BPTR handle;             /* Used by all file-handing operations */

char tmp[50],tmp2[50],line1[200], line2[200];

char *engnums[60];

int memmins, memhours;

BOOL afternoon; /* TRUE = pm, FALSE = am */

/* Following for Locale */
int language;
BOOL locale=TRUE;

/****** Global Structures *******/

struct Screen *pubscreen=NULL; /* Public screen structure */
char screen[200];                  /* Name of above */
char *screenptr = NULL;

/* Quick assignment for fonts */

struct TextAttr font1=
{
  "topaz.font",
  TOPAZ_EIGHTY,
  (UBYTE)NULL,
  FPF_ROMFONT
};

struct Event {
	BOOL used;
	int type;	/* Type of event */
	int hours;	/* Time of event */
	int minutes;
	int timecode;
	char message[256];
	int day;
	int month;
	int year;
	BOOL enabledate;
	int freq;
};

struct {
/* Prefs structure used for preferences file format */

   char header[10];  /* I.D. Header */
   int vers;         /* Version of preferences file */
   int x;            /* X dimension of window when saved */
   int y;            /* Y dimension of window when saved */
   int width;        /* Width of window when saved */
   int height;       /* Height of window when saved */
   int planguage;    /* Language selected (menu) when saved, low pri */
   int just;         /* Justification of text, 0=Left, 1=Centre */
   short date;       /* Display date?, 0 = No, 1=Yes */
   short wtf;	     /* Window to front? */
   int time_col[8];
   int date_col[8];
   short autoadjust;       /* Auto adjust ? */
   char backdrop[256];
   char pub[139];
	char accent[256];		/* Language file for tRanslate */
	char tkey[100];
	char hkey[100];

	struct Event events[11];  /* For the alarm! */ 
}prefs;

struct {
/* Time structure, set up by gettime() and used globally */

   int hours;        /* Number of hours since midnight on system clock */
   int seconds;      /* Number of seconds */
   int minutes;      /* Number of minutes */
   int years;        /* Current year */
   int days;         /* Date in current month */
   int months;       /* Current month */
   int wday;         /* Day in the week 0-6 (starting Sunday) */
}time;


struct {
/* Font structure, set up by getfont() and used globally */

   int x;            /* Width of default graphic font */
   int y;            /* Height of default graphic font */
}font;

struct IntuiMessage *message;   /* Set up our message pointer */
extern struct ExecBase *SysBase;
struct timerequest *TimerIO=NULL;
struct Library *TimerBase=NULL;

/* Following for screen information routine */
#include "EngClock_Screen.h"

   int exit_flag=0;
   struct Window *win_p;  /* Our window pointer */
   struct NewWindow win1;  /* Window structure - assigned later */

   /* IntuiText definitions */

   /* Main IntuiText for the window text */

   struct IntuiText int_text= {
      1,0,JAM1,16,9,NULL,NULL,NULL };
   struct IntuiText date_text = {
      1,0,JAM1,16,19,NULL,NULL,NULL };

	struct IntuiText req_text= {
      1,0,JAM1,16,9,NULL,NULL,NULL };

   /* IntuiTexts for the about requester */

   struct IntuiText about_text[18] = {
      {1,0,JAM1,16,9,NULL,NULL,NULL, },               /* Element 1  */
      {1,0,JAM1,16,17,NULL,NULL,&about_text[0],},     /* Element 2  */
      {1,0,JAM1,16,25,NULL,NULL,&about_text[1],},     /* Element 3  */
      {1,0,JAM1,16,33,NULL,NULL,&about_text[2],},     /* Element 4  */
      {1,0,JAM1,16,41,NULL,NULL,&about_text[3],},     /* Element 5  */
      {1,0,JAM1,16,49,NULL,NULL,&about_text[4],},     /* Element 6  */
      {1,0,JAM1,16,57,NULL,NULL,&about_text[5],},     /* Element 7  */
      {1,0,JAM1,16,65,NULL,NULL,&about_text[6],},     /* Element 8  */
      {1,0,JAM1,16,73,NULL,NULL,&about_text[7],},     /* Element 9  */
      {1,0,JAM1,16,81,NULL,NULL,&about_text[8],},     /* Element 10 */
      {1,0,JAM1,16,89,NULL,NULL,&about_text[9],},     /* Element 11 */
      {1,0,JAM1,16,97,NULL,NULL,&about_text[10],},    /* Element 12 */
      {1,0,JAM1,16,105,NULL,NULL,&about_text[11],},   /* Element 13 */
      {1,0,JAM1,16,113,NULL,NULL,&about_text[12],},   /* Element 14 */
      {1,0,JAM1,16,121,NULL,NULL,&about_text[13],},   /* Element 15 */
      {1,0,JAM1,16,129,NULL,NULL,&about_text[14],},    /* Element 16 */
      {1,0,JAM1,16,137,NULL,NULL,&about_text[15],},    /* Element 17 */
      {1,0,JAM1,16,145,NULL,NULL,&about_text[16],}    /* Element 18 */
   };

   struct IntuiText ok_text={
      1,0,JAM1,16,9,NULL,NULL,NULL };

/* Menu definitions and structure follow... */

   /* First the IntuiText strings for each menu item */

   struct IntuiText menu_text1 = {
      2,0,JAM1,0,1,NULL,"Set Prefs...",NULL };
   struct IntuiText menu_text2 = {
      2,0,JAM1,0,1,NULL,"Jump",NULL };
   struct IntuiText menu_text3 = {
      2,0,JAM1,0,1,NULL,"About",NULL };
   struct IntuiText menu_text4 = {
      2,0,JAM1,0,1,NULL,"Quit",NULL };

   /* And now the menu bits (in reverse order) */


   struct MenuItem menu_item4 = {
      NULL,0,30,150,10,ITEMTEXT|
                     ITEMENABLED|
                     COMMSEQ|
                     HIGHCOMP, 0x00000001,(APTR)&menu_text4,NULL,'Q',NULL,
                     MENUNULL,};
   struct MenuItem menu_item3 = {
      &menu_item4,0,20,150,10,ITEMTEXT|
                       ITEMENABLED|
                       HIGHCOMP|
                       COMMSEQ,0x00000001,(APTR) &menu_text3,NULL,'A',NULL,
                       MENUNULL,};
   struct MenuItem menu_item2 = {
      &menu_item3,0,10,150,10,ITEMTEXT|
                       ITEMENABLED|
                       COMMSEQ|
                       HIGHCOMP,0x00000001,(APTR) &menu_text2,NULL,'J',NULL,
                       MENUNULL,};
   struct MenuItem menu_item1 = {
      &menu_item2,0,0,150,10,ITEMTEXT|
                       ITEMENABLED|
                       COMMSEQ|
                       HIGHCOMP,0x00000001,(APTR) &menu_text1,NULL,'S',NULL,
                       MENUNULL,};
   
   /* Finally the menus themselves */

   struct Menu menu1 = {
      NULL,0,0,70,0,MENUENABLED,"Project",&menu_item1 };


/* Global pointers for data used in date */

char *months_data[13] = {
   "",
   "January",
   "February",
   "March",
   "April",
   "May",
   "June",
   "July",
   "August",
   "September",
   "October",
   "November",
   "December"
};

char *months_data_french[13] = {
   "",
   "Janvier",
   "Février",
   "Mars",
   "Avril",
   "Mai",
   "Juin",
   "Juillet",
   "Août",
   "Septembre",
   "Octobre",
   "Novembre",
   "Décembre"
};

char *months_data_spanish[13]={
	"",
	"enero",
	"febrero",
	"marzo",
	"abril",
	"mayo",
	"junio",
	"julio",
	"agosto",
	"septiembre",
	"octubre",
	"noviembre",
	"diciembre"
};

char *days_data[7] = {
   "Sunday",
   "Monday",
   "Tuesday",
   "Wednesday",
   "Thursday",
   "Friday",
   "Saturday"
};

char *days_data_french[7] = {
   "Dimanche",
   "Lundi",
   "Mardi",
   "Mercredi",
   "Jeudi",
   "Vendredi",
   "Samedi"
};

char *days_data_spanish[7] = {
	"Domingo",
	"Lunes",
	"Martes",
	"Miércoles",
	"Jueves",
	"Viernes",
	"Sábado"
};

BOOL Wb;  /* Workbench (TRUE) or CLI (FALSE) */
struct WBStartup *Wbs;

struct Process *guiproc=NULL;

/* Stuff for backdrops */

struct Picture
{
   struct BitMapHeader bmhd;  /* format and infos */
   struct BitMap *bmap;       /* bitmap */
   ULONG *palette;            /* color table in LoadRGB32() format */
   LONG palette_size;         /* mem usage */
   LONG palette_entries;      /* number of colors */
   ULONG display_ID;          /* video mode */
   UBYTE *author;             /* author info */
   UBYTE *copyright;          /* copyright info */
   UBYTE *annotation;         /* other info */
   LONG author_size;          /* mem usage */
   LONG copyright_size;       /* mem usage */
   LONG annotation_size;      /* mem usage */
};

struct Picture piccy;
BOOL ispicture=FALSE;

struct TextAttr about_font = {
	NULL,
	NULL,
	FSF_UNDERLINED,
	NULL
};

/* Special access variables */

extern struct MsgPort *CxMsgPort;
extern struct MsgPort *menu_msg;
extern struct MsgPort *CxHotKey1;
extern struct MsgPort *CxHotKey2;
extern struct MsgPort *RexxPort;

extern CxMsg *CxMessage;

/* Lib bases */

struct IntuitionBase *IntuitionBase=NULL;
struct GfxBase *GfxBase=NULL;
struct Library *UtilityBase=NULL;
struct Library *GadToolsBase=NULL;
struct Library *DiskfontBase=NULL;
struct Library *CxBase=NULL;
struct Library *WorkbenchBase=NULL;
struct Library *TranslatorBase=NULL;
struct Library *AslBase=NULL;
struct Library *IFFParseBase=NULL;
struct Library *DataTypesBase=NULL;
struct Library *RexxBase=NULL;

extern struct Library *DOSBase;



/********* Prototypes ************/

short main(void);
void gettime(void);
BOOL  about(void);
short readprefs(void);
void  setupengnums(void);
void  openall(void);
void  closeall(void);
void  getfont(void);
void  clearwindow(void);
short setupmainwindow(void);
short changemenu(void);
short refreshwindow(void);
void setupdate_english(void);
void setupdate_french(void);
void setupdate_spanish(void);


extern void process_alarm(void);
extern BOOL talk(char *text);
extern int prefsgui(void);
extern BOOL jump(void);
extern short getlocale(void);
extern char *trans(char *text);
extern char *findday(int preset2);
extern char datey[200];
extern BOOL playsam(char *esvxname);
extern void msg(char *msg);
extern BOOL loadpic(char *fname, struct Screen *scr);
extern void pattern(struct Window *win_p, struct Screen *scr,struct Picture pic);
extern void unloadpic(struct Picture pic);
extern BOOL cxinit(void);
extern BOOL wbinit(void);
extern void cxclose(void);
extern void wbclose(void);
extern BOOL wb_ask(char *body, char *opt1, char *opt2);
extern void autoadjust(void);
extern void arexxclose(void);
extern void process_arexx(void);
extern BOOL arexxinit(void);
