(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP")
(FILECREATED "12-May-88 00:45:10" {QV}<NOTECARDS>1.3LNEXT>RHTPATCH318.;6 24350  

      changes to%:  (VARS RHTPATCH318COMS)
                    (FNS NC.BringUpBrowserCard NC.BrowserCreateLink NC.ReadBrowserSavedLinkingInfo 
                         NC.ReadBrowserSavedLinkingInfoForNode NCP.LocalGlobalLink NC.ReassembleUID 
                         NC.ReadUID NC.LookUpUIDInHashArray NC.ReadBrowserRootsInfo)

      previous date%: "11-May-88 21:34:11" {QV}<NOTECARDS>1.3LNEXT>RHTPATCH318.;1)


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

(PRETTYCOMPRINT RHTPATCH318COMS)

(RPAQQ RHTPATCH318COMS ((DECLARE%: DONTCOPY (PROPS (RHTPATCH318 MAKEFILE-ENVIRONMENT)
                                                   (RHTPATCH318 FILETYPE)))
                        [DECLARE%: FIRST (P (NC.LoadFileFromDirectories 'NCBROWSERCARD]
                        
          
          (* ;; "Changed UID handling slightly so that when UIDs are read from under browser card GetFn, lookups in a hash array are performed to preclude having to worry about non-eq UID objects.  Saves time in bringing up browser cards.  Also fixed a browser bug whereby trying to create a link from filebox to child printed message saying %"foo already child of bar%" but then created the edge in the browser anyway!")

                        
          
          (* ;; "New stuff for NCDATABASE")

                        (GLOBALVARS NC.GlobalUIDHashArray)
                        (FNS NC.LookUpUIDInHashArray)
                        
          
          (* ;; "Changes to NCDATABASE")

                        (FNS NC.ReassembleUID NC.ReadUID)
                        
          
          (* ;; "Changes to NCBROWSERCARD")

                        (FNS NC.ReadBrowserSavedLinkingInfoForNode NC.BringUpBrowserCard 
                             NC.BrowserCreateLink)
                        
          
          (* ;; "Changes to NCPROGINT")

                        (FNS NCP.LocalGlobalLink)))
(DECLARE%: DONTCOPY 

(PUTPROPS RHTPATCH318 MAKEFILE-ENVIRONMENT (:PACKAGE "INTERLISP" :READTABLE "INTERLISP"))

(PUTPROPS RHTPATCH318 FILETYPE :TCOMPL)
)
(DECLARE%: FIRST 
(NC.LoadFileFromDirectories 'NCBROWSERCARD)
)



(* ;; 
"Changed UID handling slightly so that when UIDs are read from under browser card GetFn, lookups in a hash array are performed to preclude having to worry about non-eq UID objects.  Saves time in bringing up browser cards.  Also fixed a browser bug whereby trying to create a link from filebox to child printed message saying %"foo already child of bar%" but then created the edge in the browser anyway!"
)




(* ;; "New stuff for NCDATABASE")

(DECLARE%: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.GlobalUIDHashArray)
)
(DEFINEQ

(NC.LookUpUIDInHashArray
  [LAMBDA (UID)                                              (* ; "Edited 11-May-88 21:04 by Trigg")
          
          (* ;; "Looks up UID in a global hash array and returns existing object if there is one, else stashes this one in array.")

    (DECLARE (GLOBALVARS NC.GlobalUIDHashArray))
    (if (OR (NOT (BOUNDP 'NC.GlobalUIDHashArray))
            (NOT (HASHARRAYP NC.GlobalUIDHashArray)))
        then (SETQ NC.GlobalUIDHashArray (NC.CreateUIDHashArray 1000)))
    (if (GETHASH UID NC.GlobalUIDHashArray)
      else (PUTHASH UID UID NC.GlobalUIDHashArray)
           UID])
)



(* ;; "Changes to NCDATABASE")

(DEFINEQ

(NC.ReassembleUID
  [LAMBDA (UID0 UID1 UID2 UID3 UID4 UID5 UID6)               (* ; "Edited 11-May-88 21:04 by Trigg")

(* ;;; "Called when a UID that was written down by PRINT after disassembling so can be reassembled into a UID.")
          
          (* ;; "rht 5/11/88: Now calls NC.LookUpUIDInHashArray so can return prior UID object if we've seen it before.")

    (NC.LookUpUIDInHashArray (create UID
                                    UID0 ← UID0
                                    UID1 ← UID1
                                    UID2 ← UID2
                                    UID3 ← UID3
                                    UID4 ← UID4
                                    UID5 ← UID5
                                    UID6 ← UID6])

(NC.ReadUID
  [LAMBDA (NoteFileOrStream LookUpInHashArrayFlg)            (* ; "Edited 11-May-88 21:08 by Trigg")

(* ;;; "Get a UID off of the file.  Since UIDs are BIGNUMs less than {EXPT 2 112} just read their 112 bits from the file.")
          
          (* ;; "rht 5/11/88: Takes new arg LookUpInHashArrayFlg.  If non-nil, then call NC.LookUpUIDInHashArray to return existing equivalent UID object if there is one.")

    (LET ((Stream (NC.CoerceToNoteFileStream NoteFileOrStream))
          UID)
         (SETQ UID (create UID
                          UID0 ← (BIN16 Stream)
                          UID1 ← (BIN16 Stream)
                          UID2 ← (BIN16 Stream)
                          UID3 ← (BIN16 Stream)
                          UID4 ← (BIN16 Stream)
                          UID5 ← (BIN16 Stream)
                          UID6 ← (BIN16 Stream)))
         (PROG1 (if LookUpInHashArrayFlg
                    then (NC.LookUpUIDInHashArray UID)
                  else UID)

(* ;;; "skip past CR following UID")

                (BIN Stream])
)



(* ;; "Changes to NCBROWSERCARD")

(DEFINEQ

(NC.ReadBrowserSavedLinkingInfoForNode
  [LAMBDA (Stream)                                           (* ; "Edited 11-May-88 22:14 by Trigg")

(* ;;; "Read list of info on multiple links for a particular node.  In form of a source UID cons'ed to a prop list of destination UIDs and link dashing info.")
          
          (* ;; "rht 11/1/86: Now uses our readtable when reading.")
          
          (* ;; "rht 5/11/88: Now passes non-nil second arg to NC.ReadUID so as to reuse old equivalent UID objects if any.")

    (DECLARE (GLOBALVARS NC.OrigReadTable))
    (LET (CharRead SourceUID)
         (if (NEQ (SETQ CharRead (CHARACTER (BIN Stream)))
                  '%()
             then (NC.ReportError "NC.ReadBrowserSavedLinkingInfoForNode" (CONCAT 
                                                           "Expected to read left paranthesis. Saw: " 
                                                                                 CharRead)))
         (PROG1 [CONS (NC.ReadUID Stream T)
                      (while (NEQ (CHARACTER (\PEEKBIN Stream))
                                  '%)) eachtime (BLOCK) join (PROG1 (LIST (NC.ReadUID Stream T)
                                                                          (READ Stream 
                                                                                NC.OrigReadTable))
                                                             (* ; "Skip CR")

                                                                    (BIN Stream]
                                                             (* ; "Skip RightParen")

                (BIN Stream])

(NC.BringUpBrowserCard
  [LAMBDA (Card Substance Region/Position)                   (* ; "Edited 11-May-88 23:51 by Trigg")
          
          (* ;; 
          "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.")
          
          (* ;; 
       "rht 4/5/86: Now only replaces graphnodes' TONODES' NODEID and DESTNODEID if they're non-nil.")
          
          (* ;; "rht 5/5/86: Took out call to NC.SetupTitleBarMenu.")
          
          (* ;; "rht&pmi 2/6/87: Moved call to NC.GraphLinkIconUpdateCheck in front of call to GraphCard's EditFn so as to remove 'double display' problem.")
          
          (* ;; "rht 1/16/88: Had to replace the ApplySuperTypeFn call with grungy apply* to prevent infinite recursive calls.")
          
          (* ;; "rht 5/11/88: Sped up things significantly by ripping out the conversion of old UIDs to new UID objects.  This enabled by changes to reading of UIDs so that all versions of same UID read in will be eq.")

    (DECLARE (GLOBALVARS NC.GlobalUIDHashArray))
    (LET ((GraphNodes (fetch (GRAPH GRAPHNODES) of Substance))
          Window)
          
          (* ;; "Restore any saved UID user data info stashed on card UID's prop list.")

         [for BrowserSavedLinkingInfoForNode in (NC.FetchBrowserSavedLinkingInfo Card)
            do (LET ((SourceUID (CAR BrowserSavedLinkingInfoForNode)))
                    (for SavedLinkingInfo on (CDR BrowserSavedLinkingInfoForNode)
                       by (CDDR SavedLinkingInfo) eachtime (BLOCK) do (NC.GraphNodeIDPutProp
                                                                       SourceUID
                                                                       (CAR SavedLinkingInfo)
                                                                       (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.GraphNodeIDPutProp (NC.CoerceToGraphNodeID GraphNode)
                      '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 'BrowserHashArray NIL)
         (NC.GetBrowserHashArray Card Substance)
          
          (* ;; "For each graph node, fix the NODEID and DESTNODEID fields of each of its TONODES LinkParameters.  While we're at it, smash the entry in the global uid hash array for each node's uid.")

         [for GraphNode in GraphNodes eachtime (BLOCK)
            do (LET ((ThisNodeID (NC.CoerceToGraphNodeID GraphNode)))
                    (if (type? UID ThisNodeID)
                        then (PUTHASH ThisNodeID NIL NC.GlobalUIDHashArray))
                    (for ToNode in (fetch (GRAPHNODE TONODES) of GraphNode) eachtime (BLOCK)
                       when (EQ (CAR ToNode)
                                LINKPARAMS) do (AND (LISTGET ToNode 'NODEID)
                                                    (LISTPUT ToNode 'NODEID ThisNodeID))
                                               (AND (LISTGET ToNode 'DESTNODEID)
                                                    (LISTPUT ToNode 'DESTNODEID (
                                                                               NC.CoerceToGraphNodeID
                                                                                 (CADR ToNode]
          
          (* ;; "Bring up card and mess with its window.")

         (NC.GraphLinkIconUpdateCheck Card NIL Substance T)
         (SETQ Window (APPLY* (NCP.CardTypeFn 'Graph 'EditFn)
                             Card Substance Region/Position))
          
          (* ;; "I have to hang notecard's Card on window now in case REDISPLAYW runs and tries to get Card from window.")

         (WINDOWPROP Window 'NoteCardObject Card)
         (NC.MakeLinksLegendMenu Window (NC.FetchBrowserLinksLegend Card))
                                                             (* ; 
                                            "Disable the old-style right button grapher editor menu.")

         (WINDOWPROP Window 'RIGHTBUTTONFN (FUNCTION NC.BrowserRightButtonFn))
         (WINDOWADDPROP Window 'SHRINKFN (FUNCTION NC.GraphCardShrinkFn))
         (WINDOWADDPROP Window 'REPAINTFN (FUNCTION NC.BrowserRepaintFn)
                T)
         (WINDOWPROP Window 'SCROLLFN (FUNCTION NC.BrowserScrollFn))
         (WINDOWPROP Window 'RESHAPEFN (FUNCTION NC.BrowserReshapeFn))
          
          (* ;; "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.BrowserCreateLink
  [LAMBDA (FromNode ToNode Graph Window GlobalLinkFlg LinkType)
                                                             (* ; "Edited 11-May-88 23:03 by Trigg")
          
          (* ;; "Called by grapher when user creates a new link.")
          
          (* ;; "rht 9/20/85: Added GlobalLinkFlg arg to force the link created to be global.  Currently, it's global anyway if from node is a sketch card, for example.")
          
          (* ;; "rht 11/17/85: Updated to hancdle new card and notefile formats.")
          
          (* ;; "rht 1/14/88: Now takes extra LinkType argument.")
          
          (* ;; "rht 5/11/88: Now checks whether link was successfully created before returning it.")

    (DECLARE (GLOBALVARS PROMPTWINDOW NC.FiledCardLinkLabel NC.SubBoxLinkLabel))
    (LET ((GraphCard (NC.CoerceToCard Window))
          SourceCard DestinationCard Link)
         (if (EQ FromNode ToNode)
             then (NC.PrintMsg NIL T "Can't create a link from node to itself.")
                  (FLASHW PROMPTWINDOW)
                  NIL
           else (NC.MarkCardDirty GraphCard)
                (SETQ SourceCard (NC.CardFromBrowserNodeID (NC.CoerceToGraphNodeID FromNode)))
                (SETQ DestinationCard (NC.CardFromBrowserNodeID (NC.CoerceToGraphNodeID ToNode)))
                [OR LinkType (SETQ LinkType (COND
                                               ((AND (NOT GlobalLinkFlg)
                                                     (NC.FileBoxP SourceCard T))
                                                (COND
                                                   ((NC.FileBoxP DestinationCard T)
                                                    NC.SubBoxLinkLabel)
                                                   (T NC.FiledCardLinkLabel)))
                                               (T (NC.AskLinkLabel Window NIL NIL T T]
                (AND LinkType [NC.ValidLinkP (SETQ Link (COND
                                                           ((AND (NOT GlobalLinkFlg)
                                                                 (NC.TEditBasedP SourceCard))
                                                            (NCP.LocalGlobalLink LinkType SourceCard 
                                                                   DestinationCard 'END))
                                                           (T (NCP.GlobalGlobalLink LinkType 
                                                                     SourceCard DestinationCard]
                     Link])
)



(* ;; "Changes to NCPROGINT")

(DEFINEQ

(NCP.LocalGlobalLink
  [LAMBDA (LinkType SourceCard DestinationCard FromLoc DisplayMode)
                                                             (* ; "Edited 11-May-88 22:58 by Trigg")
          
          (* ;; 
          "Create a link from within the text of the SourceCard card to the DestinationCard card.")
          
          (* ;; "rht 4/1/85: Changed to handle old-style link display modes.")
          
          (* ;; "rht 11/17/85: Updated to handle new card and notefile objects.")
          
          (* ;; "rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.")
          
          (* ;; "rht 11/16/86: Changed call to NCP.ReportError")
          
          (* ;; "rht 5/27/87: Changed call to NCP.CoerceToLinkDisplayMode slightly.")
          
          (* ;; "pmi 4/8/88: Now checks if the SourceCard is graph-based, and if so, calls NC.InsertLinkInGraph, which now takes a position argument (FromLoc).")
          
          (* ;; "rht 5/11/88: Was returning non-nil when NCP.FileCards returned NIL.")

    (DECLARE (GLOBALVARS NC.SubBoxLinkLabel NC.FiledCardLinkLabel))
    (PROG ((CoercedDisplayMode (NCP.CoerceToLinkDisplayMode (OR DisplayMode SourceCard)))
           WasActive NoteFile)
          (if (NULL CoercedDisplayMode)
              then (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT DisplayMode 
                                                                " is invalid link display mode."
                                                                (CHARACTER 13)
                                                                "No link created."))
                   (RETURN NIL))
          (if (NCP.GraphBasedP SourceCard)
              then (if [NOT (FMEMB LinkType (NCP.LinkTypes (SETQ NoteFile (fetch (Card NoteFile)
                                                                             of SourceCard]
                       then (if (NC.AskYesOrNo (CONCAT "That link type hasn't been used in NoteFile "
                                                      (fetch (NoteFile FullFileName) of NoteFile)
                                                      (CHARACTER 13)
                                                      "Want to create a new link type: " LinkType 
                                                      "? ")
                                       "--" NIL T (NC.AttachPromptWindow (WFROMMENU
                                                                          (fetch (NoteFile Menu)
                                                                             of NoteFile)))
                                       NIL NIL)
                                then (NCP.CreateLinkType LinkType NoteFile)
                              else (RETURN NIL)))
                   (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                       (NCP.CacheCards SourceCard))
                   [RETURN (PROG1 (NC.InsertLinkInGraph SourceCard LinkType DestinationCard 
                                         CoercedDisplayMode FromLoc)
                                  (OR WasActive (NCP.UncacheCards SourceCard T]
            elseif (NCP.TextBasedP SourceCard)
              then (if (EQ LinkType NC.FiledCardLinkLabel)
                       then (if (AND (NOT (NCP.FileBoxP DestinationCard))
                                     (NCP.FileBoxP SourceCard))
                                then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                                         (NCP.CacheCards SourceCard))
                                     (NCP.ChangeLoc SourceCard FromLoc)
                                     [RETURN (PROG1 (if (NCP.FileCards DestinationCard SourceCard)
                                                        then (CAR (NCP.GetLinks SourceCard 
                                                                         DestinationCard 
                                                                         NC.FiledCardLinkLabel))
                                                      else NIL)
                                                    (OR WasActive (NCP.UncacheCards SourceCard T]
                              else (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                                       "FiledCard link must be from a box to a card."
                                                                                (CHARACTER 13)
                                                                                "No link created."))
                                   (RETURN NIL)))
                   (if (EQ LinkType NC.SubBoxLinkLabel)
                       then (if (AND (NCP.FileBoxP DestinationCard)
                                     (NCP.FileBoxP SourceCard))
                                then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                                         (NCP.CacheCards SourceCard))
                                     (NCP.ChangeLoc SourceCard FromLoc)
                                     [RETURN (PROG1 (if (NCP.FileCards DestinationCard SourceCard)
                                                        then (CAR (NCP.GetLinks SourceCard 
                                                                         DestinationCard 
                                                                         NC.SubBoxLinkLabel))
                                                      else NIL)
                                                    (OR WasActive (NCP.UncacheCards SourceCard T]
                              else (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                                           "SubBox link must be from a box to a box."
                                                                                (CHARACTER 13)
                                                                                "No link created."))
                                   (RETURN NIL)))            (* ; 
                                                    "Inserting non-hierarchical link into a filebox.")

                   (if (NCP.FileBoxP SourceCard)
                       then (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                     "Local links from fileboxes must be either SubBox or FiledCard."
                                                                         (CHARACTER 13)
                                                                         "No link created."))
                            (RETURN NIL))
                   (if [NOT (FMEMB LinkType (NCP.LinkTypes (SETQ NoteFile (fetch (Card NoteFile)
                                                                             of SourceCard]
                       then (if (NC.AskYesOrNo (CONCAT "That link type hasn't been used in NoteFile "
                                                      (fetch (NoteFile FullFileName) of NoteFile)
                                                      (CHARACTER 13)
                                                      "Want to create a new link type: " LinkType 
                                                      "? ")
                                       "--" NIL T (NC.AttachPromptWindow (WFROMMENU
                                                                          (fetch (NoteFile Menu)
                                                                             of NoteFile)))
                                       NIL NIL)
                                then (NCP.CreateLinkType LinkType NoteFile)
                              else (RETURN NIL)))
                   (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                       (NCP.CacheCards SourceCard))
                   (AND FromLoc (NCP.ChangeLoc SourceCard FromLoc))
                   (RETURN (PROG1 (NC.InsertLinkInText (NC.FetchSubstance SourceCard)
                                         LinkType DestinationCard SourceCard CoercedDisplayMode)
                                  (OR WasActive (NCP.UncacheCards SourceCard T])
)
(PUTPROPS RHTPATCH318 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (2850 3504 (NC.LookUpUIDInHashArray 2860 . 3502)) (3544 5438 (NC.ReassembleUID 3554 . 
4327) (NC.ReadUID 4329 . 5436)) (5481 15949 (NC.ReadBrowserSavedLinkingInfoForNode 5491 . 7174) (
NC.BringUpBrowserCard 7176 . 13343) (NC.BrowserCreateLink 13345 . 15947)) (15988 24267 (
NCP.LocalGlobalLink 15998 . 24265)))))
STOP