/* Global gear for EngClock */


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

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <proto/intuition.h>
#include <proto/diskfont.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/utility.h>
#include <proto/dos.h>
#include <proto/commodities.h>
#include <proto/langmod.h>
#include <proto/locale.h>
#include <proto/screennotify.h>
#include <libraries/screennotify.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 <libraries/diskfont.h>
#include <graphics/scale.h>
#include <graphics/gfxbase.h>
#include <utility/utility.h>
#include <utility/date.h>
#include <workbench/startup.h>
#include <datatypes/pictureclass.h>

#include "prefs.h"

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

#define VERS 1  /* Current version of preferences file */
#define MOD_PATH "modules/"

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

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

struct Catalog *catalog;
struct Library *LangModBase;  /* The hook into the modular system */

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

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

int memmins, memhours;

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

/* Following for Locale */
struct Language *chosen_lang;
struct Language *available_lang;
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 TextAttr win_font_a;
struct TextFont *win_font;

struct Prefs prefs;

struct EngTime 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;

/* 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 req_text= {
      1,0,JAM1,16,9,NULL,NULL,NULL };

   
   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 };
   struct IntuiText menu_text5 = {
     2,0,JAM1,0,1,NULL,"Snapshot",NULL };

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


   struct MenuItem menu_item5 = {
      NULL,0,30,150,10,ITEMTEXT|
                     ITEMENABLED|
                     COMMSEQ|
                     HIGHCOMP, 0x00000001,(APTR)&menu_text5,NULL,'S',NULL,
                     MENUNULL,};

   struct MenuItem menu_item4 = {
      &menu_item5,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,'P',NULL,
                       MENUNULL,};
   
   /* Finally the menus themselves */

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


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

/* 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
};

struct TimerDev {
	struct MsgPort *tport;
	BOOL close;
	long delay;
	long sig;
};

/* Special access variables */

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

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 *TranslatorBase=NULL;
struct Library *AslBase=NULL;
struct Library *IFFParseBase=NULL;
struct Library *DataTypesBase=NULL;
struct Library *RexxSysBase=NULL;

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

short main(int argc, char *argv[]);
void gettime(void);
short readprefs(void);
void  openall(void);
void  closeall(void);
void  getfont(void);
void  clearwindow(void);
short setupmainwindow(void);
short changemenu(void);
short refreshwindow(void);
void loadsnap(void);
void savesnap(void);
void rendertext(char *txt, long leftedge, long topedge, long col);


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 void cxclose(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);
extern BOOL about(void);
extern void process_args(int count, char *args[]);
extern struct TimerDev *GoTimer(long timeunit);
extern void CloseTimer(struct TimerDev *td);
extern void dissupported_languages(struct Language *a);
extern struct Language *supported_languages(char *dir);
extern void shutdown_mod(void);
extern BOOL sninit(void);
extern void snclose(void);