c************
c  Description:	Include file for the XDATALIST primitive
c
c  Author:	CLI	
c
c  $Revision: 1.1 $
c  $Modtime:   01 May 1996 15:43:42  $
c
c************
	implicit none
	include 'primitive.inc'
	include 'xprimitive.inc'
	include 'xwidgets.inc'

	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	!			 CONSTANTS
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	! Hard Limits
	integer*4 NTMPL, NUMCOLORS
	parameter (NTMPL=7, NUMCOLORS=16)
	integer*4 DEFSTRLEN, LBLLEN, FMTLEN
	parameter (DEFSTRLEN=512, LBLLEN=256, FMTLEN=40)

	! Cursor granularity constants
	integer*4 CR_NONE, CR_DEF, CR_ROW, CR_FIELD
	integer*4 CR_SCALAR, CR_FCOL, CR_SCOL
	parameter (CR_NONE=-1, CR_DEF=0, CR_ROW=1, CR_FIELD=2)
	parameter (CR_SCALAR=3, CR_FCOL=4, CR_SCOL=5)

	! Selection codes
	integer*4 SEL_NONE, SEL_ALL, SEL_INVALID
	integer*4 SEL_BEFORE_VIEW, SEL_BEYOND_VIEW
	parameter (SEL_NONE=0, SEL_ALL=-1, SEL_INVALID=-99)
	parameter (SEL_BEFORE_VIEW=-97, SEL_BEYOND_VIEW=-98)

	! Coloring codes
	integer*4 USEDEFCOLORS, DEFCURCOLOR
	parameter (USEDEFCOLORS=-99, DEFCURCOLOR=64)
	integer*4 COLOR_BY_NUM,   COLOR_BY_SUBR
	integer*4 COLOR_BY_FIELD, COLOR_BY_ENUM
	parameter (COLOR_BY_NUM=1,   COLOR_BY_SUBR=2)
	parameter (COLOR_BY_FIELD=3, COLOR_BY_ENUM=4)

	! Miscellany
	integer*4 DEFAULT_SPACING
	parameter (DEFAULT_SPACING=2)


	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	!		     FUNCTION DECLARATIONS
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	logical*4 XDATA_SENDINFOMSG
	real*8	  XDATA_ROW2ELEMT
	integer*4 XDATA_ELEMT2ROW
	logical*4 XDATA_WARNING



	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	!			DATA STRUCTURES
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	!!! Be sure to change FIELDINFOSIZE if /FIELDINFO/ changes !!!
	integer*4	FIELDINFOSIZE  ! Must be 8-byte aligned
	parameter	(FIELDINFOSIZE = 128 + 5*L_M_Ptr)
	structure /FIELDINFO/
	  record /M_PTR/ label		  ! Field label
	  record /M_PTR/ dispform	  ! Output display format string
	  record /M_PTR/ menustr	  ! Pointer to menu keyword string
	  record /M_PTR/ mvalues	  ! Pointer to menu value data
	  record /M_PTR/ mcolors	  ! Pointer to menu color data
	  integer*4	field		  ! Field number
	  integer*4	scalar1		  ! Atom index of 1st scalar in field
	  integer*4	nscalars	  ! # scalars visible in field
	  integer*4	offset		  ! Offset in chars from column 1
	  integer*4	width		  ! Field display width in characters
	  integer*4	swidth		  ! Scalar display width in characters
	  integer*4	spacing		  ! Additional spacing at end of field
	  integer*4	atomoff		  ! Atom byte offset into log. elemt
	  integer*4	fieldoff 	  ! Field byte offset into log. elemt
					  ! (== atomoff unless scalar1 != 0)
	  integer*4	bpf		  ! Bytes Per Field
	  integer*4	subelemt	  ! element/subrecord/subcomponent #
	  integer*4	llabel		  ! String length of label
	  integer*4	ldispform	  ! String length of display fmt str
	  integer*4	lmenustr	  ! String length of menu string
	  integer*4	lmvalues	  ! #bytes allocated for mvalues
	  integer*4	nmenuitems	  ! Number of menu items
	  integer*4	color		  ! color value (interp w/colormode)
	  integer*4	colormode	  ! COLOR_BY_[NUM|SUBR|FIELD]
	  logical*4	colordep	  ! do other fields mimic my colors?
	  logical*4	enumerated	  ! Is this an enumerated field?
	  logical*4	usenullval	  ! Is the NULLVAL keyword specified?
	  logical*4	FILL		  ! Keep this structure 8-byte aligned
	  real*8	nullval		  ! value of NULLVAL keyword
	  character*28	subname		  ! subrecord/subcomponent name
	  character*2	format		  ! atom digraph
	  character*2	edit		  ! Edit action to perform
	endstructure

	!!! Be sure to change EFSCOORDSIZE if /EFSCOORD/ changes !!!
	integer*4	EFSCOORDSIZE
	parameter	(EFSCOORDSIZE=24)  ! Must be 8-byte aligned
	structure /EFSCOORD/
	  real*8	elemt	 	! Logical element number
	  integer*4	field	 	! Field number
	  integer*4	scalar	 	! Scalar number
	  integer*4	color		! Color number [1,NUMCOLORS]
	  integer*4	id		! user-defined non-zero ID#
	endstructure

	integer*4 HLITREGIONSIZE
	parameter (HLITREGIONSIZE = 2*EFSCOORDSIZE)
	structure /HLITREGION/ 
	  record /EFSCOORD/	from	! Upper left hand coords
	  record /EFSCOORD/	to	! Lower right hand coords
	endstructure
	integer*4 HLITDEFAULTVAL
	parameter (HLITDEFAULTVAL = -99)

	structure /GX/ 
	  record /M_PTR/ phData		! Pointer to Data Header
	  record /M_PTR/ pbData		! Pointer to Data Buffer
	  record /M_PTR/ phTmpl(0:NTMPL)! Pointers to Template Headers
	  record /M_PTR/ pbFinfo	! Pointer to Field info Buffer
	  record /M_PTR/ pbPoll		! Pointer to Poll Buffer
	  record /M_PTR/ pbScreen	! Pointer to Screen Buffer
	  record /M_PTR/ pbPaste	! Pointer to Paste Buffer
	  record /M_PTR/ pbScratch	! Pointer to Scratch Buffer
	  record /M_PTR/ pbHlit		! Pointer to HighLIghT buffer
	  record /SCROLLBAR/ sbvert	! Vertical scrollbar
	  record /SCROLLBAR/ sbhorz	! Horizontal scrollbar
	  real*8	 nsize		! #logical elements in data file
	  real*8	 top		! Index of Topmost visible elemt
	  real*8	 elemt		! Index of currently selected elemt
	  integer*4	 field		! Index of currently selected field
	  integer*4	 scalar		! Index of currently selected scalar
	  integer*4	 status		! Program status -1=exit 0=dormant
	  integer*4	 modify		! 0:readonly 1:modify 2:"freemod"
	  integer*4	 ntmpl		! Number of Templates
	  integer*4	 view		! Index into Gx.phTmpl()
	  integer*4	 ndatarows	! Number of displayable data rows
	  integer*4	 nvisrows	! #rows containing displayed data
	  integer*4	 ntitle		! Number of Title rows
	  integer*4	 nfields	! Number of Fields
	  integer*4	 nxdlfields	! Number of X-Datalist Fields
					!  (== nfields except for Type 2000)
	  integer*4	 left		! Character index of Leftmost column
	  integer*4	 fleft		! Index of Leftmost visible field
	  integer*4	 fright		! Index of Rightmost visible field
	  integer*4	 class		! Data file's X-Midas file Type class
	  integer*4	 bpe		! Data file's Bytes Per logical Element
	  integer*4	 dispwidth	! Display Width in chars
	  integer*4	 ndatacols	! Currently displayable width in chars
	  integer*4	 nviscols	! #cols containing displayed data
	  integer*4	 spacing	! Default char. spacing between fields
	  integer*4	 labelstyle	! 0:OFF 1:ON 2:UNDERLINE
	  integer*4	 indexpos	! -1:LEFT, 0:OFF, 1:RIGHT
	  integer*4	 iwidth		! Width of index field in chars
	  integer*4	 iradix		! Number by which to MOD indices
	  integer*4	 ioffset	! Arbitrary offset to add to indices
	  integer*4	 defcolor	! Default color (data,labels,etc.)
	  integer*4	 color		! Global color code
	  integer*4	 colormode	! COLOR_BY_SUBR or COLOR_BY_FIELD
	  integer*4	 cursor		! Cursor type (see CR_* params)
	  integer*4	 curcolor	! Cursor color (arg to MX$COLORTEXT)
	  integer*4	 curcolor_bg	! Cursor Background Color
	  integer*4	 curcolor_fg	! Cursor Foreground Color
	  integer*4	 nhlit		! Number of HighLIghT entries
	  integer*4	 ahlit		! Size of HighLIghT buffer in regions
	  integer*4	 pastesize	! Size of Paste Buffer in log elemts
	  integer*4	 cntrls		! MTAG control mode
	  integer*4	 msgid		! primitive id to send info msgs to
	  integer*4	 msgmask	! mask specifying which msgs to send
	  integer*4	 xmboff		! Mouse button deactivation mask
	  real*4	 doubleclick	! Sec defining a mouse double click
	  real*4	 version	! Version of currenly open template
	  real*4	 pollperiod	! Period (in sec) to reread data file
	  real*4	 polltime	! Time of last reread
	  logical*1	 indexed	! Display row indices?
	  logical*1	 fnametitle	! Set window title to filename?
	  logical*1	 panx, pany	! Are horz/vert scrollbars needed?
	  logical*1	 pastebufempty	! Is the Paste Buffer empty?
	  logical*1	 colordep	! Are there color dependencies?
	  logical*1	 xparent_cursor ! Does cursor let field color through?
	  logical*1	 scrambled	! Are the fields contig Left to Right
	  logical*1	 tracksel	! Keep selection in view on resize?
	endstructure
	record /GX/ Gx

	! Common Block
	common /XDLGX/ Gx

