This chapter provides reference material for the clipboard API defined in Clipboard.h
. It covers:
Clipboard Data Structures
ClipboardFormatType Enum
Purpose
The ClipboardFormatType
enum specifies the type of data to add to the clipboard or retrieve from the clipboard.
Prototype
enum clipboardFormats { clipboardText, clipboardInk, clipboardBitmap };
typedef enum clipboardFormats ClipboardFormatType;
Constants
-
clipboardText
- Textual data. This is the most commonly used clipboard.
-
clipboardInk
- Reserved.
-
clipboardBitmap
- Bitmap data.
Comments
Clipboards for each type of data are separately maintained. That is, if you add a string of text to the clipboard, then add a bitmap, then ask to retrieve a clipboardText
item from the clipboard, you will receive the string you added before the bitmap; the bitmap does not overwrite textual data and vice versa.
Clipboard Functions
ClipboardAddItem Function
Purpose
Add the item passed to the specified clipboard. Replaces the current item (if any) of that type.
Declared In
Clipboard.h
Prototype
void ClipboardAddItem ( const ClipboardFormatType format, const void *ptr, UInt16 length )
Parameters
-
→
format
- Text, ink, bitmap, etc. See
ClipboardFormatType
. -
→
ptr
- Pointer to the item to place on the clipboard.
-
→
length
- Size in bytes of the item to place on the clipboard.
Returns
Comments
The clipboard makes a copy of the data that you pass to this function. Thus, you may free any data that you've passed to the clipboard without destroying the contents of the clipboard. You may also add constant data or stack-based data to the clipboard.
See Also
ClipboardAppendItem Function
Purpose
Append data to the item on the clipboard.
Declared In
Clipboard.h
Prototype
Err ClipboardAppendItem( const ClipboardFormatType format, const void *ptr, UInt16 length )
Parameters
-
→
format
- Text, ink, bitmap, etc. See
ClipboardFormatType
. This function is intended to be used only for theclipboardText
format. -
→
ptr
- Pointer to the data to append to the item on the clipboard.
-
→
length
- Size in bytes of the data to append to the clipboard.
Returns
0 upon success or memErrNotEnoughSpace
if there is not enough space to append the data to the clipboard.
Comments
This function differs from ClipboardAddItem()
in that it does not overwrite data already on the clipboard. It allows you to create a large text item on the clipboard from several small disjointed pieces. When other applications retrieve the text from the clipboard, it's retrieved as a single unit.
This function simply appends the specified item to the item already on the clipboard without attempting to parse the format. It's assumed that you'll call it several times over a relatively short interval and that no other application will attempt to retrieve text from the clipboard before your application is finished appending.
Compatibility
Implemented only if 3.2 New Feature Set is present.
ClipboardGetItem Function
Purpose
Return the handle of the contents of the clipboard of a specified type and the length of a clipboard item.
Declared In
Clipboard.h
Prototype
MemHandle ClipboardGetItem( const ClipboardFormatType format, UInt16 *length )
Parameters
-
→
format
- Text, ink, bitmap, etc. See
ClipboardFormatType
. -
←
length
- The length in bytes of the clipboard item is returned here.
Returns
Comments
The handle returned is a handle to the actual clipboard chunk. It is not suitable for passing to any API that modifies memory (such as FldSetTextHandle()
). Consider this to be read-only access to the chunk. Copy the contents of the clipboard to your application's own storage as soon as possible and use that reference instead of the handle returned by this function.
Don't free the handle returned by this function; it is freed when a new item is added to the clipboard.
Text retrieved from the clipboard does not have a null terminator. You must use the length
parameter to determine the length in bytes of the string you've retrieved.