(FILECREATED " 3-Mar-86 18:44:11" {QV}<NOTECARDS>1.3K>RHTPATCH032.;7 18102  

      changes to:  (VARS RHTPATCH032COMS)

      previous date: " 2-Mar-86 16:33:04" {QV}<NOTECARDS>1.3K>RHTPATCH032.;5)


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

(PRETTYCOMPRINT RHTPATCH032COMS)

(RPAQQ RHTPATCH032COMS ((* * New function for NCDATABASE. Put near NC.GetSpecialCards.)
			  (FNS NC.FetchSpecialCards)
			  (* * Change to NCCONVERTVERSION2TO3)
			  (FNS NC.ReadVersion2MainCardData NC.ConvertVersion2BrowserCard)
			  (* * Change to NCDATABASE)
			  (FNS NC.DisassembleUID)
			  (* * Change to NCCARDS)
			  (FNS NC.StoreLinkLabels)
			  (* * Change to NCBROWSERCARD)
			  (FNS NC.GetBrowserSubstance NC.BringUpBrowserCard 
			       NC.BrowserFixGraphEditMenuFn)
			  (* * Change to NCGRAPHCARD)
			  (FNS NC.GetGraphSubstance)
			  (* * Change to NCREPAIR)
			  (FNS NC.UndeletableCardP)))
(* * New function for NCDATABASE. Put near NC.GetSpecialCards.)

(DEFINEQ

(NC.FetchSpecialCards
  (LAMBDA (NoteFile)                                         (* rht: " 2-Mar-86 15:07")

          (* * Return list of special cards.)


    (LIST (fetch (NoteFile TableOfContentsCard) of NoteFile)
	    (fetch (NoteFile OrphansCard) of NoteFile)
	    (fetch (NoteFile ToBeFiledCard) of NoteFile)
	    (fetch (NoteFile LinkLabelsCard) of NoteFile)
	    (fetch (NoteFile RegistryCard) of NoteFile))))
)
(* * Change to NCCONVERTVERSION2TO3)

(DEFINEQ

(NC.ReadVersion2MainCardData
  (LAMBDA (Stream ID Card Version2HashArray FromNoteFile ToNoteFile)
                                                             (* rht: "28-Feb-86 17:19")

          (* * Stream should be positioned at the main data card part of ID. Get the main data and fill in for Card.)



          (* * fgh 12/17/85 changed Apply of CollectReferencesFn to be done only if there is a CollectReferencesFn for the 
	  card type)


    (LET (CardType Region StartPtr EndPtr Length TEditBasedFlg StartFormatPtr CollectReferencesFn)
         (NC.SetItemDate Card (NC.ReadVersion2CardPartHeader Stream ID NC.Version2ItemIdentifier))

          (* * Read card type and region)


         (NC.SetType Card (SETQ CardType (READ Stream)))
         (SETQ TEditBasedFlg (NC.TEditBasedP CardType))
         (READC Stream)
         (NC.SetRegion Card (NC.ReadVersion2Region Stream))

          (* * Read the substance pointers, compute the length, then call the substance get fn)


         (SETQ StartPtr (NC.ReadPtr Stream 3))
         (SETQ EndPtr (NC.ReadPtr Stream 3))
         (SETQ Length (DIFFERENCE EndPtr StartPtr))

          (* * A horrible kludge: Change the infamous file absolute pointer in the text stream to be file relative for 
	  duration of the GetSubstance call.)


         (if TEditBasedFlg
	     then (SETFILEPTR Stream (DIFFERENCE EndPtr 8))
		    (SETQ StartFormatPtr (NC.ReadPtr Stream 4))
		    (SETFILEPTR Stream (DIFFERENCE EndPtr 8))
		    (NC.WritePtr Stream (DIFFERENCE StartFormatPtr StartPtr)
				 4)
		    (SETFILEPTR Stream StartPtr))
         (NC.SetSubstance Card (NC.ApplyFn GetFn Card Length Stream -1))

          (* * Now put back the infamous file absolute pointer.)


         (if TEditBasedFlg
	     then (SETFILEPTR Stream (DIFFERENCE EndPtr 8))
		    (NC.WritePtr Stream StartFormatPtr 4)
		    (SETFILEPTR Stream EndPtr))

          (* * Now convert each link in the embedded link icons in the substance.)


         (if (fetch (Card CollectLinksFn) of Card)
	     then (for LinkIcon in (CAR (NC.ApplyFn CollectLinksFn Card NIL T))
		       eachtime (BLOCK) do (NC.ConvertVersion2LinkIcon LinkIcon Card 
									       Version2HashArray))))))

(NC.ConvertVersion2BrowserCard
  (LAMBDA (Card Version2HashArray)                           (* rht: " 2-Mar-86 16:24")

          (* * Fix the browser roots and graphnode IDs to be version 3 -
	  this is just modified version of the code in NCMERGEFILES that processes browser cards.)



          (* * Get various stuff off browser's prop list.)


    (NC.SetBrowserLinkLabels Card (CAR (NC.GetProp Card (QUOTE BrowserLinkLabels))))
    (NC.SetBrowserLinksLegend Card (CAR (NC.GetProp Card (QUOTE BrowserLinksLegend))))
    (NC.SetBrowserDepth Card (NC.GetProp Card (QUOTE BrowserDepth)))
    (NC.SetBrowserFormat Card (CAR (NC.GetProp Card (QUOTE BrowserFormat))))
    (NC.SetSpecialBrowserSpecs Card (CAR (NC.GetProp Card (QUOTE SpecialBrowserSpecs))))

          (* * Fix up browser roots)


    (NC.SetBrowserRoots Card (for BrowserRootID in (CAR (NC.GetProp Card (QUOTE 
										     BrowserRoots)))
				  collect (NC.Version3CardFromVersion2ID BrowserRootID 
									     Version2HashArray)))
                                                             (* Throw away old browser roots.)
    (NC.RemProp Card (QUOTE BrowserRoots))

          (* * Fix up graph nodeids)


    (for GraphNode in (fetch (GRAPH GRAPHNODES) of (NC.FetchSubstance Card))
       do (replace (GRAPHNODE NODEID) of GraphNode with (NC.ConvertVersion2GraphNodeID
								  (fetch (GRAPHNODE NODEID)
								     of GraphNode)
								  Card Version2HashArray))
	    (replace (GRAPHNODE TONODES) of GraphNode
	       with (for NodeID in (fetch (GRAPHNODE TONODES) of GraphNode)
			 collect (COND
				     ((EQ (CAR NodeID)
					    LINKPARAMS)
				       (RPLACA (CDR NodeID)
						 (NC.ConvertVersion2GraphNodeID (CADR NodeID)
										  Card 
										Version2HashArray))
				       (AND (LISTGET NodeID (QUOTE NODEID))
					      (LISTPUT NodeID (QUOTE NODEID)
							 (NC.ConvertVersion2GraphNodeID
							   (LISTGET NodeID (QUOTE NODEID))
							   Card Version2HashArray)))
				       (AND (LISTGET NodeID (QUOTE DESTNODEID))
					      (LISTPUT NodeID (QUOTE DESTNODEID)
							 (NC.ConvertVersion2GraphNodeID
							   (LISTGET NodeID (QUOTE DESTNODEID))
							   Card Version2HashArray)))
				       NodeID)
				     (T (NC.ConvertVersion2GraphNodeID NodeID Card 
									 Version2HashArray)))))
	    (replace (GRAPHNODE FROMNODES) of GraphNode
	       with (for NodeID in (fetch (GRAPHNODE FROMNODES) of GraphNode)
			 collect (COND
				     ((EQ (CAR NodeID)
					    LINKPARAMS)
				       (RPLACA (CDR NodeID)
						 (NC.ConvertVersion2GraphNodeID (CADR NodeID)
										  Card 
										Version2HashArray)))
				     (T (NC.ConvertVersion2GraphNodeID NodeID Card 
									 Version2HashArray))))))))
)
(* * Change to NCDATABASE)

(DEFINEQ

(NC.DisassembleUID
  (LAMBDA (UID Stream)                                       (* rht: " 2-Mar-86 16:04")

          (* * This is called when PRINT, PRIN1, etc. try to print instance of UID datatype. Returns cons of readmacro 
	  character and list to be written down which when eval'ed at read time will reassemble the UID.)



          (* * rht 1/31/86: Now checks Stream arg and only disassembles if going to a notecards stream.)



          (* * rht 2/1/86: It's too slow to check whether Stream is for a notefile. Now just check whether there's a non-nil 
	  and non-T Stream.)



          (* * rht 2/4/86: Also be sure Stream is not a window stream.)


    (if (AND Stream (NEQ Stream (QUOTE T))
		 (NOT (IMAGESTREAMP Stream)))
	then (CONS (QUOTE %|.)
		       (LIST (FUNCTION NC.ReassembleUID)
			       (ffetch (UID UID0) of UID)
			       (ffetch (UID UID1) of UID)
			       (ffetch (UID UID2) of UID)
			       (ffetch (UID UID3) of UID)
			       (ffetch (UID UID4) of UID)
			       (ffetch (UID UID5) of UID)
			       (ffetch (UID UID6) of UID)))
      else NIL)))
)
(* * Change to NCCARDS)

(DEFINEQ

(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))))
)
(* * Change to NCBROWSERCARD)

(DEFINEQ

(NC.GetBrowserSubstance
  (LAMBDA (Card Length Stream VersionNum)                    (* rht: "28-Feb-86 17:18")

          (* * Go get all the browser-specific info and then get the graph that is the browser's substance.)



          (* * rht 2/14/86: Added call to NC.ApplySupersFn)



          (* * rht 2/28/86: Added special handling for old version -1 style. I.e. pre 1.3k.)


    (if (NEQ VersionNum -1)
	then (NC.SetBrowserRootsInfo Card (NC.ReadBrowserRootsInfo Stream))
	       (NC.SetBrowserLinkLabels Card (NC.ReadBrowserLinkLabels Stream))
	       (NC.SetBrowserFormat Card (NC.ReadBrowserFormat Stream))
	       (NC.SetSpecialBrowserSpecs Card (NC.ReadSpecialBrowserSpecs Stream))
	       (NC.SetBrowserDepth Card (NC.ReadBrowserDepth Stream))
	       (NC.SetBrowserLinksLegend Card (NC.ReadBrowserLinksLegend Stream))
	       (NC.SetBrowserSavedLinkingInfo Card (NC.ReadBrowserSavedLinkingInfo Stream)))
    (NC.ApplySupersFn GetFn Card Length Stream VersionNum)))

(NC.BringUpBrowserCard
  (LAMBDA (Card Substance Region/Position)                   (* rht: " 2-Mar-86 15:32")

          (* * Given a browser Substance, open a browser window and set it up to be a NoteCard with ID.)



          (* * rht 11/17/84: Now returns window.)



          (* * rht 9/11/85: Now checks for changed link icon display global params.)



          (* * rht 11/17/85: Now handles new card and Notefile objects.)



          (* * rht 2/1/86: Now restores any saved UID user data info stashed on card's prop list.)



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



          (* * rht 2/14/86: Now rebuilds browser hash array.)



          (* * rht 2/28/86: Added WINDOWPROP for SCROLLFN and RESHAPEFN.)



          (* * rht 3/2/86: Took out call to NC.FetchBrowserHashArray.)


    (LET ((GraphNodes (fetch (GRAPH GRAPHNODES) of Substance))
	  Window OldUIDToNewUIDHashArray BrowserSavedLinkingInfo)

          (* * Restore any saved UID user data info stashed on card UID's prop list.)


         (if (SETQ BrowserSavedLinkingInfo (NC.FetchBrowserSavedLinkingInfo Card))
	     then (SETQ OldUIDToNewUIDHashArray (HASHARRAY 100 NIL (FUNCTION NC.MakeHashKey)
								 (FUNCTION NC.SameUIDP)))
		    (for BrowserSavedLinkingInfoForNode in BrowserSavedLinkingInfo
		       eachtime (BLOCK) do (for SavedLinkingInfo on (CDR 
								   BrowserSavedLinkingInfoForNode)
						    by (CDDR SavedLinkingInfo)
						    bind (SourceUID ←(
								   NC.NewBrowserNodeUIDFromOldUID
									(CAR 
								   BrowserSavedLinkingInfoForNode)
									GraphNodes 
									OldUIDToNewUIDHashArray))
						    eachtime (BLOCK)
						    do (NC.UIDPutProp SourceUID
									  (
								   NC.NewBrowserNodeUIDFromOldUID
									    (CAR SavedLinkingInfo)
									    GraphNodes 
									  OldUIDToNewUIDHashArray)
									  (CADR SavedLinkingInfo))))
	       )
         (NC.SetBrowserSavedLinkingInfo Card NIL)

          (* * For each graph node corresponding to a notecard, hang the card object off the node id's prop list.)


         (for GraphNode in GraphNodes bind LinkIcon DestCard eachtime (BLOCK)
	    when (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
							       of GraphNode)))
	    do (NC.UIDPutProp (NC.CoerceToGraphNodeID GraphNode)
				  (QUOTE CardObject)
				  (SETQ DestCard (fetch (Link DestinationCard)
						      of (NC.FetchLinkFromLinkIcon LinkIcon)))))

          (* * Make a new browser hash array with the new graph node UIDs.)


         (NC.SetUserDataProp Card (QUOTE BrowserHashArray)
			       NIL)
         (NC.GetBrowserHashArray Card Substance)

          (* * For each graph node, fix the NODEID and DESTNODEID fields of each of its TONODES LinkParameters.)


         (for GraphNode in GraphNodes eachtime (BLOCK)
	    do (for ToNode in (fetch (GRAPHNODE TONODES) of GraphNode)
		    bind (ThisNodeID ←(NC.CoerceToGraphNodeID GraphNode)) eachtime (BLOCK)
		    when (EQ (CAR ToNode)
				 LINKPARAMS)
		    do (LISTPUT ToNode (QUOTE NODEID)
				    ThisNodeID)
			 (LISTPUT ToNode (QUOTE DESTNODEID)
				    (NC.CoerceToGraphNodeID (CADR ToNode)))))

          (* * Bring up card and mess with its window.)


         (SETQ Window (NC.ApplySupersFn EditFn Card Substance Region/Position))
         (NC.SetupTitleBarMenu Window Card (QUOTE Browser))
         (NC.MakeLinksLegendMenu Window (NC.FetchBrowserLinksLegend Card))
                                                             (* Disable the old-style right button grapher editor 
							     menu.)
         (WINDOWPROP Window (QUOTE RIGHTBUTTONFN)
		       (FUNCTION NC.BrowserRightButtonFn))
         (WINDOWADDPROP Window (QUOTE SHRINKFN)
			  (FUNCTION NC.GraphCardShrinkFn))
         (WINDOWADDPROP Window (QUOTE REPAINTFN)
			  (FUNCTION NC.BrowserRepaintFn)
			  T)
         (WINDOWPROP Window (QUOTE SCROLLFN)
		       (FUNCTION NC.BrowserScrollFn))
         (WINDOWPROP Window (QUOTE RESHAPEFN)
		       (FUNCTION NC.BrowserReshapeFn))

          (* * I have to hang notecard's Card on window now in case REDISPLAYW runs and tries to get Card from window.)


         (WINDOWPROP Window (QUOTE NoteCardObject)
		       Card)                                 (* Check if link icon display global params have 
							     changed since last time card was up.
							     If so, fix graph nodes and redisplay.)
         (if (NC.GraphLinkIconUpdateCheck Card Window Substance T)
	     then (REDISPLAYW Window))
     Window)))

(NC.BrowserFixGraphEditMenuFn
  (LAMBDA (Window)                                           (* rht: " 3-Mar-86 18:42")

          (* * Attach the Graph edit menu to the side of the browser window. Put it below the links legend.)



          (* * rht 9/20/85: Now uses ADDMENU offscreen so it doesn't flash in lower left corner before coming up.)



          (* * rht 3/3/86: Now does some "random" WINDOWPROPS to make reshaping browser not screw up the attached menu.)


    (LET (GraphEditMenu GraphEditMenuWin)
         (SETQ GraphEditMenu (create MENU
					 ITEMS ← NC.GraphEditMenuItems
					 TITLE ← "Editor Menu"
					 WHENSELECTEDFN ←(FUNCTION NC.GraphEditMenuWhenSelectedFn)))
         (PUTMENUPROP GraphEditMenu (QUOTE MAINWINDOW)
			Window)
         (ATTACHWINDOW (SETQ GraphEditMenuWin (ADDMENU GraphEditMenu NIL NC.OffScreenPosition))
			 Window
			 (QUOTE RIGHT)
			 (QUOTE BOTTOM)
			 (QUOTE LOCALCLOSE))               (* These windowprops are so that menu wins reshape 
							     properly. They're stolen from file browser menu 
							     windowprops.)
         (WINDOWPROP GraphEditMenuWin (QUOTE MINSIZE)
		       (QUOTE MENUWMINSIZEFN))
         (WINDOWPROP GraphEditMenuWin (QUOTE MAXSIZE)
		       (QUOTE MENUWMINSIZEFN))
         (WINDOWPROP GraphEditMenuWin (QUOTE RESHAPEFN)
		       (QUOTE (MENUWRESHAPEFN)))
         (WINDOWPROP GraphEditMenuWin (QUOTE GRAPHEDITMENUFLG)
		       T))))
)
(* * Change to NCGRAPHCARD)

(DEFINEQ

(NC.GetGraphSubstance
  (LAMBDA (Card Length Stream VersionNum)                    (* rht: "28-Feb-86 17:17")

          (* * Read the Graph)



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



          (* * fgh 11/20/85 NoteCards now passes start and end ptrs down.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)



          (* * rht 1/23/86: Now takes Stream as arg instead of computing from Card.)



          (* * rht 2/7/86: Now uses READGRAPH instead of HREAD)



          (* * rht 2/28/86: Added special handling for old version -1 style. I.e. pre 1.3k.)


    (if (EQ VersionNum -1)
	then (HREAD Stream)
      else (READGRAPH Stream))))
)
(* * Change to NCREPAIR)

(DEFINEQ

(NC.UndeletableCardP
  (LAMBDA (Card)                                             (* rht: " 2-Mar-86 15:09")

          (* * Returns non-nil if this card is either a top level card or the link labels card.)



          (* * rht 3/2/86: Changed to use all special cards not just top level boxes.)


    (for SpecialCard in (NC.FetchSpecialCards (fetch (Card NoteFile) of Card))
       thereis (NC.SameCardP Card SpecialCard))))
)
(PUTPROPS RHTPATCH032 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (992 1480 (NC.FetchSpecialCards 1002 . 1478)) (1524 7029 (NC.ReadVersion2MainCardData 
1534 . 3936) (NC.ConvertVersion2BrowserCard 3938 . 7027)) (7063 8294 (NC.DisassembleUID 7073 . 8292)) 
(8325 9067 (NC.StoreLinkLabels 8335 . 9065)) (9104 16701 (NC.GetBrowserSubstance 9114 . 10181) (
NC.BringUpBrowserCard 10183 . 15158) (NC.BrowserFixGraphEditMenuFn 15160 . 16699)) (16736 17505 (
NC.GetGraphSubstance 16746 . 17503)) (17537 18020 (NC.UndeletableCardP 17547 . 18018)))))
STOP