/*
 * hyper.h
 *
 * global application specific defines and structures
 */

#ifndef __hyper_h
#define __hyper_h

#include "toolbox.h"

/* function return codes */

#ifndef SUCCESS
#define SUCCESS 1
#endif

#ifndef FAILED
#define FAILED 0
#endif

/*
 * MAX_LAYERS = maximum number of drawfiles per card.
 * as this is unlikely to be very many, we use an array rather
 * than a linked list.
 */
#define MAX_LAYERS 8

/* hot spot typedef */

typedef struct _HotSpot {
  struct _HotSpot *next;
  BBox box;
  char *command;
  char *name;
  ComponentId id;
} HotSpot;

/*
 * command files are loaded into a block of memory with an array
 * pointing to the start of each line.
 */

typedef struct {
  int flags;
  char *cmd;
} LINE;

#define FreeLine 1

typedef struct {
  int size;
  LINE *lines;
  char *last;
  char *Cfunction;
} CSTR;

/*
 * The structure below holds all the information that is unique
 * to a viewer (a view onto a stack). It is attached via the client
 * handle mechanism to the view's window.
 */

typedef struct _Viewer{
  ObjectId window;                      /* view window                                  */
  HotSpot *buttons;                     /* linked list of hotspots                      */
  CSTR commands;                        /* commands for this stack                      */
  char *drawfile[MAX_LAYERS];           /* drawfiles to use                             */
  int  draw_size[MAX_LAYERS];           /* ...their sizes                               */
  char *files[MAX_LAYERS];              /* ...the filenames they came from              */
  int  num_draw;                        /* number of drawfiles on current card          */
  int  wimpw;                           /* wimp window handle                           */
  int  colour;                          /* current background colour                    */
  int  trfm[3][2];                      /* current transform matrix                     */
  void *control;                        /* hcl -> function array used to interpret file */
  char *name;                           /* name of stack                                */
  char *filename;                       /* filename from where commands came            */
  char *sprite;                         /* current sprite (card type)                   */
  char *cname;                          /* current card                                 */
  ObjectId status;                      /* ObjectId of status line                      */
  int flags;                            /* Viewer flags - see below                     */
  BBox extent;                          /* extent of viewer window                      */
  struct _Viewer *next;                 /* next viewer                                  */
} Viewer;

typedef struct {
  int (** fns)(Viewer *v,char *c);
  char ** psings;
  int num;
} CCTRL;

/* unitary transform */
#define TRFM {{1<<16,0},{0,1<<16},{0,0}}

/* global variables */

extern Viewer *views;
extern int quit;
extern MessagesFD mbl;
extern char *view_name;
extern int default_scale;
extern int do_goto(Viewer *v, char *cmd);
extern int print_it(Viewer *view, int copies,int scale, int dir);
extern Viewer *load_hcl_file(char *name);
extern int file_loader(WimpMessage *message, void *handle);
extern int fileinfo_show(int event_code, ToolboxEvent  *event, IdBlock *id_block,
                   void  *handle);

#define IGNORE(a) (a=a)

/* viewer flags */

#define ViewerFlag_StatusLine           1
#define ViewerFlag_AddedToMenu          2
#define ViewerFlag_FileModified         4

#endif
