Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 UW 5/3/83; site uw-beaver Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!info-mac From: info-mac@uw-beaver (info-mac) Newsgroups: fa.info-mac Subject: Hacking the Text Edit scrap Message-ID: <1178@uw-beaver> Date: Tue, 10-Jul-84 14:23:58 EDT Article-I.D.: uw-beaver>.1178 Posted: Tue Jul 10 14:23:58 1984 Date-Received: Wed, 11-Jul-84 07:11:08 EDT Sender: daemon@uw-beave Organization: U of Washington Computer Science Lines: 63 From: Mike Schuster 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) -------