Important: The information in this document is obsolete and should not be used for new development.
Converting Data Between a Private Scrap and the Scrap
If you use a private scrap, you need to copy the data from your private scrap to the scrap upon receiving a suspend event. Upon receiving a resume event, you need to determine whether the contents of the scrap have changed since the previous suspend event. If so, your application must be sure to use the new data in the scrap for the user's next Paste command (unless the user chooses Cut or Copy before choosing Paste). In addition, your application needs to update the contents of its Clipboard window, if necessary.Listing 2-7 shows the application-defined procedure
MyConvertScrap
. This procedure is called either indirectly as a result of a resume event (indicated by thekClipboardToPrivate
, constant) or directly as a result of a suspend event (indicated by thekPrivateToClipboard
constant). If thewhichWay
parameter containskClipboardToPrivate
, then the contents of the scrap have changed. In this
case,MyConvertScrap
usesGetScrap
to read the contents of the scrap. TheMyConvertScrap
procedure checks the scrap for'PICT'
data first, and then for'TEXT'
data if the scrap doesn't contain any data in'PICT'
format.MyConvertScrap
then copies this data to its private scrap.If the
MyConvertScrap
procedure is called as a result of a suspend event, the procedure copies the data from its private scrap to the scrap. It writes the data to the scrap in its own private format, in'PICT'
format, and, if appropriate, in'TEXT'
format.Listing 2-7 Converting data between the scrap and a private scrap
PROCEDURE MyConvertScrap (whichWay: Integer); VAR sizeOfTextData: LongInt; sizeOfPictData: LongInt; offset: LongInt; hDest: Handle; ptrToScrapData: Ptr; length: LongInt; myLongErr: LongInt; BEGIN IF whichWay = kClipboardToPrivate THEN BEGIN {copy scrap to private scrap} sizeOfPictData := GetScrap(NIL, 'PICT', offset); IF sizeOfPictData > 0 THEN BEGIN {get handle to hold data from scrap, GetScrap } hDest := NewHandle(0); { automatically resizes it} HLock(hDest); {put data into memory referenced by hDest handle} sizeOfPictData := GetScrap(hDest, 'PICT', offset); MyCopyToPrivateScrap(hDest); HUnlock(hDest); DisposeHandle(hDest); END ELSE {if no 'PICT' data on scrap, check for 'TEXT'} BEGIN sizeOfTextData := GetScrap(NIL, 'TEXT', offset); IF sizeOfTextData > 0 THEN BEGIN {allocate handle to hold scrap data--GetScrap } hDest := NewHandle(0); { automatically resizes it} HLock(hDest); {put data into memory referenced by hDest handle} sizeOfTextData := GetScrap(hDest, 'TEXT', offset); {copy data to private scrap} MyCopyToPrivateScrap(hDest); HUnlock(hDest); DisposeHandle(hDest); END END; END ELSE BEGIN {copy private scrap into scrap} IF MyGetPrivateScrapSize > 0 THEN {if private scrap } myLongErr := ZeroScrap; { not empty, clear the scrap} ptrToScrapData := NewPtr(kDefaultSize); {retrieve data from private scrap in private format} IF (MyGetScrap('SURF', ptrToScrapData, length) > 0) THEN BEGIN {copy data to the scrap} myLongErr := PutScrap(length, 'SURF', ptrToScrapData); IF myLongErr <> noErr THEN DoError(myLongErr); END; {retrieve data from private scrap in 'PICT' format} IF (MyGetScrap('PICT', ptrToScrapData, length) > 0) THEN BEGIN {copy data to the scrap} myLongErr := PutScrap(length, 'PICT', ptrToScrapData); IF myLongErr <> noErr THEN DoError(myLongErr); END; {retrieve data from private scrap in 'TEXT' format} IF (MyGetScrap('TEXT', ptrToScrapData, length) > 0) THEN BEGIN {copy data to the scrap} myLongErr := PutScrap(length, 'TEXT', ptrToScrapData); IF myLongErr <> noErr THEN DoError(myLongErr); END; DisposePtr(ptrToScrapData); END; END;