(FILECREATED "14-Nov-86 16:44:00" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH152.;2 20444  

      changes to:  (VARS RHTPATCH152COMS)
		   (FNS NC.GraphCardMiddleButtonFn NC.GraphCardLeftButtonFn)

      previous date: "14-Nov-86 16:30:42" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH152.;1)


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

(PRETTYCOMPRINT RHTPATCH152COMS)

(RPAQQ RHTPATCH152COMS ((* * Fixes trivial bug in NC.MakeLink, checks for valid card selection 
			     before applying SelectionPredicate, handles button events better in 
			     browsers.)
			  (* * Change to NCLINKS)
			  (FNS NC.MakeLink)
			  (* * Change to NCINTERFACE)
			  (FNS NC.SelectNoteCards)
			  (* * Change to NCGRAPHCARD)
			  (FILES (FROM {QV}<NOTECARDS>1.3K>NEXT>)
				 NCGRAPHCARD)
			  (FNS NC.GraphCardMiddleButtonFn NC.GraphCardLeftButtonFn)))
(* * Fixes trivial bug in NC.MakeLink, checks for valid card selection before applying 
SelectionPredicate, handles button events better in browsers.)

(* * Change to NCLINKS)

(DEFINEQ

(NC.MakeLink
  (LAMBDA (Window LinkLabel DestinationCard SourceCard DisplayMode AnchorMode Message NoDisplayFlg 
		  LinkToInsertAfter CrossFileLinksMode)      (* rht: "14-Nov-86 15:26")

          (* * Make a link from (OR Window SourceCard) to DestinationCard with linklabel of LinkLabel)



          (* * rht 1/12/85: If need to create a new card, then now shows card type menu near window of SourceID.)



          (* * rht 1/13/85: Added extra args Message and NoDisplayFlg.)



          (* * rht 3/26/85: Added LinkToInsertAfter arg which should be NIL or a link to insert the new To link after.
	  If NIL, then insert at front of ToLinks.)



          (* * kirk 9/23/85: took out GETPROMPTWINDOW call for asknotecardtype)



          (* * kirk: 14Nov85: changed NC.CoerceToID to to NC.CoerceToCard)



          (* * fgh 11/16/85 Changed from PROG to LET and used COND to contyrol returnmed value.)



          (* * fgh 2/5/86 Changed call DefaultLinkDisplayMode to FetchLinkDisplayMode)



          (* * fgh 6/5/86 Now calls AskLinkLabel if LinkLabel arg is NIL)



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



          (* * kef 7/17/86: Added calls to grab the write permission on the appropriate card parts.)



          (* * kef 7/22/86: Saves the links on the Destination Card now right away, while still holding onto the FROMLINKS 
	  write lock.)



          (* * fgh 8/30/86 Adpated to use NC.IfCardPartNotBusy.)



          (* * rht 9/29/86: Tossed Ken's call to NC.PutFromLinks; It was the cause of too many nasty breaks.
	  Also made syntactic fixes.)



          (* * rht 10/4/86: Now handles cross file links. New arg CrossFileLinksMode determines whether cross-file link will 
	  be two-way, i.e. will destination card know it's being linked to.)



          (* * rht 11/10/86: Now creates new crossfile link if Destination card is a CrossFileLink card that we didn't just 
	  create.)



          (* * rht 11/14/86: Now checks if non-nil DestinationCard before trying to do cross-filelink stuff.)


    (DECLARE (GLOBALVARS NC.SelectingSingleCardMenu NC.NewCrossFileLinksTwoWayFlg))
    (OR SourceCard (SETQ SourceCard (NC.CoerceToCard Window)))
    (AND (NC.CheckForNotReadOnly SourceCard Window "Can't make links in ")
	   (LET (Link Type)
	        (OR Window (SETQ Window (NC.FetchWindow SourceCard)))
	        (OR Message (SETQ Message "Please select the Card or Box to be linked to."))
	        (OR LinkLabel (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T NIL)))
	        (OR DestinationCard (SETQ DestinationCard
			(NC.SelectNoteCards T (FUNCTION (LAMBDA (Card)
						  (COND
						    ((NOT (NC.SameCardP Card SourceCard))
						      T)
						    (T (NC.PrintMsg Window T 
							     "A Card/Box cannot link to itself. "
								      (CHARACTER 13)
								      "Selection ignored."
								      (CHARACTER 13))
						       NIL))))
					      NC.SelectingSingleCardMenu SourceCard NIL Message)))
	        (if (EQ DestinationCard (QUOTE *New% Card*))
		    then (SETQ DestinationCard (AND (SETQ Type (NC.AskNoteCardType
							      (WINDOWREGION Window)))
							  (NC.CoerceToCard
							    (NC.MakeNoteCard Type
									       (fetch (Card 
											 NoteFile)
										  of SourceCard)
									       NIL NoDisplayFlg)))))

          (* * If we're trying to link to a CrossFileLink card, then check whether card was just created.
	  If so, then it's the first link, otherwise we make a new CrossFileLink.)


	        (if DestinationCard
		    then (AND (NC.CrossFileLinkCardP DestinationCard)
				  (if (NC.FetchUserDataProp DestinationCard (QUOTE 
										   JustCreatedFlg))
				      then (NC.SetUserDataProp DestinationCard (QUOTE 
										   JustCreatedFlg)
								   NIL)
				    else (SETQ DestinationCard (NC.GetCrossFileLinkDestCard
					       DestinationCard)))))
	        (if DestinationCard
		    then (NC.IfCardPartNotBusy
			     DestinationCard
			     (QUOTE FROMLINKS)
			     (NC.IfCardPartNotBusy SourceCard (QUOTE TOLINKS)

          (* * If have cross-file link, then make two new crossfilelink cards, one per notefile. Make global link over there 
	  from crossfilelink card to DestinationCard and local link here from SourceCard to crossfilelink card.)


						   (if (NOT (NC.SameNoteFileP
								  (fetch (Card NoteFile)
								     of SourceCard)
								  (fetch (Card NoteFile)
								     of DestinationCard)))
						       then
							(LET ((CrossFileLinksTwoWayFlg
								(OR (EQ CrossFileLinksMode
									    (QUOTE TWOWAY))
								      (AND (NULL 
									       CrossFileLinksMode)
									     
								    NC.NewCrossFileLinksTwoWayFlg))))
							     (if CrossFileLinksTwoWayFlg
								 then (NC.MakeGlobalLink
									  Window LinkLabel 
									  DestinationCard
									  (
								       NC.CreateCrossFileLinkCard
									    DestinationCard 
									    SourceCard T)
									  DisplayMode))
							     (SETQ DestinationCard
							       (NC.CreateCrossFileLinkCard 
										       SourceCard 
										  DestinationCard 
									  CrossFileLinksTwoWayFlg))))
						   (SETQ Link (create Link
									  UID ←(NC.MakeUID)
									  SourceCard ← SourceCard
									  DestinationCard ← 
									  DestinationCard
									  AnchorMode ← AnchorMode
									  Label ← LinkLabel
									  DisplayMode ←(OR
									    DisplayMode
									    (NC.FetchLinkDisplayMode
									      SourceCard))))
						   (NC.AddToLink Link LinkToInsertAfter)
						   (NC.AddFromLink Link)
						   Link))
		  else NIL)))))
)
(* * Change to NCINTERFACE)

(DEFINEQ

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow ReturnLinksFlg Msg 
			 CheckForCancelFlg)                  (* rht: "14-Nov-86 15:41")

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



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


    (RESETLST (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile 
			     MenuWindow PromptWindow CopyInsertEvent SelectedCards 
			     PromptWindowProcess OldTTYProcess)
		     (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
		     (COND
		       ((NC.CardP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow (NC.FetchWindow InstigatingCardOrWindow))
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       ((WINDOWP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow InstigatingCardOrWindow)
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       (T (SETQ InstigatingWindow (SETQ PromptWindow (NC.AttachPromptWindow
				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 selected:  ")
		     (SETQ OldTTYProcess (TTY.PROCESS))

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


		     (AND (EQ (QUOTE MOUSE)
				  (PROCESSPROP (THIS.PROCESS)
						 (QUOTE NAME)))
			    (SPAWN.MOUSE))

          (* * 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)))
				   )
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectedCards)
						NIL)
				  (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
							  NIL)))
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectingCards)
						T)
				  (BQUOTE (WINDOWPROP , PromptWindow SelectingCards 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))))))
		     (RESETSAVE NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

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


		     (RESETSAVE 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)))
		     (RESETSAVE (ATTACHMENU Menu PromptWindow (if InstigatingWindow
								      then (QUOTE TOP)
								    else (QUOTE BOTTOM))
						(QUOTE LEFT))
				  (BQUOTE (PROGN (DETACHWINDOW (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)


		     (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 (EQ CopyInsertEvent (AWAIT.EVENT CopyInsertEvent))
				 do NIL)

          (* * Get the latest selection list)


			      (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								  ))
			      (RESETLST 

          (* * Turn off the caret)


					  (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))

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


					  (COND
					    ((AND (NEQ (CAR SelectedCards)
							   (QUOTE DONE))
						    (NEQ SelectedCards (QUOTE CANCELLED))
						    (NEQ (CAR SelectedCards)
							   (QUOTE *New% Card*)))

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


					      (COND
						((EQ (CAR SelectedCards)
						       (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDDR 
										    SelectedCards)))
						  (NC.ClearMsg InstigatingWindow NIL))
						((OR (NOT (NC.ValidCardP (CAR SelectedCards)))
						       (NULL (APPLY* SelectionPredicate
									 (CAR SelectedCards))))
                                                             (* Does this card match the slection predicate)
						  (NC.PrintMsg InstigatingWindow T 
								 "*** Invalid selection. ***"
								 (CHARACTER 13))
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDR 
										    SelectedCards))))
						(T           (* A valid selection.)
						   (NC.ClearMsg InstigatingWindow NIL)))

          (* * Print the results in the prompt window)


					      (NC.PrintMsg InstigatingWindow NIL
							     (COND
							       (Msg (CONCAT Msg (CHARACTER 13)))
							       (T ""))
							     "Items selected:  ")
					      (for Card in (REVERSE SelectedCards)
						 do
						  (NC.PrintMsg InstigatingWindow NIL (
								   NC.RetrieveTitle Card)
								 ",  ")
						  (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))))))
)
(* * Change to NCGRAPHCARD)

(FILESLOAD (FROM {QV}<NOTECARDS>1.3K>NEXT>)
	   NCGRAPHCARD)
(DEFINEQ

(NC.GraphCardMiddleButtonFn
  [LAMBDA (GraphNode GraphWindow)                            (* Randy.Gobbel "14-Nov-86 16:42")

          (* IF Selection in progress, then pressing a node gets its destination ID if its actually a note card node.
	  Otherwise, jump to normal button processing for an link icon)



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



          (* * fgh 11/14/85 Isn't this obsolete????????)



          (* * rht&pmi 11/14/86: No longer does stupid NC.SpecialBrowserMiddleButtonFn stuff.)


    (LET ((LinkIcon (fetch (GRAPHNODE NODELABEL) of GraphNode)))
         (if [AND (NC.LinkIconImageObjP LinkIcon)
		      (NOT (OR (KEYDOWNP (QUOTE LSHIFT))
				   (KEYDOWNP (QUOTE RSHIFT))
				   (KEYDOWNP (QUOTE CTRL))
				   (KEYDOWNP (QUOTE COPY))
				   (KEYDOWNP (QUOTE DELETE))
				   (KEYDOWNP (QUOTE MOVE]
	     then (NC.LinkIconMiddleButtonFn LinkIcon GraphWindow)
	   else NIL])

(NC.GraphCardLeftButtonFn
  [LAMBDA (GraphNode GraphWindow)                            (* Randy.Gobbel "14-Nov-86 16:42")

          (* * If this is a node containing a link icon, then do: IF Selection in progress, then pressing a node gets its 
	  destination ID if its actually a note card node. Otherwise, bring up the note card pointed to by the node.)



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



          (* * fgh 11/14/85 Isn't this obsolete??????)



          (* * rht&pmi 11/14/86: No longer does stupid pushcopy stuff.)


    (LET ((LinkIcon (fetch (GRAPHNODE NODELABEL) of GraphNode)))
         (if [AND (NC.LinkIconImageObjP LinkIcon)
		      (NOT (OR (KEYDOWNP (QUOTE LSHIFT))
				   (KEYDOWNP (QUOTE RSHIFT))
				   (KEYDOWNP (QUOTE CTRL))
				   (KEYDOWNP (QUOTE COPY))
				   (KEYDOWNP (QUOTE DELETE))
				   (KEYDOWNP (QUOTE MOVE]
	     then (NC.EditNoteCard (fetch (Link DestinationCard) of (
									 NC.FetchLinkFromLinkIcon
									      LinkIcon)))
	   else NIL])
)
(PUTPROPS RHTPATCH152 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1040 7057 (NC.MakeLink 1050 . 7055)) (7092 18073 (NC.SelectNoteCards 7102 . 18071)) (
18169 20362 (NC.GraphCardMiddleButtonFn 18179 . 19216) (NC.GraphCardLeftButtonFn 19218 . 20360)))))
STOP