(FILECREATED " 8-Oct-85 23:13:01" {QV}<NOTECARDS>RELEASE1.2I>NCTEXTSUBSTANCE.;18 28893  

      changes to:  (VARS NCTEXTSUBSTANCECOMS)
		   (FNS NC.ResetTEditProcess NC.ResetTEdit NC.BringUpTEditCard NC.MakeTEditPropsList)

      previous date: " 8-Oct-85 15:57:51" {QV}<NOTECARDS>RELEASE1.2I>NCTEXTSUBSTANCE.;15)


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

(PRETTYCOMPRINT NCTEXTSUBSTANCECOMS)

(RPAQQ NCTEXTSUBSTANCECOMS ((E (SETQ NC.SystemDate (DATE))
			       (PUTPROP (QUOTE NC.SystemDate)
					(QUOTE NewestFile)
					(ROOTFILENAME (FULLNAME (OUTPUT)))))
	(* * Stuff for the TEXT substance type.)
	(FILES NCTYPESMECH)
	(GLOBALVARS TEDIT.DEFAULT.MENU NC.TEditPasswordDividedBy100 NC.DefaultFont 
		    NC.DeletedLinkImageObject NC.CardTypes NC.AnnoFlg)
	(FNS NC.BringUpTEditCard NC.CollectReferencesInText NC.MakeTEditLeftMenu 
	     NC.MakeTEditMiddleMenu NC.MarkTextDirty NC.ResetTEdit NC.ResetTEditProcess 
	     NC.TEditBasedP NC.TEditCloseFn NC.TEditMenuFn NC.TEditQuitFn NC.TextCopySubstance 
	     NC.TextDirtyP NC.\TEDIT.LOOKS NC.\TEDIT.QUIT NC.TextCardShrinkFn)
	(VARS (TEDIT.DEFAULT.PROPS (CONS (QUOTE SLOWUPDATE)
					 (CONS (QUOTE T)
					       TEDIT.DEFAULT.PROPS)))
	      (NC.TEditPasswordDividedBy100 314))
	(* * This stuff supports the "push-copy" method of copying links in NC)
	(FNS NC.TranslateWindowPositionToTEditPosition NC.InsertLinkInTextWindow)
	(* * New FNS for fixing TEdit bugs in intermezzo.)
	(GLOBALVARS NC.ExternalPutLinkIconImageFns)
	(FNS NC.IDFromTextStream NC.TEditPutFn NC.TEditPutFnAuxiliary NC.TEditGetFn 
	     NC.MakeTEditPropsList)
	(* * Add Text substance type to list)
	(FNS NC.AddTextSubstance)
	(P (NC.AddTextSubstance))))
(* * Stuff for the TEXT substance type.)

(FILESLOAD NCTYPESMECH)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDIT.DEFAULT.MENU NC.TEditPasswordDividedBy100 NC.DefaultFont NC.DeletedLinkImageObject 
	    NC.CardTypes NC.AnnoFlg)
)
(DEFINEQ

(NC.BringUpTEditCard
  (LAMBDA (ID TextStream Region/Position)                    (* rht: "10-Sep-85 17:17")
                                                             (* Bring up a TEdit window for Card ID whose text 
							     stream is TextStream in Region specified by 
							     Region/Position or by the user.)

          (* * rht 9/10/85: Fixed call to NC.MakeTEditPropsList so prompt window gets fixed up before card is brought up.)


    (PROG (Region TEditWindow TEditProcess Title TextStreamDirtyFlg)
          (COND
	    ((AND (SETQ TEditWindow (WINDOW.FROM.TEDIT.THING TextStream))
		  (SETQ TEditProcess (WINDOWPROP TEditWindow (QUOTE PROCESS))))
	      (TOTOPW TEditWindow)
	      (RPTQ 2 (FLASHW TEditWindow))
	      (TTY.PROCESS TEditProcess)
	      (RETURN TEditWindow)))
          (SETQ Region (NC.DetermineDisplayRegion ID Region/Position))
          (SETQ Title (NC.FetchTitle ID))
          (SETQ TEditWindow (CREATEW Region Title NIL T))
          (WINDOWADDPROP TEditWindow (QUOTE SHRINKFN)
			 (FUNCTION NC.TextCardShrinkFn))
          (WINDOWPROP TEditWindow (QUOTE NoteCardsLeftButtonMenu)
		      (NC.MakeTEditLeftMenu (NC.FetchType ID)))
          (WINDOWPROP TEditWindow (QUOTE NoteCardsMiddleButtonMenu)
		      (NC.MakeTEditMiddleMenu))
          (SETQ TextStreamDirtyFlg (NC.CardDirtyP ID))
          (TEDIT TextStream TEditWindow NIL (NC.MakeTEditPropsList TEditWindow))
          (AND TextStreamDirtyFlg (NC.MarkCardDirty ID))
          (RETURN TEditWindow))))

(NC.CollectReferencesInText
  (LAMBDA (ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* fgh: "23-Oct-84 11:56")

          (* * Return a list of all links or link icons in text substance Substance. If CheckAndDeleteFlg, then delete any 
	  links found that are not valid links.)


    (PROG (ActualLink DirtyFlg Links (Substance (NC.FetchSubstance ID)))
          (SETQ Links (for ImageObjectDecriptor in (TEDIT.LIST.OF.OBJECTS (TEXTOBJ Substance)
									  (FUNCTION 
									    NC.LinkIconImageObjP))
			 when (PROG NIL
				    (SETQ ActualLink (NC.FetchLinkFromLinkIcon (CAR 
									     ImageObjectDecriptor)))
				    (COND
				      ((NULL CheckAndDeleteFlg)
                                                             (* No checking required)
					(RETURN T))
				      ((AND (LISTP CheckAndDeleteFlg)
					    (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ActualLink)
						   CheckAndDeleteFlg))
                                                             (* Already checked since ID cached on CheckAndDeleteFlg
							     list)
					(RETURN T))
				      ((NC.ValidLinkP ActualLink DatabaseStream)
                                                             (* Link is valid)
					(RETURN T))
				      (T                     (* Link is bad. Replace it with the DeletedLink image 
							     object.)
					 (create IMAGEOBJ
					    smashing (CAR ImageObjectDecriptor)
						     OBJECTDATUM ←(fetch (IMAGEOBJ OBJECTDATUM)
								     of NC.DeletedLinkImageObject)
						     IMAGEOBJPLIST ←(fetch (IMAGEOBJ IMAGEOBJPLIST)
								       of NC.DeletedLinkImageObject)
						     IMAGEOBJFNS ←(fetch (IMAGEOBJ IMAGEOBJFNS)
								     of NC.DeletedLinkImageObject))
					 (SETQ DirtyFlg T)
					 (RETURN NIL))))
			 collect (COND
				   ((AND ReturnLinkIconsFlg (NOT ReturnLocationsFlg))
				     (CAR ImageObjectDecriptor))
				   ((AND ReturnLinkIconsFlg ReturnLocationsFlg)
				     (CONS (CAR ImageObjectDecriptor)
					   (CADR ImageObjectDecriptor)))
				   ((AND (NOT ReturnLinkIconsFlg)
					 ReturnLocationsFlg)
				     (CONS ActualLink (CADR ImageObjectDecriptor)))
				   (T ActualLink))))
          (RETURN (CONS Links DirtyFlg)))))

(NC.MakeTEditLeftMenu
  (LAMBDA (NoteCardType)                                     (* rht: " 1-Oct-85 17:25")

          (* * Make the LeftButton TEdit menu appropriate for this type of text card. If menu doesn't exist, then make it.)



          (* * rht 8/1/84: Added a new menu item for the CONTENTS menu called Collect Children)



          (* * rht 9/17/84: (actually redoing earlier changes which got trashed) Added menu item for the CONTENTS menu called 
	  Make Document.)



          (* * rht 9/20/84: New menu item for TEXT menu called "Insert Spreadsheet".)



          (* * rht 9/25/84: Made MakeDocument also present in TEXT menu.)



          (* * rht 12/8/84: Now both fileboxes and notecards do filing via NC.AddParents. Also took out all the strange uses 
	  of NC.TEditMenus.)


    (\TEDIT.CREATEMENU (COND
			 ((NEQ NoteCardType (QUOTE FileBox))
			   (QUOTE ((Edit% Property% List (FUNCTION NC.EditProperties)
							 
					"Brings up an editor for the property list of this card.")
				    (Show% Links (FUNCTION NC.ShowPointers)
						 
					   "Brings up a list of the links to and from this card.")
				    (Title/Sources/FileBoxes (FUNCTION (LAMBDA (TextStream)
								 (NC.AssignTitle TextStream)
								 (NC.AssignSources TextStream)
								 (NC.AddParents TextStream)))
							     
		       "Do all of the operations necessary to file this note card in a file box."
							     (SUBITEMS (Assign% Title
									 (FUNCTION NC.AssignTitle)
									 
						       "Assigns a (new) title to this note card.")
								       (Designate% Sources
									 (FUNCTION NC.AssignSources)
									 
				       "Designate the source(s) of the information in this card.")
								       (File% in% FileBoxes
									 (FUNCTION NC.AddParents)
									 
						 "File this note card in one or more file boxes.")
								       (Unfile% from% FileBoxes
									 (FUNCTION NC.UnfileNoteCard)
									 
					   "Remove this card from one or more of its file boxes.")
								       (Delete% Source
									 (FUNCTION NC.DeleteSource)
									 
							"Delete one of the sources of this card.")))
				    (Insert% Link (FUNCTION NC.AddLinkToTextCard)
						  
		     "Insert a link to another card at the currently selected point in the text."
						  (SUBITEMS (Insert% Link (FUNCTION 
									    NC.AddLinkToTextCard)
									  
		     "Insert a link to another card at the currently selected point in the text.")
							    (Insert% Links (FUNCTION 
									    NC.AddLinksToTextCard)
									   
		       "Insert links to other cards at the currently selected point in the text.")
							    (Add% Global% Link
							      (FUNCTION NC.AddGlobalLinkToCard)
							      
						    "Add a global link emanating from this card.")
							    (Add% Global% Links
							      (FUNCTION NC.AddGlobalLinksToCard)
							      
						     "Add global links emanating from this card.")))
				    (Close% and% Save (FUNCTION NC.QuitCard)
						      
					  "Close this note card after saving it in the NoteFile."
						      (SUBITEMS (Close% and% Save
								  (FUNCTION NC.QuitCard)
								  
					  "Close this note card after saving it in the NoteFile.")
								(Close% w/o% Saving
								  (FUNCTION NC.QuitWithoutSaving)
								  
		      "Close this note card without saving any changes made since the last Save.")
								(Save% in% NoteFile
								  (FUNCTION NC.CardSaveFn)
								  
				       "Save this card in the NoteFile but don't close the card.")
								(Delete% Card (FUNCTION 
									       NC.DeleteNoteCards)
									      
						"Permenantly delete this card from the NoteFile.")))))
			   )
			 (T (QUOTE ((Edit% Property% List (FUNCTION NC.EditProperties)
							  
					"Brings up an editor for the property list of this card.")
				     (Show% Links (FUNCTION NC.ShowPointers)
						  
					   "Brings up a list of the links to and from this card.")
				     (File% in% FileBoxes (FUNCTION NC.AddParents)
							  "File this FileBox in new FileBox(es).")
				     (Add% Global% Link (FUNCTION NC.AddGlobalLinkToCard)
							
						 "Add a global link emanating from this FileBox."
							(SUBITEMS (Add% Global% Link
								    (FUNCTION NC.AddGlobalLinkToCard)
								    
						 "Add a global link emanating from this FileBox.")
								  (Add% Global% Links
								    (FUNCTION NC.AddGlobalLinksToCard)
								    
						  "Add global links emanating from this FileBox.")))
				     (Assign% Title (FUNCTION NC.AssignTitle)
						    "Assign a new title to this FileBox.")
				     (Put% Cards% Here (FUNCTION NC.FileBoxCollectChildren)
						       
					    "Collect new cards and file boxes into this FileBox.")
				     (Close% and% Save (FUNCTION NC.QuitCard)
						       
					  "Close this note card after saving it in the NoteFile."
						       (SUBITEMS (Close% and% Save
								   (FUNCTION NC.QuitCard)
								   
					  "Close this note card after saving it in the NoteFile.")
								 (Save% in% NoteFile
								   (FUNCTION NC.CardSaveFn)
								   
				       "Save this card in the NoteFile but don't close the card.")
								 (Delete% FileBox
								   (FUNCTION NC.DeleteNoteCards)
								   
					     "Permenantly delete this FileBox from the NoteFile.")))))
			    )))))

(NC.MakeTEditMiddleMenu
  (LAMBDA NIL                                                (* fgh: "26-Mar-85 22:57")

          (* * Make the Middle Button Menu fort a Tedit card.)


    (\TEDIT.CREATEMENU (DREMOVE NIL (BQUOTE ((Restart% Editor (FUNCTION NC.ResetTEdit)
							      
					      "Resets and restarts the editor for this Card/Box.")
					     ,
					     (AND NC.AnnoFlg (for Item in (fetch (MENU ITEMS)
									     of TEDIT.DEFAULT.MENU)
								when (EQ (CAR Item)
									 (QUOTE Annotate))
								do (RETURN Item)))
					     (Advanced% Editing% Menu (FUNCTION \TEDIT.EXPANDED.MENU)
								      
					  "Brings up the menu for the advanced editing commands.")
					     (Change% Font (FUNCTION NC.\TEDIT.LOOKS)
							   "Changes the font of the selected text.")
					     (Hardcopy (FUNCTION TEDIT.HARDCOPY)
						       "Send a copy to the default printer.")
					     ,
					     (for Item in (fetch (MENU ITEMS) of TEDIT.DEFAULT.MENU)
						when (EQ (CAR Item)
							 (QUOTE Edit% Marks))
						do (RETURN Item))))))))

(NC.MarkTextDirty
  (LAMBDA (ID ResetFlg)                                      (* rht: " 1-Feb-85 15:45")

          (* * Mark or unmark TextStream as being changed.)



          (* * rht 2/1/85: Updated to use the documented function.)


    (TEDIT.STREAMCHANGEDP (TEXTSTREAM (NC.FetchSubstance ID))
			  ResetFlg)))

(NC.ResetTEdit
  (LAMBDA (TextStream)                                       (* NoteCards% User "17-Jun-84 01:58")

          (* * Kill the Tedit process running on TextStream and the restart a new one. Goal is to clean up display if TEdit 
	  goea awary.)


    (ADD.PROCESS (LIST (FUNCTION NC.ResetTEditProcess)
		       TextStream)
		 (QUOTE NAME)
		 (QUOTE ResetTEdit))))

(NC.ResetTEditProcess
  (LAMBDA (TextStream)                                       (* rht: " 8-Oct-85 23:05")

          (* * Added-process that actually does the works for NC.ResetTEdit. Kill the Tedit process running on TextStream and 
	  the restart a new one. Goal is to clean up display if TEdit goea awary.)



          (* * rht 2/1/85: Changed to calls to NC.MarkCardDirty and NC.CardDirtyP.)



          (* * rht 10/8/85: Now closes prompt window if TEDIT call brought it up.)


    (LET ((Window (WINDOW.FROM.TEDIT.THING TextStream))
       (TextObj (TEXTOBJ TextStream))
       DirtyFlg ID PromptWin)
      (if (AND (WINDOWP Window)
	       (SETQ ID (NC.IDFromWindow Window)))
	  then (SETQ DirtyFlg (NC.CardDirtyP ID))
	       (TEDIT.KILL TextStream)
	       (TEDIT TextStream Window)
	       (if (OPENWP (SETQ PromptWin (CAR (WINDOWPROP Window (QUOTE PROMPTWINDOW)))))
		   then (CLOSEW PromptWin))
	       (NC.MarkCardDirty ID (NOT DirtyFlg))
	       (WINDOWPROP Window (QUOTE TITLE)
			   (NC.RetrieveTitle ID PSA.Database))))))

(NC.TEditBasedP
  (LAMBDA (Type)                                             (* rht: " 8-Nov-84 12:03")

          (* * Returns T if Type is a note card type that is based on TEdit or else an ID of such a note card.
	  NIL otherise.)



          (* * rht 11/8/84: Hacked to reflect notecards typing mechanism. Seems gross to have to search the types list to get 
	  the record.)


    (COND
      ((NC.IDP Type)
	(SETQ Type (NC.FetchType Type))))
    (for CardType in NC.CardTypes when (EQ Type (fetch (NoteCardType TypeName) of CardType))
       do (RETURN (EQ (QUOTE TEXT)
		      (fetch (NoteCardType SubstanceType) of CardType))))))

(NC.TEditCloseFn
  (LAMBDA (WindowOrTextStreamOrID)                           (* rht: "13-Nov-84 09:55")
                                                             (* Close this TEdit window by Quitting from TEdit)

          (* * rht 11/12/84: Changed call to TEXTSTREAM to a WINDOWPROP call.)


    (PROG (Window (ID (NC.CoerceToID WindowOrTextStreamOrID)))
          (SETQ Window (NC.FetchWindow ID))
          (NC.TEditQuitFn ID)
          (COND
	    (Window (WINDOWDELPROP Window (QUOTE CLOSEFN)
				   (FUNCTION NC.QuitCard))
		    (TEDIT.QUIT (TEXTSTREAM Window)))))))

(NC.TEditMenuFn
  (LAMBDA (Window)                                           (* NoteCards% User "17-Jun-84 00:23")

          (* * Gets called from LEFT or MIDDLE button press in title bar of TEdit window. If LEFT press bring up the Notecards
	  Manipulation Window. IF MIDDLE press bring up the TEdit specific NoteCard operations menu. Bring up menus using 
	  TEDIT.DEFAULT.MENUFN)


    (PROGN (COND
	     ((LASTMOUSESTATE LEFT)
	       (WINDOWPROP Window (QUOTE TEDIT.MENU)
			   (WINDOWPROP Window (QUOTE NoteCardsLeftButtonMenu))))
	     (T (WINDOWPROP Window (QUOTE TEDIT.MENU)
			    (WINDOWPROP Window (QUOTE NoteCardsMiddleButtonMenu)))))
	   (TEDIT.DEFAULT.MENUFN Window))))

(NC.TEditQuitFn
  (LAMBDA (WindowOrID)                                       (* fgh: " 6-Jun-85 15:16")
                                                             (* Called by TEdit when quitting out of a TEdit-based 
							     note card. Close up attached windows,)
    (PROG (TextStream Window PromptWindow (ID (NC.CoerceToID WindowOrID)))
          (SETQ Window (NC.FetchWindow ID))
          (SETQ PromptWindow (CAR (WINDOWPROP Window (QUOTE PROMPTWINDOW))))
          (AND Window (for AttachedWindow in (ALLATTACHEDWINDOWS Window) unless (EQ AttachedWindow 
										    PromptWindow)
			 do (DETACHWINDOW AttachedWindow)
			    (CLOSEW AttachedWindow)
			    (until (NULL (OPENWP AttachedWindow)) do (BLOCK))))
          (SETQ TextStream (NC.FetchSubstance ID))
          (NC.DeactivateCard ID)

          (* * Obsolete (* MAke sure TEdit won't close the database file) (replace (TEXTOBJ TXTFILE) of 
	  (TEXTOBJ TextStream) with NIL) (TEDIT.MAPPIECES (TEXTOBJ TextStream) (FUNCTION (LAMBDA (CH# PC PC# OBL) 
	  (replace (PIECE PFILE) of PC with NIL)))))



          (* * Setting the PromptWindow PROCESS to NIL is to break a circularity caused by TEXTOBJ -> PROMPTWINDOW -> PROCESS 
	  -> TEXTSTREAM -> TEXTOBJ)


          (AND Window (SETQ PromptWindow (GETPROMPTWINDOW Window NIL NIL T))
	       (WINDOWPROP PromptWindow (QUOTE PROCESS)
			   NIL)
	       (REMOVEPROMPTWINDOW Window))
          (RETURN T))))

(NC.TextCopySubstance
  (LAMBDA (ID FromStream ToStream)                           (* fgh: " 8-Oct-85 15:50")

          (* * Copy a text substance from FromStream to ToStream.)


    (PROG (FromStartPtr FromEndPtr ToEndPtrLoc ToEndPtr ToStartPtr)

          (* * Set up start/end pointers on ToStream)


	    (SETQ ToStartPtr (IPLUS (GETFILEPTR ToStream)
					6))
	    (NC.PutPtr ToStream ToStartPtr)
	    (SETQ ToEndPtrLoc (GETFILEPTR ToStream))
	    (NC.PutPtr ToStream 0)

          (* * Get FromStream start/end pointers)


	    (SETQ FromStartPtr (NC.GetPtr FromStream 3))
	    (SETQ FromEndPtr (NC.GetPtr FromStream 3))

          (* * Copy the bytes, fixing up the file absolute pointers on the way.)


	    (COND
	      ((IGREATERP (IDIFFERENCE FromEndPtr FromStartPtr)
			    2)
		(SETFILEPTR FromStream (IDIFFERENCE FromEndPtr 2))
		(COND
		  ((EQUAL (IQUOTIENT (\WIN FromStream)
					 100)
			    NC.TEditPasswordDividedBy100)
		    (COPYBYTES FromStream ToStream FromStartPtr (IDIFFERENCE FromEndPtr 8))
		    (\DWOUT ToStream (IPLUS (IDIFFERENCE (\DWIN FromStream)
							       FromStartPtr)
						ToStartPtr))
		    (RPTQ 2 (\WOUT ToStream (\WIN FromStream))))
		  (T (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))))
	      (T (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr)))

          (* * Set up the ned ptr on the ToStream)


	    (SETQ ToEndPtr (GETFILEPTR ToStream))
	    (SETFILEPTR ToStream ToEndPtrLoc)
	    (NC.PutPtr ToStream ToEndPtr)
	    (RETURN T))))

(NC.TextDirtyP
  (LAMBDA (ID)                                               (* fgh: "23-Oct-84 12:34")

          (* * Return T is TextSubstance has been changed.)


    (TEDIT.STREAMCHANGEDP (TEXTSTREAM (NC.FetchSubstance ID)))))

(NC.\TEDIT.LOOKS
  (LAMBDA (TextStream)                                       (* fgh: "31-Mar-84 16:02")
    (\TEDIT.LOOKS (TEXTOBJ TextStream))))

(NC.\TEDIT.QUIT
  (LAMBDA (TextStream)                                       (* fgh: "10-May-84 16:27")
    (PROG ((Window (WINDOW.FROM.TEDIT.THING TextStream)))
          (NC.TEditQuitFn Window)
          (\TEDIT.QUIT Window))))

(NC.TextCardShrinkFn
  (LAMBDA (W)                                                (* rht: "31-May-85 15:45")

          (* * This is in order to get the right title on the TEdit icon. This is a kludgy finesse around TEdit's shrunken 
	  icon title facility.)


    (PROG ((OldIconTitle (WINDOWPROP W (QUOTE NoteCardsIconTitle)))
	   (Icon (WINDOWPROP W (QUOTE ICON)))
	   (ID (NC.CoerceToID W))
	   IconTitle)
          (if (NULL Icon)
	      then (APPLY* (WINDOWPROP W (QUOTE ICONFN))
			   W)
		   (SETQ Icon (WINDOWPROP W (QUOTE ICON))))
          (if (NOT (EQUAL OldIconTitle (SETQ IconTitle (CONCAT "NC: " (NC.FetchTitle ID)))))
	      then (ICONTITLE IconTitle NIL NIL Icon)
		   (WINDOWPROP W (QUOTE NoteCardsIconTitle)
			       IconTitle)))))
)

(RPAQ TEDIT.DEFAULT.PROPS (CONS (QUOTE SLOWUPDATE)
				(CONS (QUOTE T)
				      TEDIT.DEFAULT.PROPS)))

(RPAQQ NC.TEditPasswordDividedBy100 314)
(* * This stuff supports the "push-copy" method of copying links in NC)

(DEFINEQ

(NC.TranslateWindowPositionToTEditPosition
  (LAMBDA (Window WindowPositionX WindowPositionY)           (* fgh: "15-Feb-85 19:42")

          (* * comment)


    (PROG (TextObj)
          (COND
	    ((AND (WINDOWP Window)
		  (type? TEXTOBJ (SETQ TextObj (WINDOWPROP Window (QUOTE TEXTOBJ)))))
	      (RETURN (fetch (SELECTION CH#) of (TEDIT.SELECT WindowPositionX WindowPositionY TextObj
							      (fetch (TEXTOBJ MOUSEREGION)
								 of TextObj)
							      NIL NIL Window))))))))

(NC.InsertLinkInTextWindow
  (LAMBDA (TextWindow LinkOrLinkLabel CharacterPosition)     (* rht: "26-Mar-85 15:31")

          (* * Given a Window and a Link, insert the Link at CharacterPosition in the TextStream of Window)


    (PROG ((TextStream (WINDOWPROP TextWindow (QUOTE TEXTSTREAM))))
          (RETURN (NC.InsertLinkInText TextStream LinkOrLinkLabel NIL NIL NIL CharacterPosition)))))
)
(* * New FNS for fixing TEdit bugs in intermezzo.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.ExternalPutLinkIconImageFns)
)
(DEFINEQ

(NC.IDFromTextStream
  (LAMBDA (TextStream)                                       (* fgh: "28-May-85 23:12")

          (* * Return the NoteCards ID for a TextStream)


    (STREAMPROP TextStream (QUOTE NoteCardID))))

(NC.TEditPutFn
  (LAMBDA (TextStream FileName When?)                        (* fgh: "30-May-85 23:06")

          (* * This function designed to be attached to the PUTFN Tedit property of NC textstreams.)



          (* * Before actions: Mark the card dirty for NoteCards, if TEdit thinks the card is dirty. Also, change the link 
	  icons to be ExternalPut Link Icons so that thety are no longer active in the file being put to.
	  Necessary when a put is done outside the normal NoteCards mechanism.)


    (SELECTQ When?
	     (BEFORE (PROG ((TextObj (TEXTOBJ TextStream))
			    LinkIcons)

          (* * first Mark the card dirty NoteCards style, if necessary)


		           (COND
			     ((TEDIT.STREAMCHANGEDP TextStream)
			       (NC.MarkCardDirty (NC.IDFromTextStream (TEXTSTREAM TextStream)))))
		           (RESETLST 

          (* * Remove this PUTFN from the TEXTOBJ temporarily)


				     (RESETSAVE (TEXTPROP TextObj (QUOTE PUTFN)
							  NIL)
						(BQUOTE (TEXTPROP , TextObj PUTFN ,
								  (TEXTPROP TextObj (QUOTE PUTFN)))))

          (* * Collect all the link icons in the TextStream)


				     (SETQ LinkIcons (TEDIT.LIST.OF.OBJECTS TextObj
									    (FUNCTION 
									     NC.LinkIconImageObjP)))

          (* * Temporarily set them to be ExternalPut link icons)


				     (RESETSAVE (NC.TEditPutFnAuxiliary LinkIcons 
								   NC.ExternalPutLinkIconImageFns)
						(BQUOTE (NC.TEditPutFnAuxiliary , LinkIcons , 
									      NC.LinkIconImageFns)))

          (* * Fix up the title on the way out)


				     (RESETSAVE NIL (BQUOTE (AND , (WINDOW.FROM.TEDIT.THING 
										       TextStream)
								 (WINDOWPROP , (
									  WINDOW.FROM.TEDIT.THING
									       TextStream)
									     (QUOTE TITLE)
									     ,
									     (NC.FetchTitle
									       (NC.IDFromTextStream
										 TextStream))))))

          (* * Put the file as usual)


				     (TEDIT.PUT TextStream FileName FORCENEW UNFORMATTED?))
		           (RETURN (QUOTE DON'T))))
	     NIL)))

(NC.TEditPutFnAuxiliary
  (LAMBDA (LinkIcons NewImageFns)                            (* fgh: "30-May-85 17:29")

          (* * For a list of link icons as returned by TEDIT.LIST.OF.OBJECTS, replace all the IMAGEFNS of the objects with 
	  NewImageFns)


    (for LinkIconPair in LinkIcons do (replace (IMAGEOBJ IMAGEOBJFNS) of (CAR LinkIconPair)
					 with NewImageFns))))

(NC.TEditGetFn
  (LAMBDA (TextStream FileName When?)                        (* fgh: "30-May-85 23:26")

          (* * This function called from the GETFN for all NC TextStreams)


    (SELECTQ When?
	     (BEFORE (LET ((LinkIcons (TEDIT.LIST.OF.OBJECTS (TEXTOBJ TextStream)
							     (FUNCTION NC.LinkIconImageObjP))))

          (* * Delete all the links currentluy in the text stream)


		       (for LinkIconPair in LinkIcons do (TEDIT.DELETE TextStream (CADR LinkIconPair)
								       1))))
	     (AFTER (LET ((ID (NC.IDFromTextStream TextStream)))

          (* * Mark the card dirty ala NoteCards)


		      (NC.MarkCardDirty ID)

          (* * Reset the NC title)


		      (WINDOWPROP (WINDOW.FROM.TEDIT.THING TextStream)
				  (QUOTE TITLE)
				  (NC.RetrieveTitle ID))))
	     NIL)))

(NC.MakeTEditPropsList
  (LAMBDA (TEditWindow)                                      (* rht: "11-Sep-85 10:37")

          (* * Create the props list to hand to all TEdit and OPENTEXTSTREAM calls)



          (* * rht 9/10/85: Now takes a TEditWindow arg so can compute a prompt window.)


    (LIST (QUOTE FONT)
	  NC.DefaultFont
	  (QUOTE TITLEMENUFN)
	  (FUNCTION NC.TEditMenuFn)
	  (QUOTE PUTFN)
	  (FUNCTION NC.TEditPutFn)
	  (QUOTE GETFN)
	  (FUNCTION NC.TEditGetFn)
	  (QUOTE QUITFN)
	  (LIST (FUNCTION NC.QuitCard)
		(FUNCTION (LAMBDA NIL
		    (QUOTE DON'T))))
	  (QUOTE PROMPTWINDOW)
	  (AND TEditWindow (NC.GetPromptWindow TEditWindow)))))
)
(* * Add Text substance type to list)

(DEFINEQ

(NC.AddTextSubstance
  (LAMBDA NIL                                                (* fgh: "19-Jun-85 16:30")
    (NC.AddSubstanceType (QUOTE TEXT)
			 (BQUOTE ((CreateSubstanceFn , (FUNCTION NC.MakeTEditCard))
				  (EditSubstanceFn , (FUNCTION NC.BringUpTEditCard))
				  (QuitSubstanceFn , (FUNCTION NC.TEditCloseFn))
				  (GetSubstanceFn , (FUNCTION NC.GetTextSubstance))
				  (PutSubstanceFn , (FUNCTION NC.PutTextSubstance))
				  (CopySubstanceFn , (FUNCTION NC.TextCopySubstance))
				  (MarkSubstanceDirtyFn , (FUNCTION NC.MarkTextDirty))
				  (SubstanceDirtyPFn , (FUNCTION NC.TextDirtyP))
				  (CollectLinksInSubstanceFn , (FUNCTION NC.CollectReferencesInText))
				  (DeleteLinksInSubstanceFn , (FUNCTION 
							      NC.DelReferencesToCardFromText))
				  (UpdateLinkIconsInSubstanceFn , (FUNCTION NC.UpdateLinkImagesInText)
								)
				  (InsertLinkInSubstanceFn , (FUNCTION NC.InsertLinkInTextWindow))
				  (TranslateWindowPositionToSubstancePositionFn
				    ,
				    (FUNCTION NC.TranslateWindowPositionToTEditPosition))))
			 (QUOTE ((SubstanceDefaultWidth 300)
				  (SubstanceDefaultHeight 200)
				  (SubstanceLinkAnchorModesSupported T))))))
)
(NC.AddTextSubstance)
(PUTPROPS NCTEXTSUBSTANCE COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1953 21609 (NC.BringUpTEditCard 1963 . 3632) (NC.CollectReferencesInText 3634 . 6130) (
NC.MakeTEditLeftMenu 6132 . 11603) (NC.MakeTEditMiddleMenu 11605 . 12780) (NC.MarkTextDirty 12782 . 
13128) (NC.ResetTEdit 13130 . 13540) (NC.ResetTEditProcess 13542 . 14710) (NC.TEditBasedP 14712 . 
15437) (NC.TEditCloseFn 15439 . 16076) (NC.TEditMenuFn 16078 . 16827) (NC.TEditQuitFn 16829 . 18417) (
NC.TextCopySubstance 18419 . 20063) (NC.TextDirtyP 20065 . 20319) (NC.\TEDIT.LOOKS 20321 . 20483) (
NC.\TEDIT.QUIT 20485 . 20738) (NC.TextCardShrinkFn 20740 . 21607)) (21843 22842 (
NC.TranslateWindowPositionToTEditPosition 21853 . 22412) (NC.InsertLinkInTextWindow 22414 . 22840)) (
22981 27480 (NC.IDFromTextStream 22991 . 23228) (NC.TEditPutFn 23230 . 25441) (NC.TEditPutFnAuxiliary 
25443 . 25860) (NC.TEditGetFn 25862 . 26746) (NC.MakeTEditPropsList 26748 . 27478)) (27525 28785 (
NC.AddTextSubstance 27535 . 28783)))))
STOP