(FILECREATED "20-Nov-84 01:14:04" {PHYLUM}<PSA>NOTECARDS>RELEASE1.1>RHTPATCH004.;10 85273  

      changes to:  (FNS NC.InsertLinksInText NC.AddLinksToTextCard NC.MakeMainMenu 
			NC.MainMenuWhenSelectedFn NC.MakeTEditLeftMenu NC.ShowPointers 
			NC.AskLinkLabel NC.CloseDatabaseFile NC.CheckTitle NC.LinkIconCopyFn 
			NC.FillInLinkIcon NC.LinkIconWhenDeletedFn NC.LinkIconWhenCopiedFn 
			NC.LinkIconWhenMovedFn NC.MovedImageObjAddProcess 
			NC.DelReferencesToCardFromGlobalList NC.FillInLinkIconCopy 
			NC.ReplaceMovedImageObj NC.DeleteCopiedImageObj NC.InsertImageObjCopy 
			NC.DeleteImageObj NC.CopiedImageObjAddProcess NC.ConvertImageObjToInvisible 
			NC.Setup NC.RelabelLink)
		   (VARS RHTPATCH004COMS)

      previous date: "17-Nov-84 18:31:04" {PHYLUM}<PSA>NOTECARDS>RELEASE1.1>RHTPATCH004.;5)


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

(PRETTYCOMPRINT RHTPATCH004COMS)

(RPAQQ RHTPATCH004COMS ((FNS NC.LinkIconImageBoxFn NC.LinkIconDisplayFn NC.DelFromLink 
			     NCP.ActivateCards NCP.DeactivateCards NC.MakeLinkIndex 
			     NC.AppendLinkIndexEntry NCP.MakeLinkIndex NCP.MakeDocument 
			     NC.MakeDocument NC.MakeDocInspectorSelectionFn NC.AppendStringToStream 
			     NC.MakeBrowserCard NC.BringUpBrowserCard NCP.CreateBrowserCard 
			     NCP.DeleteCards NC.FileBoxCollectChildren NC.ChooseTopLevelCard 
			     NC.MakeCardTypesList NC.DelReferencesToCardFromGraph NC.RelabelLink 
			     NC.DelReferencesToCardFromGlobalList)
	(P (PUTPROP (QUOTE NC.MakeDocParameters)
		    (QUOTE --DONE--)
		    (QUOTE --CANCEL--)))
	(FNS NC.LinkIconWhenDeletedFn NC.LinkIconWhenCopiedFn NC.LinkIconWhenMovedFn 
	     NC.LinkIconCopyFn NC.FillInLinkIcon NC.InsertImageObjCopy NC.DeleteImageObj 
	     NC.CopiedImageObjAddProcess NC.MovedImageObjAddProcess NC.Setup)
	(FNS NC.InsertLinksInText NC.AddLinksToTextCard NC.MakeTEditLeftMenu NC.ShowPointers 
	     NC.AskLinkLabel)
	(FNS NC.CloseDatabaseFile NC.CheckTitle)
	(GLOBALVARS NC.ForceTitlesFlg)))
(DEFINEQ

(NC.LinkIconImageBoxFn
  (LAMBDA (ImageObj ImageStream CurrentX RightMargin DummyArg DisplayType Title Label)
                                                             (* rht: "13-Nov-84 10:43")

          (* * rht 9/20/84: Now scales result before returning by proper amount depending on stream type.
	  e.g. for PRESS and INTERPRESS.)



          (* * rht 11/13/84: In computation of XSIZE, extra width is figured using characters in the font, "nn", rather than 
	  absolute pixel count.)


    (PROG (FONT Window ID NoteCardType (Link (NC.FetchLinkFromLinkIcon ImageObj))
		(Scale (DSPSCALE NIL ImageStream)))
          (SETQ DisplayType (COND
	      ((EQ DisplayType T)
		(QUOTE Title))
	      (DisplayType DisplayType)
	      ((fetch (NOTECARDLINK DISPLAYMODE) of Link))
	      (T (QUOTE Icon))))
          (AND (FMEMB DisplayType (QUOTE (Title Both)))
	       (OR Title (SETQ Title (NC.RetrieveTitle (fetch (NOTECARDLINK DESTINATIONID)
							  of Link)
						       PSA.Database))))
          (AND (EQ DisplayType (QUOTE SourceTitle))
	       (OR Title (SETQ Title (NC.RetrieveTitle (fetch (NOTECARDLINK SOURCEID) of Link)
						       PSA.Database))))
          (AND (FMEMB DisplayType (QUOTE (Label Both)))
	       (OR Label (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link))))
          (RETURN (create IMAGEBOX
			  XSIZE ←(ITIMES Scale
					 (STRINGWIDTH (CONCAT "nn"
							      (SELECTQ DisplayType
								       (SourceTitle Title)
								       (Title Title)
								       (Label (CONCAT "<" Label ">"))
								       (Both (CONCAT "<" Label ">" 
										     " "
										     Title))
								       "   "))
						      (SETQ FONT (FONTCREATE (QUOTE HELVETICA)
									     10
									     (QUOTE BOLD)))))
			  YSIZE ←(ITIMES Scale (IPLUS (FONTPROP FONT (QUOTE HEIGHT))
						      8))
			  YDESC ←(COND
			    (RightMargin                     (* This is in a TEdittextstream)
					 (ITIMES Scale (FONTPROP FONT (QUOTE DESCENT))))
			    (T 0))
			  XKERN ← 0)))))

(NC.LinkIconDisplayFn
  (LAMBDA (ImageObj ImageStream STREAMTYPE TEXTSTREAM SCALE TitleFlg)
                                                             (* rht: "13-Nov-84 10:44")

          (* * Display a link icon)



          (* * rht 11/13/84: Made width of box lines also scale dependent.)


    (PROG (YSize XSize Left Bottom DisplayType Window ID Title Label BoxLeft BoxBottom BoxWidth 
		 BoxHeight BoxBarHeight TextLeft TextBaseLine ImageBox (Scale (DSPSCALE NIL 
										      ImageStream))
		 (Link (NC.FetchLinkFromLinkIcon ImageObj))
		 (Font (FONTCREATE (QUOTE HELVETICA)
				   10
				   (QUOTE BOLD))))

          (* * Determine what type of Display to do)


          (SETQ DisplayType (COND
	      (TitleFlg (QUOTE Title))
	      ((fetch (NOTECARDLINK DISPLAYMODE) of Link))
	      (T (QUOTE Icon))))
          (AND (FMEMB DisplayType (QUOTE (Title Both)))
	       (SETQ Title (NC.RetrieveTitle (fetch (NOTECARDLINK DESTINATIONID) of Link)
					     PSA.Database)))
          (AND (FMEMB DisplayType (QUOTE (Label Both)))
	       (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link)))
          (AND (EQ DisplayType (QUOTE SourceTitle))
	       (SETQ Title (NC.RetrieveTitle (fetch (NOTECARDLINK SOURCEID) of Link))))

          (* * Get the image box info for this icon)


          (SETQ ImageBox (OR (IMAGEOBJPROP ImageObj (QUOTE BOUNDBOX))
			     (NC.LinkIconImageBoxFn ImageObj ImageStream NIL NIL NIL DisplayType 
						    Title Label)))
          (SETQ XSize (fetch (IMAGEBOX XSIZE) of ImageBox))
          (SETQ YSize (fetch (IMAGEBOX YSIZE) of ImageBox))

          (* * Draw a box around the border of the link icon)


          (SETQ Bottom (IDIFFERENCE (DSPYPOSITION NIL ImageStream)
				    (fetch (IMAGEBOX YDESC) of ImageBox)))
          (SETQ Left (DSPXPOSITION NIL ImageStream))
          (SETQ BoxLeft (IPLUS Scale Left))
          (SETQ BoxBottom (IPLUS Scale Bottom))
          (SETQ BoxWidth (IDIFFERENCE XSize (ITIMES Scale 4)))
          (SETQ BoxHeight (IDIFFERENCE YSize (ITIMES Scale 4)))
          (SETQ BoxBarHeight (IPLUS (IDIFFERENCE BoxHeight (ITIMES Scale 2))
				    BoxBottom))
          (DRAWBOX BoxLeft BoxBottom BoxWidth BoxHeight Scale ImageStream)
          (if (EQ DisplayType (QUOTE Icon))
	      then (DRAWLINE (IPLUS Scale BoxLeft)
			     BoxBarHeight
			     (IDIFFERENCE (IPLUS BoxLeft BoxWidth)
					  Scale)
			     BoxBarHeight
			     (ITIMES Scale 5)
			     NIL ImageStream))

          (* * Enter the appropriate text.)


          (SETQ TextLeft (IPLUS Left (ITIMES Scale 6)))
          (SETQ TextBaseLine (IPLUS Bottom (ITIMES Scale (IPLUS 3 (FONTPROP Font (QUOTE DESCENT))))))
          (DSPXPOSITION TextLeft ImageStream)
          (DSPYPOSITION TextBaseLine ImageStream)
          (DSPFONT (PROG1 (DSPFONT Font ImageStream)
			  (PRIN1 (SELECTQ DisplayType
					  (SourceTitle Title)
					  (Title Title)
					  (Label (CONCAT "<" Label ">"))
					  (Both (CONCAT "<" Label ">" " " Title))
					  "")
				 ImageStream))
		   ImageStream))))

(NC.DelFromLink
  (LAMBDA (Link DatabaseStream NoOrphanHookFlg)              (* rht: "16-Nov-84 18:16")
                                                             (* Delete a FromLink from card on DatabaseStream.
							     Hook card to orphan if this is the last link.)

          (* * rht 11/15/84: Changed decision as to when to orphanize a card. Now must have deleted its last link 
	  (not just last subbox or filedcard link). Also checks that link doesn't point from card to itself.)


    (PROG ((ID (fetch (NOTECARDLINK DESTINATIONID) of Link)))
          (COND
	    ((NC.ActiveCardP ID)
	      (NC.SetFromLinks ID (DREMOVE (for OldLink in (NC.FetchFromLinks ID)
					      thereis (AND (EQ (fetch (NOTECARDLINK LINKID)
								  of Link)
							       (fetch (NOTECARDLINK LINKID)
								  of OldLink))
							   OldLink))
					   (NC.FetchFromLinks ID)))
	      (NC.SetLinksDirtyFlg ID T)
	      (AND (NULL NoOrphanHookFlg)
		   (NOT (FMEMB ID NC.TopLevelCards))
		   (NOT (EQ (fetch (NOTECARDLINK SOURCEID) of Link)
			    ID))
		   (NULL (NC.FetchNewCardFlg ID))
		   (NOT (EQ (fetch (NOTECARDLINK SOURCEID) of Link)
			    NC.OrphanID))
		   (COND
		     ((OR (NULL (NC.FetchFromLinks ID))
			  (for Link in (NC.FetchFromLinks ID) always (EQ (fetch (NOTECARDLINK 
											 SOURCEID)
									    of Link)
									 ID)))
		       (NC.PrintMsg NIL T "You have just removed the last link to " (NC.RetrieveTitle
				      ID)
				    "."
				    (CHARACTER 13)
				    "It is being filed in the Orphan FileBox.")
		       (NC.HookToOrphanCard ID NC.OrphanID DatabaseStream))
		     ((for Link in (NC.FetchFromLinks ID) never (FMEMB (fetch (NOTECARDLINK LINKLABEL)
									  of Link)
								       (QUOTE (SubBox FiledCard))))
		       (NC.PrintMsg NIL T "You have just unfiled " (NC.RetrieveTitle ID)
				    " from its last filebox."
				    (CHARACTER 13)
				    "It is being filed in the Orphan FileBox.")
		       (NC.HookToOrphanCard ID NC.OrphanID DatabaseStream)))))
	    (T (WITH.MONITOR (NC.FetchMonitor DatabaseStream "NC.AddFromLink")
			     (NC.GetLinks ID DatabaseStream)
			     (NC.SetFromLinks ID (DREMOVE (for OldLink in (NC.FetchFromLinks ID)
							     thereis
							      (AND (EQ (fetch (NOTECARDLINK LINKID)
									  of Link)
								       (fetch (NOTECARDLINK LINKID)
									  of OldLink))
								   OldLink))
							  (NC.FetchFromLinks ID)))
			     (NC.SetLinksDirtyFlg ID T)
			     (NC.PutLinks ID DatabaseStream)
			     (AND (NULL NoOrphanHookFlg)
				  (NOT (FMEMB ID NC.TopLevelCards))
				  (NOT (EQ (fetch (NOTECARDLINK SOURCEID) of Link)
					   ID))
				  (NULL (NC.FetchNewCardFlg ID))
				  (NOT (EQ (fetch (NOTECARDLINK SOURCEID) of Link)
					   NC.OrphanID))
				  (COND
				    ((OR (NULL (NC.FetchFromLinks ID))
					 (for Link in (NC.FetchFromLinks ID)
					    always (EQ (fetch (NOTECARDLINK SOURCEID) of Link)
						       ID)))
				      (NC.PrintMsg NIL T "You have just removed the last link to "
						   (NC.RetrieveTitle ID)
						   "."
						   (CHARACTER 13)
						   "It is being filed in the Orphan FileBox.")
				      (NC.HookToOrphanCard ID NC.OrphanID DatabaseStream))
				    ((for Link in (NC.FetchFromLinks ID)
					never (FMEMB (fetch (NOTECARDLINK LINKLABEL) of Link)
						     (QUOTE (SubBox FiledCard))))
				      (NC.PrintMsg NIL T "You have just unfiled " (NC.RetrieveTitle
						     ID)
						   " from its last filebox."
						   (CHARACTER 13)
						   "It is being filed in the Orphan FileBox.")
				      (NC.HookToOrphanCard ID NC.OrphanID DatabaseStream)))))
	       (NC.SetFromLinks ID NIL)
	       (NC.SetToLinks ID NIL)))
          (RETURN Link))))

(NCP.ActivateCards
  (LAMBDA (IDs)                                              (* rht: "15-Nov-84 11:30")

          (* * Cache all the info for any inactive cards in IDs.)


    (for ID in (MKLIST IDs) unless (if (NOT (NCP.ValidID ID))
				       then (NCP.ReportError ID " not an existing card or filebox.")
					    T)
       do (if (NOT (NCP.ActiveCardP ID))
	      then (NC.GetNoteCard ID PSA.Database))
       finally (RETURN ID))))

(NCP.DeactivateCards
  (LAMBDA (IDs)                                              (* rht: "15-Nov-84 11:42")

          (* * Uncache all the info for any active cards in IDs.)


    (for ID in (MKLIST IDs) bind Win (OldProc ←(TTY.PROCESS)) unless (COND
								       ((NOT (NCP.ValidID ID))
									 (NCP.ReportError ID 
							      " not an existing card or filebox.")
									 T))
       do (if (NCP.ActiveCardP ID)
	      then (SETQ Win (NC.FetchWindow ID))
		   (NC.QuitCard ID T)
		   (AND Win (while (OPENWP Win) do (BLOCK))))
       finally (AND (PROCESSP OldProc)
		    (TTY.PROCESS OldProc))
	       (RETURN ID))))

(NC.MakeLinkIndex
  (LAMBDA (ID Title NoDisplayFlg SpecialArgsList)            (* rht: "15-Nov-84 15:47")

          (* * Gather all instances of a given set of linktypes, printing the titles of cards at the from and to ends of the 
	  link.)



          (* * rht 10/24/84: Now callable from Programmer's interface. If NoDisplayFlg it non-nil, then will build LinkIndex 
	  invisibly. If SpecialArgsList is non-nil, then should be list of (<linklabels> <backpointersP> <sortP>))


    (PROG (IndexCardID Window WindowOrID LinkLabels BackPointersP Stream SortedWinners LastID)
          (SPAWN.MOUSE)
          (SETQ WindowOrID (NC.MakeNoteCard (QUOTE Text)
					    "Link Index" NoDisplayFlg NIL ID))
          (if NoDisplayFlg
	      then (SETQ Window NIL)
		   (SETQ IndexCardID WindowOrID)
	    else (SETQ Window WindowOrID)
		 (SETQ IndexCardID (NC.IDFromWindow Window)))
          (SETQ LinkLabels (if SpecialArgsList
			       then (CAR SpecialArgsList)
			     else (NC.AskLinkLabel Window T T NIL NIL T)))
          (if (NULL LinkLabels)
	      then (NC.PrintMsg Window T "No link labels to search for.")
		   (RETURN NIL))
          (SETQ BackPointersP (if SpecialArgsList
				  then (CADR SpecialArgsList)
				else (NC.YesP (NC.AskUser "Build back pointers to cards and boxes? " 
							  "--"
							  NIL NIL Window T))))
          (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		    (SETQ Stream (NC.FetchSubstance IndexCardID))
		    (NC.AppendStringToStream Stream (CONCAT "Sorted link index compiled on: "
							    (DATE)
							    (CHARACTER 13)
							    " for linktypes: "
							    (CAR LinkLabels)))
		    (for Label in (CDR LinkLabels) do (NC.AppendStringToStream Stream
									       (CONCAT ", " Label)))
		    (NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)
							    (CHARACTER 13)))
		    (SETQ LastID (SUB1 (SUBATOM (NC.GetNewID PSA.Database T)
						4)))         (* Subtract one more so that this LinkIndex's ID isn't 
							     counted.)
		    (SETQ LastID (SUB1 LastID))
		    (NC.PrintMsg Window T "Gathering links ... ")

          (* * Find all ID's with instances of a desired link label, record whether they were active, sort them, print their 
	  titles to the stream, and deactivate the ones that weren't active.)


		    (SETQ SortedWinners (SORT (for ID# from 1 to LastID bind ID ActiveP
						 when (PROGN (SETQ ID (NC.IDFromNumber ID#))
							     (SETQ ActiveP (NC.ActiveCardP ID))
							     (PUTPROP ID (QUOTE WasActiveFlg)
								      ActiveP)
							     (OR ActiveP (NC.GetLinks ID PSA.Database)
								 )
							     (OR (for Link in (NC.FetchToLinks ID)
								    thereis (NC.LinkLabelP Link 
										       LinkLabels))
								 (for Link in (NC.FetchFromLinks
										ID)
								    thereis (NC.ReverseLinkLabelP
									      Link LinkLabels))))
						 collect (CONS (NC.FetchTitle ID)
							       ID))
					      T))
		    (for WinnerPair in SortedWinners bind ID
		       do (SETQ ID (CDR WinnerPair))
			  (NC.AppendLinkIndexEntry Stream IndexCardID ID (CAR WinnerPair)
						   LinkLabels BackPointersP))
		    (for ID# from 1 to LastID bind ID
		       do (SETQ ID (NC.IDFromNumber ID#))
			  (OR (GETP ID (QUOTE WasActiveFlg))
			      (NC.DeactivateCard ID))
			  (REMPROP ID (QUOTE WasActiveFlg)))
		    (NC.PrintMsg Window NIL "Done!" (CHARACTER 13)))
          (if (NOT NoDisplayFlg)
	      then (BLOCK 250)
		   (NC.ClearMsg Window T))
          (RETURN IndexCardID))))

(NC.AppendLinkIndexEntry
  (LAMBDA (Stream IndexCardID ID Title LinkLabels BackPointersP)
                                                             (* rht: "15-Nov-84 15:46")

          (* * Build a link index entry consisting of all instances of links from or to ID with a label in LinkLabels.
	  Append these to the end of Stream.)


    (PROG (FromLinks ToLinks ToLinkPairs FromLinkPairs (SortArg (FUNCTION NC.LinkIndexCompareFn)))
          (SETQ ToLinks (NC.FetchToLinks ID))
          (SETQ FromLinks (NC.FetchFromLinks ID))

          (* * Find all winning links.)


          (SETQ ToLinkPairs (SORT (for Link in ToLinks bind Label when (SETQ Label (NC.LinkLabelP
									   Link LinkLabels))
				     collect (CONS Label Link))
				  SortArg))
          (SETQ FromLinkPairs (SORT (for Link in FromLinks bind Label when (SETQ Label
									     (NC.ReverseLinkLabelP
									       Link LinkLabels))
				       collect (CONS Label Link))
				    SortArg))

          (* * Print the title of ID if there were any wins.)


          (COND
	    ((OR ToLinkPairs FromLinkPairs)
	      (NC.AppendStringToStream Stream Title)
	      (if BackPointersP
		  then (NC.AppendStringToStream Stream " ")
		       (NC.AppendLinkToText IndexCardID ID NC.LinkIndexBackPtrLinkLabel (QUOTE Icon)))
	      (NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)))))

          (* * Print the winning links from the ID card.)


          (for LinkPair in ToLinkPairs bind OldLabel Label DestID
	     do (SETQ Label (CAR LinkPair))
		(SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of (CDR LinkPair)))
		(COND
		  ((NEQ OldLabel Label)
		    (NC.AppendStringToStream Stream (CONCAT "  <" Label "> TO" (CHARACTER 13)))
		    (SETQ OldLabel Label)))
		(NC.AppendStringToStream Stream "    ")
		(NC.AppendStringToStream Stream (NC.FetchTitle DestID))
		(if BackPointersP
		    then (NC.AppendStringToStream Stream " ")
			 (NC.AppendLinkToText IndexCardID DestID NC.LinkIndexBackPtrLinkLabel
					      (QUOTE Icon)))
		(NC.AppendStringToStream Stream (CONCAT (CHARACTER 13))))
          (for LinkPair in FromLinkPairs bind OldLabel Label DestID
	     do (SETQ Label (CAR LinkPair))
		(SETQ DestID (fetch (NOTECARDLINK SOURCEID) of (CDR LinkPair)))
		(COND
		  ((NEQ OldLabel Label)
		    (NC.AppendStringToStream Stream (CONCAT "  <" Label "> FROM" (CHARACTER 13)))
		    (SETQ OldLabel Label)))
		(NC.AppendStringToStream Stream "    ")
		(NC.AppendStringToStream Stream (NC.FetchTitle DestID))
		(if BackPointersP
		    then (NC.AppendStringToStream Stream " ")
			 (NC.AppendLinkToText IndexCardID DestID NC.LinkIndexBackPtrLinkLabel
					      (QUOTE Icon)))
		(NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)))))))

(NCP.MakeLinkIndex
  (LAMBDA (LinkLabels BackPointersP NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "15-Nov-84 19:57")

          (* * Do a MakeLinkIndex on LinkLabels inserting backpointers according to BackPointersP.)


    (PROG (ValidLinkLabels)
          (SETQ ValidLinkLabels (for Label in (MKLIST LinkLabels) join (COND
									 ((EQ Label (QUOTE ALL))
									   (NCP.GetLinkLabels))
									 ((EQ Label (QUOTE ←ALL))
									   (NCP.GetReverseLinkLabels))
									 ((NOT (NCP.ValidLinkLabel
										 Label))
									   (NCP.ReportError Label 
								       " not a valid link label.")
									   NIL)
									 (T (LIST Label)))))
          (SETQ ValidLinkLabels (INTERSECTION ValidLinkLabels ValidLinkLabels))
          (RETURN (if (AND LinkLabels (NULL ValidLinkLabels))
		      then NIL
		    else (NCP.CreateCard (QUOTE LinkIndex)
					 NIL NoDisplayFlg Props ParentFileBoxes (LIST ValidLinkLabels 
										    BackPointersP)))))
    ))

(NCP.MakeDocument
  (LAMBDA (RootID ParamProps NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "15-Nov-84 20:00")

          (* * Do a MakeDocument starting from RootID according to parameters in ParamProps if non-nil.
	  Otherwise use the default parameters. Note that ParamProps are *only* used for the duration of this MakeDocument and
	  do not affect the default parameter values.)


    (PROG (CurParams DocID WasActive)
          (if (NCP.ValidID RootID)
	      then (AND (NOT (SETQ WasActive (NCP.ActiveCardP RootID)))
			(NCP.ActivateCards RootID))
		   (if ParamProps
		       then (SETQ CurParams (NCP.DocumentParameters ParamProps)))
		   (SETQ DocID (NCP.CreateCard (QUOTE Document)
					       NIL NoDisplayFlg Props ParentFileBoxes RootID))
		   (if ParamProps
		       then (SETPROPLIST (QUOTE NC.MakeDocParameters)
					 CurParams))
		   (AND (NOT WasActive)
			(NCP.DeactivateCards RootID))
		   (RETURN DocID)
	    else (NCP.ReportError RootID " not a valid card or filebox.")
		 (RETURN NIL)))))

(NC.MakeDocument
  (LAMBDA (ID Title NoDisplayFlg WindowOrTextStreamOrID)     (* rht: "17-Nov-84 15:44")

          (* * Called from a filebox's title bar. Makes a document by smashing all the descendant cards's text together.
	  Ask user if wants numbered section headings and titles. The former are made from FileBox titles, the latter from 
	  notecard titles. Delete embedded links at the end if the user desires.)



          (* * rht 10/22/84: Hacked to be callable from Programmer's interface.)



          (* * rht 11/17/84: Checks for cancel when choosing rootID and also when setting parameters.)


    (PROG (RootID RootTitle DocWindow DocCardID DocWindowOrID DocStream HeadingsFromFileboxes 
		  TitlesFromNoteCards BuildBackpointers CopyEmbeddedLinks ExpandEmbeddedLinks 
		  InspectWin WasActive)
          (OR NoDisplayFlg (SPAWN.MOUSE))
          (SETQ DocWindowOrID (NC.MakeNoteCard (QUOTE Text)
					       "Document" NoDisplayFlg NIL ID))
          (COND
	    (NoDisplayFlg (SETQ DocWindow NIL)
			  (SETQ DocCardID DocWindowOrID))
	    (T (SETQ DocWindow DocWindowOrID)
	       (SETQ DocCardID (NC.IDFromWindow DocWindow))))
                                                             (* NC.MakeNoteCard either returned an ID or a window 
							     depending on NoDisplayFlg.)
          (SETQ RootTitle (NC.FetchTitle (SETQ RootID (COND
					     ((NC.IDP WindowOrTextStreamOrID)
					       WindowOrTextStreamOrID)
					     ((TEXTSTREAMP WindowOrTextStreamOrID)
					       (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING 
									   WindowOrTextStreamOrID)))
					     ((WINDOWP WindowOrTextStreamOrID)
					       (NC.IDFromWindow WindowOrTextStreamOrID))
					     (T (PROGN (NC.PrintMsg DocWindow T 
			"Please select the Note Card or File Box the document should start from."
								    (CHARACTER 13))
						       (NC.SelectNoteCards T NIL 
								    NC.SelectingBrowserSourceMenu 
									   DocWindow)))))))
          (if (NOT RootID)
	      then (NC.DeleteNoteCards ID T)
		   (RETURN NIL))
          (NC.SetTitle DocCardID (CONCAT "Document from %"" RootTitle "%""))
          (AND DocWindow (WINDOWPROP DocWindow (QUOTE TITLE)
				     (NC.FetchTitle DocCardID)))
          (SETQ DocStream (NC.FetchSubstance DocCardID))

          (* * Get MakeDocument parameters from user via inspector window.)


          (if (NOT NoDisplayFlg)
	      then (SETQ InspectWin (NC.BuildMakeDocInspector DocWindow))
		   (TOTOPW InspectWin)
		   (for while (OPENWP InspectWin) do (BLOCK)))
          (if (EQ (GETPROP (QUOTE NC.MakeDocParameters)
			   (QUOTE --DONE--))
		  (QUOTE QUIT))
	      then (PUTPROP (QUOTE NC.MakeDocParameters)
			    (QUOTE --DONE--)
			    (QUOTE --CANCEL--))
		   (NC.DeleteNoteCards ID T)
		   (RETURN NIL))
          (SETQ HeadingsFromFileboxes (GETPROP (QUOTE NC.MakeDocParameters)
					       (QUOTE HeadingsFromFileboxes)))
          (SETQ TitlesFromNoteCards (GETPROP (QUOTE NC.MakeDocParameters)
					     (QUOTE TitlesFromNoteCards)))
          (SETQ BuildBackpointers (GETPROP (QUOTE NC.MakeDocParameters)
					   (QUOTE BuildBackpointers)))
          (SETQ CopyEmbeddedLinks (GETPROP (QUOTE NC.MakeDocParameters)
					   (QUOTE CopyEmbeddedLinks)))
          (SETQ ExpandEmbeddedLinks (GETPROP (QUOTE NC.MakeDocParameters)
					     (QUOTE ExpandEmbeddedLinks)))

          (* * Call recursive routine to dump filebox.)


          (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		    (NC.PrintMsg DocWindow NIL "Collecting text from descendant cards ... ")
		    (OR (SETQ WasActive (NC.ActiveCardP RootID))
			(NC.GetNoteCard RootID PSA.Database))
		    (SELECTQ (NC.RetrieveType RootID PSA.Database)
			     (FileBox (NC.DumpFileBoxToDoc RootID DocCardID DocStream "" 
							   HeadingsFromFileboxes TitlesFromNoteCards 
							   BuildBackpointers CopyEmbeddedLinks 
							   ExpandEmbeddedLinks T))
			     (Text (NC.DumpNoteCardToDoc RootID DocCardID DocStream "" 1 
							 HeadingsFromFileboxes TitlesFromNoteCards 
							 BuildBackpointers CopyEmbeddedLinks 
							 ExpandEmbeddedLinks T))
			     NIL)
		    (OR WasActive (NC.DeactivateCard RootID))

          (* * Clean up the SeenBefore markers placed on the cards and boxes just copied.)


		    (RESETSAVE NIL (QUOTE (PROGN (for ID in (GETPROP DocCardID (QUOTE SeenCards))
						    do (REMPROP ID (QUOTE SeenBefore)))
						 (REMPROP DocCardID (QUOTE SeenCards)))))
		    (NC.PrintMsg DocWindow NIL "Done!"))
          (COND
	    ((NOT NoDisplayFlg)
	      (BLOCK 250)
	      (NC.ClearMsg DocWindow T)))
          (RETURN DocWindowOrID))))

(NC.MakeDocInspectorSelectionFn
  (LAMBDA (Property ValueFlg InspectWin)                     (* rht: "17-Nov-84 15:43")

          (* * Called when user buttons in the make document inspector menu on the Property parameter.
	  Put up a menu of choices for new values for this parameter.)



          (* * rht 11/17/84: Now can select --CANCEL--. Notice strange way of checking for --DONE-- versus --CANCEL--.
	  This is because the Inspector package doesn't send the property name in Property arg if ValueFlg is on.
	  That bug has been reported.)


    (PROG (Menu Answer)
          (if (FMEMB Property (QUOTE (--DONE-- --CANCEL--)))
	      then (CLOSEW InspectWin)
		   (if ValueFlg
		       then (PUTPROP (QUOTE NC.MakeDocParameters)
				     (QUOTE --DONE--)
				     (QUOTE QUIT)))
		   (RETURN NIL))
          (AND ValueFlg (RETURN (INSPECTW.SELECTITEM InspectWin)))
          (SETQ Menu (create MENU
			     ITEMS ←(CDR (FASSOC Property NC.MakeDocParameters))
			     TITLE ← "Choose New Value"))
          (SETQ Answer (MENU Menu))
          (COND
	    ((AND Answer (OR (NEQ Answer (QUOTE Select))
			     (SETQ Answer (NC.AskLinkLabel InspectWin T T NIL NIL T))))
	      (PUTPROP (QUOTE NC.MakeDocParameters)
		       Property Answer)
	      (INSPECTW.REDISPLAY InspectWin Property)))
          (INSPECTW.SELECTITEM InspectWin))))

(NC.AppendStringToStream
  (LAMBDA (Stream String BoldFlg)                            (* rht: "16-Nov-84 12:38")

          (* * Add the String to the end of the tedit Stream.)



          (* * rht 11/16/84: Now calls TEDIT.LOOKS in any case, bold or no.)


    (PROG ((StrLen (NCHARS String)))
          (TEDIT.INSERT Stream String (TEDIT.SETSEL Stream (fetch (TEXTOBJ TEXTLEN)
							      of (TEXTOBJ Stream))
						    0
						    (QUOTE RIGHT))
			NIL T)
          (TEDIT.LOOKS Stream (if BoldFlg
				  then (QUOTE (FACE BRR))
				else (QUOTE (FACE MRR)))
		       (ADD1 (IDIFFERENCE (fetch (TEXTOBJ TEXTLEN) of (TEXTOBJ Stream))
					  StrLen))
		       StrLen))))

(NC.MakeBrowserCard
  (LAMBDA (ID Title NoDisplayFlg ListOfRootIDAndListOfLinkLabels)
                                                             (* rht: "17-Nov-84 15:59")

          (* Make a browser card with id ID using root at RootID and the link following predictae specified by Predicate.
	  IF Root and/or ListOfLinkLabels not specified, ask the user.)



          (* * rht 8/3/84: Changed to call NC.AskLinkLabel with its ReverseLinkLabel parameter set to T.)



          (* * fgh 10/2/84 Changed Link Icons to be image objects in NodeLabel of Graph Npodes rather than annotations on 
	  graph nodes.)



          (* * rht 10/19/84: Fixed setting up of browser card's prop list in case NoDisplayFlg is T so we have no Window.
	  Now NC.MakeLinksLegend returns the label pairs.)


    (PROG (Lattice Window Graph PropList BrowserSpecs (RootID (CAR ListOfRootIDAndListOfLinkLabels))
		   (ListOfLinkLabels (CADR ListOfRootIDAndListOfLinkLabels))
		   LabelPairs)
          (NC.ActivateCard ID)
          (OR NoDisplayFlg (SETQ Window (CREATEW (GETBOXREGION NC.BrowserCardDefaultWidth 
							       NC.BrowserCardDefaultHeight (GETMOUSEX)
							       (IDIFFERENCE (GETMOUSEY)
									    
								      NC.BrowserCardDefaultHeight)
							       NIL 
					   "Please indicate where to place the new browser card.")
						 (NC.FetchTitle ID)
						 NIL)))
          (SETQ RootID (OR RootID (PROGN (NC.PrintMsg Window T 
			 "Please select the Note Card or File Box the browser should start from."
						      (CHARACTER 13))
					 (NC.SelectNoteCards T NIL NC.SelectingBrowserSourceMenu 
							     Window))))
          (COND
	    ((NULL RootID)
	      (NC.DeactivateCard ID)
	      (CLOSEW Window)
	      (RETURN)))
          (OR ListOfLinkLabels (SETQ ListOfLinkLabels (NC.AskLinkLabel Window T T NIL NIL T))
	      (PROGN (NC.PrintMsg Window T "Defaulting to SubBox pointers." (CHARACTER 13))
		     (SETQ ListOfLinkLabels NC.SubBoxLinkLabel)))
          (SETQ BrowserSpecs (COND
	      (NC.SpecialBrowserSpecsFlg (NC.AskBrowserSpecs Window))
	      (T (create BrowserSpecs))))
          (OR NoDisplayFlg (NC.PrintMsg Window NIL (CHARACTER 13)
					"Computing browser graph. Please wait. ..."))
          (SETQ Lattice (CDR (NC.GrowLinkLattice RootID (LIST NIL)
						 ListOfLinkLabels ID PSA.Database)))
          (SETQ LabelPairs (NC.MakeLinksLegend Lattice Window))
          (OR NoDisplayFlg (WINDOWPROP Window (QUOTE NoteCardID)
				       ID))
          (OR NoDisplayFlg (WINDOWADDPROP Window (QUOTE CLOSEFN)
					  (FUNCTION NC.GraphCardCloseFn)
					  T))

          (* * Link destination id information stored in NodeLabel field into a LinkIcon for display)


          (for Node in Lattice do (replace (GRAPHNODE NODELABEL) of Node
				     with (NC.MakeLinkIcon (NC.MakeLink Window 
								      NC.BrowserContentsLinkLabel
									(fetch (GRAPHNODE NODELABEL)
									   of Node)
									ID NIL))))
          (SETQ Graph (LAYOUTGRAPH Lattice (LIST (CAAR Lattice))
				   (fetch (BrowserSpecs Format) of BrowserSpecs)
				   (fetch (BrowserSpecs Font) of BrowserSpecs)
				   (fetch (BrowserSpecs MotherD) of BrowserSpecs)
				   (fetch (BrowserSpecs PersonalD) of BrowserSpecs)
				   (fetch (BrowserSpecs FamilyD) of BrowserSpecs)))
          (OR NoDisplayFlg (NC.PrintMsg Window NIL "Done!"))
          (NC.SetSubstance ID Graph)
          (SETQ PropList (NC.FetchPropList ID))
          (COND
	    (PropList (LISTPUT PropList (QUOTE BrowserLinkLabels)
			       (LIST (OR ListOfLinkLabels NC.SubBoxLinkLabel))))
	    (T (NC.SetPropList ID (SETQ PropList (LIST (QUOTE BrowserLinkLabels)
						       (LIST (OR ListOfLinkLabels NC.SubBoxLinkLabel))
						       )))))
          (LISTPUT PropList (QUOTE BrowserRoot)
		   RootID)
          (LISTPUT PropList (QUOTE BrowserLinksLegend)
		   LabelPairs)
          (AND NC.SpecialBrowserSpecsFlg (LISTPUT PropList (QUOTE BrowserSpecs)
						  (LIST BrowserSpecs)))
          (NC.SetPropListDirtyFlg ID T)
          (COND
	    (NoDisplayFlg (RETURN ID)))
          (replace (GRAPH GRAPH.ADDNODEFN) of Graph with (FUNCTION NC.GraphAddNodeFn))
          (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
		     (FUNCTION NC.GraphCardMiddleButtonFn)
		     NIL T)
          (NC.SetupTitleBarMenu Window ID)
          (NC.ClearMsg Window T)
          (RETURN Window))))

(NC.BringUpBrowserCard
  (LAMBDA (ID Substance Region/Position)                     (* rht: "17-Nov-84 16:05")

          (* * Given a browser Substance, open a browser window and set it up to be a NoteCard with ID.)



          (* * rht 11/17/84: Now returns window.)


    (PROG (Window)
          (SETQ Window (NC.BringUpGraphCard ID Substance Region/Position))
          (if (NOT (for AttachedWin in (ATTACHEDWINDOWS Window) thereis (WINDOWPROP AttachedWin
										    (QUOTE 
										     NCLABELPAIRS))))
	      then (NC.MakeLinksLegendMenu Window (LISTGET (NC.RetrievePropList ID)
							   (QUOTE BrowserLinksLegend))))
          (RETURN Window))))

(NCP.CreateBrowserCard
  (LAMBDA (Title RootID LinkLabels NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "15-Nov-84 20:03")

          (* * Creates a new browser notecard with given type, title, props, parents, starting ID and link labels.
	  LinkLabels can be atom or list and can contain litatoms ALL and/or ←ALL.)


    (PROG (ValidLinkLabels)
          (SETQ ValidLinkLabels (for Label in (MKLIST LinkLabels) join (COND
									 ((EQ Label (QUOTE ALL))
									   (NCP.GetLinkLabels))
									 ((EQ Label (QUOTE ←ALL))
									   (NCP.GetReverseLinkLabels))
									 ((NOT (NCP.ValidLinkLabel
										 Label))
									   (NCP.ReportError Label 
								       " not a valid link label.")
									   NIL)
									 (T (LIST Label)))))
          (SETQ ValidLinkLabels (INTERSECTION ValidLinkLabels ValidLinkLabels))
          (RETURN (if (AND LinkLabels (NULL ValidLinkLabels))
		      then NIL
		    else (NCP.CreateCard (QUOTE Browser)
					 Title NoDisplayFlg Props ParentFileBoxes (LIST RootID 
										  ValidLinkLabels)))))
    ))

(NCP.DeleteCards
  (LAMBDA (IDs)                                              (* rht: "16-Nov-84 12:09")

          (* * Delete the given cards and boxes. Or just one, if IDs is atomic.)


    (SETQ IDs (for ID in (MKLIST IDs) unless (if (NOT (NCP.ValidID ID))
						 then (NCP.ReportError ID 
							       " is not an existing card or box.")
						      T)
		 collect ID))
    (AND IDs (NC.DeleteNoteCards IDs T))))

(NC.FileBoxCollectChildren
  (LAMBDA (WindowOrTextStream ID NewChildren NoDisplayFlg)   (* rht: "15-Nov-84 16:13")

          (* * Ask user for new children (either cards or fileboxes) for this filebox. Check to make sure that no 
	  circularities are introduced. This code is sort of the inverse of the NC.AddParents code and thus looks quite 
	  similar.)



          (* * rht 10/29/84: Added NoDisplayFlg to prevent error message when no appropriate elements exist.
	  Also now returns ID if at least one child was added, NIL otherwise.)


    (PROG (OneHook Window ReturnVal)
          (COND
	    (WindowOrTextStream (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))))
          (OR ID (SETQ ID (NC.IDFromWindow Window)))
          (COND
	    (NewChildren)
	    (T (NC.PrintMsg Window T " Please select new children." (CHARACTER 13))
	       (SETQ NewChildren (NC.SelectNoteCards NIL NIL NC.SelectingFileBoxChildrenMenu ID))))
          (AND NewChildren ID (for NewChildID in NewChildren
				 do (COND
				      ((for Link in (NC.FetchToLinks ID)
					  thereis (AND (NC.ChildLinkP Link)
						       (EQ NewChildID (fetch (NOTECARDLINK 
										    DESTINATIONID)
									 of Link))))
					(NC.PrintMsg Window NIL (NC.RetrieveTitle NewChildID 
										  PSA.Database)
						     " is already a child of "
						     (NC.RetrieveTitle ID PSA.Database)
						     (CHARACTER 13)))
				      ((AND (NEQ ID NewChildID)
					    (NC.NotDaughterP NewChildID ID (FUNCTION NC.ChildLinkP)))
					(NC.MakeAContentsHook ID NewChildID
							      (COND
								((EQ (NC.RetrieveType NewChildID 
										     PSA.Database)
								     (QUOTE FileBox))
								  (QUOTE Sub))
								(T NIL))
							      PSA.Database)
					(SETQ OneHook T))
				      (T (NC.PrintMsg Window T (NC.RetrieveTitle NewChildID 
										 PSA.Database)
						      " is a parent of "
						      (NC.RetrieveTitle ID PSA.Database)
						      (CHARACTER 13))))))
          (if (NULL OneHook)
	      then (OR NoDisplayFlg (NC.PrintMsg Window NIL 
						 "No appropriate NoteCards or FileBoxes chosen."
						 (CHARACTER 13)
						 "Hence no children added."
						 (CHARACTER 13)))
		   (SETQ ReturnVal NIL)
	    else (SETQ ReturnVal ID))
          (AND Window (GETPROMPTWINDOW Window NIL NIL T)
	       (PROG1 (DISMISS 1000)
		      (NC.ClearMsg Window T)))
          (RETURN ReturnVal))))

(NC.ChooseTopLevelCard
  (LAMBDA NIL                                                (* rht: "16-Nov-84 10:24")

          (* Let the user choose one of the top level cards. Top level cards are specified by globalvar NC.TopLevelCards which
	  is a list of IDs)


    (PROG (ID Menu W Z)
          (SETQ Menu (create MENU
			     ITEMS ←(for CardID in NC.TopLevelCards collect (LIST (NC.RetrieveTitle
										    CardID 
										    PSA.Database)
										  CardID))
			     CENTERFLG ← T
			     MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
						   10
						   (QUOTE BOLD))
			     WHENSELECTEDFN ←(FUNCTION (LAMBDA (Item Button Menu)
				 (NC.EditNoteCard (CADR Item))))
			     TITLE ← "FileBox?"))
          (SETQ W (MENUITEMREGION (CAR (NTH (fetch (MENU ITEMS) of NC.MainMenu)
					    4))
				  NC.MainMenu))
          (SETQ Z (WINDOWPROP (WFROMMENU NC.MainMenu)
			      (QUOTE REGION)))
          (replace (MENU MENUPOSITION) of Menu with (create POSITION
							    XCOORD ←(IPLUS (fetch (REGION LEFT)
									      of W)
									   (fetch (REGION LEFT)
									      of Z))
							    YCOORD ←(IPLUS
							      (fetch (REGION TOP) of W)
							      (fetch (REGION BOTTOM) of Z)
							      (IMINUS (fetch (MENU IMAGEHEIGHT)
									 of Menu)))))
          (SETQ ID (MENU Menu)))))

(NC.MakeCardTypesList
  (LAMBDA NIL                                                (* rht: "16-Nov-84 17:31")

          (* * Make initial set of card types.)


    (SETQ NC.CardTypes (LIST (create NoteCardType
				     TypeName ←(QUOTE NoteCard)
				     SuperType ← NIL
				     SubstanceType ← NIL
				     MakeCardFn ← NIL
				     EditCardFn ← NIL
				     QuitCardFn ← NIL
				     GetCardFn ← NIL
				     PutCardFn ← NIL
				     CopyCardFn ← NIL
				     MarkCardDirtyFn ← NIL
				     CardDirtyPFn ← NIL
				     CollectLinksInCardFn ← NIL
				     DeleteLinksInCardFn ← NIL
				     UpdateLinkIconsInCardFn ← NIL
				     LinkDisplayMode ←(QUOTE Icon))))
    (NC.AddCardType (QUOTE Text)
		    (QUOTE NoteCard)
		    (QUOTE TEXT)
		    (FUNCTION NC.MakeTEditCard)
		    NIL
		    (FUNCTION NC.TEditCloseFn)
		    NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Icon))
    (NC.AddCardType (QUOTE Graph)
		    (QUOTE NoteCard)
		    (QUOTE GRAPH)
		    (FUNCTION NC.MakeGraphCard)
		    NIL
		    (FUNCTION NC.GraphCardCloseFn)
		    NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Title))
    (NC.AddCardType (QUOTE Sketch)
		    (QUOTE NoteCard)
		    (QUOTE SKETCH)
		    (FUNCTION NC.MakeSketchCard)
		    NIL
		    (FUNCTION NC.SketchCardCloseFn)
		    NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Icon))
    (NC.AddCardType (QUOTE FileBox)
		    (QUOTE Text)
		    (QUOTE TEXT)
		    (FUNCTION NC.MakeContentsCard)
		    NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Title))
    (NC.AddCardType (QUOTE Browser)
		    (QUOTE Graph)
		    (QUOTE GRAPH)
		    (FUNCTION NC.MakeBrowserCard)
		    (FUNCTION NC.BringUpBrowserCard)
		    NIL NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Title))
    (NC.AddCardType (QUOTE Search)
		    (QUOTE Text)
		    (QUOTE TEXT)
		    (FUNCTION NC.MakeSearchCard)
		    NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Title))
    (NC.AddCardType (QUOTE LinkIndex)
		    (QUOTE Text)
		    (QUOTE TEXT)
		    (FUNCTION NC.MakeLinkIndex)
		    NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Title))
    (NC.AddCardType (QUOTE Document)
		    (QUOTE Text)
		    (QUOTE TEXT)
		    (FUNCTION NC.MakeDocument)
		    NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL (QUOTE Icon))
    (SETQ NC.NoteCardTypeMenu)))

(NC.DelReferencesToCardFromGraph
  (LAMBDA (SourceID LinkOrDestinationID)                     (* rht: "17-Nov-84 18:05")
                                                             (* Delete from the graph specified by Graph all link 
							     icon nodes whose DESTINATIONID is eq to DestinationID)

          (* * rht 11/17/84: Now only redisplays graph if ID is both active *and* has a window.)


    (PROG ((ImageBox (NC.DeletedLinkImageBoxFn NC.DeletedLinkImageObject))
	   LinkIcon
	   (LinkFlg (type? NOTECARDLINK LinkOrDestinationID))
	   LinkID DestinationID Graph)
          (COND
	    (LinkFlg (SETQ LinkID (fetch (NOTECARDLINK LINKID) of LinkOrDestinationID))
		     (OR (NC.IDP SourceID)
			 (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of LinkOrDestinationID))))
	    (T (SETQ DestinationID LinkOrDestinationID)))
          (SETQ Graph (NC.FetchSubstance SourceID))
          (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
	     when (AND (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
							       of GraphNode)))
		       (COND
			 (LinkFlg (EQ LinkID (fetch (NOTECARDLINK LINKID) of (NC.FetchLinkFromLinkIcon
									       LinkIcon))))
			 (T (EQ (fetch (NOTECARDLINK DESTINATIONID) of (NC.FetchLinkFromLinkIcon
									 LinkIcon))
				DestinationID))))
	     do (replace (GRAPHNODE NODELABEL) of GraphNode with NC.DeletedLinkImageObject)
		(replace (GRAPHNODE NODEWIDTH) of GraphNode with (fetch (IMAGEBOX XSIZE)
								    of ImageBox))
		(replace (GRAPHNODE NODEHEIGHT) of GraphNode with (fetch (IMAGEBOX YSIZE)
								     of ImageBox)))
          (if (AND (NC.ActiveCardP SourceID)
		   (NC.FetchWindow SourceID))
	      then (REDISPLAYGRAPH (NC.FetchWindow SourceID))))))

(NC.RelabelLink
  (LAMBDA (LinkOrLinkIcon Window NewLinkLabel ForceRedisplayFlg)
                                                             (* rht: "19-Nov-84 02:26" pp pp)
                                                             (* Relabel a NoteCard link. Ask user for new label.
							     Update all the proper references to this link.)

          (* * rht 11/19/84: Fixed so that ID is defined before first use.)


    (PROG (Link LinkIcon LinkID ID DestinationID OldLabel NoteCardType GlobalLinkFlg)
          (COND
	    ((NC.LinkIconImageObjP LinkOrLinkIcon)
	      (SETQ Link (NC.FetchLinkFromLinkIcon LinkOrLinkIcon))
	      (SETQ LinkIcon LinkOrLinkIcon))
	    (T (SETQ Link LinkOrLinkIcon)
	       (COND
		 ((NOT (SETQ GlobalLinkFlg (NC.GlobalLinkP Link)))
		   (SETQ LinkIcon (NC.FetchLinkIconForLink Link))))))
          (SETQ ID (fetch (NOTECARDLINK SOURCEID)
			  from Link))
          (COND
	    ((WINDOWP Window))
	    ((NC.ActiveCardP ID)
	      (SETQ Window (NC.FetchWindow ID))))
          (COND
	    ((NC.SystemLinkLabelP (fetch (NOTECARDLINK LINKLABEL) of Link))
	      (NC.PrintMsg Window T "This is a system maintained pointer." (CHARACTER 13)
			   "You cannot change its label."
			   (CHARACTER 13))
	      (SPAWN.MOUSE)
	      (DISMISS 1500)
	      (NC.ClearMsg Window T))
	    ((SETQ NewLinkLabel (OR NewLinkLabel (NC.AskLinkLabel Window NIL NIL T T)))
	      (SETQ DestinationID (fetch (NOTECARDLINK DESTINATIONID) of Link))
	      (SETQ LinkID (fetch (NOTECARDLINK LINKID) of Link))
	      (SETQ NoteCardType (NC.FetchType ID))

          (* * Put new label in Link Icon or global links list)


	      (COND
		(GlobalLinkFlg (for GlobalLink in (NC.FetchGlobalLinks ID)
				  when (EQ (fetch (NOTECARDLINK LINKID) of GlobalLink)
					   LinkID)
				  do (replace (NOTECARDLINK LINKLABEL) of GlobalLink with 
										     NewLinkLabel)
				     (NC.SetLinksDirtyFlg ID T)
				     (RETURN)))
		(T (replace (NOTECARDLINK LINKLABEL) of (NC.FetchLinkFromLinkIcon LinkIcon)
		      with NewLinkLabel)
		   (NC.MarkCardDirty ID)))

          (* * Update ToLink list of the SourceID card)


	      (for ToLink in (NC.FetchToLinks ID) when (EQ (fetch (NOTECARDLINK LINKID) of ToLink)
							   LinkID)
		 do (replace (NOTECARDLINK LINKLABEL) of ToLink with NewLinkLabel)
		    (NC.SetLinksDirtyFlg ID T)
		    (RETURN))

          (* * Update FromLink list of DestinationID card)


	      (COND
		((NC.ActiveCardP DestinationID)
		  (for FromLink in (NC.FetchFromLinks DestinationID)
		     when (EQ (fetch (NOTECARDLINK LINKID) of FromLink)
			      LinkID)
		     do (replace (NOTECARDLINK LINKLABEL) of FromLink with NewLinkLabel)
			(NC.SetLinksDirtyFlg DestinationID T)
			(RETURN)))
		(T (WITH.MONITOR (NC.FetchMonitor PSA.Database)
				 (NC.GetLinks DestinationID PSA.Database)
				 (for FromLink in (NC.FetchFromLinks DestinationID)
				    when (EQ (fetch (NOTECARDLINK LINKID) of FromLink)
					     LinkID)
				    do (replace (NOTECARDLINK LINKLABEL) of FromLink with 
										     NewLinkLabel)
				       (NC.SetLinksDirtyFlg DestinationID T)
				       (RETURN))
				 (NC.PutLinks DestinationID PSA.Database)
				 (NC.DeactivateCard DestinationID))))

          (* * Update images in SourceID window)


	      (COND
		((AND (NULL ForceRedisplayFlg)
		      (NC.TEditBasedP NoteCardType))
		  (RETURN (QUOTE CHANGED)))
		((WINDOWP Window)
		  (NC.UpdateLinkImages Window (fetch (NOTECARDLINK DESTINATIONID) of Link))
		  (RETURN NIL))
		(T (RETURN NIL))))))))

(NC.DelReferencesToCardFromGlobalList
  (LAMBDA (SourceID LinkOrDestinationID DatabaseStream)      (* rht: "19-Nov-84 22:53")

          (* The card or link specified by DestinationID is being deleted. Remove all references to it from the global links 
	  list of the card specified by SourceID)



          (* * rht 11/19/84: Fixed a naming typo changing ID to SourceID everywhere. Also fixed DestinationID arg to be 
	  LinkOrDestinationID.)


    (COND
      ((NC.ActiveCardP SourceID)
	(NC.SetGlobalLinks SourceID (for Link in (NC.FetchGlobalLinks SourceID)
				       when (if (NC.IDP LinkOrDestinationID)
						then (NEQ LinkOrDestinationID (fetch (NOTECARDLINK
										       DESTINATIONID)
										 of Link))
					      else (NEQ (fetch (NOTECARDLINK LINKID) of 
									      LinkOrDestinationID)
							(fetch (NOTECARDLINK LINKID) of Link)))
				       collect Link)))
      (T (WITH.MONITOR (NC.FetchMonitor DatabaseStream)
		       (NC.GetLinks SourceID DatabaseStream)
		       (NC.SetGlobalLinks SourceID (for Link in (NC.FetchGlobalLinks SourceID)
						      when (if (NC.IDP LinkOrDestinationID)
							       then (NEQ LinkOrDestinationID
									 (fetch (NOTECARDLINK 
										    DESTINATIONID)
									    of Link))
							     else (NEQ (fetch (NOTECARDLINK LINKID)
									  of LinkOrDestinationID)
								       (fetch (NOTECARDLINK LINKID)
									  of Link)))
						      collect Link))
		       (NC.PutLinks SourceID DatabaseStream))))))
)
(PUTPROP (QUOTE NC.MakeDocParameters)
	 (QUOTE --DONE--)
	 (QUOTE --CANCEL--))
(DEFINEQ

(NC.LinkIconWhenDeletedFn
  (LAMBDA (ImageObject Stream)                               (* rht: "19-Nov-84 23:26")

          (* * When deleting a link icon image object from a card, make sure the link information on the source and 
	  destinmation cards get updated. When deleting a link image object from a prop list editor, just inform the user that
	  this is a useless operation.)



          (* * rht 11/19/84: Now handles the case when a move is in progress. True if the old link is cached on the ImageObj.
	  Also changed so that SourceID is computed from ImageObject rather than from Stream. Similarly for the window.)


    (PROG (Link SourceID DestinationID LinkType Window)
          (SETQ Link (NC.FetchLinkFromLinkIcon ImageObject))
          (COND
	    ((SETQ OldLink (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)))
	      (NC.DelFromLink OldLink PSA.Database)
	      (NC.DelToLink OldLink PSA.Database)
	      (replace (NOTECARDLINK LINKID) of OldLink with -1)
	      (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
			    NIL))
	    ((NC.IDP (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of Link)))
	      (SETQ DestinationID (fetch (NOTECARDLINK DESTINATIONID) of Link))
	      (NC.CheckForOrphanDelete SourceID DestinationID)
	      (NC.DelFromLink Link PSA.Database)
	      (NC.DelToLink Link PSA.Database)
	      (replace (NOTECARDLINK LINKID) of Link with -1))
	    ((AND (SETQ Window (NC.FetchWindow SourceID))
		  (WINDOWPROP Window (QUOTE PropListEditor)))
	      (NC.PrintMsg Window T "Note:" (CHARACTER 13)
			   "Deleting a pointer from this list does NOT"
			   (CHARACTER 13)
			   "delete the pointer from the card."
			   (CHARACTER 13))
	      (ADD.PROCESS (LIST (QUOTE PROGN)
				 (QUOTE (DISMISS 5000))
				 (LIST (QUOTE AND)
				       (LIST (QUOTE OPENWP)
					     Window)
				       (LIST (QUOTE GETPROMPTWINDOW)
					     Window NIL NIL T)
				       (LIST (QUOTE NC.ClearMsg)
					     Window T)))))))))

(NC.LinkIconWhenCopiedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "19-Nov-84 21:56")

          (* * Called when copying a link icon from FromTextStream to ToWindowStream. Sets the necessary link information up 
	  for card corresponding to ToWindowStream.)



          (* * rht 11/18/84: Major hacking. Now checks for all sorts of illegal cases. Either goes ahead with copy, converts 
	  link type to "Unspecified", or deletes the new "invisible" link. The latter will change when imageobj fns can return
	  DON'T.)


    (PROG (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		 SourceID DestID NewSourceID NewLabel NewDisplayMode ImageObjectCopy)
          (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link))
          (SETQ NewSourceID (NC.CoerceToID ToTextStream))
          (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of Link))
          (SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link))
          (SETQ ImageObjectCopy (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)))
          (COND
	    ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		  (NEQ (NC.FetchType NewSourceID)
		       (QUOTE FileBox)))                     (* Copy from filebox to non-filebox.)
	      (NC.PrintMsg NIL NIL (CONCAT "Tried to copy filedcard or subbox link to a non-filebox."
					   (CHARACTER 13)
					   "Link type of copy set to 'Unspecified'."
					   (CHARACTER 13)))
	      (SETQ NewLabel NC.UnspecifiedLinkLabel)
	      (SETQ NewDisplayMode (QUOTE Both)))
	    ((AND (NEQ (NC.FetchType SourceID)
		       (QUOTE FileBox))
		  (EQ (NC.FetchType NewSourceID)
		      (QUOTE FileBox)))                      (* Copy from non-filebox to filebox.)
	      (NC.PrintMsg NIL NIL (CONCAT "Can't copy links from non-filebox to filebox."
					   (CHARACTER 13)
					   "Try using CollectChildren."
					   (CHARACTER 13)))
	      (RETURN (NC.CopiedImageObjAddProcess ImageObjectCopy ToTextStream)))
	    ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		  (EQ NewSourceID SourceID))                 (* Copy within same filebox.)
	      (NC.PrintMsg NIL NIL (CONCAT "Can't copy links within a FileBox.  Try move instead."
					   (CHARACTER 13)))
	      (RETURN (NC.CopiedImageObjAddProcess ImageObjectCopy ToTextStream)))
	    ((AND (EQ (NC.FetchType NewSourceID)
		      (QUOTE FileBox))
		  (for Link1 in (NC.FetchToLinks NewSourceID)
		     thereis (AND (NC.ChildLinkP Link1)
				  (EQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link1)))))
                                                             (* Copy to a filebox already containing this child.)
	      (NC.PrintMsg NIL NIL (CONCAT (NC.RetrieveTitle DestID PSA.Database)
					   " not copied: already appears as a child of "
					   (NC.RetrieveTitle NewSourceID PSA.Database)
					   (CHARACTER 13)))
	      (RETURN (NC.CopiedImageObjAddProcess ImageObjectCopy ToTextStream)))
	    ((AND (EQ Label (QUOTE SubBox))
		  (OR (EQ NewSourceID DestID)
		      (NOT (NC.NotDaughterP DestID NewSourceID (FUNCTION NC.ChildLinkP)))))
                                                             (* Copy to a filebox causes a cycle.)
	      (NC.PrintMsg NIL NIL (CONCAT "Couldn't copy " Link " because of subbox cycle."
					   (CHARACTER 13)))
	      (RETURN (NC.CopiedImageObjAddProcess ImageObjectCopy ToTextStream)))
	    ((AND (FMEMB Label NC.SystemLinkLabels)
		  (NOT (FMEMB Label (QUOTE (FiledCard SubBox))))
		  (NEQ NewSourceID SourceID))                (* Copy of system link outside of own card.)
	      (NC.PrintMsg NIL NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
					   "Link type of copy set to 'Unspecified'."
					   (CHARACTER 13)))
	      (SETQ NewLabel NC.UnspecifiedLinkLabel)
	      (SETQ NewDisplayMode (QUOTE Both))))
          (NC.FillInLinkIcon ImageObjectCopy (OR NewLabel Label)
			     DestID NewSourceID (OR NewDisplayMode (fetch (NOTECARDLINK DISPLAYMODE)
								      of Link))))))

(NC.LinkIconWhenMovedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "19-Nov-84 22:27")

          (* * Called when moving a link icon from FromTextStream to ToWindowStream. Sets the necessary link information up 
	  for card corresponding to ToWindowStream.)



          (* * rht 11/18/84: Major hacking. Now checks for all sorts of illegal cases. Either goes ahead with move, converts 
	  link type to "Unspecified", or deletes the new "invisible" link. The code is very similar to NC.LinkIconWhenCopiedFn
	  except that within-filebox moves are allowed. Also when aborting a move, we must insert a copy of the link back to 
	  take the place of the deleted original. This will all change when imageobj fns can return DON'T.)


    (PROG (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		 SourceID DestID NewSourceID NewLabel NewDisplayMode)
          (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link))
          (SETQ NewSourceID (NC.CoerceToID ToTextStream))
          (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of Link))
          (SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link))
          (COND
	    ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		  (NEQ (NC.FetchType NewSourceID)
		       (QUOTE FileBox)))                     (* Move from filebox to non-filebox.)
	      (NC.PrintMsg NIL NIL (CONCAT "Tried to move filedcard or subbox link to a non-filebox."
					   (CHARACTER 13)
					   "Link type of copy set to 'Unspecified'."
					   (CHARACTER 13)))
	      (SETQ NewLabel NC.UnspecifiedLinkLabel)
	      (SETQ NewDisplayMode (QUOTE Both)))
	    ((AND (NEQ (NC.FetchType SourceID)
		       (QUOTE FileBox))
		  (EQ (NC.FetchType NewSourceID)
		      (QUOTE FileBox)))                      (* Move from non-filebox to filebox.)
	      (NC.PrintMsg NIL NIL (CONCAT "Can't move links from non-filebox to filebox."
					   (CHARACTER 13)
					   "Try using CollectChildren."
					   (CHARACTER 13)))
	      (RETURN (NC.MovedImageObjAddProcess ImageObject FromTextStream ToTextStream)))
	    ((AND (EQ (NC.FetchType NewSourceID)
		      (QUOTE FileBox))
		  (NEQ NewSourceID SourceID)
		  (for Link1 in (NC.FetchToLinks NewSourceID)
		     thereis (AND (NC.ChildLinkP Link1)
				  (EQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link1)))))
                                                             (* Move to a filebox already containing this child.)
	      (NC.PrintMsg NIL NIL (CONCAT (NC.RetrieveTitle DestID PSA.Database)
					   " not moved: already appears as a child of "
					   (NC.RetrieveTitle NewSourceID PSA.Database)
					   (CHARACTER 13)))
	      (RETURN (NC.MovedImageObjAddProcess ImageObject FromTextStream ToTextStream)))
	    ((AND (EQ Label (QUOTE SubBox))
		  (NEQ NewSourceID SourceID)
		  (OR (EQ NewSourceID DestID)
		      (NOT (NC.NotDaughterP DestID NewSourceID (FUNCTION NC.ChildLinkP)))))
                                                             (* Move to a filebox causes a cycle.)
	      (NC.PrintMsg NIL NIL (CONCAT "Couldn't move " Link " because of subbox cycle."
					   (CHARACTER 13)))
	      (RETURN (NC.MovedImageObjAddProcess ImageObject FromTextStream ToTextStream)))
	    ((AND (FMEMB Label NC.SystemLinkLabels)
		  (NOT (FMEMB Label (QUOTE (FiledCard SubBox))))
		  (NEQ NewSourceID SourceID))                (* Move of system link outside of own card.)
	      (NC.PrintMsg NIL NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
					   "Link type of copy set to 'Unspecified'."
					   (CHARACTER 13)))
	      (SETQ NewLabel NC.UnspecifiedLinkLabel)
	      (SETQ NewDisplayMode (QUOTE Both))))
          (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
			Link)
          (NC.FillInLinkIcon ImageObject (OR NewLabel Label)
			     DestID NewSourceID (OR NewDisplayMode (fetch (NOTECARDLINK DISPLAYMODE)
								      of Link))))))

(NC.LinkIconCopyFn
  (LAMBDA (ImageObject)                                      (* rht: "19-Nov-84 21:16")

          (* * Return a copy of image object. IF it is a system link label, then make its label unspecified.)



          (* * rht 11/18/84: No longer worries about system link labels. All that is handled by WhenCopiedFn and WhenMovedFn.
	  Caches the new copy on the prop list of the original imageobj.)


    (PROG ((ImageObjectCopy (IMAGEOBJCREATE (fetch (NOTECARDLINK LINKID) of (NC.FetchLinkFromLinkIcon
									      ImageObject))
					    NC.InvisibleLinkImageFns)))
          (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)
			ImageObjectCopy)
          (RETURN ImageObjectCopy))))

(NC.FillInLinkIcon
  (LAMBDA (ImageObj Label DestID SourceID DisplayMode)       (* rht: "19-Nov-84 14:43")

          (* * Called by WhenCopiedFn and WhenMovedFn to build the new link and stick it in the ImageObj.)


    (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)
		  (NC.MakeLink NIL Label DestID SourceID DisplayMode))
    (replace (IMAGEOBJ IMAGEOBJFNS) of ImageObj with NC.LinkIconImageFns)))

(NC.InsertImageObjCopy
  (LAMBDA (ImageObj TextStream CH#)                          (* rht: "19-Nov-84 17:56")

          (* * Make a copy of ImageObj and stick at CH# in TextStream.)


    (TEDIT.INSERT.OBJECT (NCREATE (QUOTE IMAGEOBJ)
				  ImageObject)
			 TextStream CH#)))

(NC.DeleteImageObj
  (LAMBDA (ImageObj TextStream)                              (* rht: "19-Nov-84 17:11")

          (* * Delete first occurrence of ImageObj from TextStream.)


    (for Obj in (TEDIT.LIST.OF.OBJECTS (TEXTOBJ TextStream)
				       (FUNCTION IMAGEOBJP))
       when (EQ ImageObj (CAR Obj)) do (RETURN (TEDIT.DELETE TextStream (CADR Obj)
							     1)))))

(NC.CopiedImageObjAddProcess
  (LAMBDA (ImageObjCopy TextStream)                          (* rht: "19-Nov-84 18:09")

          (* * Add a process that will delete the copied image object.)


    (ADD.PROCESS (BQUOTE (NC.DeleteImageObj , ImageObjCopy , TextStream)))))

(NC.MovedImageObjAddProcess
  (LAMBDA (ImageObj FromTextStream ToTextStream)             (* rht: "19-Nov-84 21:55")

          (* * Add a process which deletes the copy of the image obj in the ToTextStream and adds a copy of the original back 
	  in the FromTextStream.)


    (ADD.PROCESS (BQUOTE (PROGN (NC.InsertImageObjCopy , ImageObj , FromTextStream ,
						       (fetch (SELECTION CH#) of TEDIT.MOVESELECTION))
				(NC.DeleteImageObj , ImageObj , ToTextStream))))))

(NC.Setup
  (LAMBDA (DatabaseFileName)                                 (* rht: "18-Nov-84 20:34")

          (* * rht 11/17/84: Added definition of NC.InvisibleLinkImageObj.)


    (GCGAG NC.GCGAGFlg)
    (SETQ NC.WindowRightButtonMenu (create MENU
					   ITEMS ←(for Item in WindowMenuCommands
						     when (NOT (FMEMB (CAR Item)
								      (QUOTE (Snap Paint Clear))))
						     collect Item)
					   MENUCOLUMNS ← 1
					   CENTERFLG ← T
					   MENUFONT ←(QUOTE (HELVETICA 10))))
    (UNADVISE DOWINDOWCOM)
    (ADVISE (QUOTE DOWINDOWCOM)
	    (QUOTE AROUND)
	    (QUOTE (AND (OR (NEQ WINDOW NC.MainMenuWindow)
			    (NOT NC.FixedMenuFlg))
			(COND
			  ((AND NC.ShortWindowMenuFlg (NC.IDP (NC.IDFromWindow WINDOW)))
			    (RESETLST (RESETSAVE WindowMenu NC.WindowRightButtonMenu)*))
			  (T *)))))
    (SETQ UseMapWithPoliticalBoundaries T)
    (SETQ TEDIT.INPUT.FORMATS NIL)
    (SETQ PSA.NoteCards (QUOTE (NC00002 NC00001)))
    (SETQ PSA.MenuOfNoteCards)
    (SETQ PSA.NoteCardDefaultWidth 400)
    (SETQ PSA.NoteCardDefaultHeight 200)
    (SETQ PSA.ContentsCardDefaultWidth 335)
    (SETQ PSA.ContentsCardDefaultHeight 200)
    (SETQ PSA.GraphCardDefaultWidth 300)
    (SETQ PSA.GraphCardDefaultHeight 200)
    (SETQ PSA.TEditCardDefaultWidth 300)
    (SETQ PSA.TEditCardDefaultHeight 200)
    (SETQ PSA.SketchCardDefaultWidth 400)
    (SETQ PSA.SketchCardDefaultHeight 350)
    (SETQ NC.BrowserCardDefaultWidth 500)
    (SETQ NC.BrowserCardDefaultHeight 350)
    (SETQ PSA.MapSketchType (for SketchType in SKETCH.ELEMENT.TYPES
			       thereis (EQ (fetch (SKETCHTYPE LABEL) of SketchType)
					   (QUOTE Map))))
    (SETQ PSA.TimesRoman10 (FONTCREATE (QUOTE HELVETICA)
				       12))
    (DSPFONT (FONTCREATE (QUOTE HELVETICA)
			 12)
	     PROMPTWINDOW)
    (LINELENGTH 500 PROMPTWINDOW)
    (NC.MakeMainMenu)
    (SETQ NC.LinkIconImageFns (IMAGEFNSCREATE (FUNCTION NC.LinkIconDisplayFn)
					      (FUNCTION NC.LinkIconImageBoxFn)
					      (FUNCTION NC.LinkIconPutFn)
					      (FUNCTION NC.LinkIconGetFn)
					      (FUNCTION NC.LinkIconCopyFn)
					      (FUNCTION NC.LinkIconButtonEventInFn)
					      (FUNCTION NILL)
					      (FUNCTION NC.LinkIconWhenMovedFn)
					      (FUNCTION NC.LinkIconWhenInsertedFn)
					      (FUNCTION NC.LinkIconWhenDeletedFn)
					      (FUNCTION NC.LinkIconWhenCopiedFn)
					      (FUNCTION NILL)
					      (FUNCTION NILL)))
    (SETQ NC.NoDeleteImageFns (PROG ((ImageObj (NC.MakeLinkIcon NIL)))
				    (replace (IMAGEOBJ IMAGEOBJFNS) of ImageObj
				       with (create IMAGEFNS using (fetch (IMAGEOBJ IMAGEOBJFNS)
								      of ImageObj)))
				    (IMAGEOBJPROP ImageObj (QUOTE WHENDELETEDFN)
						  (FUNCTION NILL))
				    (RETURN (fetch (IMAGEOBJ IMAGEOBJFNS) of ImageObj))))
    (COND
      ((GETD (QUOTE INITIALIZEINTERCALC))
	(INITIALIZEINTERCALC)))
    (SETQ NC.DeletedLinkImageObject (IMAGEOBJCREATE "DeletedLink" (IMAGEFNSCREATE
						      (FUNCTION NC.DeletedLinkDisplayFn)
						      (FUNCTION NC.DeletedLinkImageBoxFn)
						      (FUNCTION NC.DeletedLinkPutFn)
						      (FUNCTION NC.DeletedLinkGetFn)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL))))
    (SETQ NC.InvisibleLinkImageFns (IMAGEFNSCREATE (FUNCTION NILL)
						   (FUNCTION NC.InvisibleLinkImageBoxFn)
						   (FUNCTION NC.InvisibleLinkPutFn)
						   (FUNCTION NC.InvisibleLinkGetFn)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)
						   (FUNCTION NILL)))
    (SETQ NC.InvisibleLinkImageObject (IMAGEOBJCREATE "InvisibleLink" NC.InvisibleLinkImageFns))
    (NC.AdjustCloseF)))
)
(DEFINEQ

(NC.InsertLinksInText
  (LAMBDA (TextStream LinkLabel)                             (* rht: "20-Nov-84 00:25")

          (* * Add several links to the text all with the same link label.)


    (PROG (Window SourceID DestinationIDs)
          (SETQ SourceID (NC.IDFromWindow (SETQ Window (WINDOW.FROM.TEDIT.THING TextStream))))
          (NC.PrintMsg Window T "Please select the Cards or Boxes to be pointed to." (CHARACTER
			 13))
          (SETQ DestinationIDs (NC.SelectNoteCards NIL (FUNCTION (LAMBDA (CardID)
						       (COND
							 ((NEQ CardID SourceID)
							   T)
							 (T (NC.PrintMsg (NC.FetchWindow SourceID)
									 T 
							    "A Card/Box cannot point to itself. "
									 (CHARACTER 13)
									 "Selection ignored."
									 (CHARACTER 13))
							    NIL))))
						   NC.SelectingMultipleCardsMenu SourceID))
          (NC.ClearMsg Window T)
          (for DestinationID in DestinationIDs do (NC.InsertLinkInText TextStream LinkLabel 
								       DestinationID SourceID NIL)))))

(NC.AddLinksToTextCard
  (LAMBDA (TextStream)                                       (* rht: "20-Nov-84 00:25")

          (* * Called from a TEXT TEdit window to add multiple links to the text.)


    (PROG ((Label (NC.AskLinkLabel (WINDOW.FROM.TEDIT.THING TextStream)
				   NIL NIL T T)))
          (AND Label (RETURN (NC.InsertLinksInText TextStream Label NIL NIL NIL))))))

(NC.MakeTEditLeftMenu
  (LAMBDA (NoteCardType)                                     (* rht: "20-Nov-84 00:38")

          (* * 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.)


    (\TEDIT.CREATEMENU (OR (AND (BOUNDP (QUOTE NC.TEditMenus))
				(LISTP NC.TEditMenus)
				(LISTGET NC.TEditMenus NoteCardType))
			   (SETQ NC.TEditMenus
			     (COND
			       ((NEQ NoteCardType (QUOTE FileBox))
				 (QUOTE ((Show/Edit% Properties (FUNCTION NC.EditProperties)
								
					"Brings up an editor for the property list of this card."
								(SUBITEMS
								  (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.FileNoteCard 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.FileNoteCard)
									   
						 "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.")))
					  (Close% and% Save (FUNCTION NC.QuitCard)
							    
					  "Close this note card after saving it in the NoteFile."
							    (SUBITEMS (Close% and% Save
									(FUNCTION NC.TEditCloseFn)
									
					  "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.TEditSaveFn)
									
				       "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 ((Show/Edit% Properties
					     (FUNCTION NC.EditProperties)
					     
					"Brings up an editor for the property list of this card."
					     (SUBITEMS (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.")))
					   (Put% in% FileBox (FUNCTION NC.AddParents)
							     
						    "Put this FileBox in new parent FileBox(es).")
					   (Assign% Title (FUNCTION NC.AssignTitle)
							  "Assign a new title to this FileBox.")
					   (Collect% Children (FUNCTION NC.FileBoxCollectChildren)
							      
				       "Collect new child cards and file boxes for this FileBox.")
					   (Close% and% Save (FUNCTION NC.TEditCloseFn)
							     
					  "Close this note card after saving it in the NoteFile."
							     (SUBITEMS (Close% and% Save
									 (FUNCTION NC.TEditCloseFn)
									 
					  "Close this note card after saving it in the NoteFile.")
								       (Save% in% NoteFile
									 (FUNCTION NC.TEditSaveFn)
									 
				       "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.ShowPointers
  (LAMBDA (TextStream)                                       (* rht: "20-Nov-84 00:37")
                                                             (* Open an inspector for the links for note card 
							     specified by TextStream above the window for the note 
							     card.)
    (PROG (Links (ID (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING TextStream))))
          (SETQ Links (NCONC (for Link in (NC.FetchToLinks ID)
				join (LIST (CONCAT (fetch (NOTECARDLINK LINKLABEL) of Link)
						   " TO ")
					   (LIST (create NOTECARDLINK copying Link DISPLAYMODE ←(
										QUOTE Title)))))
			     (for Link in (NC.FetchFromLinks ID)
				join (LIST (CONCAT (fetch (NOTECARDLINK LINKLABEL) of Link)
						   " FROM ")
					   (LIST (create NOTECARDLINK copying Link DISPLAYMODE ←(
										QUOTE Title)
									      SOURCEID ←(fetch
										(NOTECARDLINK 
										    DESTINATIONID)
											   of Link)
									      DESTINATIONID ←(fetch
										(NOTECARDLINK 
											 SOURCEID)
												of
												 Link)
							 ))))))
          (NC.OpenPropListEditor TextStream Links "List of Links" T T))))

(NC.AskLinkLabel
  (LAMBDA (MainWindow MultipleFlg SystemLinksFlg NewLinkFlg CancelOkayFlg ReverseLinksFlg)
                                                             (* rht: "20-Nov-84 00:44")
                                                             (* Asks for label on notecard links)

          (* * rht 8/2/84: Added double columns for when called by the browser, i.e. ReverseLinksFlg=T.
	  Reverse links have prefix "←".)



          (* * rht 11/19/84: Changed strings from "pointer" to "link" and from "label" to "type".)


    (PROG (Menu Choice LabelsList (LinkLabels (NC.RetrieveLinkLabels PSA.Database SystemLinksFlg)))
          (GETPROMPTWINDOW MainWindow 3 (FONTCREATE (QUOTE HELVETICA)
						    10))
          (NC.PrintMsg MainWindow T (COND
			 (MultipleFlg "Please choose link type(s).")
			 (T "Please choose link type."))
		       (CHARACTER 13)
		       "Link types chosen: ")
          (SETQ Menu (create MENU
			     TITLE ←(COND
			       (MultipleFlg "Link Type(s)?")
			       (T "Link Type?"))
			     ITEMS ←(NCONC (COND
					     (ReverseLinksFlg (for Link in LinkLabels
								 join (LIST Link (CONCAT "←" Link))))
					     (T (COPY LinkLabels)))
					   (AND MultipleFlg (LIST (QUOTE --ALL--)))
					   (AND MultipleFlg ReverseLinksFlg (LIST (QUOTE --←ALL--)))
					   (AND MultipleFlg (LIST (QUOTE --DONE--)))
					   (AND NewLinkFlg (LIST (QUOTE --New% Label--)))
					   (AND CancelOkayFlg (LIST (QUOTE **CANCEL**))))
			     MENUPOSITION ←(AND (WINDOWP MainWindow)
						(create POSITION
							XCOORD ←(fetch (REGION LEFT)
								   of (WINDOWPROP MainWindow
										  (QUOTE REGION)))
							YCOORD ←(fetch (REGION TOP)
								   of (WINDOWREGION MainWindow))))
			     MENUCOLUMNS ←(AND ReverseLinksFlg 2)))
          (RETURN (PROG1 (until NIL
			    do (SETQ Choice (OR (MKATOM (MENU Menu))
						NC.UnspecifiedLinkLabel))
			       (COND
				 ((EQ Choice (QUOTE **CANCEL**))
				   (SETQ Choice))
				 ((EQ Choice (QUOTE --New% Link% Type--))
				   (NC.ClearMsg MainWindow NIL)
				   (until (COND
					    ((NOT (FMEMB (U-CASE (SETQ Choice
								   (MKATOM (NC.AskUser 
									    "Enter new link type"
										       " -- " NIL NIL 
										       MainWindow T)))
								 )
							 NC.UCASESystemLinkLabels))
					      T)
					    (T (NC.PrintMsg MainWindow T Choice 
							    " is a system reserved link type."
							    (CHARACTER 13)
							    "Please choose another link type."
							    (CHARACTER 13))
					       NIL)))
				   (OR Choice (SETQ Choice NC.UnspecifiedLinkLabel))
				   (AND (NOT (FMEMB Choice LinkLabels))
					(NC.PutLinkLabels PSA.Database (CONS Choice LinkLabels)))))
			       (COND
				 ((NULL Choice)
				   (RETURN))
				 ((NULL MultipleFlg)
				   (RETURN Choice))
				 ((EQ Choice (QUOTE --DONE--))
				   (RETURN LabelsList))
				 ((EQ Choice (QUOTE --ALL--))
				   (COND
				     (ReverseLinksFlg (NC.PrintMsg MainWindow NIL Choice ", ")
						      (SETQ LabelsList (UNION LabelsList LinkLabels)))
				     (T (RETURN LinkLabels))))
				 ((EQ Choice (QUOTE --←ALL--))
				   (NC.PrintMsg MainWindow NIL Choice ", ")
				   (SETQ LabelsList (UNION LabelsList (for Link in LinkLabels
									 collect (PACK* (QUOTE ←)
											Link)))))
				 ((AND (EQ Choice NC.UnspecifiedLinkLabel)
				       (FMEMB Choice LabelsList)))
				 (Choice (NC.PrintMsg MainWindow NIL Choice ", ")
					 (SETQ LabelsList (CONS Choice LabelsList)))))
			 (NC.ClearMsg MainWindow T))))))
)
(DEFINEQ

(NC.CloseDatabaseFile
  (LAMBDA NIL                                                (* rht: "20-Nov-84 00:58")
                                                             (* Close the currently open database file.)

          (* * rht 10/23/84: Now gives user option of closing and saving all open cards on the screen.)



          (* * rht 11/8/84: Put RESETLST around NC.CacheTitles call.)


    (PROG (File CardTotal ID OpenWindows)
          (COND
	    ((OR (NULL PSA.Database)
		 (NOT (OPENP PSA.Database)))
	      (NC.PrintMsg NIL T "There is no open NoteFile!!!" (CHARACTER 13)))
	    (T (COND
		 ((SETQ OpenWindows (for Window in (OPENWINDOWS)
				       when (NC.ActiveCardP (OR (NC.IDFromWindow Window)
								(NC.IDFromWindow (WINDOWPROP
										   Window
										   (QUOTE ICONFOR)))))
				       collect Window))
		   (NC.PrintMsg NIL T "There are cards still active on the screen." (CHARACTER 13))
		   (COND
		     ((NC.YesP (NC.AskUser "Want to close and save them? " " -- " (QUOTE Yes)))
		       (NC.PrintMsg NIL T "Closing and saving active cards ... ")
		       (RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
				 (RESETSAVE NC.ForceFilingFlg NIL)
				 (RESETSAVE NC.ForceTitlesFlg NIL)
				 (for Window in OpenWindows
				    do (COND
					 ((WINDOWPROP Window (QUOTE ICONFOR))
					   (SETQ Window (EXPANDW Window))))
				       (NC.QuitCard (NC.IDFromWindow Window)
						    T)
				       (until (NULL (OPENWP Window)) do (BLOCK))))
		       (NC.PrintMsg NIL NIL "Done." (CHARACTER 13)))
		     (T (RETURN NIL)))))
	       (NC.PrintMsg NIL T "Closing Notefile ... " (CHARACTER 13))
	       (RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
			 (RESETSAVE NC.ForceFilingFlg NIL)
			 (RESETSAVE NC.ForceTitlesFlg NIL)
			 (NC.CacheTypesAndTitles PSA.Database T NIL "Closing NoteFile."))
	       (NC.SaveNextLinkID PSA.Database T)
	       (SETQ File (FULLNAME PSA.Database))

          (* * Set PSA.Database GlobalVar to NIL so that the advise to CLOSEF will not refuse to close this file.)


	       (NC.ForceDatabaseClose PSA.Database)
	       (replace (MENU TITLE) of NC.MainMenu with "No Open NoteFile")
	       (replace (MENU IMAGE) of NC.MainMenu with NIL)
	       (WINDOWPROP (WFROMMENU NC.MainMenu)
			   (QUOTE CLOSEFN)
			   NIL)
	       (NC.DisplayMainMenu)
	       (SETQ PSA.Database)
	       (NC.PrintMsg NIL T File " closed."))))))

(NC.CheckTitle
  (LAMBDA (ID DatabaseStream)                                (* rht: "20-Nov-84 01:07")
                                                             (* If card specified by ID has no title, ask the user 
							     for a title.)

          (* * rht 11/19/84: Now checks NC.ForceTitlesFlg before griping.)


    (PROG (Title (Window (NC.FetchWindow ID)))
          (COND
	    ((AND NC.ForceTitlesFlg (OR (NULL (NC.FetchTitle ID))
					(EQUAL "Untitled" (NC.FetchTitle ID))))
	      (NC.PrintMsg Window T "This note card has no title." (CHARACTER 13))
	      (NC.AssignTitle Window T))
	    ((AND (NULL NC.ForceTitlesFlg)
		  (NULL (NC.FetchTitle ID)))
	      (NC.AssignTitle Window NIL "Untitled"))))))
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.ForceTitlesFlg)
)
(PUTPROPS RHTPATCH004 COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2000 51496 (NC.LinkIconImageBoxFn 2010 . 4249) (NC.LinkIconDisplayFn 4251 . 7684) (
NC.DelFromLink 7686 . 11855) (NCP.ActivateCards 11857 . 12376) (NCP.DeactivateCards 12378 . 13125) (
NC.MakeLinkIndex 13127 . 17100) (NC.AppendLinkIndexEntry 17102 . 20210) (NCP.MakeLinkIndex 20212 . 
21357) (NCP.MakeDocument 21359 . 22559) (NC.MakeDocument 22561 . 27638) (
NC.MakeDocInspectorSelectionFn 27640 . 29140) (NC.AppendStringToStream 29142 . 29913) (
NC.MakeBrowserCard 29915 . 34753) (NC.BringUpBrowserCard 34755 . 35500) (NCP.CreateBrowserCard 35502
 . 36737) (NCP.DeleteCards 36739 . 37220) (NC.FileBoxCollectChildren 37222 . 39873) (
NC.ChooseTopLevelCard 39875 . 41373) (NC.MakeCardTypesList 41375 . 43834) (
NC.DelReferencesToCardFromGraph 43836 . 45814) (NC.RelabelLink 45816 . 49826) (
NC.DelReferencesToCardFromGlobalList 49828 . 51494)) (51576 69712 (NC.LinkIconWhenDeletedFn 51586 . 
53762) (NC.LinkIconWhenCopiedFn 53764 . 58203) (NC.LinkIconWhenMovedFn 58205 . 62552) (
NC.LinkIconCopyFn 62554 . 63307) (NC.FillInLinkIcon 63309 . 63741) (NC.InsertImageObjCopy 63743 . 
64044) (NC.DeleteImageObj 64046 . 64479) (NC.CopiedImageObjAddProcess 64481 . 64773) (
NC.MovedImageObjAddProcess 64775 . 65292) (NC.Setup 65294 . 69710)) (69713 81614 (NC.InsertLinksInText
 69723 . 70831) (NC.AddLinksToTextCard 70833 . 71245) (NC.MakeTEditLeftMenu 71247 . 76367) (
NC.ShowPointers 76369 . 77675) (NC.AskLinkLabel 77677 . 81612)) (81615 85123 (NC.CloseDatabaseFile 
81625 . 84314) (NC.CheckTitle 84316 . 85121)))))
STOP