(FILECREATED " 7-Aug-87 16:48:39" {QV}<NOTECARDS>1.3KNEXT>PMIPATCH056.;2 8021   

      changes to:  (VARS PMIPATCH056COMS)
		   (FNS NC.DumpExportableCardToDoc)

      previous date: " 7-Aug-87 15:34:20" {QV}<NOTECARDS>1.3KNEXT>PMIPATCH056.;1)


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

(PRETTYCOMPRINT PMIPATCH056COMS)

(RPAQQ PMIPATCH056COMS ((DECLARE: FIRST (P (NC.LoadFileFromDirectories (QUOTE NCDOCUMENTCARD))))
			  (* * pmi 8/7/87: Fixes bug %#22: Document card Edit Graph breaks.)
			  (* * Changed in NCDOCUMENTCARD)
			  (FNS NC.DumpExportableCardToDoc)))
(DECLARE: FIRST 
(NC.LoadFileFromDirectories (QUOTE NCDOCUMENTCARD))
)
(* * pmi 8/7/87: Fixes bug %#22: Document card Edit Graph breaks.)

(* * Changed in NCDOCUMENTCARD)

(DEFINEQ

(NC.DumpExportableCardToDoc
  (LAMBDA (Card DocCard DocStream CurSection SubSectionNum HeadingsFromFileboxes TitlesFromNoteCards 
		BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks CardType)
                                                             (* pmi: " 7-Aug-87 16:39")

          (* * Dump the CardID sketch or graph card to the document card DocStream.)



          (* * rht 9/16/85: Now handles cr's around titles using para leading.)



          (* * fgh 11/17/85 Updated to handle card objects and removal of SubstanceTypes.)



          (* * rht 7/31/86: Now can handle other card types than Graph or Sketch based ones, but they must have an 
	  appropriate fn on the ExportSubstanceFn property of the atom. That fn should return either an imageobj or a 
	  textstream.)



          (* * rht 8/11/86: Added ShrunkenFlg so that Card is reshrunk afterwards if necessary.)



          (* * rht 10/15/86: Integrated markM's changes and fixed box numbering.)



          (* * rht 10/31/86: Now uses TEDIT.COPY rather than TEDIT.INCLUDE because the latter loses formatting info.)



          (* * rht 3/26/87: Fixed bug whereby links in sketch cards weren't getting smashed to "external" link icons.
	  Now calls NC.MakeExternalSketchCopy.)



          (* * rht 4/22/87: Now expects NC.MakeExternalSketchCopy to return an imageobj.)



          (* * rht 6/4/87: Now calls NC.MakeLink rather than NCP.LocalGlobalLink and handles computes proper cross-file links
	  mode.)



          (* * pmi 8/7/87: Now "externalizes" graphs so that they won't break when edited once in the document.)


    (DECLARE (GLOBALVARS NC.DocBackPtrLinkLabel))
    (LET ((CardStream (NC.FetchSubstance Card))
	  (DocObj (TEXTOBJ DocStream))
	  (InterestedWindow (NC.CoerceToInterestedWindow DocCard))
	  ShrunkenFlg OldLoc ThingToInsert)
         (NC.AddCRIfNeeded DocStream)
         (SETQ OldLoc (fetch (TEXTOBJ TEXTLEN) of DocObj))
         (AND (NEQ TitlesFromNoteCards (QUOTE NONE))
		(NC.AppendStringToStream DocStream (CONCAT (NC.RetrieveTitle Card))
					   (EQ TitlesFromNoteCards (QUOTE Bold))))
         (AND (FMEMB BuildBackLinks (QUOTE (ToCards ToCardsBoxes)))
		(NC.AddLinkToCard DocCard (NC.MakeLink NIL NC.DocBackPtrLinkLabel Card DocCard
							   (create LINKDISPLAYMODE
								     ATTACHBITMAPFLG ← T)
							   NIL NIL NIL NIL
							   (NC.ComputeCrossFileLinkMode
							     Card
							     (NC.FetchUserDataProp DocCard
										     (QUOTE 
									CrossFileLinkModePropList))
							     InterestedWindow))
				    Card))
         (if (GREATERP (fetch (TEXTOBJ TEXTLEN) of DocObj)
			   OldLoc)
	     then (NC.AddCRIfNeeded DocStream)
		    (NC.ChangeParaLeading DocStream))
         (if (NOT (NC.FetchUserDataProp Card (QUOTE SeenBefore)))
	     then (SETQ ShrunkenFlg (NC.GetShrunkenWin Card))
		    (NC.SetUserDataProp DocCard (QUOTE SeenCards)
					  (CONS Card (NC.FetchUserDataProp DocCard (QUOTE
										 SeenCards))))
		    (NC.SetUserDataProp Card (QUOTE SeenBefore)
					  T)

          (* * Stick an imageobj made from the card into the document. Also might be a textstream computed by the card type's
	  ExportSubstanceFn.)


		    (SETQ ThingToInsert (if (NCP.GraphBasedP CardType)
					      then (GRAPHEROBJ (NC.MakeExternalGraphCopy 
										       CardStream))
					    elseif (NCP.SketchBasedP CardType)
					      then (NC.MakeExternalSketchCopy (OR (
										   NC.FetchWindow
											Card)
										      CardStream))
					    elseif (LET ((ExportSubstanceFn (GETPROP
										CardType
										(QUOTE 
										ExportSubstanceFn))))
						          (AND ExportSubstanceFn (APPLY* 
										ExportSubstanceFn 
										       CardStream)))))
		    (AND CardStream (if (IMAGEOBJP ThingToInsert)
					  then (TEDIT.INSERT.OBJECT ThingToInsert DocStream)
					elseif (TEXTSTREAMP ThingToInsert)
					  then (TEDIT.COPY (TEDIT.SETSEL ThingToInsert 1
									       (fetch TEXTLEN
										  of (TEXTOBJ
											 
										    ThingToInsert)))
							       (TEDIT.SETSEL DocStream
									       (fetch TEXTLEN
										  of DocObj)
									       1
									       (QUOTE RIGHT)))))

          (* * Step through list of notecard imageobjs in the card we're working on and either expand or copy or ignore each 
	  according to values of ExpandEmbeddedLinks and CopyEmbeddedLinks.)


		    (for Link in (CAR (NC.CollectReferences Card NIL NIL NIL))
		       bind LinkLabel ToCard ToCardType ActiveFlg ExpandFlg CopyFlg AlreadyExpanded
		       eachtime (BLOCK)
		       do (SETQ LinkLabel (fetch (Link Label) of Link))
			    (SETQ CopyFlg (OR (EQ CopyEmbeddedLinks (QUOTE ALL))
						  (AND (LISTP CopyEmbeddedLinks)
							 (FMEMB LinkLabel CopyEmbeddedLinks))))
			    (SETQ ExpandFlg (OR (EQ ExpandEmbeddedLinks (QUOTE ALL))
						    (AND (LISTP ExpandEmbeddedLinks)
							   (FMEMB LinkLabel ExpandEmbeddedLinks))))
			    (if (AND (SETQ AlreadyExpanded (NC.FetchUserDataProp
					     (SETQ ToCard (fetch (Link DestinationCard)
							       of Link))
					     (QUOTE SeenBefore)))
					 ExpandFlg)
				then (NC.PrintMsg NIL NIL (NC.RetrieveTitle ToCard)
						      " only expanded once in this cycle."
						      (CHARACTER 13)))
			    (if (OR CopyFlg (AND ExpandFlg AlreadyExpanded))
				then                       (* Copy this link.)
				       (NC.AddLinkToCard DocCard
							   (NC.MakeLink NIL LinkLabel ToCard 
									  DocCard NIL NIL NIL NIL NIL
									  (
								      NC.ComputeCrossFileLinkMode
									    ToCard
									    (NC.FetchUserDataProp
									      DocCard
									      (QUOTE 
									CrossFileLinkModePropList))
									    InterestedWindow))
							   ToCard))
			    (if (AND ExpandFlg (NOT AlreadyExpanded))
				then                       (* Expand this link. Check type and make recursive 
							     call.)
				       (SETQ SubSectionNum
					 (NC.DumpCardToDoc ToCard DocCard DocStream CurSection 
							     SubSectionNum HeadingsFromFileboxes 
							     TitlesFromNoteCards BuildBackLinks 
							     CopyEmbeddedLinks ExpandEmbeddedLinks)))
		       finally (TEDIT.SETSEL DocStream (ADD1 (fetch TEXTLEN of DocObj))
						 0
						 (QUOTE RIGHT)))
		    (NC.SetUserDataProp Card (QUOTE SeenBefore)
					  NIL)
		    (AND ShrunkenFlg (SHRINKW (NC.FetchWindow Card)))
	   else (NC.PrintMsg NIL NIL (NC.RetrieveTitle Card)
				 " only expanded once in this cycle."
				 (CHARACTER 13)))
     SubSectionNum)))
)
(PUTPROPS PMIPATCH056 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (786 7939 (NC.DumpExportableCardToDoc 796 . 7937)))))
STOP