Important: The information in this document is obsolete and should not be used for new development.
Converting Data Between the TextEdit Scrap and the Scrap
If your application uses TextEdit to handle text in its document windows, then use TextEdit routines instead of Scrap Manager routines to implement editing commands. For example, use the TextEdit proceduresTECut
,TECopy
, andTEPaste
to implement the Cut, Copy, and Paste commands. Upon receiving a suspend event, useTEToScrap
instead ofPutScrap
to write the data to the scrap (always callZeroScrap
before callingTEToScrap
). Upon receiving a resume event, useTEFromScrap
instead ofGetScrap
to read data from the scrap. TextEdit uses a private scrap and handles copying data between its private scrap and the scrap. See Inside Macintosh: Text for complete information on TextEdit.To implement the Cut (or Copy) commands, use the TextEdit routines
TECut
(orTECopy
) instead ofZeroScrap
andPutScrap
. The TextEdit proceduresTECut
andTECopy
copy the data in the current selection to TextEdit's private scrap. For example, Listing 2-8 shows an application-defined routine that uses TextEdit to
help handle the application's Cut command (assuming the application uses TextEdit to handle text editing in its document windows).Listing 2-8 Using TextEdit to handle the Cut command
PROCEDURE DoCutOrCopyCmd (cut: Boolean); VAR window: WindowPtr; windowType: Integer; myData: MyDocRecHnd; teHand: TEHandle; BEGIN window := FrontWindow; windowType := MyGetWindowType(window); IF windowType = kMyDocWindow THEN BEGIN myData := MyDocRecHnd(GetWRefCon(window)); teHand := myData^^.editRec; IF cut THEN TECut(teHand) ELSE TECopy(teHand); END ELSE IF windowType <> kNIL THEN BEGIN {window is a dialog box} IF cut THEN DialogCut(window) ELSE DialogCopy(window); END; END;Use the TextEdit routineTEPaste
instead ofGetScrap
to read the data to paste. TheTEPaste
procedure reads the data to paste from TextEdit's private scrap. Listing 2-9 shows an application-defined routine that uses TextEdit to help handle the application's Paste command (assuming the application uses TextEdit to handle text editing in its document windows).Listing 2-9 Using TextEdit to handle the Paste command
PROCEDURE DoPasteCmd; VAR window: WindowPtr; windowType: Integer; myData: MyDocRecHnd; teHand: TEHandle; BEGIN window := FrontWindow; windowType := MyGetWindowType(window); IF windowType = kMyDocWindow THEN BEGIN myData := MyDocRecHnd(GetWRefCon(window)); teHand := myData^^.editRec; TEPaste(teHand); END ELSE IF windowType <> kNIL THEN BEGIN {window is a dialog box} DialogPaste(window); END; END;Upon receiving a suspend event, useZeroScrap
and then the TextEdit procedureTEToScrap
to copy data from TextEdit's private scrap to the scrap. Upon receiving a resume event, use the TextEdit procedureTEFromScrap
to copy data from the scrap to TextEdit's private scrap. As with any other private scrap and as explained in "Handling Resume Events" on page 2-25, either you can choose to immediately copy the data from the scrap to TextEdit's private scrap or you can delay performing the copy until the data is needed. See Listing 2-5 on page 2-24 and Listing 2-6 on page 2-25 for code that uses this approach.