/*
** Generated by X-Designer
*/

/*
** X-Designer-generated prelude.
** Do not edit lines before "End of X-Designer generated prelude"
** Lines beginning ** X-Designer Stub indicate a stub
** which will not be output on re-generation
*/

/*
**LIBS: -lXm -lXt -lX11
*/

#include <stdlib.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>

#include <Xm/Xm.h>
#include <Xm/SpinB.h>

#include "SpinBoxClock.h"



/* End of X-Designer generated prelude */

#include <time.h>

/*
** X-Designer Stub set_initial_clock
*/

#ifndef   _NO_PROTO
void set_initial_clock(void)
#else  /* _NO_PROTO */
void set_initial_clock()
#endif /* _NO_PROTO */
{
	long       tick = time((long *) 0) ;
	struct tm *tptr = localtime(&tick) ;

	XtVaSetValues(hours,   XmNposition, tptr->tm_hour, NULL) ;	
	XtVaSetValues(minutes, XmNposition, tptr->tm_min,  NULL) ;	
	XtVaSetValues(seconds, XmNposition, tptr->tm_sec,  NULL) ;	
}

/*
** X-Designer Stub check_time
*/

#ifndef   _NO_PROTO
static void check_time(Widget w, int reason)
#else  /* _NO_PROTO */
static void check_time(w, reason)
	Widget w ;
	int    reason ;
#endif /* _NO_PROTO */
{
	int    maximum  = 0 ;
	int    minimum  = 0 ;
	int    position = 0 ;
		
	XtVaGetValues(w, 
		      XmNmaximumValue, &maximum, 
		      XmNminimumValue, &minimum, 
		      XmNposition,     &position, 
		      NULL) ;

	     if (reason == XmCR_SPIN_PRIOR) {
		if (--position < minimum) {
			position = maximum ;
		}
	}
	else if (reason == XmCR_SPIN_NEXT) {
		if (++position > maximum) {
			position = minimum ;
		}
	}
		
	XtVaSetValues(w, XmNposition, position, NULL) ;
}

/*
** X-Designer Stub value_changed_callback
*/

#ifndef   _NO_PROTO
void value_changed_callback(Widget w, XtPointer client_data, XtPointer xt_call_data)
#else  /* _NO_PROTO */
void value_changed_callback(w, client_data, call_data)
	Widget                   w ;
	XtPointer                client_data ;
	XmSpinBoxCallbackStruct *call_data ;
#endif /* _NO_PROTO */
{
#ifndef   _NO_PROTO
	XmSpinBoxCallbackStruct *call_data = (XmSpinBoxCallbackStruct *) xt_call_data ;
#endif /* _NO_PROTO */
	int    maximum  = 0 ;
	int    minimum  = 0 ;
	int    position = 0 ;
	Widget widget   = call_data->widget ;

	if (call_data->crossed_boundary == True) {
		if (widget == seconds) {
			XtVaGetValues(minutes, 
				      XmNmaximumValue, &maximum, 
				      XmNminimumValue, &minimum, 
				      XmNposition,     &position, 
				      NULL) ;
			
			check_time(minutes, call_data->reason) ;
	     
			     if (call_data->reason == XmCR_SPIN_PRIOR) {
				if (position == minimum) {
					widget = minutes ;
				}
			}
			else if (call_data->reason == XmCR_SPIN_NEXT) {
				if (position == maximum) {
					widget = minutes ;
				}
			}
		}
		
		if (widget == minutes) {
			check_time(hours, call_data->reason) ;
		}
	}
}

