;+
; NAME:
;	qImage_cw_Property
; PURPOSE:
;	Extracts widget properties from state vector
; CATEGORY:
;	Compound widget qImage_cw
; CALLING SEQUENCE:
	FUNCTION qImage_cw_Property, state	, $
		screen_size 	= screen_size	, $
		slider_origin	= slider_origin , $
		blowup_size 	= blowup_size	, $
		image_size		= image_size	, $
		window_nr		= window_nr 	, $
		image_name		= image_name	, $
		no_extension	= no_extension	, $
		image_time		= image_time	, $
		quaternion		= quaternion
; INPUTS:
;	state	    array[1]; type: structure
;					qImage_cw state structure
; OUTPUTS:
;	result		depends on keyword selected
; OPTIONAL OUTPUT PARAMETERS:
;	window_nr=window_nr
;				window of draw widget (/screen_size set) or
;				blowup window (/blowup_size set)
; INCLUDE:
	@compile_opt.pro		; On error, return to caller
; CALLS:
;	IsType, TimeGet, GetFileSpec, smei_filename
;	smei_sky_field
; PROCEDURE:
; MODIFICATION HISTORY:
;	MAY-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
;-

CASE 1 OF

IsType(image_name,/defined): BEGIN

	widget_control, state.wid_self, get_uvalue=info, /no_copy
	IF IsType(info, /string) THEN full_name = info[0]
	widget_control, state.wid_self, set_uvalue=info, /no_copy

	; 'full_name' is fully-qualified name with (optional) Fits
	; extension appended following an underscore.

	InitVar, no_extension, /key

	CASE 1 OF
	IsType(full_name,/undefined): result = ''
	1-no_extension				: result = full_name
	ELSE: BEGIN
		type = GetFileSpec(full_name,part='type')
		tmp = strpos(type,'_')
		IF tmp[0] NE -1 THEN	$
			full_name = GetFileSpec(upto='name')+strmid(type,0,tmp)
		result = full_name
	END
	ENDCASE

END

IsType(image_time,/defined): BEGIN

	widget_control, state.wid_self, get_uvalue=info, /no_copy
	IF IsType(info, /string) THEN full_name = info[0]
	widget_control, state.wid_self, set_uvalue=info, /no_copy

	result = strarr(4)

	; 'full_name' is fully-qualified name with (optional) Fits
	; extension appended following an underscore.

	IF IsType(full_name,/defined) THEN BEGIN

		type = GetFileSpec(full_name,part='type',/strict)
 
		; Check for Fits extension (added to file type as e.g. "_2"
		; Strip the extension from 'full_name'

		tmp = strpos(type,'_')
		IF tmp NE -1 THEN BEGIN
			exten_no = fix(strmid(type,tmp+1))
			full_name = GetFileSpec(upto='name')+strmid(type,0,tmp)
		ENDIF

		name = GetFileSpec(part='name')
		time = smei_filename(name, cam=cam, mode=mode, pos_tt=tmp)

		IF tmp NE -1 THEN BEGIN
			CASE IsType(mode,/generic_int) OF
			0: InitVar, exten_no, 0
			1: mode = 'm'+strcompress(mode,/rem)
			ENDCASE
			result[0:2] = [TimeGet(time,/ydoy),mode,'c'+strcompress(cam,/rem)]
			IF IsType(exten_no,/defined) THEN	$
				result[3] = smei_sky_field(full_name,exten_no=exten_no,/cvsmei)
		ENDIF

	ENDIF

END

IsType(quaternion,/defined): BEGIN

	widget_control, state.wid_self, get_uvalue=info, /no_copy
	IF IsType(info, /string) THEN name = info[0]
	widget_control, state.wid_self, set_uvalue=info, /no_copy

	; 'name' is fully-qualified name

	CASE IsType(name,/defined) OF
	0: Result = 0.0d0
	1: BEGIN
		result = smei_getfile(name,/get_hdr,/exists)
		result = smei_property(result,/quaternion)
	END
	ENDCASE
	
END

1-widget_info(state.wid_draw_wrap, /valid_id):	$
	result = -1

IsType(screen_size,/defined): BEGIN
	widget_control, state.wid_draw, get_value=window_nr
	wold = !d.window
	IF window_nr NE wold THEN wset, window_nr
	result = [!d.x_size,!d.y_size]
	IF window_nr NE wold THEN wset, wold
END

IsType(blowup_size,/defined): BEGIN
	widget_control, state.wid_blowup, get_value=window_nr
	wold = !d.window
	IF window_nr NE wold THEN wset, window_nr
	result = [!d.x_size,!d.y_size]
	IF window_nr NE wold THEN wset, wold
END

IsType(slider_origin,/defined): BEGIN
	widget_control, state.wid_xslide, get_value=ix
	widget_control, state.wid_yslide, get_value=iy
	result = [ix,iy]
END

IsType(image_size,/defined): BEGIN
	widget_control, state.wid_image, get_uvalue=image, /no_copy
	result = size(image,/dim)
	widget_control, state.wid_image, set_uvalue=image, /no_copy
END

ENDCASE

RETURN, result  &  END
