[net.sources.mac] __TEScrap.src

dubois@uwmacc.UUCP (Paul DuBois) (12/20/85)

Rascal does not have the "[ Not in ROM ]" routines described in
the Text Edit section of Inside Mac for transferring text back and
forth between the text scrap and the desk scrap (clipboard), so I took
the IMLib stuff posted recently by Andrew Shebanow and adapted the
relevant calls to Rascal.  Thank you, Andrew.

Just compile the source and use it like any other library.

--- cut here ---
Program __TEScrap;

(*
    Non-ROM TextEdit Scrap-handling routines.
    Rascal source written 18 December 1985 by Paul DuBois
*)

Uses __ToolBox, __ToolUtil ;

Const
    TEScrpLength = $0AB0;    (* TWO bytes *)
    TEScrpHandle = $0AB4;

Type
    OSErr = integer;
    Handle = PtrL;

(* these two are lifted from __Memory.src *)

PROCEDURE HLock(h: ptrL); { RegCall(trap $A029,h,,)};
PROCEDURE HUnlock(h: ptrL); { RegCall(trap $A02A,h,,)};    

(*
    Return handle to TextEdit scrap
*)

Func TEScrapHandle (): Handle;
{
    TEScrapHandle := ptrl (TEScrpHandle)^;
};

(*
    Return length of TextEdit scrap
*)

Func TEGetScrapLen (): longint;
{
    TEGetScrapLen := longint (ptrw (TEScrpLength)^);
};

(*
    Set length of TextEdit scrap
*)

Proc TESetScrapLen (len : longint);
{
    ptrw (TEScrpLength)^ := integer (len);
};

(*
    Copy the TextEdit scrap to the desk scrap.  ZeroScrap should
    be called first.
    Actually returns the scrap length, not an OSErr.
*)

Func TEToScrap (): OSErr;
var ScrpHand: Handle; result: longint;
{
    ScrpHand := TEScrapHandle ();
    HLock (ScrpHand);
    result := PutScrap (TEGetScrapLen (), $54455854L (* 'TEXT' *), ScrpHand^);
    HUnlock (ScrpHand);
    if result > 0 then result := 0;
    TEToScrap := result;
};

(*
    Copy the desk scrap into the TextEdit scrap.
    Actually returns the scrap length, not an OSErr.
*)

Func TEFromScrap (): OSErr;
var ScrpHand: ptrl; result, offset: longint;
{
    ScrpHand := TEScrapHandle ();
    result := GetScrap (ScrpHand, $54455854L (* 'TEXT' *), @offset);
    if result > 0 then TESetScrapLen (result);
    TEFromScrap := result;
};

(* end __TEScrap.src *)
-- 
                                                                    |
Paul DuBois     {allegra,ihnp4,seismo}!uwvax!uwmacc!dubois        --+--
                                                                    |
"The voice of the Lord is full of majesty."                         |
                           Psalm 29:4