(FILECREATED " 8-Jun-87 18:02:18" {QV}<NOTECARDS>1.3K>NEXT>NCCARDS.;93 179905 

      changes to:  (FNS NC.QuitCard NC.ClosePropListEditor NC.CheckTitle NC.EditNoteCard 
			NC.LinksCachedP NC.AbortCard NC.DetermineDisplayRegion NC.CardSaveFn 
			NC.RetrieveFromLinks NC.RetrieveToLinks NC.RetrieveGlobalLinks 
			NC.SeverExternalLinks NC.DeleteNoteCardInternal)
		   (VARS NCCARDSCOMS)

      previous date: "22-Apr-87 12:10:20" {QV}<NOTECARDS>1.3K>NEXT>NCCARDS.;92)


(* Copyright (c) 1984, 1985, 1986, 1987 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT NCCARDSCOMS)

(RPAQQ NCCARDSCOMS ((* * Internal variables)
	(GLOBALVARS NC.SubBoxMarkerLabel NC.FiledCardMarkerLabel NC.PlaceMarkerDisplayFont USERNAME 
		    NC.SavePropEditMenu TEDIT.SELPENDING NC.SystemLinkLabels NC.SourceLinkLabel 
		    NC.FiledCardLinkLabel NC.CloseCardsOffScreenFlg NC.BringUpCardAtOldPosFlg 
		    NC.DefaultLinkIconAttachedBitMapHeights NC.SystemCardPropNames)
	[VARS (NC.SubBoxMarkerLabel "File Boxes")
	      (NC.FiledCardMarkerLabel "Note Cards")
	      (NC.PlaceMarkerDisplayFont (FONTCREATE (QUOTE HELVETICA)
						     12
						     (QUOTE ITALIC)))
	      (NC.SystemCardPropNames (QUOTE (Updates]
	[INITVARS (NC.DefaultLinkIconAttachedBitMapHeights (QUOTE (11 13 15 17 18 19 20 21 23 25]
	(* * The Card Objects)
	(RECORDS CardObject CardCache Card LinksCache)
	(FNS NC.CardOrCardHolderFromUID NC.CardP NC.DeleteNoteCard NC.DeleteNoteCardInternal 
	     NC.SameCardP)
	(* * Manipulate Note Card Representations)
	(FNS NC.FetchStatus NC.SetNewCardFlg NC.FetchNewCardFlg NC.ActivateCard NC.ActiveCardP 
	     NC.DeactivateCard NC.FetchFromLinks NC.FetchGlobalLinks NC.FetchLinksDirtyFlg 
	     NC.FetchPropList NC.FetchRegion NC.FetchSavedRegion NC.FetchRegionViewed NC.FetchScale 
	     NC.FetchSlotNum NC.FetchSubstance NC.FetchTitle NC.FetchToLinks NC.FetchType 
	     NC.FetchWindow NC.IDP NC.MarkCardDirty NC.CardDirtyP NC.SetFromLinks NC.SetGlobalLinks 
	     NC.SetLinksDirtyFlg NC.SetPropList NC.SetRegion NC.SetSavedRegion NC.SetRegionViewed 
	     NC.SetScale NC.SetSubstance NC.SetTitle NC.SetToLinks NC.SetType NC.FetchTitleDirtyFlg 
	     NC.SetTitleDirtyFlg NC.FetchPropListDirtyFlg NC.SetPropListDirtyFlg 
	     NC.SetSubstanceDirtyFlg NC.FetchSubstanceDirtyFlg NC.TurnOffDirtyFlgs 
	     NC.FetchUserDataProp NC.SetUserDataProp NC.SetUserDataPropList NC.MakeTypeIconBitMapSet 
	     NC.MakeNewCardWindow)
	(* * Read subscriptions and write locks on card parts)
	(FNS NC.ObtainEditPermission NC.CardPartBusy)
	(MACROS NC.WithWritePermission NC.IfCardPartNotBusy NC.IfMultipleCardPartsNotBusy)
	(* * Stuff to handle read-only notefiles.)
	(FNS NC.ReadOnlyCardP NC.CardSomehowDirtyP)
	(* * Hash Array Handler)
	(MACROS NC.MapCards)
	(* * Retrieve Note Card Info)
	(FNS NC.RetrieveFromLinks NC.RetrieveLinkLabels NC.StoreLinkLabels NC.RetrievePropList 
	     NC.RetrieveTitle NC.RetrieveToLinks NC.RetrieveGlobalLinks NC.RetrieveType 
	     NC.RetrieveTypeAndTitle NC.LinksCachedP NC.ShowInfo)
	(* * General note card manipulations)
	(FNS NC.AddParents NC.SeverExternalLinks NC.AssignTitle NC.DeleteNoteCards NC.EditNoteCard 
	     NC.MakeNoteCard NC.QuitCard NC.CheckFiling NC.CheckTitle NC.ForceFilingForCardTypeP 
	     NC.InsureProperFiling NC.QuitWithoutSaving NC.UnfileNoteCard NC.UpdateUpdateList 
	     NC.CollectReferences NC.CardSaveFn NC.DetermineDisplayRegion NC.AbortCard 
	     NC.CardNeedsFilingP NC.TopLevelCardP NC.MakeDummyRegion NC.ValidCardP 
	     NC.TitleBarButtonEventFn NC.InstallTitleBarMiddleMenu)
	(* * Prop List Editor)
	(RECORDS PropListItem)
	(FNS NC.AddPropToPropList NC.CloseAllPropListEditors NC.ClosePropListEditor 
	     NC.DelPropFromList NC.EditPropButtonFN NC.EditProperties NC.EditPropList 
	     NC.ExtractPropList NC.OpenPropListEditor NC.ProcessEditedPropList NC.PropListEditorOpenP 
	     NC.SelectProperty NC.ShowLinks NC.StringIsListP NC.PutProp NC.GetProp NC.RemProp)
	(* * Unknown ?????????)
	(FNS NC.FetchBeingDeletedFlg NC.SetBeingDeletedFlg NC.RemoveDELETEMEImageObjsFromCard 
	     NC.InsureIntegerDate)
	(* * Place marker ImageObjects)
	(FNS NC.PlaceMarkerCopyFn NC.PlaceMarkerDisplayFn NC.PlaceMarkerGetFn 
	     NC.PlaceMarkerImageBoxFn NC.PlaceMarkerPutFn NC.MakePlaceMarker)
	(* * Functions for handling dates.)
	(FNS NC.FetchTitleDate NC.FetchItemDate NC.FetchPropListDate NC.FetchLinksDate 
	     NC.FetchLinkIconAttachedBitMap NC.FetchLinkDisplayMode NC.FetchDefaultWidth 
	     NC.FetchDefaultHeight NC.FetchLinkAnchorModesSupported)
	(FNS NC.SetTitleDate NC.SetItemDate NC.SetPropListDate NC.SetLinksDate)))
(* * Internal variables)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.SubBoxMarkerLabel NC.FiledCardMarkerLabel NC.PlaceMarkerDisplayFont USERNAME 
	    NC.SavePropEditMenu TEDIT.SELPENDING NC.SystemLinkLabels NC.SourceLinkLabel 
	    NC.FiledCardLinkLabel NC.CloseCardsOffScreenFlg NC.BringUpCardAtOldPosFlg 
	    NC.DefaultLinkIconAttachedBitMapHeights NC.SystemCardPropNames)
)

(RPAQ NC.SubBoxMarkerLabel "File Boxes")

(RPAQ NC.FiledCardMarkerLabel "Note Cards")

(RPAQ NC.PlaceMarkerDisplayFont (FONTCREATE (QUOTE HELVETICA)
					      12
					      (QUOTE ITALIC)))

(RPAQQ NC.SystemCardPropNames (Updates))

(RPAQ? NC.DefaultLinkIconAttachedBitMapHeights (QUOTE (11 13 15 17 18 19 20 21 23 25)))
(* * The Card Objects)

[DECLARE: EVAL@COMPILE 

(DATATYPE CardObject (UID NoteFile Monitor Status (IndexDirtyFlg FLAG)
			      (IndexLoc INTEGER)
			      (MainLoc INTEGER)
			      (LinksLoc INTEGER)
			      (PropListLoc INTEGER)
			      (TitleLoc INTEGER)
			      Title
			      (TitleDirtyFlg FLAG)
			      Type
			      (ActiveFlg FLAG)
			      CardCache UserData))

(DATATYPE CardCache (Substance Links PropList Region SavedRegion (ItemDate FIXP)
				 (LinksDate FIXP)
				 (TitleDate FIXP)
				 (PropListDate FIXP)
				 (ActiveCardFlg FLAG)
				 (LinksDirtyFlg FLAG)
				 (PropListDirtyFlg FLAG)
				 (SubstanceDirtyFlg FLAG)
				 (NewCardFlg FLAG)
				 (BeingDeletedFlg FLAG)))

(ACCESSFNS Card [

          (* * Instance variables of the card object)


		   (UID (fetch (CardObject UID) of DATUM)
			  (replace (CardObject UID) of DATUM with NEWVALUE))
		   (NoteFile [LET ((\NF (fetch (CardObject NoteFile) of DATUM)))
			          (COND
				    ((type? NoteFile \NF)
				      \NF)
				    (\NF (replace (CardObject NoteFile) of DATUM
					    with (NC.NoteFileFromNoteFileUID \NF]
			     (replace (CardObject NoteFile) of DATUM with NEWVALUE))
		   (Monitor (fetch (CardObject Monitor) of DATUM)
			    (replace (CardObject Monitor) of DATUM with NEWVALUE))
		   (Status (fetch (CardObject Status) of DATUM)
			   (replace (CardObject Status) of DATUM with NEWVALUE))
		   (IndexDirtyFlg (fetch (CardObject IndexDirtyFlg) of DATUM)
				  (replace (CardObject IndexDirtyFlg) of DATUM with NEWVALUE))
		   (IndexLoc (fetch (CardObject IndexLoc) of DATUM)
			     (replace (CardObject IndexLoc) of DATUM with NEWVALUE))
		   (MainLoc (fetch (CardObject MainLoc) of DATUM)
			    (replace (CardObject MainLoc) of DATUM with NEWVALUE))
		   (LinksLoc (fetch (CardObject LinksLoc) of DATUM)
			     (replace (CardObject LinksLoc) of DATUM with NEWVALUE))
		   (PropListLoc (fetch (CardObject PropListLoc) of DATUM)
				(replace (CardObject PropListLoc) of DATUM with NEWVALUE))
		   (TitleLoc (fetch (CardObject TitleLoc) of DATUM)
			     (replace (CardObject TitleLoc) of DATUM with NEWVALUE))
		   (Title (fetch (CardObject Title) of DATUM)
			  (replace (CardObject Title) of DATUM with NEWVALUE))
		   (TitleDirtyFlg (fetch (CardObject TitleDirtyFlg) of DATUM)
				  (replace (CardObject TitleDirtyFlg) of DATUM with NEWVALUE))

          (* Note the use of NC.GetType if CardType is NIL. This is required to force the access to go to the disk for the 
	  card type if the card type caching process is not finished before this fetch is being made.
	  Sort of a kludge.)


		   (Type (OR (fetch (CardObject Type) of DATUM)
			       (NC.GetType DATUM))
			 (replace (CardObject Type) of DATUM with NEWVALUE))
		   (ActiveFlg (fetch (CardObject ActiveFlg) of DATUM)
			      (replace (CardObject ActiveFlg) of DATUM with NEWVALUE))
		   (ActiveCardFlg (fetch (CardObject ActiveFlg) of DATUM)
				  (replace (CardObject ActiveFlg) of DATUM with NEWVALUE))
		   (CardCache (fetch (CardObject CardCache) of DATUM)
			      (replace (CardObject CardCache) of DATUM with NEWVALUE))
		   (UserData (fetch (CardObject UserData) of DATUM)
			     (replace (CardObject UserData) of DATUM with NEWVALUE))
		   [Substance (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (AND \Cache (fetch (CardCache Substance) of \Cache)))
			      (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (COND
				     (\Cache (replace (CardCache Substance) of \Cache
						with NEWVALUE))
				     (T (replace (CardObject CardCache) of DATUM
					   with (create CardCache
							    Substance ← NEWVALUE))
					NEWVALUE]
		   [Links (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			       (AND \Cache (fetch (CardCache Links) of \Cache)))
			  (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			       (COND
				 (\Cache (replace (CardCache Links) of \Cache with NEWVALUE))
				 (T (replace (CardObject CardCache) of DATUM
				       with (create CardCache
							Links ← NEWVALUE))
				    NEWVALUE]
		   [FromLinks (LET ((\Cache (fetch (CardObject CardCache) of DATUM))
				    \Links)
			           (AND \Cache (SETQ \Links (fetch (CardCache Links)
								   of \Cache))
					  (fetch (LinksCache FromLinks) of \Links)))
			      (LET ([\Cache (OR (fetch (CardObject CardCache) of DATUM)
						  (replace (CardObject CardCache) of DATUM
						     with (create CardCache]
				    \Links)
			           (SETQ \Links (fetch (CardCache Links) of \Cache))
			           (COND
				     (\Links (replace (LinksCache FromLinks) of \Links
						with NEWVALUE))
				     (T (replace (CardCache Links) of \Cache
					   with (create LinksCache
							    FromLinks ← NEWVALUE))
					NEWVALUE]
		   [ToLinks (LET ((\Cache (fetch (CardObject CardCache) of DATUM))
				  \Links)
			         (AND \Cache (SETQ \Links (fetch (CardCache Links)
								 of \Cache))
					(fetch (LinksCache ToLinks) of \Links)))
			    (LET ([\Cache (OR (fetch (CardObject CardCache) of DATUM)
						(replace (CardObject CardCache) of DATUM
						   with (create CardCache]
				  \Links)
			         (SETQ \Links (fetch (CardCache Links) of \Cache))
			         (COND
				   (\Links (replace (LinksCache ToLinks) of \Links with 
											 NEWVALUE))
				   (T (replace (CardCache Links) of \Cache
					 with (create LinksCache
							  ToLinks ← NEWVALUE))
				      NEWVALUE]
		   [GlobalLinks (LET ((\Cache (fetch (CardObject CardCache) of DATUM))
				      \Links)
				     (AND \Cache (SETQ \Links (fetch (CardCache Links)
								     of \Cache))
					    (fetch (LinksCache GlobalLinks) of \Links)))
				(LET ([\Cache (OR (fetch (CardObject CardCache) of DATUM)
						    (replace (CardObject CardCache) of DATUM
						       with (create CardCache]
				      \Links)
				     (SETQ \Links (fetch (CardCache Links) of \Cache))
				     (COND
				       (\Links (replace (LinksCache GlobalLinks) of \Links
						  with NEWVALUE))
				       (T (replace (CardCache Links) of \Cache
					     with (create LinksCache
							      GlobalLinks ← NEWVALUE))
					  NEWVALUE]
		   [PropList (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			          (AND \Cache (fetch (CardCache PropList) of \Cache)))
			     (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			          (COND
				    (\Cache (replace (CardCache PropList) of \Cache with 
											 NEWVALUE))
				    (T (replace (CardObject CardCache) of DATUM
					  with (create CardCache
							   PropList ← NEWVALUE))
				       NEWVALUE]
		   [Region (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			        (AND \Cache (fetch (CardCache Region) of \Cache)))
			   (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			        (COND
				  (\Cache (replace (CardCache Region) of \Cache with NEWVALUE))
				  (T (replace (CardObject CardCache) of DATUM
					with (create CardCache
							 Region ← NEWVALUE))
				     NEWVALUE]
		   [SavedRegion (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				     (AND \Cache (fetch (CardCache SavedRegion) of \Cache)))
				(LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				     (COND
				       (\Cache (replace (CardCache SavedRegion) of \Cache
						  with NEWVALUE))
				       (T (replace (CardObject CardCache) of DATUM
					     with (create CardCache
							      SavedRegion ← NEWVALUE))
					  NEWVALUE]
		   [ItemDate (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			          (AND \Cache (fetch (CardCache ItemDate) of \Cache)))
			     (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			          (COND
				    (\Cache (replace (CardCache ItemDate) of \Cache with 
											 NEWVALUE))
				    (T (replace (CardObject CardCache) of DATUM
					  with (create CardCache
							   ItemDate ← NEWVALUE))
				       NEWVALUE]
		   [LinksDate (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (AND \Cache (fetch (CardCache LinksDate) of \Cache)))
			      (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (COND
				     (\Cache (replace (CardCache LinksDate) of \Cache
						with NEWVALUE))
				     (T (replace (CardObject CardCache) of DATUM
					   with (create CardCache
							    LinksDate ← NEWVALUE))
					NEWVALUE]
		   [TitleDate (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (AND \Cache (fetch (CardCache TitleDate) of \Cache)))
			      (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
			           (COND
				     (\Cache (replace (CardCache TitleDate) of \Cache
						with NEWVALUE))
				     (T (replace (CardObject CardCache) of DATUM
					   with (create CardCache
							    TitleDate ← NEWVALUE))
					NEWVALUE]
		   [PropListDate (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				      (AND \Cache (fetch (CardCache PropListDate) of \Cache)))
				 (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				      (COND
					(\Cache (replace (CardCache PropListDate) of \Cache
						   with NEWVALUE))
					(T (replace (CardObject CardCache) of DATUM
					      with (create CardCache
							       PropListDate ← NEWVALUE))
					   NEWVALUE]
		   [LinksDirtyFlg (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				       (AND \Cache (fetch (CardCache LinksDirtyFlg) of \Cache)))
				  (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				       (COND
					 (\Cache (replace (CardCache LinksDirtyFlg) of \Cache
						    with NEWVALUE))
					 (T (replace (CardObject CardCache) of DATUM
					       with (create CardCache
								LinksDirtyFlg ← NEWVALUE))
					    NEWVALUE]
		   [PropListDirtyFlg (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				          (AND \Cache (fetch (CardCache PropListDirtyFlg)
							   of \Cache)))
				     (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				          (COND
					    (\Cache (replace (CardCache PropListDirtyFlg)
						       of \Cache with NEWVALUE))
					    (T (replace (CardObject CardCache) of DATUM
						  with (create CardCache
								   PropListDirtyFlg ← NEWVALUE))
					       NEWVALUE]
		   [SubstanceDirtyFlg (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				           (AND \Cache (fetch (CardCache SubstanceDirtyFlg)
							    of \Cache)))
				      (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				           (COND
					     (\Cache (replace (CardCache SubstanceDirtyFlg)
							of \Cache with NEWVALUE))
					     (T (replace (CardObject CardCache) of DATUM
						   with (create CardCache
								    SubstanceDirtyFlg ← NEWVALUE))
						NEWVALUE]
		   [NewCardFlg (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				    (AND \Cache (fetch (CardCache NewCardFlg) of \Cache)))
			       (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				    (COND
				      (\Cache (replace (CardCache NewCardFlg) of \Cache
						 with NEWVALUE))
				      (T (replace (CardObject CardCache) of DATUM
					    with (create CardCache
							     NewCardFlg ← NEWVALUE))
					 NEWVALUE]
		   [BeingDeletedFlg (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				         (AND \Cache (fetch (CardCache BeingDeletedFlg)
							  of \Cache)))
				    (LET ((\Cache (fetch (CardObject CardCache) of DATUM)))
				         (COND
					   (\Cache (replace (CardCache BeingDeletedFlg)
						      of \Cache with NEWVALUE))
					   (T (replace (CardObject CardCache) of DATUM
						 with (create CardCache
								  BeingDeletedFlg ← NEWVALUE))
					      NEWVALUE]

          (* * Class variables of the card object {class == card type})


		   (SuperType (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			           (NC.GetCardTypeField SuperType NoteCardType)))
		   (LinkDisplayMode (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				         (NC.GetCardTypeField LinkDisplayMode NoteCardType)))
		   (DefaultWidth (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				      (NC.GetCardTypeField DefaultWidth NoteCardType)))
		   (DefaultHeight (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				       (NC.GetCardTypeField DefaultHeight NoteCardType)))
		   (LinkAnchorModesSupported (LET ((NoteCardType (fetch (Card Type) of DATUM)))
					          (NC.GetCardTypeField LinkAnchorModesSupported 
								       NoteCardType)))
		   (LinkIconAttachedBitMap (LET ((NoteCardType (fetch (Card Type) of DATUM)))
					        (NC.GetCardTypeField LinkIconAttachedBitMap 
								     NoteCardType)))
		   (LeftButtonMenuItems (LET ((NoteCardType (fetch (Card Type) of DATUM)))
					     (NC.GetCardTypeField LeftButtonMenuItems NoteCardType)))
		   (MiddleButtonMenuItems (LET ((NoteCardType (fetch (Card Type) of DATUM)))
					       (NC.GetCardTypeField MiddleButtonMenuItems 
								    NoteCardType)))

          (* * Methods of the card object {class == card type})


		   (MakeFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			        (NC.GetCardTypeField MakeFn NoteCardType)))
		   (EditFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			        (NC.GetCardTypeField EditFn NoteCardType)))
		   (QuitFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			        (NC.GetCardTypeField QuitFn NoteCardType)))
		   (GetFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			       (NC.GetCardTypeField GetFn NoteCardType)))
		   (PutFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			       (NC.GetCardTypeField PutFn NoteCardType)))
		   (CopyFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			        (NC.GetCardTypeField CopyFn NoteCardType)))
		   (MarkDirtyFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				     (NC.GetCardTypeField MarkDirtyFn NoteCardType)))
		   (DirtyPFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
			          (NC.GetCardTypeField DirtyPFn NoteCardType)))
		   (CollectLinksFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				        (NC.GetCardTypeField CollectLinksFn NoteCardType)))
		   (DeleteLinksFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				       (NC.GetCardTypeField DeleteLinksFn NoteCardType)))
		   (UpdateLinkIconsFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				           (NC.GetCardTypeField UpdateLinkIconsFn NoteCardType)))
		   (InsertLinkFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
				      (NC.GetCardTypeField InsertLinkFn NoteCardType)))
		   (TranslateWindowPositionFn (LET ((NoteCardType (fetch (Card Type) of DATUM)))
					           (NC.GetCardTypeField TranslateWindowPositionFn 
									NoteCardType)))

          (* * Methods inherited from the cards current NoteFile device)


		   (MarkCardDeletedFn (fetch (NoteFile MarkCardDeletedFn)
					 of (fetch (Card NoteFile) of DATUM)))
		   (GetCardInfoFn (fetch (NoteFile GetCardInfoFn) of (fetch (Card NoteFile)
									    of DATUM)))
		   (PutCardPartFn (fetch (NoteFile PutCardPartFn) of (fetch (Card NoteFile)
									    of DATUM)))
		   (GetCardPartFn (fetch (NoteFile GetCardPartFn) of (fetch (Card NoteFile)
									    of DATUM)))
		   (ObtainWritePermissionFn (fetch (NoteFile ObtainWritePermissionFn)
					       of (fetch (Card NoteFile) of DATUM)))
		   (ReleaseWritePermissionFn (fetch (NoteFile ReleaseWritePermissionFn)
						of (fetch (Card NoteFile) of DATUM)))
		   (CancelCacheSubscriptionFn (fetch (NoteFile CancelCacheSubscriptionFn)
						 of (fetch (Card NoteFile) of DATUM]
		  (CREATE (create CardObject))
		  (TYPE? (TYPE? CardObject DATUM)))

(DATATYPE LinksCache (ToLinks FromLinks GlobalLinks))
]
(/DECLAREDATATYPE (QUOTE CardObject)
		  (QUOTE (POINTER POINTER POINTER POINTER FLAG FIXP FIXP FIXP FIXP FIXP POINTER FLAG 
				  POINTER FLAG POINTER POINTER))
		  (QUOTE ((CardObject 0 POINTER)
			  (CardObject 2 POINTER)
			  (CardObject 4 POINTER)
			  (CardObject 6 POINTER)
			  (CardObject 6 (FLAGBITS . 0))
			  (CardObject 8 FIXP)
			  (CardObject 10 FIXP)
			  (CardObject 12 FIXP)
			  (CardObject 14 FIXP)
			  (CardObject 16 FIXP)
			  (CardObject 18 POINTER)
			  (CardObject 18 (FLAGBITS . 0))
			  (CardObject 20 POINTER)
			  (CardObject 20 (FLAGBITS . 0))
			  (CardObject 22 POINTER)
			  (CardObject 24 POINTER)))
		  (QUOTE 26))
(/DECLAREDATATYPE (QUOTE CardCache)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER FIXP FIXP FIXP FIXP FLAG FLAG FLAG 
				  FLAG FLAG FLAG))
		  [QUOTE ((CardCache 0 POINTER)
			  (CardCache 2 POINTER)
			  (CardCache 4 POINTER)
			  (CardCache 6 POINTER)
			  (CardCache 8 POINTER)
			  (CardCache 10 FIXP)
			  (CardCache 12 FIXP)
			  (CardCache 14 FIXP)
			  (CardCache 16 FIXP)
			  (CardCache 8 (FLAGBITS . 0))
			  (CardCache 8 (FLAGBITS . 16))
			  (CardCache 8 (FLAGBITS . 32))
			  (CardCache 8 (FLAGBITS . 48))
			  (CardCache 8 (FLAGBITS . 64))
			  (CardCache 8 (FLAGBITS . 80]
		  (QUOTE 18))
(/DECLAREDATATYPE (QUOTE LinksCache)
		  (QUOTE (POINTER POINTER POINTER))
		  (QUOTE ((LinksCache 0 POINTER)
			  (LinksCache 2 POINTER)
			  (LinksCache 4 POINTER)))
		  (QUOTE 6))
(DEFINEQ

(NC.CardOrCardHolderFromUID
  (LAMBDA (CardUID NoteFileUID)                              (* kirk: "16-May-86 16:21")

          (* * Get the CardObject specified by CardUID and NoteFIleUID. This will have to be expanded a great deal when there
	  are crosslinked NFs.)



          (* * fgh 5/7/86 Added card holder notion. If NF does not exists send back a new card object holding just the given 
	  ID's)



          (* * kirk 16May86 fixed above to work if NoteFile exists but is closed)


    (LET (NoteFile)
         (if (AND (SETQ NoteFile (NC.NoteFileFromNoteFileUID NoteFileUID))
		      (NC.CardFromUID CardUID NoteFile))
	   else (create Card
			    UID ← CardUID
			    NoteFile ← NoteFileUID)))))

(NC.CardP
  (LAMBDA (Card)                                             (* rht: "15-Nov-85 16:54")

          (* * Return non-NIL if the arg is a Card object.)


    (type? Card Card)))

(NC.DeleteNoteCard
  [LAMBDA (CardIdentifier DontClearFlg NoConfirmFlg QuietFlg InterestedWindow)
                                                             (* pmi: "27-Mar-87 16:22")

          (* * User interface level fn to delete a single note card from a NoteFile)



          (* * rht 3/25/87: Added a bunch of new args. Fixed InterestedWindow stuff.)



          (* * 3/26/87: Now clears InterestedWindow when done.)



          (* * pmi 3/27/87: Changed call of NC.SeverAllLinks to NC.SeverExternalLinks.)


    (LET ((Card (NC.CoerceToCard CardIdentifier)))
         (if (NC.ValidCardP Card)
	     then (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow
			      Card)))
		    (NC.ProtectedCardOperation Card "Delete Note Card" InterestedWindow
					       (AND (if (NC.TopLevelCardP Card)
							  then (NC.PrintMsg InterestedWindow T 
								"You cannot delete this FileBox."
										(CHARACTER 13))
								 (DISMISS 1000)
								 (NC.ClearMsg InterestedWindow T)
								 NIL
							else T)
						      (NC.CheckForNotReadOnly Card InterestedWindow 
								     "Can't delete cards from a ")
						      (OR NoConfirmFlg
							    (PROG1 (NC.AskYesOrNo 
							  "Are you sure you want to delete this?"
										      " -- " "Yes"
										      (NULL 
										     DontClearFlg)
										      
										 InterestedWindow NIL 
										      NIL)
								     (NC.ClearMsg InterestedWindow 
										    T)))
						      (PROGN 

          (* * Mark UID of card about to be deleted.)


							       (NC.UIDPutProp (fetch
										  (Card UID)
										   of Card)
										(QUOTE 
									      AboutToBeDeletedFlg)
										T)

          (* * Sever all links into and out of Card)


							       (NC.SeverExternalLinks (LIST
											  Card)
											QuietFlg 
										 InterestedWindow)

          (* * Now delete the card)


							       (PROG1 (NC.DeleteNoteCardInternal
									  Card QuietFlg 
									  InterestedWindow)
									(OR QuietFlg
									      (NC.ClearMsg 
										 InterestedWindow T])

(NC.DeleteNoteCardInternal
  [LAMBDA (Card QuietFlg InterestedWindow IgnoreLinksFlg)    (* pmi: " 8-Jun-87 12:26")

          (* * Delete a single note card from a NoteFile)



          (* * rht 8/11/86 Now calls NC.DeleteReferencesToCardFromShowLinks to smash any link icons in show links menus 
	  pointing to this card.)



          (* * kef 7/28/86: Added code to obtain all of the write locks deemed necessary.)



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



          (* * kef 7/31/86: Added the nesting of the obtaining writelocks with deactivating the card.)



          (* * fgh 8/30/86 Translated APPLY* to NC.ApplyFn. Made cosmetic changes in FOR loop concewrning WriteLocks.)



          (* * rht 1/16/87: Moved call to MarkCardDeletedFn after call to NC.QuitCard.)



          (* * rg 3/11/87 renamed)



          (* * rht 3/13/87: Added QuietFlg, InterestedWindow, and IgnoreLinksFlg args. The latter non-nil causes card 
	  deletion but no link cutting.)



          (* * rht 3/25/87: Now calls NC.CoerceToInterestedWindow.)



          (* * pmi 6/8/87: Moved call to NC.GreyCard to beginning of this function.)


    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		(RESETSAVE NIL (BQUOTE (NC.SetBeingDeletedFlg , Card NIL)))
		(WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
			      (OR (OPENWP InterestedWindow)
				    (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
			      (LET ((WriteLocks (for CardPart
						   in (QUOTE (SUBSTANCE TITLE TOLINKS FROMLINKS 
									    GLOBALTOLINKS PROPLIST))
						   collect (CONS Card CardPart)))
				    ToLinks FromLinks BusyPart)
			           (NC.SetBeingDeletedFlg Card T)

          (* * First grey the card being deleted.)


			           (NC.GreyCard Card)
			           [if (NOT IgnoreLinksFlg)
				       then (SETQ ToLinks (NC.RetrieveToLinks Card))
					      (SETQ FromLinks (NC.RetrieveFromLinks Card))
					      [for ToLink in ToLinks
						 do (NCONC WriteLocks
							       (for CardPart
								  in (QUOTE (TOLINKS FROMLINKS 
										    GLOBALTOLINKS))
								  collect
								   (CONS (fetch (Link 
										  DestinationCard)
									      of ToLink)
									   CardPart]
					      (for FromLink in FromLinks
						 do (NCONC WriteLocks
							       (for CardPart
								  in (QUOTE (SUBSTANCE TOLINKS 
											FROMLINKS 
										    GLOBALTOLINKS))
								  collect
								   (CONS (fetch (Link SourceCard)
									      of FromLink)
									   CardPart]

          (* * The for... loop that follows is the condition that we can obtain all of the write locks on all of the card 
	  parts collected in WriteLocks. If we obtain a writelock, setup a RESETSAVE to release it upon exit.
	  Then finally, if we do obtain a write lock, return T so that the for loop's "always" condition is satisfied.
	  If we don't obtain a write lock for a given card part, save that one as a variable so we can report it to the user.
	  Then return NIL, so that the for loop's "always" condition is not satisfied, and we bump out of the for loop.)


			           (OR QuietFlg (NC.PrintMsg InterestedWindow T 
								 "Collecting write locks..."))
			           (COND
				     ((for WriteLock in WriteLocks bind WLCard WLCardPart
					 when (NC.ValidCardP (SETQ WLCard (CAR WriteLock)))
					 always (SETQ WLCardPart (CDR WriteLock))
						  (COND
						    ((NC.ApplyFn ObtainWritePermissionFn WLCard 
								 WLCardPart)
						      (RESETSAVE NIL
								   (BQUOTE
								     (APPLY* , (fetch
										 (Card 
									 ReleaseWritePermissionFn)
										    of WLCard)
									       , WLCard , WLCardPart))
								   )
						      T)
						    (T (SETQ BusyPart WriteLock)
						       NIL)))

          (* * Call off to the MarkCardDeletedFn specific to the NoteFile.)


				       (RESETSAVE (for CardPart
						       in (QUOTE (SUBSTANCE TOLINKS GLOBALTOLINKS 
										PROPLIST))
						       do (NC.ApplyFn ObtainWritePermissionFn Card 
									CardPart))
						    (BQUOTE (NC.DeactivateCard , Card T)))
				       (NC.ApplyFn MarkCardDeletedFn Card)
				       (NC.SetToLinks Card NIL)
				       (NC.SetFromLinks Card NIL)
				       (if (NOT IgnoreLinksFlg)
					   then (OR QuietFlg (NC.PrintMsg InterestedWindow NIL 
						      "Removing links to and from other cards..."))
						  (for ToLink in ToLinks when (NC.ValidLinkP
										      ToLink)
						     do (NC.DelFromLink ToLink)
							  (NC.DelReferencesToCardFromShowLinks
							    (fetch (Link DestinationCard)
							       of ToLink)
							    ToLink))
						  (for FromLink in FromLinks when (
										    NC.ValidLinkP
											  FromLink)
						     do (NC.DelToLink FromLink)
							  (NC.DelReferencesToCard
							    (fetch (Link SourceCard) of FromLink)
							    Card)
							  (NC.DelReferencesToCardFromShowLinks
							    (fetch (Link SourceCard) of FromLink)
							    FromLink))
						  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL 
										"..done.")))
				       (if (NC.ActiveCardP Card)
					   then (NC.TurnOffDirtyFlgs Card)
						  (NC.CloseAllPropListEditors Card)
						  (NC.QuitCard Card T T))
				       (NC.ApplyFn MarkCardDeletedFn Card)
				       (NC.SetNewCardFlg Card NIL))
				     (T (NC.CardPartBusy (CAR BusyPart)
							   (CDR BusyPart)
							   InterestedWindow])

(NC.SameCardP
  (LAMBDA (Card1 Card2)                                      (* fgh: "14-Nov-85 00:26")

          (* * are Card1 and card2 the same Card?)


    (EQ Card1 Card2)))
)
(* * Manipulate Note Card Representations)

(DEFINEQ

(NC.FetchStatus
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:52")

          (* * Return the status of the card specified by Card)


    (fetch (Card Status) of Card)))

(NC.SetNewCardFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:00")
                                                             (* Set the new card flg of ID to Value)

          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card NewCardFlg) of Card with Value)))

(NC.FetchNewCardFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:01")
                                                             (* Return the value of the new card flg of ID)

          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card NewCardFlg) of Card)))

(NC.ActivateCard
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:02")

          (* * Set the active card flg for ID)



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


    (replace (Card ActiveFlg) of Card with T)))

(NC.ActiveCardP
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 18:41")

          (* * If the active card flg is set in the cache for ID, the return ID's type. Otherwise return NIL.)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (AND Card (fetch (Card ActiveFlg) of Card)
	   (NC.FetchType Card))))

(NC.DeactivateCard
  (LAMBDA (Card DeleteTypeAndTitleFlg)                       (* fgh: "30-Aug-86 00:11")

          (* * Remove all the information from the prop list of the NoteCard ID, except for the title which usually statys 
	  cached.)



          (* * rht 7/9/85: Now also removes the new date properties.)



          (* * fgh 10/15/85 altered to use new caching mechanism)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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



          (* * kef 7/16/86: Added the release of the write permission and cancel cache subscription.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn.)


    (replace (Card ActiveFlg) of Card with NIL)
    (replace (Card CardCache) of Card with NIL)
    (for CardPart in (QUOTE (SUBSTANCE TOLINKS GLOBALTOLINKS PROPLIST))
       do (NC.ApplyFn ReleaseWritePermissionFn Card CardPart)
	    (NC.ApplyFn CancelCacheSubscriptionFn Card CardPart))
    (if DeleteTypeAndTitleFlg
	then (replace (Card Type) of Card with NIL)
	       (replace (Card Title) of Card with NIL)
	       (NC.ApplyFn CancelCacheSubscriptionFn Card (QUOTE TITLE)))))

(NC.FetchFromLinks
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:17")

          (* * Fetch ID's links from the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card FromLinks) of Card)))

(NC.FetchGlobalLinks
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:18")

          (* * Fetch IDs global links from the cache)



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


    (fetch (Card GlobalLinks) of Card)))

(NC.FetchLinksDirtyFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:18")

          (* * fetch IDs links dirty flag fom the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card LinksDirtyFlg) of Card)))

(NC.FetchPropList
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:19")

          (* * fetych IDs prop list from the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card PropList) of Card)))

(NC.FetchRegion
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:19")

          (* * fetch IDs region from the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card Region) of Card)))

(NC.FetchSavedRegion
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:20")

          (* * fetch IDs saved region from the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card SavedRegion) of Card)))

(NC.FetchRegionViewed
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:21")

          (* * For sketch cards -- fetch from the UserData prop list the region viewed property)



          (* * fgh 11/12/85 Updated to handle Card objects.)


    (LISTGET (fetch (Card UserData) of Card)
	       (QUOTE RegionViewed))))

(NC.FetchScale
  (LAMBDA (Card)                                             (* fgh: "17-Nov-85 18:10")

          (* * For sketch cards -- fetch from the UserData prop list the region viewed property)



          (* * fgh 11/12/85 Updated to handle Card objects)


    (NC.FetchUserDataProp Card (QUOTE Scale))))

(NC.FetchSlotNum
  (LAMBDA (Card)                                             (* kirk: " 9-Sep-86 08:55")

          (* * compute card's slot number in the notefile)


    (ADD1 (QUOTIENT (DIFFERENCE (fetch (Card IndexLoc) of Card)
				      (CONSTANT (fetch (NoteFileVersion NoteFileHeaderSize)
						     of (NCLocalDevice.CurrentVersion))))
			(CONSTANT (fetch (NoteFileVersion NoteFileIndexWidth) of (
								     NCLocalDevice.CurrentVersion)))
			))))

(NC.FetchSubstance
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:23")

          (* * Return the substance of card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card Substance) of Card)))

(NC.FetchTitle
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:23")

          (* * Fetch the title from IDs cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card Title) of Card)))

(NC.FetchToLinks
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:24")

          (* * fetch the to links from IDs cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



          (* * fgh 11/13/85 Updated to handl;e Card object.)


    (fetch (Card ToLinks) of Card)))

(NC.FetchType
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:24")

          (* * Fetch the note card type from IDs cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card Type) of Card)))

(NC.FetchWindow
  (LAMBDA (Card)                                             (* fgh: "15-Nov-85 23:51")

          (* * Given an ID of a card, return the open window containing that card.)



          (* * rht 9/22/85: Rewrote slightly to remove the dangerous nested WINDOWPROP calls.)



          (* * fgh 11/15/85 Updated to handle card object.)


    (if (NC.ActiveCardP Card)
	then (for Window in (OPENWINDOWS) bind UnshrunkenWin
		  do (COND
			 ((NC.SameCardP Card (NC.CoerceToCard Window))
			   (RETURN Window))
			 ((AND (WINDOWP (SETQ UnshrunkenWin (WINDOWPROP Window (QUOTE
										  ICONFOR))))
				 (NC.SameCardP Card (NC.CoerceToCard UnshrunkenWin)))
			   (RETURN UnshrunkenWin)))))))

(NC.IDP
  (LAMBDA (CardID)                                           (* kirk: "23-Dec-85 00:43")

          (* * rht 10/29/85: Totally rewritten. May get changed again soon! Stay tuned.)



          (* * fkr 11/8/85 Updated to new CardID scheme.)


    (type? UID CardID)))

(NC.MarkCardDirty
  (LAMBDA (Card ResetFlg)                                    (* fgh: " 6-Feb-86 22:03")
                                                             (* Mark card specified by ID as being DIRTY and 
							     needing to be writtent to the database)

          (* * rht 2/1/85: Now also sets/resets property on ID indicating substance dirty.)



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



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


    (NC.ApplyFn MarkDirtyFn Card ResetFlg)
    (NC.SetSubstanceDirtyFlg Card (NOT ResetFlg))))

(NC.CardDirtyP
  (LAMBDA (Card)                                             (* fgh: " 5-Feb-86 20:01")

          (* * Return T if card ID has been changed.)



          (* * rht 2/1/85: Now also checks flag on prop list.)



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



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


    (OR (NC.ApplyFn DirtyPFn Card)
	  (NC.FetchSubstanceDirtyFlg Card))))

(NC.SetFromLinks
  (LAMBDA (Card Links)                                       (* fgh: "13-Nov-85 19:25")

          (* * Cache the from links for ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card FromLinks) of Card with Links)))

(NC.SetGlobalLinks
  (LAMBDA (Card GlobalLinks)                                 (* fgh: "13-Nov-85 19:25")

          (* * Cache the global links of ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card GlobalLinks) of Card with GlobalLinks)))

(NC.SetLinksDirtyFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:30")

          (* * Set the flag indicating the links cache is dirty)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card LinksDirtyFlg) of Card with Value)))

(NC.SetPropList
  (LAMBDA (Card PropList)                                    (* fgh: "13-Nov-85 19:32")

          (* * Cache the prop list of ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card PropList) of Card with PropList)))

(NC.SetRegion
  (LAMBDA (Card Region)                                      (* fgh: "13-Nov-85 19:32")

          (* * Cache the region of ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card Region) of Card with Region)))

(NC.SetSavedRegion
  (LAMBDA (Card Region)                                      (* rht: " 5-Jul-86 17:21")

          (* * Cache the saved region of card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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



          (* * rht 7/5/86: Now makes sure region is on screen.)


    (replace (Card SavedRegion) of Card with (MAKEWITHINREGION (create REGION copying
											 Region)))))

(NC.SetRegionViewed
  (LAMBDA (Card RegionValue)                                 (* fgh: "17-Nov-85 18:10")

          (* * For sketch cards -- save the cache the region viewd on the cache UserData prop list)



          (* * fgh 11/12/85 Updated to handle CardID and CardInfo objects.)



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


    (NC.SetUserDataProp Card (QUOTE RegionViewed)
			  RegionValue)))

(NC.SetScale
  (LAMBDA (Card ScaleValue)                                  (* fgh: "18-Nov-85 00:01")

          (* * For sketch cards -- cache the scale on the cache UserData prop list)



          (* * fgh 11/12/85 Updated to handle CardID and CardInfo objects.)



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


    (NC.SetUserDataProp Card (QUOTE Scale)
			  ScaleValue)))

(NC.SetSubstance
  (LAMBDA (Card Substance)                                   (* fgh: "13-Nov-85 19:41")

          (* * Set the cached substance of card ID to be substance)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card Substance) of Card with Substance)))

(NC.SetTitle
  (LAMBDA (Card Title)                                       (* fgh: "13-Nov-85 19:43")

          (* * Cache the title for card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card Title) of Card with Title)))

(NC.SetToLinks
  (LAMBDA (Card Links)                                       (* fgh: "13-Nov-85 19:43")

          (* * Cache the to links for card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card ToLinks) of Card with Links)))

(NC.SetType
  (LAMBDA (Card NoteCardType)                                (* fgh: "13-Nov-85 19:43")

          (* * Cache the type of ID)



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


    (replace (Card Type) of Card with NoteCardType)))

(NC.FetchTitleDirtyFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:44")

          (* * fetch the cached title dirty flag)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card TitleDirtyFlg) of Card)))

(NC.SetTitleDirtyFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:44")

          (* * Set the title cahce is dirty flag)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card TitleDirtyFlg) of Card with Value)))

(NC.FetchPropListDirtyFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:44")

          (* * Fetch the prop liost list cache dirty flag)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card PropListDirtyFlg) of Card)))

(NC.SetPropListDirtyFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:45")

          (* * Set the prop list cache dirty flg)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card PropListDirtyFlg) of Card with Value)))

(NC.SetSubstanceDirtyFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:45")

          (* * Set the substance cahce dirty flg)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card SubstanceDirtyFlg) of Card with Value)))

(NC.FetchSubstanceDirtyFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:45")

          (* * fetch the substance cache dirty flag)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card SubstanceDirtyFlg) of Card)))

(NC.TurnOffDirtyFlgs
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 20:13")

          (* * Make this card look not dirty by turning off all its dirty flags.)



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


    (NC.MarkCardDirty Card (QUOTE RESET))
    (NC.SetLinksDirtyFlg Card NIL)
    (NC.SetTitleDirtyFlg Card NIL)
    (NC.SetPropListDirtyFlg Card NIL)))

(NC.FetchUserDataProp
  (LAMBDA (Card Prop)                                        (* fgh: "17-Nov-85 18:11")

          (* * Fetch a prop value from Card's UserData entry)


    (AND (fetch (Card UserData) of Card)
	   (LISTGET (fetch (Card UserData) of Card)
		      Prop))))

(NC.SetUserDataProp
  (LAMBDA (Card Prop Value)                                  (* fgh: "17-Nov-85 18:00")

          (* * Set a property on the USerData list)


    (LET ((UserDataPropList (fetch (Card UserData) of Card)))
         (COND
	   ((LISTP UserDataPropList)
	     (LISTPUT UserDataPropList Prop Value))
	   (T (replace (Card UserData) of Card with (LIST Prop Value)))))))

(NC.SetUserDataPropList
  (LAMBDA (Card PropList)                                    (* rht: "19-Dec-85 16:51")

          (* * Replace the user data prop list of Card.)


    (replace (Card UserData) of Card with PropList)))

(NC.MakeTypeIconBitMapSet
  (LAMBDA (Bitmap Heights)                                   (* rht: "10-May-86 18:44")

          (* * Create a prop list of pairs of Height and scaled copies of Bitmap having that height.)


    (LET ((OriginalHeight (BITMAPHEIGHT Bitmap)))
         (OR (for Height in Heights join (LIST Height (SCALEBITMAP Bitmap
									       (FQUOTIENT Height 
										   OriginalHeight))))
	       Bitmap))))

(NC.MakeNewCardWindow
  (LAMBDA (Card Title BorderWidth NoOpenFlg Region/Position)
                                                             (* rht: "20-Sep-86 00:06")

          (* * Creates a window for Card and Title or "Untitled." If Region/Position NIL, then use default display region for
	  Card.)


    (LET ((Window (CREATEW (NC.DetermineDisplayRegion Card Region/Position)
			     (OR Title "Untitled")
			     BorderWidth NoOpenFlg)))
         (WINDOWPROP Window (QUOTE NoteCardObject)
		       Card)
     Window)))
)
(* * Read subscriptions and write locks on card parts)

(DEFINEQ

(NC.ObtainEditPermission
  (LAMBDA (Card)                                             (* Feuerman " 4-Aug-86 15:08")

          (* * Tries to get permission to edit the Card by obtaining write permission on the SUBSTANCE, TOLINKS and 
	  GLOBALTOLINKS of the Card. If any one of these fail, those that had been obtained so far are released and NIL is 
	  returns, otherwise T.)



          (* * kef 7/22/86: Added PROPLIST to the set of card parts that need to have their write locks owned.)



          (* * kef 8/4/86: Modified so that if a window already exists for the card, the write locks aren't re-obtained, thus
	  not messing up the write lock count.)


    (PROG ((WRITEPERMISSIONFN (fetch (NoteFile ObtainWritePermissionFn)
				   of (fetch (Card NoteFile) of Card)))
	     (WRITERELEASEFN (fetch (NoteFile ReleaseWritePermissionFn) of (fetch (Card 
											 NoteFile)
										  of Card))))
	    (RETURN (OR (NC.FetchWindow Card)
			    (COND
			      ((APPLY* WRITEPERMISSIONFN Card (QUOTE SUBSTANCE))
				(COND
				  ((APPLY* WRITEPERMISSIONFN Card (QUOTE TOLINKS))
				    (COND
				      ((APPLY* WRITEPERMISSIONFN Card (QUOTE GLOBALTOLINKS))
					(COND
					  ((APPLY* WRITEPERMISSIONFN Card (QUOTE PROPLIST))
					    T)
					  (T (APPLY* WRITERELEASEFN Card (QUOTE GLOBALTOLINKS))
					     (APPLY* WRITERELEASEFN Card (QUOTE SUBSTANCE))
					     (APPLY* WRITERELEASEFN Card (QUOTE TOLINKS))
					     NIL)))
				      (T (APPLY* WRITERELEASEFN Card (QUOTE SUBSTANCE))
					 (APPLY* WRITERELEASEFN Card (QUOTE TOLINKS))
					 NIL)))
				  (T (APPLY* WRITERELEASEFN Card (QUOTE SUBSTANCE))
				     NIL)))
			      (T NIL)))))))

(NC.CardPartBusy
  (LAMBDA (Card Part InterestedWindow)                       (* Feuerman " 6-Aug-86 12:51")
    (PRIN1 (CONCAT "Card part(s) busy for card %"" (NC.FetchTitle Card)
		       "%":  " Part)
	     (OR InterestedWindow PROMPTWINDOW))))
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NC.WithWritePermission (CardForm CardPartForm &REST Body)
	  (* * Evaluate Body after obtaining WritePermission for the CardPart of a Card. Release 
	     Write permission afterwards.)
	  (* * fgh 8/30/86 First created.)
	  (BQUOTE (RESETLST [RESETSAVE (NC.ApplyFn ObtainWritePermissionFn , CardForm , CardPartForm)
				       (BQUOTE (APPLY* , (fetch (Card ReleaseWritePermissionFn)
								of , CardForm)
						       , , CardForm , (QUOTE , CardPartForm]
			    ,@ Body)))
[DEFMACRO NC.IfCardPartNotBusy (CardForm CardPartForm &REST Body)
	  (* * Do Body if can obtain write permission for CardPart of Card. Otherwise call 
	     CardPartBusy.)
	  (* * fgh 8/30/86 First created.)
	  (BQUOTE (COND ((NOT (NC.ApplyFn ObtainWritePermissionFn , CardForm , CardPartForm))
			 (NC.CardPartBusy , CardForm , CardPartForm)
			 NIL)
			(T (RESETLST (RESETSAVE NIL (BQUOTE (APPLY* , (fetch (Card 
									 ReleaseWritePermissionFn)
									     of , CardForm)
								    , , CardForm , , CardPartForm)))
				     ,@ Body]
(DEFMACRO NC.IfMultipleCardPartsNotBusy (CardForm CardPartsList &REST Body)
	  (* * Essentially call IfCardPartNotBusy for a whole bunch of CardParts)
	  (* * fgh 8/30/86 First created.)
	  (LET [(FormUnderConstruction (BQUOTE (PROGN ,@ Body]
	       [for CardPart in (REVERSE CardPartsList)
		    do
		    (SETQ FormUnderConstruction (BQUOTE (NC.IfCardPartNotBusy , CardForm
									      (QUOTE , CardPart)
									      , FormUnderConstruction]
	       FormUnderConstruction))
)
(* * Stuff to handle read-only notefiles.)

(DEFINEQ

(NC.ReadOnlyCardP
  (LAMBDA (Card)                                             (* rht: " 4-Jul-86 18:53")

          (* * Return non-nil if card's notefile is open for read only. Someday it will get smarter.)


    (NC.ReadOnlyNoteFileP (fetch (Card NoteFile) of Card))))

(NC.CardSomehowDirtyP
  (LAMBDA (Card)                                             (* rht: " 2-Jul-86 23:31")

          (* * Return non-nil if substance, title, props, or links of card is dirty.)


    (OR (NC.FetchNewCardFlg Card)
	  (NC.CardDirtyP Card)
	  (NC.FetchTitleDirtyFlg Card)
	  (NC.FetchPropListDirtyFlg Card)
	  (NC.FetchLinksDirtyFlg Card))))
)
(* * Hash Array Handler)

(DECLARE: EVAL@COMPILE 
[DEFMACRO NC.MapCards (NoteFile Function &OPTIONAL CollectResultPredicate)
	  (* * Map over the entries in a NoteFiles hash array applying function to the CardID and 
	     Hash table value for each entry.)
	  (* * rht 7/14/86: Changed from function to macro.)
	  (* * fgh 7/16/86 Fixed several bugs and reorganized macro.)
	  (COND (CollectResultPredicate (BQUOTE (LET (CollectionList)
						     [MAPHASH (fetch (NoteFile HashArray)
								     of , NoteFile)
							      (FUNCTION
								(LAMBDA
								  (Value Key)
								  (LET (PredicateResult)
								       (BLOCK)
								       (COND ((SETQ PredicateResult
										    (APPLY* , 
									   CollectResultPredicate 
											    Value))
									      (SETQ
										CollectionList
										(CONS (APPLY* , 
											 Function 
											    Value 
										  PredicateResult)
										      CollectionList))
									      )
									     (T (APPLY* , Function 
											Value]
						     CollectionList)))
		(T (BQUOTE (MAPHASH (fetch (NoteFile HashArray)
					   of , NoteFile)
				    (FUNCTION (LAMBDA (Value Key)
						      (BLOCK)
						      (APPLY* , Function Value]
)
(* * Retrieve Note Card Info)

(DEFINEQ

(NC.RetrieveFromLinks
  [LAMBDA (Card LeaveCachedFlg)                              (* rht: "29-May-87 16:27")
                                                             (* Get or Fetch the from links for the card ID)

          (* * rht 11/10/85: Updated to handle new CardID and hash array scheme.)



          (* * fgh 11/11/85: Updated to handle CardInfo objects.)



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



          (* * rht&pmi 5/29/87: Change to functionality. Default is now to not leave links cached if they weren't when we 
	  came in. If LeaveCachedFlg is non-nil, then get old functionality.)


    (LET ((LinksWereCachedFlg (NC.LinksCachedP Card)))
         (if (NOT LinksWereCachedFlg)
	     then (NC.GetLinks Card))
         (PROG1 (NC.FetchFromLinks Card)
		  (if (AND (NOT LinksWereCachedFlg)
			       (NOT LeaveCachedFlg))
		      then (NC.UncacheLinks Card])

(NC.RetrieveLinkLabels
  (LAMBDA (NoteFile SystemLinksFlg)                          (* fgh: "13-Nov-85 20:54")
                                                             (* Retrieve the list of link labels used in database 
							     specified by DatabaseStream.
							     Include system maintained links only when specified by
							     SystemLinksFlg)

          (* * fgh 11/12/85 Updated to handle NoteFile and Card objects.)


    (LET ((LinkLabelsCard (fetch (NoteFile LinkLabelsCard) of NoteFile)))
         (UNION (AND SystemLinksFlg NC.SystemLinkLabels)
		  (for Label in (OR (NC.FetchSubstance LinkLabelsCard)
					  (PROGN (NC.GetNoteCard LinkLabelsCard)
						   (NC.FetchSubstance LinkLabelsCard)))
		     when (OR SystemLinksFlg (NULL (NC.SystemLinkLabelP Label)))
		     collect Label)))))

(NC.StoreLinkLabels
  (LAMBDA (NoteFile LinkLabels)                              (* rht: " 2-Mar-86 15:22")

          (* * Store the new set of links labels for NoteFile)



          (* * rht 3/2/86: Added call to NC.GetType before call to NC.MarkCardDirty in order to get Type cached for the link 
	  labels card.)


    (LET ((LinkLabelsCard (fetch (NoteFile LinkLabelsCard) of NoteFile)))
         (NC.SetSubstance LinkLabelsCard LinkLabels)       (* Type has to be cached before NC.MarkCardDirty can 
							     be called.)
         (if (NULL (NC.FetchType LinkLabelsCard))
	     then (NC.GetType LinkLabelsCard))
         (NC.MarkCardDirty LinkLabelsCard))))

(NC.RetrievePropList
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:55")
                                                             (* Fetch or get the prop list for the note card 
							     specified by ID)

          (* * rht 11/10/85: Updated to handle new CardID and hasharray scheme.)



          (* * fgh 11/11/85: UPdated to handle Card object.)


    (OR (NC.FetchPropList Card)
	  (NC.GetPropList Card))))

(NC.RetrieveTitle
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:55")
                                                             (* If note card specified by NoteCardID is active then
							     fetch its title. Otherwise activate the card, fetch 
							     title and then deactivate the card.)

          (* * fkr 10/29/85: Rewrote to use new cache array stuff.)



          (* * rht 11/10/85: Updated to handle new CardID and hasharray scheme.)



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


    (OR (NC.FetchTitle Card)
	  (NC.GetTitle Card))))

(NC.RetrieveToLinks
  [LAMBDA (Card LeaveCachedFlg)                              (* rht: "29-May-87 16:26")
                                                             (* Get or Fetch the from links for the card ID)

          (* * rht 11/10/85: Updated to handle new CardID and hasharray scheme.)



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



          (* * rht&pmi 5/29/87: Change to functionality. Default is now to not leave links cached if they weren't when we 
	  came in. If LeaveCachedFlg is non-nil, then get old functionality.)


    (LET ((LinksWereCachedFlg (NC.LinksCachedP Card)))
         (if (NOT LinksWereCachedFlg)
	     then (NC.GetLinks Card))
         (PROG1 (NC.FetchToLinks Card)
		  (if (AND (NOT LinksWereCachedFlg)
			       (NOT LeaveCachedFlg))
		      then (NC.UncacheLinks Card])

(NC.RetrieveGlobalLinks
  [LAMBDA (Card LeaveCachedFlg)                              (* rht: "29-May-87 16:28")

          (* * Fetch or get the global links of ID)



          (* * rht 11/10/85: Updated to handle new CardID and hasharray scheme.)



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



          (* * rht&pmi 5/29/87: Change to functionality. Default is now to not leave links cached if they weren't when we 
	  came in. If LeaveCachedFlg is non-nil, then get old functionality.)


    (LET ((LinksWereCachedFlg (NC.LinksCachedP Card)))
         (if (NOT LinksWereCachedFlg)
	     then (NC.GetLinks Card))
         (PROG1 (NC.FetchGlobalLinks Card)
		  (if (AND (NOT LinksWereCachedFlg)
			       (NOT LeaveCachedFlg))
		      then (NC.UncacheLinks Card])

(NC.RetrieveType
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:57")
                                                             (* Get or Fetch NoteCardType of ID)

          (* * fkr 10/29/85: Rewrote to use new cache array stuff.)



          (* * rht 11/10/85: Updated to handle new CardID and hasharray scheme.)



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


    (OR (NC.FetchType Card)
	  (NC.GetType Card))))

(NC.RetrieveTypeAndTitle
  (LAMBDA (Card)                                             (* fgh: " 3-Sep-86 21:03")

          (* * Retrieve the type and title of a card using NC.GetCardInfo where possible to decrease Courier calls if using 
	  server.)



          (* * fgh 9/3/86 First created.)


    (LET (Type Title Info)
         (if (EQ (NC.FetchStatus Card)
		     (QUOTE ACTIVE))
	     then (if (SETQ Type (NC.FetchType Card))
			then (if (SETQ Title (NC.FetchTitle Card))
				   then NIL
				 else (NC.SetTitle Card (SETQ Title (NC.GetTitle Card))))
		      else (if (SETQ Title (NC.FetchTitle Card))
				 then (NC.SetType Card (SETQ Type (NC.GetType Card)))
			       else (SETQ Info (NC.ApplyFn GetCardInfoFn Card
							       (QUOTE (TYPE TITLE))))
				      (NC.SetTitle Card (SETQ Title (CDR (FASSOC
										 (QUOTE TITLE)
										 Info))))
				      (NC.SetType Card (SETQ Type (CDR (FASSOC (QUOTE
											 TYPE)
										       Info))))))
		    (CONS Type Title)))))

(NC.LinksCachedP
  [LAMBDA (Card)                                             (* rht: "16-May-87 00:06")

          (* * Does this card have links cahced?)



          (* * rht 5/16/87: Changed to also return non-nil if card is active and new.)


    (OR (fetch (Card Links) of Card)
	  (AND (NC.ActiveCardP Card)
		 (NC.FetchNewCardFlg Card])

(NC.ShowInfo
  [LAMBDA (Window)                                           (* Randy.Gobbel " 6-Apr-87 16:47")

          (* * Bring up an inspector on certain attribute/value pairs of this card. The default ones are card part dates and 
	  Updates.)



          (* * Need a hook so that users can provide other attribute/value pairs for given card types.)



          (* * kirk: 1May86 added NC.AttachNoteFileName)



          (* * fgh 6/13/86 Now places and sizes window with less visual nnoise.)



          (* * fgh&rht 7/4/86: Now also print card type.)



          (* * rht 7/14/86: Now includes card object if global param is set. No longer includes UID.)



          (* * rg 4/1/87 added NC.ProtectedCardOperation wrapper)



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


    (LET ((Card (NC.CoerceToCard Window))
	  [Attributes (BQUOTE (Type ItemDate TitleDate LinksDate PropsDate Updates ,@
				      (AND NC.IncludeCardObjectInShowInfo (QUOTE (CardObject]
	  Region AttributesAndValues InfoWindow)
         (NC.AttachNoteFileName Window)
         (SETQ Region (WINDOWREGION Window))
         (for Win in (ATTACHEDWINDOWS Window) when (WINDOWPROP Win (QUOTE ShowInfo))
	    do (CLOSEW Win))                             (* close any previous info window)
         [SETQ AttributesAndValues (BQUOTE (Type , (NC.FetchType Card)
						     ItemDate , (NC.FetchItemDate Card)
						     TitleDate , (NC.FetchTitleDate Card)
						     LinksDate , (NC.FetchLinksDate Card)
						     PropsDate , (NC.FetchPropListDate Card)
						     Updates , (LISTGET (NC.FetchPropList Card)
									  (QUOTE Updates))
						     ,@
						     (AND NC.IncludeCardObjectInShowInfo
							    (BQUOTE (CardObject , Card]
         (SETQ InfoWindow (INSPECTW.CREATE AttributesAndValues Attributes (FUNCTION LISTGET)
					       NIL "Can't set values of these attributes." NIL NIL 
					       "Card attributes"
					       NIL
					       (CREATEW (CREATEREGION (fetch (POSITION XCOORD)
									     of 
									     NC.OffScreenPosition)
									  (fetch (POSITION YCOORD)
									     of 
									     NC.OffScreenPosition)
									  (fetch (REGION WIDTH)
									     of Region)
									  50)
							  NIL NIL)))
         (SHAPEW InfoWindow (create REGION
				 using (WINDOWPROP InfoWindow (QUOTE REGION))
					 HEIGHT ← (HEIGHTIFWINDOW (fetch (REGION HEIGHT)
								       of (WINDOWPROP
									      InfoWindow
									      (QUOTE EXTENT)))
								    T)))
         (ATTACHWINDOW InfoWindow Window (QUOTE TOP)
			 (QUOTE JUSTIFY)
			 (QUOTE LOCALCLOSE))
         (NC.MoveWindowOntoScreen Window)
         (REDISPLAYW InfoWindow)
         (WINDOWPROP InfoWindow (QUOTE ShowInfo)
		       (QUOTE Showing))
         (WINDOWADDPROP InfoWindow (QUOTE CLOSEFN)
			  (FUNCTION FREEATTACHEDWINDOW)
			  T])
)
(* * General note card manipulations)

(DEFINEQ

(NC.AddParents
  [LAMBDA (WindowOrTextStream)                               (* Randy.Gobbel " 2-Apr-87 15:38")

          (* Add a subtopic link from a contents card specified by the user to the contents card specified by 
	  WindowOrTextStream. But first check to make sure that this would not introduce any circularities in the contents 
	  lattice.)



          (* * rht 12/8/84: Massive shaving. Now calls NC.MakeChildLink to do the tough work.)



          (* * rht 10/3/85: No longer prints final, annoying, slow-to-disappear message in prompt window if nothing 
	  selected.)



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



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)



          (* * rht 7/5/86: Now checks for readonly cards.)



          (* * rht&pmi 11/24/86: Surrounded call to NC.MakeChildLink with NC.ActivateCardAndDo so that ParentCard will be 
	  active for duration of the call.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rht 1/28/87: Took out call to NC.ActivateCardAndDo. Need to make sure ParentCard gets saved after getting link
	  if wasn't active originally.)



          (* * rg 3/3/87 Enlarged scope of NC.ProtectedCardOperation)



          (* * rg 3/18/87 added NC.CardSelectionOperation wrapper)



          (* * rg 4/2/87 changed NC.CardSelectionOperation to NCP.WithLockedCards)


    (NCP.WithLockedCards (LET (Card NewParents (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
				    )
			      (SETQ Card (NC.CoerceToCard Window))
			      (NC.ProtectedCardOperation
				Card "Designate FileBoxes" NIL
				(if (NC.CheckForNotReadOnly Card Window "Can't do filing in ")
				    then (SETQ NewParents (NC.SelectNoteCards
					       NIL
					       (FUNCTION NC.FileBoxP)
					       NC.SelectingParentsMenu Card 
					       " Please shift-select the new parent FileBox(es)."))
					   (AND NewParents Card
						  (for ParentCard in NewParents bind OneHook
						     when [LET ((WasActiveFlg (NC.ActiveCardP
										  ParentCard)))
							         (OR WasActiveFlg (NC.GetNoteCard
									 ParentCard))
							         (PROG1 (NC.MakeChildLink Card 
										       ParentCard 
											   Window)
									  (OR WasActiveFlg
										(NC.QuitCard 
										       ParentCard NIL 
											      NIL NIL 
											      NIL NIL 
											       T]
						     do (SETQ OneHook T) finally (RETURN
											 OneHook])

(NC.SeverExternalLinks
  [LAMBDA (ListOfCards QuietFlg InterestedWindow)            (* pmi: " 8-Jun-87 09:44")

          (* * Delete all links in ListOfCards to or from cards not in ListOfCards. Furthermore, do it efficiently by caching
	  an external card only long enough to delete all the links between it and ListOfCards. Note that we depend on the 
	  fact that every card in ListOfCards has its AboutToBeDeletedFlg set.)



          (* * rht&pmi 5/29/87: Now passes non-nil LeaveCachedFlg to NC.RetrieveToLinks and NC.RetrieveFromLinks.
	  Not sure if this is really necessary.)



          (* * pmi 6/8/87: Added call to NC.GreyCard to grey cards being deleted before deleting all of their links.)


    (LET (LinksToSever NumLinksToSever)
         (OR QuietFlg (NC.PrintMsg InterestedWindow T "Gathering external links of "
				       (LENGTH ListOfCards)
				       " cards."))
         [SETQ LinksToSever (NC.UnionListsOfLinks
	     (for Card in ListOfCards
		join                                       (* Grey the cards being deleted.)
		       (NC.GreyCard Card)
		       (for Link in (NC.RetrieveToLinks Card T)
			  unless (NC.UIDGetProp (fetch (Card UID) of (fetch (Link 
										  DestinationCard)
										of Link))
						    (QUOTE AboutToBeDeletedFlg))
			  collect Link))
	     (for Card in ListOfCards join (for Link in (NC.RetrieveFromLinks Card T)
						    unless (NC.UIDGetProp
							       (fetch (Card UID)
								  of (fetch (Link SourceCard)
									  of Link))
							       (QUOTE AboutToBeDeletedFlg))
						    collect Link]

          (* * Now sort links so that links with same external anchor card are grouped together. Furthermore, the links 
	  having that anchor card has source card are grouped before the ones having that card as destination card.)


         (OR QuietFlg (NC.PrintMsg InterestedWindow T "Sorting " (SETQ NumLinksToSever
					 (LENGTH LinksToSever))
				       " links prior to severing."))
         [SORT LinksToSever (FUNCTION (LAMBDA (Link1 Link2)
		     (LET (DestCard1 DestCard2 ExtCard1 ExtCard2 Link1SourceIsExtFlg)
		          (SETQ ExtCard1 (if (NC.UIDGetProp (fetch (Card UID)
								     of (SETQ DestCard1
									    (fetch (Link 
										  DestinationCard)
									       of Link1)))
								  (QUOTE AboutToBeDeletedFlg))
					       then (SETQ Link1SourceIsExtFlg T)
						      (fetch (Link SourceCard) of Link1)
					     else DestCard1))
		          (SETQ ExtCard2 (if (NC.UIDGetProp (fetch (Card UID)
								     of (SETQ DestCard2
									    (fetch (Link 
										  DestinationCard)
									       of Link2)))
								  (QUOTE AboutToBeDeletedFlg))
					       then (fetch (Link SourceCard) of Link2)
					     else DestCard2))
		          (if (NC.SameCardP ExtCard1 ExtCard2)
			      then Link1SourceIsExtFlg
			    else (LESSP (fetch (Card IndexLoc) of ExtCard1)
					    (fetch (Card IndexLoc) of ExtCard2]

          (* * Now walk down the list of links one by one activating the external anchor cards as needed.)


         (OR QuietFlg (NC.PrintMsg InterestedWindow T "Severing links: 1 out of " NumLinksToSever 
				       " ..."))
         (for Link in LinksToSever as i from 1 bind PreviousExtCard WasNotActiveFlg 
							      PreviousExtCardIsSourceFlg
	    eachtime (BLOCK) when (NC.ValidLinkP Link)
	    do (OR QuietFlg (if (ZEROP (REMAINDER i 10))
				    then (NC.PrintMsg InterestedWindow T "Severing links: " i 
							  " out of "
							  NumLinksToSever " ...")))
		 (LET (ExtCard ExtCardIsSourceFlg)
		      (SETQ ExtCard (if (NC.UIDGetProp (fetch (Card UID)
								of (fetch (Link DestinationCard)
									of Link))
							     (QUOTE AboutToBeDeletedFlg))
					  then (SETQ ExtCardIsSourceFlg T)
						 (fetch (Link SourceCard) of Link)
					else (fetch (Link DestinationCard) of Link)))
		      [if (NOT (NC.SameCardP ExtCard PreviousExtCard))
			  then                             (* Write down changes to previous external card's 
							     substance.)
				 (if WasNotActiveFlg
				     then (if PreviousExtCardIsSourceFlg
						then       (* Have to call NC.CardSaveFn first and then 
							     NC.QuitCard with Don'tSaveFlg to avoid 
							     insureProperFiling check.)
						       (NC.CardSaveFn PreviousExtCard T)
						       (NC.QuitCard PreviousExtCard NIL T NIL NIL 
								      NIL T)
					      else (NC.PutLinks PreviousExtCard)))
                                                             (* If ExtCard not active, then cache.)
				 (if (SETQ WasNotActiveFlg (NOT (NC.ActiveCardP ExtCard)))
				     then (if ExtCardIsSourceFlg
						then       (* Cache whole card if it's the link's source.)
						       (NC.GetNoteCard ExtCard)
					      else         (* Else only need the links since we're deleting the 
							     from link.)
						     (NC.GetLinks ExtCard]
                                                             (* Delete the appropriate half of the link.)
		      (if ExtCardIsSourceFlg
			  then (NC.DeleteToLink Link)
			else (NC.DeleteFromLink Link))
		      (replace (Link UID) of Link with -1)
		      (SETQ PreviousExtCard ExtCard)
		      (SETQ PreviousExtCardIsSourceFlg ExtCardIsSourceFlg))
	    finally (if (AND WasNotActiveFlg (NC.ValidCardP PreviousExtCard))
			  then (if PreviousExtCardIsSourceFlg
				     then                  (* Have to call NC.CardSaveFn first and then 
							     NC.QuitCard with Don'tSaveFlg to avoid 
							     insureProperFiling check.)
					    (NC.CardSaveFn PreviousExtCard T)
					    (NC.QuitCard PreviousExtCard NIL T NIL NIL NIL T)
				   else (NC.PutLinks PreviousExtCard])

(NC.AssignTitle
  [LAMBDA (CardIdentifier NoClearMsgFlg NewTitle InterestedWindow)
                                                             (* rht: "25-Mar-87 11:25")

          (* * Change the title of the card specified by the WindowOrTextStreamOrID)



          (* * rht 2/1/85: Changed from NC.PutTitle to NC.SetTitleDirtyFlg, unless card is not active.
	  We shouldn't be writing to the notefile until save time.)



          (* * fgh 11/11/85: Added support for CardID, CardInfo and noteFile objects. Also entered call to Nc.StoreTitle.)



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)



          (* * fgh 6/13/86 Now spawns mouse in case called under MOUSE process.)



          (* * fgh 6/27/86 returns T if completed okay.)



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



          (* * kef 7/16/86: Added obtain write permission.)



          (* * kef 7/24/86: Doesn't release the write lock if this is a new card.)



          (* * 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 Converted to use NC.IfCardPartNotBusy.)



          (* * rg 3/3/87 Enlarged scope of NC.ProtectedCardOperation)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * rht 3/24/87: Now calls NC.CoerceToInterestedWindow)


    (ALLOW.BUTTON.EVENTS)
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  ContainingCard OldTitle Window)
         (NC.ProtectedCardOperation Card "Assign Title" NIL
				    (NC.IfCardPartNotBusy
				      Card
				      (QUOTE TITLE)
				      (OR InterestedWindow (SETQ InterestedWindow (
						NC.CoerceToInterestedWindow Card)))
				      (if (NC.CheckForNotReadOnly Card InterestedWindow 
							      "Can't change titles for cards in ")
					  then (COND
						   ((SETQ NewTitle
						       (OR (STRINGP NewTitle)
							     (AND NewTitle (OR (LITATOM 
											 NewTitle)
										   (NUMBERP 
											 NewTitle))
								    (MKSTRING NewTitle))
							     (NC.AskUser
							       (CONCAT 
								  "Enter the title for this card"
									 (CHARACTER 13))
							       "-->  "
							       (COND
								 ((AND (STREQUAL (SETQ OldTitle
										       (
										 NC.RetrieveTitle
											 Card))
										     "Untitled")
									 (NC.FetchNewCardFlg Card))
								   NIL)
								 (T OldTitle))
							       (NULL NoClearMsgFlg)
							       InterestedWindow)))
						     (NC.SetTitle Card NewTitle)

          (* * Now do a PutTitle so that anyone else coming along will pick up on the new title. The only exception is if 
	  this card hasn't been written to the NoteFile yet, which is true when the NewCardFlg is T. In that case, we can't 
	  put the title down yet, so just mark it dirty.)


						     (COND
						       ((fetch (Card NewCardFlg) of Card)
							 (NC.SetTitleDirtyFlg Card T))
						       (T (NC.PutTitle Card)
							  (NC.SetTitleDirtyFlg Card NIL)))
						     (AND (WINDOWP (SETQ Window (
									   NC.FetchWindow Card)))
							    (WINDOWPROP Window (QUOTE TITLE)
									  NewTitle))
						     (for FromLink in (NC.RetrieveFromLinks
									    Card)
							do (AND (NC.ActiveCardP
								      (SETQ ContainingCard
									(fetch (Link SourceCard)
									   of FromLink)))
								    (WINDOWP (NC.FetchWindow
										 ContainingCard))
								    (NC.UpdateLinkImages 
										   ContainingCard 
											   Card)))
						     T))
					else NIL])

(NC.DeleteNoteCards
  [LAMBDA (CardIdentifiers NoIndividualConfirmFlg DontClearFlg InterestedWindow QuietFlg 
			   NoGroupConfirmFlg)                (* Randy.Gobbel " 2-Apr-87 16:05")
                                                             (* Delete note cards. If no card specified then get a 
							     list of note cards to be deleted.
							     Then delete these cards.)

          (* * fgh 11/11/85: Updated to handle new Card objects. Also split off main work of deleteing a single note card 
	  into NC.DeleteNoteCard function.)



          (* * kirk 21Feb86 Added InterestedWindow)



          (* * kirk 29Apr86 Now returns CardIdentifiers)



          (* * fgh 6/9/86 Added checks to see if other operations are in progress)



          (* * rht 7/4/86: Now checks that card is not read-only.)



          (* * kirk 18Aug86 Added main window for windowless cards.)



          (* * rht 8/29/86: Reorganized and added call to NC.SeverAllLinks to make deleting more efficient.
	  Added QuietFlg, NoGroupConfirmFlg and Don'tPutToBeDeletedCardsFlg args.)



          (* * rht 9/5/86: Now forces NoGroupConfirmFlg to be non-nil if NoIndividualConfirmFlg is NIL and only one card to 
	  delete.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rht 12/16/86: Removed obsolete Don'tPutToBeDeletedCardsFlg arg.)



          (* * rht 3/9/87: Changed NC.DeleteSelectingMenu to NC.SelectingCardsMenu.)



          (* * rg 3/9/87 added NC.ProtectedSessionOperation wrapper)



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



          (* * rg 3/18/87 changed NC.ProtectedSessionOperation to NC.CardSelectionOperation)



          (* * rht 3/30/87: Now calls NC.SeverExternalLinks rather than NC.SeverAllLinks.)



          (* * rg 3/31/87 now protects cards passed in in list)


    (DECLARE (GLOBALVARS NC.SelectingCardsMenu))
    (NCP.WithLockedCards
      (NC.IfAllCardsFree (NC.LockListOfCards (MKLIST CardIdentifiers)
					       "Delete Note Cards")
			 (OR CardIdentifiers (SETQ CardIdentifiers
				 (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu InterestedWindow 
					      "Please shift-select the Note Cards to be deleted.")))

          (* * Kludge in case args are nil, say, when we're called from a card's menu.)


			 (if (AND (NULL NoIndividualConfirmFlg)
				      (NULL NoGroupConfirmFlg)
				      (EQ (LENGTH (MKLIST CardIdentifiers))
					    1))
			     then (SETQ NoGroupConfirmFlg T)
				    (SETQ QuietFlg T))

          (* * First collect cards that are deletable.)


			 (LET ((CardsToDelete (for CardIdentifier in (MKLIST CardIdentifiers)
						 bind Card eachtime (BLOCK)
						 when
						  [AND (SETQ Card (NC.CoerceToCard 
										   CardIdentifier))
							 (if (NOT (NC.TopLevelCardP Card))
							   else (NC.PrintMsg (NC.FetchWindow
										   Card)
										 T 
								"You cannot delete this FileBox."
										 (CHARACTER 13))
								  (DISMISS 1000)
								  (NC.ClearMsg (NC.FetchWindow
										   Card)
										 T)
								  NIL)
							 (NC.CheckForNotReadOnly Card (
										   NC.FetchWindow
										     Card)
										   
								     "Can't delete cards from a ")
							 (OR NoIndividualConfirmFlg
							       (PROG1 (NC.AskYesOrNo
									  
							  "Are you sure you want to delete this?"
									  " -- " "Yes" (NULL 
										     DontClearFlg)
									  (OR (NC.FetchWindow
										  Card)
										InterestedWindow)
									  NIL NIL)
									(NC.ClearMsg]
						 collect Card))
			       (NumSpecified (LENGTH (MKLIST CardIdentifiers)))
			       NumToDelete)
			      (SETQ NumToDelete (LENGTH CardsToDelete))
			      (if [AND (GREATERP NumToDelete 0)
					   (if (EQUAL NumToDelete NumSpecified)
					       then (OR NoGroupConfirmFlg
							    (PROG1 (NC.AskYesOrNo
								       (CONCAT "You've specified " 
										 NumToDelete 
									      " cards to delete."
										 (CHARACTER 13)
										 
							 "Are you sure you want to delete them? ")
								       NIL "Yes" (NULL DontClearFlg)
								       InterestedWindow)
								     (NC.ClearMsg)))
					     else (PROG1 (NC.AskYesOrNo (CONCAT "Out of " 
										     NumSpecified 
									     " cards specified, "
											(DIFFERENCE
											  
										     NumSpecified 
										      NumToDelete)
											
									    " are not deletable."
											(CHARACTER
											  13)
											
								  "Want to delete the remaining "
											NumToDelete 
										       " cards? ")
									      NIL "Yes" (NULL
										DontClearFlg)
									      InterestedWindow)
							     (NC.ClearMsg]
				  then 

          (* * Mark UIDs of cards about to be deleted.)


					 (for Card in CardsToDelete
					    do (NC.UIDPutProp (fetch (Card UID) of Card)
								  (QUOTE AboutToBeDeletedFlg)
								  T))

          (* * Sever all links into and out of CardsToDelete)


					 (NC.SeverExternalLinks CardsToDelete QuietFlg 
								  InterestedWindow)

          (* * Now delete the cards one at a time.)


					 (OR QuietFlg (NC.PrintMsg InterestedWindow T 
								      "Deleting cards: 1 out of "
								       NumToDelete " ..."))
					 (for Card in CardsToDelete as i from 1
					    eachtime (BLOCK)
					    do (OR QuietFlg
						       (if (ZEROP (REMAINDER i 10))
							   then (NC.PrintMsg InterestedWindow T 
									       "Deleting cards: "
										 i " out of " 
										 NumToDelete " ...")))
						 (NC.DeleteNoteCardInternal Card QuietFlg 
									      InterestedWindow T))
					 (OR QuietFlg (NC.ClearMsg InterestedWindow T))
					 CardIdentifiers])

(NC.EditNoteCard
  [LAMBDA (Card RegionOrPosition TypeSpecificArgs)           (* rht: "13-May-87 11:04")

          (* * Bring the already created NoteCard specified by ID onto the screen at Region or Position specified by 
	  RegionOrPosition)



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



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



          (* * kirk 15May86 Added call to NC.AttachNoteFileName)



          (* * rht 7/13/86: Added TypeSpecificArgs arg.)



          (* * kef 7/16/86: Added NC.ObtainCardEditPermission.)



          (* * kef 8/7/86: Added check to make sure that applying the EditFn worked. If not, then release those write locks, 
	  thus keeping the writelock count consistent.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn.)



          (* * rht 10/6/86: Added checks before doing WINDOWPROP calls in case there was a recursive call to 
	  NC.EditNoteCard.)



          (* * rg 3/30/87 added NC.ProtectedCardOperation wrapper)



          (* * rht 5/13/87: Added call to new NC.InstallCopyButtonEventFn.)


    (DECLARE (GLOBALVARS NC.ShowNoteFileOnCards))
    (NC.ProtectedCardOperation Card "Edit NoteCard" NIL (RESETSAVE (CURSOR WAITINGCURSOR))
			       (PROG (NoteCardType Window Substance EditResult)
				       [COND
					 ((AND (NC.ActiveCardP Card)
						 (NC.ObtainEditPermission Card))
					   (SETQ Substance (NC.FetchSubstance Card)))
					 ((NC.ObtainEditPermission Card)
					   (NC.GetNoteCard Card)
					   (SETQ Substance (NC.FetchSubstance Card)))
					 (T (RETURN (NC.CardPartBusy Card
									 (QUOTE (SUBSTANCE TOLINKS 
										    GLOBALTOLINKS 
											 PROPLIST]
				       (SETQ NoteCardType (NC.RetrieveType Card))
				       (COND
					 ([AND (SETQ EditResult
						   (ERSETQ (NC.ApplyFn EditFn Card Substance 
									 RegionOrPosition 
									 TypeSpecificArgs)))
						 (WINDOWP (SETQ Window (CAR EditResult]
					   (WINDOWADDPROP Window (QUOTE CLOSEFN)
							    (FUNCTION NC.QuitCard)
							    (QUOTE FIRST))
					   (OR (NC.CardP (WINDOWPROP Window (QUOTE 
										   NoteCardObject)))
						 (WINDOWPROP Window (QUOTE NoteCardObject)
							       Card))
					   (NC.InstallCopyButtonEventFn Window)
					   (if NC.ShowNoteFileOnCards
					       then (NC.AttachNoteFileName Window)))
					 (T                  (* At this point, we've obtain the write locks but the
							     edit failed, so we'd better release them)
					    (for CardPart in (QUOTE (SUBSTANCE TOLINKS 
										    GLOBALTOLINKS 
										     PROPLIST))
					       do (NC.ApplyFn ReleaseWritePermissionFn Card 
								CardPart))
					    (RETURN)))
				       (RETURN Window])

(NC.MakeNoteCard
  (LAMBDA (NoteCardType NoteFile Title NoDisplayFlg TypeSpecificArgs Card)
                                                             (* Feuerman " 4-Aug-86 14:11")
                                                             (* Make a new note card of type NoteCardType.
							     If type note specified, ask the user.)

          (* * rht 2/1/85: Added call to NC.MarkCardDirty.)



          (* * fgh 10/15/85 Added extra DatabaseStream argument for use by caching mechanism)



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



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



          (* * kirk 15May86 Added call to NC.AttachNoteFileName)



          (* * rht 7/4/86: Now checks for read-only notefile before proceeding.)



          (* * kef 8/4/86: Updated to pass NoteCardType argument on to NC.GetNewCard.)


    (if (NC.ReadOnlyNoteFileP NoteFile)
	then NIL
      else (LET (ReturnValue Window)
	          (COND
		    ((SETQ NoteCardType (OR NoteCardType (NC.AskNoteCardType
						  (fetch (NoteFile Menu) of NoteFile))))
		      (SETQ Card (OR (PROGN (type? Card Card)
						  Card)
					 (NC.GetNewCard NoteFile NoteCardType)))
		      (NC.SetNewCardFlg Card T)
		      (NC.ActivateCard Card)
		      (NC.SetType Card NoteCardType)
		      (COND
			((OR (NULL (ERSETQ (SETQ ReturnValue (NC.ApplyFn MakeFn Card Title 
										 NoDisplayFlg 
										 TypeSpecificArgs))))
			       (NULL ReturnValue))
			  (NC.SetStatus Card (QUOTE DELETED))
			  (NC.DeactivateCard Card T))
			(T (SETQ Window (WINDOWP ReturnValue))
			   (COND
			     ((NULL (NC.RetrieveTitle Card))
			       (SETQ Title (NC.SetTitle Card (SETQ Title
							      (COND
								((STRINGP Title)
								  Title)
								((AND Title (OR (LITATOM Title)
										    (NUMBERP Title))
									)
								  (MKSTRING Title))
								(T "Untitled")))))
			       (AND Window (WINDOWPROP Window (QUOTE TITLE)
							   Title)))
			     (T (NC.SetTitle Card (MKSTRING (NC.RetrieveTitle Card)))))
			   (COND
			     (Window (WINDOWADDPROP Window (QUOTE CLOSEFN)
						      (FUNCTION NC.QuitCard)
						      (QUOTE FIRST))
				     (WINDOWPROP Window (QUOTE NoteCardObject)
						   Card)
				     (WINDOWPROP Window (QUOTE OldCopyButtonEventFn)
						   (WINDOWPROP Window (QUOTE COPYBUTTONEVENTFN)
								 (FUNCTION NC.CopyButtonEventFn)))))
			   (NC.SetTitleDirtyFlg Card T)    (* Reset the type in case of recursive calls change 
							     the type. Always want the highest level type in a 
							     recursive descent)
			   (NC.SetType Card NoteCardType)
                                                             (* Insure that a link ptr is set up during the first 
							     save)
			   (NC.SetLinksDirtyFlg Card T)
			   (NC.SetPropListDirtyFlg Card T)
                                                             (* Mark that substance is dirty.)
			   (NC.MarkCardDirty Card T)
			   (if NC.ShowNoteFileOnCards
			       then (NC.AttachNoteFileName Window))))
		      ReturnValue))))))

(NC.QuitCard
  [LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg InterestedWindow OperationMsg 
			  QuietFlg Don'tDeactivateFlg)       (* rht: "24-Apr-87 16:17")

          (* * Force note card specified by ID to quit or stop)



          (* * rht 2/9/85: New arg DontSaveFlg prevents NC.CardSaveFn from being called. Used when aborting a card.
	  This is NOT equivalent to NC.QuitWithoutSaving.)



          (* * rht 6/25/85: Now moves card off screen before saving if NC.CloseCardsOffScreenFlg is non-nil.)



          (* * rht 6/25/85: Brought the insure proper filing check back here from NC.CardSaveFn. Bails out if user cancelled 
	  operation inside of NC.InsureProperFiling)



          (* * fgh 11/11/85: Updated to handle CardID and CardInfo objects.)



          (* * fgh 1/16/86 Put in code to insure that if one of the TopLevelCards is quit then it is reactivated immedialtely
	  to make sure it stays cached for fast access.)



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



          (* * fgh 5/2/86 Added DontRecacheFlg arg)



          (* * fgh 6/9/86 Added code to check to make sure other operations are not in progress. And DontCheckOpInProgressFlg
	  arg to match)



          (* * fgh 6/26/86 Added InterestedWindow & OperationMsg arg.)



          (* * rht 7/2/86: Now bails out if notefile is readonly, user confirms, but we're supposed to write down changes.)



          (* * rht 7/13/86: Now takes QuietFlg arg.)



          (* * rht 7/14/86: Call NC.DeactivateCard from here instead of in card type QuitFn. Take a Don'tDeactivateFlg as 
	  well.)



          (* * rht 10/7/86: Now removes DELETEME imageobj's from card substance.)



          (* * rht 11/2/86: Now returns DON'T if operation in progress.)



          (* * rht 11/13/86: Now closes open proplist editor if any before saving.)



          (* * rg 3/4/87 rewritten to use new NC.ProtectedCardOperation, removed DontCheckOpInProgressFlg arg)



          (* * rht 3/24/87: Now calls NC.CoerceToInterestedWindow and passes InterestedWindow to NC.InsureProperFiling.)



          (* * rht 4/24/87: Fixed a vmem leak: when CallCloseWFlg is nil it doesn't clear CardObject windowprop.)


    (DECLARE (GLOBALVARS NC.RemoveDELETEMEImageObjsFromCardFlg))
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  Window ReadOnlyCardFlg)
         (NC.ProtectedCardOperation
	   Card "Close Card" InterestedWindow
	   (PROG NIL
	           (SETQ ReadOnlyCardFlg (NC.ReadOnlyCardP Card))
                                                             (* The window not being open should mean that it's 
							     shrunken. If so, expand it.)
	           (SETQ Window (NC.FetchWindow Card))
	           (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow
			     Card)))
	           (COND
		     ((AND Window (NOT (OPENWP Window)))
		       (EXPANDW Window)))

          (* * if proper filing says don't quit then get out)


	           [OR DontSaveFlg ReadOnlyCardFlg (COND
			   ((EQ (NC.InsureProperFiling Card InterestedWindow)
				  (QUOTE DON'T))
			     (RETURN (QUOTE DON'T]

          (* * If card is readonly but we've made changes that we're supposed to save, then get user confirmation and bail 
	  out.)


	           (if [AND (NOT DontSaveFlg)
				(NOT Don'tDeactivateFlg)
				ReadOnlyCardFlg
				(NC.CardSomehowDirtyP Card)
				(NULL QuietFlg)
				(NOT (PROGN (NC.PrintMsg InterestedWindow T 
					       "Card has been changed, but notefile is readonly."
							       (CHARACTER 13))
						(NC.AskYesOrNo 
							"Want to quit anyway, flushing changes? "
								 NIL
								 (QUOTE Yes)
								 NIL InterestedWindow]
		       then (RETURN (QUOTE DON'T)))

          (* * Otherwise go ahead and quit)


	           (RETURN (PROGN                        (* Close open proplist editor if any.)
				      [AND Window (LET ((PropListEditorWindow (
									   NC.PropListEditorOpenP
										  Window)))
						         (AND PropListEditorWindow (CLOSEW 
									     PropListEditorWindow]
				      (COND
					((AND Window NC.CloseCardsOffScreenFlg)
					  [COND
					    ((NOT (NC.FetchSavedRegion Card))
					      (NC.SetSavedRegion Card (WINDOWPROP Window
										      (QUOTE REGION]
					  (MOVEW Window 1500 1500)))
				      (OR DontSaveFlg (if ReadOnlyCardFlg
							    then (NC.TurnOffDirtyFlgs Card)
							  else
							   (AND 
							    NC.RemoveDELETEMEImageObjsFromCardFlg
								  (
							       NC.RemoveDELETEMEImageObjsFromCard
								    Card
								    (FUNCTION NC.DELETEMEImageObjP))
								  )
							   (NC.CardSaveFn Card (OR 
									NC.CloseCardsOffScreenFlg 
										       QuietFlg)
									    InterestedWindow 
									    OperationMsg)))
				      (AND Window (WINDOWDELPROP Window (QUOTE CLOSEFN)
								     (FUNCTION NC.QuitCard)))
				      (PROG1 (NC.ApplyFn QuitFn Card)
					       (AND Window (WINDOWPROP Window (QUOTE 
										   NoteCardObject)
									   NIL))
					       (AND CallCloseWFlg Window (CLOSEW Window))
					       (OR Don'tDeactivateFlg (NC.DeactivateCard Card))

          (* * if this is one of the top level cards, then make sure it stays cached)


					       (if (AND (NC.TopLevelCardP Card)
							    (NULL DontRecacheFlg)
							    (NULL Don'tDeactivateFlg))
						   then (NCP.ActivateCards Card])

(NC.CheckFiling
  [LAMBDA (Card InterestedWindow)                            (* rht: "26-Mar-87 19:43")
                                                             (* Check to make sure this card has a contents hook of
							     some sort. If not, hook it up to a contents card.)

          (* * rht 12/8/84: Now checks whether both cards *and* fileboxes have been filed.)



          (* * rht 12/9/84: Now files in orphan filebox if NC.ForceFiling flag is off, without bothering the user.)



          (* * rht 2/9/85: Added call to NC.CardNeedsFilingP)



          (* * fgh 11/12/85 Updated to handle Card and NoteFile objects.)



          (* * fgh 6/9/86 Updated to set operation in progress indicator.)



          (* * rg 1/28/87 Make sure we always return a useful value)



          (* * rg 3/4/87 rewritten for new version of NC.ProtectedCardOperation)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * Rht 3/24/87: Now calls NC.CoerceToInterestedWindow)



          (* * rht 3/26/87: Changed msg slightly.)


    (NC.ProtectedCardOperation Card "Filing" NIL (COND
				 [(NC.CardNeedsFilingP Card)
				   (OR InterestedWindow (SETQ InterestedWindow (
					     NC.CoerceToInterestedWindow Card)))
				   (COND
				     (NC.ForceFilingFlg (NC.MakeFilingLinks Card
									      (CONCAT "This card ("
											(
										 NC.RetrieveTitle
											  Card)
											
					") is not currently filed in a FileBox in this notefile."
											(CHARACTER
											  13))
									      InterestedWindow))
				     (T (NC.PrintMsg InterestedWindow T "This card (" (
							 NC.RetrieveTitle Card)
						       ") is not currently filed in a FileBox."
						       (CHARACTER 13)
						       "It is being filed in the ToBeFiled FileBox."
						       (CHARACTER 13))
					(NC.HookToOrphanCard Card (fetch (NoteFile ToBeFiledCard)
								       of (fetch (Card NoteFile)
									       of Card]
				 (T T])

(NC.CheckTitle
  [LAMBDA (Card InterestedWindow)                            (* rht: "28-Apr-87 11:43")
                                                             (* If card specified by ID has no title, ask the user 
							     for a title.)

          (* * rht 11/19/84: Now checks NC.ForceTitlesFlg before griping.)



          (* * rht 12/6/84: Now sends ID rather than Window to NC.AssignTitle.)



          (* * fgh 11/11/85: Updated to handle new Card objects.)



          (* * rg 2/3/87 Now returns T if card already titled)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * rg 4/22/87 now returns T even if card remains untitled ; we need a CANCEL button!)



          (* * rht 4/28/87: Now only calls NC.AssignTitle if current title is NIL, i.e. this is a new card.)


    (DECLARE (GLOBALVARS NC.ForceTitlesFlg))
    (OR InterestedWindow (SETQ InterestedWindow (NC.FetchWindow Card)))
    (LET (Title)
         (COND
	   ([AND NC.ForceTitlesFlg (OR (NULL (SETQ Title (NC.RetrieveTitle Card)))
					   (AND (NC.FetchNewCardFlg Card)
						  (STREQUAL Title "Untitled"]
	     (NC.PrintMsg InterestedWindow T "This note card has no title." (CHARACTER 13))
	     (NC.AssignTitle Card T NIL InterestedWindow))
	   ((AND (NULL NC.ForceTitlesFlg)
		   (NULL (NC.RetrieveTitle Card)))
	     (NC.AssignTitle Card NIL "Untitled" InterestedWindow)))
     T])

(NC.ForceFilingForCardTypeP
  [LAMBDA (CardType)                                         (* rht: " 6-Oct-86 10:58")

          (* * Does this card type have to be filed somewhere? For now checks property, should eventually be a slot in the 
	  card type def'n.)


    (NULL (GETPROP CardType (QUOTE Don'tForceFilingFlg])

(NC.InsureProperFiling
  [LAMBDA (Card InterestedWindow)                            (* Randy.Gobbel " 1-Apr-87 17:33")
                                                             (* Called when any type of note card is being quitted 
							     from, i.e., closed)

          (* * rht 12/9/84: Moved check of the NC.ForceFiling flag into NC.CheckContentsHooks.)



          (* * fgh 11/12/85 Updated to handle Card and NoteFile objects.)



          (* * fgh 6/27/86 Changed format to allow being killed by ERROR!)



          (* * rg 1/28/87 Now returns CANCELLED if any of the component tests fail)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * rg 4/1/87 now returns DON'T if component tests fail)


    (OR (AND (NULL (NC.FetchBeingDeletedFlg Card))
		 (NC.CheckTitle Card InterestedWindow)
		 (NC.CheckFiling Card InterestedWindow))
	  (QUOTE DON'T])

(NC.QuitWithoutSaving
  [LAMBDA (CardIdentifier)                                   (* Randy.Gobbel "16-Mar-87 18:25")

          (* Quit from a note card without saving its contents on the database. But must make sure that any updates that 
	  would have been done to this card even if it had been on the database are carried out on the old image currently on
	  the database)



          (* * rht 2/1/85: Now only writes out links if it has to. Also resets dirty flags and calls normal quit procedure.
	  I think we've still got possible problems with recently changed titles, both ours and those of cards we point to.)



          (* * rht 2/3/85: Now handles title changes properly. Also fixed so that changes to from links will force links to 
	  be written.)



          (* * rht 2/9/85: Now accepts IDs as arg.)



          (* * fgh 11/12/85: Updated to handle Card objects. Removed DatabaseStream argument.)



          (* * fgh 6/4/86 No longer asks for confirmation if no changes have been made.)



          (* * kef 8/7/86: Now compares ToLinks by NC.SameUIDP rather than EQ. Situation comes up in Server, when the same 
	  UIDs may not be EQ. Also, now obtains write lock on FROMLINKS before deleting FROMLINKS on the DestinationCard of a
	  changed FROMLINK.)



          (* * fgh 8/30/86 Converted to use NC.WithWrotePermission macro.)



          (* * rht 10/16/86: Changed NC.ProtectedCardOperation wrapper placement so that card deletion could still happen for
	  new cards.)



          (* * rg 3/3/87 Rewrote NC.ProtectedCardOperation wrapping)



          (* * rg 3/16/87 Now uses NC.DeleteNoteCard instead of NC.DeleteNoteCards)


    (LET (Window Card NewFromLinks ToLinks DeletedLinks Process TextObj MadeNewLinksP 
		 ChangedFromLinksP OldFromLinks OldToLinks)
         (SETQ Card (NC.CoerceToCard CardIdentifier))
         (NC.ProtectedCardOperation Card "Close w/o Saving" NIL (SETQ Window (NC.FetchWindow
					Card))
				    (SETQ ToLinks (NC.FetchToLinks Card))
				    (SETQ NewFromLinks (NC.FetchFromLinks Card))
				    (if (OR (NULL (OR (NC.CardDirtyP Card)
							      (NC.FetchLinksDirtyFlg Card)
							      (NC.FetchTitleDirtyFlg Card)
							      (NC.FetchPropListDirtyFlg Card)))
						(NC.AskYesOrNo 
						   "Are you sure you want to flush your changes?"
								 " -- " "Yes" T Window NIL NIL))
					then

          (* * EIther no changes have been made or the user has confirmed.)


					 (if (EQ (fetch (Card Status) of Card)
						     (QUOTE ACTIVE))
					     then          (* Read old card parts off notefile.)
					      (NC.GetNoteCard Card) 
                                                             (* If from links have changed then we'll have to write
							     the new ones out.)
					      (SETQ OldFromLinks (NC.FetchFromLinks Card))
					      (if (NOT (NC.SameLinksP NewFromLinks OldFromLinks)
							   )
						  then (NC.SetFromLinks Card NewFromLinks)
							 (SETQ ChangedFromLinksP T))
                                                             (* Delete the back links from all links that are not 
							     in the old to link set.)
					      (SETQ OldToLinks (NC.FetchToLinks Card))
					      [for ToLink in ToLinks
						 unless (for Link in OldToLinks
							     eachtime (BLOCK)
							     thereis (NC.SameLinkP Link ToLink))
						 do (LET ((DestinationCard (fetch (Link 
										  DestinationCard)
										of ToLink)))
                                                             (* Grab the writelock on the FROMLINKS before trying 
							     to write out the change.)
						           (NC.WithWritePermission DestinationCard
										   (QUOTE FROMLINKS)
										   (NC.DelFromLink
										     ToLink)
										   (SETQ 
										    MadeNewLinksP T]
                                                             (* Check to make sure none of the old To links point 
							     to a deleted card. If so, replace with a deleted 
							     marker.)
					      (SETQ DeletedLinks
						(bind DestinationCard for Link in OldToLinks
						   eachtime (BLOCK)
						   when [PROGN (SETQ DestinationCard
								     (fetch (Link DestinationCard)
									of Link))
								   (AND (NOT (NC.ActiveCardP
										   DestinationCard))
									  (EQ (QUOTE DELETED)
										(NC.FetchStatus
										  DestinationCard]
						   collect (NC.DelReferencesToCard Card 
										  DestinationCard)
							     Link))
					      (NC.SetToLinks Card (LDIFFERENCE OldToLinks 
										   DeletedLinks))
                                                             (* Mark links dirty if we had to delete any to links 
							     or if the from links changed.)
					      (NC.SetLinksDirtyFlg Card (OR DeletedLinks 
										ChangedFromLinksP))
                                                             (* Mark the substance dirty if had to delete any to 
							     links.)
					      (if DeletedLinks
						  then (NC.MarkCardDirty Card)
						else (NC.MarkCardDirty Card (QUOTE RESET)))
					      (NC.SetPropListDirtyFlg Card NIL)
					      (if (NC.FetchTitleDirtyFlg Card)
						  then 

          (* If we've changed title and any of the cards pointing to this one are up on the screen, then we need to update 
	  their images.)


							 (for FromLink in OldFromLinks
							    bind SourceCard eachtime (BLOCK)
							    when
							     (AND (NC.ActiveCardP
								      (SETQ SourceCard
									(fetch (Link SourceCard)
									   of FromLink)))
								    (WINDOWP (NC.FetchWindow
										 SourceCard)))
							    do (NC.UpdateLinkImages SourceCard 
											Card))
							 (NC.SetTitleDirtyFlg Card NIL))
					      (NC.QuitCard Card T)
					   else            (* If the card has never been written to the database 
							     quit w/o saving is equivalent to deleting the card.)
						  (NC.PrintMsg Window T 
								"This card has never been saved."
								 (CHARACTER 13)
								 
							  "It will be deleted from the database."
								 (CHARACTER 13))
						  (NC.DeleteNoteCard Card T])

(NC.UnfileNoteCard
  [LAMBDA (WindowOrTextStream)                               (* Randy.Gobbel " 2-Apr-87 15:38")
                                                             (* Take a notecard out of a file box.
							     Called fom title bar menu.)

          (* * fgh 11/12/85 Updated to handle Card objects.)



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rht 2/2/87: Fixed bug %#418: Trashed all the stuff about opening PropListEditor on the fromlinks.
	  Now just uses SelectNoteCards to choose the fileboxes to delete from.)



          (* * rg 3/4/87 rewritten for new NC.ProtectedCardOperation)



          (* * rg 3/18/87 added NC.CardSelectionOperation wrapper)



          (* * RG 4/2/87 changed NC.CardSelectionOperation to NCP.WithLockedCards)


    (DECLARE (GLOBALVARS NC.SelectingParentsMenu))
    (NCP.WithLockedCards (LET ((Card (NC.CoerceToCard WindowOrTextStream)))
			      (NC.ProtectedCardOperation
				Card "Unfile" NIL (LET* [(FromLinks (NC.FetchFromLinks Card))
							 (Parents (for FromLink in FromLinks
								     when
								      (FMEMB (fetch (Link Label)
										  of FromLink)
									       (QUOTE (FiledCard
											  SubBox)))
								     collect (fetch (Link 
										       SourceCard)
										  of FromLink]
						        (for Box
							   in (NC.SelectNoteCards
								  NIL
								  [FUNCTION (LAMBDA (Box)
								      (AND (NC.FileBoxP Box)
									     (FMEMB Box Parents]
								  NC.SelectingParentsMenu Card 
			  "Please shift-select the file box(es) from which to remove this card. ")
							   do (for FromLink in FromLinks
								   when (NC.SameCardP
									    Box
									    (fetch (Link SourceCard)
									       of FromLink))
								   do (NC.DeleteLink FromLink T])

(NC.UpdateUpdateList
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 20:36")
                                                             (* Update the list of update authors and times for the
							     note card specified by ID)

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


    (COND
      ((NC.ActiveCardP Card)
	(COND
	  ((NULL (NC.FetchPropList Card))
	    (NC.SetPropList Card (LIST (QUOTE Updates)
					   (LIST (LIST USERNAME (DATE))))))
	  (T (LISTPUT (NC.FetchPropList Card)
			(QUOTE Updates)
			(CONS (LIST USERNAME (DATE))
				(LISTGET (NC.FetchPropList Card)
					   (QUOTE Updates))))))
	(NC.SetPropListDirtyFlg Card T))
      (T (NC.ReportError "NC.UpdateUpdateList" (CONCAT Card ": Card not active on screen"))))))

(NC.CollectReferences
  (LAMBDA (Card CheckAndDeleteFlg ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* fgh: " 5-Feb-86 19:54")

          (* * Collect all the links in a card specified by ID. RETURNS the CONS of a list of link identifiers {described 
	  below} and a dirtyflg that is non-NIL if the Substance of ID has been modified {i.e., when a non-valid link is 
	  found and CheckAndDeleteFlg is NIL}. IF CheckAndDeleteFlg is non-NIL checks for valid links and deletes those that 
	  are not valid. If ReturnLinkIconsFlg is NIL, returns link icons. Otherwise, returns links. If ReturnLinkIconsFlg is
	  NIL, returns just the links/link icons. Otherwise, returns the CONS of link/link icon and the type-specific 
	  location of the link icon in the card.)



          (* * fgh 11/12/85 Updated to handle Card objects.)



          (* * rht 12/19/85: Fixed to handle types with no CollectReferencesFn defined.)



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


    (COND
      ((NC.ActiveCardP Card)
	(NC.ApplyFn CollectLinksFn Card CheckAndDeleteFlg ReturnLinkIconsFlg ReturnLocationsFlg))
      (T (NC.ReportError "NC.CollectReferences" (CONCAT "Attempt to call with inactive card:  " 
							    Card))))))

(NC.CardSaveFn
  [LAMBDA (WindowOrID QuietFlg InterestedWindow OperationMsg)
                                                             (* Randy.Gobbel "20-May-87 13:48")

          (* * rht 2/1/85: New function for saving ANY kind of card. All strangenesses are handled in NC.CardDirtyP and 
	  NC.MarkCardDirty. Added print statements to show what is being saved. Lets NC.CardDirtyP take care of proper dirty 
	  checks.)



          (* * rht 2/8/85: Added InsureFilingFlg)



          (* * rht 6/25/85: Pulled out InsureFilingFlg. That check now done upstairs in NC.QuitCard.)



          (* * rht 9/20/85: Added QuietFlg.)



          (* * fgh 11/12/85 Updated to handle Card objects. Removed DatabaseStream object.)



          (* * kirk 29Jan86 replaced call on undefined NC.UpdateRegionData with NC.PutRegion)



          (* * fgh 6/13/86 Added operations in progress code and DontCheckForOpsInProgressFlg arg.)



          (* * fgh 6/26/86 Added InterestedWindow & OperationMsg arg.)



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



          (* * kef 7/22/86: Added something to obtain the write permission on the FROMLINKS if the links have been changed.
	  FROMLINKS aren't ordinarily obtained at edit time like the rest of the links are.)



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



          (* * kef 7/30/86: Added a check to see if the NewCardFlg was on, then release TITLE and FROMLINKS writelocks.
	  This is needed since ordinary deactivation of cards won't do this; i.e., only new cards have their TITLE and 
	  FROMLINKS also writelocked.)



          (* * fgh 8/30/86 Changed APPLY* to NC.ApplyFn where possible.)



          (* * rht&pmi 11/21/86: Now calls WhenSavedFn for card type if any.)



          (* * rg 3/4/87 rewritten for new NC.ProtectedCardOperation, removed DontCheckForOpsInProgressFlg)



          (* * rht 3/23/87: Fixed weirdness with InterestedWindow/Window.)



          (* * Rht 3/24/87: Now calls NC.CoerceToInterestedWindow)



          (* * rht 3/30/87: No longer prints messages if nothing got written down.)



          (* * rg 3/31/87 fiddled w/ InterestedWindow stuff)



          (* * rg 5/20/87 added FORCEOUTPUT on stream after all writes done. WARNING! THIS IS A KLUDGE, AND WILL ONLY WORK 
	  FOR OLD-FASHIONED LOCAL NOTEFILES. For remote notefiles, we really need to add another operation to the protocol.)


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP)
         (NC.ProtectedCardOperation
	   Card "Save Card" InterestedWindow (LET [(WhenSavedFn (GETPROP (NC.FetchType Card)
									   (QUOTE WhenSavedFn]
					          (AND WhenSavedFn (APPLY* WhenSavedFn Card)))
	   (SETQ Window (NC.FetchWindow Card))
	   (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
	   (if (NC.CheckForNotReadOnly Card InterestedWindow "Can't save cards in ")
	       then (COND
			((OR (NC.CardDirtyP Card)
			       (NC.FetchNewCardFlg Card))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow T (OR OperationMsg "")
							(NC.FetchTitle Card)
							": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "substance, "))
			  (NC.PutMainCardData Card T)
			  (SETQ DoneAPutP T)
			  (NC.MarkCardDirty Card (QUOTE RESET)))
			([AND (NOT (NC.FetchBeingDeletedFlg Card))
				Window
				(OR [NOT (EQUAL (fetch (REGION WIDTH) of (SETQ OldRegion
										     (NC.FetchRegion
										       Card)))
						      (fetch (REGION WIDTH)
							 of (SETQ NewRegion (WINDOWPROP
								  Window
								  (QUOTE REGION]
				      (NOT (EQUAL (fetch (REGION HEIGHT) of OldRegion)
						      (fetch (REGION HEIGHT) of NewRegion]
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "region, "))
			  (NC.PutRegion Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchTitleDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "title, "))
			  (NC.PutTitle Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchPropListDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "proplist, "))
			  (NC.PutPropList Card)
			  (SETQ DoneAPutP T)))
		      [COND
			((NC.FetchLinksDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "links, "))
                                                             (* Make sure that we have the FROMLINKS of this card.
							     Only necessary because all of the LINKS are written 
							     together.)
			  (RESETLST (until (NC.ApplyFn ObtainWritePermissionFn Card (QUOTE
							     FROMLINKS))
					 do (BLOCK)
					      (NC.PrintMsg InterestedWindow NIL 
						     "waiting for FROMLINKS write permission...."))
				      (RESETSAVE NIL (BQUOTE (APPLY* , (fetch (Card 
									 ReleaseWritePermissionFn)
										of Card)
									   , Card FROMLINKS)))
				      (NC.PutLinks Card)
				      (SETQ DoneAPutP T]   (* It's not a new card anymore.)
		      (FORCEOUTPUT (fetch (NoteFile Stream) of (fetch (Card NoteFile)
									of Card))
				     T)
		      (COND
			((NC.FetchNewCardFlg Card)

          (* If a new card, then make sure we release the FROMLINKS and TITLE. Necessary because DeactivateCard normally 
	  doesn't do this, because the FROMLINKS and TITLE aren't ordinarily owned on an active card.)


			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE FROMLINKS))
			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE TITLE))
			  (NC.SetNewCardFlg Card NIL)))
		      (OR QuietFlg (if DoneAPutP
					 then (NC.PrintMsg InterestedWindow NIL "Done."
							       (CHARACTER 13))
						(NC.ClearMsg InterestedWindow T])

(NC.DetermineDisplayRegion
  [LAMBDA (Card RegionOrPosition)                            (* rht: "17-May-87 00:09")

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



          (* * fgh 2/5/86 Changed names DefaultcardWidth to FeatchDefaultWidth ...)



          (* * rht 3/25/87: Changed so as to account for the NoteFile indicator window height if present.)



          (* * pmi 3/31/87: Changed prompt message for placing card to not say "... Card NIL" for a new card.)



          (* * rht 5/16/87: Now takes attached windows into account for cases when RegionOrPosition is a region.
	  But only when the card's window is already open.)


    (DECLARE (GLOBALVARS NC.BringUpCardAtOldPosFlg NC.ShowNoteFileOnCards))
    (LET ((Window (NC.FetchWindow Card))
	  CardWinRegion TotalWinRegion Region)
         (if (WINDOWP Window)
	     then (SETQ CardWinRegion (WINDOWPROP Window (QUOTE REGION)))
		    (SETQ TotalWinRegion (WINDOWREGION Window)))
         (COND
	   [(POSITIONP RegionOrPosition)
	     (if (SETQ Region (OR TotalWinRegion (NC.FetchRegion Card)))
		 then (CREATEREGION (fetch (POSITION XCOORD) of RegionOrPosition)
					(fetch (POSITION YCOORD) of RegionOrPosition)
					(fetch (REGION WIDTH) of Region)
					(fetch (REGION HEIGHT) of Region))
	       else (CREATEREGION (fetch XCOORD of RegionOrPosition)
				      (fetch YCOORD of RegionOrPosition)
				      (NC.FetchDefaultWidth Card)
				      (NC.FetchDefaultHeight Card]
	   ([SETQ Region (OR (REGIONP RegionOrPosition)
				 (AND NC.BringUpCardAtOldPosFlg (NC.FetchRegion Card]
	     (if Window
		 then [create REGION using Region HEIGHT ← (PLUS (fetch HEIGHT
									    of TotalWinRegion)
									 (DIFFERENCE (fetch
											 HEIGHT
											  of Region)
										       (fetch
											 HEIGHT
											  of 
										    CardWinRegion)))
						 WIDTH ← (PLUS (fetch WIDTH of TotalWinRegion)
								 (DIFFERENCE (fetch WIDTH
										  of Region)
									       (fetch WIDTH
										  of CardWinRegion]
	       else Region))
	   (Window TotalWinRegion)
	   (T (LET (Width Height TotalHeight CardTitle NewRegion)
	           (if (SETQ Region (NC.FetchRegion Card))
		       then (SETQ Width (fetch WIDTH of Region))
			      (SETQ Height (fetch HEIGHT of Region))
		     else (SETQ Width (NC.FetchDefaultWidth Card))
			    (SETQ Height (NC.FetchDefaultHeight Card)))
	           (SETQ TotalHeight (if NC.ShowNoteFileOnCards
					   then (PLUS Height (NC.NoteFileIndicatorWinHeight))
					 else Height))
	           (SETQ CardTitle (NC.FetchTitle Card))
	           (replace (REGION HEIGHT) of [SETQ NewRegion
						     (GETBOXREGION Width TotalHeight (GETMOUSEX)
								     (IDIFFERENCE (GETMOUSEY)
										    TotalHeight)
								     NIL
								     (if CardTitle
									 then (CONCAT
										  
							 "Please specify location for Note Card "
										  (NC.FetchTitle
										    Card))
								       else (CONCAT 
							       "Please specify location for new "
											(
										  NC.RetrieveType
											  Card)
											" Card"]
		      with Height)
	       NewRegion])

(NC.AbortCard
  [LAMBDA (Card QuietFlg)                                    (* rht: "16-May-87 20:50")

          (* * Kill this card's process and its window.)



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



          (* * rht 7/6/86: Now passes non-nil Don'tRecacheFlg to NC.QuitCard.)



          (* * rht 7/13/86: Now takes QuietFlg and passes to NC.QuitCard.)



          (* * rht 5/16/87: Now passes non-nil CloseWFlg to NC.QuitCard.)


    (NC.QuitCard Card T T T NIL NIL QuietFlg])

(NC.CardNeedsFilingP
  [LAMBDA (Card)                                             (* rht: "26-Mar-87 19:30")

          (* * Returns non-nil if this card is filed in some not currently filed anywhere unless it's a top level card.
	  Assumes card is active.)



          (* * fgh 11/12/85 Updated to handle Card objects.)



          (* * rht 10/6/86: Now checks for card types that don't have to be filed. Also makes sure that there's at least one 
	  filing link that's within this notefile.)



          (* * rht 12/8/86: Now checks for individual cards that don't require filing.)



          (* * rg 12/18/86: Added check of FilingLinkTypeFlg prop.)



          (* * rht 3/26/87: Fixed check for crossfilelink card.)


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (AND (NOT (NC.TopLevelCardP Card))
		(NC.ForceFilingForCardTypeP (NC.FetchType Card))
		(NOT (NCP.CardProp Card (QUOTE Don'tRequireFilingFlg)))
		(for Link in (NC.FetchFromLinks Card)
		   never (AND (OR (FMEMB (fetch (Link Label) of Link)
						 (QUOTE (FiledCard SubBox)))
					(GETPROP (fetch (Link Label) of Link)
						   (QUOTE FilingLinkTypeFlg)))
				  (NOT (NC.CrossFileLinkCardP (fetch (Link SourceCard)
								     of Link])

(NC.TopLevelCardP
  (LAMBDA (Card)                                             (* rht: "13-Jul-86 17:35")

          (* * Is Card a top level card in its NoteFile?)


    (for TopLevelCard in (NC.FetchSpecialCards (fetch (Card NoteFile) of Card))
       thereis (NC.SameCardP Card TopLevelCard))))

(NC.MakeDummyRegion
  (LAMBDA (Card)                                             (* fgh: " 5-Jun-86 19:54")

          (* * Returns a region based at (0 0) with default width and height according to Type.)



          (* * fgh 2/5/86 Changed names DefaultcardWidth to FeatchDefaultWidth ...)



          (* * fgh 6/5/86 Now leaves room for scroll bars.)


    (CREATEREGION 20 20 (NC.FetchDefaultWidth Card)
		    (NC.FetchDefaultHeight Card))))

(NC.ValidCardP
  (LAMBDA (Card)                                             (* rht: "14-Nov-85 19:57")

          (* * Is ID a currently extant card or box?)



          (* * rht 1/31/85: Now reads status from index array rather than file.)



          (* * fkr 11/8/85 Updated to handle NoteFile objects and new Card scheme.)


    (AND (NC.CardP Card)
	   (OR (EQ (QUOTE ACTIVE)
		       (NC.FetchStatus Card))
		 (NC.FetchNewCardFlg Card)))))

(NC.TitleBarButtonEventFn
  [LAMBDA (Window)                                           (* rht: " 6-May-86 12:10")

          (* * if inside title region, bringup left or middle menu, otherwise just call the oldbuttoneventfn)


    (LET (MiddleButtonMenu LeftButtonMenu)
         (COND
	   ((INSIDEP (DSPCLIPPINGREGION NIL Window)
		       (LASTMOUSEX Window)
		       (LASTMOUSEY Window))
	     (APPLY* (WINDOWPROP Window (QUOTE OLDBUTTONEVENTFN))
		       Window))
	   ([AND (LASTMOUSESTATE MIDDLE)
		   (type? MENU (SETQ MiddleButtonMenu (WINDOWPROP Window (QUOTE 
									 TitleBarMiddleButtonMenu]
	     (APPLY* (OR (MENU MiddleButtonMenu)
			     (FUNCTION NILL))
		       Window))
	   ([AND (LASTMOUSESTATE LEFT)
		   (type? MENU (SETQ LeftButtonMenu (WINDOWPROP Window (QUOTE 
									   TitleBarLeftButtonMenu]
	     (APPLY* (OR (MENU LeftButtonMenu)
			     (FUNCTION NILL))
		       Window])

(NC.InstallTitleBarMiddleMenu
  [LAMBDA (Window CardType)                                  (* pmi: " 1-Apr-87 16:47")

          (* * Make a middle button title bar menu and install.)



          (* * pmi 4/1/87: Added NC.MenuFont to all menus)


    (DECLARE (GLOBALVARS NC.MenuFont))
    (WINDOWPROP Window (QUOTE TitleBarMiddleButtonMenu)
		  (create MENU
			    ITEMS ← (NC.GetCardTypeField MiddleButtonMenuItems CardType)
			    CENTERFLG ← T
			    MENUFONT ← NC.MenuFont
			    ITEMHEIGHT ← (IPLUS (FONTPROP NC.MenuFont (QUOTE HEIGHT))
						  1])
)
(* * Prop List Editor)

[DECLARE: EVAL@COMPILE 

(RECORD PropListItem (PropertyName Value OriginalListFlg AllowEditFlg AllowSelectFlg ButtonFn))
]
(DEFINEQ

(NC.AddPropToPropList
  [LAMBDA (editW)                                            (* rht: "16-Jan-87 16:06")
                                                             (* Add a new prop to the propList being edited in 
							     editW)

          (* * fgh 2/10/86 Fix problem with ClearMsg deleting editing window.)



          (* * rht 4/11/86: Fixed bug whereby it couldn't add property when none exist.)



          (* * rht 1/16/87: Now uses prop names on windowprop rather than number of props. Makes sure that propname doesn't 
	  already exist and that it's not system-reserved.)


    (PROG [(promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	     selectedObject propName propValue insertPtr insertChars beginPtr
	     (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	     (tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	     (PropNames (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES]
	    (SETQ propName (MKATOM (NC.AskUser "New Property Name is = " NIL NIL T promptWindow)
				       ))
	    (COND
	      ((FMEMB propName PropNames)
		(NC.PrintMsg promptWindow T (CONCAT "'" propName "' property already exists."
							(CHARACTER 13)))
		(RETURN))
	      ((FMEMB propName NC.SystemCardPropNames)
		(NC.PrintMsg promptWindow T (CONCAT "'" propName 
							"' is a system-reserved property name."
							(CHARACTER 13)))
		(RETURN)))
	    (SETQ propValue (NC.AskUser (CONCAT "Value for " propName " property = ")
					    NIL NIL T promptWindow))
                                                             (* Insert these values into the editW)
	    (if PropNames
		then                                       (* Position just before selected button)
		       (NC.PrintMsg promptWindow T 
			     "Please select a property before which to insert this new property."
				      (CHARACTER 13))
		       (SETQ selectedObject (NC.SelectProperty editW))
		       (NC.ClearMsg promptWindow T)
		       (AND (NULL selectedObject)
			      (RETURN NIL))
		       (SETQ insertPtr (TEDIT.FIND.OBJECT tobj selectedObject))
	      else                                         (* No properties to insert before.)
		     (SETQ insertPtr 1))
	    (SETQ beginPtr insertPtr)                      (* Insert a button with this property name)
	    (TEDIT.INSERT.OBJECT (MBUTTON.CREATE propName (FUNCTION NC.EditPropButtonFN)
						     (FONTCREATE (QUOTE HELVETICA)
								   10
								   (QUOTE BOLD)))
				   stream insertPtr)         (* Spacer between Prop and Value)
	    (add insertPtr 1)
	    (TEDIT.INSERT stream (CHARACTER 9)
			    insertPtr)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON))
			   insertPtr 1)
	    (add insertPtr 1)                              (* Create a new field (Copied from JBS's 
							     \TEXTMENU.DOC.CREATE))
	    (TEDIT.INSERT stream (CONCAT "  {}" (CHARACTER 13))
			    insertPtr)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON))
			   insertPtr 5)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON SELECTPOINT ON))
			   (IPLUS insertPtr 2)
			   1)
	    (TEDIT.INSERT stream (MKSTRING propValue)
			    (IPLUS insertPtr 3))
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED OFF SELECTPOINT OFF))
			   (IPLUS insertPtr 3)
			   (NCHARS (MKSTRING propValue)))
	    (add insertPtr (NCHARS (MKSTRING propValue)))
	    (add insertPtr 5)
	    (WINDOWADDPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
			     propName])

(NC.CloseAllPropListEditors
  (LAMBDA (Card)                                             (* rht: "11-Aug-86 19:11")
                                                             (* Force all prop list editors open on card ID to 
							     close without saving changes.)

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



          (* * rht 8/11/86: Now makes sure that proplist window gets closed.)


    (for AttachedWindow in (ALLATTACHEDWINDOWS (NC.FetchWindow Card))
       when (WINDOWPROP AttachedWindow (QUOTE PropListEditor)) eachtime (BLOCK)
       do (NC.ClosePropListEditor AttachedWindow (QUOTE NoSave))
	    (AND (OPENWP AttachedWindow)
		   (CLOSEW AttachedWindow)))))

(NC.ClosePropListEditor
  [LAMBDA (Window SaveFlg)                                   (* rht: "24-Apr-87 16:49")

          (* Close the prop list editor, saving or not saving the edited prop list as specified by the SaveFlg or by the user
	  if SaveFlg is NIL)



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



          (* * fgh 6/8/86 Added call to RAPOSITIONATTACHEDWINDOWS)



          (* * rht 8/12/86 Now uses TEXTOBJ to get TextObj from window.)



          (* * kef 7/16/86: Added the call to release the write permission should the window property declare that it be 
	  necessary.)



          (* * kef 7/22/86: Now only releases the write permission if the card is inactive. The reason is that it was 
	  determined that a card being edited would update the property list upon being closed.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn. Added Card local var.)



          (* * rht 11/12/86: Now calls MAINWINDOW instead of WINDOWPROP to get Window's mainwindow and recovers card from a 
	  prop of Window.)



          (* * rht 1/16/87: Now checks that tedit stream has been modified before using user as to whether to save changes.
	  No longer puts up stupid save/cancel menu.)



          (* * rht&rg 4/24/87: Now smashes more windowprops to prevent storage leaks.)


    (DECLARE (GLOBALVARS NC.SavePropEditMenu))
    (PROG (TextObj Answered OldPropList NewPropList MainWindow Card)
	    (SETQ Card (WINDOWPROP Window (QUOTE SavedCardObject)))
	    (SETQ MainWindow (MAINWINDOW Window))
	    (DETACHWINDOW Window)
	    [SETQ TextObj (CAR (NLSETQ (TEXTOBJ Window]
	    (SETQ OldPropList (WINDOWPROP Window (QUOTE PROPERTYLIST.BEING.EDITED)))
	    [AND TextObj (COND
		     ((EQ SaveFlg (QUOTE NoSave)))
		     ((EQ (WINDOWPROP Window (QUOTE PropListEditor))
			    (QUOTE ShowOnly)))
		     ((OR (EQ SaveFlg (QUOTE Save))
			    (TEDIT.STREAMCHANGEDP TextObj))
		       (SETQ NewPropList (NC.ExtractPropList Window))
		       (NC.ProcessEditedPropList NewPropList OldPropList Card]
	    (WINDOWPROP Window (QUOTE TEDIT.MENU)
			  NIL)
	    (WINDOWPROP Window (QUOTE TEDIT.PROPS)
			  NIL)
	    (WINDOWPROP Window (QUOTE PropListEditor)
			  NIL)
	    (WINDOWPROP Window (QUOTE SavedCardObject)
			  NIL)
	    (WINDOWPROP Window (QUOTE PROPERTYLIST.BEING.EDITED)
			  NIL)
	    (WINDOWPROP Window (QUOTE PROPERTYLIST.PROPNAMES)
			  NIL)
	    (WINDOWDELPROP Window (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor))
	    (COND
	      ((AND (WINDOWPROP Window (QUOTE ReleaseWritePermissionP))
		      (NOT (NC.ActiveCardP Card)))
		(NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE PROPLIST))
		(WINDOWPROP Window (QUOTE ReleaseWritePermissionP)
			      NIL)))
	    [COND
	      (TextObj (replace (TEXTOBJ \DIRTY) of TextObj with NIL)
		       [\TEDIT.QUIT (CAR (MKLIST (fetch (TEXTOBJ \WINDOW) of TextObj]
		       (until (fetch (TEXTOBJ EDITFINISHEDFLG) of TextObj) do (BLOCK]
	    (ADD.PROCESS (BQUOTE (PROGN (until (NULL (OPENWP , Window)) do (BLOCK))
					      (REPOSITIONATTACHEDWINDOWS , MainWindow])

(NC.DelPropFromList
  [LAMBDA (editW)                                            (* rht: "16-Jan-87 15:52")

          (* * rht 4/11/86: Now decrements PROPERTYLIST.LENGTH windowprop.)



          (* * rht 1/16/87: Now uses prop names on windowprop rather than number of props.)


    (PROG ((promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	     (tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	     (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	     selectedObject CH#)
	    (if (NULL (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES)))
		then (NC.PrintMsg promptWindow T "No properties to delete.")
		       (RETURN))
	    (NC.PrintMsg promptWindow T "Please select property to be deleted.")
	    (SETQ selectedObject (NC.SelectProperty editW))
	    (NC.ClearMsg promptWindow T)
	    (if (IMAGEOBJPROP selectedObject (QUOTE EditPropListNoDelete))
		then (NC.PrintMsg promptWindow T 
				      "Selected property:value pair cannot be deleted."
				      (CHARACTER 13))
	      else (SETQ CH# (TEDIT.FIND.OBJECT tobj selectedObject))
		     (MBUTTON.FIND.NEXT.FIELD tobj CH#)    (* Delete everything between the imageobj and the 
							     end-of-line.)
		     (TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
				    CH#
				    (IPLUS 2 (IDIFFERENCE (fetch CHLIM
								 of (fetch SCRATCHSEL
									 of tobj))
							      CH#)))
		     (TEDIT.DELETE stream CH# (IPLUS 2 (IDIFFERENCE (fetch CHLIM
									     of (fetch SCRATCHSEL
										     of tobj))
									  CH#)))
		     (TEDIT.SETSEL stream (GETEOFPTR stream)
				     0
				     (QUOTE RIGHT))
		     (WINDOWDELPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
				      (IMAGEOBJPROP selectedObject (QUOTE MBTEXT])

(NC.EditPropButtonFN
  (LAMBDA (imageObject sel window)                           (* fgh: "20-Apr-84 21:17")
                                                             (* This is the default function called whenever the 
							     user selects a button in the NC.EditPropList window.)
    (WINDOWPROP window (QUOTE SelectedObject)
		  imageObject)))

(NC.EditProperties
  [LAMBDA (TextStream)                                       (* Randy.Gobbel " 1-Apr-87 12:25")
                                                             (* Open a property list editor for the card 
							     corresponding to TextStream.
							     Called from Title bar menus.)

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



          (* * rht 4/11/86: No longer sticks dates and Updates in property list. Only user-defined stuff.)



          (* * kef 7/22/86: Added call to card's obtain write permission function for the PROPLIST.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn.)



          (* * rht 1/16/87: Now uses NC.SystemCardPropNames globalvar.)



          (* * rg 4/1/87 added NC.ProtectedCardOperation wrapper)


    (DECLARE (GLOBALVARS NC.SystemCardPropNames))
    (LET ((Card (NC.CoerceToCard (WINDOW.FROM.TEDIT.THING TextStream)))
	  PropList PropEditorWindow)
         (NC.ProtectedCardOperation Card "Edit Properties" NIL (SETQ PropList (NC.FetchPropList
					Card))
				    (COND
				      ((NC.ApplyFn ObtainWritePermissionFn Card (QUOTE PROPLIST))
					(WINDOWPROP (SETQ PropEditorWindow
							(NC.OpenPropListEditor
							  TextStream
							  (for SubList on PropList
							     by (CDDR SubList)
							     when (NOT (FMEMB (CAR SubList)
										    
									   NC.SystemCardPropNames))
							     join (LIST (CAR SubList)
									    (CADR SubList)))
							  "Edit Property List"))
						      (QUOTE ReleaseWritePermissionP)
						      T)
					PropEditorWindow)
				      (T (NC.CardPartBusy Card (QUOTE PROPLIST])

(NC.EditPropList
  [LAMBDA (propList window showOnlyFlg)                      (* pmi: "25-Mar-87 12:30")

          (* * propList is a list of RECORDS of type PropListItem)



          (* * Edit a property list using the TEDIT menu-based editor. The var window is the window to use.
	  If none supplied, get one from user.)



          (* * rht 4/11/86: Now stashes length of propList on WINDOWPROP.)



          (* * rht 8/12/86: Moved code to add NC.ClosePropListEditor on CLOSEFN from NC.OpenPropListEditor to here so that it
	  can before TEDIT.DEACTIVATE.WINDOW on the CLOSEFN list.)



          (* * rht 1/16/87: Now stashes prop names on windowprop rather than number of props.)



          (* * pmi 3/25/87: Added NC.MenuFont to all menus)


    (DECLARE (GLOBALVARS NC.MenuFont))
    (PROG (menuStream textObj editW button (font (FONTCREATE (QUOTE HELVETICA)
								 8))
			(CH# 1)
			(ENDCH# 1))                          (* Init the editList and the propFnsList)
                                                             (* Create a TEDITMenu that reflects the structure of 
							     the proplist)
	    [SETQ menuStream
	      (\TEXTMENU.DOC.CREATE
		(for X in propList
		   join (NCONC [LIST (LIST (QUOTE MB.BUTTON)
						   (MKSTRING (fetch (PropListItem PropertyName)
								  of X))
						   (OR (fetch (PropListItem ButtonFn)
							    of X)
							 (FUNCTION NC.EditPropButtonFN]
				   (COND
				     [(NOT (IMAGEOBJP (fetch (PropListItem Value) of X)))
				       (COND
					 ((fetch (PropListItem AllowEditFlg) of X)
					   (LIST (LIST (QUOTE MB.TEXT)
							   (CONCAT (CHARACTER 9)
								     "  ["
								     (MKSTRING (fetch
										   (PropListItem
										     Value)
										    of X))
								     "]"
								     (CHARACTER 13))
							   font)))
					 (T (LIST (LIST (QUOTE MB.TEXT)
							    (CHARACTER 9)
							    font)
						    (LIST (QUOTE MB.INSERT)
							    (MKSTRING (fetch (PropListItem Value)
									   of X)))
						    (LIST (QUOTE MB.TEXT)
							    (CHARACTER 13)
							    font]
				     (T (LIST (LIST (QUOTE MB.TEXT)
							(CHARACTER 9)
							font)
						(LIST (QUOTE MB.INSERT))
						(LIST (QUOTE MB.TEXT)
							(CHARACTER 13)
							font]
	    (SETQ textObj (TEXTOBJ menuStream))          (* Go back and insert the ImageObjects into their 
							     value fields.)
	    (SETQ CH# 0)
	    [for prop in propList when (OR (IMAGEOBJP (fetch (PropListItem Value)
								   of prop))
						   (NULL (fetch (PropListItem AllowEditFlg)
							      of prop)))
	       do (MBUTTON.FIND.NEXT.FIELD textObj (SETQ CH# (ADD1 CH#)))
		    (SETQ CH# (fetch CH# of (fetch SCRATCHSEL of textObj)))
		    (COND
		      ((IMAGEOBJP (CADR prop))
			(TEDIT.INSERT.OBJECT (fetch (PropListItem Value) of prop)
					       menuStream CH#]
	    (SETQ CH# 0)
	    (for prop in propList
	       do (SETQ button (MBUTTON.FIND.NEXT.BUTTON textObj (ADD1 CH#)))
		    (SETQ CH# (CDR button))              (* If the buttonProtect flag is on, protect the 
							     button)
		    (AND (fetch (PropListItem AllowSelectFlg) of prop)
			   (IMAGEOBJPROP (CAR button)
					   (QUOTE EditPropListNoDelete)
					   T)))              (* Set up window and window title)
	    [SETQ editW (COND
		(window window)
		(T (CREATEW (GETREGION)
			      "Edit Property List"]          (* Point to the proplist being edited so we can update
							     it when this menu is closed.
							     (See NC.CloseEditPropListWindow))
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED)
			  propList)
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
			  (for Item in propList collect (CAR Item)))
                                                             (* Set the right margin to very-far-away.
							     Prevents stuff from wrapping around)
	    (TEDIT.PARALOOKS textObj [QUOTE (RIGHTMARGIN 1000 TABS (50 (80 . LEFT]
			       1
			       (GETFILEINFO menuStream (QUOTE LENGTH)))
                                                             (* Set the first tab so the fields will line up 
							     correctly)
                                                             (* Set selection to the top -- make it look pretty)
	    (replace (SELECTION SET) of (fetch (TEXTOBJ SEL) of textObj) with NIL)
	    [TEDIT menuStream editW NIL (LIST
		       (QUOTE MENU)
		       (create MENU
				 ITEMS ← [COND
				   [showOnlyFlg (QUOTE (("Quit" (NC.ClosePropListEditor
								    W
								    (QUOTE NoSave))
								  "Quit from pointer list display."]
				   (T (QUOTE (("Add New Property" (NC.AddPropToPropList W)
								    
					       "Add a new property to this card's property list.")
						 ("Delete Selected Property" (NC.DelPropFromList
									       W)
									     
				       "Delete selected property from this card's property list.")
						 ("Quit w/o Saving Changes" (NC.ClosePropListEditor
									      W
									      (QUOTE NoSave))
									    
					   "Quit from property list edit. Changes are not saved.")
						 ("Quit - Saving Changes" (NC.ClosePropListEditor
									    W
									    (QUOTE Save))
									  
						  "Quit from property list editor. Save changes."]
				 MENUFONT ← NC.MenuFont
				 CENTERFLG ← T
				 ITEMHEIGHT ← (IPLUS (FONTPROP NC.MenuFont (QUOTE HEIGHT))
						       1]
	    (WINDOWADDPROP editW (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor)
			     T])

(NC.ExtractPropList
  [LAMBDA (editW)                                            (* rht: "16-Jan-87 12:29")
                                                             (* Exctract the prop list from the TextStream in prop 
							     list editor window editW)

          (* * rht 1/16/87: Now makes sure tobj isn't empty before searching for items.)


    (LET [(tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	  menuStream button propName (propValue T)
	  EOL
	  (CH# 1)
	  (propList (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED]
                                                             (* Move through each field/value pair in menu.
							     Update each PROP in the list.)
                                                             (* For each property in the list, move to the next 
							     field, and drop its value into the field slot.)
         (SETQ menuStream (fetch STREAMHINT of tobj))
                                                             (* for each button in the menu do)
         (AND (GREATERP (fetch (TEXTOBJ TEXTLEN) of tobj)
			    1)
		(while (SETQ button (MBUTTON.FIND.NEXT.BUTTON tobj CH#))
		   collect                                 (* Convert the name of the button into the property 
							     name)
                                                             (* Set up the looks of the fields so that 
							     MBUTTON.NEXT.FIELD will work correctly -- Real kludge 
							     to get around limitations in TEditMenu stuff)
			     (TEDIT.LOOKS tobj (QUOTE (PROTECTED ON SELECTPOINT ON))
					    (IPLUS 4 (CDR button))
					    1)
			     [COND
			       ([SETQ EOL (MBUTTON.FIND.NEXT.BUTTON tobj (IPLUS 4 (CDR button]
				 (SETQ EOL (IDIFFERENCE (CDR EOL)
							    2)))
			       (T (SETQ EOL (SUB1 (TEDIT.FIND tobj (CHARACTER 13)
								    (CDR button]
			     [TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
					    (IPLUS 4 (CDR button))
					    (IDIFFERENCE EOL (IPLUS 4 (CDR button]
                                                             (* Get the name of the property from the butrton)
			     (SETQ propName (IMAGEOBJPROP (CAR button)
							      (QUOTE MBTEXT)))
                                                             (* Now get its value by reading the next field)
			     (SETQ propValue (MBUTTON.NEXT.FIELD.AS.TEXT.OR.IMAGEOBJ
				 tobj
				 (CDR button)))
			     [COND
			       [(NULL propValue)
				 (SETQ propValue (fetch (PropListItem Value)
						      of (FASSOC propName propList]
			       ((IMAGEOBJP propValue))
			       ((NC.StringIsListP propValue 0)
                                                             (* This string should really be interpreted as a LIST)
				 (SETQ propValue (READ propValue)))
			       (T                            (* This really is a string)
				  (SETQ propValue (MKATOM propValue]
                                                             (* Keep track of where that property was in the menu 
							     stream)
			     (SETQ CH# (ADD1 (CDR button)))
			     (LIST propName propValue])

(NC.OpenPropListEditor
  [LAMBDA (WindowOrTextStream PropList Title ShowOnlyFlg MakeImageObjFlg ShowLinksFlg)
                                                             (* rht: "11-Dec-86 12:26")
                                                             (* Open a property list editor above the card 
							     specified by TextStream , which is either a TextStream
							     or a Window)

          (* * rht 8/11/86: Now takes ShowLinksFlg arg and passes to NC.PropListEditorOpenP so that we don't bail out if 
	  there's an open proplist not of our type.)



          (* * rht 11/13/86: Now hangs Card object off prop list editor's window so that we can get to the card from the 
	  proplist editor at close time.)



          (* * rht 12/11/86: Now only breaks out list if we're under ShowLinks.)


    (PROG ((Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	     (SystemProperties (QUOTE (ID Updates ItemDate LinksDate PropsDate TitleDate)))
	     EditWindow CardUID Card)                        (* Make sure there is no prop list editor already 
							     there)
	    (AND (NC.PropListEditorOpenP Window ShowLinksFlg)
		   (RETURN))
	    [SETQ CardUID (fetch (Card UID) of (SETQ Card (NC.CoerceToCard Window]
                                                             (* FOR each prop/value pair with LISTP value.
							     Make a series of individual prop/value pairs 
							     corresponding to the elements of the LISTP)
	    [SETQ PropList (for Item on PropList by (CDDR Item)
				join (COND
					 ((AND (LISTP (CADR Item))
						 (type? Link (CAADR Item)))
					   (for Element in (CADR Item)
					      collect (create PropListItem
								  PropertyName ← (CAR Item)
								  Value ← Element
								  OriginalListFlg ← T
								  AllowEditFlg ← NIL
								  AllowSelectFlg ← NIL
								  ButtonFn ← NIL)))
					 (T (LIST (create PropListItem
							      PropertyName ← (CAR Item)
							      Value ← (CADR Item)
							      OriginalListFlg ← NIL
							      AllowEditFlg ← NIL
							      AllowSelectFlg ← NIL
							      ButtonFn ← NIL]
                                                             (* If specified, translate all NOTECARDLINK values 
							     into Image Objects for display.)
	    [AND MakeImageObjFlg (for Item in PropList bind LinkIcon
				      when (type? Link (fetch (PropListItem Value)
							      of Item))
				      do (replace (PropListItem Value) of Item
					      with (SETQ LinkIcon (NC.MakeLinkIcon
							 (fetch (PropListItem Value) of Item)))
						     (IMAGEOBJPROP LinkIcon (QUOTE 
									     InsidePropListEditor)
								     T]
                                                             (* Indicate which properties can be edited by user.)
	    [for Item in PropList do (COND
					     ((FMEMB (fetch (PropListItem PropertyName)
							  of Item)
						       SystemProperties)
					       (replace (PropListItem AllowEditFlg) of Item
						  with T)
					       (replace (PropListItem AllowSelectFlg) of Item
						  with T))
					     (ShowOnlyFlg (replace (PropListItem AllowEditFlg)
							     of Item with NIL)
							  (replace (PropListItem AllowSelectFlg)
							     of Item with T))
					     (T (replace (PropListItem AllowEditFlg) of Item
						   with NIL)
						(replace (PropListItem AllowSelectFlg)
						   of Item with NIL]
                                                             (* Call the prop list editor)
	    (ATTACHWINDOW (SETQ EditWindow (CREATEW (CREATEREGION 1000 2000 100 100)
							  (OR Title "Edit Property List")
							  NIL T))
			    Window
			    (QUOTE TOP)
			    (QUOTE JUSTIFY)
			    (QUOTE LOCALCLOSE))
	    (WINDOWADDPROP EditWindow (QUOTE CLOSEFN)
			     (FUNCTION FREEATTACHEDWINDOW)
			     T)
	    (WINDOWPROP EditWindow (QUOTE PropListEditor)
			  (COND
			    (ShowOnlyFlg (QUOTE ShowOnly))
			    (T T)))
	    (WINDOWPROP EditWindow (QUOTE SavedCardObject)
			  Card)
	    (NC.EditPropList PropList EditWindow ShowOnlyFlg)
	    (RETURN EditWindow])

(NC.ProcessEditedPropList
  [LAMBDA (EditedPropList OldPropList Card)                  (* rht: "16-Jan-87 13:28")
                                                             (* Take an edited prop list and set the prop list of 
							     the card as required.)

          (* * rht 2/1/85: Removed call to NC.MarkCardDirty.)



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



          (* * rht 11/13/86: No longer "spreads" out prop values.)



          (* * rht 1/16/87: Revised wholesale to fix bugs with prop ordering and prop deletion.)


    (DECLARE (GLOBALVARS NC.SystemCardPropNames))
    (LET ((CurPropList (NC.FetchPropList Card)))
         [NC.SetPropList Card (NCONC (for PropName in NC.SystemCardPropNames
					    join (LIST PropName (LISTGET CurPropList PropName)))
					 (for Item in EditedPropList
					    join (LET* [(Prop (fetch (PropListItem PropertyName)
								   of Item))
							  (NewValue
							    (if (ZEROP (NCHARS (CADR Item)))
								then NIL
							      else (CADR Item]
						         (LIST Prop (if (fetch (PropListItem
										       
										  OriginalListFlg)
									       of (FASSOC Prop 
										      OldPropList))
									  then (LIST NewValue)
									else NewValue]
         (NC.SetPropListDirtyFlg Card T])

(NC.PropListEditorOpenP
  (LAMBDA (Window ShowLinksFlg)                              (* rht: "12-Aug-86 00:08")
                                                             (* Is there a prop list editor opened on this window?)

          (* * rht 8/11/86: Now doesn't return NIL unless there's an open proplist editor of our type.)


    (for AttachedWindow in (ALLATTACHEDWINDOWS Window)
       thereis (AND (WINDOWPROP AttachedWindow (QUOTE PropListEditor))
			(LET ((ShowLinks (WINDOWPROP AttachedWindow (QUOTE ShowLinks))))
                                                             (* Check that ShowLinksFlg iff ShowLinks.)
			     (OR (AND ShowLinksFlg ShowLinks)
				   (AND (NULL ShowLinksFlg)
					  (NULL ShowLinks))))))))

(NC.SelectProperty
  (LAMBDA (Window)                                           (* fgh: "20-Apr-84 21:44")
                                                             (* Select one of the properties in prop list editor 
							     window Window)
    (PROG ((ClippingRegion (DSPCLIPPINGREGION NIL Window)))
	    (WINDOWPROP Window (QUOTE SelectedObject)
			  NIL)
	    (until (WINDOWPROP Window (QUOTE SelectedObject))
	       do (until (AND (MOUSESTATE LEFT)
				    (EQ (WHICHW LASTMOUSEX LASTMOUSEY)
					  Window)))
		    (COND
		      ((INSIDEP ClippingRegion (LASTMOUSEX Window)
				  (LASTMOUSEY Window))
			(APPLY* (WINDOWPROP Window (QUOTE BUTTONEVENTFN))
				  Window))))
	    (AND (EQ TEDIT.SELPENDING (WINDOWPROP Window (QUOTE TEXTOBJ)))
		   (SETQ TEDIT.SELPENDING))
	    (RETURN (WINDOWPROP Window (QUOTE SelectedObject)
				    NIL)))))

(NC.ShowLinks
  [LAMBDA (TextStream)                                       (* Randy.Gobbel " 6-Apr-87 16:43")
                                                             (* 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.)


    (LET [Links EditWindow (Card (NC.CoerceToCard (WINDOW.FROM.TEDIT.THING TextStream]
         [SETQ Links (NCONC [for Link in (NC.FetchToLinks Card)
				   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]
				(for Link in (NC.FetchFromLinks Card)
				   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]
         (WINDOWPROP (SETQ EditWindow (NC.OpenPropListEditor TextStream Links "List of Links" T 
								   T T))
		       (QUOTE ShowLinks)
		       T)
     EditWindow])

(NC.StringIsListP
  (LAMBDA (string parenCount)                                (* dmr: "20-Mar-84 23:46")
                                                             (* T if string has a balanced number of 
							     (and). Var "parenCount" counts open parens.)
    (PROG (nextParen)
	    (COND
	      ((NULL string)
		(COND
		  ((ZEROP parenCount)
		    (RETURN T))
		  (T (RETURN NIL)))))
	    (SETQ nextParen (STRPOSL (QUOTE (%( %)))
					 string))
	    (COND
	      ((NULL nextParen)
		(RETURN NIL)))
	    (COND
	      ((EQ (CHARCODE "(")
		     (EVAL (BQUOTE (CHARCODE , (SUBSTRING string nextParen nextParen)))))
		(RETURN (NC.StringIsListP (SUBSTRING string (ADD1 nextParen))
					      (ADD1 parenCount)))))
	    (COND
	      ((EQ (CHARCODE ")")
		     (EVAL (BQUOTE (CHARCODE , (SUBSTRING string nextParen nextParen)))))
		(RETURN (NC.StringIsListP (SUBSTRING string (ADD1 nextParen))
					      (SUB1 parenCount)))))
	    (BREAK))))

(NC.PutProp
  [LAMBDA (Card Prop Value)                                  (* rht: "25-Mar-87 16:11")

          (* * Put a property value pair on the NoteCardsPropList property of ID. ID must be active.)



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



          (* * rht 3/25/87: Now calls NC.SetPropListDirtyFlg to mark prop list as dirty.)


    (PROG ((PropList (NC.FetchPropList Card)))
	    [COND
	      (PropList (LISTPUT PropList Prop Value)
			(NC.SetPropList Card PropList))
	      (T (NC.SetPropList Card (LIST Prop Value]
	    (NC.SetPropListDirtyFlg Card T])

(NC.GetProp
  (LAMBDA (Card Prop)                                        (* fgh: "13-Nov-85 20:42")

          (* * Get the value of a property on the NoteCardsPropList property of ID. ID must be active.)



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


    (LISTGET (NC.FetchPropList Card)
	       Prop)))

(NC.RemProp
  (LAMBDA (Card Prop)                                        (* rht: "26-Nov-85 21:14")

          (* * Remove given property from Card's property list. Someday maybe this could be smarter and save space.)


    (NC.PutProp Card Prop NIL)))
)
(* * Unknown ?????????)

(DEFINEQ

(NC.FetchBeingDeletedFlg
  (LAMBDA (Card)                                             (* fgh: "13-Nov-85 19:46")

          (* * fetch IDs being deleted flag from the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (fetch (Card BeingDeletedFlg) of Card)))

(NC.SetBeingDeletedFlg
  (LAMBDA (Card Value)                                       (* fgh: "13-Nov-85 19:46")

          (* * Set the being deleted flag in the cache)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card BeingDeletedFlg) of Card with Value)))

(NC.RemoveDELETEMEImageObjsFromCard
  [LAMBDA (Card PredicateFn)                                 (* rht: " 7-Oct-86 01:20")

          (* * If card needs cleaning, find and remove any image objects satisfying PredicateFn from Card.
	  Currently only works for text cards.)


    (if (AND (NC.FetchUserDataProp Card (QUOTE NeedsCleaningFlg))
		 (NCP.TextBasedP Card))
	then (LET ((WasActiveFlg (NCP.CardCachedP Card))
		     TextStream)
		    (if (NOT WasActiveFlg)
			then (NCP.CacheCards Card))
		    (SETQ TextStream (NCP.CardSubstance Card))
                                                             (* Need to reverse list so that we delete the last 
							     icon first.)
		    (for IconPair in (REVERSE (TEDIT.LIST.OF.OBJECTS (TEXTOBJ TextStream)
									     PredicateFn))
		       do (TEDIT.DELETE TextStream (CADR IconPair)
					    1))
		    (if (NOT WasActiveFlg)
			then (NCP.UncacheCards Card)))
	       (NC.SetUserDataProp Card (QUOTE NeedsCleaningFlg)
				     NIL])

(NC.InsureIntegerDate
  (LAMBDA (Date)                                             (* rht: " 5-Sep-86 12:15")

          (* * Convert a date to IDATE format if necessary)



          (* * rht 9/5/86: Now returns 0 if IDATE returns nil.)


    (COND
      ((NULL Date)
	0)
      ((FIXP Date))
      ((STRINGP Date)
	(OR (IDATE Date)
	      0))
      (T (NC.ReportError NIL "Unknown date format")))))
)
(* * Place marker ImageObjects)

(DEFINEQ

(NC.PlaceMarkerCopyFn
  (LAMBDA (ImageObj)                                         (* fgh: " 5-Mar-84 23:22")
    (NC.MakePlaceMarker (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))))

(NC.PlaceMarkerDisplayFn
  (LAMBDA (ImageObj Stream)                                  (* rht: " 7-Dec-84 19:33")

          (* * rht 9/24/84: Now works for press and interpress as well as screen.)


    (PROG ((Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))
	     (Scale (DSPSCALE NIL Stream))
	     (Font (FONTCREATE (QUOTE HELVETICA)
				 12
				 (QUOTE ITALIC)
				 NIL Stream)))
	    (RELMOVETO (ITIMES Scale 3)
			 0 Stream)
	    (DSPFONT (PROG1 (DSPFONT Font Stream)
				(PRIN1 (U-CASE Label)
					 Stream))
		       Stream))))

(NC.PlaceMarkerGetFn
  (LAMBDA (FileStream TextStream)                            (* fgh: " 5-Mar-84 23:25")
    (NC.MakePlaceMarker (READ FileStream))))

(NC.PlaceMarkerImageBoxFn
  (LAMBDA (ImageObj Stream)                                  (* rht: " 7-Dec-84 19:33")

          (* * rht 9/24/84: Now scales the box dimensions so can go to press and interpress.)


    (PROG ((Font (FONTCREATE (QUOTE HELVETICA)
				 12
				 (QUOTE ITALIC)
				 NIL Stream))
	     (Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))
	     (Scale (DSPSCALE NIL Stream)))
	    (RETURN (create IMAGEBOX
				XSIZE ←(IPLUS (TIMES 6 Scale)
						(STRINGWIDTH (U-CASE Label)
							       Font))
				YSIZE ←(IPLUS (TIMES 18 Scale)
						(FONTPROP Font (QUOTE HEIGHT)))
				YDESC ←(IPLUS (TIMES 3 Scale)
						(FONTPROP Font (QUOTE DESCENT)))
				XKERN ← 0)))))

(NC.PlaceMarkerPutFn
  (LAMBDA (ImageObj FileStream)                              (* fgh: "29-Feb-84 19:15")
    (PROG ((Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM))))
	    (PRIN2 (MKSTRING Label)
		     FileStream))))

(NC.MakePlaceMarker
  (LAMBDA (Label)                                            (* fgh: " 5-Mar-84 01:43")
    (IMAGEOBJCREATE Label (IMAGEFNSCREATE (FUNCTION NC.PlaceMarkerDisplayFn)
					      (FUNCTION NC.PlaceMarkerImageBoxFn)
					      (FUNCTION NC.PlaceMarkerPutFn)
					      (FUNCTION NC.PlaceMarkerGetFn)
					      (FUNCTION NC.PlaceMarkerCopyFn)
					      (FUNCTION NILL)
					      (FUNCTION NILL)
					      (FUNCTION NILL)
					      (FUNCTION NILL)
					      (FUNCTION NILL)))))
)
(* * Functions for handling dates.)

(DEFINEQ

(NC.FetchTitleDate
  (LAMBDA (Card DontConvertFlg)                              (* fgh: "13-Nov-85 19:47")

          (* * Fetch IDs title date from the cache and and convert to string format if necessary)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (LET ((Date (fetch (Card TitleDate) of Card)))
         (COND
	   ((ZEROP Date)
	     NIL)
	   (DontConvertFlg Date)
	   (T (GDATE Date))))))

(NC.FetchItemDate
  (LAMBDA (Card DontConvertFlg)                              (* fgh: "13-Nov-85 19:47")

          (* * Fetch IDs item date from the cache and and convert to string format if necessary)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (LET ((Date (fetch (Card ItemDate) of Card)))
         (COND
	   ((ZEROP Date)
	     NIL)
	   (DontConvertFlg Date)
	   (T (GDATE Date))))))

(NC.FetchPropListDate
  (LAMBDA (Card DontConvertFlg)                              (* fgh: "13-Nov-85 19:48")

          (* * Fetch IDs prop list date from the cache and and convert to string format if necessary)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (LET ((Date (fetch (Card PropListDate) of Card)))
         (COND
	   ((ZEROP Date)
	     NIL)
	   (DontConvertFlg Date)
	   (T (GDATE Date))))))

(NC.FetchLinksDate
  (LAMBDA (Card DontConvertFlg)                              (* fgh: "13-Nov-85 19:48")

          (* * Fetch IDs links date from the cache and and convert to string format if necessary)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (LET ((Date (fetch (Card LinksDate) of Card)))
         (COND
	   ((ZEROP Date)
	     NIL)
	   (DontConvertFlg Date)
	   (T (GDATE Date))))))

(NC.FetchLinkIconAttachedBitMap
  (LAMBDA (Card ScaledHeightToMatch Scale)                   (* rht: " 7-Aug-86 18:00")

          (* * Return the default link icon attached bit map corresponding to Card)



          (* * fgh 2/5/86 First created.)



          (* * rht 5/10/86: Now takes special action if BitMapVal is a list. In that case, it should be an ordered prop list 
	  of heights and bitmaps. We take the one closest in height to HeightToMatch.)



          (* * rht 8/7/86: Now converts single bitmap to list of bitmaps of different heights if necessary.
	  Also now takes Scale argument.)


    (LET ((BitMapVal (fetch (Card LinkIconAttachedBitMap) of Card)))
         (if (BITMAPP BitMapVal)
	     then (replace (NoteCardType LinkIconAttachedBitMap) of (NC.CardTypeRecord
									    (NC.FetchType Card))
		       with (SETQ BitMapVal (NC.MakeTypeIconBitMapSet BitMapVal 
							  NC.DefaultLinkIconAttachedBitMapHeights))))
         (if (LISTP BitMapVal)
	     then (OR ScaledHeightToMatch (SETQ ScaledHeightToMatch 0))
		    (OR Scale (SETQ Scale 1))
		    (LET (BitMap)
		         (for X on BitMapVal by (CDDR X)
			    do (LET ((ScaledHeight (TIMES Scale (CAR X))))
				      (if (OR (NULL BitMap)
						  (LEQ ScaledHeight ScaledHeightToMatch))
					  then (SETQ BitMap (CADR X))
					elseif (GREATERP ScaledHeight ScaledHeightToMatch)
					  then (RETURN))))
		     BitMap)))))

(NC.FetchLinkDisplayMode
  (LAMBDA (Card)                                             (* fgh: " 5-Feb-86 13:40")

          (* * Fetch the default link display mode corresponding to Card)



          (* * fgh 2/5/86 First created.)


    (fetch (Card LinkDisplayMode) of Card)))

(NC.FetchDefaultWidth
  (LAMBDA (Card)                                             (* fgh: " 5-Feb-86 13:42")

          (* * Fetch the default width corresponding to Card)



          (* * fgh 2/5/86 First created.)


    (fetch (Card DefaultWidth) of Card)))

(NC.FetchDefaultHeight
  (LAMBDA (Card)                                             (* fgh: " 5-Feb-86 13:43")

          (* * Fetch default height corresponding to Card)



          (* * fgh 2/5/86 First created.)


    (fetch (Card DefaultHeight) of Card)))

(NC.FetchLinkAnchorModesSupported
  (LAMBDA (Card)                                             (* fgh: " 5-Feb-86 13:45")

          (* * Fetch the link anchor modes supported of Card)


    (fetch (Card LinkAnchorModesSupported) of Card)))
)
(DEFINEQ

(NC.SetTitleDate
  (LAMBDA (Card Date)                                        (* fgh: "13-Nov-85 19:49")

          (* * Set the title date in the cahce for card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card TitleDate) of Card with (NC.InsureIntegerDate Date))
    Date))

(NC.SetItemDate
  (LAMBDA (Card Date)                                        (* fgh: "13-Nov-85 19:49")

          (* * Set the item date in the cache for ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card ItemDate) of Card with (NC.InsureIntegerDate Date))
    Date))

(NC.SetPropListDate
  (LAMBDA (Card Date)                                        (* fgh: "13-Nov-85 19:49")

          (* * Set the prop list date in the cache for ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card PropListDate) of Card with (NC.InsureIntegerDate Date))
    Date))

(NC.SetLinksDate
  (LAMBDA (Card Date)                                        (* fgh: "13-Nov-85 19:50")

          (* * Set the links date in the cache for card ID)



          (* * rht 11/10/85: Updated to handle CardID scheme and new version of NC.FetchCardCache.)



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


    (replace (Card LinksDate) of Card with (NC.InsureIntegerDate Date))
    Date))
)
(PUTPROPS NCCARDS COPYRIGHT ("Xerox Corporation" 1984 1985 1986 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (24101 33584 (NC.CardOrCardHolderFromUID 24111 . 24884) (NC.CardP 24886 . 25086) (
NC.DeleteNoteCard 25088 . 27337) (NC.DeleteNoteCardInternal 27339 . 33386) (NC.SameCardP 33388 . 33582
)) (33634 54109 (NC.FetchStatus 33644 . 33870) (NC.SetNewCardFlg 33872 . 34330) (NC.FetchNewCardFlg 
34332 . 34781) (NC.ActivateCard 34783 . 35075) (NC.ActiveCardP 35077 . 35570) (NC.DeactivateCard 35572
 . 36890) (NC.FetchFromLinks 36892 . 37283) (NC.FetchGlobalLinks 37285 . 37579) (NC.FetchLinksDirtyFlg
 37581 . 37988) (NC.FetchPropList 37990 . 38382) (NC.FetchRegion 38384 . 38768) (NC.FetchSavedRegion 
38770 . 39170) (NC.FetchRegionViewed 39172 . 39554) (NC.FetchScale 39556 . 39893) (NC.FetchSlotNum 
39895 . 40421) (NC.FetchSubstance 40423 . 40812) (NC.FetchTitle 40814 . 41195) (NC.FetchToLinks 41197
 . 41586) (NC.FetchType 41588 . 41976) (NC.FetchWindow 41978 . 42781) (NC.IDP 42783 . 43077) (
NC.MarkCardDirty 43079 . 43690) (NC.CardDirtyP 43692 . 44141) (NC.SetFromLinks 44143 . 44544) (
NC.SetGlobalLinks 44546 . 44958) (NC.SetLinksDirtyFlg 44960 . 45390) (NC.SetPropList 45392 . 45792) (
NC.SetRegion 45794 . 46185) (NC.SetSavedRegion 46187 . 46737) (NC.SetRegionViewed 46739 . 47189) (
NC.SetScale 47191 . 47610) (NC.SetSubstance 47612 . 48041) (NC.SetTitle 48043 . 48436) (NC.SetToLinks 
48438 . 48838) (NC.SetType 48840 . 49124) (NC.FetchTitleDirtyFlg 49126 . 49526) (NC.SetTitleDirtyFlg 
49528 . 49943) (NC.FetchPropListDirtyFlg 49945 . 50360) (NC.SetPropListDirtyFlg 50362 . 50783) (
NC.SetSubstanceDirtyFlg 50785 . 51208) (NC.FetchSubstanceDirtyFlg 51210 . 51621) (NC.TurnOffDirtyFlgs 
51623 . 52067) (NC.FetchUserDataProp 52069 . 52382) (NC.SetUserDataProp 52384 . 52815) (
NC.SetUserDataPropList 52817 . 53066) (NC.MakeTypeIconBitMapSet 53068 . 53540) (NC.MakeNewCardWindow 
53542 . 54107)) (54171 56285 (NC.ObtainEditPermission 54181 . 56010) (NC.CardPartBusy 56012 . 56283)) 
(57872 58575 (NC.ReadOnlyCardP 57882 . 58177) (NC.CardSomehowDirtyP 58179 . 58573)) (59826 70584 (
NC.RetrieveFromLinks 59836 . 60824) (NC.RetrieveLinkLabels 60826 . 61729) (NC.StoreLinkLabels 61731 . 
62461) (NC.RetrievePropList 62463 . 62954) (NC.RetrieveTitle 62956 . 63608) (NC.RetrieveToLinks 63610
 . 64521) (NC.RetrieveGlobalLinks 64523 . 65388) (NC.RetrieveType 65390 . 65898) (
NC.RetrieveTypeAndTitle 65900 . 67066) (NC.LinksCachedP 67068 . 67452) (NC.ShowInfo 67454 . 70582)) (
70629 133645 (NC.AddParents 70639 . 73496) (NC.SeverExternalLinks 73498 . 79798) (NC.AssignTitle 79800
 . 83778) (NC.DeleteNoteCards 83780 . 90097) (NC.EditNoteCard 90099 . 93044) (NC.MakeNoteCard 93046 . 
96422) (NC.QuitCard 96424 . 102234) (NC.CheckFiling 102236 . 104341) (NC.CheckTitle 104343 . 105872) (
NC.ForceFilingForCardTypeP 105874 . 106222) (NC.InsureProperFiling 106224 . 107187) (
NC.QuitWithoutSaving 107189 . 113794) (NC.UnfileNoteCard 113796 . 116051) (NC.UpdateUpdateList 116053
 . 116947) (NC.CollectReferences 116949 . 118285) (NC.CardSaveFn 118287 . 125222) (
NC.DetermineDisplayRegion 125224 . 128777) (NC.AbortCard 128779 . 129319) (NC.CardNeedsFilingP 129321
 . 130700) (NC.TopLevelCardP 130702 . 131039) (NC.MakeDummyRegion 131041 . 131520) (NC.ValidCardP 
131522 . 132017) (NC.TitleBarButtonEventFn 132019 . 133038) (NC.InstallTitleBarMiddleMenu 133040 . 
133643)) (133802 167893 (NC.AddPropToPropList 133812 . 137581) (NC.CloseAllPropListEditors 137583 . 
138368) (NC.ClosePropListEditor 138370 . 141829) (NC.DelPropFromList 141831 . 143718) (
NC.EditPropButtonFN 143720 . 144097) (NC.EditProperties 144099 . 145861) (NC.EditPropList 145863 . 
151925) (NC.ExtractPropList 151927 . 155284) (NC.OpenPropListEditor 155286 . 159747) (
NC.ProcessEditedPropList 159749 . 161190) (NC.PropListEditorOpenP 161192 . 162004) (NC.SelectProperty 
162006 . 162982) (NC.ShowLinks 162984 . 165517) (NC.StringIsListP 165519 . 166632) (NC.PutProp 166634
 . 167273) (NC.GetProp 167275 . 167621) (NC.RemProp 167623 . 167891)) (167924 170344 (
NC.FetchBeingDeletedFlg 167934 . 168348) (NC.SetBeingDeletedFlg 168350 . 168775) (
NC.RemoveDELETEMEImageObjsFromCard 168777 . 169897) (NC.InsureIntegerDate 169899 . 170342)) (170383 
172961 (NC.PlaceMarkerCopyFn 170393 . 170593) (NC.PlaceMarkerDisplayFn 170595 . 171200) (
NC.PlaceMarkerGetFn 171202 . 171371) (NC.PlaceMarkerImageBoxFn 171373 . 172151) (NC.PlaceMarkerPutFn 
172153 . 172404) (NC.MakePlaceMarker 172406 . 172959)) (173004 177988 (NC.FetchTitleDate 173014 . 
173573) (NC.FetchItemDate 173575 . 174131) (NC.FetchPropListDate 174133 . 174702) (NC.FetchLinksDate 
174704 . 175263) (NC.FetchLinkIconAttachedBitMap 175265 . 176846) (NC.FetchLinkDisplayMode 176848 . 
177151) (NC.FetchDefaultWidth 177153 . 177438) (NC.FetchDefaultHeight 177440 . 177724) (
NC.FetchLinkAnchorModesSupported 177726 . 177986)) (177989 179812 (NC.SetTitleDate 177999 . 178451) (
NC.SetItemDate 178453 . 178897) (NC.SetPropListDate 178899 . 179356) (NC.SetLinksDate 179358 . 179810)
))))
STOP