(FILECREATED "15-Jul-87 17:33:46" {QV}<NOTECARDS>1.3KNEXT>RGPATCH053.;1 13488  

      changes to:  (VARS RGPATCH053COMS)
		   (FNS NC.LinkIconImageBoxFn))


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

(PRETTYCOMPRINT RGPATCH053COMS)

(RPAQQ RGPATCH053COMS ((* * rg&pmi 7/15/87 recreates changes lost in peggy's patch to make links to 
			    deleted cards turn into deleted link icons)
			 (* * changes to NCLINKS)
			 (FNS NC.LinkIconImageBoxFn)))
(* * rg&pmi 7/15/87 recreates changes lost in peggy's patch to make links to deleted cards 
turn into deleted link icons)

(* * changes to NCLINKS)

(DEFINEQ

(NC.LinkIconImageBoxFn
  [LAMBDA (ImageObj ImageStream CurrentX RightMargin DummyArg DisplayType Title Label LinkIconString 
		    Icon LinkIconStrings)                    (* Randy.Gobbel "15-Jul-87 17:30")

          (* * rht 9/20/84: Now scales result before returning by proper amount depending on stream type.
	  e.g. for PRESS and INTERPRESS.)



          (* * rht 11/13/84: In computation of XSIZE, extra width is figured using characters in the font, "nn", rather than 
	  absolute pixel count.)



          (* * rht 2/9/85: Now uses new displaymode format.)



          (* * rht 5/9/86: Note that RightMargin non-nil signals a TEdit stream.)



          (* * rht & fgh 5/9/86: Massive hacking to display coords, etc.)



          (* * rht 5/10/86: Rearranged order of expressions a bit and added arg to call to NC.FetchLinkIconAttachedBitMap in 
	  order to get a bitmap with correct height for the box we're drawing.)



          (* * rht 8/7/86: Now passes Scale argument to NC.FetchLinkIconAttachedBitMap. Also uses the Title and Label args if
	  non-nil. If not, then recomputes them more sensibly.)



          (* * rht 8/25/85: Fixed improperly placed comment.)



          (* * rg 11/18/86: Added TotalEdgeSpaceY to local vars declaration)



          (* * pmi 2/6/87: Overhauled to accommodate multi-line link icons)



          (* * pmi 2/27/87: Fixed problems with only displaying the attached bitmap and with displaying null titles)



          (* * pmi 5/1/87: added missing local vars declarations.)



          (* * pmi&rg 7/15/87 recreated peggy's patch to deal w/ links to deleted cards)


    (DECLARE (GLOBALVARS NC.LinkIconMultiLineMode NC.LinkIconMaxWidth NC.LinkIconSpaceInnerX 
			     NC.LinkIconSpaceOuterX NC.LinkIconAttachBitmapFlg NC.LinkIconSpaceInnerY 
			     NC.LinkIconSpaceOuterY NC.LinkIconSpaceInterLine NC.LinkIconBorderWidth 
			     NC.LinkIconShowLinkTypeFlg NC.LinkIconShowTitleFlg))
    (RESETLST (RESETSAVE NIL (BQUOTE (DSPFONT , (DSPFONT NC.LinkIconFont ImageStream)
						      , ImageStream)))
		(PROG ((Link (NC.FetchLinkFromLinkIcon ImageObj))
			 (Scale (DSPSCALE NIL ImageStream))
			 (StringWidth 0)
			 Card Font FontHeight ShowTitleFlg AttachBitmapFlg LinkDisplayMode 
			 ApproxBoxWidth ScaledIconHeight ScaledIconWidth NumberOfLines XSize YSize 
			 ScaledLinkIconMaxWidth ScaledBorderWidth ScaledSpaceInnerX ScaledSpaceOuterX 
			 ScaledSpaceInnerY ScaledSpaceOuterY ScaledSpaceInterLine 
			 HalfScaledSpaceInterLine TotalEdgeSpaceY)
		        (SETQ Font (DSPFONT NIL ImageStream))
		        (SETQ FontHeight (FONTHEIGHT Font))

          (* * Check for bad Link)


		        (if [NOT (AND (NC.ValidCardP (fetch (Link SourceCard) of Link))
					    (NC.ValidCardP (fetch (Link DestinationCard)
								of Link]
			    then 

          (* * Delete the offending link, smash its image object into a "Deleted" image object, and return by displaying it.)


				   (RETURN (NC.DeletedLinkImageBoxFn ImageObj ImageStream)))

          (* * Determine what type of Display to do)


		        (OR DisplayType (SETQ DisplayType (fetch (Link DisplayMode)
								 of Link)))
		        (SETQ ShowTitleFlg (fetch (LINKDISPLAYMODE SHOWTITLEFLG) of DisplayType)
			  )
		        (SETQ Card (if (EQ ShowTitleFlg (QUOTE SOURCE))
					 then (fetch (Link SourceCard) of Link)
				       else (fetch (Link DestinationCard) of Link)))
		        (SETQ LinkDisplayMode (fetch (LINKDISPLAYMODE SHOWLINKTYPEFLG)
						   of DisplayType))
		        (SETQ AttachBitmapFlg (fetch (LINKDISPLAYMODE ATTACHBITMAPFLG)
						   of DisplayType))
		        (SETQ AttachBitmapFlg (if (EQ AttachBitmapFlg (QUOTE FLOAT))
						    then NC.LinkIconAttachBitmapFlg
						  else AttachBitmapFlg))

          (* * Construct the text for the link icon)


		        [if (NOT LinkIconString)
			    then (OR Title (SETQ Title
					   (if (AND ShowTitleFlg (OR (NEQ ShowTitleFlg
										  (QUOTE FLOAT))
									   NC.LinkIconShowTitleFlg))
					       then (NC.RetrieveTitle Card)
					     else NIL)))
				   [OR Label (SETQ Label (AND (if (EQ LinkDisplayMode
										(QUOTE FLOAT))
									then 
								       NC.LinkIconShowLinkTypeFlg
								      else LinkDisplayMode)
								    (fetch (Link Label)
								       of Link]
				   (SETQ LinkIconString (CONCAT (COND
								      (Label (CONCAT "<" Label ">"))
								      (T ""))
								    (COND
								      ((AND Label Title)
									" ")
								      (T ""))
								    (OR Title ""]

          (* * Make temporaries of scaled vars.)


		        (SETQ ScaledLinkIconMaxWidth (TIMES Scale NC.LinkIconMaxWidth))
		        (SETQ ScaledBorderWidth (TIMES Scale NC.LinkIconBorderWidth))
		        (SETQ ScaledSpaceInnerX (TIMES Scale NC.LinkIconSpaceInnerX))
		        (SETQ ScaledSpaceOuterX (TIMES Scale NC.LinkIconSpaceOuterX))
		        (SETQ ScaledSpaceInnerY (TIMES Scale NC.LinkIconSpaceInnerY))
		        (SETQ ScaledSpaceOuterY (TIMES Scale NC.LinkIconSpaceOuterY))
		        (SETQ ScaledSpaceInterLine (TIMES Scale NC.LinkIconSpaceInterLine))
		        (SETQ HalfScaledSpaceInterLine (IQUOTIENT ScaledSpaceInterLine 2))

          (* *)


		        (SETQ TotalEdgeSpaceY (PLUS ScaledBorderWidth ScaledSpaceOuterY 
							ScaledSpaceInnerY))
		        (SETQ YSize (PLUS TotalEdgeSpaceY TotalEdgeSpaceY FontHeight))

          (* * Set up the icon, if displayed)


		        (if AttachBitmapFlg
			    then 

          (* * Attached icon)



          (* * Use an estimate of the width to tell if the box contains more than one line of text)


				   [if NC.LinkIconMultiLineMode
				       then 

          (* * Multi-line link icons are enabled)


					      (SETQ ApproxBoxWidth (PLUS ScaledSpaceOuterX 
									     ScaledBorderWidth 
									     ScaledSpaceInnerX
									     (STRINGWIDTH 
										   LinkIconString 
											    Font)
									     ScaledSpaceInnerX 
									     ScaledBorderWidth 
									     ScaledSpaceOuterX))

          (* * The image box must be calculated)


					      [if (GREATERP ApproxBoxWidth ScaledLinkIconMaxWidth)
						  then     (* Calculate Multi-line icon)
							 (SETQ ScaledIconHeight
							   (PLUS ScaledBorderWidth 
								   ScaledSpaceInnerY FontHeight 
								   HalfScaledSpaceInterLine))
							 (SETQ Icon (
							     NC.FetchLinkIconAttachedBitMap Card 
										 ScaledIconHeight 
											    Scale))
							 (SETQ ScaledIconHeight
							   (TIMES Scale (BITMAPHEIGHT Icon)))
							 (SETQ ScaledIconWidth (TIMES
							     Scale
							     (BITMAPWIDTH Icon)))
						else       (* Calculate Single line icon)
						       (SETQ ScaledIconHeight
							 (PLUS ScaledBorderWidth ScaledSpaceInnerY 
								 FontHeight ScaledSpaceInnerY 
								 ScaledBorderWidth))
						       (SETQ Icon (NC.FetchLinkIconAttachedBitMap
							   Card ScaledIconHeight Scale))
						       (SETQ ScaledIconHeight (TIMES
							   Scale
							   (BITMAPHEIGHT Icon)))
						       (SETQ ScaledIconWidth (TIMES Scale
											(BITMAPWIDTH
											  Icon)))

          (* * Now see if total width, including the icon, will still fit if this is a Single line)


						       (if (AND (NOT (STREQUAL LinkIconString 
										       ""))
								    (GREATERP (PLUS 
										   ApproxBoxWidth 
										  ScaledIconWidth)
										
									   ScaledLinkIconMaxWidth))
							   then 
                                                             (* Now it doesn't fit. Calculate Multi-line icon)
								  (SETQ ScaledIconHeight
								    (PLUS ScaledBorderWidth 
									    ScaledSpaceInnerY 
									    FontHeight 
									 HalfScaledSpaceInterLine))
								  (SETQ Icon (
								   NC.FetchLinkIconAttachedBitMap
								      Card ScaledIconHeight Scale))
								  (SETQ ScaledIconHeight
								    (TIMES Scale (BITMAPHEIGHT
									       Icon)))
								  (SETQ ScaledIconWidth
								    (TIMES Scale (BITMAPWIDTH
									       Icon]
				     else 

          (* * Multi-line link icons are disabled)


					    (SETQ ScaledIconHeight (PLUS ScaledBorderWidth 
									     ScaledSpaceInnerY 
									     FontHeight 
									     ScaledSpaceInnerY 
									     ScaledBorderWidth))
					    (SETQ Icon (NC.FetchLinkIconAttachedBitMap Card 
										 ScaledIconHeight 
											   Scale))
					    (SETQ ScaledIconHeight (TIMES Scale (BITMAPHEIGHT
										Icon)))
					    (SETQ ScaledIconWidth (TIMES Scale (BITMAPWIDTH
									       Icon]
			  else 

          (* * No attached icon)


				 (SETQ Icon NIL)
				 (SETQ ScaledIconHeight 0)
				 (SETQ ScaledIconWidth 0))

          (* * Now determine the actual size of the image box)


		        [if (AND Icon (GREATERP (PLUS ScaledIconWidth ScaledSpaceOuterX 
							      ScaledSpaceOuterX)
						      ScaledLinkIconMaxWidth))
			    then 

          (* If the width of the icon plus the outer x's is greater than the ScaledLinkIconMaxWidth set by the user, set the 
	  box width to ScaledLinkIconMaxWidth)


				   (SETQ XSize ScaledLinkIconMaxWidth)
			  elseif (STREQUAL LinkIconString "")
			    then (if Icon
				       then                (* There is no text to print, so the box width is just
							     the icon width plus the outer x on each side)
					      (SETQ XSize (PLUS ScaledIconWidth ScaledSpaceOuterX 
								    ScaledSpaceOuterX))
				     else 

          (* There is no text or Icon to print, so the box width is just the inner x, border width, and outer x on each side)


					    (SETQ XSize (PLUS ScaledSpaceInnerX ScaledSpaceInnerX 
								  ScaledBorderWidth ScaledBorderWidth 
								  ScaledSpaceOuterX ScaledSpaceOuterX)
					      ))
			  else                             (* Have the text parsed into separate lines)
				 (SETQ LinkIconStrings (NC.CreateLinkIconStrings Link 
										   LinkIconString 
										     Icon ImageStream)
				   )
				 (if LinkIconStrings
				     then (SETQ NumberOfLines (LENGTH LinkIconStrings))
					    (if (GREATERP NumberOfLines 1)
						then (SETQ StringWidth
							 (PLUS (STRINGWIDTH (CAR 
										  LinkIconStrings)
										Font)
								 ScaledIconWidth))
                                                             (* Find the longest string for the width of the box)
						       (for String in (CDR LinkIconStrings)
							  bind PartStringWidth
							  when (GREATERP (SETQ PartStringWidth
									       (STRINGWIDTH String 
											     Font))
									     StringWidth)
							  do (SETQ StringWidth PartStringWidth))
						       (SETQ YSize (PLUS TotalEdgeSpaceY 
									     TotalEdgeSpaceY
									     (TIMES NumberOfLines 
										      FontHeight)
									     (TIMES (SUB1 
										    NumberOfLines)
										      
									     ScaledSpaceInterLine)))
					      else (SETQ StringWidth (PLUS (STRINGWIDTH
										   (CAR 
										  LinkIconStrings)
										   Font)
										 ScaledIconWidth)))
					    (SETQ XSize (MIN (PLUS StringWidth 
									 ScaledSpaceOuterX 
									 ScaledSpaceOuterX 
									 ScaledSpaceInnerX 
									 ScaledSpaceInnerX
									 (if Icon
									     then ScaledBorderWidth
									   else (PLUS 
										ScaledBorderWidth 
										ScaledBorderWidth)))
								 (PLUS (TIMES Scale 
									   ScaledLinkIconMaxWidth)
									 ScaledSpaceOuterX 
									 ScaledSpaceOuterX]
		        (RETURN (create IMAGEBOX
					    XSIZE ← XSize
					    YSIZE ← YSize
					    YDESC ← (COND
					      (RightMargin 
                                                             (* This is in a TEdittextstream)
							   (PLUS (FONTDESCENT Font)
								   TotalEdgeSpaceY))
					      (T 0))
					    XKERN ← 0])
)
(PUTPROPS RGPATCH053 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (642 13407 (NC.LinkIconImageBoxFn 652 . 13405)))))
STOP