;+
; NAME:
;	qTool_State
; PURPOSE:
; CATEGORY:
; CALLING SEQUENCE:
	FUNCTION qTool_State, state, event, send=send, silent=silent
; INPUTS:
;	state
; OPTIONAL INPUT PARAMETERS:
;	/send
; INCLUDE:
	@compile_opt.pro		; On error, return to caller
; CALLS:
;	IsType, InitVar
; PROCEDURE:
; MODIFICATION HISTORY:
;	JUL-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
;-

tool_state = {QTOOL_SEND, ID:0L, TOP:0L, HANDLER:0L,    $
	on		  : 1	, $
	update	  : 0	, $
	zoom_val  : 1 	, $
	zoom_uval : 0.0	, $
	rebin_val : 1	, $
	rebin_uval: 0	, $
	box_drag  : 0	, $
	white	  : 0	, $
	fixz	  : 0	, $
	zlog	  : 0	, $
	zmin	  : 0.0 , $
	zmax	  : 0.0 , $
	ellipse   : 0	, $
	mouse	  : 0	, $
	fullsize  : 0	, $
	ctable	  : 0	}

IF IsType(state,/undefined) THEN	$
	RETURN, tool_state

InitVar, send  , /key
InitVar, silent, 0

widget_control, state.wid_zoom, get_value=vtmp, get_uvalue=utmp

tool_state.zoom_val  = vtmp
tool_state.zoom_uval = utmp 

widget_control, state.wid_rebin, get_value=vtmp, get_uvalue=utmp

tool_state.rebin_val  = vtmp
tool_state.rebin_uval = utmp 

widget_control, state.wid_white, get_uvalue=utmp
tool_state.white = utmp

widget_control, state.wid_fixz, get_uvalue=utmp
tool_state.fixz = utmp

widget_control, state.wid_zlog, get_uvalue=utmp
tool_state.zlog = utmp

widget_control, state.wid_ellipse, get_uvalue=utmp
tool_state.ellipse = utmp

widget_control, state.wid_zmin, get_value=vtmp
tool_state.zmin = vtmp

widget_control, state.wid_zmax, get_value=vtmp
tool_state.zmax = vtmp

tool_state.mouse  = widget_info(state.wid_mouse , /droplist_select)
tool_state.ctable = widget_info(state.wid_ctable, /droplist_select)

CASE event.id OF
state.wid_exit		: tool_state.on 	=  0
state.wid_white 	: tool_state.update =  1
state.wid_ctable	: tool_state.update =  2
state.wid_mouse 	: tool_state.update =  3
state.wid_fullsize	: tool_state.update =  4
state.wid_histogram : tool_state.update =  5
state.wid_fixz		: tool_state.update =  6
state.wid_zlog		: tool_state.update =  7
state.wid_ellipse	: tool_state.update =  8
state.wid_zmin		: tool_state.update =  9
state.wid_zmax		: tool_state.update = 10
ELSE				: tool_state.update =  0
ENDCASE

CASE send OF

0: BEGIN

	tags = tag_names(tool_state)	
	format = '(A'+strcompress(max(strlen(tags)),/rem)+')'
	FOR i=0,n_elements(tags)-1 DO boost, tmp, string(tags[i],format=format)+' = '+string(tool_state.(i))
	tmp = dialog_message(/info, dialog_parent=state.wid_info, tmp)

END

1: IF widget_info(state.wid_send, /valid) THEN		$
		widget_control, state.wid_send, send_event=tool_state

ENDCASE

RETURN, tool_state  &  END
