; $Id: ppopup.pro,v 1.6 2002/09/16 20:43:56 jmspark Exp $
PRO print_ps, filename=filen, encapsulated=encap, noplot=noplot, info=info, davePtr = davePtr $
	, printer = printer
;+
;	NAME: print_ps
;	DESCRIPTION: Prints a tasxp plot on a PostScript printer
;		INTERNAL tasxp procedure
;	MODIFICATION HISTORY:
;		Paul Schleger, Riso National Lab, Nov 1993
;-
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON fitinfo_com, fitstuff
COMMON com_minchoice, minchoice, minpath

     IF NOT keyword_set(filen) THEN filen='tasxp.ps'
     psinit, FILE = filen, printer = printer, /QUIET
     IF keyword_set(encapsulated) THEN device, /ENCAPSULATED

     IF keyword_set(info) THEN BEGIN
     	psave=!P.REGION
     	!P.REGION = [0.2,0.4,0.8,1.0]
     	lasty = 0.35	;normalized y axis coordinates of where there is still room
     END ELSE lasty=-0.1


     !p.font = -1
     font = 17
     taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr $
     	, font = font

	  ;Use the typwriter font to avoid proportional spacing (#11)
      case !d.name of
     		'PRINTER': begin
     			!p.font = -1 ; 1

     			device, set_character_size = [ 64, 80 ]
     			font = 11
     			bold_font = 4
     		end
     		'PS': begin
     			!p.font = 0
     			 font = 11
     			 bold_font = 5
     		end
      endcase



     IF (fit eq 'true') THEN $
     	fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,/hardcopy,lasty=lasty
     ;Print out tasinfo as well

     IF keyword_set(info) THEN BEGIN


     	str = tasinfo(d,/ongraph,font=font, bold_font = bold_font)
     	IF (minchoice NE 'SFit') AND (fit EQ 'true') THEN $
		str = str+fitinfo(fitstuff,/ongraph,font=font)
     	xyouts, 0.1, lasty, str, /NORMAL, charsize=0.7
     	!P.REGION = psave

     END
     psterm, noplot=noplot, printer = printer
     !p.font = -1
     case !version.os_family of
     	'Windows': set_plot, 'WIN'
     	'MacOS': set_plot, 'MAC'
     	else: set_plot, 'X'
     endcase
END

pro ppopup_event,ev
;Event Handler for ppopup, below
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON COMMON_fname, name, first_time
COMMON com_stuffy, info
widget_control, name, GET_VALUE=filen
filen=filen(0)
CASE ev.value of
  'Print': BEGIN
     widget_control,/hour
     IF (strlen(filen) EQ 0) THEN $
     	filen=0 ELSE $
     	filen=filen+'.ps'
     print_ps, NOPLOT = 0, filename=filen, info=info
     ;print_ps, info=info, /printer
     widget_control,ev.top,/destroy
     END
  'Encapsulated Postscript file':BEGIN
     widget_control,/hour
     IF (strlen(filen) EQ 0) THEN filen=0 ELSE filen=filen+'.eps'
     print_ps, /NOPLOT, /ENCAPSULATED, filename=filen, info=info
     widget_control,ev.top,/destroy
     END
  'Postscript file':BEGIN
     widget_control,/hour
     IF (strlen(filen) EQ 0) THEN $
     	filen=0 ELSE $
     	filen=filen+'.ps'
     print_ps, /NOPLOT, filename=filen, info=info
     widget_control, ev.top, /destroy
     END
  'CGM file':BEGIN
     widget_control,/hour
     set_plot,'cgm'
     loadct,0
     IF (strlen(filen) EQ 0) THEN filen=0 ELSE filen=filen+'.cgm'
     device,filename=filen,/binary
     taspl,d,xax,yax,nsym=symboln,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, davePtr=davePtr
     IF (fit eq 'true') THEN fitov,d,xax,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,/hardcopy
     device,/close
     set_plot,'X'
     widget_control,ev.top,/destroy
     END
  'Yes': info=1
  'No': info=0
  'Cancel':widget_control,ev.top,/destroy
  ENDCASE
END

pro ppopup
;+
;	NAME: ppopup
;	DESCRIPTION: Pops up a window in tasxp to make a hardcopy of a plot
;		INTERNAL tasxp PROCEDURE
;	MODIFICATION HISTORY:
;		Thom Mason, Riso National Lab., 1993
;	Nov 1993 Paul Schleger, ditto
;		changed it so that we use compound widget function calls
;		Also added an input field to allow printing to a seperate
;		file
;-
COMMON data,xax,yax,fit,symboln,dindex,d,xmin,xmax,ymin,ymax,pcomm
COMMON COMMON_fname, name, first_time
COMMON com_stuffy, info
base=widget_base(title='Hardcopy',xsize=300,/column)
things=['Print','Encapsulated Postscript file','Postscript file',$
	'CGM file','Cancel']
buttons=cw_bgroup(base,things,/RETURN_NAME,/COLUMN)
button6=cw_bgroup(base,LABEL_LEFT='Print Extra Info?',['Yes','No'],$
/EXCLUSIVE,/RETURN_NAME,ROW=1,SET_VALUE=0)
info=1
IF (first_time NE 0) THEN BEGIN
	IF (strlen(d.text(0)) LE 10) THEN fname=d.text(0) ELSE fname='tasxp'
	first_time=0
END
name=cw_field(base,uvalue='File',/STRING,/COLUMN,TITLE='File Name (no extension):',$
	value=fname)
widget_control,base,/realize
xmanager,'ppopup',base
END



