Viewing contents of file '../idllib/astron/contrib/varosi/vlib/allpro/get_window.pro'
;+
; NAME:
; get_window
;
; PURPOSE:
; Get a new window or set focus to existing window (non /FREE windows).
; This makes repeated use of windows easier:
; first call creates window, subsequent calls just set focus to it.
; If window was deleted, then it is just recreated with no errors.
; Window size and position values are the defaults of IDL,
; unless specified with the usual window routine keywords.
; If existing window size is different then specified in keywords
; it is recreated with requested size. If new window is requested
; and more than 32 windows exist (max # of non /FREE windows)
; this routine stops with request that user delete a window,
; then continue (IDL> .c), and then new window will be created.
;
; CALLING:
; get_window, winum
;
; INPUTS:
; winum = 0 <= integer <= 31, window # to get, default is new window.
; If window exists the focus is set to it.
; If # is negative, creates new window.
;
; KEYWORDS:
;
; XSIZE, YSIZE = size of window (optional),
; default for new window: 640 by 512.
;
; /SHOW : de-iconify and/or pop window into view.
; /ERASE : erase contents of an existing window.
;
; Standard window keywords such as TITLE, XPOS, and YPOS
; are passed to window call via _EXTRA keyword mechanism.
;
; OUTPUTS:
; winum = window # actually created or focus set to.
;
; RESTRICTIONS:
; Works only with window numbers between 0 and 31 (inclusive),
; not the /FREE created windows which have numbers 32 and higher.
; PROCEDURE:
; Get the numbers of currently open windows
; and check if in table or create a new window.
; HISTORY:
; Written: Frank Varosi NASA/GSFC 1990.
; F.V.1992, mod to handle new IDL-X feature that #>31 are for /FREE only.
; F.V.1995, mod to return if not windowing system,
; and on Macintosh cannot check window states so skip it.
; F.V.1998, mod to _EXTRA keyword instead of XPOS and YPOS explicitly.
;-
pro get_window, winum, XSIZE=xsiz, YSIZE=ysiz, $
SHOW=show, ERASE=erase, _EXTRA=extra
CASE !D.name OF
"X": device,WINDOW_STATE=win_flags
"SUN": device,WINDOW_STATE=win_flags
"WIN": device,WINDOW_STATE=win_flags
"MAC": win_flags = intarr(32)
else: return
ENDCASE
if N_elements( win_flags ) GT 32 then win_flags = win_flags(0:31)
if N_elements( xsiz ) EQ 1 then xsize=xsiz else xsize=640
if N_elements( ysiz ) EQ 1 then ysize=ysiz else ysize=512
if N_elements( winum ) NE 1 then begin
w = where( win_flags EQ 0, nw )
if (nw GT 0) then winum = w(nw-1) else goto,FULL
window, winum, XSIZ=xsize, YSIZ=ysize, _EXTRA=extra
endif else if (winum LT 0) then begin
w = where( win_flags EQ 0, nw )
if (nw GT 0) then winum = w(nw-1) else goto,FULL
window, winum, XSIZ=xsize, YSIZ=ysize, _EXTRA=extra
endif else begin
if winum GE N_elements( win_flags ) then begin
winum = -1
get_window, winum, XS=xsize, YS=ysize,$
SHOW=show, _EXTRA=extra
return
endif
if win_flags(winum) EQ 0 then begin
window, winum, XSIZ=xsize, YSIZ=ysize, _EXTRA=extra
endif else begin
wset,winum
if keyword_set( show ) then wshow,winum,ICON=0
if keyword_set( erase ) then erase
if (N_elements( xsiz ) EQ 1) OR $
(N_elements( ysiz ) EQ 1) then begin
if N_elements( xsiz ) ne 1 then xsiz = !D.x_vsize
if N_elements( ysiz ) ne 1 then ysiz = !D.y_vsize
if (xsiz NE !D.x_vsize) OR $
(ysiz NE !D.y_vsize) then begin
window, winum, XS=xsiz, YS=ysiz, $
_EXTRA=extra
endif
endif
endelse
endelse
return
FULL: message,"all 32 of non-FREE windows are being used!",/INFO
stop," please delete unused windows and then: IDL> .con" + string(7b)
get_window, winum, XSIZ=xsize, YSIZ=ysize, _EXTRA=extra, $
SHOW=show, ERASE=erase
end