// Select Module GMOUSE.SR Shared subroutines

get "BRAVO.DF"
get "CHAR.DF"
get "GINN.DF"

// Incoming Procedures

external [
	ratio;
	invalidatedisplay;
	updatedisplay;
	linemark;
	updatelinemark;
	formatx;
	formaty;
	finddl;
	errhlt;
	backnlines;
	setbug;
	mousedecode
	stripedecode
	pollmouse
	pollstripe
	pollkeyset
	visible
	cpvisible
	wwmark
	updatewwmark
	menuitem
	resetmessage
	setmessage
	pollinput
	elapsed
	setmenu
	cpparabounds
	parabounds
	umin
	umax
	specstate
	nextspecstate
	cppara
	lastparacp
	cpc
	selectsel
	];

// Incoming Statics

external [
	vjumpbar
	vwindows
	vmscroll
	vwords
	mdoc
	vcp;
	vdlhint;
	vulmode;
	rgmaccp;
	rgcplast;
	rgupdate;
	rgcpfirst;
	rgxfirst;
	rgdoc;
	rgdlfirst;
	rgdllast;
	rgyfirst;
	rgylast;
	rgmaxdl;
	rgcpfdispl;
	rgxlast;
	vwidth;
	vdoc;
	vcpatx;
	vx;
	vww;
	vdl;
	vheight;
	vbetwixt;
	vstripe;
	comt;
	vcpadjusteq;
	abs
	selection;
	selaux;
	rgsdoc
	ddoc
	cursorstate ;
	vwwcurrent
	vcpfirst
	vcplast
	vxfirst
	vxlast
	rgdirty
	mww
	vpause
	rgprogram
	nmenuitems
	sdoc
	sww
	];

// Outgoing Procedures

external [
	stripewindow;
	stripeline
	stripefly
	stripemenu
	stripenone
	marks
	locatebug
	stillselecting
	buggedsomething
	newbias
	hidemark
	];

// Outgoing statics

external
	[
	xbug;
	ybug;
	jcpfirst;
	cpleft
	cpright
	xleft
	xright
	cptex
	cpb
	cpe
	mcpfirst;
	mcplast;
	mxfirst;
	mxlast;
	origdl
	origww
	inmargin
	xbias;
	ybias;
	];

// Local Statics

static [
	xbug;
	ybug;
	jcpfirst;
	cpleft
	cpright
	xleft
	xright
	cptex
	cpb
	cpe
	mcpfirst;
	mcplast;
	mxfirst;
	mxlast;
	origdl
	origww
	inmargin
	xbias;
	ybias;
	];

// GLOBAL SUBROUTINES :

let marks(onoff) be
	[
	linemark(onoff, selection);
	if onoff then updatelinemark(selection);
	linemark(onoff, selaux);
	if onoff then updatelinemark(selaux);
	wwmark(onoff) ;
	if onoff then updatewwmark() ;
	] // end of marks

// LOCAL SUBROUTINES :

and locatebug() be
	[
	xbug = rv(xbugloc)+xbias;
	ybug = rv(ybugloc)+ybias;
	] // end of locatebug

and buggedsomething(okvacww, origy, oksys, bugshape) = valof
	[
	let origbugshape = cursorstate ;
	if bugshape ne -1 then setbug(bugshape);
	locatebug();
	test origy ge 0 &
		    origy-vheight le ybug & ybug le origy+vheight
		ifso	[
			vww = origww
			vdl = origdl
			]
		ifnot formaty(ybug);
	vdoc = rgdoc ! vww ;
	if rgmaccp ! vdoc eq 0 %
		 ((not okvacww) & rgdllast!vww ls rgdlfirst!vww) %
		 ((not oksys) & vdoc eq docsys) then
		[
		if bugshape ne -1 then setbug(origbugshape) ;
		resultis false;
		];
	resultis true;
	] // end of buggedsomething

and stillselecting(origy, sel, anywhere, finalbugshape) = valof
	[
	let origbugshape = cursorstate ;
		[
		if pollmouse() eq smouse then
			[
			setbug(finalbugshape);
			resultis false ;
			];
		unless buggedsomething(anywhere, origy,
				anywhere, -1) do
			[
			setbug(finalbugshape) ;
			loop;
			];
		if sel eq 0 then break;
		if sel >> SEL.doc ne rgdoc ! vww then
			[
			setbug(finalbugshape) ;
			loop;
			];
		break;
		] repeat;
	setbug(origbugshape) ;
	resultis true;
	] // end stillselecting

and newbias(newxbias, newybias) be
	[
	@ybugloc = @ybugloc + ybias - newybias ;
	@xbugloc = @xbugloc + xbias - newxbias ;
	xbias = newxbias
	ybias = newybias
	]

// STRIPES

and stripewindow(cmdcode) = stripe(cmdcode, swindow)
and stripeline(cmdcode) = stripe(cmdcode, snoline)
and stripefly(cmdcode) = stripe(cmdcode, spage)
and stripemenu(cmdcode) = stripe(cmdcode, smenu)
and stripenone(cmdcode) = stripe(cmdcode, snone)

and stripe(cmdcode, sbugshape) = valof
	[
	vstripe = cmdcode;
	setbug(sbugshape);
	resultis 0;
	] // end of stripeline

and hidemark() = valof
	[
	if selaux >> SEL.doc eq sdoc then resultis 0
	selectsel(selaux, sww, lastparacp(sdoc) - 1) ;
	resultis 0
	]