(FILECREATED " 1-Jul-87 19:34:21" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH281.;3 20442  

      changes to:  (VARS RHTPATCH281COMS)
		   (FNS NC.LinkIconWhenCopiedFn NC.LinkIconWhenMovedFn NC.LinkIconCopyFn 
			NC.LinkIconWhenInsertedFn)

      previous date: "24-Jun-87 17:56:54" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH281.;1)


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

(PRETTYCOMPRINT RHTPATCH281COMS)

(RPAQQ RHTPATCH281COMS ((DECLARE: FIRST (P (NC.LoadFileFromDirectories (QUOTE NCSKETCHCARD))))
			  (* * Fixes to make copying links between sketch cards and between sketch 
			     and tedit cards possible. Relies on Richard's recent sketch patch. Also 
			     copying or moving a link with system link label may still change link 
			     type to Unspecified, but no longer changes link display mode.)
			  (* * Changes to NCLINKS)
			  (FNS NC.LinkIconCopyFn NC.LinkIconWhenInsertedFn NC.LinkIconWhenCopiedFn 
			       NC.LinkIconWhenMovedFn)
			  (* * Following should be added to coms of KOTOSKETCHPATCHES)
			  (FILES (FROM {phylum}<paperworks>)
				 SKETCHWHENCOPIEDPATCH)))
(DECLARE: FIRST 
(NC.LoadFileFromDirectories (QUOTE NCSKETCHCARD))
)
(* * Fixes to make copying links between sketch cards and between sketch and tedit cards 
possible. Relies on Richard's recent sketch patch. Also copying or moving a link with system 
link label may still change link type to Unspecified, but no longer changes link display mode.)

(* * Changes to NCLINKS)

(DEFINEQ

(NC.LinkIconCopyFn
  (LAMBDA (ImageObject)                                      (* rht: "24-Jun-87 16:30")

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



          (* * fgh 1/29/86 Removed the "copying ImageObj" clause in the create of ImageObjectCopy to fix bug where the 
	  copying was causing a stack overflow thru infinite recursive COPYALL calls. Copying clause was unnecessary.)



          (* * rht 6/24/87: Now saves original imageobj on the OriginalImageObject property of ImageObjectCopy.)


    (LET ((ImageObjectCopy (create IMAGEOBJ))
	  (Link (NC.FetchLinkFromLinkIcon ImageObject)))
         (NC.CoerceToExternalPutLinkIcon ImageObjectCopy (fetch (Link SourceCard) of Link)
					   (fetch (Link DestinationCard) of Link)
					   (fetch (Link Label) of Link))
         (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)
			 ImageObjectCopy)
         (IMAGEOBJPROP ImageObjectCopy (QUOTE OriginalImageObject)
			 ImageObject)
         (IMAGEOBJPROP ImageObjectCopy (QUOTE WHENINSERTEDFN)
			 (FUNCTION NC.LinkIconWhenInsertedFn))
     ImageObjectCopy)))

(NC.LinkIconWhenInsertedFn
  (LAMBDA (ImageObj WindowStream)                            (* rht: "24-Jun-87 16:29")
                                                             (* An Notecard link is being inserted.
							     If this is a deleteundo, then have to re-establish the
							     link information)

          (* * kirk 15Nov85: deleted use of PSA.Database)



          (* * rht 6/24/87: Now calls WhenDeletedFn if the imageobj has an OriginalImageObject property, i.e. we're in the 
	  middle of a copy.)


    (LET ((OriginalImageObj (IMAGEOBJPROP ImageObj (QUOTE OriginalImageObject))))
         (if OriginalImageObj
	     then (NC.LinkIconWhenCopiedFn OriginalImageObj WindowStream)
		    (IMAGEOBJPROP ImageObj (QUOTE OriginalImageObject)
				    NIL)
	   else (LET ((StackPointer (STKPOS (QUOTE TEDIT.UNDO.DELETION)))
			SourceCard Link)
		       (COND
			 ((NULL StackPointer)
			   (RELSTK StackPointer))
			 (T (RELSTK StackPointer)
			    (SETQ SourceCard (NC.CoerceToCard WindowStream))
			    (COND
			      ((NC.CardP SourceCard)
				(SETQ Link (NC.FetchLinkFromLinkIcon ImageObj))
				(NC.AddFromLink Link)
				(NC.AddToLink Link))))))))))

(NC.LinkIconWhenCopiedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: " 1-Jul-87 19:27")

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



          (* * rht 3/24/86: Changed call to NC.CoerceToID to NC.CoerceToCard)



          (* * fgh 6/30/86 Now ERROR! out of attempt to copy between NoteFiles)



          (* * rht 7/14/86: Reversed order of tests for WINDOWP and TEXTSTREAMP in computation of NewSourceCard.)



          (* * rht 8/11/86: Now only resets NewSourceCard if it was NIL so that copies to a sketch will work.)



          (* * rht 10/5/86: Undid change fgh 6/30/86: now allows copies of links across notefiles. Also handles illegal 
	  copies differently. Rather than RETFROM'ing or ERROR!'ing, it puts in a DELETE ME imageobj.)



          (* * rht 12/16/86: Now passes Window to NC.GetCrossFileLinkDestCard.)



          (* * rht 1/21/87: Now handles attempt to copy to non-NoteCards stream differently than other illegalities.)



          (* * rht 1/25/87: Now stashes new link created on source card's user data props for use by NC.LinkAtCharPos in case
	  this is a copy of multiple links.)



          (* * rht 6/24/87: Undid change of 3/25/85. No longer needed and causes bugs.)



          (* * rht 7/1/87: Removed action of changing linkdisplaymode when copying system links.)


    (DECLARE (GLOBALVARS NC.CopyCrossFileLinksMode NC.DELETEMEImageObjDatum NC.SystemLinkLabels 
			     NC.UnspecifiedLinkLabel NC.NewCrossFileLinksTwoWayFlg))
    (LET ((Link (NC.FetchLinkFromLinkIcon ImageObject))
	  (ImageObjectCopy (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)))
	  (InTEditCopyFlg (COND
			    ((STKPOS (QUOTE TEDIT.COPY))
			      T)))
	  (Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
	  SourceCard DestinationCard NewSourceCard NewLabel OldDisplayMode Label InsertPos 
	  IllegalCopyFlg ExternalCopyFlg)
         (SETQ Label (fetch (Link Label) of Link))
         (SETQ SourceCard (fetch (Link SourceCard) of Link))
         (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
         (SETQ OldDisplayMode (fetch (Link DisplayMode) of Link))
         (SETQ NewSourceCard (COND
	     ((TEXTSTREAMP ToTextStream)
	       (NC.CoerceToCard ToTextStream))
	     ((WINDOWP Window)
	       (NC.CoerceToCard Window))))
         (COND
	   ((TEXTSTREAMP ToTextStream)                     (* If it's a text copy, then compute position to 
							     insert link at.)
	     (SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))
         (COND
	   ((NULL NewSourceCard)                           (* Trying to copy to a non NoteCard stream)
	     (NC.PrintMsg NIL NIL (CONCAT "Tried to copy a NoteCards link icon" 
					      " to a non-NoteCards stream."
					      (CHARACTER 13)))
	     (SETQ ExternalCopyFlg T))
	   ((NULL (NC.LinksSupportedP NewSourceCard (QUOTE (Local))))
	     (NC.PrintMsg Window NIL (CONCAT "Tried to copy a NoteCards link icon" 
						 " to a NoteCard that"
						 " does not support links!!."
						 (CHARACTER 13)))
	     (SETQ IllegalCopyFlg T))
	   ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		   (NEQ (NC.RetrieveType NewSourceCard)
			  (QUOTE FileBox)))                (* Copy from filebox to non-filebox.)
	     (NC.PrintMsg Window 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))
	   ((AND (NEQ (NC.RetrieveType SourceCard)
			  (QUOTE FileBox))
		   (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox)))                 (* Copy from non-filebox to filebox.)
	     (NC.PrintMsg Window NIL (CONCAT "Can't copy links from non-filebox to filebox."
						 (CHARACTER 13)
						 "Try using 'PutCardsHere'."
						 (CHARACTER 13)))
	     (SETQ IllegalCopyFlg T))
	   ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		   (EQ NewSourceCard SourceCard))          (* Copy within same filebox.)
	     (NC.PrintMsg Window NIL (CONCAT 
					  "Can't copy links within a FileBox.  Try move instead."
						 (CHARACTER 13)))
	     (SETQ IllegalCopyFlg T))
	   ((AND (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox))
		   (for Link1 in (NC.FetchToLinks NewSourceCard)
		      thereis (AND (NC.ChildLinkP Link1)
				       (EQ DestinationCard (fetch (Link DestinationCard)
								of Link1)))))
                                                             (* Copy to a filebox already containing this child.)
	     (NC.PrintMsg Window NIL (CONCAT (NC.RetrieveTitle DestinationCard)
						 " not copied: already appears as a child of "
						 (NC.RetrieveTitle NewSourceCard)
						 (CHARACTER 13)))
	     (SETQ IllegalCopyFlg T))
	   ((AND (EQ Label (QUOTE SubBox))
		   (OR (EQ NewSourceCard DestinationCard)
			 (NOT (NC.NotDaughterP DestinationCard NewSourceCard
						   (FUNCTION NC.ChildLinkP)))))
                                                             (* Copy to a filebox causes a cycle.)
	     (NC.PrintMsg Window NIL (CONCAT "Couldn't copy " Link " because of subbox cycle."
						 (CHARACTER 13)))
	     (SETQ IllegalCopyFlg T))
	   ((AND (FMEMB Label NC.SystemLinkLabels)
		   (NOT (FMEMB Label (QUOTE (FiledCard SubBox))))
		   (NEQ NewSourceCard SourceCard))         (* Copy of system link outside of own card.)
	     (NC.PrintMsg Window NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
						 "Link type of copy set to 'Unspecified'."
						 (CHARACTER 13)))
	     (SETQ NewLabel NC.UnspecifiedLinkLabel))
	   ((NC.CrossFileLinkCardP DestinationCard)        (* Copy of a cross-file link.)
	     (if (NOT (NC.ActiveCardP DestinationCard))
		 then (NC.GetNoteCard DestinationCard))
                                                             (* If it's to be two-way, then make a fresh 
							     CrossFileLinkCard.)
	     (if (OR (EQ NC.CopyCrossFileLinksMode (QUOTE TWOWAY))
			 (AND (NULL NC.CopyCrossFileLinksMode)
				NC.NewCrossFileLinksTwoWayFlg))
		 then (SETQ DestinationCard (NC.GetCrossFileLinkDestCard DestinationCard Window)
			  ))
	     (OR DestinationCard (SETQ IllegalCopyFlg T))))
         (COND
	   (IllegalCopyFlg (IMAGEOBJPROP ImageObjectCopy (QUOTE OBJECTDATUM)
					   NC.DELETEMEImageObjDatum)
			   (NC.SetUserDataProp SourceCard (QUOTE NeedsCleaningFlg)
						 T))
	   (ExternalCopyFlg (NC.CoerceToExternalPutLinkIcon ImageObjectCopy SourceCard 
							      DestinationCard (OR NewLabel Label)))
	   (T (NC.SetUserDataProp NewSourceCard (QUOTE LastLinkCopiedOrMoved)
				    (NC.FillInLinkIcon ImageObjectCopy (OR NewLabel Label)
							 DestinationCard NewSourceCard OldDisplayMode
							 (NC.LinkAtCharPos InsertPos ToTextStream)
							 NC.CopyCrossFileLinksMode))))
         (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)
			 NIL))))

(NC.LinkIconWhenMovedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: " 1-Jul-87 19: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.)



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



          (* * kirk 15Nov85: deleted use of PSA.Database)



          (* * rht 3/24/86: Changed call to NC.CoerceToID to NC.CoerceToCard)



          (* * kirk 24Mar86: added Dave Newman patch to avoid duplicate links in sketch cards)



          (* * rht 7/14/86: Reversed order of tests for WINDOWP and TEXTSTREAMP in computation of NewSourceCard.)



          (* * rht 8/11/86: Now only resets NewSourceCard if it was NIL so that moves to a sketch will work.
	  Now checks if SourceCard = NewSourceCard in which case we're moving within a card. Don't make a new link in that 
	  case.)



          (* * rht 10/5/86: Undid change fgh 6/30/86: now allows copies of links across notefiles.)



          (* * rht 11/13/86: Removed "tsk, tsk" messages.)



          (* * rht 12/16/86: Fixed calls to NC.PrintMsg to use Window arg.)



          (* * rht 1/25/87: Now stashes new link created on source card's user data props for use by NC.LinkAtCharPos in case
	  this is a copy of multiple links.)



          (* * rht 7/1/87: Removed action of changing linkdisplaymode when copying system links.)


    (DECLARE (GLOBALVARS NC.SystemLinkLabels NC.UnspecifiedLinkLabel))
    (LET (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		SourceCard DestinationCard NewSourceCard NewLabel OldDisplayMode
		(Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
		InsertPos)
         (SETQ Label (fetch (Link Label) of Link))
         (SETQ NewSourceCard (COND
	     ((TEXTSTREAMP ToTextStream)
	       (NC.CoerceToCard ToTextStream))
	     ((WINDOWP Window)
	       (NC.CoerceToCard Window))))
         (SETQ SourceCard (fetch (Link SourceCard) of Link))
         (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
         (SETQ OldDisplayMode (fetch (Link DisplayMode) of Link))
         (COND
	   ((AND (NULL NewSourceCard)
		   (NULL FromTextStream)
		   (NULL ToTextStream))                    (* We must be moving within a sketch.)
	     (SETQ NewSourceCard SourceCard))
	   ((TEXTSTREAMP ToTextStream)                     (* If it's a text copy, then compute position to 
							     insert link at.)
	     (SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))
         (COND
	   ((NULL NewSourceCard)                           (* 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)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((NULL (NC.LinksSupportedP NewSourceCard (QUOTE (Local))))
	     (NC.PrintMsg Window NIL (CONCAT "Tried to move a NoteCards link icon" 
						 " to a NoteCard that"
						 " does not support links!!."
						 (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		   (NEQ (NC.RetrieveType NewSourceCard)
			  (QUOTE FileBox)))                (* Move from filebox to non-filebox.)
	     (NC.PrintMsg Window 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))
	   ((AND (NEQ (NC.RetrieveType SourceCard)
			  (QUOTE FileBox))
		   (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox)))                 (* Move from non-filebox to filebox.)
	     (NC.PrintMsg Window NIL (CONCAT "Can't move links from non-filebox to filebox."
						 (CHARACTER 13)
						 "Try using PutCardsHere."
						 (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox))
		   (NEQ NewSourceCard SourceCard)
		   (for Link1 in (NC.FetchToLinks NewSourceCard)
		      thereis (AND (NC.ChildLinkP Link1)
				       (EQ DestinationCard (fetch (Link DestinationCard)
								of Link1)))))
                                                             (* Move to a filebox already containing this child.)
	     (NC.PrintMsg Window NIL (CONCAT (NC.RetrieveTitle DestinationCard)
						 " not moved: already appears as a child of "
						 (NC.RetrieveTitle NewSourceCard)
						 (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (EQ Label (QUOTE SubBox))
		   (NEQ NewSourceCard SourceCard)
		   (OR (EQ NewSourceCard DestinationCard)
			 (NOT (NC.NotDaughterP DestinationCard NewSourceCard
						   (FUNCTION NC.ChildLinkP)))))
                                                             (* Move to a filebox causes a cycle.)
	     (NC.PrintMsg Window 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 NewSourceCard SourceCard))         (* Move of system link outside of own card.)
	     (NC.PrintMsg Window NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
						 "Link type of copy set to 'Unspecified'."
						 (CHARACTER 13)))
	     (SETQ NewLabel NC.UnspecifiedLinkLabel)))
         (if (EQ SourceCard NewSourceCard)
	     then                                          (* Moving within a card, so just reposition Link in 
							     ToLinks list.)
		    (AND (NC.TEditBasedP SourceCard)
			   (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard)
					   Link))
		    (NC.AddToLink Link (NC.LinkAtCharPos InsertPos ToTextStream)
				    T)
	   else (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
				  Link)
		  (NC.SetUserDataProp NewSourceCard (QUOTE LastLinkCopiedOrMoved)
					(NC.FillInLinkIcon ImageObject (OR NewLabel Label)
							     DestinationCard NewSourceCard 
							     OldDisplayMode (NC.LinkAtCharPos
							       InsertPos ToTextStream)))))))
)
(* * Following should be added to coms of KOTOSKETCHPATCHES)

(FILESLOAD (FROM {phylum}<paperworks>)
	   SKETCHWHENCOPIEDPATCH)
(PUTPROPS RHTPATCH281 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1498 20227 (NC.LinkIconCopyFn 1508 . 3271) (NC.LinkIconWhenInsertedFn 3273 . 4560) (
NC.LinkIconWhenCopiedFn 4562 . 12830) (NC.LinkIconWhenMovedFn 12832 . 20225)))))
STOP