[ont.micro.mac] Hacking the Text Edit scrap

info-mac@utcsrgv.UUCP (info-mac) (07/11/84)

Date: 10 Jul 1984 1104-PDT
Subject: Hacking the Text Edit scrap
From: Mike Schuster <uw-beaver!MIKES@CIT-20.ARPA>
To: info-mac@SUMEX-AIM.ARPA

The Text Edit routines use a scrap whose length and handle are located
in the low memory global area.  The length of the scrap is a short at
absolute 2736.  The handle to the scrap is a long at absolute 2740.
Here is a useful C structure:

  typedef struct
     {
     short length;	/* length of text edit scrap */
     short filler;	/* what is this for? seems to be -1 always */
     Handle handle;	/* handle to text edit scrap */
     } TEGloRec;
  typedef TEGloRec *TEGloPtr;
  TEGloPtr TEGlo;

The variable TEGlo is initialized via

  TEGlo = (TEGloPtr) 2736;

The routine TEInit initializes TEGlo.length to 0 and TEGlo.handle to
NewHandle(0).  The routines TECut and TECopy set TEGlo.length to the
length of the selected text and set TEGlo.handle to point to a copy of
the selected text.

If you are using the TE scrap as a private scrap, here are some things
to remember:
   1) Be sure to squirrel away a copy of the TE scrap before opening a
      dialog box containing editable text, since the scrap might be
      modified (for example, SFPutFile).
   2) Be sure to establish a convention on the location of the 'true'
      clipboard.  Here is one that seems to work:
         When an application window is active, the clipboard is contained
         in TE scrap.  When a system desk accessory window is active, or
         when no windows are open, the clipboard is contained in the 
         Scrap Manager scrap.
      With this convention, I perform the following TE scrap -- SM scrap 
      transfers:
         a) when no windows are open, and an application window is opened
	    (SM scrap -> TE scrap).
         b) when an application window is closed leaving no opened windows
	    (TE scrap -> SM scrap).
         c) when an application window is deactivated or closed and a desk 
            accessory window is activated or opened (TE scrap -> SM scrap).
         d) when a desk accessory window is deactivated or closed and an 
	    application window is activated or opened (SM scrap -> TE scrap).
         e) when an application window is active upon ExitToShell
	    (TE scrap -> SM scrap)
      You can use the changeFlag in the modifiers field of the next
      event to catch some of the cases c) and d).  Be aware that no 
      deactivation event, and hence no changeFlag occurs when a window is 
      closed.  I have been forcing the clipboard scrap to disk to avoid 
      multiple copied during these operations.  Be sure to check for
      SM errors (such as disk locked or write protected, etc).
   3) Be careful with cutting and pasting long selections.  I have seen
      cases where a TERecord was left in an inconsistent state after a
      TEPaste.  I suspect that TE routines fail to handle MemError
      conditions.  On the other hand, it maybe a bug in my program.
      I'm currently reverse engineering TE to find out whats going on.
      Preliminary results support my conjecture.

Mike
(mikes@cit-20, mikes@cit-vax)
-------