(FILECREATED "12-Mar-85 05:37:29" {IVY}<TEDIT>TEDITWINDOW.;51 114711 

      changes to:  (FNS TEDIT.DEACTIVATE.WINDOW)

      previous date: " 6-Mar-85 23:09:59" {IVY}<TEDIT>TEDITWINDOW.;50)


(* Copyright (c) 1983, 1984, 1985 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.WINDOW.SETUP TEDIT.MINIMAL.WINDOW.SETUP \TEDIT.ACTIVE.WINDOWP \TEDIT.BUTTONEVENTFN 
	     \TEDIT.EXPANDFN \TEDIT.MAINW \TEDIT.PRIMARYW \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 (* User-typein support)
	      (FNS TEDIT.GETINPUT \TEDIT.MAKEFILENAME))
	(COMS (* Attached Prompt window support.)
	      (FNS TEDIT.PROMPTPRINT TEDIT.PROMPTFLASH)
	      (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 \TEDIT.CARET)
	      (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
			(VARS (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 
										   Expanded% Menu 
										 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 " 7-Feb-85 13:56")
                                                             (* 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 (for LINES inside (fetch LINES of TEXTOBJ)
							   as WINDOW inside (fetch \WINDOW
									       of TEXTOBJ)
							   when (EQ W WINDOW) do (RETURN LINES))
							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.WINDOW.SETUP
  [LAMBDA (WINDOW TEXTOBJ TEXTSTREAM PROPS)                  (* jds "25-Feb-85 14:38")
                                                             (* 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))
          (WINDOWPROP WINDOW (QUOTE HARDCOPYFN)
		      (FUNCTION TEDIT.HARDCOPYFN))           (* Hook into the system standard hardcopy interface)
          (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 "11-Feb-85 00:49")
                                                             (* 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 (COND
					       [(LISTP (fetch CARET of TEXTOBJ))
						 (CAR (FLAST (fetch CARET of TEXTOBJ]
					       (T (fetch CARET of TEXTOBJ)))
	     with (WINDOWPROP WINDOW (QUOTE DSP)))           (* The displaystream for flashing the caret)
          (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 (WINDOWPROP WINDOW (QUOTE DSP)))
          (DSPRIGHTMARGIN 32767 DS)                          (* So we don't get spurious RETURNs printed out by the 
							     system)
          [replace \WINDOW of TEXTOBJ with (COND
					     ((LISTP (fetch \WINDOW of TEXTOBJ))
					       (NCONC1 (fetch \WINDOW of TEXTOBJ)
						       WINDOW))
					     (WINDOW (LIST WINDOW]
          (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]
                                                             (* A displaystream for changeing the image caches)
          (DSPCLIPPINGREGION (create REGION
				     LEFT ← 0
				     BOTTOM ← 0
				     WIDTH ← 100
				     HEIGHT ← 15)
			     (fetch DISPLAYCACHEDS of TEXTOBJ))
                                                             (* Remember its size, too.)
          [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)                                         (* jds "13-Feb-85 11:55")
                                                             (* 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                                  (* Otherwise, create a new process to handle the menu.)
			    (ADD.PROCESS (LIST USERFN (KWOTE W]
	    ((AND TEXTOBJ (NOT (fetch EDITOPACTIVE of TEXTOBJ)))
                                                             (* Usual case -- he's really selecting something.
							     And there's nothing else going on now.)
	      (TOTOPW W)                                     (* Move the editing window to the top, so he can select
							     wherever he wants.)
	      [for CARET inside (fetch CARET of TEXTOBJ) do (COND
							      ((NOT (fetch TCUP of CARET))
                                                             (* If the caret isn't up--off the screen, and hence 
							     invisible--turn if off.)
								(\EDIT.FLIPCARET CARET 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 (for CARET inside (fetch CARET of TEXTOBJ)
				      do (replace TCCURSORBM of CARET 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)))
			  ((fetch (SHIFTSTATE CTRL) of \SHIFTSTATE)
                                                             (* He's holding the control key down;
							     note the fact.)
			    (\SHOWSEL (fetch SEL of TEXTOBJ)
				      NIL NIL)
			    (SETQ GLOBALSEL TEDIT.DELETESELECTION)
			    [COND
			      ((fetch SET of (fetch DELETESEL of TEXTOBJ))
                                                             (* There's a pending delete selection.
							     Use it, and turn off the existing normal selection.)
				)
			      (T                             (* No existing delete selection.
							     Use the normal selection as a starting point.)
				 (\COPYSEL (fetch SEL of TEXTOBJ)
					   (fetch DELETESEL of TEXTOBJ]
			    (replace SET of (fetch SEL of TEXTOBJ) with NIL)
                                                             (* Remember to turn off the normal selection, since 
							     we'll be moving it to a new spot after the deletion.)
			    (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)
			      [COND
				((ZEROP (LOGAND LASTMOUSEBUTTONS 7))
                                                             (* No mouse buttons are down;
							     don't try anything.)
				  )
				((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)
                                                             (* He's holding down both ctrl and shift -- do a move.)
				      (SETQ SELOPERATION (QUOTE MOVE)))
				    (T                       (* Just the SHIFT key. It's a COPY)
				       (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 only the CTRL key -- mark the selection
							     for deletion.)
				  (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.)
			(for CARET inside (fetch CARET of TEXTOBJ)
			   do (OR (fetch TCUP of CARET)
				  (\EDIT.FLIPCARET CARET 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.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 WINDOWS)                                  (* jds " 8-Feb-85 18:37")
                                                             (* Set the window's EXTENT property according to 1st 
							     and last char on screen.)
    (for WINDOW inside WINDOWS do (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 "15-Feb-85 09:29")
                                                             (* 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]
    (WINDOWPROP W (QUOTE ICON])

(\TEDIT.SHRINKFN
  [LAMBDA (W ICON ICONW)                                     (* jds "14-Dec-84 08:56")
                                                             (* hands off the tty to the exec process)
    (COND
      ((AND (EQ (WINDOWPROP W (QUOTE PROCESS))
		(TTY.PROCESS)))
	(TTY.PROCESS T)                                      (* per bvm, this means 
							     "Hand the TTY to some other process". It tries EXEC 
							     first; if that's not found, it hands it to MOUSE.)
	])

(\TEDIT.SPLITW
  [LAMBDA (WINDOW Y)                                         (* jds "19-Jan-85 17:01")
                                                             (* SPLIT WINDOW W AT W-RELATIVE Y.)
    (PROG ((WREG (WINDOWPROP WINDOW (QUOTE REGION)))
	   (TEXTOBJ (WINDOWPROP WINDOW (QUOTE TEXTOBJ)))
	   NEWW OLDW OTITLE OLDCARET NEWCARET OLINES)
          (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))
          (SETQ OLDCARET (fetch CARET of TEXTOBJ))
          (SETQ NEWCARET (create TEDITCARET
				 TCCARETDS ← NEWW
				 TCFORCEUP ← T))
          [replace CARET of TEXTOBJ with (COND
					   ((LISTP OLDCARET)
					     (NCONC1 OLDCARET NEWCARET))
					   (T (LIST OLDCARET NEWCARET]
          (for SEL in (LIST (fetch SEL of TEXTOBJ)
			    (fetch SCRATCHSEL of TEXTOBJ)
			    (fetch MOVESEL of TEXTOBJ)
			    (fetch SHIFTEDSEL of TEXTOBJ)
			    (fetch DELETESEL of TEXTOBJ))
	     do (replace L1 of SEL with (NCONC1 (fetch L1 of SEL)
						NIL))
		(replace LN of SEL with (NCONC1 (fetch LN of SEL)
						NIL)))
          (SETQ OLINES (fetch LINES of TEXTOBJ))
          (\TEDIT.WINDOW.SETUP NEWW TEXTOBJ (fetch STREAMHINT of TEXTOBJ)
			       (APPEND (QUOTE (NOTITLE T PROMPTWINDOW DON'T))
				       (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]
          [replace LINES of TEXTOBJ with (COND
					   ((LISTP OLINES)
					     (NCONC1 OLINES (fetch LINES of TEXTOBJ)))
					   (T (LIST OLINES (fetch LINES of TEXTOBJ]
          (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 "19-Feb-85 10:49")
                                                             (* Set up the window and TEXTOBJ so they correspond, 
							     and the window is a TEDIT window.)
    (PROG ((ICONFN (WINDOWPROP WINDOW (QUOTE ICONFN)))
	   TEDITPROMPTWINDOW)
          (OR WINDOW (\ILLEGAL.ARG WINDOW))
          (TEDIT.WINDOW.SETUP WINDOW TEXTOBJ TEXTSTREAM PROPS)
                                                             (* Do the general-purpose window setting up--the kind 
							     that every user will want. Then do the stuff that a 
							     TEdit session needs as well.)
          (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]   (* Only put our menu function on the window if the 
							     originator didn't supply one.)
          (WINDOWADDPROP WINDOW (QUOTE CLOSEFN)
			 (FUNCTION TEDIT.DEACTIVATE.WINDOW)
			 T)                                  (* To clean up when the window is closed)
          (WINDOWPROP WINDOW (QUOTE WINDOWENTRYFN)
		      (FUNCTION \TEDIT.PROCIDLEFN))          (* For grabbing the TTY when the mouse clicks in the 
							     window)
          (OR ICONFN (WINDOWPROP WINDOW (QUOTE ICONFN)
				 (FUNCTION \TEDIT.SHRINK.ICONCREATE)))
                                                             (* Only set up to create a shrink icon if nobody else 
							     has.)
          (WINDOWADDPROP WINDOW (QUOTE SHRINKFN)
			 (FUNCTION \TEDIT.SHRINKFN))         (* But always give up control of the keyboard on 
							     shrinking.)
          (WINDOWADDPROP WINDOW (QUOTE EXPANDFN)
			 (FUNCTION \TEDIT.EXPANDFN))         (* And grab it back on expansion)
          (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)                                 (* And remember that this is a TEdit-supplied prompt 
							     window)
	      ])

(\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)
)



(* User-typein support)

(DEFINEQ

(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.MAKEFILENAME
  [LAMBDA (STRING)                                           (* jds " 8-Feb-85 11:25")
                                                             (* Takes a string, removes leading and trailing spaces,
							     and converts it to an ATOM.)
    (PROG ((FIRSTNONSPACE (STRPOSL (QUOTE (% ))
				   STRING NIL T))
	   (LASTNONSPACE (STRPOSL (QUOTE (% ))
				  STRING NIL T T)))
          (COND
	    ((AND FIRSTNONSPACE LASTNONSPACE)
	      (RETURN (MKATOM (SUBSTRING STRING FIRSTNONSPACE LASTNONSPACE])
)



(* Attached Prompt window support.)

(DEFINEQ

(TEDIT.PROMPTPRINT
  [LAMBDA (TEXTSTREAM MSG CLEAR?)                            (* jds " 5-Mar-85 17:07")
                                                             (* 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)))
                                                             (* Find the TEXTOBJ for the main edit window, and use 
							     ITS prompting window.)
	      (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)))
		    (PRIN1 MSG WINDOW))
	    (T                                               (* Failing all else, use PROMPTWINDOW.)
	       (FRESHLINE PROMPTWINDOW)
	       (printout PROMPTWINDOW MSG])

(TEDIT.PROMPTFLASH
  [LAMBDA (TEXTSTREAM)                                       (* jds " 8-Feb-85 11:01")
                                                             (* Flash the TEdit prompt window, or the global 
							     promptwindow, if TEdit has none.)
    (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)))
                                                             (* Find the TEXTOBJ for the main edit window, and use 
							     ITS prompting window.)
	      (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)
          (FLASHWINDOW (OR WINDOW PROMPTWINDOW)
		       2])
)

(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)                                       (* jds "15-Jan-85 13:11")

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


    (PROG ((TEXTOBJ (TEXTOBJ TEXTSTREAM))
	   OFILE)
          [COND
	    ((type? STREAM (fetch TXTFILE of TEXTOBJ))
	      [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 "12-Mar-85 04:02")
                                                             (* 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
		((AND (\TEDIT.WINDOW.TITLE TEXTOBJ)
		      (OPENWP (fetch PROMPTWINDOW of TEXTOBJ))
		      (OPENWP W))
		  (\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.)
		    (replace EDITFINISHEDFLG of (TEXTOBJ MENUW) with T)
		    (GIVE.TTY.PROCESS MENUW)
		    (DISMISS 300))
	      (GIVE.TTY.PROCESS W)
	      (DISMISS 300)
	      [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 " 5-Mar-85 12:54")
                                                             (* 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                                     (* Run thru the lines, until we hit the first one that 
							     is below the top of the edit window)
			 (COND
			   ((ILESSP (fetch YBOT of TOPLINE)
				    WHEIGHT)
			     (RETURN))
			   (T (SETQ PREVLINE TOPLINE)
			      (SETQ TOPLINE (fetch NEXTLINE of TOPLINE]
		   [COND
		     ((AND (EQ PREVLINE LINES)
			   (OR (NOT (fetch NEXTLINE of PREVLINE))
			       (IGREATERP (fetch CHAR1 of (fetch NEXTLINE of PREVLINE))
					  1)))               (* There's nothing between us and start of file that's 
							     formatted; start by making some.)
		       (SETQ PREVLINE (\BACKFORMAT LINES TEXTOBJ]
		   (SETQ THEIGHT 0)                          (* Accumulates the heights of the lines we've backed 
							     over. When this exceeds the scrolling distance, we've 
							     found the line.)
		   (bind (FIRSTTIME ← T) while (OR FIRSTTIME (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
			   ((OR (NOT PREVLINE)
				(ILESSP (fetch CHAR1 of PREVLINE)
					1))                  (* We need to format some lines above where we are -- 
							     go do it.)
			     (SETQ PREVLINE (\BACKFORMAT LINES TEXTOBJ]
			 (SETQ FIRSTTIME NIL))
		   [COND
		     ([OR (EQ TOPLINE (fetch NEXTLINE of PREVLINE))
			  (EQ TOPLINE (fetch NEXTLINE of (fetch NEXTLINE of PREVLINE]
                                                             (* Always move at least one line backward.
							     So if we're about to move no lines, force a single 
							     line.)
		       )
		     ((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]
		   [COND
		     ((NEQ TOPLINE (fetch NEXTLINE 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 [for LINE inside (fetch L1 of SEL) when LINE
		      do (replace YBOT of LINE with (SUB1 (fetch WBOTTOM of TEXTOBJ]
                                                             (* Make sure it thinks the old selection is off-screen 
							     for now)
		   [for LINE inside (fetch LN of SEL) when LINE
		      do (replace YBOT of LINE 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 "27-Feb-85 11:52")
                                                             (* Put the caret down -- i.e., MAKE IT VISIBLE -- as 
							     fast as possible)
    (replace TCFORCEUP of CARET with NIL)                    (* Turn off any enforced UPness)
    (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 "19-Jan-85 17:05")
                                                             (* Unless the caret is constrained to be INVISIBLE, 
							     give it a chance to flash.)
    (for CARET inside CARET do (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 " 6-Mar-85 22:09")
                                                             (* Scroll the text window so that the caret is visible 
							     in it.)
    (SETQ TEXTOBJ (TEXTOBJ TEXTOBJ))
    (PROG ((SEL (OR SEL (fetch SEL of TEXTOBJ)))
	   (WINDOW (fetch SELWINDOW of TEXTOBJ))
	   WHEIGHT 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# (SUB1 (fetch CHLIM of SEL)))
			  (SETQ Y (fetch YLIM of SEL)))
		   NIL)
          (COND
	    ((AND (OR (IGEQ Y WHEIGHT)
		      (ILESSP Y (fetch WBOTTOM of TEXTOBJ)))
		  (NOT (fetch TXTNEEDSUPDATE of TEXTOBJ)))   (* The caret is off-screen. Scroll to get it on)
	      [for LINE inside (fetch L1 of SEL) when LINE
		 do (replace YBOT of LINE with (SUB1 (fetch WBOTTOM of TEXTOBJ]
                                                             (* Make sure it thinks the old selection is off-screen 
							     for now)
	      [for LINE inside (fetch LN of SEL) when LINE
		 do (replace YBOT of LINE 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 CARET)                             (* jds "19-Jan-85 16:26")
    (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 CARET)))                      (* Only put down the caret the line it points to is 
							     on-screen)
      ])

(\TEDIT.CARET
  [LAMBDA (CARETS)                                           (* jds "19-Jan-85 17:04")
                                                             (* Reset the caret to its normal state state, from the 
							     selection caret)
    (FOR CARET INSIDE CARETS DO (replace (TEDITCARET TCCURSORBM) of CARET with BXCARET])
)
(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 " 6-Mar-85 21:15")
                                                             (* 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 NIL NIL (TEXTPROP TEXTOBJ (QUOTE 
											 CLEARPUT]
				     (Plain-Text (TEDIT.PUT TEXTOBJ NIL NIL T))
				     [Get                    (* Get a new file (overwriting the one being edited.))
					  (TEDIT.GET TEXTOBJ NIL (TEXTPROP TEXTOBJ (QUOTE CLEARGET]
				     (Unformatted% Get (TEDIT.GET TEXTOBJ NIL T))
				     (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 (ADD1 (CADR CH)))
							  (replace DCH of SEL
							     with (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 \INSERTPCVALID of TEXTOBJ with NIL)
                                                             (* Doing a FIND invalidates the insertion-piece cahce? 
							     I don't understand this. Check it.)
					   )
				     (Looks                  (* He wants to set the font for the current selection)
					    (\TEDIT.LOOKS TEXTOBJ))
				     (Hardcopy               (* Print this document)
					       (TEDIT.HARDCOPY TEXTOBJ))
				     (Press% File            (* Make a hardcopy file with this document in it.)
						  (TEDIT.HCPYFILE TEXTOBJ))
				     (Expanded% Menu         (* Open the expanded operations menu.)
						     (\TEDIT.EXPANDED.MENU TEXTOBJ))
				     (Character% Looks       (* Open the menu for setting character looks)
						       (\TEDIT.EXPANDEDCHARLOOKS.MENU TEXTOBJ))
				     (Paragraph% Formatting 
                                                             (* Open the paragraph formatting menu)
							    (\TEDIT.EXPANDEDPARA.MENU TEXTOBJ))
				     (Page% Layout           (* Open the page-layout menu)
						   (\TEXTMENU.START (COPYTEXTSTREAM 
									  TEDIT.EXPANDED.PAGEMENU T)
								    (\TEDIT.PRIMARYW TEXTOBJ)
								    "Page Layout Menu" 150))
				     (COND
				       ((CAR ITEM)           (* This is a user-supplied entry.
							     Get the function, and apply it to the TEXTSTREAM for 
							     him)
					 (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 
										   Expanded% Menu 
										 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 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3665 52045 (TEDIT.CREATEW 3675 . 4849) (\TEDIT.CREATEW.FROM.REGION 4851 . 5792) (
TEDIT.CURSORMOVEDFN 5794 . 8170) (TEDIT.CURSOROUTFN 8172 . 8722) (TEDIT.WINDOW.SETUP 8724 . 10283) (
TEDIT.MINIMAL.WINDOW.SETUP 10285 . 15930) (\TEDIT.ACTIVE.WINDOWP 15932 . 16412) (\TEDIT.BUTTONEVENTFN 
16414 . 34154) (\TEDIT.EXPANDFN 34156 . 34450) (\TEDIT.MAINW 34452 . 35555) (\TEDIT.PRIMARYW 35557 . 
36555) (\TEDIT.COPYINSERTFN 36557 . 37267) (\TEDIT.NEWREGIONFN 37269 . 38995) (
\TEDIT.SET.WINDOW.EXTENT 38997 . 41951) (\TEDIT.SHRINK.ICONCREATE 41953 . 43994) (\TEDIT.SHRINKFN 
43996 . 44539) (\TEDIT.SPLITW 44541 . 47288) (\TEDIT.UNSPLITW 47290 . 47992) (\TEDIT.WINDOW.SETUP 
47994 . 51666) (\SAFE.FIRST 51668 . 52043)) (52810 54806 (TEDIT.GETINPUT 52820 . 54222) (
\TEDIT.MAKEFILENAME 54224 . 54804)) (54851 58333 (TEDIT.PROMPTPRINT 54861 . 56792) (TEDIT.PROMPTFLASH 
56794 . 58331)) (58563 61602 (TEXTSTREAM.TITLE 58573 . 59179) (\TEDIT.ORIGINAL.WINDOW.TITLE 59181 . 
60349) (\TEDIT.WINDOW.TITLE 60351 . 60919) (\TEXTSTREAM.FILENAME 60921 . 61600)) (61641 87503 (
TEDIT.DEACTIVATE.WINDOW 61651 . 65158) (\TEDIT.REPAINTFN 65160 . 67684) (\TEDIT.RESHAPEFN 67686 . 
71263) (\TEDIT.SET.WINDOW.TITLE 71265 . 71851) (\TEDIT.SCROLLFN 71853 . 87501)) (87541 89594 (
\TEDIT.PROCIDLEFN 87551 . 88815) (\TEDIT.PROCENTRYFN 88817 . 89147) (\TEDIT.PROCEXITFN 89149 . 89592))
 (89668 97012 (\EDIT.DOWNCARET 89678 . 90298) (\EDIT.FLIPCARET 90300 . 92298) (TEDIT.FLASHCARET 92300
 . 92822) (\EDIT.UPCARET 92824 . 93288) (TEDIT.NORMALIZECARET 93290 . 96142) (\SETCARET 96144 . 96633)
 (\TEDIT.CARET 96635 . 97010)) (98511 108080 (TEDIT.ADD.MENUITEM 98521 . 100121) (TEDIT.DEFAULT.MENUFN
 100123 . 105911) (TEDIT.REMOVE.MENUITEM 105913 . 106602) (\TEDIT.CREATEMENU 106604 . 107098) (
\TEDIT.MENU.WHENHELDFN 107100 . 107722) (\TEDIT.MENU.WHENSELECTEDFN 107724 . 108078)))))
STOP