;+
; Project     : SOHO - CDS           
;                                                                   
; Name        : CDS_TEMP_EVENT
;                                                   
; Purpose     : Services the widget events from CDS_TEMP_MENU
;                                                   
; Explanation : Used within the temperature plotting routine.
;                                                   
; Use         : Only used by XMANAGER to service ENG_MON_MENU
;       
; Inputs      : ev  -  structure of event generated
;                                                   
; Opt. Inputs : None
;                                                   
; Outputs     : None
;                                                   
; Opt. Outputs: None
;                                                   
; Keywords    : None
;
; Calls       : None
;                                                   
; Restrictions: None
;                                                   
; Side effects: None
;                                                   
; Category    : Telemetry
;                                                   
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 27-Oct-95
;                                                   
; Modified    : Delete windows before a replot.  CDP, 18-Dec-95
;               Include reset of time limits.  CDP, 19-DEc-95
;               Modify window handling for IDL v5.2.  CDP, 14-Apr-99
;
; Version     : Version 4, 14-Apr-99
;-                                       

PRO cds_temp_event, ev

;
;  common for communication
;
@cds_temperature.com
common cds_utplot_com, cds_xoffset

;
;  determine the type of widget event to be serviced
;
type = TAG_NAMES(ev, /structure)


;
;  if it is a button then retrieve the user value 
;
IF (type EQ 'WIDGET_BUTTON') THEN BEGIN
   WIDGET_CONTROL, ev.id, GET_UVALUE=uvalue


;
;  begin to act depending on the identification of the widget
;

;
;  if a top level DONE was requested, everything dies
;                 ====

   if (uvalue EQ 'Done') then begin

      DEVICE, WINDOW_STATE=STATE
      IF N_ELEMENTS(STATE) GT 32 THEN FOR I_WIN=32,N_ELEMENTS(STATE)-1 DO $
                IF STATE(I_WIN) THEN WDELETE, I_WIN
      WIDGET_CONTROL, /destroy, ev.top
   endif 



;
;  want to SELECT parameters
;          ======
  
   IF (uvalue EQ 'PARMS') THEN BEGIN
      sel_tsens_menu
      xmanager,"sel_tsens",sel_tplot_base
   endif

;
;  want to set TIME range
;              ====
  
   IF (uvalue EQ 'TIME') THEN BEGIN
      widget_control,msg_widg,/append,$
                     set_val='Select start and stop times '+$
                             '(TWO mouse button clicks)'
      wset,!d.window
      wshow
      mintime = min(cds_temp_log.time)
      maxtime = max(cds_temp_log.time)

      cursor,t1,y,3,/data
      tplot_min = utc2tai(sec2utc(t1 + cds_xoffset))
      outplot,[tai2utc(tplot_min),tai2utc(tplot_min)],[-1000,1000],thick=2

      cursor,t2,y,3,/data
      tplot_max = utc2tai(sec2utc(t2 + cds_xoffset))
      outplot,[tai2utc(tplot_max),tai2utc(tplot_max)],[-1000,1000],line=2
      if tplot_min gt tplot_max then begin
         t1= tplot_min
         tplot_min = tplot_max
         tplot_max = t1
      endif

   endif


;
;  want to REPLOT parameters
;          ======
  
   if (uvalue EQ 'REPLOT') then begin
      DEVICE, WINDOW_STATE=STATE
      IF N_ELEMENTS(STATE) GT 32 THEN FOR I_WIN=32,N_ELEMENTS(STATE)-1 DO $
                IF STATE(I_WIN) THEN WDELETE, I_WIN
      cds_tplot
   endif

;
;  want to RESET time range
;          =====
  
   if (uvalue EQ 'RESET') then begin
      tplot_min = min(cds_temp_log.time)
      tplot_max = max(cds_temp_log.time)
      cds_tplot
   endif

;
;  want some HELP
;            ====
  
   if (uvalue EQ 'HELP') THEN BEGIN
      widg_help, 'cds_temp.hlp'
   endif

;
;  want HARDCOPY on/off
;       ========
  
   if (uvalue EQ 'HARD') THEN BEGIN
      if hard then begin
         hard = 0
         widget_control,hardonoff,set_val='Hardcopy OFF'
      endif else begin
         hard = 1
         widget_control,hardonoff,set_val='Hardcopy ON'
      endelse
   endif


ENDIF

END


