/* $Header: /bioy2/biocomputing/doelz/development/jam/RCS/optional.c,v 2.0 1995/07/23 08:56:48 doelz Exp doelz $ */ 

/* 
         ***********************************************************
         *                                                         *
         *                         J A M                           * 
         *        J u s t   A n o t h e r   M e t a f i l e        *
         *                                                         *
         ***********************************************************

        --- SEE MAIN PROGRAM (JAM.C) FOR COPYRIGHT AND DEFINITION ---
*/ 


/*----------- NOTE: THIS MODULE IS ONLY REQUIRED IN VIBRANT MODE */ 
#ifdef JAMGUI
static char code_id[] = "$Id: optional.c,v 2.0 1995/07/23 08:56:48 doelz Exp doelz $";
#include "vibrant.h"
#include "document.h"
#include "jam.h"     
#include "jamproto.h"

/* Global variables */ 

#ifdef DEBUG 
extern int jam_debug;
#else
extern int jam_debug; 
#endif 


extern char jam_line[MAXLINE],jam_link[MAXLINE],jam_file[MAXINC][MAXFIL],jam_out[MAXLINE];  
extern char myline[MAXLINE]; 
extern int jam_lineno[MAXINC];
extern FILE *jam_fp[MAXINC], *jam_op, *jam_index,*jam_all,*jam_cts, *jam_lnk, *jam_ref; 
extern int current_jam; /* current open jam file */   
extern int def_flag; /* whether ifdef'ed or not */

/* conditionals */ 

extern int if_tstack;
extern int if_dstack; 
extern char if_token[MAXIF][MAXDEF];  
extern char if_defined[MAXIF][MAXDEF]; 

/* output modus */ 
extern int modus,sitespecific; 
extern int did_a_print; 
extern int vms_status; 
extern int single_file; 

/* chapters */ 
extern  int chapter_number; 
extern  int section_number;
extern  int subsection_number; 
extern  int line_number; 
extern  int line_in_file; 
extern  int line_in_input[MAXINC]; 

/* styles */ 
extern  int verbatim; 
extern  int special;  
extern  int special_on; 
extern  int item_on; 
extern  int link_on;   
extern int did_feed; 
extern  int item; 
extern  int last_verbatim; 
extern int behaviour; 

/* item formatter */
extern char item_prefix[MAXLINE]; 

extern int if_dstack, sitespecific; 
extern TexT input, rinput; 
WindoW OptionWindow; 
extern ButtoN OptionalButton; 
extern char infileName[MAXLINE]; 
extern char reflec_prefix[MAXLINE];   
extern int modus; 
PopuP  popModus;
 
FonT headingFont;
ButtoN OptionalButton; 

ButtoN  bSRS, bENTREZ, bDECNET, bRCP, bPEARSON, bATLAS, bREADSEQ, bEGCG;
ButtoN bUSR1,bUSR2; 	
GrouP bOS,bSTE,bBEHAVIOUR, bSINGLE, ReflecG; 

TexT input, rinput;
char infileName[MAXLINE];

static CharPtr popHTML [] = {"Reflector", "None", NULL}; /* options for 
							    CreateSelectBehaviour */ 
void jamstart(ButtoN dummy); 
void MakeOptionalWindow (WindoW w2);             /* make an options window */ 
void Jam_HTML (void);                            /* a HTML option executer */ 
void Jam_SINGLE (void);                          /* RTF option exectuor */ 
void JAM_modus (PopuP popModus);                        /* the modus is HTML, RTF or LATEX */ 
void AboutClose(WindoW about);			 /* the close handler for about window */ 
void QuitProc (IteM i);                          /* quitting the program */ 
void RunSelect (GrouP h);                        /* to run or call the option window */ 
void CreateSelectBehaviour (WindoW w);           /* selection of HTML: reflec or none */ 
static void CreateSelectNumber (WindoW w);       /* selection of RTF: multiple/single */ 
void CreateOutputSelectFormat (WindoW w);        /* modus again, the window this time */ 
void AboutVer(IteM Dummy);                       /* Version display (message type) */ 
void AboutProc(IteM Dummy);                      /* README file display */ 
void SetupObjects (WindoW w);                    /* help to setup main window */ 
void SetupMenus (WindoW w);                      /* the setup of main windows menu */ 


void Jam_OS (void); 
void Jam_STE (void); 




/* Jam_OS sets either UNIX or VMS, and causes vms_status to be set TRUE if so. */ 
void Jam_OS (void) 
{
  if (GetValue(bOS) == 1 )  { 
    strcpy(if_defined[if_dstack], "VMS"); 
    if_dstack++; 
  }
}

/* Jam_STE allows site-specific (STE) files rather than integral (INT) files. */ 
void Jam_STE (void)
{
  if (GetValue(bSTE) == 1 )  { 
    sitespecific=TRUE;
    }else{
    sitespecific=FALSE;
      }
}

 
/* Jam_HTML sets either 'active' or 'none' for program links. */ 
void Jam_HTML (void)
{
  if (GetValue(bBEHAVIOUR) == 1 ) 
  behaviour=JAMREFLECTOR;   else 
  behaviour=JAMDUMMY; 
}

/* JAM_Single allows to have more than one RTF file if not set. */ 
void Jam_SINGLE (void)
{
  if (GetValue(bSINGLE) > 1 ){ 
    single_file=TRUE;
  } 
} 


/* Jam_modus sets the output format. */ 
static void Jam_modus (PopuP popModus)
{
  modus = GetValue(popModus); 
  switch (modus) { 
  case HTML: 
    Enable (bBEHAVIOUR); 
    Disable (bSINGLE);
    Enable (ReflecG);  
    break; 
  case RTF: 
    Disable (bBEHAVIOUR); 
    Enable (bSINGLE);  
    Disable (ReflecG);
    break; 
  case LATEX:
    Disable (bBEHAVIOUR); 
    Disable (bSINGLE); 
    Disable (ReflecG);
    break; 
  } 
}
 

/* to Quit a program */ 
void QuitProc (IteM i)
{
  QuitProgram ();
}

/* to run or call the option window */ 
void RunSelect (GrouP h)
{
  ButtoN  b;
  GrouP   g;

  g = HiddenGroup (h, 2, 2, NULL); 
  if_tstack = 0; 
  if_dstack = 0;   
  OptionalButton =  PushButton(g,"  Optional Parameters ", (Nlm_BtnActnProc) MakeOptionalWindow); 

  b = DefaultButton (g, "         Run JAM       ", jamstart);
}

/* Behaviour of the HTML */  
void CreateSelectBehaviour (WindoW w)
{
  Int2 i;
  bBEHAVIOUR = NormalGroup (w, 4, 0, "HTML Layout",NULL,NULL);
  for (i = 0; popHTML [i] != NULL; i++) {
    RadioButton (bBEHAVIOUR, popHTML [i]);
  }
  SetValue (bBEHAVIOUR, 2);
} 
static CharPtr popSINGLE [] = {
  "Multiple", "Single", NULL
};

/* Behaviour of the RTF */ 
static void CreateSelectNumber (WindoW w)
{
  Int2 i; 

  bSINGLE = NormalGroup (w, 4, 0, "RTF Layout",NULL,NULL);
  for (i = 0; popSINGLE [i] != NULL; i++) {
    RadioButton (bSINGLE, popSINGLE [i]);
  }
  SetValue (bSINGLE, 2);
} 
 
/* Format selection: which format */ 
void CreateOutputSelectFormat (WindoW w)

{

  GrouP  h;
  h = HiddenGroup (w, 2, 20, NULL);
  CreateSelectBehaviour (h);
  CreateSelectNumber(h); 
  StaticPrompt (h, "Document Format Type", 0, popupMenuHeight, systemFont,  'l');
  popModus = PopupList (h, TRUE, Jam_modus);
  PopupItem (popModus, "RTF");
  PopupItem (popModus, "LaTEX");
  PopupItem (popModus, "HTML");
  SetValue (popModus, RTF);
  Disable (bBEHAVIOUR); 
}

/* make about window close */ 
void AboutClose(WindoW aboutWindow)
{
        Hide(aboutWindow);
}

/* how to show a version */ 
void AboutVer(IteM Dummy)
{ 
  char amess[120]; 
  	sprintf(amess, "%s",code_id); 
  	Message (MSG_OK,amess);

}

/* show a nice window and tell'em who we are */ 
void AboutProc(IteM Dummy)
{
  WindoW aboutWindow;
  DoC aboutDoc;
  FonT displayFont;  
  FILE *afile;        
  char amess[120]; 
  
#ifdef WIN_MSWIN
  displayFont = ParseFont("Courier, 10");
#endif
#ifdef WIN_MAC
  displayFont = ParseFont("Courier, 10");
#endif
#ifdef WIN_MOTIF
  displayFont = ParseFont("Courier, 10");
#endif
   
  afile = fopen ("about.txt", "r"); 
  if (afile == NULL) {  /* no about file found */
  	sprintf(amess, "%s",code_id); 
  	Message (MSG_OK,amess);
  	Message (MSG_OK, "SORRY; no documentation file in current directory");  
  	} else {
  	fclose (afile);
  	aboutWindow = FixedWindow(-50, -33, -15, -15, "About JAM", AboutClose);
  	aboutDoc = DocumentPanel(aboutWindow, 600, 300);         
	DisplayFile(aboutDoc, "about.txt", displayFont);
  	Show(aboutWindow);
  	}
}



/* setup nice objects */ 
void SetupObjects (WindoW w)
{
  GrouP  h;

  h = HiddenGroup (w, 2, 20, NULL);
  StaticPrompt (h, "JAM - Just Another Metaformat", 0,0, headingFont,  'c');
  h = NormalGroup (w, 3, 1, "Output definition parameters",systemFont,NULL);
  CreateOutputSelectFormat (h);      
  SetValue (popModus, RTF);
  h =  HiddenGroup (w, 2, 20, NULL);
  RunSelect (h);
  Jam_OS(); 
  Jam_STE(); 

}

/* setup the menus of the main window */ 
void SetupMenus (WindoW w)
{

  MenU    m;

#ifdef WIN_MAC
  m = AppleMenu (NULL);
  DeskAccGroup (m);
#endif
  m = PulldownMenu (w, "File");
  CommandItem (m, "Quit/Q", QuitProc);
  CommandItem(m, "About/A", AboutProc);
  CommandItem(m, "Version Info/V", AboutVer);
#ifdef WIN_MSWIN
        headingFont = ParseFont("Arial, 18, b");
#endif
#ifdef WIN_MAC
        headingFont = ParseFont("Geneva, 18, b");
#endif
#ifdef WIN_MOTIF
        headingFont = ParseFont("Helvetica, 18, b");
#endif

}



void SelectDefines (GrouP h)

{

  GrouP   g;

  g = NormalGroup (h, 5, 0, "Available Extras", NULL, NULL);
  bSRS = CheckBox (g, "SRS", NULL);
  SetStatus (bSRS, TRUE);
  bENTREZ =CheckBox (g, "ENTREZ", NULL);
  SetStatus (bENTREZ, FALSE);
  bATLAS =CheckBox (g, "ATLAS", NULL);
  SetStatus (bATLAS, FALSE);
  bREADSEQ =CheckBox (g, "READSEQ", NULL);
  SetStatus (bREADSEQ, FALSE);
  bRCP =CheckBox (g, "RCP", NULL);
  SetStatus (bRCP,FALSE);
  bDECNET =CheckBox (g, "DECNET", NULL);
  SetStatus (bDECNET, FALSE);
  bPEARSON =CheckBox (g, "PEARSON", NULL);
  SetStatus (bPEARSON, FALSE);
  bEGCG =CheckBox (g, "EGCG", NULL);
  SetStatus (bEGCG, FALSE);
  bUSR1 =CheckBox (g, "USR1", NULL);
  SetStatus (bUSR1, FALSE);
  bUSR2 =CheckBox (g, "USR2", NULL);
  SetStatus (bUSR2, FALSE);
  /* new types: declare global Variable, and add here as well as in 
  TurnOnDefines */
}

       
static void GetInfileName()
{
	GetInputFileName(infileName, sizeof(infileName),"", "");
	SetTitle(input, infileName);

}


static void TypeInReflecName()
{
	GetTitle(rinput, reflec_prefix, sizeof(reflec_prefix));     
}

static void PutReflecName()
{
	TypeInReflecName();      
	/*SetTitle(rinput,reflec_prefix); */

}


static void TypeInInfileName()
{
	GetTitle(input, infileName, sizeof(infileName));
}
                                 
static void PutInfileName()
{
	TypeInInfileName();      
	SetTitle(input,infileName); 

}


/* TurnOnDefines will get the defined values to be set. (survival-specific) */ 
/* Note that adding new ones will require coding here, and in SetDefines below. */ 

void TurnOnDefines (void)
{ 
	
  if (GetStatus(bSRS)) { 
    strcpy(if_defined[if_dstack], "SRS"); 
    if_dstack++; 
    }
  if (GetStatus(bENTREZ)) { 
    strcpy(if_defined[if_dstack], "ENTREZ"); 
    if_dstack++; 
    }
  if (GetStatus(bDECNET)) { 
    strcpy(if_defined[if_dstack], "DECNET"); 
    if_dstack++; 
    }
  if (GetStatus(bRCP)) { 
    strcpy(if_defined[if_dstack], "RCP"); 
    if_dstack++; 
    }
  if (GetStatus(bPEARSON)) { 
    strcpy(if_defined[if_dstack], "PEARSON"); 
    if_dstack++; 
    }
  if (GetStatus(bATLAS)) { 
    strcpy(if_defined[if_dstack], "ATLAS"); 
    if_dstack++; 
    }
  if (GetStatus(bEGCG)) { 
    strcpy(if_defined[if_dstack], "EGCG"); 
    if_dstack++; 
    }
  if (GetStatus(bREADSEQ)) { 
    strcpy(if_defined[if_dstack], "READSEQ"); 
    if_dstack++; 
    }
  if (GetStatus(bUSR1)) { 
    strcpy(if_defined[if_dstack], "USR1"); 
    if_dstack++; 
    }
  if (GetStatus(bUSR2)) { 
    strcpy(if_defined[if_dstack], "USR2"); 
    if_dstack++; 
    }
}

void FinishOptional(void)
{
   Enable (OptionalButton);
   Hide (OptionWindow);
} 
void FinishAll(void)
{
   QuitProgram();
}       


void SetupMenus2 (WindoW w2)
{
  MenU    m;  

#ifdef WIN_MAC
  m = AppleMenu (NULL);
  DeskAccGroup (m);
#endif
  m = PulldownMenu (w2, "File");
  CommandItem (m, "Quit/Q", (Nlm_ItmActnProc) FinishAll);
  CommandItem (m, "Resume/R", (Nlm_ItmActnProc) FinishOptional);
 }
             
  static CharPtr divvs [] = {
  "Site-specific", "Neutral", NULL
};
static CharPtr divisions [] = {
  "VMS", "UNIX", NULL
};

static void CreateOsSelect (WindoW w2)

{

  Int2   i;


  bOS = NormalGroup (w2, 4, 0, "Target System",NULL,NULL);
  for (i = 0; divisions [i] != NULL; i++) {
    RadioButton (bOS, divisions [i]);
  }
  SetValue (bOS, 2);
}
static void CreateSTESelect (WindoW w)

{

  Int2   i;

  bSTE = NormalGroup (w, 4, 0, "Target Layout",NULL,NULL);
  for (i = 0; divvs [i] != NULL; i++) {
    RadioButton (bSTE, divvs [i]);
  }
  SetValue (bSTE, 2);
}

void SetupObjects2 (WindoW w2)
{
  GrouP   h, g2;
  ButtoN  b2,b3; 
/* 
  g2 = NormalGroup (w2, 4, 0, "JAM Master Source File",NULL,NULL); 
  b2 = PushButton(g2, "Select File", (BtnActnProc) GetInfileName);
  input = DialogText(g2, "", 25, (TxtActnProc) PutInfileName);
*/   
 ReflecG = NormalGroup (w2, 4, 0, "JAM Reflector Prefix",NULL,NULL); 
  rinput = DialogText(ReflecG, "", 25, (TxtActnProc) PutReflecName);
   if (modus == HTML) Enable(ReflecG); 
  	else            
  	Disable (ReflecG); 
  g2 = HiddenGroup (w2, 2, 2, NULL); 
  b2 = DefaultButton    (g2, "   Continue  ", (Nlm_BtnActnProc) FinishOptional); 
  b3 = PushButton (g2, "Abort entire program", (Nlm_BtnActnProc) FinishAll); 
  Disable (OptionalButton);  
  h = HiddenGroup (w2, 6, 20, NULL);
  SelectDefines (h);
  h = HiddenGroup (w2, 2, 20, NULL);
  CreateOsSelect (h);
  CreateSTESelect (h);          
  
                    
}  
  /* setup custom objects here */ 



void MakeOptionalWindow (WindoW w)
{
#ifdef WIN_MAC
  SetupMenus2 (NULL);
#endif
  OptionWindow = FixedWindow (-100, -100, -5, -5, "JAM OPTIONAL PARAMETERS", NULL);
#ifndef WIN_MAC
  SetupMenus2 (OptionWindow);
#endif
  SetupObjects2 (OptionWindow);
  Show (OptionWindow);
  ProcessEvents ();
}


#endif

