(FILECREATED " 4-Dec-86 12:21:43" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH006.;1 6733   

      changes to:  (VARS PMIPATCH006COMS)
		   (FNS NC.PrintMsg))


(* Copyright (c) 1986 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT PMIPATCH006COMS)

(RPAQQ PMIPATCH006COMS ((* * Fixes bug #113: Gives prompt windows a minimum size that is larger
			     (300 pixels))
			  (* * Change to NCUTILITIES)
			  (FNS NC.PrintMsg)))
(* * Fixes bug #113: Gives prompt windows a minimum size that is larger (300 pixels))

(* * Change to NCUTILITIES)

(DEFINEQ

(NC.PrintMsg
  (LAMBDA Msgs                                               (* pmi: " 4-Dec-86 12:13")

          (* Print the msgs in the specified window. First argument is a window to print msg in, second arg is flag telling 
	  whether to clear first, rest of arguments are simply prin1'ed to the msg window)



          (* * rht 7/24/85: Now checks to be sure that window arg is a notecards window. If not, doesn't use promptwindow, 
	  but prints directly to window.)



          (* * rht 9/11/85: Added call to NC.MoveWindowOntoScreen in case we're crammed near the top of screen.)



          (* * fgh 6/8/86 Now opens prompt window to width that matches longest line in Msg.)



          (* * fgh 6/13/86 Now attaches prompt window to NF menus as well as cards.)



          (* * fgh 6/26/86 Now tries to make the window an appropriate width to hold the whole msg. Height remains a 
	  constant.)


    (LET ((Font (FONTCREATE (QUOTE HELVETICA)
			      10))
	  NoteCardWinFlg PromptWin CachedStream Window MaxWidth)
         (SETQ Window (ARG Msgs 1))

          (* * find the maximun line length in the given arg list. Cached on the main window under the PromptWindowLastNotCR 
	  prop is the length of the previous line if it didn't end in a carriage return. Need to add this to the length of 
	  the first line in this call.)


         (SETQ MaxWidth
	   (APPLY
	     (FUNCTION MAX)
	     (OR (bind (LastNotCR ←(if (AND Window (NULL (ARG Msgs 2)))
					   then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
								)))
		      for Msg from 3 to Msgs
		      join 

          (* * Parse each arg into a list of line lengths. Set the LastNotCR to the length of the last line in the arg if the
	  arg does not end in a CR. This will be added to the length of the first line in the next arg whether it be in this 
	  call or the next call to Printmsg.)


			     (if (STREQUAL (ARG Msgs Msg)
					       "")
				 then (LIST 0)
			       else
				(while (SETQ Char (GNC CopyString)) as Ctr from 1
				   bind Char (LastCR ← 0)
					  (CopyString ←(SUBSTRING (ARG Msgs Msg)
								    1))
					  (OriginalString ←(SUBSTRING (ARG Msgs Msg)
									1))
				   when (EQ Char (CHARACTER 13))
				   collect (PROG1 (PLUS (OR LastNotCR 0)
							      (STRINGWIDTH
								(OR (SUBSTRING OriginalString
										   (ADD1 LastCR)
										   (SUB1 Ctr))
								      "")
								Font))
						      (SETQ LastCR Ctr)
						      (SETQ LastNotCR 0))
				   finally

          (* if the last line doesn't end in a CR, save its length as LastNotCR but be sure to put its length on the list 
	  anyway in case this is the last call.)


				    (if (NOT (EQP Ctr LastCR))
					then (SETQ $$VAL
						 (CONS (PLUS (OR LastNotCR 0)
								 (STRINGWIDTH
								   (OR (SUBSTRING OriginalString
										      (ADD1 LastCR)
										      (SUB1 Ctr))
									 "")
								   Font))
							 $$VAL))
					       (SETQ LastNotCR (CAR $$VAL))
				      else (SETQ LastNotCR))))
		      finally                              (* Cache the last linelength if it didn't end in a CR,
							     we'll need it to add to the first line next time.)
				(if Window
				    then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
							 LastNotCR)))
		   0)))
         (if (IGREATERP Msgs 2)
	     then 

          (* * Figure out the prompt window)


		    (SETQ NoteCardWinFlg (NC.NoteCardsWindowP Window))
		    (if (NOT (WINDOWP Window))
			then (SETQ PromptWin PROMPTWINDOW)
		      elseif NoteCardWinFlg
			then (SETQ PromptWin (NC.AttachPromptWindow Window NIL NIL NIL T))
		      else (SETQ PromptWin Window))

          (* * If requested, reset all the width caches.)


		    (if (AND PromptWin (ARG Msgs 2))
			then (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
					     300))

          (* * Set window width to the max width of the current max width and the cached max width from previous lines since 
	  the last clear)


		    (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
				  (SETQ MaxWidth (MAX MaxWidth (OR (WINDOWPROP PromptWin
										       (QUOTE
											 OldMaxWidth))
									 300))))

          (* * Actual width of window is this maxwidth, except that if window is open, don't make it smaller.)


		    (if NoteCardWinFlg
			then (SETQ PromptWin (NC.AttachPromptWindow
				   Window
				   (if (OPENWP PromptWin)
				       then (MAX MaxWidth (WINDOWPROP PromptWin (QUOTE WIDTH))
						     )
				     else MaxWidth)))
			       (NC.MoveWindowOntoScreen Window))

          (* * Print the msg.)


		    (RESETLST (OR NoteCardWinFlg (RESETSAVE (TTYDISPLAYSTREAM PromptWin)))
				(RESETSAVE NIL (BQUOTE (DSPFONT , (DSPFONT Font PromptWin)
								      , PromptWin)))
				(if (ARG Msgs 2)
				    then (CLEARW PromptWin))
				(LINELENGTH 1000 PromptWin)
				(if (NULL PromptWin)
				    then (BREAK1 T T))
				(for Msg from 3 to Msgs collect (PRIN1 (ARG Msgs Msg)
										 PromptWin))))
     PromptWin)))
)
(PRETTYCOMPRINT PMIPATCH006COMS)

(RPAQQ PMIPATCH006COMS ((* * Fixes bug #113: Gives prompt windows a minimum size that is larger
			     (300 pixels))
			  (* * Change to NCUTILITIES)
			  (FNS NC.PrintMsg)
			  (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
				    (ADDVARS (NLAMA)
					     (NLAML)
					     (LAMA NC.PrintMsg)))))
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NC.PrintMsg)
)
(PUTPROPS PMIPATCH006 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (564 6154 (NC.PrintMsg 574 . 6152)))))
STOP