(FILECREATED "30-Sep-86 01:01:36" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH112.;2 19771  

      changes to:  (VARS RHTPATCH112COMS)
		   (FNS NC.ChangeLinkDisplayMode NC.PutFromLinks NC.RelabelLink NC.DeleteLink 
			NC.MakeLink)

      previous date: "29-Sep-86 23:42:15" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH112.;1)


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

(PRETTYCOMPRINT RHTPATCH112COMS)

(RPAQQ RHTPATCH112COMS ((* * Changes to NCLINKS)
			  (FNS NC.RelabelLink NC.ChangeLinkDisplayMode NC.DeleteLink NC.MakeLink)
			  (* * Please delete the function NC.CardBeingEditedP from NCCARDS.)
			  (* * Change to NCDATABASE)
			  (FNS NC.PutFromLinks)))
(* * Changes to NCLINKS)

(DEFINEQ

(NC.RelabelLink
  (LAMBDA (LinkOrLinkIcon Window NewLinkLabel ForceRedisplayFlg)
                                                             (* rht: "29-Sep-86 22:51" 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 Card is defined before first use.)



          (* * kirk 14Nov85: deleted use of and LinkID)



          (* * kef 8/8/86: Added obtaining write lock and NC.PutFromLinks.)



          (* * fgh 8/30/86 Adapted to NC.IfCardPartNotBusy)



          (* * rht 9/29/86: Changed Ken's call to NC.CardBeingEditedP to NC.ActiveCardP and other minor mod's.)


    (LET (Link LinkIcon Card DestinationCard OldLabel NoteCardType GlobalLinkFlg)
         (if (NC.LinkIconImageObjP LinkOrLinkIcon)
	     then (SETQ Link (NC.FetchLinkFromLinkIcon LinkOrLinkIcon))
		    (SETQ LinkIcon LinkOrLinkIcon)
	   else (SETQ Link LinkOrLinkIcon)
		  (OR (SETQ GlobalLinkFlg (NC.GlobalLinkP Link))
			(SETQ LinkIcon (NC.FetchLinkIconForLink Link))))
         (SETQ Card (fetch (Link SourceCard) of Link))
         (COND
	   ((WINDOWP Window))
	   ((NC.ActiveCardP Card)
	     (SETQ Window (NC.FetchWindow Card))))
         (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
         (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
			       (COND
				 ((NC.SystemLinkLabelP (fetch (Link Label) 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 NoteCardType (NC.RetrieveType Card))

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


				   (if GlobalLinkFlg
				       then (for GlobalLink in (NC.FetchGlobalLinks Card)
						 when (NC.SameLinkP GlobalLink Link)
						 do (replace (Link Label) of GlobalLink
							 with NewLinkLabel)
						      (NC.SetLinksDirtyFlg Card T)
						      (RETURN))
				     else (replace (Link Label) of (NC.FetchLinkFromLinkIcon
									   LinkIcon)
					       with NewLinkLabel)
					    (NC.MarkCardDirty Card))

          (* * Update ToLink list of the SourceCard card)


				   (for ToLink in (NC.FetchToLinks Card)
				      when (NC.SameLinkP ToLink Link)
				      do (replace (Link Label) of ToLink with NewLinkLabel)
					   (NC.SetLinksDirtyFlg Card T)
					   (RETURN))

          (* * Update FromLink list of DestinationCard card)


				   (if (NC.ActiveCardP DestinationCard)
				       then (for FromLink in (NC.FetchFromLinks 
										  DestinationCard)
						 when (NC.SameLinkP FromLink Link)
						 do (replace (Link Label) of FromLink
							 with NewLinkLabel)
						      (NC.SetLinksDirtyFlg DestinationCard T)
						      (RETURN))
				     else (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile)
										of DestinationCard))
							  (NC.GetLinks DestinationCard)
							  (for FromLink in (NC.FetchFromLinks
										 DestinationCard)
							     when (NC.SameLinkP FromLink Link)
							     do (replace (Link Label)
								     of FromLink with 
										     NewLinkLabel)
								  (NC.SetLinksDirtyFlg 
										  DestinationCard T)
								  (RETURN))
							  (NC.PutFromLinks DestinationCard)
							  (NC.UncacheLinks DestinationCard)))

          (* * Update images in SourceCard window)


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

(NC.ChangeLinkDisplayMode
  (LAMBDA (LinkOrLinkIcon Window NewDisplayMode)             (* rht: "29-Sep-86 23:53")

          (* * Change the display mode of the NOTECARDLINK defined by LinkOrLinkIcon. Have the user choose the new display 
	  mode.)



          (* * NOTE: assumes that the SourceID card of the link is active, i.e., the substance and links are cached for this 
	  card.)



          (* * rht 2/1/85: Now doesn't do all the work if new display mode is same as the old one. Or if user doesn't make a 
	  selection from the menu.)



          (* * kef 8/8/86: Now does the write through to the NoteFile even if the card is active, but not being edited.
	  Also, in the case of doing the write through, puts only the from links.)



          (* * fgh 8/30/86 Adapted to call NC.IfCardPartNotBusy.)



          (* * rht 9/29/86: Changed Ken's call to NC.CardBeingEditedP to NC.ActiveCardP and other minor changes.)


    (LET (Card DestinationCard Link LinkIcon GlobalLinkFlg OldDisplayMode)
         (if (NC.LinkIconImageObjP LinkOrLinkIcon)
	     then (SETQ Link (NC.FetchLinkFromLinkIcon LinkOrLinkIcon))
		    (SETQ LinkIcon LinkOrLinkIcon)
	   else (SETQ Link LinkOrLinkIcon)
		  (OR (SETQ GlobalLinkFlg (NC.GlobalLinkP Link))
			(SETQ LinkIcon (NC.FetchLinkIconForLink Link))))
         (SETQ Card (fetch (Link SourceCard) of Link))
         (SETQ OldDisplayMode (fetch (Link DisplayMode) of Link))
         (COND
	   ((WINDOWP Window))
	   ((NC.ActiveCardP Card)
	     (SETQ Window (NC.FetchWindow Card))))

          (* * Get new display mode from user)


         (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
         (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
			       (if (NOT NewDisplayMode)
				   then (SETQ NewDisplayMode
					    (NC.DisplayModeFromStylesheetSelections
					      (STYLESHEET (CREATE.STYLE
							      (QUOTE ITEMS)
							      (LIST (create MENU
										ITEMS ←(QUOTE
										  (Yes No Float)))
								      (create MENU
										ITEMS ←(QUOTE
										  (Yes No Float)))
								      (create MENU
										ITEMS ←(QUOTE
										  (Yes No Float))))
							      (QUOTE ITEM.TITLES)
							      (QUOTE (Title?%  LinkType?%  
										 AttachBitmap?))
							      (QUOTE ITEM.TITLE.FONT)
							      (FONTCOPY MENUFONT (QUOTE WEIGHT)
									  (QUOTE BOLD))
							      (QUOTE SELECTIONS)
							      (
							   NC.StylesheetSelectionsFromDisplayMode
								OldDisplayMode)
							      (QUOTE NEED.NOT.FILL.IN)
							      NIL
							      (QUOTE TITLE)
							      (QUOTE Display% Mode?)
							      (QUOTE POSITION)
							      (create POSITION
									XCOORD ← LASTMOUSEX
									YCOORD ← LASTMOUSEY))))))
			       (if (OR (NULL NewDisplayMode)
					   (EQUAL NewDisplayMode OldDisplayMode))
				   then 

          (* * If new display mode is same as old, then bail out.)


					  NIL
				 else 

          (* * Update link in LinkIcon or in global links list)


					(if GlobalLinkFlg
					    then (for GlobalLink in (NC.FetchGlobalLinks
									    Card)
						      when (NC.SameLinkP Link GlobalLink)
						      do (replace (Link DisplayMode)
							      of GlobalLink with NewDisplayMode))
						   (NC.SetLinksDirtyFlg Card T)
					  else (replace (Link DisplayMode) of (
									 NC.FetchLinkFromLinkIcon
										      LinkIcon)
						    with NewDisplayMode)
						 (NC.MarkCardDirty Card))

          (* * Update link in ToLinks List of Source card)


					(for ToLink in (NC.FetchToLinks Card)
					   when (NC.SameLinkP Link ToLink)
					   do (replace (Link DisplayMode) of ToLink
						   with NewDisplayMode))
					(NC.SetLinksDirtyFlg Card T) 

          (* * Update Link in FromLinks list of Destination card)


					(if (NC.ActiveCardP DestinationCard)
					    then (for FromLink in (NC.FetchFromLinks 
										  DestinationCard)
						      when (NC.SameLinkP Link FromLink)
						      do (replace (Link DisplayMode)
							      of FromLink with NewDisplayMode))
						   (NC.SetLinksDirtyFlg DestinationCard T)
					  else (WITH.MONITOR (NC.FetchMonitor
								 (fetch (Card NoteFile)
								    of DestinationCard))
							       (NC.GetLinks DestinationCard)
							       (for FromLink in (
										NC.FetchFromLinks
										      DestinationCard)
								  when (NC.SameLinkP Link 
											 FromLink)
								  do (replace (Link DisplayMode)
									  of FromLink with 
										   NewDisplayMode))
							       (NC.PutFromLinks DestinationCard)
							       (NC.DeactivateCard DestinationCard)))

          (* * Update the image in any active window for Card)


					(if (AND (WINDOWP Window)
						     (NOT (NC.TEditBasedP (NC.RetrieveType
										Card))))
					    then (NC.UpdateLinkImages Window (fetch
									    (Link DestinationCard)
										    of Link)))
                                                             (* This causes tedit to redisplay the screen.)
					(QUOTE CHANGED))))))

(NC.DeleteLink
  (LAMBDA (Link NoOrphanHookFlg Don'tDelLinkIconFlg)         (* rht: "29-Sep-86 23:13")

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


    (LET ((SourceCard (fetch (Link SourceCard) of Link))
	  (DestinationCard (fetch (Link DestinationCard) of Link))
	  BusyCardPart)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
		       (OR (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
						   (OR (NC.IfCardPartNotBusy DestinationCard
									       (QUOTE TOLINKS)
									       (OR 
									      Don'tDelLinkIconFlg
										     (
									   NC.DelReferencesToCard
										       SourceCard 
										       Link))
									       (NC.DelFromLink
										 Link NoOrphanHookFlg)
									       (NC.DelToLink Link)
									       (
							      NC.DelReferencesToCardFromShowLinks
										 SourceCard Link)
									       (
							      NC.DelReferencesToCardFromShowLinks
										 DestinationCard Link)

          (* * This UID replacement is worrisome. Does it mean that link deletion can't be undone?)


									       (replace
										 (Link UID)
										  of Link
										  with -1)
									       T)
							 (ERROR!))
						   T)
			     (ERROR!))))))

(NC.MakeLink
  (LAMBDA (Window LinkLabel DestinationCard SourceCard DisplayMode AnchorMode Message NoDisplayFlg 
		  LinkToInsertAfter)                         (* rht: "29-Sep-86 23:34")

          (* * Make a link from (OR Window SourceCard) to DestinationCard with linklabel of LinkLabel)



          (* * rht 1/12/85: If need to create a new card, then now shows card type menu near window of SourceID.)



          (* * rht 1/13/85: Added extra args Message and NoDisplayFlg.)



          (* * rht 3/26/85: Added LinkToInsertAfter arg which should be NIL or a link to insert the new To link after.
	  If NIL, then insert at front of ToLinks.)



          (* * kirk 9/23/85: took out GETPROMPTWINDOW call for asknotecardtype)



          (* * kirk: 14Nov85: changed NC.CoerceToID to to NC.CoerceToCard)



          (* * fgh 11/16/85 Changed from PROG to LET and used COND to contyrol returnmed value.)



          (* * fgh 2/5/86 Changed call DefaultLinkDisplayMode to FetchLinkDisplayMode)



          (* * fgh 6/5/86 Now calls AskLinkLabel if LinkLabel arg is NIL)



          (* * rht 7/4/86: Added check for readonly card.)



          (* * kef 7/17/86: Added calls to grab the write permission on the appropriate card parts.)



          (* * kef 7/22/86: Saves the links on the Destination Card now right away, while still holding onto the FROMLINKS 
	  write lock.)



          (* * fgh 8/30/86 Adpated to use NC.IfCardPartNotBusy.)



          (* * rht 9/29/86: Tossed Ken's call to NC.PutFromLinks; It was the cause of too many nasty breaks.
	  Also made syntactic fixes.)


    (DECLARE (GLOBALVARS NC.SelectingSingleCardMenu))
    (OR SourceCard (SETQ SourceCard (NC.CoerceToCard Window)))
    (AND (NC.CheckForNotReadOnly SourceCard Window "Can't make links in ")
	   (LET (Link Type)
	        (OR Window (SETQ Window (NC.FetchWindow SourceCard)))
	        (OR Message (SETQ Message "Please select the Card or Box to be linked to."))
	        (OR LinkLabel (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T NIL)))
	        (OR DestinationCard (SETQ DestinationCard
			(NC.SelectNoteCards T (FUNCTION (LAMBDA (Card)
						  (COND
						    ((NOT (NC.SameCardP Card SourceCard))
						      T)
						    (T (NC.PrintMsg Window T 
							     "A Card/Box cannot link to itself. "
								      (CHARACTER 13)
								      "Selection ignored."
								      (CHARACTER 13))
						       NIL))))
					      NC.SelectingSingleCardMenu SourceCard NIL Message)))
	        (if (EQ DestinationCard (QUOTE *New% Card*))
		    then (SETQ DestinationCard (AND (SETQ Type (NC.AskNoteCardType
							      (WINDOWREGION Window)))
							  (NC.CoerceToCard
							    (NC.MakeNoteCard Type
									       (fetch (Card 
											 NoteFile)
										  of SourceCard)
									       NIL NoDisplayFlg)))))
	        (if DestinationCard
		    then (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
						 (NC.IfCardPartNotBusy SourceCard (QUOTE TOLINKS)
								       (SETQ Link
									 (create
									   Link
									   UID ←(NC.MakeUID)
									   SourceCard ← SourceCard
									   DestinationCard ← 
									   DestinationCard
									   AnchorMode ← AnchorMode
									   Label ← LinkLabel
									   DisplayMode ←(OR
									     DisplayMode
									     (
									  NC.FetchLinkDisplayMode
									       SourceCard))))
								       (NC.AddToLink Link 
										LinkToInsertAfter)
								       (NC.AddFromLink Link)
								       Link))
		  else NIL)))))
)
(* * Please delete the function NC.CardBeingEditedP from NCCARDS.)

(* * Change to NCDATABASE)

(DEFINEQ

(NC.PutFromLinks
  (LAMBDA (Card)                                             (* rht: "30-Sep-86 01:00")

          (* * The top level function for writing out only the FROMLINKS of a card. Became a necessary function in the 
	  process of implementing the Server.)



          (* * rht 9/11/86: Now checks for card active via NC.CardActiveP rather than by checking for ACTIVE status.)



          (* * rht 9/30/86: Undid change of 9/11/86. Card may not have ActiveFlg set when we're doing PutFromLinks.)


    (DECLARE (GLOBALVARS NC.LinksIdentifier))            (* Check to make sure this is an active note card.)
    (if (NEQ (NC.FetchStatus Card)
		 (QUOTE ACTIVE))
	then (NC.ReportError "NC.PutFromLinks" (CONCAT (NC.FetchTitle Card)
							     " is not an active note card.")))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (RESETLST (RESETSAVE (APPLY* (fetch (NoteFile PutCardPartFn)
							     of (fetch (Card NoteFile)
								     of Card))
							  Card
							  (QUOTE FROMLINKS)
							  (QUOTE BEFORE))
						(BQUOTE (APPLY* , (fetch (NoteFile 
										    PutCardPartFn)
									 of (fetch (Card NoteFile)
										 of Card))
								    , Card FROMLINKS AFTER)))
				   (LET ((Stream (NC.CoerceToNoteFileStream Card))
					 StartLoc)

          (* * Write the links data at the end of the database file.)


				        (SETQ StartLoc (GETFILEPTR Stream))
				        (NC.WriteCardPartHeader Card NC.LinksIdentifier
								  (NC.SetLinksDate Card (DATE))
								  Stream)
				        (NC.WriteListOfLinks Stream (NC.FetchFromLinks Card))

          (* * Now update the index to point to the link data just written. Done last in case writing of links doesn't 
	  complete okay.)


				        (NC.SetLinksDirtyFlg Card)

          (* * Now, since we were successful, we'll bind the PutSuccessfulLoc variable, which will be used freely by the 
	  AFTER PutCardPartFns to determine first if the Put succeeded, and if so, where in the stream it was Put.)


				        (SETQ PutSuccessfulLoc StartLoc)
				    Card))))))
)
(PUTPROPS RHTPATCH112 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (709 17265 (NC.RelabelLink 719 . 5078) (NC.ChangeLinkDisplayMode 5080 . 10654) (
NC.DeleteLink 10656 . 13480) (NC.MakeLink 13482 . 17263)) (17372 19689 (NC.PutFromLinks 17382 . 19687)
))))
STOP