(FILECREATED "30-Jun-86 14:24:00" {QV}<NOTECARDS>1.3K>FGHPATCH082.;3 15991  

      changes to:  (VARS FGHPATCH082COMS)
		   (FNS NC.GRAPHERCOPYBUTTONEVENTFN NC.TrackCursorInGrapherWindow NC.MakeGraphCard 
			NC.BringUpGraphCard NC.RelayoutBrowserCard NC.InsideGrapherNodeP)

      previous date: "30-Jun-86 13:13:02" {QV}<NOTECARDS>1.3K>FGHPATCH082.;1)


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

(PRETTYCOMPRINT FGHPATCH082COMS)

(RPAQQ FGHPATCH082COMS ((* * Fixes for bug %# 92 -- implements shift-selection from Graph Cards)
			  (* * New functions for NCGRAPHCARD)
			  (FNS NC.GRAPHERCOPYBUTTONEVENTFN NC.InsideGrapherNodeP 
			       NC.TrackCursorInGrapherWindow)
			  (* * Redefined fns from NCGRAPHCARD and NCBROWSERCARD)
			  (FNS NC.MakeGraphCard NC.BringUpGraphCard NC.RelayoutBrowserCard)))
(* * Fixes for bug %# 92 -- implements shift-selection from Graph Cards)

(* * New functions for NCGRAPHCARD)

(DEFINEQ

(NC.GRAPHERCOPYBUTTONEVENTFN
  (LAMBDA (Window)                                           (* fgh: "30-Jun-86 13:16")

          (* * Handle a COPYBUTTONEVENT in a NC Grapher window. If the button is down over a node and the TTY PROCESS is a 
	  selecting cards process, process it as such, otherwise do the standard grapher copy button event fn of 
	  copyinserting he whole graph.)



          (* * fgh 6/30/86 First created.)


    (LET ((Graph (WINDOWPROP Window (QUOTE GRAPH)))
	  InNode PositionAndLastState TTYWindow (Position (CONS 0 0)))
         (if (NOT (AND (WINDOWP (SETQ TTYWindow (PROCESSPROP (TTY.PROCESS)
									 (QUOTE WINDOW))))
			     (WINDOWPROP TTYWindow (QUOTE SelectingCards))))
	     then 

          (* * The current TTY PROCESS is not a selecting cards process -- just do what grapher normally does.)


		    (GRAPHERCOPYBUTTONEVENTFN Window)
	   else 

          (* * We want to handle this special for NoteCards to allow shift-select of link icons in the graph)



          (* * First track the cursor until its let up)


		  (SETQ PositionAndLastState (NC.TrackCursorInGrapherWindow Window Graph)) 

          (* * Cursor up -- determine what to do)


		  (if (NULL (CAR PositionAndLastState))
		      then 

          (* * Let up outside the window -- get out of here)


			     NIL
		    else 

          (* * Find the node the mouse was when the buttons were let up -- if any)


			   (SETQ InNode (for GraphNode in (fetch (GRAPH GRAPHNODES)
								   of Graph)
					     thereis (NC.InsideGrapherNodeP
							 (PROGN (replace (POSITION XCOORD)
								     of Position
								     with (LASTMOUSEX Window))
								  (replace (POSITION YCOORD)
								     of Position
								     with (LASTMOUSEY Window))
								  Position)
							 GraphNode)))
			   (if (OR (NULL InNode)
				       (NULL (NC.LinkIconImageObjP (fetch (GRAPHNODE NODELABEL)
									  of InNode))))
			       then 

          (* * Let up innside the window, but not in a node. Or the Node is not a LinkIcon node. Do the standard COPYINSERTFN
	  for GRAPHER)


				      (COPYINSERT (GRAPHEROBJ (COPYGRAPH Graph)))
			     else 

          (* * Let up inside a node, must want to select it.)


				    (COPYINSERT (fetch (GRAPHNODE NODELABEL) of InNode))))))))

(NC.InsideGrapherNodeP
  (LAMBDA (Position Node)                                    (* fgh: "30-Jun-86 13:08")

          (* * Is position inside of graphernode Node)



          (* * fgh 6/30/86 First created.)


    (LET ((Left (GN/LEFT Node))
	  (Bottom (GN/BOTTOM Node)))
         (AND (GEQ (fetch (POSITION XCOORD) of Position)
		       Left)
		(LEQ (fetch (POSITION XCOORD) of Position)
		       (PLUS Left (fetch (GRAPHNODE NODEWIDTH) of Node)))
		(GEQ (fetch (POSITION YCOORD) of Position)
		       Bottom)
		(LEQ (fetch (POSITION YCOORD) of Position)
		       (PLUS Bottom (fetch (GRAPHNODE NODEHEIGHT) of GraphNode)))
		Node))))

(NC.TrackCursorInGrapherWindow
  (LAMBDA (Window Graph)                                     (* fgh: "30-Jun-86 13:44")

          (* * Follow the cursor around a graph window inverting nodes that its in until the mouse buttons are let up.)



          (* * fgh 6/30/86 First created.)


    (LET (Buttons NewInNode InNode (Position (CONS 0 0))
		  (DS (WINDOWPROP Window (QUOTE DSP))))
         (until (MOUSESTATE UP)
	    do 

          (* * Track the cursor until the mouse is up)


		 (SETQ Buttons LASTMOUSEBUTTONS)
		 (SETQ InNode NewInNode) 

          (* * Figure out if in a node)


		 (SETQ NewInNode (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
				      thereis (NC.InsideGrapherNodeP (PROGN
									   (replace (POSITION
											XCOORD)
									      of Position
									      with (LASTMOUSEX
										       Window))
									   (replace (POSITION
											YCOORD)
									      of Position
									      with (LASTMOUSEY
										       Window))
									   Position)
									 GraphNode)))

          (* * Uninvert the old node, invert the new node.)


		 (if (NEQ InNode NewInNode)
		     then (AND InNode (FLIPNODE InNode DS))
			    (AND NewInNode (FLIPNODE NewInNode DS))))

          (* * Univert anything that needs it)


         (AND NewInNode (FLIPNODE NewInNode DS))

          (* * Return a record of the mouse location at button up and the last mouse button that were dowen before let up)


         (CONS (CONS (LASTMOUSEX Window)
			 (LASTMOUSEY Window))
		 Buttons))))
)
(* * Redefined fns from NCGRAPHCARD and NCBROWSERCARD)

(DEFINEQ

(NC.MakeGraphCard
  (LAMBDA (Card Title NoDisplayFlg)                          (* fgh: "30-Jun-86 13:32")

          (* * Creates a StructEdit card. Alot like a graph card except that it allows editing of underlying NC structure, 
	  and doesn't allow an "insertlink" operation in title bar menu.)



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



          (* * rht 5/5/86: Replaced call to NC.SetupTitleBarMenu with Install calls.)



          (* * fgh 6/30/86 Added NC.GRAPHERCOPYBUTTONEVENTFN to SHOWGRAPH call)


    (LET (Window Graph CardType)
         (SETQ Graph (create GRAPH
				 GRAPH.ADDNODEFN ←(FUNCTION NC.GraphAddNodeFn)
				 GRAPH.DELETENODEFN ←(FUNCTION NC.GraphDeleteNodeFn)
				 GRAPH.ADDLINKFN ←(FUNCTION NC.GraphAddLinkFn)
				 GRAPH.DELETELINKFN ←(FUNCTION NC.GraphDeleteLinkFn)
				 GRAPH.MOVENODEFN ←(FUNCTION NC.GraphMoveNodeFn)
				 GRAPH.FONTCHANGEFN ←(FUNCTION NC.GraphFontChangeFn)))
         (NC.SetSubstance Card Graph)
         (COND
	   ((NOT NoDisplayFlg)
	     (SETQ Window (CREATEW (NC.DetermineDisplayRegion Card NIL)
				       (OR Title "Untitled")))
	     (SETQ CardType (NC.RetrieveType Card))
	     (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
			  (FUNCTION NC.GraphCardMiddleButtonFn)
			  T T (FUNCTION NC.GRAPHERCOPYBUTTONEVENTFN))
	     (WINDOWADDPROP Window (QUOTE SHRINKFN)
			      (FUNCTION NC.GraphCardShrinkFn))
	     (NC.InstallTitleBarButtonEventFn Window (FUNCTION NC.GraphTitleBarButtonEventFn))
	     (NC.InstallTitleBarLeftMenu Window CardType)
	     (NC.InstallGraphTitleBarMiddleMenu Window CardType)))
         (OR Window Card))))

(NC.BringUpGraphCard
  (LAMBDA (Card Substance Region/Position)                   (* fgh: "30-Jun-86 13:32")

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



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



          (* * rht 5/5/86: Now calls NC.InstallTitleBarButtonEventFn, NC.InstallTitleBarLeftMenu, and 
	  NC.InstallGraphTitleBarMiddleMenu instead of NC.SetupTitleBarMenu.)



          (* * fgh 6/30/86 Added NC.GRAPHERCOPYBUTTONEVENTFN to SHOWGRAPH call)


    (LET (Region Title GraphWindow IconWindow CardType)
         (COND
	   ((SETQ GraphWindow (NC.FetchWindow Card))
	     (AND (WINDOWP (WINDOWPROP GraphWindow (QUOTE ICONFOR)))
		    (SETQ GraphWindow (EXPANDW GraphWindow)))
	     (TOTOPW GraphWindow)
	     (RPTQ 2 (FLASHW GraphWindow)))
	   (T (SETQ GraphWindow (SHOWGRAPH Substance (CREATEW (NC.DetermineDisplayRegion
								      Card Region/Position)
								    (NC.RetrieveTitle Card))
					       (FUNCTION NC.GraphCardLeftButtonFn)
					       (FUNCTION NC.GraphCardMiddleButtonFn)
					       NIL T (FUNCTION NC.GRAPHERCOPYBUTTONEVENTFN)))
	      (SETQ CardType (NC.RetrieveType Card))
	      (WINDOWADDPROP GraphWindow (QUOTE SHRINKFN)
			       (FUNCTION NC.GraphCardShrinkFn))
	      (NC.InstallTitleBarButtonEventFn GraphWindow (FUNCTION 
						   NC.GraphTitleBarButtonEventFn))
	      (NC.InstallTitleBarLeftMenu GraphWindow CardType)
	      (NC.InstallGraphTitleBarMiddleMenu GraphWindow CardType)))
     GraphWindow)))

(NC.RelayoutBrowserCard
  (LAMBDA (Window)                                           (* fgh: "30-Jun-86 13:41")

          (* * Called from the middle button of a browser or structeditbrowser card. This lays out and displays the browser, 
	  but does not recompute the nodes.)



          (* * rht 11/17/85: updated to handle new notefile and card objects.)



          (* * rht 2/7/86: Now gets browser format, etc. via fetch/set fns.)



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



          (* * rht 5/8/86: Added calls to rig title bar properly.)



          (* * fgh 6/30/86 Added NC.GRAPHERCOPYBUTTONEVENTFN to SHOWGRAPH call)


    (PROG (Card RootCards RootNodeIDs OldToNodePairs Graph GraphNodes BrowserFormat 
		  DropVirtualNodesFlg SpecialBrowserSpecs)
	    (NC.PrintMsg Window T "Laying out graph ...")
	    (SETQ Card (NC.CoerceToCard Window))
	    (SETQ RootCards (NC.FetchBrowserRoots Card))
	    (SETQ BrowserFormat (OR (NC.FetchBrowserFormat Card)
					(QUOTE (LATTICE))))
                                                             (* If user wants *GRAPH* format, i.e. virtual nodes 
							     eliminated, then set the flag)
	    (if (FMEMB NC.*Graph*BrowserFormat BrowserFormat)
		then (SETQ DropVirtualNodesFlg T))
	    (SETQ SpecialBrowserSpecs (OR (CAR (NC.FetchSpecialBrowserSpecs Card))
					      (create SPECIALBROWSERSPECS)))
	    (SETQ GraphNodes (fetch (GRAPH GRAPHNODES) of (SETQ Graph (WINDOWPROP
								    Window
								    (QUOTE GRAPH)))))
                                                             (* Create hash array if haven't already.)
	    (NC.GetBrowserHashArray Card Graph)            (* check graph node size against image box size.)
	    (NC.GraphLinkIconUpdateCheck Card Window Graph NIL)

          (* Save the TONODES values of the nodes so can replace later after LAYOUTGRAPH call. At the same time, throw away 
	  all the link params info in TONODES field.)


	    (SETQ OldToNodePairs (for Node in GraphNodes bind ToNodes eachtime (BLOCK)
				      collect (PROG1 (CONS (fetch (GRAPHNODE NODEID)
								    of Node)
								 (APPEND (SETQ ToNodes
									     (fetch (GRAPHNODE
											TONODES)
										of Node))))
							 (replace (GRAPHNODE TONODES) of Node
							    with (for ToNode in ToNodes
								      collect
								       (if (EQ (CAR ToNode)
										   LINKPARAMS)
									   then (CADR ToNode)
									 else ToNode))))))
	    (SETQ RootNodeIDs (for RootCard in RootCards collect (NC.GetBrowserNodeID
									   Card RootCard)))
	    (NC.SetPropListDirtyFlg Card T)                (* Layout graph, including as roots any non-virtual 
							     nodes with no from nodes to avoid disconnected 
							     graphs.)
	    (SETQ Graph (if GraphNodes
			      then (LAYOUTGRAPH GraphNodes
						    (for Node in GraphNodes bind NodeID
						       eachtime (BLOCK)
								  (SETQ NodeID (fetch
								      (GRAPHNODE NODEID)
										    of Node))
						       when
							(OR (AND (NULL (fetch (GRAPHNODE
											FROMNODES)
										of Node))
								     (NOT (LISTP NodeID)))
							      (FMEMB NodeID RootNodeIDs))
						       collect NodeID)
						    (SUBST (QUOTE LATTICE)
							     NC.*Graph*BrowserFormat BrowserFormat)
						    (fetch (SPECIALBROWSERSPECS Font) of 
									      SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS MotherD)
						       of SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS PersonalD)
						       of SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS FamilyD)
						       of SpecialBrowserSpecs))
			    else (create GRAPH)))

          (* Replace the TONODES fields of the Graph nodes by their pre-LAYOUTGRAPH values. Also throw away any nodes that 
	  didn't appear in the old graph.)


	    (if Graph
		then (replace (GRAPH GRAPHNODES) of Graph
			  with (for Node in (fetch (GRAPH GRAPHNODES) of Graph)
				    bind AssocPair eachtime (BLOCK)
				    when (SETQ AssocPair (FASSOC (fetch (GRAPHNODE NODEID)
									  of Node)
								       OldToNodePairs))
				    collect (replace (GRAPHNODE TONODES) of Node
						 with (CDR AssocPair))
					      (if DropVirtualNodesFlg
						  then (replace (GRAPHNODE NODEBORDER)
							    of Node with NIL))
                                                             (* Throw away LINKPARAMS junk from the FromNodes that 
							     LAYOUTGRAPH stuck in.)
					      (replace (GRAPHNODE FROMNODES) of Node
						 with (for FromNode in (fetch (GRAPHNODE
											FROMNODES)
										of Node)
							   eachtime (BLOCK)
							   collect (if (EQ (CAR FromNode)
										 LINKPARAMS)
									 then (CADR FromNode)
								       else FromNode)))
					      Node)))
	    (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
			 (FUNCTION NC.GraphCardMiddleButtonFn)
			 NIL T (FUNCTION NC.GRAPHERCOPYBUTTONEVENTFN))

          (* * Have to reset windowprops since SHOWGRAPH messes with them.)

                                                             (* Disable the old-style right button grapher editor 
							     menu.)
	    (WINDOWPROP Window (QUOTE RIGHTBUTTONFN)
			  (FUNCTION NC.BrowserRightButtonFn))
	    (WINDOWADDPROP Window (QUOTE REPAINTFN)
			     (FUNCTION NC.BrowserRepaintFn)
			     T)
	    (WINDOWPROP Window (QUOTE SCROLLFN)
			  (FUNCTION NC.BrowserScrollFn))
	    (WINDOWPROP Window (QUOTE RESHAPEFN)
			  (FUNCTION NC.BrowserReshapeFn))
	    (NC.SetSubstance Card (WINDOWPROP Window (QUOTE GRAPH)))
	    (NC.MarkCardDirty Card)
	    (NC.InstallTitleBarButtonEventFn Window (FUNCTION NC.GraphTitleBarButtonEventFn))
	    (NC.ClearMsg Window T))))
)
(PUTPROPS FGHPATCH082 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (961 5995 (NC.GRAPHERCOPYBUTTONEVENTFN 971 . 3525) (NC.InsideGrapherNodeP 3527 . 4282) (
NC.TrackCursorInGrapherWindow 4284 . 5993)) (6057 15909 (NC.MakeGraphCard 6067 . 7836) (
NC.BringUpGraphCard 7838 . 9532) (NC.RelayoutBrowserCard 9534 . 15907)))))
STOP