NS BASIC Tech Note                                     March 8, 1998

How to use the Clipboard
--------------------------------------------------------------------------
Clipboard functions work from both NS BASIC and NewtCard. They require
Newton OS 2.1.

1. Putting something on the Clipboard: setClipboard(clipBoardDataFrame)

To put something onto the clipboard, you need to set up a frame with
certain slots in it, and call the setClipBoard() function.

clipboardDataFrame.label: A string containing the name that the clipboard
item should be displayed with.

clipboardDataFrame.types: An array containing an array with a label
identifiying the type of data. (optional)

clipboardDataFrame.bounds: Set to {}.

clipboardDataFrame.data: The data to put on the clipboard. It can be of
any data type.

When putting data onto the Clipboard, it's important to do an
ensureInternal() function on the data, so the data on the clipboard is a
true copy of the data, and not just pointers to data in your program.

If you want put something on the clipboard to paste into Notes or Works,
set types to [['text]], and data to [["text to put onto clipboard"]].

Example:

10 clipBoardDataFrame={}
20 clipBoardDataFrame.label="My Data"
30 clipBoardDataFrame.types=[['myProgram]]
40 clipBoardDataFrame.bounds={}
50 clipBoardDataFrame.data="This is the data I'm saving to the clipboard."
60 setClipBoard(ensureInternal(clipBoardDataFrame))

A hilited clipboard item labeled "My Data" should appear on the edge of
your screen.

To clear the clipboard, use

100 setClipboard(nil)




2. Getting something from the Clipboard: getClipboard(clipBoardDataFrame)

This function recalls the data from the clipboard. It returns the frame
that was written out in setClipBoard().

If you are getting a clipboard item that was written by Notes or Works,
the type slot will contain [['text]], and the text will be in
data[0][0].text.

10 getclipBoard(clipBoardDataFrame)
20 if clipBoardDataFrame.type[0][0]<>'myProgram then
30   print "Data not for this program"
40 else
50   print clipboardDataFrame.data
60   setClipboard(nil)
60 end if

run

This is the data I'm saving to the clipboard.




3. Putting program code on the clipboard

Use the LIST command to put program code onto the clipboard.

list 100,200,"clipboard"

will put the statements from 100 to 200 onto the clipboard. To put your
entire program on the clipboard, type

list ,,"Clipboard"

You can also select LIST ,,"Clipboard" from the Command popup. Selecting
code and dragging it to the side is not supported. Warning: since
clipboard items are stored in memory, putting programs on the clipboard
may cause out of memory errors if they are too large.



4. Getting program code from the clipboard

Use the ENTER command to take program code from the clipboard and insert
it into the current program.

enter "clipboard"

A progress box will display as the lines are entered. You can also select
ENTER "Clipboard" from the Command popup. Dragging clipboard items into
the program editor is not supported, but may still work depending on your
configuration.