/* **********************************************************************
 * *                                                                    *
 * *   Time related routines                                            *
 * *                                                                    *
 * **********************************************************************
 * File: iris/xsig/turbo_time.c
 *
 *                     COPYRIGHT (c) 1999, 2005  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

#include <stdio.h>
#include <Mrm/MrmAppl.h>
#include <Xm/MwmUtil.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <Xm/TextF.h>

#include "sigtypes.h"
#include "xsig_lib.h"

/* ----------------------------------------------------------------------------
  Create a HHMM turbo time popup menu.
*/
void XsCreateHHmmPop(Widget  base_a,
		     Widget* shl_a, const char* sshl_a,
		     Widget* txt_a, const char* stxt_a,
		     XtCallbackProc hhmm_cbf_a )
{
  Widget pop, hhincbtn, hhdecbtn, mmincbtn, mmdecbtn, okbtn;

  *shl_a = XtCreatePopupShell( sshl_a,  transientShellWidgetClass,
			       base_a,  NULL,0 );
/*

  XtVaSetValues(*shl_a, XmNmwmFunctions,
    MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE, NULL );
*/

/*
  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_MOVE, 
                XmNmwmDecorations, MWM_DECOR_ALL, NULL);
*/
  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_MOVE, NULL);

  pop = XmCreateForm(*shl_a,(char *)"hhmmpop",NULL,0 );
  XtVaSetValues( pop, XmNwidth, 95, NULL );

  hhincbtn=XmCreatePushButton(pop,(char *)"hhincbtn",NULL,0 );
  hhdecbtn=XmCreatePushButton(pop,(char *)"hhdecbtn",NULL,0 );
  mmincbtn=XmCreatePushButton(pop,(char *)"mmincbtn",NULL,0 );
  mmdecbtn=XmCreatePushButton(pop,(char *)"mmdecbtn",NULL,0 );
  *txt_a  =XmCreateTextField (pop,(char *)stxt_a,    NULL,0 );
  okbtn   =XmCreatePushButton(pop,(char *)"hhmmokbtn",  NULL,0 );
           
  XtAddCallback( *txt_a,   XmNactivateCallback, hhmm_cbf_a, (char *)"txt");
  XtAddCallback( okbtn,    XmNactivateCallback, hhmm_cbf_a, (char *)"ok" );
  XtAddCallback( hhincbtn, XmNactivateCallback, hhmm_cbf_a, (char *)"hi" );
  XtAddCallback( hhdecbtn, XmNactivateCallback, hhmm_cbf_a, (char *)"hd" );
  XtAddCallback( mmincbtn, XmNactivateCallback, hhmm_cbf_a, (char *)"mi" );
  XtAddCallback( mmdecbtn, XmNactivateCallback, hhmm_cbf_a, (char *)"md" );

  /* Form Attachments */
  XsAttach1FFXX( hhincbtn );		          
  XsAttach1FTXX( hhdecbtn, hhincbtn );
  XsAttach1LFFX( mmincbtn, hhincbtn );
  XsAttach1LTFX( mmdecbtn, hhdecbtn, mmincbtn );
  XsAttach1FTFX( *txt_a,   hhdecbtn );
  XsAttach1FTFF( okbtn,    *txt_a   );

  XtManageChild( hhincbtn  );  XtManageChild( hhdecbtn  );
  XtManageChild( mmincbtn  );  XtManageChild( mmdecbtn  );
  XtManageChild( *txt_a    );
  XtManageChild( okbtn);  
  XtManageChild( pop  );

}


/*---------------------------------------------------------------------------- 
  Create a HHMMSS turbo time popup menu.
*/
void XsCreateHHmmssPop(Widget  base_a,
		       Widget* shl_a, const char* sshl_a,
		       Widget* txt_a, const char* stxt_a,
		       XtCallbackProc hhmmss_cbf_a )
{
  Widget pop, hhincbtn, hhdecbtn, mmincbtn, mmdecbtn, okbtn;
  Widget ssincbtn, ssdecbtn;

  *shl_a = XtCreatePopupShell( sshl_a,  transientShellWidgetClass,
			       base_a,  NULL,0 );

/*
  XtVaSetValues(*shl_a, XmNmwmFunctions,
    MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE, NULL );
*/

/*
  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_ALL, 
                XmNmwmDecorations, MWM_DECOR_ALL, NULL);
*/

  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_MOVE, NULL);

  pop = XmCreateForm(*shl_a,(char *)"hhmmsspop",NULL,0 );
  XtVaSetValues( pop, XmNwidth, 145, NULL );

  hhincbtn=XmCreatePushButton(pop,(char *)"hhincbtn",NULL,0 );
  hhdecbtn=XmCreatePushButton(pop,(char *)"hhdecbtn",NULL,0 );
  mmincbtn=XmCreatePushButton(pop,(char *)"mmincbtn",NULL,0 );
  mmdecbtn=XmCreatePushButton(pop,(char *)"mmdecbtn",NULL,0 );
  ssincbtn=XmCreatePushButton(pop,(char *)"ssincbtn",NULL,0 );
  ssdecbtn=XmCreatePushButton(pop,(char *)"ssdecbtn",NULL,0 );
  *txt_a  =XmCreateTextField (pop,(char *)stxt_a,    NULL,0 );
  okbtn   =XmCreatePushButton(pop,(char *)"hhmmokbtn",  NULL,0 );
           
  XtAddCallback( *txt_a,   XmNactivateCallback, hhmmss_cbf_a, (char *)"txt");
  XtAddCallback( okbtn,    XmNactivateCallback, hhmmss_cbf_a, (char *)"ok");
  XtAddCallback( hhincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"hi" );
  XtAddCallback( hhdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"hd" );
  XtAddCallback( mmincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"mi" );
  XtAddCallback( mmdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"md" );
  XtAddCallback( ssincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"si" );
  XtAddCallback( ssdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"sd" );

  XtVaSetValues( hhincbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( hhdecbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhincbtn, NULL );

  XtVaSetValues( mmincbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhincbtn,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( mmdecbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhdecbtn,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       mmincbtn, NULL );

  XtVaSetValues( ssincbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( ssdecbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       ssincbtn, NULL );
  XtVaSetValues( *txt_a,   XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhdecbtn, NULL );

  XtVaSetValues( okbtn,    XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM, 
		           XmNbottomAttachment,XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       *txt_a,   NULL );

  XtManageChild( hhincbtn  );  XtManageChild( hhdecbtn  );
  XtManageChild( mmincbtn  );  XtManageChild( mmdecbtn  );
  XtManageChild( ssincbtn  );  XtManageChild( ssdecbtn  );
  XtManageChild( *txt_a    );
  XtManageChild( okbtn);  
  XtManageChild( pop  );

}
/*---------------------------------------------------------------------------- 
  Create a HHMMSS turbo time popup menu.
*/
void XsCreateHHmmssNonePop(Widget  base_a,
			   Widget* shl_a, const char* sshl_a,
			   Widget* txt_a, const char* stxt_a,
			   XtCallbackProc hhmmss_cbf_a )
{
  Widget pop, hhincbtn, hhdecbtn, mmincbtn, mmdecbtn, okbtn, nonebtn;
  Widget ssincbtn, ssdecbtn;

  *shl_a = XtCreatePopupShell( (char *)sshl_a,  transientShellWidgetClass,
			       base_a,  NULL,0 );

/*
  XtVaSetValues(*shl_a, XmNmwmFunctions,
    MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE, NULL );
*/
/*

  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_ALL, 
                XmNmwmDecorations, MWM_DECOR_ALL, NULL);
*/

  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_MOVE, NULL);

  pop = XmCreateForm(*shl_a,(char *)"hhmmsspop",NULL, 0 );
  XtVaSetValues( pop, XmNwidth, 145, NULL );

  hhincbtn=XmCreatePushButton(pop,(char *)"hhincbtn",NULL,0 );
  hhdecbtn=XmCreatePushButton(pop,(char *)"hhdecbtn",NULL,0 );
  mmincbtn=XmCreatePushButton(pop,(char *)"mmincbtn",NULL,0 );
  mmdecbtn=XmCreatePushButton(pop,(char *)"mmdecbtn",NULL,0 );
  ssincbtn=XmCreatePushButton(pop,(char *)"ssincbtn",NULL,0 );
  ssdecbtn=XmCreatePushButton(pop,(char *)"ssdecbtn",NULL,0 );
  *txt_a  =XmCreateTextField (pop, (char *)stxt_a,    NULL,0 );
  okbtn   =XmCreatePushButton(pop,(char *)"hhmmokbtn",  NULL,0 );
  nonebtn   =XmCreatePushButton(pop,(char *)"nonebtn",  NULL,0 );
           
  XtAddCallback( *txt_a,   XmNactivateCallback, hhmmss_cbf_a, (char *)"txt");
  XtAddCallback( okbtn,    XmNactivateCallback, hhmmss_cbf_a, (char *)"ok");
  XtAddCallback( nonebtn,  XmNactivateCallback, hhmmss_cbf_a, (char *)"no");
  XtAddCallback( hhincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"hi" );
  XtAddCallback( hhdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"hd" );
  XtAddCallback( mmincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"mi" );
  XtAddCallback( mmdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"md" );
  XtAddCallback( ssincbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"si" );
  XtAddCallback( ssdecbtn, XmNactivateCallback, hhmmss_cbf_a, (char *)"sd" );

  XtVaSetValues( hhincbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( hhdecbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhincbtn, NULL );

  XtVaSetValues( mmincbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhincbtn,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( mmdecbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhdecbtn,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       mmincbtn, NULL );

  XtVaSetValues( ssincbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( ssdecbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       ssincbtn, NULL );
  XtVaSetValues( *txt_a,   XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhdecbtn, NULL );

  XtVaSetValues( nonebtn,    XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM, 
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       *txt_a,   NULL );

  XtVaSetValues( okbtn,    XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM, 
		           XmNbottomAttachment,XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       nonebtn,   NULL );

  XtManageChild( hhincbtn  );  XtManageChild( hhdecbtn  );
  XtManageChild( mmincbtn  );  XtManageChild( mmdecbtn  );
  XtManageChild( ssincbtn  );  XtManageChild( ssdecbtn  );
  XtManageChild( *txt_a    );
  XtManageChild( okbtn);  
  XtManageChild( nonebtn);  
  XtManageChild( pop  );

}

/* hhmmss dd month year */
void XsCreateHHmmddmoyyPop(Widget  base_a,
			   Widget* shl_a, const char* sshl_a,
			   Widget* txt_a, const char* stxt_a,
			   XtCallbackProc hhmmddmoyy_cbf_a )
{
  Widget ddincbtn, dddecbtn, moincbtn, modecbtn, yyincbtn, yydecbtn;
  Widget hhincbtn, hhdecbtn, mmincbtn, mmdecbtn;
  Widget pop, okbtn;

  *shl_a = XtCreatePopupShell( (char *)sshl_a,  transientShellWidgetClass,
			       base_a,  NULL,0 );

/*
  XtVaSetValues(*shl_a, XmNmwmFunctions,
    MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE, NULL );
  XtVaSetValues(*shl_a, XmNmwmDecorations,
     MWM_DECOR_RESIZEH | MWM_DECOR_BORDER |  MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE , NULL);

*/
/*
  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_ALL, 
                XmNmwmDecorations, MWM_DECOR_ALL, NULL);
*/

  XtVaSetValues(*shl_a, XmNmwmFunctions, MWM_FUNC_MOVE, NULL);


  pop = XmCreateForm(*shl_a,(char *)"hhmmddmoyypop",NULL, 0 );
  XtVaSetValues( pop, XmNwidth, 240, NULL );

  hhincbtn=XmCreatePushButton(pop,(char *)"hhincbtn",NULL,0 );
  hhdecbtn=XmCreatePushButton(pop,(char *)"hhdecbtn",NULL,0 );
  mmincbtn=XmCreatePushButton(pop,(char *)"mmincbtn",NULL,0 );
  mmdecbtn=XmCreatePushButton(pop,(char *)"mmdecbtn",NULL,0 );

  ddincbtn=XmCreatePushButton(pop,(char *)"ddincbtn",NULL,0 );
  dddecbtn=XmCreatePushButton(pop,(char *)"dddecbtn",NULL,0 );
  moincbtn=XmCreatePushButton(pop,(char *)"moincbtn",NULL,0 );
  modecbtn=XmCreatePushButton(pop,(char *)"modecbtn",NULL,0 );
  yyincbtn=XmCreatePushButton(pop,(char *)"yyincbtn",NULL,0 );
  yydecbtn=XmCreatePushButton(pop,(char *)"yydecbtn",NULL,0 );
  *txt_a  =XmCreateTextField (pop, (char *)stxt_a,    NULL,0 );
  okbtn   =XmCreatePushButton(pop,(char *)"hhmmokbtn",  NULL,0 );
           
  XtAddCallback( *txt_a,   XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"txt");
  XtAddCallback( okbtn,    XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"ok");
  XtAddCallback( hhincbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"hi" );
  XtAddCallback( hhdecbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"hd" );
  XtAddCallback( mmincbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"mi" );
  XtAddCallback( mmdecbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"md" );
  XtAddCallback( ddincbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"di" );
  XtAddCallback( dddecbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"dd" );
  XtAddCallback( moincbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"ni" );
  XtAddCallback( modecbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"nd" );
  XtAddCallback( yyincbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"yi" );
  XtAddCallback( yydecbtn, XmNactivateCallback, hhmmddmoyy_cbf_a, (char *)"yd" );

  /*
  XsAttach1FFXX( hhincbtn );
  XsAttach1LFXX( mmincbtn, hhincbtn );
  XsAttach1LFXX( ddincbtn, mmincbtn );
  XsAttach1LFXX( moincbtn, ddincbtn );
  XsAttach1XFFX( yyincbtn );
  */

  XtVaSetValues( hhincbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( mmincbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhincbtn,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( ddincbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      mmincbtn,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( moincbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      ddincbtn,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );
  XtVaSetValues( yyincbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_FORM, NULL );


  XtVaSetValues( hhdecbtn, XmNleftAttachment,  XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhincbtn, NULL );
  XtVaSetValues( mmdecbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      hhdecbtn,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       mmincbtn, NULL );
  XtVaSetValues( dddecbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      mmdecbtn,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       ddincbtn, NULL );
  XtVaSetValues( modecbtn, XmNleftAttachment,  XmATTACH_WIDGET,
		           XmNleftWidget,      dddecbtn,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       moincbtn, NULL );
  XtVaSetValues( yydecbtn, XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       yyincbtn, NULL );

  XtVaSetValues( *txt_a,   XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       hhdecbtn, NULL );
  XtVaSetValues( okbtn,    XmNleftAttachment,  XmATTACH_FORM,
		           XmNrightAttachment, XmATTACH_FORM, 
		           XmNbottomAttachment,XmATTACH_FORM,
		           XmNtopAttachment,   XmATTACH_WIDGET,
		           XmNtopWidget,       *txt_a,   NULL );

  XtManageChild( hhincbtn  );  XtManageChild( hhdecbtn  );
  XtManageChild( mmincbtn  );  XtManageChild( mmdecbtn  );
  XtManageChild( ddincbtn  );  XtManageChild( dddecbtn  );
  XtManageChild( moincbtn  );  XtManageChild( modecbtn  );
  XtManageChild( yyincbtn  );  XtManageChild( yydecbtn  );
  XtManageChild( *txt_a    );
  XtManageChild( okbtn);  
  XtManageChild( pop  );
}
