/* Select_Boxes.rexx  */
/* Selects all boxes on current page. */
/* Previously selected lines are left selected. */


/* Requires Toaster_CG v4.03 */
/* By Ross Fenmore © 1995 Light Source Video & Graphics */

PARSE arg picknot

SIGNAL ON ERROR
SIGNAL ON SYNTAX

CALL addlib(CG_AREXX,0)

IF (picknot='PICKNOT') | (picknot="") THEN picknot=0

RestoreCursorString=RememberCursor()
PARSE var RestoreCursorString '"'text'"' charnum x y noline .

current_line=1
total_lines=get_page(size)
IF noline THEN total_lines=total_lines-1
DO WHILE current_line <= total_lines
   CALL set_line(current_line)
	linetype=get_line(TYPE)
	IF (linetype='Box') & (picknot=0) THEN CALL pickline()
	IF (linetype='Box') & (picknot=1) THEN CALL pickline(NOT)
   current_line=current_line+1
END

CALL RestoreCursor(RestoreCursorString)

CALL OUTAHERE
EXIT

/* Remember cursor position */
/* Returns space separated argument string to be PARSEd. */

/* RETURN: "text" = text on original line retrieved from get_line() */
/*        charnum = original cursor position from get_char(spot)    */
/*        x and y = original line coordinates from get_line(spot)   */
/*         noline = If cursor was on a new blank line (0 if not)    */
/* Note: text is surrounded by quotes in string */

RememberCursor: PROCEDURE

charnum=get_char(spot)
coords=get_line(spot)
PARSE var coords x y
text=get_line()

noline=0
type=get_line(type)
IF (type='Text')&(text="") THEN noline=1

RETURN '"'text'"'||" "||charnum||" "||strip(x)||" "||strip(y)||" "||noline

/* Restore cursor position */
/* ARGS: text = text on original line retrieved from get_line() */
/*    charnum = original cursor position from get_char(spot)    */
/*    x and y = original line coordinates from get_line(spot)   */
/*     noline = If cursor was on a new blank line (0 if not)    */

RestoreCursor: PROCEDURE

PARSE arg '"'text'"' charnum x y noline .
coords=x||" "||y

total_lines=get_page(size)

IF noline=0 THEN DO

	current_line=1
	cx=0; cy=0

	DO WHILE current_line <= total_lines
   	CALL set_line(current_line)

		comparetext=get_line()
		IF comparetext=text THEN DO
	   	comparecoords=GET_LINE(SPOT)
			PARSE var comparecoords cx cy
		END

		IF (cx=x)&(cy=y) THEN LEAVE

	   current_line=current_line+1

	END

call set_char(spot,charnum+1)
END

RETURN


OUTAHERE:
CALL req_bar("Toaster CG")
CALL remlib(CG_AREXX)
EXIT

ERROR:
SYNTAX:
errorcode = rc
line=SIGL
text='"'errortext(errorcode)'"'
call req_tell("ERROR= "||errorcode,"On line# "||line,text)
exit
