[futurebasic] Re: [FB] Append a String to the Clipboard in Carbon

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2002 : Group Archive : Group : All Groups

From: Alain Pastor <pixmix@...>
Date: Sun, 16 Jun 2002 15:20:06 +0200
Ken Shmidheiser wrote:

> ---- code snipped ------
> 
> Alain,
> 
> Thanks for the modifications. They undoubtedly will be more stable
> than the rough demo I posted, particularly in the areas of memory
> allocation and error checking.
> 
> Let me give a little rationale for my experiment with containers:
> 
> As jonathan noted earlier in this thread,  the OS X clipboard is a
> complicated beast capable of holding an assorted array of data
> flavors.
> 
> Your approach is solid based on long-standing FB tradition, but it
> relies on edit fields and ZTEXT which automatically limit the scrap
> to 32k, and to text-only clips.
> 
> It strikes me that in the world of OS X, where anything from QT video
> to PDF files may be on the clipboard, we need to begin exploring
> other methods to massage larger scrap sizes of assorted flavors. The
> container approach may not be the best-- or even viable-- but I'm
> used to stumbling around in the dark.
> 
> As always, thanks for your valuable insights and elegant code. I'm
> learning more each day.
> 
Actually, the limitation you are speaking about is a Toolbox
limitation with edit fields. Besides your code using containers
suffers from the same limitation.
With both methods, nothing stops you , except available memory that
is, from dealing with scrap sizes greater than 32K. Of course, you may
need to find a way to display that info to the user other than the one
shown in the demo code. 

Now, if you still want to use containers, I would suggest that you
make your functions in local mode passing the container as a
parameter. Here is an old piece of code of mine that shows how to do
this. Caution it is not carbonized. The short piece of code shows that
we can store a picture (actually anything we wish) in a container.


BEGIN GLOBALS
DIM AS CONTAINER gC
END GLOBALS

LOCAL MODE
LOCAL FN ClipToContainer( @Caddr AS PTR, type AS OSType, @offset AS
^LONG )
IF Caddr.nil& = _nil THEN Caddr.nil& = FN NewHandle(0)
END FN = FN GetScrap( [Caddr], type, #offset )


LOCAL MODE
LOCAL FN ContainerToClip( @Caddr AS PTR, type AS OSType )
LONG IF Caddr.nil&
LONG IF FN GetHandleSize( Caddr.nil& )
LONG IF FN ZeroScrap = _noErr
HLock( Caddr.nil& )
LONG IF FN PutScrap(FN GetHandleSize( Caddr.nil& ), type, [Caddr.nil&]
) = _noErr
type = FN UnloadScrap
END IF
HUnlock( Caddr.nil& )
END IF
END IF
END IF
END FN


LOCAL FN testReadClip
DIM AS LONG @ offSet

SELECT 
CASE FN GetScrap( _nil ,_"TEXT", offset ) > 0
FN ClipToContainer( gC, _"TEXT", offset )
PRINT gC
CASE FN GetScrap( _nil, _"PICT", offset ) > 0
FN ClipToContainer( gC, _"PICT", offset )
IF [@gC] THEN PICTURE, [@gC]
END SELECT

END FN

LOCAL FN testWriteClip
DIM AS HANDLE theHndl
DIM AS RECT   r

PRINT "This is a drawn text ( a picture )"
SetRect( r, 0, 0, 300, 100)
gC = &USR GETPICT (r )
FN ContainerToClip( gC, _"PICT" )

// unrem below to test with ASCII data
/*
gC = "This is some ASCII text"
FN ContainerToClip( gC, _"TEXT" )
*/

END FN

WINDOW 1


FN testWriteClip
BEEP : cls : delay _sec * 2
FN testReadClip

DO
HANDLEEVENTS
UNTIL _nil


-- 
Cheers,

Alain