(FILECREATED "22-Apr-87 21:35:10" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH241.;3 10574  

      changes to:  (FNS NC.BuildMakeDocInspector NC.MakeExternalSketchCopy)
		   (VARS RHTPATCH241COMS)

      previous date: "19-Apr-87 20:57:21" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH241.;1)


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

(PRETTYCOMPRINT RHTPATCH241COMS)

(RPAQQ RHTPATCH241COMS ((* * Fixes bug #517: Sketch scaling lost when grabbed into a document.)
			  (FILES (FROM NOTECARDSNEXT)
				 KOTOSKETCHPATCHES)
			  (DECLARE: FIRST (P (LOAD? (NC.FindFile (QUOTE NCDOCUMENTCARD)))))
			  (* * NOTE: NC.Files should be changed to include KOTOSKETCHPATCHES. Also 
			     should copy KOTOSKETCHPATCHES over to notecards>1.3k>.)
			  (* * Change to NCSKETCHCARD)
			  (FNS NC.MakeExternalSketchCopy)
			  (* * Change to NCDOCUMENTCARD)
			  (FNS NC.DumpExportableCardToDoc NC.BuildMakeDocInspector)
			  (* * Fix to minor bug in message printing.)
			  (* * Change to NCLISTCARD)
			  (FNS NC.EvaluateListCardSubstance)))
(* * Fixes bug #517: Sketch scaling lost when grabbed into a document.)

(FILESLOAD (FROM NOTECARDSNEXT)
	   KOTOSKETCHPATCHES)
(DECLARE: FIRST 
(LOAD? (NC.FindFile (QUOTE NCDOCUMENTCARD)))
)
(* * NOTE: NC.Files should be changed to include KOTOSKETCHPATCHES. Also should copy 
KOTOSKETCHPATCHES over to notecards>1.3k>.)

(* * Change to NCSKETCHCARD)

(DEFINEQ

(NC.MakeExternalSketchCopy
  (LAMBDA (SketchViewerOrImageObj)                           (* rht: "22-Apr-87 20:54")

          (* * Make a copy of the sketch smashing any link icons.)



          (* * rht 4/22/87: Now installs proper grid, scale and region viewed in the copy. Now returns a sketch imageobj.)


    (LET ((SketchCopy (SKETCH.ADD.ELEMENT NIL NIL)))
         (SKETCH.COPY.ELEMENTS (SKETCH.ELEMENTS.OF.SKETCH (INSURE.SKETCH SketchViewerOrImageObj)
							      )
				 SketchCopy)
         (NC.ExternalizeLinkIconsInSketch SketchCopy)
         (MAKE.IMAGE.OBJECT.OF.SKETCH SketchCopy (SKETCH.REGION.VIEWED SketchViewerOrImageObj)
					(SKETCH.VIEWER.SCALE SketchViewerOrImageObj)
					(SKETCH.VIEWER.GRID SketchViewerOrImageObj)))))
)
(* * Change to NCDOCUMENTCARD)

(DEFINEQ

(NC.DumpExportableCardToDoc
  (LAMBDA (Card DocCard DocStream CurSection SubSectionNum HeadingsFromFileboxes TitlesFromNoteCards 
		BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks CardType)
                                                             (* rht: "22-Apr-87 20:52")

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


    (DECLARE (GLOBALVARS NC.DocBackPtrLinkLabel))
    (LET ((CardStream (NC.FetchSubstance Card))
	  (DocObj (TEXTOBJ DocStream))
	  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)))
		(NCP.LocalGlobalLink NC.DocBackPtrLinkLabel DocCard Card (QUOTE END)
				       (create LINKDISPLAYMODE
						 ATTACHBITMAPFLG ← T)))
         (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 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.)
				       (NCP.LocalGlobalLink LinkLabel DocCard ToCard (QUOTE
								END)))
			    (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)))

(NC.BuildMakeDocInspector
  (LAMBDA (MainWin)                                          (* rht: "22-Apr-87 21:34")

          (* * Build and dislay an inspector window on the parameters for making documents.)



          (* * rht 10/3/85: No longer brings up prompt window.)



          (* * rht 4/22/87: Now tries to put inspect window in the right place so ATTACHWINDOW won't have to move it.)


    (DECLARE (GLOBALVARS NC.MakeDocParameters))
    (LET ((Region (WINDOWREGION MainWin))
	  InspectWindow)
         (SETQ InspectWindow (INSPECTW.CREATE (QUOTE NC.MakeDocParameters)
						  (for Item in NC.MakeDocParameters
						     collect (CAR Item))
						  (FUNCTION GETPROP)
						  NIL "Use left button to change values." NIL
						  (FUNCTION NC.InspectorTitleCommandFn)
						  "MakeDocument Parameters"
						  (FUNCTION NC.MakeDocInspectorSelectionFn)
						  (CREATEPOSITION (fetch (REGION LEFT)
								       of Region)
								    (ADD1 (fetch (REGION TOP)
									       of Region)))
						  NIL))
         (ATTACHWINDOW InspectWindow MainWin (QUOTE TOP)
			 (QUOTE LEFT)
			 (QUOTE LOCALCLOSE))
         (WINDOWPROP InspectWindow (QUOTE NoteCardsMakeDocInspector)
		       T)
     InspectWindow)))
)
(* * Fix to minor bug in message printing.)

(* * Change to NCLISTCARD)

(DEFINEQ

(NC.EvaluateListCardSubstance
  (LAMBDA (Card Message InterestedWindow)                    (* rht: "19-Apr-87 19:54")

          (* * Evaluate the contents of a list card.)



          (* * rht 4/2/87: Added InterestedWindow arg.)



          (* * rht 4/19/87: Now clears InterestedWindow before printing.)


    (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
    (if Message
	then (NC.PrintMsg InterestedWindow T Message))
    (ERSETQ (for Item in (NCP.CardSubstance Card) do (ERRORSET Item)))))
)
(PUTPROPS RHTPATCH241 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1412 2220 (NC.MakeExternalSketchCopy 1422 . 2218)) (2258 9796 (
NC.DumpExportableCardToDoc 2268 . 8456) (NC.BuildMakeDocInspector 8458 . 9794)) (9880 10492 (
NC.EvaluateListCardSubstance 9890 . 10490)))))
STOP