PRO qView_GetData, state, event, wid_send=wid_send, send_event=send_event
    @compile_opt.pro        ; On error, return to caller

status = qImage_TriggerSend(event, state.wid_view, state.wid_data, wid_send, send_event)

CASE status of
0B:                                 ; No qImage widget exists (yet)
1B: RETURN                          ; Return to event handler to send 'send_event' to 'wid_send'
2B: qView_SetInfo, state, event, /boxset        ; Process QIMAGE_SEND event
ENDCASE

IF NOT qView_GetInfo(state, dim=dim, subdim=subdim, offset=offset) THEN BEGIN
    i = dialog_message('No area selected. Click "Set Area".', dialog_parent=state.wid_box)
    RETURN
ENDIF

box = offset#[1,1]+[ [0,0], [subdim-1] ]

IF box[0] LT 0 OR box[1] LT 0 OR box[2] GE dim[0] OR box[3] GE dim[1] THEN BEGIN
    i = dialog_message( dialog_parent=state.wid_box,    $
            ['Current box from '+strcompress(dim[0])+' x'+strcompress(dim[1])+' image', $
            'X:['+strcompress(box[0])+'-'+strcompress(box[2])+']  '+                    $
            'Y:['+strcompress(box[1])+'-'+strcompress(box[3])+']','','Invalid area. Click "Set Area".'])
    RETURN
ENDIF

IF dialog_message( /question, /cancel, dialog_parent=state.wid_box,                 $
            ['Current box from '+strcompress(dim[0])+' x'+strcompress(dim[1])+' image', $
            'X:['+strcompress(box[0])+'-'+strcompress(box[2])+']  '+                    $
            'Y:['+strcompress(box[1])+'-'+strcompress(box[3])+']','','Box OK?']) EQ 'Yes' THEN BEGIN

    list  = qView_ImageInfo(state, /number, /list)
    nlist = list[0]                         ; # files selected
    list  = list[1:*]                       ; File indices

    widget_control, state.wid_pick, get_uvalue=allfiles, /no_copy
    files = allfiles[list,*]
    widget_control, state.wid_pick, set_uvalue=allfiles, /no_copy

    widget_control, /hourglass              ; Pause while reading image cube

    ; Set up floating array matching size of specified box.

    data = fltarr(box[2]-box[0]+1,box[3]-box[1]+1,nlist)

    ; The specified box may extend beyond the size of the images that will be read
    ; from file (these have dimension 'dim'). Portions of 'box' outside 'dim' will
    ; be zero in array 'data'

    from = [box[0:1] > 0, box[2:3] < (dim-1)]   ; Index range from 'img' used to fill 'data'
    to   = from-box[0:1]#[1,1]                  ; Index range in 'data' to be filled

    widget_control, state.wid_ftsext, get_value=exten_no; Fits extension

    catch, ierr

    IF ierr EQ 0 THEN BEGIN

        FOR i=0,nlist-1 DO BEGIN

            stat = img_read(files[i,0],img,/pseudo,img_info=tmp,exten_no=exten_no)
            IF NOT stat THEN message, /info, 'oops'
            data[to[0]:to[2],to[1]:to[3],i] = img[from[0]:from[2],from[1]:from[3]]
            files[i,1:2] = tmp

            tmp = qView_UpdateActive(state, value=list[i], time=files[i,2])

        ENDFOR

        tmp = qView_UpdateActive(state, value=list[0], time=files[0,2], /force)

    ENDIF

    catch, /cancel

    IF ierr EQ 0 THEN BEGIN
        widget_control, state.wid_data, set_uvalue=data, /no_copy, sensitive=0  ; Store image cube

        widget_control, state.wid_pick, get_uvalue=allfiles, /no_copy
        allfiles[list,1:2] = files[*,1:2]
        widget_control, state.wid_pick, set_uvalue=allfiles, /no_copy

        IF files[0,2] NE '' THEN    $
            widget_control, state.wid_time, set_uvalue=TimeLimits(TimeSet(files[*,2]), /range)

        widget_control, state.deep[2], /set_button, set_uvalue=1B

        qView_Sensitive, state

        ; Must be an easier way to do this.
        ; This sets the values of wid_win (the size of the draw widget) in the qImage_cw
        ; widget to force a window size equal to the image size

        ;widget_control, state.wid_view, get_uvalue=wid_qimage
        ;IF widget_info(wid_qimage, /valid) THEN BEGIN
        ;   widget_control, wid_qimage, get_uvalue=tmp, /no_copy
        ;   wid_child = widget_info(tmp.wid_qimage_cw, /child)
        ;   widget_control, wid_qimage, set_uvalue=tmp, /no_copy
        ;   widget_control, wid_child, get_uvalue=tmp, /no_copy
        ;   widget_control, tmp.wid_win[0], set_value=from[2]-from[0]+1
        ;   widget_control, tmp.wid_win[1], set_value=from[3]-from[1]+1
        ;   widget_control, wid_child, set_uvalue=tmp, /no_copy
        ;ENDIF

    ENDIF ELSE BEGIN

        i = dialog_message('bummer ..... read error occurred')

        qView_Sensitive, state, /set_box

    ENDELSE

ENDIF

RETURN  &  END