// MenuEditMore.bcpl -- additional procedures for MenuEdit
// by L. Stewart  last modified March 8, 1978  9:43 PM


get "MenuDefs.d"

external		// incoming OS procedures
	[
	Ws
	Wns
	Gets
	Zero
	]

external		// incoming statics
	[
	menu
	selected
	dcb
	systemdcb
	keys		// OS statics
	]

external  //incoming procedures
	[
	getnumber
	getname
	DCBPress
	]


external  //outgoing procedures
	[
	Instructions
	Sensitize
	ShowSensitize
	DotCorners
	JustifyText
	Boundary	
	DoDCBPress	
]

static		//internal statics
	[
	pNameDefault
	]

let DotCorners(box;numargs na) = valof
	[
	// Writes black dots into box corners
	if (na eq 0) % (box eq 0) then resultis false

	// define boundaries of the box
	let Xo=box>>BOX.xorigin
	let Yo=box>>BOX.yorigin
	let Xc=box>>BOX.xcorner
	let Yc=box>>BOX.ycorner
	if Xo eq Xc % Yo eq Yc then resultis false

	// get dcb
	let dcb=box>>BOX.dcb
	if dcb eq 0 then resultis false
	let width=dcb>>DCB.width

	// draw in corner dots
	// using erase function from BoxUtils.asm
	// erase(nbits,wordstart,bitstart,nwords,nlines,flag [0])
	let wordstart=dcb>>DCB.bitmap+Yo*width
	erase(1,wordstart,Xo,width,1,1)
	erase(1,wordstart,Xc,width,1,1)
	wordstart=dcb>>DCB.bitmap+Yc*width
	erase(1,wordstart,Xo,width,1,1)
	erase(1,wordstart,Xc,width,1,1)
	resultis true
	]

and Sensitize(switch) be
	[
	if selected!0 ls 1 then return
	let box=nil
	for n=1 to selected!0 do
		[
		box=menu!(selected!n)
		box>>BOX.sensitive=switch
		]
	]

and ShowSensitize() be
	[
	if menu!0 ls 1 then return
	let box=nil
	Zero(selected,MaxLength)
	for n=1 to menu!0 do
		[
		box=menu!n
		if (box>>BOX.sensitive ne 0) then
			[
			selected!0 = selected!0+1
			selected!(selected!0)=n
			]
		]
	]

and JustifyText(switch) be
	[
	if selected!0 ls 1 then return
	let box=nil
	let joffs=nil
	@#420=systemdcb
	test switch
		ifso joffs=getnumber("*NLeft margin",4)
		ifnot joffs=0
	for n=1 to selected!0 do
		[
		box=menu!(selected!n)
		box>>BOX.ljustified=switch
		box>>BOX.joffset=joffs
		]
	]

and Instructions() be
	[
	@#420=systemdcb
	Ws("*N*N*N*N*N")
	Ws("*Na/A autoDeSelect ON/OFF, c-change, d-delete, e/E-Set/Clear Sensitivity, g-set gap")
	Ws("*Ni-insert string, j/J-Justify/Center Text, l-line up, n-name, o-outline, p-pressfile")
	Ws("*Nr-read, s-same size, <TAB>-refresh, v-See Sensitives, w-write.")
	Ws("*NType any char to continue.")
	Gets(keys)
	]


and Boundary() be
	[
	// move all selected windows to word boundaries
	for n=1 to selected!0 do
		[
		let box=menu!(selected!n)
		let Xo=box>>BOX.xorigin
		let remain=Xo rem 16
		box>>BOX.xorigin=Xo-remain
		box>>BOX.xcorner=box>>BOX.xcorner-remain
		]
	]

and DoDCBPress() be
	[
	@#420=systemdcb
	if pNameDefault eq 0 then pNameDefault="MenuDisplay.Press"
	let name=getname("*NPress File Name",pNameDefault)
	if name eq 0 then name = pNameDefault
	pNameDefault=name
	DCBPress(name,dcb)
	]