/*****************************************************
 *                  Menu Definitions                 *
 *                                                   *
 *             Created with Menu Creator             *
 *                        by                         *
 *                   David Pehrson                   *
 *                                                   *
 *         Copyright (C) 1986  David Pehrson         *
 *                 Mantis Development                *
 *                                                   *
 *****************************************************/

#include <exec/types.h>
#include <intuition/intuition.h>
#include "Options.h"

#define BAUDITEM     5
#define MODEITEM     BAUDITEM + 5
#define CHOPITEM     0
#define XONITEM      CHOPITEM + 2
#define PROTOCOLITEM XONITEM  + 2
#define DEFAULT ITEMENABLED | ITEMTEXT | HIGHCOMP

static UBYTE stTopaz[] = "topaz.font";

static struct TextAttr taPlain = {  stTopaz, 8, FS_NORMAL, FPF_ROMFONT };

static struct IntuiText SubText[] =
{
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   On", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Off", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   On", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Off", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   XModem", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   XModem - CRC", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Kermit", NULL },
};

static struct IntuiText ItemText[] =
{
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Ascii Capture", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Ascii Transmit     ", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Binary Receive", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Binary Send", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Prompt", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"    300", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   1200", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   2400", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   4800", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   9600", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Half", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Full", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)"   Echo", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" FKey Load", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" FKey Save", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Define FKey     ", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Auto Chop", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Xon/Xoff", NULL },
	{ 2, 1, JAM1, 0, 1, &taPlain, (UBYTE *)" Protocol", NULL },
};

static struct MenuItem SubItems[] =
{
  {
     &SubItems[1], 140, 0, 64, 10, DEFAULT | CHECKIT,
     2, (APTR)&SubText[0], NULL, NULL, NULL, NULL  },
  {
     NULL, 140, 10, 64, 10, DEFAULT | CHECKIT,
     1, (APTR)&SubText[1], NULL, NULL, NULL, NULL  },
  {
     &SubItems[3], 140, 0, 64, 10, DEFAULT | CHECKIT,
     2, (APTR)&SubText[2], NULL, NULL, NULL, NULL  },
  {
     NULL, 140, 10, 64, 10, DEFAULT | CHECKIT,
     1, (APTR)&SubText[3], NULL, NULL, NULL, NULL  },
  {
     &SubItems[5], 140, 0, 136, 10, DEFAULT | CHECKIT,
     6, (APTR)&SubText[4], NULL, NULL, NULL, NULL },
  {
     &SubItems[6], 140, 10, 136, 10, DEFAULT | CHECKIT,
     5, (APTR)&SubText[5], NULL, NULL, NULL, NULL },
  {
     NULL, 140, 20, 136, 10, ITEMTEXT | CHECKIT | HIGHCOMP,
     3, (APTR)&SubText[6], NULL, NULL, NULL, NULL },
};

static struct MenuItem Items[] =
{
  {
     &Items[1], 0, 0, 176, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[0], NULL, 'C', NULL, NULL },
  {
     &Items[2], 0, 10, 176, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[1], NULL, 'T', NULL, NULL },
  {
     &Items[3], 0, 20, 176, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[2], NULL, 'R', NULL, NULL },
  {
     &Items[4], 0, 30, 176, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[3], NULL, 'S', NULL, NULL },
  {
     NULL, 0, 40, 176, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[4], NULL, 'P', NULL, NULL },
  {
     &Items[6], 0, 0, 72, 10, DEFAULT | CHECKIT,
     30, (APTR)&ItemText[5], NULL, NULL, NULL, NULL },
  {
     &Items[7], 0, 10, 72, 10, DEFAULT | CHECKIT,
     29, (APTR)&ItemText[6], NULL, NULL, NULL, NULL 
  },
  {
     &Items[8], 0, 20, 72, 10, DEFAULT | CHECKIT,
     27, (APTR)&ItemText[7], NULL, NULL, NULL, NULL },
  {
     &Items[9], 0, 30, 72, 10, DEFAULT | CHECKIT,
     23, (APTR)&ItemText[8], NULL, NULL, NULL, NULL },
  {
     NULL, 0, 40, 72, 10, DEFAULT | CHECKIT,
     15, (APTR)&ItemText[9], NULL, NULL, NULL, NULL },
  {
     &Items[11], 0, 0, 99, 10, DEFAULT | CHECKIT | COMMSEQ,
     6, (APTR)&ItemText[10], NULL, 'H', NULL, NULL },
  {
     &Items[12], 0, 10, 99, 10, DEFAULT | CHECKIT | COMMSEQ,
     5, (APTR)&ItemText[11], NULL, 'F', NULL, NULL },
  {
     NULL, 0, 20, 99, 10, DEFAULT | CHECKIT | COMMSEQ,
     3, (APTR)&ItemText[12], NULL, 'E', NULL, NULL },
  {
     &Items[14], 0, 0, 144, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[13], NULL, 'K', NULL, NULL },
  {
     &Items[15], 0, 10, 144, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[14], NULL, 'W', NULL, NULL },
  {
     &Items[16], 0, 20, 144, 10, DEFAULT | COMMSEQ,
     0, (APTR)&ItemText[15], NULL, 'D', NULL, NULL },
  {
     &Items[17], 0, 30, 144, 10, DEFAULT,
     0, (APTR)&ItemText[16], NULL, NULL, &SubItems[0], NULL },
  {
     &Items[18], 0, 40, 144, 10, DEFAULT,
     0, (APTR)&ItemText[17], NULL, NULL, &SubItems[2], NULL },
  {
     NULL, 0, 50, 144, 10, DEFAULT,
     0, (APTR)&ItemText[18], NULL, NULL, &SubItems[4], NULL },
};

static struct Menu Titles[] =
{
	{ &Titles[1], 3, 0, 54, 10, MENUENABLED, " File", &Items[0] },
	{ &Titles[2], 56, 0, 86, 10, MENUENABLED, " BaudRate", &Items[5] },
	{ &Titles[3], 141, 0, 54, 10, MENUENABLED, " Mode", &Items[10] },
	{ NULL, 194, 0, 126, 10, MENUENABLED, " Miscellaneous", &Items[13] },
};


static struct Menu *menuStrip = Titles;
static struct Window *mywindow;

/*---------------------------------------------------------*/
/*	InitMenu: set up the initial (default) menu	   */
/*---------------------------------------------------------*/

struct Menu *InitMenu( window )
struct Window *window;
{
   SetMenuStrip( window, menuStrip );
   mywindow = window;

   return menuStrip;
}

/*---------------------------------------------------------*/
/*	CloseMenu: Just ClearMenuStrip.			   */
/*---------------------------------------------------------*/

void CloseMenu()
{
   ClearMenuStrip( mywindow );
}

/*---------------------------------------------------------*/
/*	setFlag: turn checkmark on or off		   */
/*---------------------------------------------------------*/

static void setFlag( menuItem, seton )
register struct MenuItem *menuItem;
register BOOL   seton;
{
   if ( seton )
      menuItem->Flags |= CHECKED;
   else
      menuItem->Flags &= ~CHECKED;
}
 
/*---------------------------------------------------------*/
/*	SetMenu: set up the menu for the given options.	   */
/*---------------------------------------------------------*/

void SetMenu( opt )
register struct options *opt;
{
   static int menuBaud[] = { 300, 1200, 2400, 4800, 9600 };
   register int i;

   ClearMenuStrip( mywindow );
   
   /* Set the Baud Rate */
   for (i = 0; i < 5; i++)
      setFlag( &Items[ i + BAUDITEM ], (BOOL)(opt->Baud == menuBaud[ i ]) );

   /* Set the Mode Flag */
   for (i = 0; i < 3; i++)
      setFlag( &Items[ i + MODEITEM ], (BOOL)(opt->Mode == i) );
 
   /* Set Auto Chop Flag */
   setFlag( &SubItems[ CHOPITEM + 0 ], (BOOL)(opt->AutoChop) );
   setFlag( &SubItems[ CHOPITEM + 1 ], (BOOL)(!opt->AutoChop) );
     
   /* Set Xon Flag */
   setFlag( &SubItems[ XONITEM + 0 ], (BOOL)(opt->Xon) );
   setFlag( &SubItems[ XONITEM + 1 ], (BOOL)(!opt->Xon) );
     
   /* Set the correct Protocol */
   for (i = 0; i < 3; i++)
      setFlag( &SubItems[ i + PROTOCOLITEM ], (BOOL)(opt->Protocol == i) );

   SetMenuStrip( mywindow, menuStrip );
}
