(FILECREATED "28-Nov-84 18:01:26" {IVY}<TEDIT>TEDITWINDOW.;13 103387 

      changes to:  (FNS TEDIT.DEFAULT.MENUFN)

      previous date: "25-Nov-84 14:59:53" {IVY}<TEDIT>TEDITWINDOW.;12)


(* Copyright (c) 1983, 1984 by John Sybalsky & Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT TEDITWINDOWCOMS)

(RPAQQ TEDITWINDOWCOMS [(FILES TEXTOFD TEDITLOOKS ATTACHEDWINDOW)
	(FNS TEDIT.CREATEW \TEDIT.CREATEW.FROM.REGION TEDIT.CURSORMOVEDFN TEDIT.CURSOROUTFN 
	     TEDIT.GETINPUT TEDIT.WINDOW.SETUP TEDIT.MINIMAL.WINDOW.SETUP \TEDIT.ACTIVE.WINDOWP 
	     \TEDIT.BUTTONEVENTFN \TEDIT.EXPANDFN \TEDIT.MAINW \TEDIT.PRIMARYW \TEDIT.CARET 
	     \TEDIT.COPYINSERTFN \TEDIT.NEWREGIONFN \TEDIT.SET.WINDOW.EXTENT \TEDIT.SHRINK.ICONCREATE 
	     \TEDIT.SHRINKFN \TEDIT.SPLITW \TEDIT.UNSPLITW \TEDIT.WINDOW.SETUP \SAFE.FIRST)
	[COMS (* to get the record def for SHIFTSTATE)
	      (DECLARE: DONTCOPY DOEVAL@COMPILE (P (LOADCOMP? (QUOTE LLKEY]
	(CURSORS BXCARET BXHICARET TEDIT.LINECURSOR)
	(INITVARS (TEDIT.DEFAULT.WINDOW NIL))
	(GLOBALVARS TEDIT.DEFAULT.WINDOW)
	(COMS (* Attached Prompt window support.)
	      (FNS TEDIT.PROMPTPRINT)
	      (INITVARS (TEDIT.PROMPT.FONT (FONTCREATE 'GACHA 10))
			(TEDIT.PROMPTWINDOW.HEIGHT NIL))
	      (GLOBALVARS TEDIT.PROMPT.FONT TEDIT.PROMPTWINDOW.HEIGHT))
	(COMS (* Title creation and update)
	      (FNS TEXTSTREAM.TITLE \TEDIT.ORIGINAL.WINDOW.TITLE \TEDIT.WINDOW.TITLE 
		   \TEXTSTREAM.FILENAME))
	(COMS (* Screen updating utilities)
	      (FNS TEDIT.DEACTIVATE.WINDOW \TEDIT.REPAINTFN \TEDIT.RESHAPEFN \TEDIT.SET.WINDOW.TITLE 
		   \TEDIT.SCROLLFN))
	(COMS (* Process-world interfaces)
	      (FNS \TEDIT.PROCIDLEFN \TEDIT.PROCENTRYFN \TEDIT.PROCEXITFN))
	(COMS (INITVARS (\CARETRATE 333))
	      (* Caret handler; stolen from CHAT.)
	      (FNS \EDIT.DOWNCARET \EDIT.FLIPCARET TEDIT.FLASHCARET \EDIT.UPCARET 
		   TEDIT.NORMALIZECARET \SETCARET)
	      (DECLARE: EVAL@COMPILE DONTCOPY (RECORDS TEDITCARET)))
	[COMS (* Menu interfacing)
	      (FNS TEDIT.ADD.MENUITEM TEDIT.DEFAULT.MENUFN TEDIT.REMOVE.MENUITEM \TEDIT.CREATEMENU 
		   \TEDIT.MENU.WHENHELDFN \TEDIT.MENU.WHENSELECTEDFN)
	      (GLOBALVARS TEDIT.DEFAULT.MENU)
	      [DECLARE: DONTEVAL@LOAD DOCOPY
			(INITVARS (TEDIT.DEFAULT.MENU (\TEDIT.CREATEMENU
							(QUOTE ((Put (QUOTE Put)
								     NIL
								     (SUBITEMS Plain-Text))
								(Get (QUOTE Get)
								     NIL
								     (SUBITEMS Unformatted% Get))
								Include Find Looks Substitute Quit 
								Hardcopy Press% File
								(Expanded% Menu (QUOTE Expanded% Menu)
										NIL
										(SUBITEMS 
										 Character% Looks 
									    Paragraph% Formatting 
										     Page% Layout]
	      (DECLARE: DONTEVAL@LOAD DOCOPY (P [OR (SASSOC (QUOTE TEdit)
							    BackgroundMenuCommands)
						    (NCONC1 BackgroundMenuCommands
							    (QUOTE (TEdit (QUOTE (TEDIT))
									  
								  "Opens a TEdit window for use."]
						(SETQ BackgroundMenu NIL]
	(INITRECORDS TEDITCARET)
	(FILES IMAGEOBJ)
	(COMS (* titled icon info)
	      (FILES ICONW)
	      (BITMAPS TEDITICON TEDITMASK)
	      (INITVARS (TEDIT.ICON.FONT (FONTCREATE (QUOTE HELVETICA)
						     8
						     (QUOTE BOLD)))
			(TEDIT.ICON.TITLE.REGION (CREATE REGION BOTTOM ← 4 LEFT ← 16 WIDTH ← 64 
							 HEIGHT ← 77))
			(TEDIT.TITLED.ICON.TEMPLATE (CREATE TITLEDICON ICON←TEDITICON MASK←TEDITMASK 
							    TITLEREG←TEDIT.ICON.TITLE.REGION])
(FILESLOAD TEXTOFD TEDITLOOKS ATTACHEDWINDOW)
(DEFINEQ

(TEDIT.CREATEW
  [LAMBDA (PROMPT FILE PROPS)                                (* jds "13-Nov-84 11:15")
    (CLRPROMPT)
    (printout PROMPTWINDOW PROMPT T)
    (PROG ((PROMPT (LISTGET PROPS (QUOTE PROMPTWINDOW)))
	   (PHEIGHT 0)
	   PWINDOW REGION)
          [COND
	    ((EQ PROMPT (QUOTE DON'T)))
	    (PROMPT)
	    (T (SETQ PHEIGHT (HEIGHTIFWINDOW (ITIMES (OR (LISTGET PROPS (QUOTE PROMPTWINDOWHEIGHT))
							 TEDIT.PROMPTWINDOW.HEIGHT 1)
						     (FONTPROP TEDIT.PROMPT.FONT (QUOTE HEIGHT]
          (SETQ REGION (GETREGION 32 (IPLUS PHEIGHT 32)))
          (add (fetch HEIGHT of REGION)
	       (IMINUS PHEIGHT))
          (SETQ TEDIT.DEFAULT.WINDOW (CREATEW REGION (\TEDIT.ORIGINAL.WINDOW.TITLE FILE)))
          (CLRPROMPT)
          (WINDOWPROP TEDIT.DEFAULT.WINDOW (QUOTE TEDITCREATED)
		      T)
          (OR PROMPT (GETPROMPTWINDOW TEDIT.DEFAULT.WINDOW (OR (LISTGET PROPS (QUOTE 
									       PROMPTWINDOWHEIGHT))
							       TEDIT.PROMPTWINDOW.HEIGHT 1)
				      TEDIT.PROMPT.FONT)))
    TEDIT.DEFAULT.WINDOW])

(\TEDIT.CREATEW.FROM.REGION
  [LAMBDA (REGION FILE PROPS)                                (* gbn "15-Nov-84 18:04")
    (PROG ((PROMPT (LISTGET PROPS (QUOTE PROMPTWINDOW)))
	   (PHEIGHT 0)
	   PWINDOW)
          [COND
	    ((EQ PROMPT (QUOTE DON'T)))
	    (PROMPT)
	    (T (SETQ PHEIGHT (HEIGHTIFWINDOW (ITIMES (OR (LISTGET PROPS (QUOTE PROMPTWINDOWHEIGHT))
							 TEDIT.PROMPTWINDOW.HEIGHT 1)
						     (FONTPROP TEDIT.PROMPT.FONT (QUOTE HEIGHT]
          (SETQ TEDIT.DEFAULT.WINDOW (CREATEW REGION (\TEDIT.ORIGINAL.WINDOW.TITLE FILE)))
          (WINDOWPROP TEDIT.DEFAULT.WINDOW (QUOTE TEDITCREATED)
		      T)
          (OR PROMPT (GETPROMPTWINDOW TEDIT.DEFAULT.WINDOW (OR (LISTGET PROPS (QUOTE 
									       PROMPTWINDOWHEIGHT))
							       TEDIT.PROMPTWINDOW.HEIGHT 1)
				      TEDIT.PROMPT.FONT)))
    TEDIT.DEFAULT.WINDOW])

(TEDIT.CURSORMOVEDFN
  [LAMBDA (W)                                                (* jds " 9-Dec-83 18:04")
                                                             (* Watch the mouse and change the cursor to reflect the 
							     region of the window it's in 
							     (line select, window split eventually?))
    (PROG ((X (LASTMOUSEX W))
	   (Y (LASTMOUSEY W))
	   (TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ)))
	   (CURSORREG (WINDOWPROP W (QUOTE TEDIT.CURSORREGION)))
	   LINE LEFT RIGHT)
          (COND
	    ((INSIDE? CURSORREG X Y)                         (* Do nothing)
	      NIL)
	    (T (SETQ LINE (\TEDIT.FIND.OVERLAPPING.LINE (fetch LINES of TEXTOBJ)
							Y))
	       [COND
		 (LINE (replace BOTTOM of CURSORREG with (fetch YBOT of LINE))
		       (replace HEIGHT of CURSORREG with (fetch LHEIGHT of LINE]
	       (SELECTQ (fetch MOUSEREGION of TEXTOBJ)
			[TEXT (COND
				([ILESSP X (SETQ LEFT (OR (AND LINE (fetch LEFTMARGIN of LINE))
							  (IPLUS (fetch WLEFT of TEXTOBJ)
								 8]
                                                             (* In left margin; switch to the line-select cursor)
				  (CURSOR TEDIT.LINECURSOR)
				  (replace MOUSEREGION of TEXTOBJ with (QUOTE LINE))
				  (replace LEFT of CURSORREG with 0)
				  (replace WIDTH of CURSORREG with LEFT))
				(T (replace LEFT of CURSORREG with LEFT)
				   (replace WIDTH of CURSORREG with (fetch WRIGHT of TEXTOBJ]
			[LINE (COND
				([IGEQ X (SETQ LEFT (OR (AND LINE (fetch LEFTMARGIN of LINE))
							(IPLUS (fetch WLEFT of TEXTOBJ)
							       8]
				  (CURSOR T)
				  (replace MOUSEREGION of TEXTOBJ with (QUOTE TEXT))
				  (replace LEFT of CURSORREG with LEFT)
				  (replace WIDTH of CURSORREG with (fetch WRIGHT of TEXTOBJ)))
				(T (replace LEFT of CURSORREG with 0)
				   (replace WIDTH of CURSORREG with LEFT]
			NIL])

(TEDIT.CURSOROUTFN
  [LAMBDA (W)                                                (* jds "28-Mar-84 11:30")
                                                             (* Cursor leaves edit window;
							     make sure we think we're in the text region.)
    (PROG [(TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ]
          (COND
	    ((AND TEXTOBJ (EQ (fetch MOUSEREGION of TEXTOBJ)
			      (QUOTE LINE)))
	      (CURSOR T)
	      (replace MOUSEREGION of TEXTOBJ with (QUOTE TEXT])

(TEDIT.GETINPUT
  [LAMBDA (STREAM PROMPTSTRING DEFAULTSTRING DELIMITER.LIST)
                                                             (* jds "13-Nov-84 11:18")
                                                             (* Ask for input (file names, &c) for TEdit, perhaps 
							     with a default.)
    (PROG [(TEXTOBJ (TEXTOBJ STREAM))
	   (TPROMPT (OR (fetch PROMPTWINDOW of (TEXTOBJ STREAM))
			(GETPROMPTWINDOW (\TEDIT.MAINW STREAM)
					 NIL NIL T]
          (COND
	    (TPROMPT                                         (* If it's our own promptwindow, just clear it.)
		     (CLEARW (fetch PROMPTWINDOW of TEXTOBJ)))
	    (T                                               (* If it's the system's window, just move to a new 
							     line.)
	       (FRESHLINE PROMPTWINDOW)))
          (RETURN (PROG1 (PROMPTFORWORD PROMPTSTRING DEFAULTSTRING NIL (OR TPROMPT PROMPTWINDOW)
					NIL
					(QUOTE TTY)
					(OR DELIMITER.LIST (CHARCODE (EOL LF TAB ESCAPE)))
					NIL)                 (* Get what the guy wants to tell us)
			 (WINDOWPROP (OR (fetch PROMPTWINDOW of TEXTOBJ)
					 PROMPTWINDOW)
				     (QUOTE PROCESS)
				     NIL)                    (* Now detach the prompt window from its process, to 
							     avoid a circularity.)
			 ])

(TEDIT.WINDOW.SETUP
  [LAMBDA (WINDOW TEXTOBJ TEXTSTREAM PROPS)                  (* jds "15-Aug-84 10:50")
                                                             (* Set up the window and TEXTOBJ so they correspond, and
							     the window is a TEDIT window.)
    (PROG ((SEL (fetch SEL of TEXTOBJ))
	   TEDITPROMPTWINDOW DS PROP TWIDTH THEIGHT)
          (OR WINDOW (\ILLEGAL.ARG WINDOW))
          (WINDOWPROP WINDOW (QUOTE BUTTONEVENTFN)
		      (FUNCTION \TEDIT.BUTTONEVENTFN))       (* Set the window up with the right mouse interfaces for
							     TEDIT.)
          (WINDOWPROP WINDOW (QUOTE RIGHTBUTTONFN)
		      (FUNCTION \TEDIT.BUTTONEVENTFN))
          (SETQ PROP (LISTGET PROPS (QUOTE MENU)))           (* The Command menu, or list of items for it)
          (COND
	    ((type? MENU PROP)                               (* It's a menu. just use it.)
	      (WINDOWPROP WINDOW (QUOTE TEDIT.MENU)
			  PROP))
	    (PROP                                            (* It's a list of menu items.
							     Force a new menu on next middle button.)
		  (WINDOWPROP WINDOW (QUOTE TEDIT.MENU.COMMANDS)
			      PROP)
		  (WINDOWPROP WINDOW (QUOTE TEDIT.MENU)
			      NIL)))
          (TEDIT.MINIMAL.WINDOW.SETUP WINDOW TEXTOBJ TEXTSTREAM PROPS])

(TEDIT.MINIMAL.WINDOW.SETUP
  [LAMBDA (WINDOW TEXTOBJ TEXTSTREAM PROPS)                  (* jds "21-Aug-84 13:42")
                                                             (* Do the absolute minimum setup so that TEXTOBJ and 
							     WINDOW know about each other.
							     Does NOT include mouse interface or scrolling.)
    (PROG ((SEL (fetch SEL of TEXTOBJ))
	   TEDITPROMPTWINDOW DS PROP TWIDTH THEIGHT)
          (OR WINDOW (\ILLEGAL.ARG WINDOW))
          (replace (TEDITCARET TCCARETDS) of (fetch CARET of TEXTOBJ) with (WINDOWPROP WINDOW
										       (QUOTE DSP)))
          (replace SELWINDOW of TEXTOBJ with WINDOW)
          (WINDOWPROP WINDOW (QUOTE PROCESS)
		      NIL)                                   (* For the moment, this window has no process)
          (WINDOWPROP WINDOW (QUOTE TEDIT.PROPS)
		      PROPS)                                 (* Put the props on the window for others ...
							     **this should go**)
          (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)
		      TEXTSTREAM)                            (* Save the text stream for the user to get at via the 
							     window.)
          (WINDOWPROP WINDOW (QUOTE TEXTOBJ)
		      TEXTOBJ)                               (* Give a handle on the TEXTOBJ for the text being 
							     edited.)
          (WINDOWPROP WINDOW (QUOTE TEDIT.CURSORREGION)
		      (LIST 0 0 0 0))                        (* Used by CursorMovedFn)
          (WINDOWPROP WINDOW (QUOTE CURSORMOVEDFN)
		      (FUNCTION TEDIT.CURSORMOVEDFN))
          (WINDOWPROP WINDOW (QUOTE CURSOROUTFN)
		      (FUNCTION TEDIT.CURSOROUTFN))
          [SETQ DS (replace DS of TEXTOBJ with (WINDOWPROP WINDOW (QUOTE DSP]
          (DSPRIGHTMARGIN 32767 DS)                          (* So we don't get spurious RETURNs printed out by the 
							     system)
          (replace \WINDOW of TEXTOBJ with WINDOW)
          [replace LINECACHE of TEXTOBJ with (CAR (replace LINECACHES of TEXTOBJ with (
\TEDIT.CREATE.LINECACHE 2]                                   (* CACHE for screen updates)
          (replace DISPLAYCACHE of TEXTOBJ with (CAR (\TEDIT.CREATE.LINECACHE 1)))
                                                             (* and a CACHE for creating line images for display)
          [replace DISPLAYCACHEDS of TEXTOBJ with (DSPCREATE (fetch LCBITMAP
								of (fetch DISPLAYCACHE of TEXTOBJ]
          [COND
	    ((SETQ PROP (LISTGET PROPS (QUOTE REGION)))      (* The caller wants to set a region.
							     Use his)
	      (replace WTOP of TEXTOBJ with (fetch PTOP of PROP))
	      (replace WRIGHT of TEXTOBJ with (fetch RIGHT of PROP))
	      (replace WBOTTOM of TEXTOBJ with (fetch BOTTOM of PROP))
	      (replace WLEFT of TEXTOBJ with (fetch LEFT of PROP)))
	    (T                                               (* Otherwise, default to the whole window)
	       (replace WLEFT of TEXTOBJ with 0)
	       (replace WBOTTOM of TEXTOBJ with 0)
	       (replace WTOP of TEXTOBJ with (fetch HEIGHT of (DSPCLIPPINGREGION NIL DS)))
	       (replace WRIGHT of TEXTOBJ with (fetch WIDTH of (DSPCLIPPINGREGION NIL DS]
          (WINDOWPROP WINDOW (QUOTE LINES)
		      (replace LINES of TEXTOBJ with (\SHOWTEXT TEXTOBJ)))
                                                             (* Display the text in the window, for later use.)
          (AND (SETQ PROP (LISTGET PROPS (QUOTE QUITFN)))
	       (WINDOWPROP WINDOW (QUOTE TEDIT.QUITFN)
			   PROP))                            (* What to do when user QUITs)
          (AND (SETQ PROP (LISTGET PROPS (QUOTE AFTERQUITFN)))
	       (WINDOWPROP WINDOW (QUOTE TEDIT.AFTERQUITFN)
			   PROP))                            (* What to do after the QUIT takes effect)
          (AND (SETQ PROP (LISTGET PROPS (QUOTE LOOPFN)))
	       (WINDOWPROP WINDOW (QUOTE TEDIT.CMD.LOOPFN)
			   PROP))                            (* FN to execute each time thru command loop)
          (AND (SETQ PROP (LISTGET PROPS (QUOTE CHARFN)))
	       (WINDOWPROP WINDOW (QUOTE TEDIT.CMD.CHARFN)
			   PROP))                            (* FN to execute per character typed.)
          (AND (SETQ PROP (LISTGET PROPS (QUOTE SELFN)))
	       (WINDOWPROP WINDOW (QUOTE TEDIT.CMD.SELFN)
			   PROP))                            (* FN to execute per selection made.)
          (\FIXSEL SEL TEXTOBJ)
          (TEDIT.NORMALIZECARET TEXTOBJ SEL)
          (\SHOWSEL SEL NIL T)
          (\TEDIT.SET.WINDOW.EXTENT TEXTOBJ WINDOW)
          (\COPYSEL SEL TEDIT.SELECTION])

(\TEDIT.ACTIVE.WINDOWP
  [LAMBDA (W)                                                (* gbn "27-Jan-84 06:31")
    (PROG [(TEXTOBJ (OR (WINDOWPROP W (QUOTE TEXTOBJ))
			(AND (WINDOWPROP W (QUOTE TEXTSTREAM))
			     (TEXTOBJ (WINDOWPROP W (QUOTE TEXTSTREAM]
          (RETURN (COND
		    (TEXTOBJ (AND (NOT (fetch EDITFINISHEDFLG of TEXTOBJ))
				  (PROCESSP (WINDOWPROP W (QUOTE PROCESS])

(\TEDIT.BUTTONEVENTFN
  [LAMBDA (W STREAM)                                         (* gbn "20-Nov-84 17:51")
                                                             (* Handle button events for a TEdit window)
    (AND STREAM (SETQ STREAM (TEXTOBJ STREAM)))
    (PROG ((OSEL NIL)
	   (SEL NIL)
	   [TEXTOBJ (OR STREAM (WINDOWPROP W (QUOTE TEXTOBJ]
	   (DS (WINDOWPROP W (QUOTE DSP)))
	   USERFN
	   (GLOBALSEL TEDIT.SELECTION)
	   (X (LASTMOUSEX W))
	   (Y (LASTMOUSEY W))
	   (CLIPREGION (DSPCLIPPINGREGION NIL W))
	   (SELOPERATION (QUOTE NORMAL))
	   (SELFN (WINDOWPROP W (QUOTE TEDIT.CMD.SELFN)))
	   (EXTENDFLG NIL)
	   SELFINALFN PROC NOSEL)
          (COND
	    ((NOT (MOUSESTATE (OR LEFT MIDDLE RIGHT)))       (* No button is down -- we got control on button-up 
							     transition, so ignore it.)
	      (RETURN))
	    (TEDIT.SELPENDING                                (* There is already a selection in progress.
							     Don't allow another to interfere.)
			      (RETURN)))
          (replace CH# of TEDIT.SCRATCHSELECTION with 0)     (* Mark the user-visible scratch selection fresh, so 
							     changes can be detected...)
          (COND
	    [[OR (NOT TEXTOBJ)
		 (fetch EDITFINISHEDFLG of TEXTOBJ)
		 (AND (NOT (WINDOWPROP W (QUOTE PROCESS)))
		      (NOT (fetch (SHIFTSTATE SHIFT) of \SHIFTSTATE))
		      (NOT (fetch (SHIFTSTATE CTRL) of \SHIFTSTATE))
		      (NOT (fetch (SHIFTSTATE META) of \SHIFTSTATE))
		      (NOT (KEYDOWNP (QUOTE MOVE)))
		      (NOT (KEYDOWNP (QUOTE COPY]            (* There's no edit session behind this window.
							     You can only do window ops, or re-establish a session.)
	      (TOTOPW W)
	      (COND
		((\TEDIT.MOUSESTATE RIGHT)                   (* Right button gets the window command menu)
		  (DOWINDOWCOM W))
		((AND TEXTOBJ (NOT (TEXTPROP TEXTOBJ (QUOTE READONLY)))
		      [NOT (PROCESSP (WINDOWPROP W (QUOTE PROCESS]
		      (\TEDIT.MOUSESTATE MIDDLE))            (* Middle button on a dead window gives a menu for 
							     re-starting TEDIT)
		  (COND
		    ((EQ (MENU TEDIT.RESTART.MENU)
			 (QUOTE NewEditProcess))
		      (replace EDITOPACTIVE of TEXTOBJ with NIL)
		      (TEDIT (fetch STREAMHINT of TEXTOBJ)
			     W]
	    [[OR (IGREATERP Y (fetch TOP of CLIPREGION))
		 (AND (fetch TXTREADONLY of TEXTOBJ)
		      (NOT (fetch (SHIFTSTATE SHIFT) of \SHIFTSTATE))
		      (NOT (FETCH (SHIFTSTATE CTRL) OF \SHIFTSTATE))
		      (NOT (fetch (SHIFTSTATE META) of \SHIFTSTATE))
		      (NOT (KEYDOWNP (QUOTE MOVE)))
		      (NOT (KEYDOWNP (QUOTE COPY]            (* It's not inside the window's REAL region, so call on
							     a menu.)
	      (TOTOPW W)
	      (COND
		((\TEDIT.MOUSESTATE RIGHT)
		  (DOWINDOWCOM W))
		((MOUSESTATE (OR LEFT MIDDLE))
		  (AND TEXTOBJ (SETQ USERFN (WINDOWPROP W (QUOTE TEDIT.TITLEMENUFN)))
		       (NEQ USERFN (QUOTE DON'T))
		       (COND
			 ((AND (SETQ PROC (WINDOWPROP W (QUOTE PROCESS)))
			       (PROCESSP PROC))              (* This window has a live process behind it;
							     go evaluate the button fn there.)
			   (PROCESS.APPLY PROC USERFN (LIST W)))
			 (T (ADD.PROCESS (LIST USERFN (KWOTE W]
	    ((AND TEXTOBJ (NOT (fetch EDITOPACTIVE of TEXTOBJ)))
                                                             (* Usual case -- he's really selecting something.)
	      (TOTOPW W)
	      (OR (fetch TCUP of (fetch CARET of TEXTOBJ))
		  (\EDIT.FLIPCARET (fetch CARET of TEXTOBJ)
				   T))                       (* Make sure the caret isn't being displayed.)
	      (RESETLST (RESETSAVE TEDIT.SELPENDING TEXTOBJ)

          (* Tell all TEdits not to run, since there is a selection in progress. This is reset to NIL on return from here, to 
	  re-enable TEdit runs.)


			(RESETSAVE (replace TCCURSORBM of (fetch CARET of TEXTOBJ) with BXHICARET)
				   (LIST (QUOTE \TEDIT.CARET)
					 (fetch CARET of TEXTOBJ)))
                                                             (* Then make the caret be the special, tall one so he 
							     can see it.)
			(COND
			  ((OR (KEYDOWNP (QUOTE COPY))
			       (fetch TXTREADONLY of TEXTOBJ))
                                                             (* In a read-only document, you can only copy.)
			    (SETQ GLOBALSEL TEDIT.SHIFTEDSELECTION)
			    (SETQ OSEL (fetch SHIFTEDSEL of TEXTOBJ))
			    (SETQ SELOPERATION (QUOTE COPY)))
			  ((KEYDOWNP (QUOTE MOVE))           (* The MOVE key is down, so set MOVE mode.)
			    (SETQ GLOBALSEL TEDIT.MOVESELECTION)
			    (SETQ OSEL (fetch MOVESEL of TEXTOBJ))
			    (SETQ SELOPERATION (QUOTE MOVE)))
			  [(fetch (SHIFTSTATE SHIFT) of \SHIFTSTATE)
                                                             (* the SHIFT key is down; mark this selection for COPY 
							     or MOVE.)
			    (COND
			      ((fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
                                                             (* CTRL-SHIFT select means MOVE.)
				(SETQ GLOBALSEL TEDIT.MOVESELECTION)
				(SETQ OSEL (fetch MOVESEL of TEXTOBJ))
				(SETQ SELOPERATION (QUOTE MOVE)))
			      (T (SETQ GLOBALSEL TEDIT.SHIFTEDSELECTION)
				 (SETQ OSEL (fetch SHIFTEDSEL of TEXTOBJ))
				 (SETQ SELOPERATION (QUOTE COPY]
			  ((fetch (SHIFTSTATE META) of \SHIFTSTATE)
                                                             (* He's holding the meta key down , do a copylooks 
							     selection)
			    (SETQ GLOBALSEL TEDIT.COPYLOOKSSELECTION)
			    (SETQ OSEL (fetch SHIFTEDSEL of TEXTOBJ))
			    (SETQ SELOPERATION (QUOTE COPYLOOKS)))
			  ((OR (fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
			       (KEYDOWNP (QUOTE COPY)))      (* He's holding the control key down;
							     note the fact.)
			    (\SHOWSEL (fetch SEL of TEXTOBJ)
				      NIL NIL)               (* Turn off the old normal selection.)
			    (replace SET of (fetch SEL of TEXTOBJ) with NIL)
			    (SETQ GLOBALSEL TEDIT.DELETESELECTION)
			    (SETQ OSEL (fetch DELETESEL of TEXTOBJ))
			    (SETQ SELOPERATION (QUOTE DELETE))
			    (replace BLUEPENDINGDELETE of TEXTOBJ with NIL))
			  (T (SETQ OSEL (fetch SEL of TEXTOBJ))
			     (replace BLUEPENDINGDELETE of TEXTOBJ with NIL)
                                                             (* Reset the pending-delete flag.)
			     ))
			(\COPYSEL OSEL GLOBALSEL)
			(bind (OSELOP ← SELOPERATION) while [OR (fetch (SHIFTSTATE SHIFT)
								   of \SHIFTSTATE)
								(fetch (SHIFTSTATE CTRL)
								   of \SHIFTSTATE)
								(fetch (SHIFTSTATE META)
								   of \SHIFTSTATE)
								(KEYDOWNP (QUOTE MOVE))
								(KEYDOWNP (QUOTE COPY))
								(NOT (ZEROP (LOGAND LASTMOUSEBUTTONS 
										    7]
			   do                                (* Poll the selection & display its current state)
			      [OR (ZEROP (LOGAND LASTMOUSEBUTTONS 7))
				  (COND
				    ((fetch TXTREADONLY of TEXTOBJ)
				      (SETQ SELOPERATION (QUOTE COPY)))
				    ((KEYDOWNP (QUOTE MOVE))
                                                             (* the MOVE key is down; mark this selection for MOVE.)
				      (SETQ SELOPERATION (QUOTE MOVE)))
				    [(OR (fetch (SHIFTSTATE SHIFT) of \SHIFTSTATE)
					 (KEYDOWNP (QUOTE COPY)))
                                                             (* the SHIFT key is down; mark this selection for COPY 
							     or MOVE.)
				      (COND
					((fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
					  (SETQ SELOPERATION (QUOTE MOVE)))
					(T (SETQ SELOPERATION (QUOTE COPY]
				    ((fetch (SHIFTSTATE META) of \SHIFTSTATE)
                                                             (* He's holding the meta key down;
							     note the fact.)
				      (SETQ SELOPERATION (QUOTE COPYLOOKS)))
				    ((fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
                                                             (* He's holding the control key down;
							     note the fact.)
				      (SETQ SELOPERATION (QUOTE DELETE)))
				    (T                       (* No key being held down; revert to normal selection.)
				       (SETQ SELOPERATION (QUOTE NORMAL]
			      [COND
				((IN/SCROLL/BAR? W LASTMOUSEX LASTMOUSEY)
                                                             (* If he moves to the scroll bar, let him scroll 
							     without trouble)
				  (SCROLL.HANDLER W))
				((INSIDEP CLIPREGION (SETQ X (LASTMOUSEX DS))
					  (SETQ Y (LASTMOUSEY DS)))
                                                             (* Only do selection if the mouse is inside the window 
							     proper)
				  [COND
				    ((\TEDIT.MOUSESTATE LEFT)
                                                             (* Left button is character selection)
				      (SETQ SEL (TEDIT.SELECT X Y TEXTOBJ (fetch MOUSEREGION
									     of TEXTOBJ)
							      NIL SELOPERATION W))
				      (SETQ EXTENDFLG NIL))
				    ((\TEDIT.MOUSESTATE MIDDLE)
                                                             (* Middle button is word selection)
				      (SETQ SEL (TEDIT.SELECT X Y TEXTOBJ (fetch MOUSEREGION
									     of TEXTOBJ)
							      T SELOPERATION W))
				      (SETQ EXTENDFLG NIL))
				    [(\TEDIT.MOUSESTATE RIGHT)
                                                             (* RIght button extends selections)
				      (COND
					((NEQ SELOPERATION OSELOP)

          (* Things changed since the last selection. Grab the prior selection info, so that the extension is taken from the 
	  selection NOW being made, rather than the last existing old-type selection.)


					  (\COPYSEL OSEL GLOBALSEL)))
				      (COND
					((fetch SET of GLOBALSEL)
					  (AND TEDIT.EXTEND.PENDING.DELETE (EQ SELOPERATION
									       (QUOTE NORMAL))
					       (SETQ SELOPERATION (QUOTE PENDINGDEL))
					       (replace BLUEPENDINGDELETE of TEXTOBJ with T))
                                                             (* If TeditBluePendingDelete flag is set, then simulate
							     Laurel's blue-pending-delete feature.)
					  (SETQ SEL (TEDIT.EXTEND.SEL X Y GLOBALSEL TEXTOBJ 
								      SELOPERATION W))
					  (SETQ EXTENDFLG T]
				    (T                       (* The mouse buttons are up, leaving us with a pro-tem 
							     "permanent" selection)
				       (\COPYSEL OSEL GLOBALSEL)
                                                             (* And SEL is NOT SET ANY LONGER, so it won't get 
							     copied into OSEL down below)
				       (AND SEL (replace SET of SEL with NIL]
				  [COND
				    ((AND SEL (fetch SET of SEL)
					  SELFN)             (* The selection was set, but there's a SELFN that has 
							     veto authority)
				      (COND
					((EQ (APPLY* SELFN TEXTOBJ GLOBALSEL SELOPERATION
						     (QUOTE TENTATIVE))
					     (QUOTE DON'T))
                                                             (* The selfn vetoed this selection, so mark it un-set.)
					  (replace SET of SEL with NIL]
				  (COND
				    ((\TEDIT.SEL.CHANGED? SEL OSEL OSELOP SELOPERATION)
                                                             (* Something interesting about the selection changed.
							     We have to re-display its image.)
				      (COND
					((OR (EQ SELOPERATION (QUOTE NORMAL))
					     (EQ SELOPERATION (QUOTE PENDINGDEL)))
                                                             (* For a normal selection, set the 
							     "window last selected in" for the TEXTOBJ)
					  (replace SELWINDOW of TEXTOBJ with W)))
				      (SETQ OSEL (\TEDIT.REFRESH.SHOWSEL TEXTOBJ SEL OSEL OSELOP 
									 SELOPERATION EXTENDFLG))
				      (SETQ OSELOP SELOPERATION))
				    ([AND OSEL (fetch SET of OSEL)
					  (EQ (fetch SELKIND of OSEL)
					      (QUOTE VOLATILE))
					  (OR (NOT SEL)
					      (NOT (fetch SET of SEL]

          (* There is an old selection around, but it is VOLATILE -- i.e., it shouldn't last longer than something is pointing
	  at it. Turn it off.)


				      (\SHOWSEL OSEL NIL NIL)
				      (replace SET of OSEL with NIL]
			      (BLOCK)                        (* Give other processes a chance)
			      (GETMOUSESTATE)                (* And get the new mouse info)
			      (TEDIT.CURSORMOVEDFN W))
			(\COPYSEL OSEL GLOBALSEL)
			(COND
			  ((fetch SET of OSEL)               (* Only if a selection REALLY got made should we do 
							     this....)
			    (SELECTQ SELOPERATION
				     (COPY                   (* A COPY selection -- set the copy flag, and see if 
							     this is a copy to a non-TEdit window)
					   (SETQ TEDIT.COPY.PENDING T)
					   (replace SET of OSEL with NIL)
                                                             (* And turn off OSEL, to avoid spurious highlighting)
					   (\TEDIT.FOREIGN.COPY? GLOBALSEL)
                                                             (* Maybe copy into the SYSBUF, if the recipient isn't a
							     TEdit window.)
					   )
				     (COPYLOOKS              (* A COPYLOOKS selection)
						(SETQ TEDIT.COPYLOOKS.PENDING T)
                                                             (* And turn off OSEL, to avoid spurious highlighting)
						(replace SET of OSEL with NIL))
				     (MOVE                   (* A MOVE selection -- set the flag to signal the TEdit
							     command loop,)
					   (SETQ TEDIT.MOVE.PENDING T)
                                                             (* And turn off OSEL, to avoid spurious highlighting)
					   (replace SET of OSEL with NIL))
				     (DELETE (SETQ TEDIT.DEL.PENDING T)
					     (replace SET of OSEL with NIL)
                                                             (* And turn off OSEL, to avoid spurious highlighting)
					     )
				     (NORMAL                 (* This is a normal selection;
							     set the caret looks)
					     (replace CARETLOOKS of TEXTOBJ with (
\TEDIT.GET.INSERT.CHARLOOKS TEXTOBJ OSEL)))
				     NIL)))
			(AND SELFN (APPLY* SELFN TEXTOBJ GLOBALSEL SELOPERATION (QUOTE FINAL)))
                                                             (* Give a user exit routine control, perhaps for 
							     logging of selections.)
			(OR (fetch TCUP of (fetch CARET of TEXTOBJ))
			    (\EDIT.FLIPCARET (fetch CARET of TEXTOBJ)
					     T)))
	      (AND OSEL (fetch SET of OSEL)
		   (fetch SELOBJ of OSEL)
		   (SETQ SELFINALFN (IMAGEOBJPROP (fetch SELOBJ of OSEL)
						  (QUOTE WHENOPERATEDONFN)))
		   (APPLY* SELFINALFN (fetch SELOBJ of OSEL)
			   (WINDOWPROP W (QUOTE DSP))
			   (QUOTE SELECTED)
			   OSEL
			   (fetch STREAMHINT of TEXTOBJ])

(\TEDIT.EXPANDFN
  [LAMBDA (W)                                                (* jds " 2-Feb-84 14:42")
                                                             (* steals back the tty for us!)
    (AND (WINDOWPROP W (QUOTE PROCESS))
	 (TTY.PROCESS (WINDOWPROP W (QUOTE PROCESS])

(\TEDIT.MAINW
  [LAMBDA (TEXTSTREAM)                                       (* gbn " 8-Oct-84 23:31")
                                                             (* Get the MAIN edit window for this edit session 
							     (i.e., the one with the title, and all the props & 
							     stuff))
    (PROG ((TEXTOBJ (TEXTOBJ TEXTSTREAM))
	   WINDOWS WINDOW)
          (SETQ WINDOWS (fetch \WINDOW of (TEXTOBJ TEXTSTREAM)))
          (SETQ WINDOW (COND
	      ((LISTP WINDOWS)                               (* how do we know we can just take the first window as 
							     the main one?)
		(CAR WINDOWS))
	      (T WINDOWS)))
          (RETURN (COND
		    ((AND (fetch MENUFLG of TEXTOBJ)
			  (WINDOWPROP WINDOW (QUOTE MAINWINDOW)))
                                                             (* If this is a menu window, and it's attached to a 
							     main TEdit window, then look to the main TEdit window.)
		      (WINDOWPROP WINDOW (QUOTE MAINWINDOW)))
		    (T WINDOW])

(\TEDIT.PRIMARYW
  [LAMBDA (TEXTSTREAM)                                       (* jds "19-Jun-84 01:57")

          (* Given an edit session with possibly several PANES on the same document, give me the PRINCIPAL one of 
	  them--i.e., the original edit window that has all the back pointers, props &c on it.)


    (PROG ((TEXTOBJ (TEXTOBJ TEXTSTREAM))
	   WINDOWS WINDOW)
          (SETQ WINDOWS (fetch \WINDOW of (TEXTOBJ TEXTSTREAM)))
                                                             (* The edit window (s) associated with this edit 
							     session)
          (SETQ WINDOW (COND
	      ((LISTP WINDOWS)                               (* If there are several panes, the first one in the list
							     is the original window)
		(CAR WINDOWS))
	      (T                                             (* If there's only the one window, that's the guy.)
		 WINDOWS)))
          (RETURN WINDOW])

(\TEDIT.CARET
  [LAMBDA (CARET)                                            (* jds "20-Apr-84 22:01")
                                                             (* Reset the caret to its normal state state, from the 
							     selection caret)
    (replace (TEDITCARET TCCURSORBM) of CARET with BXCARET])

(\TEDIT.COPYINSERTFN
  [LAMBDA (INSERTIONS WW)                                    (* jds "20-Jul-84 10:59")
                                                             (* Given a string, an imageobj, or a list of any of 
							     them, insert it in the tedit window WW.)
    (PROG [[TEXTSTREAM (TEXTSTREAM (WINDOWPROP WW (QUOTE MAINWINDOW]
	   (SEL (fetch SEL of (TEXTOBJ (WINDOWPROP WW (QUOTE MAINWINDOW]
          (for INSERTION inside INSERTIONS do (COND
						((STRINGP INSERTION)
						  (TEDIT.INSERT TEXTSTREAM INSERTION SEL))
						((IMAGEOBJP INSERTION)
						  (TEDIT.INSERT.OBJECT INSERTION TEXTSTREAM SEL])

(\TEDIT.NEWREGIONFN
  [LAMBDA (FIXEDPOINT MOVINGPOINT WINDOW)                    (* jds "24-FEB-83 17:43")

          (* This function is called whenever a new region for the window is needed. It constrains the size of the window so
	  that the menu and/or titles will fit)


    (COND
      ((NULL MOVINGPOINT)                                    (* This is true only the first time the function is 
							     called)
	FIXEDPOINT)
      (T (PROG (#OFMENUITEMS MENUWIDTH XDELTA YDELTA)

          (* The NEWREGIONFNARG can be either a window or a list consisting of the number of items in the menu and the 
	  minimum width of the window neede to hold the menu an titles)


	       (SETQ XDELTA (IDIFFERENCE (fetch (POSITION XCOORD) of MOVINGPOINT)
					 (fetch (POSITION XCOORD) of FIXEDPOINT)))
	       (SETQ YDELTA (IDIFFERENCE (fetch (POSITION YCOORD) of MOVINGPOINT)
					 (fetch (POSITION YCOORD) of FIXEDPOINT)))
	       [COND
		 [(IGEQ XDELTA 0)
		   (replace (POSITION XCOORD) of MOVINGPOINT with (IPLUS (fetch (POSITION XCOORD)
									    of FIXEDPOINT)
									 (IMAX 32 XDELTA]
		 (T (replace (POSITION XCOORD) of MOVINGPOINT with (IPLUS (fetch (POSITION XCOORD)
									     of FIXEDPOINT)
									  (IMIN -32 XDELTA]
	       [COND
		 [(IGEQ YDELTA 0)
		   (replace (POSITION YCOORD) of MOVINGPOINT with (IPLUS (fetch (POSITION YCOORD)
									    of FIXEDPOINT)
									 (IMAX 32 YDELTA]
		 (T (replace (POSITION YCOORD) of MOVINGPOINT with (IPLUS (fetch (POSITION YCOORD)
									     of FIXEDPOINT)
									  (IMIN -32 YDELTA]
	       (RETURN MOVINGPOINT])

(\TEDIT.SET.WINDOW.EXTENT
  [LAMBDA (TEXTOBJ WINDOW)                                   (* jds "12-Sep-84 15:38")
                                                             (* Set the window's EXTENT property according to 1st and
							     last char on screen.)
    (PROG ((WHEIGHT (fetch HEIGHT of (DSPCLIPPINGREGION NIL WINDOW)))
	   (LINES (WINDOWPROP WINDOW (QUOTE LINES)))
	   (TEXTLEN (fetch TEXTLEN of TEXTOBJ))
	   TOPCHAR BOTCHAR PREVLINE EXTHEIGHT EXTBOT YBOT)
          (COND
	    ((TEXTPROP TEXTOBJ (QUOTE NOEXTENT))             (* If he doesn't want the extent set, don't bother him.)
	      (RETURN)))
          (OR WINDOW (RETURN))                               (* Do nothing if there's no window to do it in.)
          (while (AND LINES (IGEQ (fetch YBOT of LINES)
				  WHEIGHT))
	     do                                              (* Run thru the lines looking for the first one on the 
							     screen.)
		(SETQ LINES (fetch NEXTLINE of LINES)))
          (COND
	    (LINES (SETQ TOPCHAR (fetch CHAR1 of LINES)))
	    (T (SETQ TOPCHAR TEXTLEN)))
          (while (AND LINES (IGEQ (fetch YBOT of LINES)
				  (fetch WBOTTOM of TEXTOBJ)))
	     do                                              (* Then go looking for the last line on the screen)
		(SETQ PREVLINE LINES)
		(SETQ LINES (fetch NEXTLINE of LINES)))
          (COND
	    (PREVLINE (SETQ BOTCHAR (IMIN TEXTLEN (fetch CHARLIM of PREVLINE)))
		      (SETQ YBOT (fetch YBOT of PREVLINE)))
	    (T (SETQ BOTCHAR TEXTLEN)
	       (SETQ YBOT WHEIGHT)))
          [COND
	    ((AND (IEQP BOTCHAR TEXTLEN)
		  (IEQP TOPCHAR TEXTLEN))
	      (SETQ EXTBOT (SUB1 YBOT))
	      (SETQ EXTHEIGHT WHEIGHT))
	    (T [SETQ EXTHEIGHT (FIXR (FQUOTIENT (ITIMES (IDIFFERENCE WHEIGHT YBOT)
							TEXTLEN)
						(IMAX (IDIFFERENCE BOTCHAR TOPCHAR)
						      1]
	       (SETQ EXTBOT (IDIFFERENCE YBOT (FIXR (FQUOTIENT (ITIMES (IDIFFERENCE WHEIGHT YBOT)
								       (IDIFFERENCE TEXTLEN BOTCHAR))
							       (IMAX (IDIFFERENCE BOTCHAR TOPCHAR)
								     1]
          (WINDOWPROP WINDOW (QUOTE EXTENT)
		      (create REGION
			      BOTTOM ← EXTBOT
			      HEIGHT ←(IMAX 1 EXTHEIGHT)
			      WIDTH ←(fetch WIDTH of (DSPCLIPPINGREGION NIL WINDOW))
			      LEFT ← 0])

(\TEDIT.SHRINK.ICONCREATE
  [LAMBDA (W ICON ICONW)                                     (* jds "25-Nov-84 14:52")
                                                             (* Create the icon that represents this window.)
    (PROG [(ICON (WINDOWPROP W (QUOTE ICON)))
	   (ICONTITLE (WINDOWPROP W (QUOTE TEDIT.ICON.TITLE)))
	   (SHRINKFN (WINDOWPROP W (QUOTE SHRINKFN]
          (COND
	    ((NOT (WINDOWPROP W (QUOTE TEXTOBJ)))            (* This isn't really a TEdit window any more.
							     Don't do anything)
	      NIL)
	    ((WINDOWPROP W (QUOTE TEDITMENU))                (* This is a text menu, and shrinks without trace.)
	      NIL)
	    ((OR (IGREATERP (FLENGTH SHRINKFN)
			    3)
		 (AND (NOT (FMEMB (QUOTE SHRINKATTACHEDWINDOWS)
				  SHRINKFN))
		      (IGREATERP (FLENGTH SHRINKFN)
				 2)))                        (* There are other functions that expect to handle 
							     this. Don't bother.)
	      NIL)
	    ((OR [AND ICONTITLE (EQUAL ICONTITLE (TEXTSTREAM.TITLE (TEXTSTREAM W]
		 (AND (NOT ICONTITLE)
		      ICON))                                 (* we built this and the title is the same, or he has 
							     already put an icon on this.
							     Do nothing)
	      NIL)
	    (ICON                                            (* There's an existing icon window;
							     change the title in it)
		  [WINDOWPROP W (QUOTE TEDIT.ICON.TITLE)
			      (SETQ ICONTITLE (TEXTSTREAM.TITLE (TEXTSTREAM W]
		  (ICONTITLE ICONTITLE NIL NIL ICON))
	    (T                                               (* install a new icon)
	       [WINDOWPROP W (QUOTE TEDIT.ICON.TITLE)
			   (SETQ ICONTITLE (TEXTSTREAM.TITLE (TEXTSTREAM W]
	       (WINDOWPROP W (QUOTE ICON)
			   (TITLEDICONW TEDIT.TITLED.ICON.TEMPLATE ICONTITLE TEDIT.ICON.FONT NIL T])

(\TEDIT.SHRINKFN
  [LAMBDA (W ICON ICONW)                                     (* jds "13-Apr-84 15:25")
                                                             (* hands off the tty to the exec process)
    (COND
      ((AND (EQ (WINDOWPROP W (QUOTE PROCESS))
		(TTY.PROCESS)))
	(TTY.PROCESS (QUOTE EXEC])

(\TEDIT.SPLITW
  [LAMBDA (WINDOW Y)                                         (* gbn "18-Apr-84 20:08")
                                                             (* SPLIT WINDOW W AT W-RELATIVE Y.)
    (PROG ((WREG (WINDOWPROP WINDOW (QUOTE REGION)))
	   (TEXTOBJ (WINDOWPROP WINDOW (QUOTE TEXTOBJ)))
	   NEWW OLDW OTITLE)
          (SETQ Y (OR Y (LASTMOUSEY WINDOW)))
          (SHAPEW WINDOW (create REGION using WREG BOTTOM ←(IPLUS (fetch BOTTOM of WREG)
								  Y)
					      HEIGHT ←(IDIFFERENCE (fetch HEIGHT of WREG)
								   Y)))
          (ATTACHWINDOW (SETQ NEWW (CREATEW (create REGION using WREG HEIGHT ← Y)
					    NIL NIL NIL))
			WINDOW
			(QUOTE BOTTOM)
			(QUOTE JUSTIFY)
			(QUOTE MAIN))
          (WINDOWPROP NEWW (QUOTE TEDITCREATED)
		      T)
          (SETQ OLDW (fetch \WINDOW of TEXTOBJ))
          (SETQ OTITLE (\TEDIT.WINDOW.TITLE TEXTOBJ))
          (\TEDIT.WINDOW.SETUP NEWW TEXTOBJ (fetch STREAMHINT of TEXTOBJ)
			       (fetch EDITPROPS of TEXTOBJ))
          (replace WINDOWTITLE of TEXTOBJ with OTITLE)       (* John, I'm not sure how you would like to do this, 
							     this is probably not what we want *********)
          [replace \WINDOW of TEXTOBJ with (COND
					     ((LISTP OLDW)
					       (NCONC1 OLDW NEWW))
					     (T (LIST OLDW NEWW]
          (WINDOWPROP NEWW (QUOTE PROCESS)
		      (WINDOWPROP WINDOW (QUOTE PROCESS])

(\TEDIT.UNSPLITW
  [LAMBDA (WINDOW Y)                                         (* jds "24-May-84 17:07")
                                                             (* SPLIT WINDOW W AT W-RELATIVE Y.)
    (PROG ([WREG (COPY (WINDOWPROP WINDOW (QUOTE REGION]
	   (MAINW (WINDOWPROP WINDOW (QUOTE MAINWINDOW)))
	   (TEXTOBJ (WINDOWPROP WINDOW (QUOTE TEXTOBJ)))
	   NEWW OLDW OTITLE)
          (COND
	    ((NOT MAINW)
	      (TEDIT.PROMPTPRINT TEXTOBJ "Can't UNSPLIT the main window." T)
	      (RETURN)))
          (DETACHWINDOW WINDOW)
          (TEDIT.DEACTIVATE.WINDOW WINDOW T)
          (CLOSEW WINDOW)
          (SHAPEW MAINW (UNIONREGIONS WREG (WINDOWPROP MAINW (QUOTE REGION])

(\TEDIT.WINDOW.SETUP
  [LAMBDA (WINDOW TEXTOBJ TEXTSTREAM PROPS)                  (* jds "25-Nov-84 14:44")
                                                             (* Set up the window and TEXTOBJ so they correspond, 
							     and the window is a TEDIT window.)
    (PROG ((SHRINKFN (WINDOWPROP WINDOW (QUOTE SHRINKFN)))
	   TEDITPROMPTWINDOW)
          (OR WINDOW (\ILLEGAL.ARG WINDOW))
          (TEDIT.WINDOW.SETUP WINDOW TEXTOBJ TEXTSTREAM PROPS)
          (WINDOWADDPROP WINDOW (QUOTE RESHAPEFN)
			 (FUNCTION \TEDIT.RESHAPEFN))
          (WINDOWADDPROP WINDOW (QUOTE NEWREGIONFN)
			 (FUNCTION \TEDIT.NEWREGIONFN))
          (OR (WINDOWPROP WINDOW (QUOTE SCROLLFN))
	      (WINDOWPROP WINDOW (QUOTE SCROLLFN)
			  (FUNCTION \TEDIT.SCROLLFN)))
          (WINDOWPROP WINDOW (QUOTE REPAINTFN)
		      (FUNCTION \TEDIT.REPAINTFN))
          [OR (WINDOWPROP WINDOW (QUOTE TEDIT.TITLEMENUFN))
	      (WINDOWPROP WINDOW (QUOTE TEDIT.TITLEMENUFN)
			  (OR (LISTGET PROPS (QUOTE TITLEMENUFN))
			      (QUOTE TEDIT.DEFAULT.MENUFN]
          (WINDOWADDPROP WINDOW (QUOTE CLOSEFN)
			 (FUNCTION TEDIT.DEACTIVATE.WINDOW))
          (WINDOWPROP WINDOW (QUOTE WINDOWENTRYFN)
		      (FUNCTION \TEDIT.PROCIDLEFN))
          [COND
	    ([OR (NULL SHRINKFN)
		 (EQ SHRINKFN (QUOTE SHRINKATTACHEDWINDOWS))
		 (EQUAL SHRINKFN (QUOTE (SHRINKATTACHEDWINDOWS]
                                                             (* ONLY CREATE ICONS IF NOBODY ELSE IS INTERESTED IN 
							     IT.)
	      (WINDOWADDPROP WINDOW (QUOTE SHRINKFN)
			     (FUNCTION \TEDIT.SHRINK.ICONCREATE]
          (WINDOWADDPROP WINDOW (QUOTE SHRINKFN)
			 (FUNCTION \TEDIT.SHRINKFN))         (* But always give up control of the keyboard on 
							     shrinking.)
          (WINDOWADDPROP WINDOW (QUOTE EXPANDFN)
			 (FUNCTION \TEDIT.EXPANDFN))
          (WINDOWPROP WINDOW (QUOTE TEDIT.CURSORREGION)
		      (LIST 0 0 0 0))                        (* Used by CursorMovedFn)
          (\TEDIT.WINDOW.TITLE TEXTOBJ (\TEDIT.ORIGINAL.WINDOW.TITLE WINDOW))
          (COND
	    ((EQ (QUOTE DON'T)
		 (LISTGET PROPS (QUOTE PROMPTWINDOW)))       (* He said not to provide a feedback region, so don't.)
	      )
	    ((AND (NOT (LISTGET PROPS (QUOTE READONLY)))
		  [NOT (replace PROMPTWINDOW of TEXTOBJ with (LISTGET PROPS (QUOTE PROMPTWINDOW]
		  (NOT (fetch MENUFLG of TEXTOBJ)))          (* The window is read-write, so give it a feedback 
							     region)
	      (SETQ TEDITPROMPTWINDOW (GETPROMPTWINDOW WINDOW (OR (LISTGET PROPS (QUOTE 
									       PROMPTWINDOWHEIGHT))
								  TEDIT.PROMPTWINDOW.HEIGHT 1)
						       TEDIT.PROMPT.FONT))
	      (replace PROMPTWINDOW of TEXTOBJ with TEDITPROMPTWINDOW)
	      (WINDOWPROP TEDITPROMPTWINDOW (QUOTE TEDIT.PROMPTWINDOW)
			  T])

(\SAFE.FIRST
  [LAMBDA (LIST.OR.ATOM)                                     (* gbn "18-Apr-84 21:13")
                                                             (* gives the first element whether the arg is a list or 
							     an atom. Should be a macro eventually)
    (SELECTQ (TYPENAME LIST.OR.ATOM)
	     (LISTP (CAR LIST.OR.ATOM))
	     LIST.OR.ATOM])
)



(* to get the record def for SHIFTSTATE)

(DECLARE: DONTCOPY DOEVAL@COMPILE 
(LOADCOMP? (QUOTE LLKEY))
)
(RPAQ BXCARET (CURSORCREATE (READBITMAP) 4 7))
(16 16
"@@@@"
"@@@@"
"@@@@"
"@@@@"
"@@@@"
"@@@@"
"@@@@"
"A@@@"
"CH@@"
"GL@@"
"FL@@"
"LF@@"
"@@@@"
"@@@@"
"@@@@"
"@@@@")(RPAQ BXHICARET (CURSORCREATE (READBITMAP) 4 7))
(16 16
"A@@@"
"A@@@"
"A@@@"
"A@@@"
"A@@@"
"A@@@"
"A@@@"
"A@@@"
"CH@@"
"GL@@"
"FL@@"
"LF@@"
"HB@@"
"@@@@"
"@@@@"
"@@@@")(RPAQ TEDIT.LINECURSOR (CURSORCREATE (READBITMAP) 15 15))
(16 16
"@@@A"
"@@@C"
"@@@G"
"@@@O"
"@@AO"
"@@CO"
"@@GO"
"@@@O"
"@@AK"
"@@AI"
"@@C@"
"@@C@"
"@@F@"
"@@F@"
"@@L@"
"@@L@")
(RPAQ? TEDIT.DEFAULT.WINDOW NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDIT.DEFAULT.WINDOW)
)



(* Attached Prompt window support.)

(DEFINEQ

(TEDIT.PROMPTPRINT
  [LAMBDA (TEXTSTREAM MSG CLEAR?)                            (* jds "13-Nov-84 10:51")
                                                             (* Print a message in the editor's prompt window 
							     (if none, use the global promptwindow). Optionally 
							     clear the window first.)
    (PROG (WINDOW PWINDOW (TEXTOBJ (TEXTOBJ TEXTSTREAM))
		  MAINTEXTOBJ)
          (COND
	    [(AND TEXTOBJ (fetch MENUFLG of TEXTOBJ))        (* There is a known textobj, and it's a menu.
							     Go use the main editor's promptwindow.)
	      (SETQ MAINTEXTOBJ (WINDOWPROP (\TEDIT.MAINW TEXTOBJ)
					    (QUOTE TEXTOBJ)))
	      (SETQ WINDOW (AND MAINTEXTOBJ (fetch PROMPTWINDOW of MAINTEXTOBJ]
	    ((AND TEXTOBJ (SETQ WINDOW (fetch PROMPTWINDOW of TEXTOBJ)))
                                                             (* There IS an editor window to get to;
							     use its prompt window)
	      )
	    ((SETQ WINDOW (GETPROMPTWINDOW (\TEDIT.MAINW TEXTSTREAM)
					   NIL NIL T))       (* Failing that, try any prompt window attached to the 
							     edit window.)
	      ))                                             (* Try to find an editor's prompt window for our 
							     message)
          (COND
	    (WINDOW                                          (* We found a window to use.
							     Print the message.)
		    (COND
		      (CLEAR? (CLEARW WINDOW)))
		    (PRIN3 MSG WINDOW))
	    (T                                               (* Failing all else, use PROMPTWINDOW.)
	       (FRESHLINE PROMPTWINDOW)
	       (printout PROMPTWINDOW MSG])
)

(RPAQ? TEDIT.PROMPT.FONT (FONTCREATE 'GACHA 10))

(RPAQ? TEDIT.PROMPTWINDOW.HEIGHT NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDIT.PROMPT.FONT TEDIT.PROMPTWINDOW.HEIGHT)
)



(* Title creation and update)

(DEFINEQ

(TEXTSTREAM.TITLE
  [LAMBDA (STREAM)                                           (* gbn "19-Apr-84 13:26")
                                                             (* returns a string with which you can talk to the user 
							     about this stream)
    (PROG ((TEXTOBJ (TEXTOBJ STREAM))
	   TXTFILE)
          (SETQ TXTFILE (fetch TXTFILE of TEXTOBJ))
          (RETURN (OR (SELECTQ (TYPENAME TXTFILE)
			       (STRINGP TXTFILE)
			       (STREAM (fetch FULLNAME of TXTFILE))
			       (ATOMP TXTFILE)
			       TXTFILE)
		      ""])

(\TEDIT.ORIGINAL.WINDOW.TITLE
  [LAMBDA (FILE)                                             (* gbn "25-Apr-84 22:17")
                                                             (* Given a file name, derive a title for the TEdit 
							     window that is editing it.)
    (PROG (TITLE)
          (RETURN (COND
		    ((NULL FILE)                             (* Just calling (TEDIT) should give a 
							     "Text Editor Window")
		      "Text Editor Window")
		    ((ZEROP (NCHARS (MKSTRING FILE)))        (* So should editing an empty string)
		      "Text Editor Window")
		    ((WINDOWP FILE)
		      (if (SETQ TITLE (WINDOWPROP FILE (QUOTE TITLE)))
			  then                               (* if \TEDIT.WINDOW.SETUP has assigned a title, use it)
			       TITLE
			else "Text Editor Window"))
		    (T                                       (* Strings use the string itself, otherwise grab the 
							     full file name.)
		       (CONCAT "Edit Window for:  " (SELECTQ (TYPENAME FILE)
							     (STRINGP FILE)
							     (STREAM (fetch FULLNAME of FILE))
							     (ATOMP FILE)
							     FILE])

(\TEDIT.WINDOW.TITLE
  [LAMBDA (TEXTSTREAM NEW.TITLE)                             (* jds "16-Aug-84 17:02")
    (PROG ((TEXTOBJ (TEXTOBJ TEXTSTREAM))
	   W)
          (RETURN (COND
		    ([AND (SETQ W (\TEDIT.PRIMARYW TEXTOBJ))
			  (NOT (TEXTPROP TEXTOBJ (QUOTE NOTITLE]
                                                             (* Only change the title if there IS a window, and he 
							     isn't suppressing title changes.)
		      (COND
			(NEW.TITLE (WINDOWPROP W (QUOTE TITLE)
					       NEW.TITLE))
			(T (WINDOWPROP W (QUOTE TITLE])

(\TEXTSTREAM.FILENAME
  [LAMBDA (TEXTSTREAM)                                       (* gbn " 9-Oct-84 00:02")

          (* * returns the name of the file associated with this stream if there is one. NIL otherwise.
	  Version numbers suppressed)


    (PROG ((STREAM (TEXTSTREAM TEXTSTREAM))
	   OFILE)
          [IF (type? STREAM (fetch TXTFILE of TEXTOBJ))
	      THEN [SETQ OFILE (UNPACKFILENAME (fetch FULLFILENAME (fetch TXTFILE of TEXTOBJ]
		   (AND OFILE (LISTPUT OFILE (QUOTE VERSION)
				       NIL))
		   (SETQ OFILE (AND OFILE (PACKFILENAME OFILE]
          (RETURN OFILE])
)



(* Screen updating utilities)

(DEFINEQ

(TEDIT.DEACTIVATE.WINDOW
  [LAMBDA (W FORCEFLG)                                       (* jds " 2-Jul-84 18:36")
                                                             (* Deactivate the various button fns for this window)
    (PROG [(TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ]            (* Can't be a call to TEXTOBJ, since window may NOT have
							     a textobj on it.)
          [COND
	    ((AND TEXTOBJ (PROCESSP (WINDOWPROP W (QUOTE PROCESS)))
		  (NOT (fetch EDITFINISHEDFLG of TEXTOBJ))
		  (NOT (fetch TXTREADONLY of TEXTOBJ))
		  (NOT FORCEFLG))
	      (\TEDIT.QUIT W)
	      (OR (fetch EDITFINISHEDFLG of TEXTOBJ)
		  (RETURN (QUOTE DON'T]
          (COND
	    ([AND TEXTOBJ (OR FORCEFLG (fetch EDITFINISHEDFLG of TEXTOBJ)
			      (NOT (PROCESSP (WINDOWPROP W (QUOTE PROCESS]
                                                             (* Only do this if it's a TEdit window, and has been 
							     QUIT out of.)
	      [COND
		((AND (fetch PROMPTWINDOW of TEXTOBJ)
		      (OPENWP (fetch PROMPTWINDOW of TEXTOBJ)))
		  (CLEARW (fetch PROMPTWINDOW of TEXTOBJ]
	      (COND
		((\TEDIT.WINDOW.TITLE TEXTOBJ)
		  (\TEDIT.WINDOW.TITLE TEXTOBJ "Edit Window [Inactive]")))
                                                             (* Reset the window's title to a known "inactive" value)
	      (WINDOWPROP W (QUOTE TEXTOBJ)
			  NIL)                               (* Detach the edit data structures from the window)
	      (WINDOWPROP W (QUOTE TEXTSTREAM)
			  NIL)
	      (WINDOWPROP W (QUOTE LINES)
			  NIL)
	      (WINDOWPROP W (QUOTE THISLINE)
			  NIL)
	      (WINDOWPROP W (QUOTE PROCESS.EXITFN)
			  NIL)
	      (WINDOWPROP W (QUOTE PROCESS.IDLEFN)
			  NIL)
	      (WINDOWPROP W (QUOTE CURSOROUTFN)
			  NIL)
	      (WINDOWPROP W (QUOTE CURSORMOVEDFN)
			  NIL)
	      (WINDOWPROP W (QUOTE BUTTONEVENTFN)
			  (QUOTE TOTOPW))                    (* And the button functions)
	      (WINDOWPROP W (QUOTE RIGHTBUTTONFN)
			  (QUOTE DOWINDOWCOM))
	      (WINDOWPROP W (QUOTE SCROLLFN)
			  NIL)
	      (WINDOWDELPROP W (QUOTE RESHAPEFN)
			     (QUOTE \EDITRESHAPEFN))
	      (\TEDIT.INTERRUPT.SETUP W T)                   (* Make sure any disarmed interrupts are restored.)
	      (for MENUW in (ATTACHEDWINDOWS W) when (WINDOWPROP MENUW (QUOTE TEDITMENU))
		 do                                          (* Detach all the TEDITMENU windows that belong to this 
							     window.)
		    (GIVE.TTY.PROCESS MENUW)
		    (DISMISS 20))
	      [replace \WINDOW of TEXTOBJ with (COND
						 ((LISTP (fetch \WINDOW of TEXTOBJ))
                                                             (* It's a list; remove this window)
						   (DREMOVE W (fetch \WINDOW of TEXTOBJ]
                                                             (* Disconnect the window from the edit data structures 
							     as well.)
	      ])

(\TEDIT.REPAINTFN
  [LAMBDA (W)                                                (* jds "18-Sep-84 16:09")
                                                             (* Will eventually do the right thing w/r/t text 
							     margins. For now, it's a place holder.)
    (PROG ((TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ)))
	   (TEXTSTREAM (WINDOWPROP W (QUOTE TEXTSTREAM)))
	   (CH# 0)
	   WHEIGHT FIRSTCH# LINES LINE WWIDTH)
          (OR TEXTOBJ (RETURN))                              (* If this window has no TEXTOBJ on it yet, just 
							     leave.)
          (\SHOWSEL (fetch SEL of TEXTOBJ)
		    NIL NIL)                                 (* Turn off the selection while we make changes)
          (SETQ WHEIGHT (fetch WTOP of TEXTOBJ))             (* Old window height)
          (OR (SETQ LINES (WINDOWPROP W (QUOTE LINES)))
	      (RETURN))                                      (* If no text has been displayed yet, just leave)
          (SETQ LINE LINES)
          (while LINE
	     do 

          (* Now hunt for the first line that had been visible, so we can find the CH# that has to appear at the top of the 
	  window.)


		(COND
		  ((ILESSP (fetch YBOT of LINE)
			   WHEIGHT)                          (* This line was visible)
		    (SETQ FIRSTCH# (fetch CHAR1 of LINE))    (* Note its first character #)
		    (RETURN)))
		(SETQ LINE (fetch NEXTLINE of LINE)))
          (COND
	    ((NEQ LINE LINES)
	      (replace NEXTLINE of LINES with LINE)
	      (REPLACE PREVLINE OF LINE WITH LINES)))        (* Forget the old chain of line descriptors)
          (COND
	    (LINE                                            (* You can only do this if there IS text on the screen 
							     to start with.)
		  (\DISPLAYLINE TEXTOBJ LINE W)              (* Actually display it)
		  (\FILLWINDOW (fetch YBOT of LINE)
			       LINE TEXTOBJ NIL W)           (* Fill out the window with more lines, to fill or to 
							     EOF)
		  ))
          (\FIXSEL (fetch SEL of TEXTOBJ)
		   TEXTOBJ)                                  (* Fix up the selection to account for the line 
							     shuffling)
          (\SHOWSEL (fetch SEL of TEXTOBJ)
		    NIL T)                                   (* And highlight it)
      ])

(\TEDIT.RESHAPEFN
  [LAMBDA (W BITS OLDREGION)                                 (* jds "24-Oct-84 17:38")
                                                             (* Will eventually do the right thing w/r/t text 
							     margins. For now, it's a place holder.)
    (PROG ((TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ)))
	   (TEXTSTREAM (WINDOWPROP W (QUOTE TEXTSTREAM)))
	   (NEWWHEIGHT (fetch HEIGHT of (DSPCLIPPINGREGION NIL W)))
	   (NEWWWIDTH (fetch WIDTH of (DSPCLIPPINGREGION NIL W)))
	   (NEWLEFT 0)
	   (NEWBOTTOM 0)
	   (CH# 0)
	   WHEIGHT FIRSTCH# LINES LINE WWIDTH)
          (OR TEXTOBJ (RETURN))                              (* If this window has no TEXTOBJ on it yet, just 
							     leave.)
          (\SHOWSEL (fetch SEL of TEXTOBJ)
		    NIL NIL)                                 (* Turn off the selection while we make changes)
          (SETQ WHEIGHT (fetch HEIGHT of OLDREGION))         (* Old window height)
          (replace WTOP of TEXTOBJ with NEWWHEIGHT)          (* Save new height/width for later use)
          (replace WRIGHT of TEXTOBJ with NEWWWIDTH)
          (replace WBOTTOM of TEXTOBJ with NEWBOTTOM)
          (replace WLEFT of TEXTOBJ with NEWLEFT)
          (OR (SETQ LINES (WINDOWPROP W (QUOTE LINES)))
	      (RETURN))                                      (* If no text has been displayed yet, just leave)
          (SETQ LINE LINES)
          (while LINE
	     do 

          (* Now hunt for the first line that had been visible, so we can find the CH# that has to appear at the top of the 
	  window.)


		(COND
		  ((ILESSP (fetch YBOT of LINE)
			   WHEIGHT)                          (* This line was visible)
		    (SETQ FIRSTCH# (fetch CHAR1 of LINE))    (* Note its first character #)
		    (RETURN))
		  (T (replace YBOT of LINE with NEWWHEIGHT)))
		(SETQ LINE (fetch NEXTLINE of LINE)))
          (AND FIRSTCH# (SETQ LINE (\TEDIT.FIND.FIRST.LINE TEXTOBJ NEWWHEIGHT FIRSTCH# W)))
          (COND
	    (LINE                                            (* You can only do this if there IS text on the screen 
							     to start with.)
		  (COND
		    ((NEQ LINE LINES)
		      (replace NEXTLINE of LINES with LINE)
		      (REPLACE PREVLINE OF LINE WITH LINES)))
                                                             (* Forget the old chain of line descriptors)
		  (replace YBOT of LINE with (IDIFFERENCE NEWWHEIGHT (fetch LHEIGHT of LINE)))
                                                             (* Fix the line to appear at the top of the window)
		  (replace YBASE of LINE with (IPLUS (fetch YBOT of LINE)
						     (fetch DESCENT of LINE)))
		  (\DISPLAYLINE TEXTOBJ LINE W)              (* Actually display it)
		  (\FILLWINDOW (fetch YBOT of LINE)
			       LINE TEXTOBJ NIL W)           (* Fill out the window with more lines, to fill or to 
							     EOF)
		  ))
          (\FIXSEL (fetch SEL of TEXTOBJ)
		   TEXTOBJ)                                  (* Fix up the selection to account for the line 
							     shuffling)
          (\SHOWSEL (fetch SEL of TEXTOBJ)
		    NIL T)                                   (* And highlight it)
      ])

(\TEDIT.SET.WINDOW.TITLE
  [LAMBDA (TEXTOBJ)                                          (* jds "21-Feb-84 14:21")
                                                             (* Given a text obj, create a title for the window in 
							     it.)
                                                             (* If the window has a fixed title, use it;
							     otherwise, derive a title from the name of the file 
							     being edited.)
    (OR (fetch WINDOWTITLE of TEXTOBJ)
	(\TEDIT.WINDOW.TITLE (fetch TXTFILE of TEXTOBJ])

(\TEDIT.SCROLLFN
  [LAMBDA (W DX DY)                                          (* jds "21-Aug-84 12:14")
                                                             (* Handle scrolling of the edit window)
    (PROG (WHEIGHT (TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ)))
		   (PRIORCR 0)
		   SELWASON SHIFTEDSELWASON MOVESELWASON DELETESELWASON (WREG (DSPCLIPPINGREGION
										NIL W))
		   LINES TRUEY TRUEX WWIDTH SEL (PREVLINE NIL)
		   (PRESCROLLFN (WINDOWPROP W (QUOTE TEDIT.PRESCROLLFN)))
		   (POSTSCROLLFN (WINDOWPROP W (QUOTE TEDIT.POSTSCROLLFN)))
		   TEXTLEN THEIGHT TOPLINE RHEIGHT LOWESTY YBOT LINE CH# CHNO CH)
          (COND
	    ((ZEROP (SETQ TEXTLEN (fetch TEXTLEN of TEXTOBJ)))
                                                             (* Don't scroll a zero-length file)
	      (RETURN))
	    ((fetch EDITOPACTIVE of TEXTOBJ)                 (* Don't scroll while something interesting is 
							     happening!)
	      (TEDIT.PROMPTPRINT TEXTOBJ "Edit operation in progress." T)
	      (RETURN)))                                     (* Displaystream for the window)
          (SETQ WHEIGHT (fetch HEIGHT of WREG))              (* Height of the window)
          (SETQ LOWESTY WHEIGHT)                             (* Lowest Y of a line-bottom yet seet)
          (SETQ WWIDTH (fetch WIDTH of WREG))                (* Width of the window)
          (SETQ LINES (WINDOWPROP W (QUOTE LINES)))          (* List of formatted lines)
          (AND PRESCROLLFN (DOUSERFNS PRESCROLLFN W))        (* If there's a pre-scroll fn, execute it now.)
          (COND
	    ((fetch SET of (SETQ SEL (fetch SEL of TEXTOBJ)))
                                                             (* Turn off the selection during the scroll.)
	      (SETQ SELWASON (fetch ONFLG of SEL))
	      (\SHOWSEL SEL NIL NIL)))
          (SETQ SHIFTEDSELWASON (fetch ONFLG of (fetch SHIFTEDSEL of TEXTOBJ)))
          (\SHOWSEL (fetch SHIFTEDSEL of TEXTOBJ)
		    NIL NIL)
          (SETQ MOVESELWASON (fetch ONFLG of (fetch MOVESEL of TEXTOBJ)))
          (\SHOWSEL (fetch MOVESEL of TEXTOBJ)
		    NIL NIL)
          (SETQ DELETESELWASON (fetch ONFLG of (fetch DELETESEL of TEXTOBJ)))
          (\SHOWSEL (fetch DELETESEL of TEXTOBJ)
		    NIL NIL)
          (COND
	    [(AND (FIXP DY)
		  (NOT (ZEROP DY)))                          (* Regular up/down scrolling)
	      (SETQ TRUEY (IDIFFERENCE WHEIGHT (IABS DY)))
	      (COND
		[(ILESSP 0 DY)                               (* Scroll text up)
		  (SETQ LINE LINES)
		  (while (AND LINE (IGEQ (fetch YBOT of LINE)
					 WHEIGHT))
		     do (SETQ LINE (fetch NEXTLINE of LINE)))
		  (first [COND
			   ((AND LINE (ILESSP (fetch YBOT of LINE)
					      TRUEY))        (* Make sure we scroll up at least one line.)
			     (replace YBASE of LINE with (IPLUS (fetch DESCENT of LINE)
								(replace YBOT of LINE with WHEIGHT)))
			     (SETQ LINE (fetch NEXTLINE of LINE]
		     while LINE
		     do                                      (* Find the line whose top is to move to the top of the 
							     window)
			[COND
			  ((ILESSP (fetch YBOT of LINE)
				   TRUEY)
			    (RETURN))
			  (T (replace YBASE of LINE with (IPLUS (fetch DESCENT of LINE)
								(replace YBOT of LINE with WHEIGHT]
			(SETQ PREVLINE LINE)
			(SETQ LINE (fetch NEXTLINE of LINE)))
		  [COND
		    (LINE                                    (* There is a line to go to the top)
			  (SETQ RHEIGHT (IPLUS (fetch YBASE of LINE)
					       (fetch ASCENT of LINE)))
                                                             (* Find the Ypos of the top of the line's image)
			  (BITBLT W 0 0 W 0 (IDIFFERENCE WHEIGHT RHEIGHT)
				  WWIDTH RHEIGHT (QUOTE INPUT)
				  (QUOTE REPLACE))
			  (BITBLT NIL 0 0 W 0 0 WWIDTH (IDIFFERENCE WHEIGHT RHEIGHT)
				  (QUOTE TEXTURE)
				  (QUOTE REPLACE)
				  WHITESHADE)
			  [bind NL (PL ← PREVLINE) for I from 1 to 50 while PL
			     do                              (* Let him keep 50 lines above what he can see on the 
							     screen)
				(SETQ PL (fetch PREVLINE of PL))
			     finally (COND
				       ((AND PL (NEQ PL LINES))
                                                             (* There were more than 50 lines 
							     (and we aren't pointing at the root), so lop the spare 
							     ones off.)
					 (SETQ NL (fetch NEXTLINE of LINES))
					 (UNINTERRUPTABLY
                                             (replace NEXTLINE of LINES with PL)
					     (replace PREVLINE of PL with LINES))
					 (bind NNL while (AND NL (NEQ NL PL))
					    do (SETQ NNL NL)
					       (SETQ NL (fetch NEXTLINE of NL))
					       (replace NEXTLINE of NNL with NIL]
			  (while (AND LINE (IGEQ (fetch YBOT of LINE)
						 (fetch WBOTTOM of TEXTOBJ)))
			     do                              (* Update the bottom and baseline)
				(replace YBOT of LINE with (IPLUS (fetch YBOT of LINE)
								  (IDIFFERENCE WHEIGHT RHEIGHT)))
				(replace YBASE of LINE with (IPLUS (fetch YBOT of LINE)
								   (fetch DESCENT of LINE)))
				(SETQ PREVLINE LINE)
				(SETQ LINE (fetch NEXTLINE of LINE]
		  (COND
		    ((AND LINE (IGEQ (fetch YBOT of LINE)
				     (fetch WBOTTOM of TEXTOBJ)))
                                                             (* Fill the rest of the window)
		      (\FILLWINDOW (fetch YBOT of LINE)
				   LINE TEXTOBJ NIL W))
		    (PREVLINE (\FILLWINDOW (fetch YBOT of PREVLINE)
					   PREVLINE TEXTOBJ NIL W]
		(T                                           (* Scroll text down in window, adding lines at top to 
							     fill.)
		   (SETQ PREVLINE (SETQ TOPLINE LINES))      (* Find the top line on the screen:)
		   [while TOPLINE do (COND
				       ((ILESSP (fetch YBOT of TOPLINE)
						WHEIGHT)
					 (RETURN))
				       (T (SETQ PREVLINE TOPLINE)
					  (SETQ TOPLINE (fetch NEXTLINE of TOPLINE]
		   [COND
		     ((EQ PREVLINE LINES)                    (* There's nothing between us and start of file that's 
							     formatted; start by making some.)
		       (SETQ PREVLINE (\BACKFORMAT LINES TEXTOBJ]
		   (SETQ THEIGHT 0)
		   [while (AND (ILESSP THEIGHT (IABS DY))
			       (IGEQ (fetch CHAR1 of PREVLINE)
				     1))
		      do                                     (* Starting with PREVLINE, accumulate LHEIGHTs until we 
							     hit top of text or have accumulated enough lines to fill
							     the screen)
			 (add THEIGHT (fetch LHEIGHT of PREVLINE))
			 (SETQ PREVLINE (fetch PREVLINE of PREVLINE))
			 (COND
			   ((ILESSP (fetch CHAR1 of PREVLINE)
				    1)                       (* We need to format some lines above where we are -- go
							     do it.)
			     (SETQ PREVLINE (\BACKFORMAT LINES TEXTOBJ]
		   [COND
		     ((ILESSP (IABS DY)
			      THEIGHT)                       (* BACK UP ONE LINE TO GET TO THE ONE WHICH PUSHED US 
							     OVER TOP)
		       (SETQ PREVLINE (fetch NEXTLINE of PREVLINE))
		       (SETQ THEIGHT (IDIFFERENCE THEIGHT (fetch LHEIGHT of PREVLINE]
		   (SETQ PREVLINE (fetch NEXTLINE of PREVLINE))
                                                             (* Move to the first line to be formatted.-)
		   (BITBLT W 0 THEIGHT W 0 0 WWIDTH (IDIFFERENCE WHEIGHT THEIGHT)
			   (QUOTE INPUT)
			   (QUOTE REPLACE))
		   (BITBLT NIL 0 0 W 0 (IDIFFERENCE WHEIGHT THEIGHT)
			   WWIDTH THEIGHT (QUOTE TEXTURE)
			   (QUOTE REPLACE)
			   WHITESHADE)
		   (bind (LINE ← TOPLINE) while LINE
		      do (COND
			   ((IGEQ (fetch YBOT of LINE)
				  (IPLUS (fetch WBOTTOM of TEXTOBJ)
					 THEIGHT))           (* This line will be on screen.
							     Adjust its YBOT/YBASE)
			     (replace YBOT of LINE with (IDIFFERENCE (fetch YBOT of LINE)
								     THEIGHT))
			     (replace YBASE of LINE with (IDIFFERENCE (fetch YBASE of LINE)
								      THEIGHT))
			     (SETQ LOWESTY (fetch YBOT of LINE)))
			   (T (replace YBOT of LINE with (SUB1 (fetch WBOTTOM of TEXTOBJ)))
			      (replace NEXTLINE of (fetch PREVLINE of LINE) with NIL)
			      (SETQ LINE (fetch PREVLINE of LINE))
			      (RETURN)))
			 (SETQ LINE (fetch NEXTLINE of LINE)) 
                                                             (* Clear anything below us))
		   (BITBLT NIL 0 0 W 0 (fetch WBOTTOM of TEXTOBJ)
			   WWIDTH
			   (IDIFFERENCE LOWESTY (fetch WBOTTOM of TEXTOBJ))
			   (QUOTE TEXTURE)
			   (QUOTE REPLACE)
			   WHITESHADE)
		   (SETQ YBOT WHEIGHT)
		   (while (AND PREVLINE (NEQ PREVLINE TOPLINE))
		      do                                     (* Move down lines to be added, adjusting YBOT/YBASE and
							     DISPALYLINE-ing them, until the next line to do EQ 
							     TOPLINE)
			 [replace YBOT of PREVLINE with (SETQ YBOT (IDIFFERENCE YBOT
										(fetch LHEIGHT
										   of PREVLINE]
			 (replace YBASE of PREVLINE with (IPLUS (fetch YBOT of PREVLINE)
								(fetch DESCENT of PREVLINE)))
			 (\DISPLAYLINE TEXTOBJ PREVLINE W)
			 (SETQ PREVLINE (fetch NEXTLINE of PREVLINE]
	    ((FLOATP DY)                                     (* Do a thumbing-type scroll)
	      (SETQ CH# (IMAX (IMIN (SUB1 TEXTLEN)
				    (FIXR (FTIMES TEXTLEN DY)))
			      1))
	      (SETQ LINE (fetch NEXTLINE of LINES))
	      [while (AND LINE (ILESSP (fetch CHARLIM of LINE)
				       CH#))
		 do (SETQ LINE (fetch NEXTLINE of LINE))
		 finally (COND
			   ((AND LINE (IGREATERP (fetch CHAR1 of LINE)
						 CH#))
			     (SETQ LINE NIL]                 (* find out if any line currently formatted includes the
							     target char)
	      (COND
		((AND LINE (fetch NEXTLINE of LINE))         (* If so, let's do this as a fast scroll, rather than a 
							     complete repaint of the screen)
		  [SETQ DY (COND
		      [(ILEQ WHEIGHT (fetch YBOT of LINE))   (* this line is off the top of the window)
			(IMINUS (for (DESCENDLINE ←(fetch NEXTLINE of LINE))
				   by (fetch NEXTLINE of DESCENDLINE)
				   while (AND DESCENDLINE (ILEQ WHEIGHT (fetch YBOT of LINE)))
				   sum                       (* sum the heights of all the lines in between the new 
							     top line and the present top line)
				       (fetch LHEIGHT of DESCENDLINE]
		      (T (IDIFFERENCE (IDIFFERENCE WHEIGHT (fetch YBOT of LINE))
				      (fetch LHEIGHT of LINE]
		  (\TEDIT.SCROLLFN W 0 DY)                   (* recurse telling to normally scroll instead of thumb 
							     scroll so that the screen is not blanked and reformatted
							     unnecessarily)
		  )
		(T [AND (fetch L1 of SEL)
			(replace YBOT of (fetch L1 of SEL) with (SUB1 (fetch WBOTTOM of TEXTOBJ]
                                                             (* Make sure it thinks the old selection is off-screen 
							     for now)
		   [AND (fetch LN of SEL)
			(replace YBOT of (fetch LN of SEL) with (SUB1 (fetch WBOTTOM of TEXTOBJ]
		   (BITBLT NIL 0 0 W 0 (fetch WBOTTOM of TEXTOBJ)
			   WWIDTH
			   (IDIFFERENCE WHEIGHT (fetch WBOTTOM of TEXTOBJ))
			   (QUOTE TEXTURE)
			   (QUOTE REPLACE)
			   WHITESHADE)
		   (SETQ LINE (\TEDIT.FIND.FIRST.LINE TEXTOBJ WHEIGHT CH# W))
                                                             (* Find the first line to go in the window)
		   (replace YBOT of LINE with (IDIFFERENCE WHEIGHT (fetch LHEIGHT of LINE)))
                                                             (* Set it up as the top line.)
		   (replace YBASE of LINE with (IPLUS (fetch YBOT of LINE)
						      (fetch DESCENT of LINE)))
		   (\DISPLAYLINE TEXTOBJ LINE W)
		   (\FILLWINDOW (fetch YBOT of LINE)
				LINE TEXTOBJ NIL W)))        (* And fill out the window from there.)
	      ))
          (AND POSTSCROLLFN (DOUSERFNS POSTSCROLLFN W))      (* For user subsystem cleanup)
          [COND
	    ((fetch SET of SEL)
	      (\FIXSEL SEL TEXTOBJ)
	      (AND SELWASON (\SHOWSEL SEL NIL T]
          [COND
	    ((fetch SET of (fetch SHIFTEDSEL of TEXTOBJ))
	      (\FIXSEL (fetch SHIFTEDSEL of TEXTOBJ)
		       TEXTOBJ)
	      (AND SHIFTEDSELWASON (\SHOWSEL (fetch SHIFTEDSEL of TEXTOBJ)
					     NIL T]
          [COND
	    ((fetch SET of (fetch MOVESEL of TEXTOBJ))
	      (\FIXSEL (fetch MOVESEL of TEXTOBJ)
		       TEXTOBJ)
	      (AND MOVESELWASON (\SHOWSEL (fetch MOVESEL of TEXTOBJ)
					  NIL T]
          [COND
	    ((fetch SET of (fetch DELETESEL of TEXTOBJ))
	      (\FIXSEL (fetch DELETESEL of TEXTOBJ)
		       TEXTOBJ)
	      (AND DELETESELWASON (\SHOWSEL (fetch DELETESEL of TEXTOBJ)
					    NIL T]
          (\TEDIT.SET.WINDOW.EXTENT TEXTOBJ W])
)



(* Process-world interfaces)

(DEFINEQ

(\TEDIT.PROCIDLEFN
  [LAMBDA (WINDOW)                                           (* gbn "20-Nov-84 17:52")
                                                             (* TEDIT's PROC.IDLEFN for regaining control.
							     If the shift key is down, we're not trying to restart 
							     this window, just to copy from it.)
    (GETMOUSESTATE)
    (COND
      [[AND (INSIDE? (DSPCLIPPINGREGION NIL WINDOW)
		     (LASTMOUSEX WINDOW)
		     (LASTMOUSEY WINDOW))
	    [NOT (OR (fetch (SHIFTSTATE SHIFT) of \SHIFTSTATE)
		     (fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
		     (fetch (SHIFTSTATE META) of \SHIFTSTATE)
		     (KEYDOWNP (QUOTE MOVE))
		     (KEYDOWNP (QUOTE COPY]
	    (PROCESSP (WINDOWPROP WINDOW (QUOTE PROCESS]     (* No SHIFT key down; let's regain control.)
	(TTY.PROCESS (WINDOWPROP WINDOW (QUOTE PROCESS)))
	(COND
	  ((fetch MENUFLG of (WINDOWPROP (WHICHW)
					 (QUOTE TEXTOBJ)))   (* This is a MENU -- always select.)
	    (\TEDIT.BUTTONEVENTFN WINDOW]
      (T                                                     (* Otherwise, let him select.)
	 (\TEDIT.BUTTONEVENTFN WINDOW])

(\TEDIT.PROCENTRYFN
  [LAMBDA (NEWPROCESS OLDPROCESS)                            (* jds "15-Feb-84 16:59")
                                                             (* TEDIT's PROCESS.ENTRYFN, which disarms any dangerous 
							     interrupts within the editing world)
    (\TEDIT.INTERRUPT.SETUP NEWPROCESS])

(\TEDIT.PROCEXITFN
  [LAMBDA (THISP NEWP)                                       (* jds " 5-Apr-84 10:40")
                                                             (* Re-arm any interrupts that TEdit turned off, so the 
							     poor user has them available in other parts of the 
							     system.)
    (AND (WINDOWPROP (PROCESSPROP THISP (QUOTE WINDOW))
		     (QUOTE TEXTOBJ))
	 (\TEDIT.INTERRUPT.SETUP THISP T])
)

(RPAQ? \CARETRATE 333)



(* Caret handler; stolen from CHAT.)

(DEFINEQ

(\EDIT.DOWNCARET
  [LAMBDA (CARET)                                            (* jds "20-Apr-84 21:50")
                                                             (* Put the caret down -- i.e., MAKE IT VISIBLE -- as 
							     fast as possible)
    (AND (fetch TCUP of CARET)
	 (\EDIT.FLIPCARET CARET T))                          (* CARET:FORCEDDOWN is set so that caret will come up 
							     quickly.)
    (replace TCFORCEDDOWN of CARET with T])

(\EDIT.FLIPCARET
  [LAMBDA (CARET FORCE)                                      (* jds "31-May-84 17:52")
                                                             (* changes the caret from on to off or off to on.)
    (COND
      ([OR FORCE (fetch TCFORCEDDOWN of CARET)
	   (AND (IGREATERP (CLOCK0 (fetch TCNOWTIME of CARET))
			   (fetch TCTHENTIME of CARET))
		(NOT (fetch TCFORCEUP of CARET]
	(UNINTERRUPTABLY                                     (* note the time of the next change.)
                                                             (* must be done without creating boxes because happens 
							     during keyboard wait.)
	    (\BOXIPLUS (CLOCK0 (fetch TCTHENTIME of CARET))
		       (fetch TCCARETRATE of CARET))         (* Set the time for the next caret transition)
	    (replace TCUP of CARET with (NOT (fetch TCUP of CARET)))
                                                             (* Invert the sense of the caret's UPness)
	    (replace TCFORCEDDOWN of CARET with NIL)         (* Turn off the force-down & Force-up flags)
	    (replace TCFORCEUP of CARET with NIL)
	    (PROG ((DS (fetch TCCARETDS of CARET))
		   (CURS (fetch TCCURSORBM of CARET)))
	          [COND
		    ((fetch TCUP of CARET))
		    (T                                       (* We're putting the caret down -- set the new X,Y 
							     position)
		       (replace TCCARETX of CARET with (DSPXPOSITION NIL DS))
		       (replace TCCARETY of CARET with (DSPYPOSITION NIL DS]
	          (BITBLT (fetch CURSORBITMAP of CURS)
			  0 0 DS (IDIFFERENCE (fetch TCCARETX of CARET)
					      (fetch CURSORHOTSPOTX of CURS))
			  (IDIFFERENCE (fetch TCCARETY of CARET)
				       (fetch CURSORHOTSPOTY of CURS))
			  CURSORWIDTH CURSORHEIGHT (QUOTE INPUT)
			  (QUOTE INVERT))))])

(TEDIT.FLASHCARET
  [LAMBDA (CARET)                                            (* jds "20-Apr-84 22:00")
                                                             (* Unless the caret is constrained to be INVISIBLE, give
							     it a chance to flash.)
    (COND
      ((NOT (fetch TCFORCEUP of CARET))                      (* The caret need not stay invisible.)
	(\EDIT.FLIPCARET CARET])

(\EDIT.UPCARET
  [LAMBDA (CARET)                                            (* jds "20-Apr-84 21:51")
                                                             (* Take the caret up -- i.e., MAKE IT INVISIBLE -- and 
							     keep it up)
    (OR (fetch TCUP of CARET)
	(\EDIT.FLIPCARET CARET T))                           (* CARET:FORCEUP is set so that caret will stay up.)
    (replace TCFORCEUP of CARET with T])

(TEDIT.NORMALIZECARET
  [LAMBDA (TEXTOBJ SEL)                                      (* jds "21-Nov-84 11:11")
                                                             (* Scroll the text window so that the caret is visible 
							     in it.)
    (SETQ TEXTOBJ (TEXTOBJ TEXTOBJ))
    (PROG ((SEL (OR SEL (fetch SEL of TEXTOBJ)))
	   WHEIGHT
	   (WINDOW (fetch SELWINDOW of TEXTOBJ))
	   CH# Y LINE)                                       (* First, find where the caret is)
          (OR (fetch SET of SEL)
	      (RETURN))                                      (* If there is no selection set, don't bother.)
          (SETQ WHEIGHT (fetch WTOP of TEXTOBJ))
          (SELECTQ (fetch POINT of SEL)
		   (LEFT                                     (* The caret is at the left end of the selection;
							     hunt for the first selected character)
			 (SETQ CH# (fetch CH# of SEL))
			 (SETQ Y (fetch Y0 of SEL)))
		   (RIGHT                                    (* The caret is at the right end of the selection;
							     hunt for the last selected character)
			  (SETQ CH# (fetch CHLIM of SEL))
			  (SETQ Y (fetch YLIM of SEL)))
		   NIL)
          (COND
	    ((OR (IGEQ Y WHEIGHT)
		 (ILESSP Y (fetch WBOTTOM of TEXTOBJ)))      (* The caret is off-screen. Scroll to get it on)
	      [AND (fetch L1 of SEL)
		   (replace YBOT of (fetch L1 of SEL) with (SUB1 (fetch WBOTTOM of TEXTOBJ]
                                                             (* Make sure it thinks the old selection is off-screen 
							     for now)
	      [AND (fetch LN of SEL)
		   (replace YBOT of (fetch LN of SEL) with (SUB1 (fetch WBOTTOM of TEXTOBJ]
	      (SETQ LINE (\TEDIT.FIND.FIRST.LINE TEXTOBJ WHEIGHT (IMAX 1
								       (IMIN CH#
									     (fetch TEXTLEN
										of TEXTOBJ)))
						 WINDOW))    (* Find the first line to go in the window)
	      (replace YBOT of LINE with (IDIFFERENCE WHEIGHT (fetch LHEIGHT of LINE)))
                                                             (* Set it up as the top line.)
	      (replace YBASE of LINE with (IPLUS (fetch YBOT of LINE)
						 (fetch DESCENT of LINE)))
	      (\DISPLAYLINE TEXTOBJ LINE WINDOW)
	      (\FILLWINDOW (fetch YBOT of LINE)
			   LINE TEXTOBJ NIL WINDOW)          (* And fill out the window from there.)
	      (\FIXSEL SEL TEXTOBJ)
	      (\TEDIT.SET.WINDOW.EXTENT TEXTOBJ WINDOW])

(\SETCARET
  [LAMBDA (X Y DS TEXTOBJ)                                   (* jds "21-Aug-84 12:16")
    (PROG NIL
          [COND
	    ((AND (ILESSP Y (fetch WTOP of TEXTOBJ))
		  (IGEQ Y (fetch WBOTTOM of TEXTOBJ))
		  (NOT (fetch TXTREADONLY of TEXTOBJ)))
	      (MOVETO X Y DS)
	      (\EDIT.DOWNCARET (fetch CARET of TEXTOBJ]      (* Only put down the caret the line it points to is 
							     on-screen)
      ])
)
(DECLARE: EVAL@COMPILE DONTCOPY 
[DECLARE: EVAL@COMPILE 

(DATATYPE TEDITCARET (TCNOWTIME                              (* Used to hold the current time, when checking to see 
							     if a transition is due)
				TCTHENTIME                   (* Time when the next transition is to take place)
				TCFORCEDDOWN                 (* TCFORCEDOWN = T means (Make the caret visible at the
							     next call to \EDIT.FLIPCARET.))
				TCUP                         (* TCUP = T => The caret is NOT VISIBLE.
							     Used to track the current state of the caret)
				TCCARETDS                    (* The display stream that the caret appears in)
				TCCURSORBM                   (* The CURSOR representing the caret)
				TCCARETRATE                  (* # of MSEC between caret up/down transitions)
				TCFORCEUP                    (* T => The caret is not allowed to become visible.
							     Used to keep the caret up during screen updates)
				TCCARETX                     (* X position in the window that the caret appears at)
				TCCARETY                     (* Y position in the window where the caret appears)
				)
		     TCNOWTIME ←(CREATECELL \FIXP)
		     TCTHENTIME ←(CREATECELL \FIXP)
		     TCCURSORBM ← BXCARET TCCARETRATE ← \CARETRATE TCUP ← T)
]
(/DECLAREDATATYPE (QUOTE TEDITCARET)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER 
				  POINTER)))
)



(* Menu interfacing)

(DEFINEQ

(TEDIT.ADD.MENUITEM
  [LAMBDA (MENU ITEM)                                        (* jds " 9-AUG-83 09:55")
                                                             (* Adds ITEM to the MENU, and updates all the stuff.)
    (PROG (OLDITM)
          (COND
	    ((MEMBER ITEM (fetch ITEMS of MENU))             (* Do nothing--it's already in the menu)
	      )
	    ([AND (LISTP ITEM)
		  (SETQ OLDITM (SASSOC (CAR ITEM)
				       (fetch ITEMS of MENU]
                                                             (* The menu item exists. Make sure the thing behind it 
							     is right.)
	      (RPLACD OLDITM (CDR ITEM)))
	    (T                                               (* It isn't in the menu, so go ahead and add it.)
	       (replace ITEMS of MENU with (NCONC1 (fetch ITEMS of MENU)
						   ITEM))
	       (COND
		 ((EQ (fetch MENUCOLUMNS of MENU)
		      1)                                     (* If there is only one column, force a re-figuring of 
							     the number of rows)
		   (replace MENUROWS of MENU with NIL))
		 ((EQ (fetch MENUROWS of MENU)
		      1)                                     (* There's only one row, so recompute # of columns.)
		   (replace MENUCOLUMNS of MENU with NIL)))
	       (replace ITEMWIDTH of MENU with 10000)
	       (replace ITEMHEIGHT of MENU with 10000)
	       (replace IMAGE of MENU with NIL)              (* Force it to create a new menu image.)
	       (UPDATE/MENU/IMAGE MENU])

(TEDIT.DEFAULT.MENUFN
  [LAMBDA (W)                                                (* jds "28-Nov-84 16:30")
                                                             (* Default User Fn for editor windows--displays a menu 
							     of items & acts on the commands received.)
    (PROG ((TEXTOBJ (WINDOWPROP W (QUOTE TEXTOBJ)))
	   (WMENU (WINDOWPROP W (QUOTE TEDIT.MENU)))
	   THISMENU CH OFILE OCURSOR PCTB LINES SEL ITEM)
          (COND
	    ((EQ (fetch EDITOPACTIVE of TEXTOBJ)
		 T)
	      (TEDIT.PROMPTPRINT TEXTOBJ "Edit operation in progress; please wait." T)
	      (RETURN))
	    ((fetch EDITOPACTIVE of TEXTOBJ)
	      (TEDIT.PROMPTPRINT TEXTOBJ (CONCAT (fetch EDITOPACTIVE of TEXTOBJ)
						 " in progress; please wait.")
				 T)
	      (RETURN)))
          (SETQ PCTB (fetch PCTB of TEXTOBJ))
          (SETQ THISMENU (COND
	      (WMENU)
	      ((SETQ WMENU (WINDOWPROP W (QUOTE TEDIT.MENU.COMMANDS)))
		(PROG1 (SETQ WMENU (\TEDIT.CREATEMENU WMENU))
		       (WINDOWPROP W (QUOTE TEDIT.MENU)
				   WMENU)))
	      (TEDIT.DEFAULT.MENU)))
          (SETQ ITEM (MENU THISMENU))
          (ERSETQ (RESETLST [RESETSAVE (\TEDIT.MARKACTIVE TEXTOBJ)
				       (QUOTE (AND (\TEDIT.MARKINACTIVE OLDVALUE]
			    (replace EDITOPACTIVE of TEXTOBJ with (OR (CAR ITEM)
								      T))
                                                             (* So we ca ntell the guy WHAT op is active.)
			    (SELECTQ (CAR ITEM)
				     (Put (TEDIT.PUT TEXTOBJ))
				     (Plain-Text (PROG (OCLEAR (TEXTPROP TEXTOBJ (QUOTE CLEARPUT)))
						       (TEXTPROP TEXTOBJ (QUOTE CLEARPUT)
								 T)
						       (TEDIT.PUT TEXTOBJ)
						       (TEXTPROP TEXTOBJ (QUOTE CLEARPUT)
								 OCLEAR)))
				     (Get                    (* Get a new file (overwriting the one being edited.))
					  (TEDIT.GET TEXTOBJ))
				     (Unformatted% Get (PROG (OCLEAR (TEXTPROP TEXTOBJ (QUOTE 
											 CLEARGET)))
							     (TEXTPROP TEXTOBJ (QUOTE CLEARGET)
								       T)
							     (TEDIT.GET TEXTOBJ)
							     (TEXTPROP TEXTOBJ (QUOTE CLEARGET)
								       OCLEAR)))
				     (Include                (* Insert a file where the caret is)
					      (TEDIT.INCLUDE TEXTOBJ))
				     (Quit                   (* Stop this session.)
					   (\TEDIT.QUIT W))
				     [Substitute             (* Search-and-replace)
						 (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
							   (TEDIT.SUBSTITUTE (fetch STREAMHINT
										of TEXTOBJ]
				     (Find                   (* Case sensitive search, with * and # wildcards)
					   [SETQ OFILE (TEDIT.GETINPUT TEXTOBJ "Text to find: "
								       (WINDOWPROP W (QUOTE 
									   TEDIT.LAST.FIND.STRING))
								       (CHARCODE (EOL LF ESC]
					   [COND
					     (OFILE (SETQ SEL (fetch SEL of TEXTOBJ))
						    (\SHOWSEL SEL NIL NIL)
						    (TEDIT.PROMPTPRINT TEXTOBJ "Searching..." T)
						    (SETQ CH (TEDIT.FIND TEXTOBJ (MKSTRING OFILE)
									 NIL NIL T))
						    (COND
						      (CH    (* We found the target text.)
							  (TEDIT.PROMPTPRINT TEXTOBJ "Done.")
							  (replace CH# of SEL with (CAR CH))
                                                             (* Set up SELECTION to be the found text)
							  (replace CHLIM of SEL with (CADR CH))
							  [replace DCH of SEL
							     with (ADD1 (IDIFFERENCE (CADR CH)
										     (CAR CH]
							  (replace POINT of SEL with (QUOTE RIGHT))
							  (replace CARETLOOKS of TEXTOBJ
							     with (\TEDIT.GET.INSERT.CHARLOOKS 
											  TEXTOBJ SEL)
								   )
							  (TEDIT.RESET.EXTEND.PENDING.DELETE SEL)
                                                             (* And never pending a deletion.)
							  (\FIXSEL SEL TEXTOBJ)
							  (TEDIT.NORMALIZECARET TEXTOBJ)
							  (\SHOWSEL SEL NIL T)
							  (WINDOWPROP W (QUOTE TEDIT.LAST.FIND.STRING)
								      OFILE)
                                                             (* And get it into the window)
							  )
						      (T (TEDIT.PROMPTPRINT TEXTOBJ "(not found)")
							 (\SHOWSEL SEL NIL T]
					   (replace \INSERTNEXTCH of TEXTOBJ with -1))
				     (Looks                  (* He wants to set the font for the current selection)
					    (\TEDIT.LOOKS TEXTOBJ))
				     (Hardcopy               (* Print this document)
					       (TEDIT.HARDCOPY TEXTOBJ))
				     (Press% File            (* Print this document)
						  (TEDIT.HCPYFILE TEXTOBJ))
				     (Expanded% Menu (\TEDIT.EXPANDED.MENU TEXTOBJ))
				     (Character% Looks (\TEDIT.EXPANDEDCHARLOOKS.MENU TEXTOBJ))
				     (Paragraph% Formatting (\TEDIT.EXPANDEDPARA.MENU TEXTOBJ))
				     (Page% Layout (\TEXTMENU.START (COPYTEXTSTREAM 
									  TEDIT.EXPANDED.PAGEMENU T)
								    (\TEDIT.PRIMARYW TEXTOBJ)
								    "Page Layout Menu" 150))
				     (AND (CAR ITEM)
					  (APPLY* (CAR ITEM)
						  (fetch STREAMHINT of TEXTOBJ])

(TEDIT.REMOVE.MENUITEM
  [LAMBDA (MENU ITEM)                                        (* gbn "26-Apr-84 04:06")
    (PROG (ITEMLIST)
          [COND
	    ((OR (LITATOM ITEM)
		 (STRINGP ITEM))
	      (for X in (fetch ITEMS of MENU) do (COND
						   ((AND (LISTP X)
							 (EQUAL (CAR X)
								ITEM))
						     (RETURN (SETQ ITEM X]
          (RETURN (COND
		    ((MEMBER ITEM (SETQ ITEMLIST (fetch ITEMS of MENU)))
		      (replace ITEMS of MENU with (REMOVE ITEM ITEMLIST))
		      (replace MENUCOLUMNS of MENU with NIL)
		      (replace MENUROWS of MENU with NIL)
		      (UPDATE/MENU/IMAGE MENU))
		    (T NIL])

(\TEDIT.CREATEMENU
  [LAMBDA (ITEMS)                                            (* jds " 3-AUG-83 10:23")
                                                             (* Create a TEdit command menu, given a list of menu 
							     items.)
    (create MENU
	    ITEMS ← ITEMS
	    CENTERFLG ← T
	    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
				  10
				  (QUOTE BOLD))
	    WHENHELDFN ←(QUOTE \TEDIT.MENU.WHENHELDFN)
	    WHENSELECTEDFN ←(QUOTE \TEDIT.MENU.WHENSELECTEDFN])

(\TEDIT.MENU.WHENHELDFN
  [LAMBDA (ITEM MENU BUTTON)                                 (* jds "10-Apr-84 15:14")
    (COND
      ((ATOM ITEM)
	(CLRPROMPT)
	(PROMPTPRINT (SELECTQ ITEM
			      (Put "Sends the document to a file")
			      (Get "Gets a new file as the document to edit.")
			      (Looks "Changes the font/size/etc. of characters")
			      (Find "Searches for a string")
			      (Quit "Ends the edit session")
			      (Hardcopy "Formats and sends the file to a printer.")
			      (Press% File "Creates a PRESS or INTERPRESS file of the document.")
			      "")))
      (T (DEFAULTMENUHELDFN ITEM])

(\TEDIT.MENU.WHENSELECTEDFN
  [LAMBDA (ITEM MENU BUTTON)                                 (* jds "28-APR-83 18:09")
                                                             (* A Selection fn for preserving the button pressed, for
							     special handling in PUT, e.g.)
    (CONS (DEFAULTWHENSELECTEDFN ITEM MENU BUTTON)
	  BUTTON])
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDIT.DEFAULT.MENU)
)
(DECLARE: DONTEVAL@LOAD DOCOPY 

(RPAQ? TEDIT.DEFAULT.MENU [\TEDIT.CREATEMENU (QUOTE ((Put (QUOTE Put)
							  NIL
							  (SUBITEMS Plain-Text))
						     (Get (QUOTE Get)
							  NIL
							  (SUBITEMS Unformatted% Get))
						     Include Find Looks Substitute Quit Hardcopy 
						     Press% File (Expanded% Menu (QUOTE 
										   Expanded% Menu)
										 NIL
										 (SUBITEMS 
										 Character% Looks 
									    Paragraph% Formatting 
										     Page% Layout])
)
(DECLARE: DONTEVAL@LOAD DOCOPY 
[OR (SASSOC (QUOTE TEdit)
	    BackgroundMenuCommands)
    (NCONC1 BackgroundMenuCommands (QUOTE (TEdit (QUOTE (TEDIT))
						 "Opens a TEdit window for use."]
(SETQ BackgroundMenu NIL)
)
(/DECLAREDATATYPE (QUOTE TEDITCARET)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER 
				  POINTER)))
(FILESLOAD IMAGEOBJ)



(* titled icon info)

(FILESLOAD ICONW)

(RPAQ TEDITICON (READBITMAP))
(87 95
"OOOOOOOOOOOOOOOOON@@@@@@"
"OOOOOOOOOOOOOOOOON@@@@@@"
"OOOOOOOOOOOOOOOOON@@@@@@"
"O@AA@@CH@@@H@H@@@G@@@@@@"
"OOOOOOOOOOOOOOOOOOH@@@@@"
"OH@MJH@@F@@@@@@@B@N@@@@@"
"OOOOOOOOOOOHGOOOOOOH@@@@"
"MO@@@@@F@@@OL@@C@@@OH@@@"
"LOOOOOOOOOOOOOOOOOOOON@@"
"LGOOOOOOOOOOOOOOOOOOON@@"
"LAOOOOOOOOOOOOOOOOOOON@@"
"L@CN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"LD@N@@@@@@@@@@@@@@@@@N@@"
"MLDN@@@@@@@@@@@@@@@@@N@@"
"LGBN@@@@@@@@@@@@@@@@@N@@"
"LDNN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"M@@N@@@@@@@@@@@@@@@@@N@@"
"LGBN@@@@@@@@@@@@@@@@@N@@"
"LDNN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"MH@N@@@@@@@@@@@@@@@@@N@@"
"MFBN@@@@@@@@@@@@@@@@@N@@"
"LELN@@@@@@@@@@@@@@@@@N@@"
"LDBN@@@@@@@@@@@@@@@@@N@@"
"LBBN@@@@@@@@@@@@@@@@@N@@"
"LALN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"MH@N@@@@@@@@@@@@@@@@@N@@"
"M@DN@@@@@@@@@@@@@@@@@N@@"
"MDBN@@@@@@@@@@@@@@@@@N@@"
"MCBN@@@@@@@@@@@@@@@@@N@@"
"MNBN@@@@@@@@@@@@@@@@@N@@"
"MCJN@@@@@@@@@@@@@@@@@N@@"
"L@FN@@@@@@@@@@@@@@@@@N@@"
"L@BN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"MH@N@@@@@@@@@@@@@@@@@N@@"
"M@@N@@@@@@@@@@@@@@@@@N@@"
"M@@N@@@@@@@@@@@@@@@@@N@@"
"ML@N@@@@@@@@@@@@@@@@@N@@"
"MCJN@@@@@@@@@@@@@@@@@N@@"
"M@FN@@@@@@@@@@@@@@@@@N@@"
"MHBN@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"L@@N@@@@@@@@@@@@@@@@@N@@"
"N@@N@@@@@@@@@@@@@@@@@N@@"
"G@@N@@@@@@@@@@@@@@@@@N@@"
"GH@N@@@@@@@@@@@@@@@@@N@@"
"CN@N@@@@@@@@@@@@@@@@@N@@"
"AOHN@@@@@@@@@@@@@@@@@N@@"
"@GOOOOOOOOOOOOOOOOOOON@@"
"@AOOOOOOOOOOOOOOOOOOON@@"
"@@COOOOOOOOOOOOOOOOOON@@")

(RPAQ TEDITMASK (READBITMAP))
(87 95
"OOOOOOOOOOOOOOOOON@@@@@@"
"OOOOOOOOOOOOOOOOON@@@@@@"
"OOOOOOOOOOOOOOOOON@@@@@@"
"OOOOOOOOOOOOOOOOOO@@@@@@"
"OOOOOOOOOOOOOOOOOOH@@@@@"
"OOOOOOOOOOOOOOOOOON@@@@@"
"OOOOOOOOOOOOOOOOOOOH@@@@"
"OOOOOOOOOOOOOOOOOOOOH@@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"OOOOOOOOOOOOOOOOOOOOON@@"
"GOOOOOOOOOOOOOOOOOOOON@@"
"GOOOOOOOOOOOOOOOOOOOON@@"
"COOOOOOOOOOOOOOOOOOOON@@"
"AOOOOOOOOOOOOOOOOOOOON@@"
"@GOOOOOOOOOOOOOOOOOOON@@"
"@AOOOOOOOOOOOOOOOOOOON@@"
"@@COOOOOOOOOOOOOOOOOON@@")

(RPAQ? TEDIT.ICON.FONT (FONTCREATE (QUOTE HELVETICA)
				   8
				   (QUOTE BOLD)))

(RPAQ? TEDIT.ICON.TITLE.REGION (CREATE REGION BOTTOM ← 4 LEFT ← 16 WIDTH ← 64 HEIGHT ← 77))

(RPAQ? TEDIT.TITLED.ICON.TEMPLATE (CREATE TITLEDICON ICON←TEDITICON MASK←TEDITMASK 
					  TITLEREG←TEDIT.ICON.TITLE.REGION))
(PUTPROPS TEDITWINDOW COPYRIGHT ("John Sybalsky & Xerox Corporation" 1983 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3462 47953 (TEDIT.CREATEW 3472 . 4646) (\TEDIT.CREATEW.FROM.REGION 4648 . 5589) (
TEDIT.CURSORMOVEDFN 5591 . 7672) (TEDIT.CURSOROUTFN 7674 . 8184) (TEDIT.GETINPUT 8186 . 9588) (
TEDIT.WINDOW.SETUP 9590 . 10907) (TEDIT.MINIMAL.WINDOW.SETUP 10909 . 15751) (\TEDIT.ACTIVE.WINDOWP 
15753 . 16157) (\TEDIT.BUTTONEVENTFN 16159 . 32435) (\TEDIT.EXPANDFN 32437 . 32731) (\TEDIT.MAINW 
32733 . 33836) (\TEDIT.PRIMARYW 33838 . 34791) (\TEDIT.CARET 34793 . 35128) (\TEDIT.COPYINSERTFN 35130
 . 35788) (\TEDIT.NEWREGIONFN 35790 . 37516) (\TEDIT.SET.WINDOW.EXTENT 37518 . 39902) (
\TEDIT.SHRINK.ICONCREATE 39904 . 41906) (\TEDIT.SHRINKFN 41908 . 42229) (\TEDIT.SPLITW 42231 . 43720) 
(\TEDIT.UNSPLITW 43722 . 44424) (\TEDIT.WINDOW.SETUP 44426 . 47574) (\SAFE.FIRST 47576 . 47951)) (
48730 50514 (TEDIT.PROMPTPRINT 48740 . 50512)) (50744 53748 (TEXTSTREAM.TITLE 50754 . 51325) (
\TEDIT.ORIGINAL.WINDOW.TITLE 51327 . 52495) (\TEDIT.WINDOW.TITLE 52497 . 53065) (\TEXTSTREAM.FILENAME 
53067 . 53746)) (53787 77238 (TEDIT.DEACTIVATE.WINDOW 53797 . 56809) (\TEDIT.REPAINTFN 56811 . 59335) 
(\TEDIT.RESHAPEFN 59337 . 62914) (\TEDIT.SET.WINDOW.TITLE 62916 . 63494) (\TEDIT.SCROLLFN 63496 . 
77236)) (77276 79329 (\TEDIT.PROCIDLEFN 77286 . 78550) (\TEDIT.PROCENTRYFN 78552 . 78882) (
\TEDIT.PROCEXITFN 78884 . 79327)) (79403 86040 (\EDIT.DOWNCARET 79413 . 79915) (\EDIT.FLIPCARET 79917
 . 81915) (TEDIT.FLASHCARET 81917 . 82342) (\EDIT.UPCARET 82344 . 82808) (TEDIT.NORMALIZECARET 82810
 . 85567) (\SETCARET 85569 . 86038)) (87539 96766 (TEDIT.ADD.MENUITEM 87549 . 89149) (
TEDIT.DEFAULT.MENUFN 89151 . 94597) (TEDIT.REMOVE.MENUITEM 94599 . 95288) (\TEDIT.CREATEMENU 95290 . 
95784) (\TEDIT.MENU.WHENHELDFN 95786 . 96408) (\TEDIT.MENU.WHENSELECTEDFN 96410 . 96764)))))
STOP