(FILECREATED "12-Nov-85 19:53:45" {ERIS}<LISPCORE>LIBRARY>TEDITCHAT.;4 15064  

      changes to:  (VARS TEDITCHAT.MENUITEMS)

      previous date: " 4-Sep-85 18:54:19" {ERIS}<LISPCORE>LIBRARY>TEDITCHAT.;3)


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

(PRETTYCOMPRINT TEDITCHATCOMS)

(RPAQQ TEDITCHATCOMS ((COMS (* character routines)
			      (FNS TEDITCHAT.CHARFN \TEXTSTREAMBOUT))
			(COMS (FNS TEDITSTREAM.INIT TEDITCHAT.MENUFN))
			(COMS (* TEDIT update routines)
			      (FNS TEDIT.DISPLAYTEXT))
			(GLOBALVARS TEDITCHAT.MENU CHAT.DRIVERTYPES CHAT.DISPLAYTYPES)
			(VARS TEDITCHAT.MENUITEMS (TEDITCHAT.MENU))
			(ADDVARS (CHAT.DRIVERTYPES (TEDIT TEDITCHAT.CHARFN NILL)))
			(DECLARE: EVAL@COMPILE DONTCOPY (FILES (SOURCE)
							       CHATDECLS))))



(* character routines)

(DEFINEQ

(TEDITCHAT.CHARFN
  [LAMBDA (CH CHAT.STATE)                                    (* AJB "22-May-85 18:16")
    (LET* [(TEXTSTREAM (fetch (CHAT.STATE TEXTSTREAM) of CHAT.STATE))
       (SEL (fetch SEL of (TEXTOBJ TEXTSTREAM]
      (\CARET.DOWN (fetch DS of (TEXTOBJ TEXTSTREAM)))
      (SELCHARQ CH
		[BS (\TEDIT.CHARDELETE TEXTSTREAM "" SEL)
		    (MOVETO (fetch X0 of SEL)
			    (fetch Y0 of SEL)
			    (CAR (fetch \WINDOW of (TEXTOBJ TEXTSTREAM]
		(LF NIL)
		(BOUT TEXTSTREAM CH])

(\TEXTSTREAMBOUT
  [LAMBDA (STREAM BYTE)                                      (* AJB "21-May-85 16:00")
                                                             (* Do BOUT to a text stream, which is an insertion at 
							     the caret.)
    (PROG ((TEXTOBJ (fetch (TEXTSTREAM TEXTOBJ) of STREAM))
	   CH# WINDOW TEXTLEN PS PC PSTR OFFST SEL)
          (SETQ TEXTLEN (fetch TEXTLEN of TEXTOBJ))
          (SETQ WINDOW (fetch \WINDOW of TEXTOBJ))
          (SETQ SEL (fetch SEL of TEXTOBJ))
          (COND
	    ((NOT (CAR (fetch L1 of SEL)))
	      (RETURN)))                                     (* Return if caret out of bounds, ie, user scrolls past
							     end of text)
          (SETQ CH# (fetch CH# of SEL))
          (AND WINDOW (\TEDIT.MARK.LINES.DIRTY TEXTOBJ CH# CH#))
          (\INSERTCH BYTE CH# TEXTOBJ)
          (AND WINDOW
	       (PROG ((THISLINE (fetch THISLINE of TEXTOBJ))
		      EOLFLAG CHORIG CHWIDTH OXLIM OCHLIM OCR\END PREVSPACE FIXEDLINE NEXTLINE LINES 
		      NEWLINEFLG DX PREVLINE SAVEWIDTH OFLOWFN OLHEIGHT DY TABSEEN IMAGECACHE CURLINE 
		      FONT (L1 (CAR (fetch L1 of SEL)))
		      (LN (CAR (fetch LN of SEL)))
		      (LOOKS (\TEDIT.APPLY.STYLES (fetch CARETLOOKS of TEXTOBJ)
						  (fetch \INSERTPC of TEXTOBJ)
						  TEXTOBJ)))
		     (add (fetch CH# of SEL)
			  1)                                 (* These must be here, since SELs are valid even 
							     without a window.)
		     (replace CHLIM of SEL with (fetch CH# of SEL))
		     (replace POINT of SEL with (QUOTE LEFT))
		     (replace DCH of SEL with 0)
		     (replace SELKIND of SEL with (QUOTE CHAR))
		     (SETQ CURLINE L1)
		     (add (fetch CHARLIM of CURLINE)
			  1)
		     (add (fetch CHARTOP of CURLINE)
			  1)
		     (SETQ FONT (fetch CLFONT of LOOKS))
		     (DSPFONT FONT (CAR WINDOW))
		     [COND
		       [(OR (IGREATERP (PLUS (fetch X0 of SEL)
					     (CHARWIDTH BYTE FONT))
				       (IDIFFERENCE (fetch WRIGHT of TEXTOBJ)
						    8))
			    (IEQP BYTE (CHARCODE CR)))       (* gone off the edge of the line reformat and add new 
							     line)
			 (TEDIT.UPDATE.SCREEN TEXTOBJ)
			 (\FIXSEL SEL TEXTOBJ (CAR WINDOW))
			 (SETQ L1 (CAR (fetch L1 of SEL)))
			 (SETQ LN (CAR (fetch LN of SEL)))
			 (COND
			   ([OR (NULL (SELECTQ (fetch POINT of SEL)
					       (LEFT L1)
					       (RIGHT LN)
					       NIL))
				(ILEQ (SELECTQ (fetch POINT of SEL)
					       (LEFT (fetch YBOT of L1))
					       (RIGHT (fetch YBOT of LN))
					       0)
				      (fetch BOTTOM of (DSPCLIPPINGREGION NIL (CAR WINDOW]
                                                             (* The caret is off-window in the selection window.
							     Need to scroll it up so the caret is visible.)
			     (while (OR (ILESSP (fetch Y0 of SEL)
						(fetch WBOTTOM of TEXTOBJ))
					(IGEQ (fetch Y0 of SEL)
					      (fetch WTOP of TEXTOBJ)))
				do                           (* The caret just went off-screen.
							     Move it up some.)
				   (replace EDITOPACTIVE of TEXTOBJ with NIL)
				   (SCROLLW (CAR WINDOW)
					    0
					    (LLSH (COND
						    [(SELECTQ (fetch POINT of SEL)
							      (LEFT L1)
							      (RIGHT LN)
							      NIL)
						      (fetch LHEIGHT
							 of (SELECTQ (fetch POINT of SEL)
								     (LEFT L1)
								     (RIGHT LN)
								     (SHOULDNT]
						    (T 12))
						  1]
		       (T (TEDIT.DISPLAYTEXT TEXTOBJ BYTE (CHARWIDTH BYTE FONT)
					     CURLINE
					     (fetch X0 of SEL)
					     (CAR WINDOW)
					     SEL)            (* Print out the character on the screen)
			  (add (fetch X0 of SEL)
			       (CHARWIDTH BYTE FONT))        (* And move the selection's notion of our X position to
							     the right to account for that character's width.)
			  (replace XLIM of SEL with (fetch X0 of SEL]

          (* * Fix up the TEXTSTREAM so that the FILEPTR looks like it ought to after the BOUT, even though we've been 
	  updating the screen (which usually moves the fileptr....))


		     [SETQ PS (ffetch PSTR of (SETQ PC (fetch \INSERTPC of TEXTOBJ]
                                                             (* This piece resides in a STRING.
							     Because it's newly "typed" material.)
		     (replace (TEXTSTREAM PIECE) of STREAM with PC)
                                                             (* Remember the current piece for others.)
		     (replace (TEXTSTREAM PCNO) of STREAM with (fetch \INSERTPCNO of TEXTOBJ))
                                                             (* And which number piece this is.)
		     (freplace CPPTR of STREAM with (ADDBASE (ffetch (STRINGP BASE) of PS)
							     (LRSH (SETQ OFFST (ffetch (STRINGP
											 OFFST)
										  of PS))
								   1)))
                                                             (* Pointer to the actual characters in the string 
							     (allowing for substrings.))
		     (freplace CPAGE of STREAM with 0)
		     (freplace COFFSET of STREAM with (IPLUS (freplace (TEXTSTREAM PCSTARTCH)
								of STREAM with (LOGAND 1 OFFST))
							     (fetch \INSERTLEN of TEXTOBJ)))
		     (freplace (TEXTSTREAM PCSTARTPG) of STREAM with 0)
                                                             (* Page # within the "file" where this piece starts)
		     (freplace CBUFSIZE of STREAM with (fetch COFFSET of STREAM))
		     (freplace EPAGE of STREAM with 1)
		     (freplace (TEXTSTREAM CHARSLEFT) of STREAM with 0)
                                                             (* We're, perforce, at the end of the piece.)
		     (freplace (TEXTSTREAM REALFILE) of STREAM with NIL)
                                                             (* We're not on a file....)
		 ])
)
(DEFINEQ

(TEDITSTREAM.INIT
  [LAMBDA (WINDOW MENUFN)                                    (* AJB "24-May-85 14:36")
                                                             (* Initialize and return TEDIT TEXTSTREAM)
    (PROG* ([TEXTSTREAM (OPENTEXTSTREAM NIL WINDOW NIL NIL (QUOTE (READONLY T]
	    (TEXTOBJ (TEXTOBJ TEXTSTREAM)))                  (* force shift select typein to be put in keyboard 
							     buffer)
           (TEXTPROP TEXTSTREAM (QUOTE COPYBYBKSYSBUF)
		     T)
           (replace STRMBOUTFN of TEXTSTREAM with (QUOTE \TEXTSTREAMBOUT))
           (replace SET of (fetch SEL of TEXTOBJ) with T)
           [replace L1 of (fetch SEL of TEXTOBJ) with (LIST (fetch DESC of (fetch THISLINE
									      of TEXTOBJ]
                                                             (* hookup middle button menu instead of TEDIT menu)
           (WINDOWPROP WINDOW (QUOTE TEDIT.TITLEMENUFN)
		       MENUFN)
           (RETURN TEXTSTREAM])

(TEDITCHAT.MENUFN
  [LAMBDA (WINDOW)                                           (* AJB "24-May-85 14:26")
    (DECLARE (GLOBALVARS TEDITCHAT.MENU)
	     (SPECVARS WINDOW STATE))                        (* MIDDLEBUTTON)
    (PROG ((STATE (WINDOWPROP WINDOW (QUOTE CHATSTATE)))
	   COMMAND)
          [COND
	    ((NOT STATE)                                     (* No Connection here; try to reestablish)
	      (RETURN (COND
			((LASTMOUSESTATE MIDDLE)
			  (CHAT.RECONNECT WINDOW))
			(T (TOTOPW WINDOW]
          (replace (CHAT.STATE HELD) of STATE with T)
          (\CHECKCARET WINDOW)
          (SELECTQ [SETQ COMMAND (MENU (OR TEDITCHAT.MENU (SETQ TEDITCHAT.MENU
					     (create MENU
						     ITEMS ← TEDITCHAT.MENUITEMS]
		   (Close (replace (CHAT.STATE RUNNING?) of STATE with (QUOTE CLOSE))
                                                             (* Ask CHAT.TYPEIN to shut things down.)
			  )
		   (New (replace (CHAT.STATE RUNNING?) of STATE with (QUOTE CLOSE))
			(WINDOWPROP WINDOW (QUOTE KEEPCHAT)
				    (QUOTE NEW)))
		   (Suspend (replace (CHAT.STATE RUNNING?) of STATE with (QUOTE CLOSE))
			    (WINDOWPROP WINDOW (QUOTE KEEPCHAT)
					T))
		   (Freeze                                   (* Leave in HELD state)
			   (RETURN))
		   (NIL)
		   (APPLY* COMMAND STATE WINDOW))
          (replace (CHAT.STATE HELD) of STATE with NIL])
)



(* TEDIT update routines)

(DEFINEQ

(TEDIT.DISPLAYTEXT
  [LAMBDA (TEXTOBJ CH CHWIDTH LINE XPOINT DS SEL)            (* AJB "10-May-85 15:53")
                                                             (* This function does the actual displaying of typed-in
							     text on the edit window.)
    (PROG ((LOOKS (\TEDIT.APPLY.STYLES (fetch CARETLOOKS of TEXTOBJ)
				       (fetch \INSERTPC of TEXTOBJ)
				       TEXTOBJ))
	   (TERMSA (fetch TXTTERMSA of TEXTOBJ))
	   DY FONT)
          (MOVETO XPOINT (IPLUS (fetch YBASE of LINE)
				(OR (fetch CLOFFSET of LOOKS)
				    0))
		  DS)                                        (* Set the display stream position)
          (COND
	    [TERMSA                                          (* Special terminal table for controlling character 
							     display. Use it.)
		    (RESETLST (RESETSAVE \PRIMTERMSA TERMSA)
			      (replace (TEXTSTREAM REALFILE) of (fetch STREAMHINT of TEXTOBJ)
				 with DS)
			      (COND
				[(STRINGP CH)
				  (for CHAR instring CH
				     do (SELCHARQ CHAR
						  (TAB       (* Put down white)
						       (BITBLT NIL 0 0 DS XPOINT
							       (fetch YBOT of LINE)
							       36
							       (fetch LHEIGHT of LINE)
							       (QUOTE TEXTURE)
							       (QUOTE REPLACE)
							       WHITESHADE)
						       (RELMOVETO 36 0 DS))
						  (CR (BITBLT NIL 0 0 DS XPOINT
							      (fetch YBOT of LINE)
							      (IMAX 6 (CHARWIDTH CHAR FONT))
							      (fetch LHEIGHT of LINE)
							      (QUOTE TEXTURE)
							      (QUOTE REPLACE)
							      WHITESHADE))
						  (\DSPPRINTCHAR (fetch STREAMHINT of TEXTOBJ)
								 CHAR]
				(T (SELCHARQ CH
					     (TAB            (* Put down white)
						  (BITBLT NIL 0 0 DS XPOINT (fetch YBOT of LINE)
							  36
							  (fetch LHEIGHT of LINE)
							  (QUOTE TEXTURE)
							  (QUOTE REPLACE)
							  WHITESHADE)
						  (RELMOVETO 36 0 DS))
					     (CR (BITBLT NIL 0 0 DS XPOINT (fetch YBOT of LINE)
							 (IMAX 6 (CHARWIDTH CH FONT))
							 (fetch LHEIGHT of LINE)
							 (QUOTE TEXTURE)
							 (QUOTE REPLACE)
							 WHITESHADE))
					     (\DSPPRINTCHAR (fetch STREAMHINT of TEXTOBJ)
							    CH]
	    (T                                               (* No special handling; just use native character 
							     codes)
	       (COND
		 [(STRINGP CH)
		   (for CHAR instring CH do (SELCHARQ CHAR
						      (TAB 
                                                             (* Put down white)
							   (BITBLT NIL 0 0 DS (DSPXPOSITION NIL DS)
								   (fetch YBOT of LINE)
								   36
								   (fetch LHEIGHT of LINE)
								   (QUOTE TEXTURE)
								   (QUOTE REPLACE)
								   WHITESHADE)
							   (RELMOVETO 36 0 DS))
						      (CR (BITBLT NIL 0 0 DS (DSPXPOSITION NIL DS)
								  (fetch YBOT of LINE)
								  (IMAX 6 (CHARWIDTH CHAR FONT))
								  (fetch LHEIGHT of LINE)
								  (QUOTE TEXTURE)
								  (QUOTE REPLACE)
								  WHITESHADE))
						      (BLTCHAR CHAR DS]
		 (T (SELCHARQ CH
			      (TAB                           (* Put down white)
				   (BITBLT NIL 0 0 DS (DSPXPOSITION NIL DS)
					   (fetch YBOT of LINE)
					   36
					   (fetch LHEIGHT of LINE)
					   (QUOTE TEXTURE)
					   (QUOTE REPLACE)
					   WHITESHADE)
				   (RELMOVETO 36 0 DS))
			      (CR                            (* Blank out the CR's width.)
				  (BITBLT NIL 0 0 DS (DSPXPOSITION NIL DS)
					  (fetch YBOT of LINE)
					  (IMAX 6 (CHARWIDTH CH FONT))
					  (fetch LHEIGHT of LINE)
					  (QUOTE TEXTURE)
					  (QUOTE REPLACE)
					  WHITESHADE))
			      (BLTCHAR CH DS])
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDITCHAT.MENU CHAT.DRIVERTYPES CHAT.DISPLAYTYPES)
)

(RPAQQ TEDITCHAT.MENUITEMS ((Close (QUOTE Close)
				     "Closes the connection and returns")
			      (Suspend (QUOTE Suspend)
				       "Closes the connection but leaves window up")
			      (New (QUOTE New)
				   "Closes this connection and prompts for a new host")
			      (Freeze (QUOTE Freeze)
				      "Holds typeout in this window until you bug it again")
			      ("Dribble" (FUNCTION CHAT.TYPESCRIPT)
					 "Starts a typescript of window typeout")
			      ("Input" (FUNCTION CHAT.TAKE.INPUT)
				       "Allows input from a file")
			      ("Option" (FUNCTION DO.CHAT.OPTION)
					"Do protocol specific option")))

(RPAQQ TEDITCHAT.MENU NIL)

(ADDTOVAR CHAT.DRIVERTYPES (TEDIT TEDITCHAT.CHARFN NILL))
(DECLARE: EVAL@COMPILE DONTCOPY 
(FILESLOAD (SOURCE)
	   CHATDECLS)
)
(PUTPROPS TEDITCHAT COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (822 7718 (TEDITCHAT.CHARFN 832 . 1370) (\TEXTSTREAMBOUT 1372 . 7716)) (7719 10220 (
TEDITSTREAM.INIT 7729 . 8768) (TEDITCHAT.MENUFN 8770 . 10218)) (10255 14084 (TEDIT.DISPLAYTEXT 10265
 . 14082)))))
STOP