(FILECREATED "19-Jun-87 17:16:22" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH046.;12 27941  

      changes to:  (VARS PMIPATCH046COMS)
		   (FNS NC.TraverseLink NC.LinkIconDisplayFn NC.DeleteBadLink NC.ShowLinks 
			NC.ReplaceWithDeletedLinkImageObj NC.DeleteLink NC.LinkIconImageBoxFn)

      previous date: "18-Jun-87 19:06:43" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH046.;9)


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

(PRETTYCOMPRINT PMIPATCH046COMS)

(RPAQQ PMIPATCH046COMS ((* * pmi&rht 6/19/87: Fixes bug #565: Bad link icons should make themselves 
			     Deleted. Added checks for bad links (ie: half links to deleted cards.)
			     Such links will now be deleted and their image objects replaced with 
			     "Deleted"
			     objects when they are redisplayed or touched.)
			  (* * Changed in NCLINKS)
			  (FNS NC.TraverseLink NC.LinkIconDisplayFn)
			  (* * New for NCLINKS)
			  (FNS NC.DeleteBadLink NC.ReplaceWithDeletedLinkImageObj)
			  (* * Changed in NCLINKS)
			  (FNS NC.ShowLinks NC.DeleteLink)))
(* * pmi&rht 6/19/87: Fixes bug #565: Bad link icons should make themselves Deleted. Added 
checks for bad links (ie: half links to deleted cards.) Such links will now be deleted and 
their image objects replaced with "Deleted" objects when they are redisplayed or touched.)

(* * Changed in NCLINKS)

(DEFINEQ

(NC.TraverseLink
  (LAMBDA (LinkIcon Window)                                  (* pmi: "19-Jun-87 15:04")

          (* * Follow the link to the card at the other end. For now, amounts to editing the destination card.)



          (* * pmi&rht 6/19/87: Now checks for valid destination card before trying to edit it. Prints message to prompt 
	  window and changes link icon to "Deleted" if card is invalid.)


    (DECLARE (GLOBALVARS NC.MsgDelay))
    (LET ((Link (NC.FetchLinkFromLinkIcon LinkIcon))
	  (InterestedWindow (NC.CoerceToInterestedWindow (MAINWINDOW Window)))
	  Card OldTitle)
         (SETQ Card (fetch (Link DestinationCard) of Link))
         (if (NC.ValidCardP Card)
	     then (SETQ OldTitle (NC.RetrieveTitle Card))
		    (NC.EditNoteCard Card) 

          (* * We're under TEdit, so if title was changed by EditFn, then be sure link icon gets redisplayed.)


		    (if (STREQUAL OldTitle (NC.RetrieveTitle Card))
			then (QUOTE DON'T)
		      else (QUOTE CHANGED))
	   else 

          (* * The link is bad -
	  tell the user and change it to "Deleted")


		  (NC.PrintMsg InterestedWindow T 
				 "This is a bad link - the destination card is invalid."
				 (CHARACTER 13))
		  (DISMISS NC.MsgDelay)
		  (NC.ClearMsg InterestedWindow T)
		  (NC.DeleteBadLink Link LinkIcon Window)))))

(NC.LinkIconDisplayFn
  (LAMBDA (ImageObj ImageStream StreamType TextStream Scale)
                                                             (* pmi: "19-Jun-87 16:55")

          (* * Display a link icon)



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



          (* * rht 12/4/84: Hacked so type-dependent icons come out optionally to left of text.)



          (* * rht 2/9/85: Changed to use new display mode format.)



          (* * fgh 2/5/86 Added call to NC.FetchLinkIconAttachedBitMap)



          (* * rht & fgh 5/9/86: Massive hacking to display coords, etc.)



          (* * fgh 5/9/86 Added DSPFONT kludge after TypeIcon BITBLT to get around bug in PRESS BITBLT.
	  Bug reported as AR #5630.0)



          (* * rht 5/10/86: Rearranged order of expressions a bit and added arg to call to NC.FetchLinkIconAttachedBitMap in 
	  order to get a bitmap with correct height for the box we're drawing.)



          (* * rht 8/7/86: Now passes Scale argument to NC.FetchLinkIconAttachedBitMap. Also uses the Title and Label args if
	  non-nil. If not, then recomputes them more sensibly.)



          (* * rht 8/25/86: Fixed improperly placed comment.)



          (* * pmi 2/11/87: Overhauled to accommodate multi-line link icons)



          (* * pmi 2/27/87: Fixed problems with only displaying the attached bitmap and with displaying null titles)



          (* * pmi 5/1/87: added missing local vars declarations.)



          (* * pmi&rht 6/19/87: Added check for bad link (ie: half link to a deleted card.) Such a link will now be deleted 
	  and its image object replaced with a "Bad Link" object.)


    (DECLARE (GLOBALVARS NC.LinkIconMultiLineMode NC.LinkIconMaxWidth NC.LinkIconSpaceInnerX 
			     NC.LinkIconSpaceOuterX NC.LinkIconAttachBitmapFlg NC.LinkIconSpaceInnerY 
			     NC.LinkIconSpaceOuterY NC.LinkIconSpaceInterLine NC.LinkIconBorderWidth 
			     NC.LinkIconShowLinkTypeFlg NC.LinkIconShowTitleFlg))
    (RESETLST (RESETSAVE NIL (BQUOTE (DSPFONT , (DSPFONT NC.LinkIconFont ImageStream)
						      , ImageStream)))
		(PROG ((Scale (DSPSCALE NIL ImageStream))
			 (Link (NC.FetchLinkFromLinkIcon ImageObj))
			 Font FontHeight FontAscent FontDescent Left Bottom Top ShowTitleFlg 
			 LinkDisplayMode AttachBitmapFlg DisplayType Window Card Title Label 
			 LinkIconString LinkIconStrings ApproxBoxWidth ApproxBoxHeight BoxWidth 
			 BoxHeight ImageBox Icon ScaledIconHeight ScaledIconWidth XPosition 
			 ScaledLinkIconMaxWidth ScaledBorderWidth ScaledSpaceInnerX ScaledSpaceOuterX 
			 ScaledSpaceInnerY ScaledSpaceOuterY ScaledSpaceInterLine 
			 HalfScaledSpaceInterLine BottomOfLine)

          (* * Check for bad Link)


		        (if (NOT (AND (NC.ValidCardP (fetch (Link SourceCard) of Link))
					    (NC.ValidCardP (fetch (Link DestinationCard)
								of Link))))
			    then 

          (* * Delete the offending link, smash its image object into a "Deleted" image object, and return by displaying it.)


				   (NC.DeleteBadLink Link ImageObj ImageStream StreamType 
						       TextStream Scale)
				   (RETURN))

          (* * Link is okay, continue)


		        (SETQ Font (DSPFONT NIL ImageStream))
		        (SETQ FontHeight (FONTHEIGHT Font))

          (* * Determine what type of Display to do)


		        (SETQ DisplayType (fetch (Link DisplayMode) of Link))
		        (SETQ ShowTitleFlg (fetch (LINKDISPLAYMODE SHOWTITLEFLG) of DisplayType)
			  )
		        (SETQ Card (if (EQ ShowTitleFlg (QUOTE SOURCE))
					 then (fetch (Link SourceCard) of Link)
				       else (fetch (Link DestinationCard) of Link)))
		        (SETQ LinkDisplayMode (fetch (LINKDISPLAYMODE SHOWLINKTYPEFLG)
						   of DisplayType))
		        (SETQ AttachBitmapFlg (fetch (LINKDISPLAYMODE ATTACHBITMAPFLG)
						   of DisplayType))
		        (SETQ AttachBitmapFlg (if (EQ AttachBitmapFlg (QUOTE FLOAT))
						    then NC.LinkIconAttachBitmapFlg
						  else AttachBitmapFlg))

          (* * Construct the text for the link icon)


		        (SETQ Title (if (AND ShowTitleFlg (OR (NEQ ShowTitleFlg
									     (QUOTE FLOAT))
								      NC.LinkIconShowTitleFlg))
					  then (NC.RetrieveTitle Card)
					else NIL))
		        (SETQ Label (AND (COND
					       ((EQ LinkDisplayMode (QUOTE FLOAT))
						 NC.LinkIconShowLinkTypeFlg)
					       (T LinkDisplayMode))
					     (fetch (Link Label) of Link)))
		        (SETQ LinkIconString (CONCAT (COND
							   (Label (CONCAT "<" Label ">"))
							   (T ""))
							 (COND
							   ((AND Label Title)
							     " ")
							   (T ""))
							 (OR Title "")))

          (* * Make temporaries of scaled variables)


		        (SETQ ScaledLinkIconMaxWidth (TIMES Scale NC.LinkIconMaxWidth))
		        (SETQ ScaledBorderWidth (TIMES Scale NC.LinkIconBorderWidth))
		        (SETQ ScaledSpaceInnerX (TIMES Scale NC.LinkIconSpaceInnerX))
		        (SETQ ScaledSpaceOuterX (TIMES Scale NC.LinkIconSpaceOuterX))
		        (SETQ ScaledSpaceInnerY (TIMES Scale NC.LinkIconSpaceInnerY))
		        (SETQ ScaledSpaceOuterY (TIMES Scale NC.LinkIconSpaceOuterY))
		        (SETQ ScaledSpaceInterLine (TIMES Scale NC.LinkIconSpaceInterLine))
		        (SETQ HalfScaledSpaceInterLine (IQUOTIENT ScaledSpaceInterLine 2))

          (* * Set up the icon, if displayed)


		        (SETQ ImageBox (IMAGEOBJPROP ImageObj (QUOTE BOUNDBOX)))
		        (if AttachBitmapFlg
			    then 

          (* * Attached icon)



          (* * Use an estimate of the width and height to tell if the box contains more than one line of text)


				   (if NC.LinkIconMultiLineMode
				       then 

          (* * Multi-line link icons are enabled)


					      (SETQ ApproxBoxWidth (PLUS ScaledSpaceOuterX 
									     ScaledBorderWidth 
									     ScaledSpaceInnerX
									     (STRINGWIDTH 
										   LinkIconString 
											    Font)
									     ScaledSpaceInnerX 
									     ScaledBorderWidth 
									     ScaledSpaceOuterX))
					      (SETQ ApproxBoxHeight
						(PLUS ScaledSpaceOuterY ScaledBorderWidth 
							ScaledSpaceInnerY FontHeight 
							ScaledSpaceInnerY ScaledBorderWidth 
							ScaledSpaceOuterY))
					      (if ImageBox
						  then 

          (* * The image box has already been calculated. Use the box height to determine if Multi-line or Single line.
	  Calculate the correct bitmap.)


							 (SETQ BoxHeight (fetch (IMAGEBOX
										      YSIZE)
									      of ImageBox))
							 (if (GREATERP BoxHeight ApproxBoxHeight)
							     then 
                                                             (* Calculate height for Multi-line icon)
								    (SETQ ScaledIconHeight
								      (PLUS ScaledBorderWidth 
									      ScaledSpaceInnerY 
									      FontHeight 
									 HalfScaledSpaceInterLine))
							   else 
                                                             (* Calculate height for Single line icon)
								  (SETQ ScaledIconHeight
								    (PLUS ScaledBorderWidth 
									    ScaledSpaceInnerY 
									    FontHeight 
									    ScaledSpaceInnerY 
									    ScaledBorderWidth)))
							 (SETQ Icon (
							     NC.FetchLinkIconAttachedBitMap Card 
										 ScaledIconHeight 
											    Scale))
							 (SETQ ScaledIconHeight
							   (TIMES Scale (BITMAPHEIGHT Icon)))
							 (SETQ ScaledIconWidth (TIMES
							     Scale
							     (BITMAPWIDTH Icon)))
						else 

          (* * The image box must be calculated)


						       (if (GREATERP ApproxBoxWidth 
									 ScaledLinkIconMaxWidth)
							   then 
                                                             (* Calculate Multi-line icon)
								  (SETQ ScaledIconHeight
								    (PLUS ScaledBorderWidth 
									    ScaledSpaceInnerY 
									    FontHeight 
									 HalfScaledSpaceInterLine))
								  (SETQ Icon (
								   NC.FetchLinkIconAttachedBitMap
								      Card ScaledIconHeight Scale))
								  (SETQ ScaledIconHeight
								    (TIMES Scale (BITMAPHEIGHT
									       Icon)))
								  (SETQ ScaledIconWidth
								    (TIMES Scale (BITMAPWIDTH
									       Icon)))
							 else 
                                                             (* Calculate Single line icon)
								(SETQ ScaledIconHeight
								  (PLUS ScaledBorderWidth 
									  ScaledSpaceInnerY 
									  FontHeight 
									  ScaledSpaceInnerY 
									  ScaledBorderWidth))
								(SETQ Icon (
								   NC.FetchLinkIconAttachedBitMap
								    Card ScaledIconHeight Scale))
								(SETQ ScaledIconHeight
								  (TIMES Scale (BITMAPHEIGHT
									     Icon)))
								(SETQ ScaledIconWidth
								  (TIMES Scale (BITMAPWIDTH
									     Icon)))

          (* * Now see if total width, including the icon, will still fit if this is a Single line)


								(if (AND (NOT (STREQUAL
										      LinkIconString 
										      ""))
									     (GREATERP
									       (PLUS ApproxBoxWidth 
										  ScaledIconWidth)
									       ScaledLinkIconMaxWidth)
									     )
								    then 
                                                             (* Now it doesn't fit. Calculate Multi-line icon)
									   (SETQ ScaledIconHeight
									     (PLUS 
										ScaledBorderWidth 
										ScaledSpaceInnerY 
										     FontHeight 
									 HalfScaledSpaceInterLine))
									   (SETQ Icon
									     (
								   NC.FetchLinkIconAttachedBitMap
									       Card ScaledIconHeight 
									       Scale))
									   (SETQ ScaledIconHeight
									     (TIMES Scale
										      (BITMAPHEIGHT
											Icon)))
									   (SETQ ScaledIconWidth
									     (TIMES Scale
										      (BITMAPWIDTH
											Icon))))))
				     else 

          (* * Multi-line link icons are disabled)


					    (SETQ ScaledIconHeight (PLUS ScaledBorderWidth 
									     ScaledSpaceInnerY 
									     FontHeight 
									     ScaledSpaceInnerY 
									     ScaledBorderWidth))
					    (SETQ Icon (NC.FetchLinkIconAttachedBitMap Card 
										 ScaledIconHeight 
											   Scale))
					    (SETQ ScaledIconHeight (TIMES Scale (BITMAPHEIGHT
										Icon)))
					    (SETQ ScaledIconWidth (TIMES Scale (BITMAPWIDTH
									       Icon))))
			  else 

          (* * No attached icon)


				 (SETQ Icon NIL)
				 (SETQ ScaledIconHeight 0)
				 (SETQ ScaledIconWidth 0))

          (* * Now determine the text to be printed)


		        (if (AND Icon (GREATERP (PLUS ScaledIconWidth ScaledSpaceOuterX 
							      ScaledSpaceOuterX)
						      ScaledLinkIconMaxWidth))
			    then 

          (* If the width of the icon plus the outer x's is greater than the ScaledLinkIconMaxWidth set by the user, set the 
	  icon and text to NIL)


				   (SETQ Icon NIL)
				   (SETQ ScaledIconHeight 0)
				   (SETQ ScaledIconWidth 0)
				   (SETQ LinkIconStrings (LIST ""))
			  elseif (STREQUAL LinkIconString "")
			    then                           (* There is no text to print, so set it to the null 
							     string)
				   (SETQ LinkIconStrings (LIST ""))
			  else 

          (* * Have the text parsed into separate lines)


				 (SETQ LinkIconStrings (NC.CreateLinkIconStrings Link 
										   LinkIconString 
										     Icon ImageStream)
				   ))

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


		        (SETQ ImageBox
			  (OR ImageBox
				(NC.LinkIconImageBoxFn ImageObj ImageStream NIL NIL NIL DisplayType 
							 Title Label LinkIconString Icon 
							 LinkIconStrings)))

          (* * Compute all the size values.)


		        (SETQ Bottom (PLUS (DIFFERENCE (DSPYPOSITION NIL ImageStream)
							     (fetch (IMAGEBOX YDESC)
								of ImageBox))
					       ScaledSpaceOuterY))
		        (SETQ BoxHeight (DIFFERENCE (fetch (IMAGEBOX YSIZE) of ImageBox)
							(PLUS ScaledSpaceOuterY ScaledSpaceOuterY)))
		        (SETQ Top (PLUS Bottom BoxHeight))
		        (SETQ Left (PLUS (DSPXPOSITION NIL ImageStream)
					     ScaledSpaceOuterX))
		        (SETQ BoxWidth (DIFFERENCE (fetch (IMAGEBOX XSIZE) of ImageBox)
						       (PLUS ScaledSpaceOuterX ScaledSpaceOuterX)))

          (* * Display the icon, if possible)


		        (if (AND Icon (LEQ (PLUS ScaledIconWidth ScaledSpaceOuterX 
							 ScaledSpaceOuterX)
						 ScaledLinkIconMaxWidth))
			    then 

          (* Put out the icon bitmap, but only if the width of the icon plus the outer x's does not exceed the 
	  LinkIconMaxWidth set by the user.)


				   (BITBLT Icon 0 0 ImageStream Left (DIFFERENCE Top 
										 ScaledIconHeight))

          (* DSPFONT is a kludge to get around bug in PRESS BITBLT which sets the width of a space char to NIL.
	  Bug reported as AR #5630.0)


				   (DSPFONT Font ImageStream)
				   (if (NOT (OR Label Title))
				       then                (* Quit because just a typeicon)
					      (RETURN))
			  else                             (* There isn't enough space for the icon, so set it to
							     NIL)
				 (SETQ Icon NIL)
				 (SETQ ScaledIconWidth 0))

          (* * Enter the appropriate text.)


		        (SETQ XPosition (PLUS Left (if Icon
							   then ScaledIconWidth
							 else ScaledBorderWidth)
						  ScaledSpaceInnerX))
		        (DSPXPOSITION XPosition ImageStream)
		        (SETQ FontDescent (FONTDESCENT Font))
		        (if LinkIconStrings
			    then (if (GREATERP (LENGTH LinkIconStrings)
						     1)
				       then (SETQ FontAscent (FONTASCENT Font))
					      (SETQ BottomOfLine (DIFFERENCE Top
										 (PLUS 
										ScaledBorderWidth 
										ScaledSpaceInnerY 
										       FontAscent)))
					      (SETQ XPosition (PLUS Left ScaledSpaceInnerX 
									ScaledBorderWidth))
					      (for String in LinkIconStrings
						 do (DSPYPOSITION BottomOfLine ImageStream)
						      (PRIN1 String ImageStream)
						      (SETQ BottomOfLine
							(DIFFERENCE BottomOfLine
								      (PLUS FontDescent 
									     ScaledSpaceInterLine 
									      FontAscent)))
						      (DSPXPOSITION XPosition ImageStream))

          (* * Draw the box.)


					      (NC.DrawInnerBox Left Bottom BoxWidth BoxHeight 
								 ScaledBorderWidth NIL ImageStream 
								 Icon ScaledIconWidth 
								 ScaledIconHeight)
				     else (DSPYPOSITION (PLUS Bottom ScaledBorderWidth 
								    ScaledSpaceInnerY FontDescent)
							    ImageStream)
					    (PRIN1 (CAR LinkIconStrings)
						     ImageStream)

          (* * Draw the box.)


					    (NC.DrawInnerBox (PLUS Left ScaledIconWidth)
							       Bottom
							       (DIFFERENCE BoxWidth ScaledIconWidth)
							       BoxHeight ScaledBorderWidth NIL 
							       ImageStream Icon)))))))
)
(* * New for NCLINKS)

(DEFINEQ

(NC.DeleteBadLink
  (LAMBDA (Link ImageObj ImageStream StreamType TextStream Scale)
                                                             (* pmi: "19-Jun-87 15:04")

          (* * pmi&rht 6/19/87: Deletes a bad link when it is discovered at display time. If the link icon being displayed is
	  in the Show Links window, then find its corresponding real link and delete it. Otherwise, just delete the link.)


    (LET (Card)
         (if (LISTGET (fetch (Link UserData) of Link)
			  (QUOTE InsidePropListEditor))
	     then (SETQ Card (fetch (Link SourceCard) of Link))
		    (for RealLink in (NC.FetchFromLinks Card) when (NC.SameLinkP RealLink 
											   Link)
		       do (NC.DeleteLink RealLink))
		    (for RealLink in (NC.FetchToLinks Card) when (NC.SameLinkP RealLink 
											 Link)
		       do (NC.DeleteLink RealLink))
		    (QUOTE DON'T)
	   else (NC.DeleteLink Link NIL T)
		  (NC.ReplaceWithDeletedLinkImageObj ImageObj)
		  (APPLY* (IMAGEOBJPROP ImageObj (QUOTE DISPLAYFN))
			    ImageObj ImageStream StreamType TextStream Scale)
		  (QUOTE CHANGED)))))

(NC.ReplaceWithDeletedLinkImageObj
  (LAMBDA (ImageObject)                                      (* pmi: "19-Jun-87 10:28")

          (* * pmi 6/19/87: smash a bad link's image object with the fields of a "Deleted" image object.)


    (DECLARE (GLOBALVARS NC.DeletedLinkImageObject))
    (create IMAGEOBJ smashing ImageObject OBJECTDATUM ←(fetch (IMAGEOBJ OBJECTDATUM)
							      of NC.DeletedLinkImageObject)
				  IMAGEOBJPLIST ←(fetch (IMAGEOBJ IMAGEOBJPLIST) of 
									NC.DeletedLinkImageObject)
				  IMAGEOBJFNS ←(fetch (IMAGEOBJ IMAGEOBJFNS) of 
									NC.DeletedLinkImageObject))))
)
(* * Changed in NCLINKS)

(DEFINEQ

(NC.ShowLinks
  (LAMBDA (TextStream)                                       (* pmi: "19-Jun-87 17:02")
                                                             (* Open an inspector for the links for note card 
							     specified by TextStream above the window for the note 
							     card.)

          (* * fgh 11/13/85 Updated to handle Card object.)



          (* * fgh 5/2/86 Included calls to NC.InsureLinkDisplayMode to handle litatom link display modes.
	  Added InsdiePropListEditor and Reverse indicators to UserData field of Links in show links editor.
	  Also added ShowLinks property onto the editor window so other functions can detect that a window is a show links 
	  window.)



          (* * rht 8/11/86: Now passes non-nil ShowLinksFlg to NC.OpenPropListEditor.)



          (* * rg 4/6/87 removed NC.ProtectedCardOperation wrapper.)



          (* * pmi 6/19/87: Now places each link's UID on the corresponding link created for the inspector.
	  Checks for the validity of each link's source and destination cards and deletes links that are bad 
	  (half-links.))


    (LET (Links EditWindow (Card (NC.CoerceToCard (WINDOW.FROM.TEDIT.THING TextStream))))
         (SETQ Links (NCONC (for Link in (NC.FetchToLinks Card)
				   when (if (NC.ValidCardP (fetch (Link DestinationCard)
								    of Link))
					      then         (* The link is good, include it in the show links 
							     window.)
						     T
					    else           (* The link is bad, delete it and don't include it in 
							     the show links window.)
						   (NC.DeleteLink Link)
						   NIL)
				   join (LIST (COND
						    ((EQ (fetch (Link AnchorMode) of Link)
							   (QUOTE GlobalGlobal))
						      "Global TO")
						    (T "TO"))
						  (LIST (create Link
							     using
							      Link DisplayMode ←(create 
										  LINKDISPLAYMODE
										   copying
										    (
									 NC.InsureLinkDisplayMode
										      (fetch
											(Link 
										      DisplayMode)
											 of Link))
										    SHOWTITLEFLG ← T 
										  SHOWLINKTYPEFLG ← T)
							      UserData ←(QUOTE (InsidePropListEditor
										   T))
							      UID ←(fetch (Link UID) of Link)))))
				(for Link in (NC.FetchFromLinks Card)
				   when (if (NC.ValidCardP (fetch (Link SourceCard)
								    of Link))
					      then         (* The link is good, include it in the show links 
							     window.)
						     T
					    else           (* The link is bad, delete it and don't include it in 
							     the show links window.)
						   (NC.DeleteLink Link)
						   NIL)
				   join (LIST "FROM"
						  (LIST (create Link
							     using
							      Link DisplayMode ←(create 
										  LINKDISPLAYMODE
										   copying
										    (
									 NC.InsureLinkDisplayMode
										      (fetch
											(Link 
										      DisplayMode)
											 of Link))
										    SHOWTITLEFLG ← T 
										  SHOWLINKTYPEFLG ← T)
							      SourceCard ←(fetch (Link 
										  DestinationCard)
									     of Link)
							      DestinationCard ←(fetch (Link 
										       SourceCard)
										  of Link)
							      UserData ←(QUOTE (InsidePropListEditor
										   T Reversed T))
							      UID ←(fetch (Link UID) of Link))))))
	   )
         (WINDOWPROP (SETQ EditWindow (NC.OpenPropListEditor TextStream Links "List of Links" T 
								   T T))
		       (QUOTE ShowLinks)
		       T)
     EditWindow)))

(NC.DeleteLink
  (LAMBDA (Link NoOrphanHookFlg Don'tDelLinkIconFlg)         (* pmi: "19-Jun-87 10:33")

          (* * Delete a link with the option of not putting an orphan hook in case of last filing link.
	  Also option of not deleting link icon from the source card's substance.)



          (* * fgh 5/2/86 Included calls to NC.DelReferencesToCardFromShowLinks in order to clean up ShowLinks windows when 
	  links are deleted.)



          (* * kef 7/17/86: Added the requirement that the write permissions be obtained for the TOLINKS of the Source Card 
	  and the FROMLINKS of the Destination Card.)



          (* * kef 7/22/86: Puts the links for the Destination Card now right away while we are still holding onto the write 
	  lock for the FROMLINKS.)



          (* * kef 7/30/86: Modified to check for Client's concept of whether he owns the write lock or not, thus deciding 
	  whether or not to setup the release of the write lock afterwards.)



          (* * fgh 8/30/86 Adpated to use NC.IfCardPartNotBusy. Note use of ERROR!. Unfortunately, it appears that the only 
	  way to keep TEDIT from deleting the Link's Image Object is to bail out but good. The control structure here works 
	  because NC.IfCardPartNotBusy returns NIL if the CardPart is busy. The Ts at the end as the last SExpr in each call 
	  to NC.IfCardPartNotBusy insure that NC.IfCardPartNotBusy returns non-NIL otherwise.)



          (* * rht 9/29/86: Removed the call to NC.PutFromLinks. Looks to me like it'll get called anyway by NC.DelFromLink 
	  if necessary.)



          (* * rht 10/6/86: Delete crossfilelink cards when their links are deleted.)



          (* * rht 11/4/86: Now takes Don'tCreateDeletedImageObjFlg arg.)



          (* * rht 11/13/86: Undid my change of 11/4/86.)



          (* * rg 3/11/87 changed call of NC.DeleteNoteCard to NC.DeleteNoteCardInternal)



          (* * rht 3/13/87: Broke out code into the NC.DeleteFromLink and NC.DeleteToLink functions.)



          (* * rht 5/26/87: Changed to match reduced functionality of NC.ValidLinkP, now checks that DestinationCard and 
	  SourceCard are valid cards.)



          (* * rht 6/9/87: Slight modification of previous fix; moved check for valid source and destination card to be 
	  around the relevant calls to NC.DeleteFromLink and NC.DeleteToLink.)



          (* * pmi 6/19/87: Leave the check for valid source and destination card for NC.DeleteFromLink and NC.DeleteToLink.)


    (AND (NC.ValidLinkP Link)
	   (LET ((SourceCard (fetch (Link SourceCard) of Link))
		 (DestinationCard (fetch (Link DestinationCard) of Link)))
	        (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			      (OR (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
							  (OR (NC.IfCardPartNotBusy
								  DestinationCard
								  (QUOTE TOLINKS)
								  (NC.DeleteFromLink Link 
										  NoOrphanHookFlg)
								  (NC.DeleteToLink Link 
									      Don'tDelLinkIconFlg)
								  (replace (Link UID) of Link
								     with -1)
								  T)
								(ERROR!))
							  T)
				    (ERROR!)))))))
)
(PUTPROPS PMIPATCH046 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1355 18773 (NC.TraverseLink 1365 . 2813) (NC.LinkIconDisplayFn 2815 . 18771)) (18802 
20689 (NC.DeleteBadLink 18812 . 20036) (NC.ReplaceWithDeletedLinkImageObj 20038 . 20687)) (20721 27859
 (NC.ShowLinks 20731 . 24550) (NC.DeleteLink 24552 . 27857)))))
STOP