Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 2 - Scrap Manager / Using the Scrap Manager


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 procedures TECut, TECopy, and TEPaste to implement the Cut, Copy, and Paste commands. Upon receiving a suspend event, use TEToScrap instead of PutScrap to write the data to the scrap (always call ZeroScrap before calling TEToScrap). Upon receiving a resume event, use TEFromScrap instead of GetScrap 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 (or TECopy) instead of ZeroScrap and PutScrap. The TextEdit procedures TECut
and TECopy 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 routine TEPaste instead of GetScrap to read the data to paste. The TEPaste 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, use ZeroScrap and then the TextEdit procedure TEToScrap to copy data from TextEdit's private scrap to the scrap. Upon receiving a resume event, use the TextEdit procedure TEFromScrap 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.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996