/*-*-C-*-*/

#define ITEMNAMELEN 20
#define TYPEINNAMELEN 100

typedef enum {Window = 1} ResourceType;

/* The numbers in this typedef match directly the item types
 * stored in icon validation strings.
 *
 * NOTE: the None entry must be at the end of the list for the
 * code in props to work.  It is internal to the implementation
 * and its value can change as types are added.
 */

typedef enum
{
    SimpleIcon = 0,
    CommandButton = 1,
    Label = 2,
    DisplayField = 3,
    WriteableField = 4,
    HSlider = 5,
    VSlider = 6,
    OptionButton = 7,
    RadioButton = 8,
    GroupBox = 9,
    MenuButton = 10,
    AdjusterButton = 11,
    None = 12
} ItemType;


/*
 * This number must be equal to the number of Wimp icons is
 * the biggest item.  It is used by the renumbering code which
 * does not want to know details of item layout.
 */

#define MAX_ICONS_IN_ITEM 5

/*
 * structures to represent the various types of item.
 * In each case, the following must hold true:-
 * (a) For an item with 'n' icons, the first 'n' words of the struct must
 *     be the icon numbers.
 * (b) The first icon must be the master icon.
 * (c) The icons are in their natural order in the template;
 *     i.e. the fist (master) is lowest in the stacking order,
 *     and so on.  This is so that the renumbering code knows
 *     what to do.
 */

/*
 * Simple icon - used for all single-icon items
 */

typedef struct _simpleiconrec
{
    int icon;
} SimpleIconRec, *SimpleIconPtr;


/*
 * Slider (either vertical or horizontal)
 */

typedef struct _sliderrec
{
    int well, track, knob; /* , up, down */
} SliderRec, *SliderPtr;


/*
 * Group box
 */

typedef struct _groupboxrec
{
    int box, label;
} GroupBoxRec, *GroupBoxPtr;


/*
 * Adjuster buttons.  The "down" button is master.
 */

typedef struct _adjusterbuttonrec
{
    int down, up;
} AdjusterButtonRec, *AdjusterButtonPtr;


/* Each item is represented by one of these structures.  This contains high-level
 * data about the structure of a whole item (eg a slider).   The individual
 * members of union 'u' each describe a particular item type.
 */

typedef struct _iteminforec
{
    char name[ITEMNAMELEN];     /* ID for validation string */
    ItemType type;              /* which of the following union */
    Bool selected;
    Bool pendingsnap;
    union
    {
        int master;
        int rawicons[MAX_ICONS_IN_ITEM];
        SimpleIconRec simpleicon;
        SliderRec slider;
        GroupBoxRec groupbox;
        AdjusterButtonRec adjusterbutton;
        /* to be filled in... */
    } u;
} ItemInfoRec, *ItemInfoPtr;


/*
 * Icons with anti-aliased text need one of these.
 */
#define FONTNAMELEN 40                  /* mandated by template file format */

typedef struct _fontrec
{
    int xsize, ysize;                   /* times 16 */
    char name[FONTNAMELEN];
} FontRec, *FontPtr;


/* Each icon in a template is specified by an IconInfoRec.
 * It contains a wimp IconRec which is kept up-to-date with bbox, flags
 * and data set to what they will be in the final Templates file.
 * Thus it is always suitable for Wimp_PlotIcon to plot it.
 *
 * An icons with an a-a font will have the live font handle
 * filled in in its flags field - must remember to lose it
 * when the icon is deleted, and also to re-find it whenever
 * an icon is cloned.
 */

typedef struct _iconinforec
{
    ItemInfoPtr owner;          /* which item this is part of */
    int mapping;                /* used by the save code */
    IconRec icon;               /* Wimp data */
} IconInfoRec, *IconInfoPtr;


/*
 * Struct to hold grid status
 */

typedef struct
{
    unsigned short intx, inty;  /* Grid subdivision interval */
    unsigned short subx, suby;  /* Number of subdivisions per cross */
    unsigned int show : 1,      /* Grid is switched on */
             lock : 1,          /* grid lock is on */
             : 14,
             colour: 16;
} GridRec, *GridPtr;


/*
 * Each template is represented by one of these.  The "icons" array is a realloced
 * array containing IconRecs bearing a remarkable similarity to the ones that
 * will eventually turn up in the Templates file, though the validation strings
 * might be augmented on saving.  Icons that are temporarily not there are
 * marked with IF_DELETED in their flags word, just like in the Wimp,
 * and their Owner field.
 *
 * Hence the ordering of this array is the same as the stacking order
 * of the icons.  This simplifies redraw and mouse code.
 */

#define ICON_ARRAY_DELTA 20             /* increment for realloc */
#define RESOURCENAMELEN 12              /* specified by template format */

typedef struct _resourcerec
{
    char name[RESOURCENAMELEN];         /* Used by indir text icon */
    ResourceType type;                  /* Type of this resource; determines icon etc. */
    RectRec spritebbox;                 /* icon's bounding box on work area */
    RectRec namebbox;                   /* name's bounding box on work area */
    Bool selected;                      /* this template selected in parent doc viewer */
    struct _documentrec * owner;        /* document rec that owns me */

    WindowRec window;                   /* window desc of template viewer; holds
                                           the description of the resource's window
                                           and is also the window record used by
                                           the program to display and manipulate the
                                           window.  If handle is -1, window not open.
                                           */

    int maxicons;                       /* size of the following array */
    int numicons;                       /* number actually used; nb window.numicons always zero! */
    IconInfoPtr icons;                  /* Array (realloced).  Index is icon number */
    int numselected;                    /* Number of items selected in this resource */
    int numpendingsnap;                 /* Number of items waiting to be snapped */

    GridRec grid;                       /* grid info */

    Bool testing;                       /* TRUE if test mode active */

    struct _resourcerec *next;          /* NULL = end of list */
} ResourceRec, *ResourcePtr;



#define FILENAMELEN 256

/*
 * Each document, and its associated viewer window, is represented
 * by one of these structures.
 */

typedef struct _documentrec
{
    char title[FILENAMELEN];            /* Also used for titlebar indir. text */
    int namelength;                     /* length of name part of the above */
    Bool fullpath;                      /* Filename is a full path */
    Bool modified;
    WindowRec window;                   /* window desc for document's viewer */
    int numresources;                   /* # in list below */
    ResourcePtr resources;              /* linked list of malloced records */
    int gridwidth, gridheight;          /* current rows/cols of icon layout */
    int numselected;                    /* number selected resources in the window */
    Bool internal;                      /* never show the window; it is an internal document */
} DocumentRec, *DocumentPtr;

