(FILECREATED "23-Aug-85 17:48:41" {QV}<NOTECARDS>RELEASE1.2I>RHTPATCH002.;8 27902  

      changes to:  (FNS NC.MakeExternalGraphCopy)

      previous date: "22-Aug-85 22:34:14" {QV}<NOTECARDS>RELEASE1.2I>RHTPATCH002.;7)


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

(PRETTYCOMPRINT RHTPATCH002COMS)

(RPAQQ RHTPATCH002COMS ((* * Changes to incorporate Richard's new sketch programmer's interface.)
			(* * Changed functions from NCLINKS)
			(FNS NC.DelReferencesToCardFromSketch NC.InsertLinkInSketch 
			     NC.UpdateLinkImagesInSketch NC.LinkIconWhenCopiedFn 
			     NC.LinkIconWhenMovedFn NC.LinkIconCopyFn NC.CoerceToExternalPutLinkIcon)
			(* * New function for NCLINKS)
			(FNS NC.LinkIconSketchElementP NC.DeleteLinkIconSketchElement)
			(* * Changed functions for NCSKETCHSUBSTANCE)
			(* * Add NC.DeletedLinkImageObject as a globalvar in NCSKETCHSUBSTANCE)
			(FNS NC.CollectReferencesInSketch NC.BringUpSketchCard)
			(* * Changed functions for NCDATABASE)
			(FNS NC.PutSketchSubstance)
			(* * Changed functions for NCSKETCHCARD)
			(FNS NC.AddSketchCard)
			(* * New stuff for GRAPHERPATCH)
			(ADVISE GRAPHEROBJ)
			(* * New functions for NCGRAPHSUBSTANCE)
			(FNS NC.NoteCardsGraphP NC.MakeExternalGraphCopy)))
(* * Changes to incorporate Richard's new sketch programmer's interface.)

(* * Changed functions from NCLINKS)

(DEFINEQ

(NC.DelReferencesToCardFromSketch
  (LAMBDA (SourceID LinkOrDestinationID)                     (* rht: "20-Aug-85 22:47")

          (* * Remove all Link Icons pointing to Destination ID from the sketch Substance.)



          (* * rht 8/20/85: Rewritten to use Richard's sketch programmer's interface. Eliminates references to sketch records.
	  I'm changing the innards of the affected link icons rather than deleting them and reinserting.
	  That's because deleting the icon would cause a recursive call.)


    (PROG ((LinkFlg (type? NOTECARDLINK LinkOrDestinationID))
	   LinkID DestinationID SketchSubstance)
          (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 SketchSubstance (NC.FetchSubstance SourceID))
          (for SketchElement in (SKETCH.LIST.OF.ELEMENTS SketchSubstance (FUNCTION 
							   NC.LinkIconSketchElementP))
	     bind LinkIcon when (PROGN (SETQ LinkIcon (SKETCH.IMAGEOBJ.OF.ELEMENT SketchElement))
				       (COND
					 (LinkFlg (EQ LinkID (fetch (NOTECARDLINK LINKID)
								of (NC.FetchLinkFromLinkIcon LinkIcon)
								    )))
					 (T (EQ DestinationID (fetch (NOTECARDLINK DESTINATIONID)
								 of (NC.FetchLinkFromLinkIcon 
											 LinkIcon)))))
				       )
	     do (NC.DeleteLinkIconSketchElement SketchElement SourceID)))))

(NC.InsertLinkInSketch
  (LAMBDA (SketchWindow Link SketchWindowPosition)           (* rht: "21-Aug-85 11:49")

          (* * rht 8/20/85: Rewritten to use Richard's sketch programmer's interface. Eliminates references to sketch 
	  records.)


    (LET ((LinkIcon (NC.MakeLinkIcon Link))
       (Scale (SKETCHW.SCALE SketchWindow))
       SketchIcon Size Position)
      (SETQ Size (IMAGEBOXSIZE LinkIcon))
      (SETQ Position (OR (POSITIONP SketchWindowPosition)
			 (GETBOXPOSITION (fetch (IMAGEBOX XSIZE) of Size)
					 (fetch (IMAGEBOX YSIZE) of Size)
					 NIL NIL SketchWindow)))
      (SETQ SketchIcon (SKETCH.IMAGE.OBJECT.ELEMENT LinkIcon Scale Position))
      (SKETCH.ADD.ELEMENT SketchIcon SketchWindow)
      SketchIcon)))

(NC.UpdateLinkImagesInSketch
  (LAMBDA (SourceCardID DestinationID)                       (* rht: "20-Aug-85 17:55")
                                                             (* For now do nothing since Link Images in Sketch have 
							     no titles.)

          (* * rht 8/20/85: Rigged this to use Richard's new sketch programmer's interface.)


    (LET ((SketchWin (NC.FetchWindow SourceCardID)))
      (for SketchElement in (SKETCH.LIST.OF.ELEMENTS SketchWin (FUNCTION NC.LinkIconSketchElementP))
	 bind FoundAtLeastOneFlg when (EQ DestinationID (fetch (NOTECARDLINK DESTINATIONID)
							   of (NC.FetchLinkFromLinkIcon (
SKETCH.IMAGEOBJ.OF.ELEMENT SketchElement))))
	 do (SKETCH.ELEMENT.CHANGED SketchWin SketchElement)
	    (SETQ FoundAtLeastOneFlg T)
	 finally (if FoundAtLeastOneFlg
		     then (NC.MarkCardDirty SourceCardID))))))

(NC.LinkIconWhenCopiedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "21-Aug-85 16:54")

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



          (* * rht 12/12/84: now does RETFROM instead of adding processes to delete imageobj's. This is cleaner, but still 
	  ugly.)



          (* * rht 3/25/85: Fixed to handle copies within a sketch card. That is indicated by nullity of the two textstream 
	  args.)


    (PROG (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		 SourceID DestID NewSourceID NewLabel NewDisplayMode OldDisplayMode
		 (ImageObjectCopy (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)))
		 (Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
		 (InTEditCopyFlg (COND
				   ((STKPOS (QUOTE TEDIT.COPY))
				     T)))
		 InsertPos)
          (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link))
          (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of Link))
          (SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link))
          (SETQ OldDisplayMode (fetch (NOTECARDLINK DISPLAYMODE) of Link))
          (SETQ NewSourceID (COND
	      ((WINDOWP Window)
		(NC.IDFromWindow Window))
	      ((TEXTSTREAMP ToTextStream)
		(NC.CoerceToID ToTextStream))))
          (COND
	    ((AND (NULL FromTextStream)
		  (NULL ToTextStream))                       (* We must be moving within a sketch.)
	      (SETQ NewSourceID SourceID))
	    ((TEXTSTREAMP ToTextStream)                      (* If it's a text copy, then compute position to insert
							     link at.)
	      (SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))
          (COND
	    ((NULL NewSourceID)                              (* Trying to copy to a non NoteCard stream)
	      (NC.PrintMsg Window NIL (CONCAT "Tried to copy a NoteCards link icon" 
					      " to a non-NoteCards stream!!."
					      (CHARACTER 13)
					      "Tsk. Tsk."
					      (CHARACTER 13)))
	      (NC.CoerceToExternalPutLinkIcon ImageObjectCopy SourceID DestID Label)
	      (RETURN NIL))
	    ((NULL (NC.LinksSupportedP NewSourceID (QUOTE (Local))))
	      (NC.PrintMsg Window NIL (CONCAT "Tried to copy a NoteCards link icon" 
					      " to a NoteCard that"
					      " does not support links!!."
					      (CHARACTER 13)
					      "Tsk. Tsk."
					      (CHARACTER 13)))
	      (COND
		(InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					 NIL T))
		(T (RETURN (QUOTE DON'T)))))
	    ((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 (create LINKDISPLAYMODE copying OldDisplayMode SHOWTITLEFLG ← T 
								   SHOWLINKTYPEFLG ← T)))
	    ((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)))
	      (COND
		(InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					 NIL T))
		(T (RETURN (QUOTE DON'T)))))
	    ((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)))
	      (COND
		(InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					 NIL T))
		(T (RETURN (QUOTE DON'T)))))
	    ((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)))
	      (COND
		(InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					 NIL T))
		(T (RETURN (QUOTE DON'T)))))
	    ((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)))
	      (COND
		(InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					 NIL T))
		(T (RETURN (QUOTE DON'T)))))
	    ((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 (create LINKDISPLAYMODE copying OldDisplayMode SHOWTITLEFLG ← T 
								   SHOWLINKTYPEFLG ← T))))
          (NC.FillInLinkIcon ImageObjectCopy (OR NewLabel Label)
			     DestID NewSourceID (OR NewDisplayMode OldDisplayMode)
			     (NC.LinkAtCharPos InsertPos ToTextStream)))))

(NC.LinkIconWhenMovedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "21-Aug-85 16:54")

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



          (* * rht 12/12/84: Now just RETFROM's rather than doing the addprocess stuff. Should be cleaner, but still ugly.)


    (PROG (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		 SourceID DestID NewSourceID NewLabel NewDisplayMode OldDisplayMode
		 (Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
		 InsertPos)
          (SETQ Label (fetch (NOTECARDLINK LINKLABEL) of Link))
          (SETQ NewSourceID (COND
	      ((WINDOWP Window)
		(NC.IDFromWindow Window))
	      ((TEXTSTREAMP ToTextStream)
		(NC.CoerceToID ToTextStream))))
          (SETQ SourceID (fetch (NOTECARDLINK SOURCEID) of Link))
          (SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of Link))
          (SETQ OldDisplayMode (fetch (NOTECARDLINK DISPLAYMODE) of Link))
          (COND
	    ((AND (NULL FromTextStream)
		  (NULL ToTextStream))                       (* We must be moving within a sketch.)
	      (SETQ NewSourceID SourceID))
	    ((TEXTSTREAMP ToTextStream)                      (* If it's a text copy, then compute position to insert
							     link at.)
	      (SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))
          (COND
	    ((NULL NewSourceID)                              (* Trying to copy to a non NoteCard stream)
	      (NC.PrintMsg Window NIL (CONCAT "Tried to move a NoteCards link icon" 
					      " to a non-NoteCards stream!!."
					      (CHARACTER 13)
					      "Tsk. Tsk."
					      (CHARACTER 13)))
	      (RETFROM (QUOTE TEDIT.MOVE)
		       NIL T))
	    ((NULL (NC.LinksSupportedP NewSourceID (QUOTE (Local))))
	      (NC.PrintMsg Window NIL (CONCAT "Tried to move a NoteCards link icon" 
					      " to a NoteCard that"
					      " does not support links!!."
					      (CHARACTER 13)
					      "Tsk. Tsk."
					      (CHARACTER 13)))
	      (RETFROM (QUOTE TEDIT.MOVE)
		       NIL T))
	    ((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 (create LINKDISPLAYMODE copying OldDisplayMode SHOWTITLEFLG ← T 
								   SHOWLINKTYPEFLG ← T)))
	    ((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)))
	      (RETFROM (QUOTE TEDIT.MOVE)
		       NIL T))
	    ((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)))
	      (RETFROM (QUOTE TEDIT.MOVE)
		       NIL T))
	    ((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)))
	      (RETFROM (QUOTE TEDIT.MOVE)
		       NIL T))
	    ((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 (create LINKDISPLAYMODE copying OldDisplayMode SHOWTITLEFLG ← T 
								   SHOWLINKTYPEFLG ← T))))
          (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
			Link)
          (NC.FillInLinkIcon ImageObject (OR NewLabel Label)
			     DestID NewSourceID (OR NewDisplayMode OldDisplayMode)
			     (NC.LinkAtCharPos InsertPos ToTextStream)))))

(NC.LinkIconCopyFn
  (LAMBDA (ImageObject)                                      (* rht: "22-Aug-85 14:56")

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



          (* * rht 8/22/85: Added call to NC.CoerceToExternalPutLinkIcon to make the imageobj look like a external link icon.
	  If we're in a normal imageobj copy then the whencopiedfn will get called and replace the contents of ImageObjectCopy
	  anyway. However, if only the CopyFn gets called, then this will stick.)


    (PROG ((ImageObjectCopy (create IMAGEOBJ copying ImageObject))
	   (Link (NC.FetchLinkFromLinkIcon ImageObject)))
          (NC.CoerceToExternalPutLinkIcon ImageObjectCopy (fetch (NOTECARDLINK SOURCEID)
							     of Link)
					  (fetch (NOTECARDLINK DESTINATIONID) of Link)
					  (fetch (NOTECARDLINK LINKLABEL) of Link))
          (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)
			ImageObjectCopy)
          (RETURN ImageObjectCopy))))

(NC.CoerceToExternalPutLinkIcon
  (LAMBDA (ImageObject SourceID DestinationID LinkLabel)     (* rht: "22-Aug-85 21:53")

          (* * Make image object into an external put link icon with the given data)


    (IMAGEOBJPROP ImageObject (QUOTE OBJECTDATUM)
		  (CONCAT "[[" LinkLabel " link to " (NC.RetrieveTitle DestinationID PSA.Database)
			  "]]"))
    (replace (IMAGEOBJ IMAGEOBJFNS) of ImageObject with NC.ExternalPutLinkIconImageFns)))
)
(* * New function for NCLINKS)

(DEFINEQ

(NC.LinkIconSketchElementP
  (LAMBDA (SketchElement)                                    (* rht: "20-Aug-85 16:23")

          (* * Return non-nil if SketchElement is a link icon imageobj.)


    (NC.LinkIconImageObjP (SKETCH.IMAGEOBJ.OF.ELEMENT SketchElement))))

(NC.DeleteLinkIconSketchElement
  (LAMBDA (SketchElement CardID)                             (* rht: "20-Aug-85 23:57")

          (* * This replaces the link icon for SketchElement from SketchWin with deleted link icon.)


    (LET ((Position (SKETCH.POSITION.OF.ELEMENT SketchElement))
       (SketchSubstance (NC.FetchSubstance CardID))
       (LinkIcon (SKETCH.IMAGEOBJ.OF.ELEMENT SketchElement))
       (Window (NC.FetchWindow CardID))
       Scale)
      (SETQ Scale (if Window
		      then (SKETCHW.SCALE Window)
		    else (NC.FetchScale CardID)))
      (create IMAGEOBJ smashing LinkIcon OBJECTDATUM ←(IMAGEOBJPROP NC.DeletedLinkImageObject
								    (QUOTE OBJECTDATUM))
				IMAGEOBJFNS ← NC.DeletedLinkImageFns)
      (AND Window (SKETCH.ELEMENT.CHANGED SketchSubstance SketchElement Window)))))
)
(* * Changed functions for NCSKETCHSUBSTANCE)

(* * Add NC.DeletedLinkImageObject as a globalvar in NCSKETCHSUBSTANCE)

(DEFINEQ

(NC.CollectReferencesInSketch
  (LAMBDA (ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* rht: "20-Aug-85 22:53")

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



          (* * rht 8/20/85: Rewritten to use Richard's sketch programmer's interface. Eliminates references to sketch 
	  records.)


    (LET ((SketchSubstance (NC.FetchSubstance ID))
       DirtyFlg)
      (CONS (for SketchElt in (SKETCH.LIST.OF.ELEMENTS SketchSubstance (FUNCTION 
							 NC.LinkIconSketchElementP))
	       bind LinkIcon CollectItem ActualLink
	       when (PROGN (SETQ ActualLink (NC.FetchLinkFromLinkIcon (SETQ LinkIcon (
								       SKETCH.IMAGEOBJ.OF.ELEMENT
									  SketchElt))))
			   (COND
			     ((NULL CheckAndDeleteFlg)       (* No checking required)
			       T)
			     ((AND (LISTP CheckAndDeleteFlg)
				   (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ActualLink)
					  CheckAndDeleteFlg))
                                                             (* Already checked since ID cached on CheckAndDeleteFlg
							     list)
			       T)
			     ((NC.ValidLinkP ActualLink DatabaseStream)
                                                             (* Link is valid)
			       T)
			     (T                              (* Link is bad. Replace it with the DeletedLink image 
							     object.)
				(NC.DeleteLinkIconSketchElement SketchElt ID)
				(SETQ DirtyFlg T)
				NIL)))
	       collect (SETQ CollectItem (COND
			   (ReturnLinkIconsFlg LinkIcon)
			   (T ActualLink)))
		       (if ReturnLocationsFlg
			   then (CONS CollectItem (SKETCH.POSITION.OF.ELEMENT SketchElt))
			 else CollectItem))
	    DirtyFlg))))

(NC.BringUpSketchCard
  (LAMBDA (ID Substance Region/Position)                     (* rht: "31-May-85 15:00")
                                                             (* Bring up a sketch card containing substance in 
							     specified region)

          (* * rht 2/1/85: Added windowprop to prevent sketch asking about saving changes.)


    (PROG (Region Title SketchViewer)
          (COND
	    ((SETQ SketchViewer (NC.FetchWindow ID))
	      (RPTQ 2 (FLASHW SketchViewer))
	      (TOTOPW SketchViewer)
	      (TTY.PROCESS (WINDOWPROP SketchViewer (QUOTE PROCESS)))
	      (RETURN SketchViewer)))
          (SETQ SketchViewer (SKETCHW.CREATE (OR Substance ID)
					     (NC.FetchRegionViewed ID)
					     (NC.DetermineDisplayRegion ID Region/Position)
					     (NC.FetchTitle ID)
					     (NC.FetchScale ID)))
          (WINDOWPROP SketchViewer (QUOTE DONTQUERYCHANGES)
		      T)
          (WINDOWPROP SketchViewer (QUOTE SHRINKFN)
		      (FUNCTION NC.SketchCardShrinkFn))
          (NC.SetupTitleBarMenu SketchViewer ID (QUOTE Sketch))
          (RETURN SketchViewer))))
)
(* * Changed functions for NCDATABASE)

(DEFINEQ

(NC.PutSketchSubstance
  (LAMBDA (ID DatabaseStream)                                (* rht: "22-Aug-85 20:27")

          (* Put the sketch substance for card ID to the database. Store the global sketch descriptor, the scale and region 
	  viewed for ID and any cached bit maps.)


    (PROG ((Substance (NC.FetchSubstance ID))
	   (Window (NC.FetchWindow ID))
	   SketchSpecs EndPtr EndPtrLoc StartPtr)
          (SETQ StartPtr (IPLUS (GETFILEPTR DatabaseStream)
				6))
          (NC.PutPtr DatabaseStream StartPtr)
          (SETQ EndPtrLoc (GETFILEPTR DatabaseStream))
          (NC.PutPtr DatabaseStream 0)
          (HPRINT Substance DatabaseStream NIL T)
          (PRINT (OR (AND Window (SCALE.FROM.SKW Window))
		     (NC.FetchScale ID))
		 DatabaseStream)
          (PRINT (OR (AND Window (SK.REGION.VIEWED Window))
		     (NC.FetchRegionViewed ID))
		 DatabaseStream)
          (COND
	    ((AND Window (SETQ SketchSpecs (LOCALSPECS.FROM.VIEWER Window)))
	      (MAPSKETCHSPECS SketchSpecs (FUNCTION NC.PutCachedMap)
			      DatabaseStream)))
          (PRINT (QUOTE ###ENDSKETCH###)
		 DatabaseStream)
          (SETQ EndPtr (GETFILEPTR DatabaseStream))
          (SETFILEPTR DatabaseStream EndPtrLoc)
          (NC.PutPtr DatabaseStream EndPtr))))
)
(* * Changed functions for NCSKETCHCARD)

(DEFINEQ

(NC.AddSketchCard
  (LAMBDA NIL                                                (* rht: "22-Aug-85 15:01")
    (NC.AddCardType (QUOTE Sketch)
		    (QUOTE NoteCard)
		    (QUOTE SKETCH)
		    (BQUOTE ((MakeCardFn , (FUNCTION NC.MakeSketchCard))))
		    (BQUOTE ((LinkDisplayMode Title)
			     (CardDisplayedInMenuFlg , T))))))
)
(* * New stuff for GRAPHERPATCH)


(PUTPROPS GRAPHEROBJ READVICE (NIL (BEFORE NIL (COND ((NC.NoteCardsGraphP GRAPH)
						      (SETQ GRAPH (NC.MakeExternalGraphCopy GRAPH)))))
				   ))
(READVISE GRAPHEROBJ)
(* * New functions for NCGRAPHSUBSTANCE)

(DEFINEQ

(NC.NoteCardsGraphP
  (LAMBDA (Graph)                                            (* rht: "22-Aug-85 21:01")

          (* * Return non-nil if Graph was created by notecards. Now checks the MoveNodeFn. Is there a better way?)


    (EQ (fetch (GRAPH GRAPH.MOVENODEFN) of Graph)
	(QUOTE NC.GraphMoveNodeFn))))

(NC.MakeExternalGraphCopy
  (LAMBDA (Graph)                                            (* fgh: "23-Aug-85 17:44")

          (* * Make a copy of Graph in which each link icon nodelabel has been replaced by a copy of itself and MoveNodeFn, 
	  etc. are replaced by NIL.)


    (create GRAPH
	    DIRECTEDFLG ←(fetch (GRAPH DIRECTEDFLG) of Graph)
	    SIDESFLG ←(fetch (GRAPH SIDESFLG) of Graph)
	    GRAPHNODES ←(for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
			   collect (LET (NewLinkIcon Box NewNode)
				     (PROG1 (SETQ NewNode (create GRAPHNODE
							     copying GraphNode NODELABEL ←(COND
								       ((NC.LinkIconImageObjP
									   (SETQ NodeLabel
									     (fetch (GRAPHNODE 
											NODELABEL)
										of GraphNode)))
									 (SETQ NewLinkIcon
									   (NC.LinkIconCopyFn 
											NodeLabel)))
								       (T (COPY NodeLabel)))))
					    (COND
					      (NewLinkIcon (SETQ Box (
							       NC.ExternalPutLinkIconImageBoxFn
							       NewLinkIcon NIL NIL NIL))
							   (replace (GRAPHNODE NODEHEIGHT)
							      of NewNode with (fetch (IMAGEBOX YSIZE)
										 of Box))
							   (replace (GRAPHNODE NODEWIDTH)
							      of NewNode with (fetch (IMAGEBOX XSIZE)
										 of Box))))))))))
)
(PUTPROPS RHTPATCH002 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1385 19336 (NC.DelReferencesToCardFromSketch 1395 . 3044) (NC.InsertLinkInSketch 3046
 . 3867) (NC.UpdateLinkImagesInSketch 3869 . 4812) (NC.LinkIconWhenCopiedFn 4814 . 11532) (
NC.LinkIconWhenMovedFn 11534 . 17572) (NC.LinkIconCopyFn 17574 . 18848) (
NC.CoerceToExternalPutLinkIcon 18850 . 19334)) (19374 20554 (NC.LinkIconSketchElementP 19384 . 19666) 
(NC.DeleteLinkIconSketchElement 19668 . 20552)) (20685 23912 (NC.CollectReferencesInSketch 20695 . 
22697) (NC.BringUpSketchCard 22699 . 23910)) (23958 25366 (NC.PutSketchSubstance 23968 . 25364)) (
25414 25788 (NC.AddSketchCard 25424 . 25786)) (26054 27820 (NC.NoteCardsGraphP 26064 . 26399) (
NC.MakeExternalGraphCopy 26401 . 27818)))))
STOP