;+
; NAME:
;	qvu_rebin
; PURPOSE:
;	Destroys qvu widget
; CATEGORY:
;	Widget qvu
; CALLING SEQUENCE:
	PRO qvu_rebin, state, event
; INPUTS:
;	state		array[1]; type: structure
;					qset_page state structure
;	event		array[1]; type: structure
;					event structure send by 'Done' widget
; OUTPUTS:
;	(none)
; INCLUDE:
	@compile_opt.pro					; On error, return to caller
; SIDE EFFECTS:
; PROCEDURE:
; MODIFICATION HISTORY:
;	SEP-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
;-

widget_control, state.wid_grid, get_value=ngrid, get_uvalue=winsize

IF ngrid GT winsize THEN BEGIN
	widget_control, state.wid_grid, set_value=winsize
	RETURN
ENDIF

sensitive = winsize NE ngrid

congrid_sensitive = sensitive
rebin_sensitive   = sensitive AND winsize/ngrid*ngrid EQ winsize
magnify_sensitive = rebin_sensitive

widget_control, state.wid_rebin[0], get_uvalue=congrid_on
widget_control, state.wid_rebin[1], get_uvalue=rebin_on
widget_control, state.wid_rebin[2], get_uvalue=magnify_on

sensitive = [congrid_sensitive, rebin_sensitive, magnify_sensitive]
rebin_on  = [congrid_on       , rebin_on       , magnify_on       ]

n = n_elements(sensitive)
on = 0

FOR i=0,n-1 DO BEGIN

	CASE sensitive[i] OF

	0: BEGIN
		IF rebin_on[i] THEN BEGIN
			widget_control, state.wid_rebin[i], set_uvalue=0
			rebin_on[i] = 0
		ENDIF
	END

	1: BEGIN

		IF rebin_on[i] THEN BEGIN
			CASE on OF
			0: on = 1
			1: BEGIN
			    widget_control, state.wid_rebin[i], set_uvalue=0
				rebin_on[i] = 0
			END
			ENDCASE
		ENDIF

	END

	ENDCASE

ENDFOR

IF NOT on THEN BEGIN
	i = (where(sensitive))[0]
	IF i NE -1 THEN widget_control, state.wid_rebin[i], /set_button, set_uvalue=1
ENDIF

FOR i=0,n-1 DO widget_control, state.wid_rebin[i], sensitive=sensitive[i]

RETURN  &  END
