(FILECREATED "23-Mar-87 23:59:48" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH221.;6 56078  

      changes to:  (VARS RHTPATCH221COMS)
		   (FNS NC.SelectNoteCards NC.MakeFilingLinks NC.AssignTitle NC.QuitCard 
			NC.CheckFiling NC.InsureProperFiling NC.GETPROMPTWINDOW 
			NC.SelectionMenusWhenSelectedFn NC.AttachPromptWindow NC.PrintMsg 
			NC.MaxPromptWindowWidth)

      previous date: "21-Mar-87 19:11:04" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH221.;1)


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

(PRETTYCOMPRINT RHTPATCH221COMS)

(RPAQQ RHTPATCH221COMS ((* * Fixes bug #282: cards getting whipped around horizontally by their 
			     prompt windows. Also a variety of other fixes, changes, rewrites. Mostly 
			     grappling with the vagaries of ATTACHEDWINDOWS.)
			  (* * New stuff for NCINTERFACE)
			  (FNS NC.MaxPromptWindowWidth)
			  (* * Change to NCINTERFACE)
			  (FNS NC.GETPROMPTWINDOW NC.AttachPromptWindow NC.SelectNoteCards 
			       NC.SelectionMenusWhenSelectedFn)
			  (* * Change to NCLINKS)
			  (FNS NC.MakeFilingLinks)
			  (* * New stuff for NCUTILITIES)
			  (GLOBALVARS NC.PrintMsgFont)
			  (INITVARS (NC.PrintMsgFont (FONTCREATE (QUOTE HELVETICA)
								 10)))
			  (* * Change to NCUTILITIES)
			  (FNS NC.PrintMsg)
			  (* * Change to NCCARDS)
			  (FNS NC.AssignTitle NC.QuitCard NC.CardSaveFn NC.CheckTitle NC.CheckFiling 
			       NC.InsureProperFiling)
			  (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
				    (ADDVARS (NLAMA)
					     (NLAML)
					     (LAMA NC.PrintMsg)))))
(* * Fixes bug #282: cards getting whipped around horizontally by their prompt windows. Also a
 variety of other fixes, changes, rewrites. Mostly grappling with the vagaries of 
ATTACHEDWINDOWS.)

(* * New stuff for NCINTERFACE)

(DEFINEQ

(NC.MaxPromptWindowWidth
  (LAMBDA (MainWindow)                                       (* rht: "23-Mar-87 11:26")

          (* * Returns the maximum interior width that a prompt window for MainWindow could have and still be on the screen 
	  and attached, no matter whether it's positioned left, right or center.)


    (DECLARE (GLOBALVARS WBorder))
    (LET ((WindowRegion (WINDOWPROP MainWindow (QUOTE REGION)))
	  Left RightSpace Right Width)
         (SETQ Width (fetch (REGION WIDTH) of WindowRegion))
         (DIFFERENCE (if (LESSP (SETQ Left (fetch (REGION LEFT) of WindowRegion))
				      (SETQ RightSpace (DIFFERENCE SCREENWIDTH
								       (SETQ Right
									 (PLUS Left Width)))))
			   then (MAX (DIFFERENCE SCREENWIDTH Left)
					 (PLUS (TIMES 2 Left)
						 Width))
			 else (MAX Right (PLUS (TIMES 2 RightSpace)
						     Width)))
		       (TIMES 2 WBorder)))))
)
(* * Change to NCINTERFACE)

(DEFINEQ

(NC.GETPROMPTWINDOW
  (LAMBDA (MAINWINDOW #LINES FONT DONTCREATE MINWIDTH)     (* rht: "23-Mar-87 21:03")

          (* makes sure that MAINWINDOW has an attached promptwindow and returns it. If one already exists, it is shaped to 
	  be at least #LINES high. If FONT is NIL, the font of the main window is used for the promptwindow.)



          (* * fgh 6/6/86 Adapted from system GETPROMPTWINDOW. Added MINWIDTH arg.)



          (* * rht 7/2/86: Now attaches prompt window on right if near right edge of screen.)



          (* * rht 7/4/86: Yanked out PositionOnEdge localvar. Put code in place.)



          (* * rht 3/21/87: AttachWindowPositionOnEdge to attach prompt window is left if possible, then center, then right.
	  Also doesn't let prompt window be wider than screen.)


    (DECLARE (GLOBALVARS WBorder))
    (AND MINWIDTH (SETQ MINWIDTH (MIN (DIFFERENCE SCREENWIDTH (TIMES WBorder 2))
					    MINWIDTH)))
    (PROG ((PWINDOWPROP (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOW)))
	     (PWINDOWMINWIDTH (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOWMINWIDTH)))
	     (MAINWINDOWREGION (WINDOWPROP MAINWINDOW (QUOTE REGION)))
	     PWINDOW PWINDOWREGION WIDTH HEIGHT OBSCUREDHEIGHT PWINDOW.PWINDOW PWinWidth 
	     AttachWindowPositionOnEdge)
	    (SETQ PWinWidth (WIDTHIFWINDOW (OR MINWIDTH PWINDOWMINWIDTH 1)))
	    (SETQ AttachWindowPositionOnEdge (COND
		((LEQ (PLUS (fetch (REGION LEFT) of MAINWINDOWREGION)
				PWinWidth)
			SCREENWIDTH)
		  (QUOTE LEFT))
		((LEQ (PLUS (fetch (REGION LEFT) of MAINWINDOWREGION)
				(LRSH (PLUS PWinWidth (fetch (REGION WIDTH) of 
										 MAINWINDOWREGION))
					1))
			SCREENWIDTH)
		  (QUOTE CENTER))
		(T (QUOTE RIGHT))))
	    (COND
	      (DONTCREATE (RETURN (CAR PWINDOWPROP)))
	      (PWINDOWPROP (SETQ PWINDOW (CAR PWINDOWPROP))
			   (COND
			     ((NOT (OPENWP PWINDOW))
			       (ATTACHWINDOW PWINDOW MAINWINDOW (QUOTE TOP)
					       AttachWindowPositionOnEdge
					       (QUOTE LOCALCLOSE))))
			   (if (SETQ PWINDOW.PWINDOW (WINDOWPROP PWINDOW (QUOTE PROMPTWINDOW))
				   )
			       then                        (* This prompt window has a prompt window of its own.
							     Close and detach it.)
				      (FREEATTACHEDWINDOW (CAR PWINDOW.PWINDOW))
				      (CLOSEW (CAR PWINDOW.PWINDOW)))
			   (WINDOWPROP PWINDOW (QUOTE MAXSIZE)
					 (CONS 64000 64000))
			   (WINDOWPROP PWINDOW (QUOTE MINSIZE)
					 (CONS 1 1))
			   (SETQ HEIGHT (HEIGHTIFWINDOW (TIMES (OR #LINES (CDR PWINDOWPROP)
									   1)
								     (FONTPROP (DSPFONT NIL 
											  PWINDOW)
										 (QUOTE HEIGHT)))))
			   (SETQ WIDTH (MAX PWinWidth (fetch (REGION WIDTH) of 
										 MAINWINDOWREGION)))
			   (SETQ PWINDOWREGION (WINDOWPROP PWINDOW (QUOTE REGION)))
			   (COND
			     ((OR (NOT (EQP HEIGHT (fetch (REGION HEIGHT) of PWINDOWREGION))
					   )
				    (NOT (EQP WIDTH (fetch (REGION WIDTH) of PWINDOWREGION))))
                                                             (* Window exists, but not right size.
							     Keep windows detached during reshaping.)
			       (NC.WithTopWindowsUnattached PWINDOW 
                                                             (* Detach and reattach in case 
							     AttachWindowPositionOnEdge has changed.)
							    (FREEATTACHEDWINDOW PWINDOW)
                                                             (* Have to smash these to let SHAPEW work.)
							    (WINDOWPROP PWINDOW (QUOTE MAXSIZE)
									  NIL)
							    (WINDOWPROP PWINDOW (QUOTE MINSIZE)
									  NIL)
							    (WINDOWPROP PWINDOW (QUOTE 
										   PASSTOMAINCOMS)
									  NIL)
							    (WINDOWPROP PWINDOW (QUOTE OPENFN)
									  NIL)
							    (SHAPEW PWINDOW
								      (create REGION
									 using PWINDOWREGION HEIGHT 
										 ← HEIGHT WIDTH ← 
										 WIDTH))
							    (ATTACHWINDOW PWINDOW MAINWINDOW
									    (QUOTE TOP)
									    
								       AttachWindowPositionOnEdge
									    (QUOTE LOCALCLOSE)))
			       (RPLACD PWINDOWPROP #LINES)
                                                             (* Fall through to check visibility)
			       )))
	      (T (SETQ PWINDOW (CREATEW (create REGION
						      LEFT ← 0
						      BOTTOM ← 0
						      WIDTH ←(MAX PWinWidth (fetch (REGION WIDTH)
										 of 
										 MAINWINDOWREGION))
						      HEIGHT ←(SETQ HEIGHT
							(HEIGHTIFWINDOW
							  (TIMES (OR #LINES (SETQ #LINES 1))
								   (FONTPROP (OR FONT
										     (SETQ FONT
										       (DSPFONT
											 NIL 
										       MAINWINDOW)))
									       (QUOTE HEIGHT))))))
					    NIL NIL T))
		 (DSPSCROLL T PWINDOW)
		 (DSPFONT FONT PWINDOW)
		 (WINDOWPROP PWINDOW (QUOTE PAGEFULLFN)
			       (QUOTE NILL))
		 (ATTACHWINDOW PWINDOW MAINWINDOW (QUOTE TOP)
				 AttachWindowPositionOnEdge
				 (QUOTE LOCALCLOSE))
		 (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOW)
			       (CONS PWINDOW #LINES))
		 (WINDOWPROP PWINDOW (QUOTE OPENFN)
			       (FUNCTION \PROMPTWINDOW.OPENFN))))
	    (COND
	      ((ILESSP (SETQ OBSCUREDHEIGHT (IDIFFERENCE SCREENHEIGHT
							       (fetch (REGION TOP)
								  of (WINDOWPROP PWINDOW
										     (QUOTE REGION))
									)))
			 0)                                  (* Promptwindow off screen at top, so slip window 
							     group down to make it visible)
		(RELMOVEW MAINWINDOW (create POSITION
						 XCOORD ← 0
						 YCOORD ← OBSCUREDHEIGHT))))
	    (WINDOWPROP PWINDOW (QUOTE MINSIZE)
			  (CONS 1 HEIGHT))
	    (WINDOWPROP PWINDOW (QUOTE MAXSIZE)
			  (CONS 64000 HEIGHT))
	    (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOWMINWIDTH)
			  (OR MINWIDTH 1))
	    (OPENW PWINDOW)
	    (RETURN PWINDOW))))

(NC.AttachPromptWindow
  (LAMBDA (MainWindow MinWidth Height Font DontCreate)       (* rht: "23-Mar-87 19:46")

          (* * GETPROMPTWINDOW that works for small windows. sizes default to 300 X 60)



          (* * fgh 5/1/86 MainWindowXSize now based on MainWindow's REGION WIDTH not its REGION RIGHT.)



          (* * fgh 6/6/86 To fix many bugs made into a wrapper fot NC.GETPROMPTWINDOW)



          (* * rht 3/21/87: Now keeps MinWidth small enough so that the prompt window will always fit on the screen without 
	  moving MainWindow.)


    (DECLARE (GLOBALVARS NC.PrintMsgFont))
    (if MainWindow
	then (if MinWidth
		   then (SETQ MinWidth (MIN MinWidth (NC.MaxPromptWindowWidth MainWindow)))
		 else (SETQ MinWidth 300))
	       (OR Height (SETQ Height 60))
	       (NC.GETPROMPTWINDOW MainWindow (IQUOTIENT Height (if (FONTP Font)
									then (FONTHEIGHT Font)
								      else 15))
				     (OR Font NC.PrintMsgFont)
				     DontCreate MinWidth))))

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow Msg CheckForCancelFlg)
                                                             (* rht: "23-Mar-87 23:49")

          (* Select a set of note cards or a single note card, depending on SingleCardFlg. Works by interpreting all mouse 
	  presses until a card has been chosen (if SingleCardFlg is T) or until the Done button has been pressed 
	  (if SingleCardFlg is NIL). If the mouse press occus within a Title bar of a notecard, add that note card to the 
	  selected list. Otherwise, if you are pointing into a note card, call the BUTTONEVENTFN for that note card.
	  The Selection in Progress flag has been set, so all note card BUTTONEVENTFNs should know to ignore all presses 
	  except those that occur on link icons. Link icon presses should simply add the desination of that link to the 
	  selected note cards list. This function should always be called from inside of an NC.CardSelectionOperation 
	  wrapper.)



          (* * rht 8/1/84: Changed second RESETSAVE call to give NC.ClearMsg a NIL argument.)



          (* * rht 1/9/85: Fixed so now prints name of selected item even it's a link.)



          (* * rht 2/15/85: Now can backspace over last selection chosen. Added new arg Msg so that when we reprint the list,
	  we can reprint the message as well.)



          (* * rht 3/23/85: Added the CheckForCancelFlg arg, which if non-nil causes Cancel to be handled differently then 
	  Done after no selections. Namely, Cancel will return the atom CANCELLED whereas Done with no selections returns 
	  NIL. If CheckForCancelFlg is NIL then NIL is returned in both cases.)



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



          (* * rht 11/18/85: Fixed so able to select when InstigatingNoteFile is NIL.)



          (* * fgh 12/20/85 Totally rewritten for 1.3 selection mechanism. Based on COPYINSERT now rather than on takingf 
	  over the mouse process.)



          (* * fgh 1/15/86 Added call to SPAWN.MOUSE in case this is called under the mouse process)



          (* * kirk 25Apr86 Changed to use SessionIcon (NC.NoteCardsIconWindow) rather than PROMPTWINDOW if no Instigating 
	  window is supplied.)



          (* * fgh 7/5/86 Added code to put CRs into printout of selected cards in order to keep prompt window from getting 
	  infinitely wide to accomdate the printout.)



          (* * rht 10/5/86: Now allows choice of cards from remote notefile.)



          (* * rht 10/18/86: Give TTY process to process that originally had it if possible.)



          (* * rht & pmi 11/14/86: Now checks for valid card before testing SelectionPredicate.)



          (* * pmi 12/5/86 Modified prompt messages to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument.)



          (* * rg 3/18/87 reworked for NC.CardSelectionOperation: added NAMED-RESETSAVE forms for Card locking.)



          (* * 3/23/87: Changed to call REMOVEWINDOW instead of DETACHWINDOW before deleting the attached menu.
	  Also changed so that menu is attached to InstigatingWindow rather than to PromptWindow. This makes it possible for 
	  windows to "slide down" when selection ends.)


    (DECLARE (USEDFREE NC.SelectNoteCardsResetVar))
    (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile MenuWindow 
		 PromptWindow CopyInsertEvent SelectedCards PromptWindowProcess OldTTYProcess 
		 OpInProgress ResetItems TTYResetVar InternalResetVar)
         (NAMED-RESETLST
	   InternalResetVar
	   (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
	   (COND
	     ((AND (NC.ActiveCardP InstigatingCardOrWindow)
		     (SETQ InstigatingWindow (NC.FetchWindow InstigatingCardOrWindow)))
	       (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
	     ((WINDOWP InstigatingCardOrWindow)
	       (SETQ InstigatingWindow InstigatingCardOrWindow)
	       (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
	     (T (SETQ PromptWindow (NC.AttachPromptWindow (SETQ InstigatingWindow 
								NC.NoteCardsIconWindow)))))
	   (SETQ InstigatingCard (NC.CoerceToCard InstigatingCardOrWindow))
	   (SETQ InstigatingNoteFile (AND InstigatingCard (fetch (Card NoteFile) of 
										  InstigatingCard)))
	   (NC.PrintMsg InstigatingWindow T (COND
			    (Msg (CONCAT Msg (CHARACTER 13)))
			    (T ""))
			  "Items shift-selected:  ")
	   (SETQ OldTTYProcess (TTY.PROCESS))

          (* * if we are running under the mouse process, start up a new mouse process)


	   (ALLOW.BUTTON.EVENTS)

          (* * Set up the prompt window for proper use by the CopyInsertFn)


	   (WINDOWPROP PromptWindow (QUOTE COPYINSERTFN)
			 (FUNCTION NC.SelectNoteCardsCopyInsertFn))
	   (WINDOWPROP PromptWindow (QUOTE CopyInsertEvent)
			 (SETQ CopyInsertEvent (CREATE.EVENT (QUOTE CopyInsertEvent))))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectedCards)
							     NIL)
			      (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
						      NIL)))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectingCards)
							     T)
			      (BQUOTE (WINDOWPROP , PromptWindow SelectingCards NIL)))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectCardsMonitor)
							     (CREATE.MONITORLOCK (QUOTE 
										      SelectCards)))
			      (BQUOTE (WINDOWPROP , PromptWindow SelectCards NIL)))

          (* * Make the process behind the prompt window includiong control for a blibnking cursor)


	   (WINDOWPROP PromptWindow (QUOTE PROCESS)
			 (SETQ PromptWindowProcess (ADD.PROCESS
			     (QUOTE (PROG NIL (BLOCK)
					      (TTYDISPLAYSTREAM (PROCESSPROP (THIS.PROCESS)
										 (QUOTE WINDOW)))
					      XXXX
					      (BIN)
					      (BLOCK)
					      (GO XXXX)))
			     (QUOTE WINDOW)
			     PromptWindow
			     (QUOTE NAME)
			     (QUOTE SelectNoteCardsProc)
			     (QUOTE TTYENTRYFN)
			     (FUNCTION (LAMBDA (Process)
				 (PROCESSPROP Process (QUOTE OldCaret)
						(CARET CROSSHAIRS))
				 (ECHOMODE)))
			     (QUOTE TTYEXITFN)
			     (FUNCTION (LAMBDA (Process)
				 (CARET (PROCESSPROP Process (QUOTE OldCaret)))
				 (ECHOMODE T))))))
	   (NAMED-RESETSAVE InternalResetVar NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

          (* * Insure the prompt window is cleared on the way out)


	   (NAMED-RESETSAVE InternalResetVar NIL
			      (BQUOTE (PROGN (AND (HASTTYWINDOWP , PromptWindowProcess)
							(TTY.PROCESS (if (AND (PROCESSP
										      , OldTTYProcess)
										    (HASTTYWINDOWP
										      , OldTTYProcess)
										    )
									   then , OldTTYProcess
									 else T)))
						 (NC.ClearMsg , InstigatingWindow T))))

          (* * Set up the menu above the prompt window)

                                                             (* fix in case MENUPOSITION is set incorrectly in menu
							     passed down)
	   (replace (MENU MENUPOSITION) of Menu
	      with (CONSTANT (create POSITION
					   XCOORD ← 0
					   YCOORD ← 0)))
	   (NAMED-RESETSAVE InternalResetVar (PROGN (ATTACHMENU
							  Menu InstigatingWindow (QUOTE TOP)
							  (if (WINDOWP PromptWindow)
							      then (CDR (WINDOWPROP
									      PromptWindow
									      (QUOTE WHEREATTACHED))
									    )
							    else (QUOTE LEFT)))
							(WINDOWPROP (WFROMMENU Menu)
								      (QUOTE SelectionPromptWindow)
								      PromptWindow))
			      (BQUOTE (PROGN (REMOVEWINDOW (WFROMMENU , Menu))
						 (DELETEMENU , Menu T))))

          (* * If there is an instigating window, make sure it and all its attachments are visible on the screen.)


	   (if InstigatingWindow
	       then (NC.MoveWindowOntoScreen InstigatingWindow))

          (* * Give the prompt window the tty process)


	   (TTY.PROCESS (WINDOWPROP PromptWindow (QUOTE PROCESS)))

          (* * Loop as long as necessary)


	   (WITH.MONITOR
	     (WINDOWPROP PromptWindow (QUOTE SelectCardsMonitor))
	     (until (OR (EQ SelectedCards (QUOTE CANCELLED))
			    (AND SingleCardFlg SelectedCards)
			    (EQ (CAR SelectedCards)
				  (QUOTE DONE)))
		do
		 (

          (* * Wait for the user to respond by copy inserting something into the prompt window)


		  (until (NOT (EQ SelectedCards (WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards))))
		     do (MONITOR.AWAIT.EVENT (WINDOWPROP PromptWindow (QUOTE 
									       SelectCardsMonitor))
						 CopyInsertEvent))

          (* * Get the latest selection list)


		  (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards)))
		  (NAMED-RESETLST
		    TTYResetVar

          (* * Turn off the caret)


		    (NAMED-RESETSAVE TTYResetVar (TTY.PROCESS (THIS.PROCESS)))

          (* * If the last thing wasn't a done or cancel, process the new selection)


		    (SETQ Card (CAR SelectedCards))
		    (WITH.MONITOR
		      NC.LockLock
		      (COND
			((AND (NEQ Card (QUOTE DONE))
				(NEQ SelectedCards (QUOTE CANCELLED))
				(NEQ Card (QUOTE *New% Card*)))

          (* * Check to make sure that the selection is valid)


			  (COND
			    ((EQ Card (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
			      (SETQ Card (CADR SelectedCards))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDDR SelectedCards)))
                                                             (* now get our hands off of all the locks we've 
							     acquired for this card)
			      (NAMED-RESETUNSAVE NC.SelectNoteCardsResetVar (NC.FetchUserDataProp
						     Card
						     (QUOTE ResetItems)))
			      (NC.SetUserDataProp Card (QUOTE ResetItems)
						    NIL)
			      (NC.ClearMsg InstigatingWindow NIL))
			    ((OR (NOT (NC.ValidCardP Card))
				   (NULL (APPLY* SelectionPredicate Card)))
                                                             (* Does this card match the slection predicate)
			      (NC.PrintMsg InstigatingWindow T "*** Invalid selection. ***"
					     (CHARACTER 13))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDR SelectedCards))))
			    ((SETQ OpInProgress (NC.CardCheckOpInProgress Card))
			      (NC.PrintOperationInProgressMsg InstigatingWindow "Select Card" 
								OpInProgress)
			      (DISMISS 1000)
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDR SelectedCards)))
			      (NC.ClearMsg InstigatingWindow NIL))
			    (T                               (* A valid selection.)
			       (NC.ClearMsg InstigatingWindow NIL)
			       (SETQ ResetItems NIL)
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE 
								       NC.SelectNoteCardsResetVar
									     (NC.SetUserDataProp
									       Card
									       (QUOTE 
										ProcessInProgress)
									       (THIS.PROCESS))
									     (BQUOTE (
									       NC.SetUserDataProp
											 , Card 
										ProcessInProgress NIL)
										       ))
							  ResetItems))
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE 
								       NC.SelectNoteCardsResetVar
									     (NC.SetUserDataProp
									       Card
									       (QUOTE 
									      OperationInProgress)
									       "Select Card")
									     (BQUOTE (
									       NC.SetUserDataProp
											 , Card 
									      OperationInProgress NIL)
										       ))
							  ResetItems))
			       (SETQ ResetItems
				 (CONS (NAMED-RESETSAVE NC.SelectNoteCardsResetVar
							    (NC.NoteFileProp
							      (fetch (Card NoteFile) of Card)
							      (QUOTE CardProcessInProgressList)
							      (CONS (THIS.PROCESS)
								      (NC.NoteFileProp
									(fetch (Card NoteFile)
									   of Card)
									(QUOTE 
									CardProcessInProgressList))))
							    (BQUOTE (NC.ResetCardProcessInProgress
									,
									(fetch (Card NoteFile)
									   of Card))))
					 ResetItems))
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE
							    NC.SelectNoteCardsResetVar
							    (SETQ NC.CardBusyList (CONS (
										     THIS.PROCESS)
											    
										  NC.CardBusyList))
							    (QUOTE (SETQ NC.CardBusyList
									     (DREMOVE (
										     THIS.PROCESS)
											
										  NC.CardBusyList))))
							  ResetItems))
			       (NAMED-RESETSAVE InternalResetVar (NC.SetUserDataProp
						    Card
						    (QUOTE ResetItems)
						    ResetItems)
						  (BQUOTE (NC.SetUserDataProp , Card ResetItems 
										  NIL)))))

          (* * Print the results in the prompt window)


			  (NC.PrintMsg InstigatingWindow NIL (COND
					   (Msg (CONCAT Msg (CHARACTER 13)))
					   (T ""))
					 "Items selected:  ")
			  (for ThisCard in (REVERSE SelectedCards)
			     do (NC.PrintMsg InstigatingWindow NIL (NC.RetrieveTitle ThisCard)
						 ",  ")
				  (if (AND InstigatingWindow (GREATERP
						 (DSPXPOSITION NIL PromptWindow)
						 (TIMES 1.25 (WINDOWPROP InstigatingWindow
									     (QUOTE WIDTH)))))
				      then (NC.PrintMsg InstigatingWindow NIL (CHARACTER 13)))))
			))))))

          (* * Return the result)


	   (PROG1 (COND
		      ((EQ SelectedCards (QUOTE CANCELLED))
			(COND
			  (CheckForCancelFlg (QUOTE CANCELLED))
			  (T NIL)))
		      (SingleCardFlg (if (EQ (CAR SelectedCards)
						 (QUOTE DONE))
					 then NIL
				       else (CAR SelectedCards)))
		      (T (if (EQ (CAR SelectedCards)
				     (QUOTE DONE))
			     then (DREVERSE (CDR SelectedCards))
			   else (DREVERSE SelectedCards))))
		    (WINDOWPROP PromptWindow (QUOTE SelectedCards)
				  NIL))))))

(NC.SelectionMenusWhenSelectedFn
  (LAMBDA (Item Menu Button)                                 (* rht: "23-Mar-87 22:12")

          (* * rht 2/15/85: Added handler for Undo.)



          (* * fgh 12/20/85 Updated for use with 1.3 selection mechanism.)



          (* * rht & pmi 12/12/86: Now finds promptwindow using the MAINWINDOW windowprop rather than the MAINWINDOW 
	  function.)



          (* * rht 3/23/87: Now looks for PromptWindow on SelectionPromptWindow instead of looking for main window.)


    (LET ((PromptWindow (WINDOWPROP (WFROMMENU Menu)
				      (QUOTE SelectionPromptWindow))))
         (SELECTQ (CAR Item)
		    ((Done)
		      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
				    (CONS (QUOTE DONE)
					    (WINDOWPROP PromptWindow (QUOTE SelectedCards)))))
		    ((Abort Cancel)
		      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
				    (QUOTE CANCELLED)))
		    (New% Card (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					     (CONS (QUOTE *New% Card*)
						     (WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards)))))
		    (NoSource (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (LIST (QUOTE NC00000))))
		    (Undo (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					(CONS (QUOTE *Undo% Selection*)
						(WINDOWPROP PromptWindow (QUOTE SelectedCards)))))
		    NIL)
         (NOTIFY.EVENT (WINDOWPROP PromptWindow (QUOTE CopyInsertEvent))))))
)
(* * Change to NCLINKS)

(DEFINEQ

(NC.MakeFilingLinks
  (LAMBDA (Card Msg InterestedWindow)                        (* rht: "23-Mar-87 23:34")
                                                             (* Hooks card specified by Card to all of the current 
							     contents cards by a Contents link)

          (* * rht 8/1/84: Changed the NC.PrintMsg2 call for "No FileBox has been specified." to use NIL as second arg rather
	  than T. This prevents erasure of previous error messages.)



          (* * rht 12/8/84: Massive rewrite. Now calls NC.MakeChildLink. And always orphanizes if no parent specified.
	  This is because it's currently called only by NC.InsureProperFiling.)



          (* * rht 6/25/85: Now returns NewParents and checks if CANCELLED comes back from NC.SelectNoteCards so can abort 
	  the calling operation.)



          (* * Fgh 11/15/85 Adapted from and intended to replace NC.MakeContentsHooks)



          (* * fgh 8/6/86 Updated to use NC.AttachPromptWindow and added Msg arg)



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



          (* * rg 2/19/87 Make sure NewParents always has the real value)



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



          (* * rht 3/23/87: Changed so that message will fit on one less line.)



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


    (DECLARE (GLOBALVARS NC.SelectingContentsMenu))
    (NC.CardSelectionOperation (PROG (OneHook NewParents)
				       (OR InterestedWindow (SETQ InterestedWindow (
						 NC.FetchWindow Card)))
				       (SETQ NewParents (NC.SelectNoteCards
					   NIL
					   (FUNCTION NC.FileBoxP)
					   NC.SelectingContentsMenu Card (CONCAT (OR Msg "")
										   
						"('Done' with no selections files in ToBeFiled.)")
					   T))
				       (COND
					 ((NOT (OR (EQ NewParents (QUOTE CANCELLED))
						       (AND NewParents
							      (for ParentCard in NewParents
								 bind OneHook
								 when (NC.MakeChildLink Card 
										       ParentCard 
										 InterestedWindow)
								 do (SETQ OneHook T)
								 finally (RETURN OneHook)))))
					   (NC.PrintMsg InterestedWindow NIL 
							  "No FileBox has been specified."
							  (CHARACTER 13)
							  
						  "This card will be filed in the ToBeFiled Box."
							  (CHARACTER 13))
					   (SETQ NewParents (NC.HookToOrphanCard
					       Card
					       (fetch (NoteFile ToBeFiledCard)
						  of (fetch (Card NoteFile) of Card))))
					   (COND
					     ((NC.AttachPromptWindow InterestedWindow NIL NIL NIL T)
					       (SPAWN.MOUSE)
					       (DISMISS 2000)
					       (NC.ClearMsg InterestedWindow T)))))
				       (RETURN NewParents)))))
)
(* * New stuff for NCUTILITIES)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.PrintMsgFont)
)

(RPAQ? NC.PrintMsgFont (FONTCREATE (QUOTE HELVETICA)
				     10))
(* * Change to NCUTILITIES)

(DEFINEQ

(NC.PrintMsg
  (LAMBDA Msgs                                               (* rht: "23-Mar-87 12:57")

          (* Print the msgs in the specified window. First argument is a window to print msg in, second arg is flag telling 
	  whether to clear first, rest of arguments are simply prin1'ed to the msg window)



          (* * rht 7/24/85: Now checks to be sure that window arg is a notecards window. If not, doesn't use promptwindow, 
	  but prints directly to window.)



          (* * rht 9/11/85: Added call to NC.MoveWindowOntoScreen in case we're crammed near the top of screen.)



          (* * fgh 6/8/86 Now opens prompt window to width that matches longest line in Msg.)



          (* * fgh 6/13/86 Now attaches prompt window to NF menus as well as cards.)



          (* * fgh 6/26/86 Now tries to make the window an appropriate width to hold the whole msg. Height remains a 
	  constant.)



          (* * rht 3/23/87: Now gets font from globalvar NC.PrintMsgFont.)


    (DECLARE (GLOBALVARS NC.PrintMsgFont))
    (LET (NoteCardWinFlg PromptWin CachedStream Window MaxWidth)
         (SETQ Window (ARG Msgs 1))

          (* * find the maximun line length in the given arg list. Cached on the main window under the PromptWindowLastNotCR 
	  prop is the length of the previous line if it didn't end in a carriage return. Need to add this to the length of 
	  the first line in this call.)


         (SETQ MaxWidth
	   (APPLY
	     (FUNCTION MAX)
	     (OR (bind (LastNotCR ←(if (AND Window (NULL (ARG Msgs 2)))
					   then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
								)))
		      for Msg from 3 to Msgs
		      join 

          (* * Parse each arg into a list of line lengths. Set the LastNotCR to the length of the last line in the arg if the
	  arg does not end in a CR. This will be added to the length of the first line in the next arg whether it be in this 
	  call or the next call to Printmsg.)


			     (if (STREQUAL (ARG Msgs Msg)
					       "")
				 then (LIST 0)
			       else
				(while (SETQ Char (GNC CopyString)) as Ctr from 1
				   bind Char (LastCR ← 0)
					  (CopyString ←(SUBSTRING (ARG Msgs Msg)
								    1))
					  (OriginalString ←(SUBSTRING (ARG Msgs Msg)
									1))
				   when (EQ Char (CHARACTER 13))
				   collect (PROG1 (PLUS (OR LastNotCR 0)
							      (STRINGWIDTH
								(OR (SUBSTRING OriginalString
										   (ADD1 LastCR)
										   (SUB1 Ctr))
								      "")
								NC.PrintMsgFont))
						      (SETQ LastCR Ctr)
						      (SETQ LastNotCR 0))
				   finally

          (* if the last line doesn't end in a CR, save its length as LastNotCR but be sure to put its length on the list 
	  anyway in case this is the last call.)


				    (if (NOT (EQP Ctr LastCR))
					then (SETQ $$VAL
						 (CONS (PLUS (OR LastNotCR 0)
								 (STRINGWIDTH
								   (OR (SUBSTRING OriginalString
										      (ADD1 LastCR)
										      (SUB1 Ctr))
									 "")
								   NC.PrintMsgFont))
							 $$VAL))
					       (SETQ LastNotCR (CAR $$VAL))
				      else (SETQ LastNotCR))))
		      finally                              (* Cache the last linelength if it didn't end in a CR,
							     we'll need it to add to the first line next time.)
				(if Window
				    then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
							 LastNotCR)))
		   0)))
         (if (IGREATERP Msgs 2)
	     then 

          (* * Figure out the prompt window)


		    (SETQ NoteCardWinFlg (NC.NoteCardsWindowP Window))
		    (if (NOT (WINDOWP Window))
			then (SETQ PromptWin PROMPTWINDOW)
		      elseif NoteCardWinFlg
			then (SETQ PromptWin (NC.AttachPromptWindow Window NIL NIL NIL T))
		      else (SETQ PromptWin Window))

          (* * If requested, reset all the width caches.)


		    (if (AND PromptWin (ARG Msgs 2))
			then (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
					     300))

          (* * Set window width to the max width of the current max width and the cached max width from previous lines since 
	  the last clear)


		    (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
				  (SETQ MaxWidth (MAX MaxWidth (OR (WINDOWPROP PromptWin
										       (QUOTE
											 OldMaxWidth))
									 300))))

          (* * Actual width of window is this maxwidth, except that if window is open, don't make it smaller.)


		    (if NoteCardWinFlg
			then (SETQ PromptWin (NC.AttachPromptWindow
				   Window
				   (if (OPENWP PromptWin)
				       then (MAX MaxWidth (WINDOWPROP PromptWin (QUOTE WIDTH))
						     )
				     else MaxWidth)))
			       (NC.MoveWindowOntoScreen Window))

          (* * Print the msg.)


		    (RESETLST (OR NoteCardWinFlg (RESETSAVE (TTYDISPLAYSTREAM PromptWin)))
				(RESETSAVE NIL (BQUOTE (DSPFONT , (DSPFONT NC.PrintMsgFont 
										   PromptWin)
								      , PromptWin)))
				(if (ARG Msgs 2)
				    then (CLEARW PromptWin))
				(LINELENGTH 1000 PromptWin)
				(if (NULL PromptWin)
				    then (BREAK1 T T))
				(for Msg from 3 to Msgs collect (PRIN1 (ARG Msgs Msg)
										 PromptWin))))
     PromptWin)))
)
(* * Change to NCCARDS)

(DEFINEQ

(NC.AssignTitle
  (LAMBDA (CardIdentifier NoClearMsgFlg NewTitle InterestedWindow)
                                                             (* rht: "23-Mar-87 23:45")

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


    (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 (SETQ Window
						(NC.FetchWindow 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 Window)
							    (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.QuitCard
  (LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg InterestedWindow OperationMsg 
			  QuietFlg Don'tDeactivateFlg)       (* rht: "23-Mar-87 23:38")

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


    (DECLARE (GLOBALVARS NC.RemoveDELETEMEImageObjsFromCardFlg))
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  Window ReadOnlyCardFlg)
         (SETQ Window (NC.FetchWindow Card))
         (OR InterestedWindow (SETQ InterestedWindow (OR Window NC.NoteCardsIconWindow)))
         (NC.ProtectedCardOperation
	   Card "Close Card" InterestedWindow Window
	   (PROG NIL
	           (SETQ ReadOnlyCardFlg (NC.ReadOnlyCardP Card))
                                                             (* The window not being open should mean that it's 
							     shrunken. If so, expand it.)
	           (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 CANCELLED))
			     (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 CallCloseWFlg Window
						      (PROGN (WINDOWPROP Window (QUOTE 
										   NoteCardObject)
									     NIL)
							       (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.CardSaveFn
  (LAMBDA (WindowOrID QuietFlg InterestedWindow OperationMsg)
                                                             (* rht: "23-Mar-87 23:18")

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


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP)
         (SETQ Window (NC.FetchWindow Card))
         (OR InterestedWindow (SETQ InterestedWindow Window))
         (NC.ProtectedCardOperation
	   Card "Save Card" InterestedWindow (LET ((WhenSavedFn (GETPROP (NC.FetchType Card)
									   (QUOTE WhenSavedFn))))
					          (AND WhenSavedFn (APPLY* WhenSavedFn Card)))
	   (if (NC.CheckForNotReadOnly Card InterestedWindow "Can't save cards in ")
	       then (OR QuietFlg (NC.PrintMsg InterestedWindow T (OR OperationMsg "")
						    (NC.FetchTitle Card)
						    ": Checking ... "))
		      (COND
			((OR (NC.CardDirtyP Card)
			       (NC.FetchNewCardFlg Card))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "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 NIL "Saving "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "region, "))
			  (NC.PutRegion Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchTitleDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "title, "))
			  (NC.PutTitle Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchPropListDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "proplist, "))
			  (NC.PutPropList Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchLinksDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "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))))
		      (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL (CHARACTER
								13)
							      "Nothing changed. "))
                                                             (* It's not a new card anymore.)
		      (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 (PROGN (NC.PrintMsg InterestedWindow NIL "Done."
							     (CHARACTER 13))
					      (if InterestedWindow
						  then (NC.ClearMsg InterestedWindow T)))))))))

(NC.CheckTitle
  (LAMBDA (Card InterestedWindow)                            (* rht: "23-Mar-87 23:27")
                                                             (* 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.)


    (OR InterestedWindow (SETQ InterestedWindow (NC.FetchWindow Card)))
    (LET (Title)
         (COND
	   ((AND NC.ForceTitlesFlg (OR (NULL (SETQ Title (NC.RetrieveTitle Card)))
					   (EQUAL "Untitled" Title)))
	     (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 T)))))

(NC.CheckFiling
  (LAMBDA (Card InterestedWindow)                            (* rht: "23-Mar-87 23:36")
                                                             (* 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.)


    (NC.ProtectedCardOperation Card "Filing" NIL (COND
				 ((NC.CardNeedsFilingP Card)
				   (OR InterestedWindow (SETQ InterestedWindow (NC.FetchWindow
					     Card)))
				   (COND
				     (NC.ForceFilingFlg (NC.MakeFilingLinks Card
									      (CONCAT "This card ("
											(
										 NC.RetrieveTitle
											  Card)
											
							 ") is not currently filed in a FileBox."
											(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.InsureProperFiling
  (LAMBDA (Card InterestedWindow)                            (* rht: "23-Mar-87 23:36")
                                                             (* 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.)


    (OR (AND (NULL (NC.FetchBeingDeletedFlg Card))
		 (NC.CheckTitle Card InterestedWindow)
		 (NC.CheckFiling Card InterestedWindow))
	  (QUOTE CANCELLED))))
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NC.PrintMsg)
)
(PUTPROPS RHTPATCH221 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1799 2820 (NC.MaxPromptWindowWidth 1809 . 2818)) (2855 27001 (NC.GETPROMPTWINDOW 2865
 . 9183) (NC.AttachPromptWindow 9185 . 10269) (NC.SelectNoteCards 10271 . 25427) (
NC.SelectionMenusWhenSelectedFn 25429 . 26999)) (27032 30090 (NC.MakeFilingLinks 27042 . 30088)) (
30301 36010 (NC.PrintMsg 30311 . 36008)) (36041 55853 (NC.AssignTitle 36051 . 39905) (NC.QuitCard 
39907 . 45515) (NC.CardSaveFn 45517 . 51799) (NC.CheckTitle 51801 . 53012) (NC.CheckFiling 53014 . 
54963) (NC.InsureProperFiling 54965 . 55851)))))
STOP