// pagecom.sr


get "BRAVO1.DF";
get "ST.DF";
get "MSG.DF";
get "DISPLAY.DF";
get "ALTOFILESYS.D";
get "FONT.DF";
get "VM.DF";
get "COM.DF";
get "HARDCOPY.DF";


// Incoming Procedures

external	[
	errhlt
	DefaultHo
	mapcp
	CpParseDocProf
	CpFormatPage
	ult
	umin
	setupdate
	invalidatewindow
// 	getfontc
	errhlta
	SplitWw
	updatewindow
	underline
	setsel
	umax
	SetRegionSys
	updatedisplay
	];


// Incoming Statics

external	[
	mpWwWwd
	vfDiablomode
	rgmaccp
	vcplast
// 	mpfunmagi
// 	mpfunfddfaulted
	mpfnof
	vmapstatus
	parsacred
	macww
	rgyfirst
	vxleftmargstd
	dcpendofdoc
	];


// Outgoing Procedures

external	[
	PageCom;
	];


// Outgoing Statics

// external


// Local Statics

// static


// Local Manifests

// manifest


// P A G E   C O M

let PageCom(cf) = valof
[ 
let sel = cf>>CF.sel
let doc = sel>>SEL.doc
let wwSel = sel>>SEL.ww
let wwgroup = (mpWwWwd ! wwSel)>>WWD.wwgroup
let wwUpper = wwgroup + 1
let wwdUpper = mpWwWwd ! wwUpper
if wwdUpper>>WWD.wwgroup ne wwgroup then
	errhlt("wwg")
let wwLower = wwUpper + 1
let wwdLower = mpWwWwd ! wwLower

let ymlt = vfDiablomode ? pttodmlt, pttoemlt
let ydiv = vfDiablomode ? pttoddiv, pttoediv
let ho = vec lnho
let cpFDisplUpper = sel>>SEL.cpfirst
SetRegionSys(risyscom, 167)
let fColumnBound = false
vmapstatus = statusblind
mapcp(doc, 0, parneeded)
test parsacred>>PAR.control ifso
	[
	let tcp = CpParseDocProf(ho, doc, 0)
	if tcp eq cpnil then
		resultis abmsg
	cpFDisplUpper = umax(tcp, cpFDisplUpper)
	]
ifnot	DefaultHo(ho)
if ho>>HO.ccol ne 1 then
	[
	SetRegionSys(risyscom, 220)
	ho>>HO.ccol = 1
	fColumnBound = true
	]
updatedisplay()

let cpMac = rgmaccp ! doc
let cpFDisplLower = nil
let cpFirstSel = CpFormatPage(wwSel, cpFDisplUpper, modehc, ho,
	0, 0, 0, ymlt, ydiv, lv cpFDisplLower)
if cpFirstSel eq cpnil-1 then
	resultis abmsg
// format(wwSel, cpFirstSel, modehc)
underline(0, sel)		// should be uloff but no room for df
sel>>SEL.ww = wwLower
setsel(sel, cpFirstSel,
	(ult(cpFirstSel, cpMac-dcpendofdoc) ? vcplast, cpMac-1))

let fGetfonts = false
// let xdUd = RoundRatio(vxleftmargstd, vmagLook, 3200)
wwdUpper>>WWD.cpFDispl = cpFDisplUpper;
test wwdUpper>>WWD.fHd ifso
	setupdate(wwUpper)
ifnot	[
//	wwdUpper>>WWD.mag = vmagLook;
//	wwdUpper>>WWD.xdUd = xdUd;
	wwdUpper>>WWD.fHd = true;
//	setmag(wwUpper);
	invalidatewindow(wwUpper);
	fGetfonts = true
	]
test wwdLower>>WWD.wwgroup ne wwgroup % wwLower eq macww ifso
	[
	let ydTop = rgyfirst ! wwUpper
	let ydBottom = rgyfirst ! wwLower
	let ydSplit = (ydTop + ydBottom) rshift 1
	let wgd = vec lwgd
	wgd>>WGDTABLE.cww =		1
	wgd>>WGDTABLE.ydFirst ↑ 1 =	ydSplit
	wgd>>WGDTABLE.dyd ↑ 1 =	ydBottom - ydSplit
	wgd>>WGDTABLE.doc ↑ 1 =	doc
	wgd>>WGDTABLE.cpFDispl ↑ 1 =	cpFDisplLower
	wgd>>WGDTABLE.bonw ↑ 1 =	0
	wgd>>WGDTABLE.fHd ↑ 1 =	true
	wgd>>WGDTABLE.xdUd ↑ 1 =	vxleftmargstd rshift 5
	wgd>>WGDTABLE.mag ↑ 1 =	100
	fGetfonts = true
	SplitWw(ydSplit, wgd, wwLower+1)
	wwdLower = mpWwWwd ! wwLower
	wwdLower>>WWD.wwgroup = wwgroup
	]
ifnot	[
	wwdLower>>WWD.cpFDispl = cpFDisplLower;
	test wwdLower>>WWD.fHd ifso
		setupdate(wwLower)
	ifnot	[
//		wwdLower>>WWD.mag = vmagLook;
//		wwdLower>>WWD.xdUd = xdUd;
		wwdLower>>WWD.fHd = true;
//		setmag(wwLower);
		invalidatewindow(wwLower);
		fGetfonts = true
		]
	]
// if fGetfonts then
// 	[
// 	for fun = 0 to maxfun-1 do
// 		if (mpfunmagi ! fun ne -1) &
// 			(mpfunfddfaulted ! fun ne -1) then
// 			getfontc(fun);
// 	if mpfnof ! fnfontw eq -1 then
// 		errhlta(206);
// 	]

// "Last command was . . . "
SetRegionSys(risyspast, 25, (fColumnBound ? 220, 167))
resultis abmsg;
]