/**  menstructs.c ********************************************************
 *
 *              menstructs.c - Menu structures & init functions
 *
 *      Routines in this module: MakeMyMenus , NewMenu
 *
 *      David Milligan - Cleaned up menu appearance & layout.
 *       6/7/86 - Broke up menu into discrete structures for fine-tuning.
 *              - Added shortcut keys to Flags & Activation items.
 *              - Added rudimentary MutualExcluding.
 *       6/9/86 - Made menu structures into separate file in consideration
 *                of other programmers on project.
 *      6/11/86 - Re-implemented 'stamping' method of menu init.
 *              - Re-wrote the NewMenu() function to use pointer indexing.
 *                Much cleaner & more efficient.
 *
 *      David Milligan, Surrealistic Software, Sacramento, CA.
 *              The WELL        - dmil
 *              CompuServe      - 70707,2521
 *              BIX             - dmilligan
 *      home phone - (916)366-1269
 ***********************************************************************/
 
/*  The usual header files to be inserted later  */
#include <intuition/intuition.h>
#include <libraries/dosextens.h>
#include <graphics/gfxbase.h>
#include <graphics/gfx.h>
#include <graphics/display.h>
#include <exec/memory.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <devices/narrator.h>
#include <devices/audio.h>
#include <libraries/translator.h>
#include "gad.h"
#include "men.h"
 
/*===================== EXTERNAL GLOBAL VARIABLES =====================*/
 
extern struct Gadget testgad;
extern struct PropInfo Prop;
extern struct StringInfo String;
extern struct Window *w;
extern long mask;
extern int holding;
extern int erase;
extern int siz_flag;
 
/* Copies of this structure will get "stamped" into many more */
                /* Allocated later */
 
struct IntuiText generic =
{
  0, 1,                          /* Bluepen, Whitepen */
  JAM2, 5,                       /* mode,  LeftEdge */
  0, NULL,                       /* Top (to be filled later), Font */
  NULL,                          /* Name (to be filled later) */
  NULL                           /* Next one */
};
 
/*----------- Array of Menu Widths --------------*/
 
int item_widths[NUM_MENUS] = { 190, 135, 171, 171, 182, 145 };
 
 
/***********    Array of MenuItem LeftEdge values       ****************/
 
int item_lefts[NUM_MENUS] =
        {
        FILE_LEFT,TYPE_LEFT,ACT_LEFT,FLAGS_LEFT,UTIL_LEFT,SPEC_LEFT
        };
 
/*======================== Propinfo flags menu ========================*/
 
struct MenuItem info_items[NUM_SPEC_ITEMS];
struct IntuiText info_texts[NUM_SPEC_ITEMS];
 
char *info_names[] = {
   "  Clear All Flags",
   "  AUTOKNOB",
   "  FREEHORIZ",
   "  FREEVERT",
   "  PROPBORDERLESS",
   "  KNOBHIT"
};
 
USHORT info_menuflags [] =
        {
        MENU_COMP,MENU_BOX,MENU_BOX,MENU_BOX,MENU_BOX,MENU_BOX
        };
 
USHORT info_exclude [] =
        {
        0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001
        };
 
UBYTE info_commkeys[] =
        {
        0,0,0,0,0,0
        };
 
struct Menu info_menu = {
   NULL,                                /* No next menu */
   UTIL_WIDTH + FLAGS_WIDTH + ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH,
   0, SPEC_WIDTH, 10,                   /* TopEdge, Width, Height */
   MENUENABLED,                         /* FLAGS */
   " PropInfo flags",                    /* Name of menu */
   info_items                           /* First Item structure */
};
 
/*================== DECLARATIONS FOR "UTILITY" MENU ==================*/
 
struct MenuItem util_items[NUM_UTIL_ITEMS];
struct IntuiText util_Itexts[NUM_UTIL_ITEMS];
 
char *util_names[] = {
    "Add New Gadget",
    "Delete Last Gadget",
    "Set Gadget Name",
    "Add Intuitext",
    "Set Image/Border",
    "Selected Image/Border",
    "Change Gadget Size",                /* Don't need this */
    "Change Gadget Location",            /* Nor this........*/
    "Set Mutual Exclude",
    "Add UserID",                        /* Definately not this */
    "Set PropInfo"                       /* Not sure about this */
};
 
USHORT util_menuflags [] =
        {
        MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,
        MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP
        };
 
USHORT util_exclude [] =
        {
        NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
        };
 
UBYTE util_commkeys[] =
        {
        0,0,0,0,0,0,0,0,0,0,0
        };
 
struct Menu util_menu = {
   &info_menu,                          /* No next menu */
   FLAGS_WIDTH + ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH,
   0, UTIL_WIDTH, 10,                   /* TopEdge, Width, Height */
   MENUENABLED,                         /* FLAGS */
   " Utilities",                         /* Name of menu */
   util_items                           /* First Item structure */
};
 
/*======================= Gadget flags menu =========================*/
 
struct MenuItem flags_items[NUM_FLAGS];
struct IntuiText flags_texts[NUM_FLAGS];
 
char *flags_names[] = {
   "  Clear All Flags",
   "  GADGHCOMP",
   "  GADGHBOX",
   "  GADGHIMAGE",
   "  GADGIMAGE",
   "  GRELBOTTOM",
   "  GRELRIGHT",
   "  GRELWIDTH",
   "  GRELHEIGHT",
   "  SELECTED",
   "  GADGDISABLED"
};
 
USHORT flag_menuflags [] =
        {
        MENU_COMP,MENU_BOX_COMM,MENU_BOX_COMM,MENU_DISABLE_BOX,
        MENU_DISABLE_BOX,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,
        MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM
        };
 
USHORT flag_exclude [] =
        {
        0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001,
        0x0001,0x0001,0x0001,0x0001,0x0001
        };
 
UBYTE flag_commkeys[] =
        {
        0,'P','R','S','T','U','V','W','X','Y','Z'
        };
 
struct Menu flags_menu = {
   &util_menu,                   /* No next menu */
   ACT_WIDTH + TYPE_WIDTH + FILE_WIDTH,
   0, FLAGS_WIDTH, 10,             /* TopEdge, Width, Height */
   MENUENABLED,                  /* FLAGS */
   " Gadget Flags",                 /* Name of menu */
   flags_items                     /* First Item structure */
};
 
/*============= DECLARATIONS FOR "Activation" MENU ==================*/
 
struct MenuItem act_items[NUM_ACT_FLAGS];
struct IntuiText act_texts[NUM_ACT_FLAGS];
 
char *act_item_names[] = {
    "  Clear All Flags",
    "  RELVERIFY",
    "  FOLLOWMOUSE",
    "  GADGIMMEDIATE",
    "  ENDGADGET",
    "  TOGGLESELECT",
    "  LONGINT",
    "  RIGHTBORDER",
    "  LEFTBORDER",
    "  TOPBORDER",
    "  BOTTOMBORDER",
    "  STRINGCENTER",
    "  STRINGRIGHT",
    "  ALTKEYMAP"
};
 
USHORT act_menuflags [] =
        {
        MENU_COMP,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,
        MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,
        MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM,MENU_BOX_COMM
        };
 
USHORT act_exclude [] =
        {
        0xfffe,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
        0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001
        };
 
UBYTE act_commkeys[] =
        {
        0,'A','B','C','D','E','F','G','H','I','J','K','L','O'
        };
 
struct Menu act_menu = {
   &flags_menu,                  /* No next menu */
   TYPE_WIDTH + FILE_WIDTH,
   0, ACT_WIDTH, 10,             /* TopEdge, Width, Height */
   MENUENABLED,                  /* FLAGS */
   " Activation",                 /* Name of menu */
   act_items                     /* First Item structure */
};
 
/*============ DECLARATIONS FOR Gadget Type MENU ===============*/
 
struct MenuItem type_items[NUM_GAD_TYPES];
struct IntuiText type_texts[NUM_GAD_TYPES];
 
char *type_names[] = {
  "  Boolean gadget",
  "  Prop Gadget",
  "  String Gadget"
};
 
USHORT gad_menuflags [] =
        {
        MENU_BOX,MENU_BOX,MENU_BOX
        };
 
USHORT gad_exclude [] =
        {
        0xfffe,0xffd,0xffb
        };
 
UBYTE gad_commkeys[] =
        {
        0,0,0
        };
 
 
struct Menu type_menu = {
   &act_menu,
   FILE_WIDTH,          /* Leftedge */
   0, TYPE_WIDTH, 10,   /* TopEdge, Width, Height */
   MENUENABLED,         /* Flags */
   " Gadget Type",       /* Name on menu */
   type_items
};
 
/*===================== File menu declarations =====================*/
 
struct MenuItem file_items[NUM_FILE_ITEMS];
struct IntuiText file_texts[NUM_FILE_ITEMS];
 
char *file_names[] = {
    "New Gadgets File",
    "Get Gadgets File",
    "Save Gadgets File",
    "Save As Source",
    "Quit Program"
};
 
USHORT file_menuflags [] =
        {
        MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP,MENU_COMP_COMM
        };
 
USHORT file_exclude [] =
        {
        NULL,NULL,NULL,NULL,NULL
        };
 
UBYTE file_commkeys[] =
        {
        0,0,0,0,'Q'
        };
 
 
struct Menu file_menu = {
   &type_menu,
   0,                   /* Leftedge */
   0, FILE_WIDTH, 10,   /* TopEdge, Width, Height */
   MENUENABLED,         /* Flags */
   " FILE",              /* Name on menu */
   file_items
};
 
 
/***************************************************************************
                   C R E A T E    A    N E W    M E N U
***************************************************************************/
NewMenu ( menu, item_names,  menu_items, menu_text, num_items,
          LEdge , m_exclude, commkeys, Mwidth, item_flags)
 
struct Menu      *menu;                 /* Menu structure               */
char            *item_names[];          /* Pointer to array of item names  */
register struct MenuItem *menu_items;   /* pointer to array of structures  */
register struct IntuiText *menu_text;   /* Pointer to array of text structures
register int num_items;                 /* Number of items                  */
int             LEdge;                  /* Item's LeftEdge      */
USHORT          *m_exclude;
UBYTE           *commkeys;
int             Mwidth;                 /* Menu Width */
USHORT          *item_flags;            /* Pointer to array of Item flags */
 
{
    int height;
 
        height = 0;
        while (num_items--)
        {
          /*
           Doing structure assignments is not portable, but then this stuff
           would only work on an Amiga anyway since it is made for one.
          */
 
          *menu_text = generic;
          menu_text->IText = (UBYTE *) *(item_names++);
          menu_items->NextItem = menu_items+1;    /* Link to next menu item */
          menu_items->TopEdge = height;
          menu_items->LeftEdge = LEdge;
          menu_items->Height = 8;
          menu_items->ItemFill = (APTR)menu_text;
          menu_items->Flags = *(item_flags++);
          menu_items->Width = Mwidth;
          menu_items->MutualExclude = *(m_exclude++);
          menu_items->Command = *(commkeys++);
          menu_items->SubItem = NULL;
          menu_items->NextSelect = NULL;
 
          height += 10;
 
              /* Increment all of the pointers */
                  menu_text++;
                  menu_items++;
    }
 
    (menu_items-1)->NextItem = NULL;
}
 
/*=$$$===================== CREATE THE NEW MENUS =======================*/
 
MakeMyMenus()
{
   NewMenu( &file_menu, file_names, file_items, file_texts,
           NUM_FILE_ITEMS, item_lefts[0], file_exclude,
           file_commkeys, item_widths[0], file_menuflags);
 
   NewMenu( &type_menu, type_names, type_items, type_texts,
           NUM_GAD_TYPES, item_lefts[1], gad_exclude,
           gad_commkeys, item_widths[1], gad_menuflags);
 
   NewMenu( &act_menu, act_item_names, act_items, act_texts,
           NUM_ACT_FLAGS, item_lefts[2], act_exclude,
           act_commkeys, item_widths[2], act_menuflags);
 
   NewMenu( &flags_menu, flags_names, flags_items, flags_texts,
           NUM_FLAGS, item_lefts[3], flag_exclude,
           flag_commkeys, item_widths[3], flag_menuflags);
 
   NewMenu( &util_menu, util_names, util_items, util_Itexts,
           NUM_UTIL_ITEMS, item_lefts[4], util_exclude,
           util_commkeys, item_widths[4], util_menuflags);
 
   NewMenu( &info_menu, info_names, info_items, info_texts,
           NUM_SPEC_ITEMS, item_lefts[5], info_exclude,
           info_commkeys, item_widths[5], info_menuflags);
 
   mask |= MENU;
 
   SetMenuStrip(w, &file_menu);
 
}
                                                                                                             