(FILECREATED "18-Feb-87 15:43:31" {SUMEX-AIM}PS:<TMAX.SOURCES>ENDNOTE.;4 15652  

      changes to:  (FNS NOTE.BUTTONEVENTINFN)

      previous date: "18-Feb-87 10:11:49" {SUMEX-AIM}PS:<GILMURRAY.LISP>ENDNOTE.;6)


(* Copyright (c) 1987 by Leland Stanford Junior University. All rights reserved.)

(PRETTYCOMPRINT ENDNOTECOMS)

(RPAQQ ENDNOTECOMS ((* Developed under support from NIH grant RR-00785.)
		      (* Written by Frank Gilmurray and Sami Shaio.)
		      (FNS ADD.ENDNOTE INSERT.ENDNOTES INSERT.ENDNOTES.TEXT DELETE.ENDNOTES 
			   NOTESREGIONP SET.ENDNOTE.STYLE MAP.ENDNOTE.LOOKS GET.ENDNOTE.FONTS)
		      (FNS ENDNOTEP NOTE.PUTFN NOTE.GETFN NOTE.BUTTONEVENTINFN)
		      (RECORDS ENDNOTEFONTS)
		      (* * Allow user to edit Endnote text in another TEdit window.)
		      (FNS AUX.TEDIT AUX.TEDIT.AFTERQUITFN AUX.TEDIT.TITLEMENUFN)
		      (* * Delimit text between two markers known as REGION MARKERS.)
		      (FNS REGMARKOBJ REGMARKOBJP REGMARK.DISPLAYFN REGMARK.IMAGEBOXFN REGMARK.PUTFN 
			   REGMARK.GETFN REGMARK.BUTTONEVENTINFN)
		      (RECORDS REGMARKOBJ)))



(* Developed under support from NIH grant RR-00785.)




(* Written by Frank Gilmurray and Sami Shaio.)

(DEFINEQ

(ADD.ENDNOTE
  (LAMBDA (STREAM WINDOW)                                    (* fsg "17-Feb-87 10:47")

          (* * Insert an ENDNOTE ImageObject as a superscript. Displayed as a number when updated.)


    (LET ((NOBJ (NUMBEROBJ 'NOTE)))
         (TEDIT.INSERT.OBJECT NOBJ STREAM)
         (COND
	   ((UPDATE? WINDOW)
	     (UPDATE.NUMBEROBJS WINDOW 'ENDNOTEP))
	   (T NIL))
         (replace (NUMBEROBJ NUMBER.TEXT) of (fetch OBJECTDATUM of NOBJ)
	    with (TEDIT.GETINPUT STREAM "Endnote text:"))
         (TEDIT.PROMPTPRINT STREAM "" T))))

(INSERT.ENDNOTES
  (LAMBDA (STREAM WINDOW)                                    (* fsg "18-Feb-87 09:38")

          (* * Inserts text of endnotes at the end of the TEdit document. The text is inserted between two Region marking 
	  imageobjs.)


    (LET* ((TEXTOBJ (TEXTOBJ STREAM))
	   (LIST.OF.ENDNOTES (TSP.LIST.OF.OBJECTS TEXTOBJ 'ENDNOTEP))
	   (CARETPOSITION (fetch CH# of (TEDIT.GETSEL STREAM))))
          (DELETE.ENDNOTES STREAM)
          (COND
	    (LIST.OF.ENDNOTES (TEDIT.PROMPTPRINT STREAM 
						  "Inserting notes at the end of the document..."
						   T)
			      (TEDIT.INSERT.OBJECT (REGMARKOBJ 'ENDNOTES
								   'Endnotes-START)
						     STREAM
						     (ADD1 (fetch TEXTLEN of TEXTOBJ)))
			      (TEDIT.LOOKS STREAM '(PROTECTED ON)
					     (fetch TEXTLEN of TEXTOBJ)
					     1)
			      (TEDIT.INSERT STREAM (CONCAT (CHARACTER (CHARCODE EOL))
							       "Notes"
							       (CHARACTER (CHARCODE EOL)))
					      (ADD1 (fetch TEXTLEN of TEXTOBJ))
					      (fetch (ENDNOTEFONTS TITLE.FONT)
						 of (GET.ENDNOTE.FONTS WINDOW))
					      T)
			      (INSERT.ENDNOTES.TEXT STREAM TEXTOBJ LIST.OF.ENDNOTES)
			      (TEDIT.INSERT.OBJECT (REGMARKOBJ 'ENDNOTES
								   'Endnotes-END)
						     STREAM
						     (ADD1 (fetch TEXTLEN of TEXTOBJ)))
			      (TEDIT.LOOKS STREAM '(PROTECTED ON)
					     (fetch TEXTLEN of TEXTOBJ)
					     1)
			      (TEDIT.PROMPTPRINT STREAM "done")
			      (TEDIT.NORMALIZECARET TEXTOBJ (TEDIT.SETSEL STREAM CARETPOSITION 1))
			      )
	    (T NIL)))))

(INSERT.ENDNOTES.TEXT
  (LAMBDA (STREAM TEXTOBJ LIST.OF.ENDNOTES)                  (* fsg " 7-Jan-87 14:31")

          (* * Here to print the text of each endnote.)


    (LET ((TEXTLOOKS (fetch (ENDNOTEFONTS TEXT.FONT) of (GET.ENDNOTE.FONTS WINDOW))))
         (for ENDNOTEOBJ in LIST.OF.ENDNOTES
	    do (LET ((NUMSTRING (MKSTRING (fetch (NUMBEROBJ NUMSTRING)
						 of (fetch OBJECTDATUM of (CAR ENDNOTEOBJ)))))
		       (TEXT (fetch (NUMBEROBJ NUMBER.TEXT) of (fetch OBJECTDATUM
									of (CAR ENDNOTEOBJ)))))
		      (TEDIT.INSERT STREAM NUMSTRING (ADD1 (fetch TEXTLEN of TEXTOBJ))
				      TEXTLOOKS T)
		      (TEDIT.INSERT STREAM (CONCAT " " TEXT (CHARACTER (CHARCODE EOL)))
				      (ADD1 (fetch TEXTLEN of TEXTOBJ))
				      TEXTLOOKS T))))))

(DELETE.ENDNOTES
  (LAMBDA (STREAM)                                           (* fsg "18-Feb-87 09:11")

          (* * Delete the Endnotes, i.e. delete the start/end REGMARK ImageObjects and all the text between them.)


    (LET* ((TEXTOBJ (TEXTOBJ STREAM))
	   (NOTEMARKER.LIST (TSP.LIST.OF.OBJECTS TEXTOBJ 'NOTESREGIONP))
	   (NOTES.START (CADAR NOTEMARKER.LIST))
	   (NOTES.END (CADADR NOTEMARKER.LIST)))
          (AND NOTEMARKER.LIST (TEDIT.DELETE STREAM NOTES.START (IDIFFERENCE (ADD1 NOTES.END)
										   NOTES.START))))))

(NOTESREGIONP
  (LAMBDA (IMOBJ)                                            (* fsg "26-Jan-87 09:41")
    (AND (REGMARKOBJP IMOBJ)
	   (EQ (fetch REGION.USE of (fetch OBJECTDATUM of IMOBJ))
		 'ENDNOTES))))

(SET.ENDNOTE.STYLE
  (LAMBDA (STREAM WINDOW)                                    (* fsg " 9-Jan-87 09:18")

          (* * Set the font of the ENDNOTE number, title, or text.)


    (LET ((NOTE.FONTS (GET.ENDNOTE.FONTS WINDOW))
	  (NOTE.TYPE (MENU (create MENU
				       TITLE _ "ENDNOTE Fonts"
				       CENTERFLG _ T
				       ITEMS _ '(Number Title Text))))
	  OLD.FONT NEW.FONT)
         (AND NOTE.TYPE (PROGN (SETQ OLD.FONT (SELECTQ NOTE.TYPE
							       (Number (fetch (ENDNOTEFONTS 
										      NUMBER.FONT)
									  of NOTE.FONTS))
							       (Title (fetch (ENDNOTEFONTS 
										       TITLE.FONT)
									 of NOTE.FONTS))
							       (Text (fetch (ENDNOTEFONTS TEXT.FONT)
									of NOTE.FONTS))
							       NIL))
				   (TEDIT.PROMPTPRINT STREAM (CONCAT "Change Endnote " NOTE.TYPE 
									 " font "
									 (LIST (ABBREVIATE.FONT
										   OLD.FONT))
									 " to...")
							T)
				   (SETQ NEW.FONT (FONTCREATE (GET.TSP.FONT WINDOW OLD.FONT)))
				   (COND
				     ((NEQ OLD.FONT NEW.FONT)
				       (SELECTQ NOTE.TYPE
						  (Number (replace (ENDNOTEFONTS NUMBER.FONT)
							     of NOTE.FONTS with NEW.FONT))
						  (Title (replace (ENDNOTEFONTS TITLE.FONT)
							    of NOTE.FONTS with NEW.FONT))
						  (Text (replace (ENDNOTEFONTS TEXT.FONT)
							   of NOTE.FONTS with NEW.FONT))
						  NIL)
				       (AND (EQ NOTE.TYPE 'Number)
					      (MAP.ENDNOTE.LOOKS STREAM NEW.FONT)))
				     (T NIL))
				   (TEDIT.PROMPTPRINT STREAM "" T))))))

(MAP.ENDNOTE.LOOKS
  (LAMBDA (STREAM NUMBERFONT)                                (* fsg " 9-Jan-87 09:09")

          (* * Here to update the ENDNOTE looks. Only the ENDNOTE superscript numbers are updated.)


    (LET ((LIST.OF.NOTES (TSP.LIST.OF.OBJECTS (TEXTOBJ STREAM)
						'ENDNOTEP)))
         (AND LIST.OF.NOTES (PROGN (TEDIT.PROMPTPRINT STREAM "Updating ENDNOTE Number looks..." 
							    T)
				       (for NOTE/CH# in LIST.OF.NOTES
					  do (TEDIT.LOOKS STREAM NUMBERFONT (CADR NOTE/CH#)
							      1))
				       (TEDIT.PROMPTPRINT STREAM "done."))))))

(GET.ENDNOTE.FONTS
  (LAMBDA (WINDOW)                                           (* fsg " 5-Jan-87 10:40")

          (* * Setup the default ENDNOTE fonts for number, title, and text.)


    (OR (WINDOWPROP WINDOW 'ENDNOTE.FONTS)
	  (PROGN (WINDOWPROP WINDOW 'ENDNOTE.FONTS
				 (create ENDNOTEFONTS
					   NUMBER.FONT _ GP.DefaultFont
					   TITLE.FONT _ GP.DefaultFont
					   TEXT.FONT _ GP.DefaultFont))
		   (WINDOWPROP WINDOW 'ENDNOTE.FONTS)))))
)
(DEFINEQ

(ENDNOTEP
  (LAMBDA (IMOBJ)                                            (* ss: " 2-Jul-85 16:51")
    (AND (NUMBEROBJP IMOBJ)
	   (EQ (fetch USE of (fetch OBJECTDATUM of IMOBJ))
		 'NOTE))))

(NOTE.PUTFN
  (LAMBDA (NUMBEROBJ STREAM WINDOW)                        (* fsg "28-Jan-87 13:48")

          (* * Used to put a numberobj that is functioning as an endnote.)


    (replace (NUMBEROBJ FONT) of (fetch OBJECTDATUM of NUMBEROBJ)
       with (for NOTEFONT in (GET.ENDNOTE.FONTS WINDOW) collect (LIST.FONT.PROPS NOTEFONT)
		     ))
    (PRIN4 (LIST 'Endnote
		     (IMAGEOBJPROP NUMBEROBJ 'TAG)
		     (fetch OBJECTDATUM of NUMBEROBJ))
	     STREAM)))

(NOTE.GETFN
  (LAMBDA (NEWOBJ USE/TEXT WINDOW)                           (* fsg " 8-Jan-87 10:19")

          (* * Used to get a numberobj that is functioning as an endnote.)


    (WINDOWPROP WINDOW 'ENDNOTE.FONTS
		  (for NOTEFONT in (fetch (NUMBEROBJ FONT) of USE/TEXT)
		     collect (FONTCREATE NOTEFONT)))
    (replace (NUMBEROBJ FONT) of USE/TEXT with NIL)
    (replace OBJECTDATUM of NEWOBJ with USE/TEXT)
    NEWOBJ))

(NOTE.BUTTONEVENTINFN
  (LAMBDA (NUMBEROBJ STREAM)                               (* fsg "18-Feb-87 11:16")

          (* * Bring up another TEdit window where user can edit the text of an Endnote.)


    (MENU (create MENU
		      TITLE _ 'Endnotes% Menu
		      CENTERFLG _ T
		      ITEMS _ '((Edit% Endnote (AUX.TEDIT NUMBEROBJ
							  (CONCAT "Endnote #"
								  (fetch NUMSTRING of
									 (fetch OBJECTDATUM of 
										NUMBEROBJ)))
							  STREAM))
				(Tag% Endnote (XREF.TAG.OBJECT NUMBEROBJ STREAM)))))))
)
[DECLARE: EVAL@COMPILE 

(RECORD ENDNOTEFONTS (NUMBER.FONT TITLE.FONT TEXT.FONT))
]
(* * Allow user to edit Endnote text in another TEdit window.)

(DEFINEQ

(AUX.TEDIT
  (LAMBDA (IMOBJ TITLE STREAM)                               (* fsg "20-Jan-87 15:46")

          (* * Open a TEdit window where the user can view/edit the text of the selected Endnote.)


    (LET* ((MAINWINDOW (\TEDIT.MAINW STREAM))
	   (AUXWINDOW (CREATEW (WINDOWPROP MAINWINDOW 'AUXW.REGION)
				 TITLE)))
          (WINDOWPROP AUXWINDOW 'MAIN.WINDOW
			MAINWINDOW)
          (WINDOWPROP AUXWINDOW 'NOTE.IMAGEOBJ
			IMOBJ)
          (TEDIT (MKSTRING (fetch (NUMBEROBJ NUMBER.TEXT) of (fetch OBJECTDATUM
									  of IMOBJ)))
		   AUXWINDOW NIL '(AFTERQUITFN AUX.TEDIT.AFTERQUITFN TITLEMENUFN 
					       AUX.TEDIT.TITLEMENUFN)))))

(AUX.TEDIT.AFTERQUITFN
  (LAMBDA (AUXWINDOW)                                        (* fsg "20-Jan-87 15:56")

          (* * Here AFTER user finished with Endnote TEdit process.)


    (LET ((MAINWINDOW (WINDOWPROP AUXWINDOW 'MAIN.WINDOW)))
         (WINDOWPROP MAINWINDOW 'AUXW.REGION
		       (WINDOWPROP AUXWINDOW 'REGION))
         (GIVE.TTY.PROCESS MAINWINDOW)
         (TEDIT.NORMALIZECARET (TEXTOBJ MAINWINDOW)))))

(AUX.TEDIT.TITLEMENUFN
  (LAMBDA (AUXWINDOW)                                        (* fsg "20-Jan-87 15:49")

          (* * Here when left or middle button hit in title bar.)


    (LET ((ITEM (MENU (create MENU
				  CENTERFLG _ T
				  ITEMS _ '(Save% Changes Abort% Changes)))))
         (AND ITEM (PROGN (SELECTQ ITEM
					 (Save% Changes (replace (NUMBEROBJ NUMBER.TEXT)
							   of (fetch OBJECTDATUM
								   of (WINDOWPROP AUXWINDOW
										      'NOTE.IMAGEOBJ))
							   with (COERCETEXTOBJ (TEXTSTREAM
										     AUXWINDOW)
										   'STRINGP)))
					 NIL)
			      (TEDIT.QUIT (TEXTSTREAM AUXWINDOW)))))))
)
(* * Delimit text between two markers known as REGION MARKERS.)

(DEFINEQ

(REGMARKOBJ
  (LAMBDA (USE MARKING)                                      (* ss: "15-Jul-85 11:54")
    (LET ((NEWOBJ (IMAGEOBJCREATE (create REGMARKOBJ
					      REGION.USE _ USE
					      MARKING _ MARKING)
				    (IMAGEFNSCREATE (FUNCTION REGMARK.DISPLAYFN)
						      (FUNCTION REGMARK.IMAGEBOXFN)
						      (FUNCTION REGMARK.PUTFN)
						      (FUNCTION REGMARK.GETFN)
						      (FUNCTION NILL)
						      (FUNCTION REGMARK.BUTTONEVENTINFN)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)
						      (FUNCTION NILL)))))
         (IMAGEOBJPROP NEWOBJ 'TYPE
			 'REGMARKOBJ)
     NEWOBJ)))

(REGMARKOBJP
  (LAMBDA (IMOBJ)                                            (* ss: "12-Jul-85 15:04")
    (AND IMOBJ (EQ (IMAGEOBJPROP IMOBJ 'TYPE)
		       'REGMARKOBJ))))

(REGMARK.DISPLAYFN
  (LAMBDA (OBJ STREAM)                                       (* fsg "18-Feb-87 09:18")

          (* * REGMARK is just a marker, it doesn't actually display anything.)


    NIL))

(REGMARK.IMAGEBOXFN
  (LAMBDA (OBJ STREAM CURRENTX RIGHTMARGIN)                  (* fsg "17-Feb-87 10:22")

          (* * REGMARK is just a marker, it doesn't actually display anything.)


    (create IMAGEBOX
	      XSIZE _ 0
	      YSIZE _ 0
	      YDESC _ 0
	      XKERN _ 0)))

(REGMARK.PUTFN
  (LAMBDA (MARKOBJ STREAM)                                   (* fsg "28-Jan-87 14:10")
    (PRIN2 (LIST 'Region
		     (IMAGEOBJPROP MARKOBJ 'TAG)
		     (LIST (fetch REGION.USE of (fetch OBJECTDATUM of MARKOBJ))
			     (fetch MARKING of (fetch OBJECTDATUM of MARKOBJ))))
	     STREAM)))

(REGMARK.GETFN
  (LAMBDA (STREAM)                                           (* fsg "28-Jan-87 16:06")
    (OR (WINDOWPROP (PROCESSPROP (THIS.PROCESS)
				       'WINDOW)
			'IMAGEOBJ.MENUW)
	  (TSP.FMMENU (TEXTSTREAM (PROCESSPROP (THIS.PROCESS)
						     'WINDOW))))
    (LET* ((REGMARK.ARGS (CDR (READ STREAM)))
	   (NEWOBJ (APPLY 'REGMARKOBJ
			    (CADR REGMARK.ARGS))))
          (IMAGEOBJPROP NEWOBJ 'TAG
			  (CAR REGMARK.ARGS))
      NEWOBJ)))

(REGMARK.BUTTONEVENTINFN
  (LAMBDA (MARKOBJ STREAM)                                   (* fsg "18-Feb-87 10:07")

          (* * This function is never called because the REGMARK ImageObjects are protected after they are inserted and 
	  anything protected can't be selected.)


    (AND (MOUSESTATE MIDDLE)
	   (LET ((MARKDATUM (fetch OBJECTDATUM of MARKOBJ)))
	        (TEDIT.PROMPTPRINT STREAM (CONCAT "Region used for " (fetch REGION.USE
									    of MARKDATUM)
						      (COND
							((fetch MARKING of MARKDATUM)
							  (CONCAT ", Marker is "
								    (fetch MARKING of MARKDATUM)))
							(T "")))
				     T)))))
)
[DECLARE: EVAL@COMPILE 

(RECORD REGMARKOBJ (REGION.USE MARKING))
]
(PUTPROPS ENDNOTE COPYRIGHT ("Leland Stanford Junior University" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1240 8234 (ADD.ENDNOTE 1252 . 1873) (INSERT.ENDNOTES 1877 . 3628) (INSERT.ENDNOTES.TEXT
 3632 . 4538) (DELETE.ENDNOTES 4542 . 5135) (NOTESREGIONP 5139 . 5384) (SET.ENDNOTE.STYLE 5388 . 7086)
 (MAP.ENDNOTE.LOOKS 7090 . 7727) (GET.ENDNOTE.FONTS 7731 . 8231)) (8236 10115 (ENDNOTEP 8248 . 8477) (
NOTE.PUTFN 8481 . 9034) (NOTE.GETFN 9038 . 9547) (NOTE.BUTTONEVENTINFN 9551 . 10112)) (10280 12228 (
AUX.TEDIT 10292 . 11019) (AUX.TEDIT.AFTERQUITFN 11023 . 11495) (AUX.TEDIT.TITLEMENUFN 11499 . 12225)) 
(12302 15479 (REGMARKOBJ 12314 . 13131) (REGMARKOBJP 13135 . 13328) (REGMARK.DISPLAYFN 13332 . 13548) 
(REGMARK.IMAGEBOXFN 13552 . 13859) (REGMARK.PUTFN 13863 . 14228) (REGMARK.GETFN 14232 . 14759) (
REGMARK.BUTTONEVENTINFN 14763 . 15476)))))
STOP
