(FILECREATED "11-Jun-85 16:27:41" {PHYLUM}<NOTECARDS>RELEASE1.2I>FGHPATCH015.;1 13335  

      changes to:  (VARS FGHPATCH015COMS)
		   (FNS NC.CoerceToExternalPutLinkIcon))


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

(PRETTYCOMPRINT FGHPATCH015COMS)

(RPAQQ FGHPATCH015COMS ((* * New for NCLINKS)
			(FNS NC.CoerceToExternalPutLinkIcon)
			(* * Redefined from NCLINKS)
			(FNS NC.LinkIconWhenCopiedFn NC.LinkIconWhenMovedFn)
			(* * Depends on FGHPATCH012)
			(FILES (FROM {PHYLUM}<NOTECARDS>RELEASE1.2I>)
			       FGHPATCH012)))
(* * New for NCLINKS)

(DEFINEQ

(NC.CoerceToExternalPutLinkIcon
  (LAMBDA (ImageObject SourceID DestinationID LinkLabel)     (* fgh: "11-Jun-85 15:40")

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


    (IMAGEOBJPROP ImageObject (QUOTE OBJECTDATUM)
		  (CONCAT "***[[" LinkLabel " link to " (NC.RetrieveTitle DestinationID)
			  "]]***"))
    (replace (IMAGEOBJ IMAGEOBJFNS) of ImageObject with NC.ExternalPutLinkIconImageFns)))
)
(* * Redefined from NCLINKS)

(DEFINEQ

(NC.LinkIconWhenCopiedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* fgh: "11-Jun-85 15:18")

          (* * 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)))
		 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))))              (* If it's a text copy, then compute position to insert
							     link at.)
          (AND (TEXTSTREAMP ToTextStream)
	       (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)))
	      (RETFROM (QUOTE TEDIT.COPY)
		       NIL 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)))
	      (RETFROM (QUOTE TEDIT.COPY)
		       NIL 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)))
	      (RETFROM (QUOTE TEDIT.COPY)
		       NIL 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)))
	      (RETFROM (QUOTE TEDIT.COPY)
		       NIL 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)))
	      (RETFROM (QUOTE TEDIT.COPY)
		       NIL 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)
                                                             (* fgh: "11-Jun-85 16:22")

          (* * 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))
                                                             (* If it's a text copy, then compute position to insert
							     link at.)
          (AND (TEXTSTREAMP ToTextStream)
	       (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)))))
)
(* * Depends on FGHPATCH012)

(FILESLOAD (FROM {PHYLUM}<NOTECARDS>RELEASE1.2I>)
	   FGHPATCH012)
(PUTPROPS FGHPATCH015 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (595 1084 (NC.CoerceToExternalPutLinkIcon 605 . 1082)) (1120 13151 (
NC.LinkIconWhenCopiedFn 1130 . 7251) (NC.LinkIconWhenMovedFn 7253 . 13149)))))
STOP