;+
; NAME:
;	SMEI_SEQUENCE::MK_PIXMAP
;
;
; PURPOSE:
;	To create a pixmap window in which to store SMEI images.
;
;
; CATEGORY:
;	SMEI_SEQUENCE
;
;
; CALLING SEQUENCE:
;	seqid->mk_pixmap
;
; KEYWORD PARAMETERS:
;	/destroy	Delete the pixmap window (needed if images are
;			added or removed from the sequence)
;	/clear		Clear the pixmap flags of the images (when
;			display options are changed)
;
; SIDE EFFECTS:
;	A pixmap window large enough to store all the images is
;	created
;
;
; MODIFICATION HISTORY:
;	Original: 11/12/02; SJT
;-

pro smei_sequence::mk_pixmap, destroy = destroy, clear = clear

if keyword_set(clear) or keyword_set(destroy) then begin
    if self -> get_pixmap() eq -1 then return
    im = self -> get_first()
    while obj_valid(im) do begin
        im -> mk_pixmap, /destroy
        im = im -> get_next()
    endwhile
    self -> set_pxm_hwm, 0
    if keyword_set(destroy) then begin
        device, window_state = wex
        if wex[self -> get_pixmap()] then $
          wdelete, self -> get_pixmap()
        self.pixmap.id = -1
        self -> set_pxm_hwm, lonarr(2)
    endif
    return
endif

wc = !d.window

im = self -> get_first()
x = 0l
y = 0l
ncol = 1
ym = 0l

zf = self -> get_zoom()

while obj_valid(im) do begin
    sz = ceil(im -> get_size()*zf)
    x = x > sz[0]
    y = y + sz[1]
    if y ge 32767L then begin   ; It appears not to be possible to
                                ; write to windows bigger than this.
        ncol = ncol+1
        y = sz[1]
    endif
    ym = y > ym
    im = im -> get_next()
endwhile

if self -> get_pixmap() ne -1 then begin
    wset, self -> get_pixmap()
    self -> mk_pixmap, /destroy
endif

window, /pixmap, /free, xsize = x*ncol, ysize = ym
self.pixmap.id = !d.window

self -> set_pxm_hwm, lonarr(2)
self.pixmap.colwidth = x

wset, wc

end
