(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP")
(FILECREATED "28-May-88 16:44:45" {QV}<NOTECARDS>1.3LNEXT>RHTPATCH305.;6 17273  

      changes to%:  (FNS NC.ATTACHWINDOW NC.FindPlacements NC.DeletePlacement 
                         NC.AddPlacementForWindow)
                    (VARS RHTPATCH305COMS)

      previous date%: "26-May-88 00:04:25" {QV}<NOTECARDS>1.3LNEXT>RHTPATCH305.;4)


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

(PRETTYCOMPRINT RHTPATCH305COMS)

(RPAQQ RHTPATCH305COMS (

(* ;;; "New file")

                        (DECLARE%: DONTCOPY (PROPS (RHTPATCH305 MAKEFILE-ENVIRONMENT)
                                                   (RHTPATCH305 FILETYPE)))
                        
          
          (* ;; "New functions for NCUTILITIES")

                        (FUNCTIONS NC.WithWindowUnHidden)
                        (FNS NC.UnHideWindow NC.HideWindow NC.WindowHiddenP NC.OPENWINDOWS NC.CLOSEW 
                             NC.OPENWP NC.EXPANDW NC.SHRINKW)
                        (FNS NC.ATTACHWINDOW NC.FindPlacements NC.DeletePlacement 
                             NC.AddPlacementForWindow)
                        
          
          (* ;; "Changes to NCINTERFACE")

                        (FNS)
                        
          
          (* ;; "Change to NCCARDS")

                        (FNS NC.FetchWindow NC.QuitCard)))



(* ;;; "New file")

(DECLARE%: DONTCOPY 

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

(PUTPROPS RHTPATCH305 FILETYPE :TCOMPL)
)



(* ;; "New functions for NCUTILITIES")


(DEFMACRO NC.WithWindowUnHidden (Window &REST Body)
   `(RESETLST [if (NC.WindowHiddenP ,Window)
                  then (RESETSAVE (NC.UnHideWindow ,Window)
                              `(NC.HideWindow ,,Window]
           ,@Body))

(DEFINEQ

(NC.UnHideWindow
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 23:45 by Trigg")
          
          (* ;; "Unhide the given window, i.e. copy it into current room.")

    (if (AND (CL:FIND-PACKAGE "ROOMS")
             (NC.WindowHiddenP Window))
        then (CL:FUNCALL (CL:INTERN "UN-HIDE-WINDOW" "ROOMS")
                    Window])

(NC.HideWindow
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 23:45 by Trigg")
          
          (* ;; "Hide the given window, i.e. get rid of copy in current room.")

    (if (AND (CL:FIND-PACKAGE "ROOMS")
             (NOT (NC.WindowHiddenP Window)))
        then (CL:FUNCALL (CL:INTERN "HIDE-WINDOW" "ROOMS")
                    Window])

(NC.WindowHiddenP
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 23:44 by Trigg")
          
          (* ;; "Hide the given window, i.e. get rid of copy in current room.")

    (AND (CL:FIND-PACKAGE "ROOMS")
         (CL:FUNCALL (CL:INTERN "WINDOW-HIDDEN?" "ROOMS")
                Window])

(NC.OPENWINDOWS
  [LAMBDA NIL                                                (* ; "Edited 22-Jan-88 18:39 by Trigg")
          
          (* ;; "Returns the list of open windows.  Like OPENWINDOWS except it works when ROOMS is running and some of the notefile's windows aren't in the current room.  Note that ROOMS:ALL-WINDOWS doesn't return attached windows unlike OPENWINDOWS.")

    (if (CL:FIND-PACKAGE "ROOMS")
        then (CL:FUNCALL (CL:INTERN "ALL-WINDOWS" "ROOMS")
                    T)
      else (OPENWINDOWS])

(NC.CLOSEW
  [LAMBDA (Window)                                           (* ; "Edited 26-May-88 00:00 by Trigg")
          
          (* ;; "Close the window even if we're running Rooms and it's in a different room.  In that case, we have to unhide the hidden window and then close it.")

    (if (AND (WINDOWP Window)
             (NC.WindowHiddenP Window))
        then (NC.UnHideWindow Window))
    (CLOSEW Window])

(NC.OPENWP
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 22:45 by Trigg")
          
          (* ;; "Returns non-nil if window is either open or hidden in another Room.")

    (OR (OPENWP Window)
        (AND (CL:FIND-PACKAGE "ROOMS")
             (CL:FUNCALL (CL:INTERN "WINDOW-HIDDEN?" "ROOMS")
                    Window])

(NC.EXPANDW
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 23:36 by Trigg")
          
          (* ;; "Expands window even if hidden in another Room.")

    (NC.WithWindowUnHidden Window (EXPANDW Window])

(NC.SHRINKW
  [LAMBDA (Window)                                           (* ; "Edited 25-May-88 23:36 by Trigg")
          
          (* ;; "Shrinks Window even if hidden in another Room.")

    (NC.WithWindowUnHidden Window (SHRINKW Window])
)
(DEFINEQ

(NC.ATTACHWINDOW
  [LAMBDA (WINDOWTOATTACH MAINWINDOW EDGE POSITIONONEDGE WINDOWCOMACTION)
                                                             (* ; "Edited 28-May-88 16:41 by Trigg")
          
          (* ;; 
     "Calls ATTACHWINDOW, but makes sure that Rooms placements for the windows are handled properly.")

    (if (CL:FIND-PACKAGE "ROOMS")
        then (LET ((WINDOWTOATTACH-Placements (NC.FindPlacements WINDOWTOATTACH))
                   (MAINWINDOW-Placements (NC.FindPlacements MAINWINDOW)))
          
          (* ;; "Be sure both windows are open.")

                  (OPENW WINDOWTOATTACH)
                  (OPENW MAINWINDOW)
          
          (* ;; "Delete all placments for both windows.")

                  (for RoomPlacementPair in WINDOWTOATTACH-Placements
                     do (NC.DeletePlacement (CAR RoomPlacementPair)
                               (CDR RoomPlacementPair)))
                  (for RoomPlacementPair in MAINWINDOW-Placements do (NC.DeletePlacement (CAR 
                                                                                    RoomPlacementPair
                                                                                              )
                                                                            (CDR RoomPlacementPair)))
          
          (* ;; "Current room requires special handling.")

                  (if (NC.WindowHiddenP MAINWINDOW)
                      then (NC.HideWindow WINDOWTOATTACH)
                    else (NC.UnHideWindow WINDOWTOATTACH))
          
          (* ;; "Attach windows in the usual way.")

                  (ATTACHWINDOW WINDOWTOATTACH MAINWINDOW EDGE POSITIONONEDGE WINDOWCOMACTION)
          
          (* ;; "Build placements for mainwindow in all the right rooms.")

                  (for RoomPlacementPair in MAINWINDOW-Placements do (NC.AddPlacementForWindow
                                                                      (CAR RoomPlacementPair)
                                                                      MAINWINDOW)))
      else (ATTACHWINDOW WINDOWTOATTACH MAINWINDOW EDGE POSITIONONEDGE WINDOWCOMACTION])

(NC.FindPlacements
  [LAMBDA (Window)                                           (* ; "Edited 28-May-88 16:44 by Trigg")
          
          (* ;; "Return list of pairs of rooms and placements for all rooms containing this window.")

    (if (CL:FIND-PACKAGE "ROOMS")
        then (for Room in (CL:FUNCALL (CL:INTERN "ALL-ROOMS" "ROOMS")) bind Placement
                when (SETQ Placement (CL:FUNCALL (CL:INTERN "FIND-PLACEMENT" "ROOMS")
                                            Window Room)) collect (CONS Room Placement])

(NC.DeletePlacement
  [LAMBDA (Room Placement)                                   (* ; "Edited 28-May-88 16:34 by Trigg")
          
          (* ;; "Remove given Placement from given Room.")

    (CL:SETF (ROOMS::ROOM-PLACEMENTS Room)
           (CL:DELETE Placement (ROOMS::ROOM-PLACEMENTS Room])

(NC.AddPlacementForWindow
  [LAMBDA (Room Window)                                      (* ; "Edited 28-May-88 16:33 by Trigg")
          
          (* ;; "Make a new placement for Window and add it to Room.")

    (CL:PUSH (ROOMS:MAKE-PLACEMENT Window)
           (ROOMS::ROOM-PLACEMENTS Room])
)



(* ;; "Changes to NCINTERFACE")




(* ;; "Change to NCCARDS")

(DEFINEQ

(NC.FetchWindow
  [LAMBDA (Card)                                             (* ; "Edited 23-Jan-88 19:09 by Trigg")

(* ;;; "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.")
          
          (* ;; "rht 1/22/88:  Changed OPENWINDOWS call to NC.OPENWINDOWS which handles ROOMS case.")

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

(NC.QuitCard
  [LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg InterestedWindow OperationMsg 
                 QuietFlg Don'tDeactivateFlg)                (* ; "Edited 25-May-88 23:54 by Trigg")

(* ;;; "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.")
          
          (* ;; "pmi 9/16/87: Undoes previous fix to this function.  Needed to get NCLOGGER working.  It depends on getting the CardObject off of the Window passed in as CardIdentifier.")
          
          (* ;; "rht 3/30/88: Restores fix of 4/24/87.  NCLOGGER will have to finesse this somehow.")

    (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 (NC.OPENWP Window)))
                    (NC.EXPANDW Window)))
          
          (* ;; "if proper filing says don't quit then get out")

                [OR DontSaveFlg ReadOnlyCardFlg (COND
                                                   ((EQ (NC.InsureProperFiling Card InterestedWindow)
                                                        'DON'T)
                                                    (RETURN '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
                                            'Yes NIL InterestedWindow]
                    then (RETURN 'DON'T))
          
          (* ;; "Otherwise go ahead and quit")

                (RETURN (PROGN                               (* ; 
                                                             "Close open proplist editor if any.")

                               [AND Window (LET ((PropListEditorWindow (NC.PropListEditorOpenP Window
                                                                              )))
                                                (AND PropListEditorWindow (NC.CLOSEW 
                                                                                 PropListEditorWindow
                                                                                 ]
                               (COND
                                  ((AND Window NC.CloseCardsOffScreenFlg)
                                   [COND
                                      ((NOT (NC.FetchSavedRegion Card))
                                       (NC.SetSavedRegion Card (WINDOWPROP Window '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 'CLOSEFN (FUNCTION NC.QuitCard)))
                               (PROG1 (NC.ApplyFn QuitFn Card)
                                      (AND Window (WINDOWPROP Window 'NoteCardObject NIL))
                                      (AND CallCloseWFlg Window (NC.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])
)
(PUTPROPS RHTPATCH305 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (1916 4993 (NC.UnHideWindow 1926 . 2329) (NC.HideWindow 2331 . 2739) (NC.WindowHiddenP 
2741 . 3085) (NC.OPENWINDOWS 3087 . 3638) (NC.CLOSEW 3640 . 4089) (NC.OPENWP 4091 . 4471) (NC.EXPANDW 
4473 . 4731) (NC.SHRINKW 4733 . 4991)) (4994 8501 (NC.ATTACHWINDOW 5004 . 7298) (NC.FindPlacements 
7300 . 7872) (NC.DeletePlacement 7874 . 8187) (NC.AddPlacementForWindow 8189 . 8499)) (8577 17190 (
NC.FetchWindow 8587 . 9576) (NC.QuitCard 9578 . 17188)))))
STOP