;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Changed SHEET-STRING-OUT-EXPLICIT-1 to return INDEX as the final-index
;;; value instead of END. END is the index of the last char in the string
;;; which is NOT the last char printed.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 05/21/90 16:38:07 by MARKY,
;;; while running on LIBRA from band LODB
;;; With SYSTEM 6.23, VIRTUAL-MEMORY 6.2, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.6, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.6, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.14, TV 6.19, DATALINK 6.0, CHAOSNET 6.5, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.16,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.2, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.3, MAIL-READER 6.6, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.4, PROFILE 6.2, VISIDOC 6.5, TI-CLOS 6.26, CLEH 6.5, IP 3.56,
;;;  Experimental CLX 6.7, CLUE 6.32, X11M 6.16, Experimental BUG 11.17, MMON 6.2,
;;;   microcode 429, Band Name: REL6-mmon-11/15/89

;;; fix bug from clint hyde :

;;the method :STRING-OUT-EXPLICIT returns three values, final X, final Y,
;;and end-of-string index. I was expecting the final-index value to be the
;;position of the final character printed in the window, corresponding to
;;the final-x, final-y values. instead, it's the index of the last
;;character in the string, whether or not that was the last one printed on
;;that line. The manual also says that these can be used to execute in
;;consecutive places on the screen. if that third value returned is the
;;end-of-string index (a relatively worthless result), then it means that
;;I can't forcibly print a string [left-justified] anywhere on a window in
;;any-sized rectangular region, because I don't know where each line in
;;the region terminated inside the print string.

#!C
; From file SHWARM.LISP#> WINDOW; Hotel:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: WINDOW; SHWARM.#"


(DEFUN SHEET-STRING-OUT-EXPLICIT-1
       (SHEET STRING START-X Ypos XLIM YLIM FONT ALUF
	&OPTIONAL (START 0) (END NIL) MULTI-LINE-LINE-HEIGHT (ALIGN-FOR-LOZENGE NIL) color)
  "Output STRING on SHEET without using SHEET's cursor, font, etc.
Output starts at cursor position START-X, Y but SHEET's cursor is not
moved.  Output of current line stops if x-position XLIM or y-position YLIM is reached
unless RETURN characters are in string then portions of the string may be printed 
on subsequent lines, again clipping to XLIM, until YLIM is reached.
Font FONT is used, and alu-function ALU.
START and END specify a portion of STRING to be used.
MULTI-LINE-LINE-HEIGHT is how far to move down for Return
	characters. Return also moves back to x-position START-X.
	NIL means output <Return> with a lozenge.

All position arguments are relative to SHEET's outside edges."
  (DECLARE (VALUES FINAL-X FINAL-Y FINAL-INDEX))
  (COERCE-FONT FONT SHEET)
  (prepare-color (sheet color)
  (PREPARE-SHEET (SHEET)
  (OR XLIM (SETQ XLIM (SHEET-WIDTH SHEET)))
    (LET* ((INDEX (OR START 0))
	   (END (OR END (ARRAY-ACTIVE-LENGTH STRING)))
	   (XPOS start-x)
	   CH)
      (WHEN (PLUSP (SHEET-RIGHT-MARGIN-CHARACTER-FLAG SHEET))
        ;; Ensure enough room for ! at right of screen.
	(DECF XLIM (FONT-CHAR-WIDTH FONT)))
      (LOOP WHILE (< INDEX END) DOING
	    (MULTIPLE-VALUE-SETQ (XPOS INDEX)
	      (DRAW-STRING-INTERNAL SHEET STRING INDEX END
			    xpos ypos XLIM FONT ALUF))
	    (UNLESS index			;Done?
	       (RETURN xpos ypos index))	;; may 05/21/90 Changed END to INDEX
	    (SETQ CH (AREF STRING INDEX))
	    (COND ((AND MULTI-LINE-LINE-HEIGHT (= CH #\NEWLINE))
		   (SETQ Xpos START-X
			 Ypos (+ Ypos MULTI-LINE-LINE-HEIGHT))
		   (INCF index)
		   (IF (AND YLIM (> (+ Ypos MULTI-LINE-LINE-HEIGHT) YLIM))
		       (RETURN Xpos Ypos Index)))
		  ((NOT (GRAPHIC-CHAR-P ch))		;Special character?
		   (LET ((STRING (LOZENGED-SPECIAL-CHAR-NAME CH))
			 NX)
		     (MULTIPLE-VALUE-BIND (LOZENGE-WIDTH CORNER-WIDTH CORNER-HEIGHT)
			 (LOZENGED-STRING-GEOMETRY STRING)
		       (IF (> (SETQ NX (+ XPOS LOZENGE-WIDTH)) XLIM)
			   (RETURN XLIM YLIM INDEX))
		       (SHEET-DISPLAY-LOZENGED-STRING-INTERNAL
			 SHEET STRING
			 XPOS (OR ALIGN-FOR-LOZENGE YPOS)
			 XLIM ALUF
			 LOZENGE-WIDTH CORNER-WIDTH CORNER-HEIGHT)
		       (SETQ XPOS NX)))
		   (INCF INDEX))
		  ;; may 05/16/89 Added this cond clause to allow continuing printing of string if
		  ;; it has multi-lines (return chars) and YLIM has not been reached.
		  ((and multi-line-line-height (find #\newline string :start index))
		      (setq xpos start-x
			    ypos (+ ypos multi-line-line-height))
		      (setq index (+ 1 (position #\newline string :start index)))
		      (if (and ylim (> (+ ypos multi-line-line-height) ylim))
			  (return xpos ypos index)))
		  (T (RETURN XPOS YPOS index)))	; Else end of line	;; may 05/21/90 Changed END to INDEX
	    FINALLY (RETURN xpos ypos index)	; KED 3/16/88   ;; may 05/21/90 Changed END to INDEX
	    )))))
))
