Framework | HIServices/HIServices.h |
Companion guide | |
Declared in | Pasteboard.h |
The Pasteboard Manager lets you create and manipulate pasteboards, which act as holding containers for data to be transferred from one place to another. Typically you use pasteboards to facilitate copy-and-paste or drag-and-drop operations, but you can use them whenever you need to temporarily store data that will be moved elsewhere.
Note: The Pasteboard Manager supersedes the Scrap Manager and the drag flavor APIs in the Drag Manager, adding greater flexibility in the type and quantity of data to be transferred. Pasteboard Manager pasteboards are also fully compatible with Cocoa pasteboards.
PasteboardCreate
PasteboardSynchronize
PasteboardClear
PasteboardCopyName
PasteboardGetItemCount
PasteboardGetItemIdentifier
PasteboardCopyItemFlavors
PasteboardGetItemFlavorFlags
PasteboardCopyItemFlavorData
PasteboardPutItemFlavor
PasteboardSetPromiseKeeper
PasteboardCopyPasteLocation
PasteboardSetPasteLocation
PasteboardResolvePromises
Clears the contents of the specified pasteboard.
OSStatus PasteboardClear ( PasteboardRef inPasteboard );
The pasteboard you want to clear.
A result code. See “Pasteboard Manager Result Codes.”
After calling this function, the application owns the pasteboard
and can add data to it. You must call PasteboardClear
before
modifying a pasteboard.
Pasteboard.h
Obtains data from a pasteboard for the desired flavor.
OSStatus PasteboardCopyItemFlavorData ( PasteboardRef inPasteboard, PasteboardItemID inItem, CFStringRef inFlavorType, CFDataRef *outData );
The pasteboard containing the data.
The identifier for the item whose flavor data you want to obtain.
The flavor of the data you want to obtain, specified as a uniform type identifier.
On return, outData
points to the flavor data. You must release this data using CFRelease
when you are done using it.
A result code. See “Pasteboard Manager Result Codes.”
Pasteboard.h
Obtains an array of flavors for a specified item in a pasteboard.
OSStatus PasteboardCopyItemFlavors ( PasteboardRef inPasteboard, PasteboardItemID inItem, CFArrayRef *outFlavorTypes );
The pasteboard containing the data.
The identifier for the item whose flavors you want to obtain.
On return, outFlavorTypes
points
to an array of flavors, specified as uniform type identifiers. You
must release this array by calling CFRelease
when
you are done using it.
A result code. See “Pasteboard Manager Result Codes.”
Pasteboard.h
Gets the name of a pasteboard.
OSStatus PasteboardCopyName ( PasteboardRef inPasteboard, CFStringRef *outName );
The pasteboard whose name you want to retrieve.
A pointer to a CFStringRef
variable allocated by the caller. On return, the string contains the name of the specified pasteboard. The caller is responsible for releasing the string.
A result code. See “Pasteboard Manager Result Codes.”
You can use this function to discover the name of a uniquely-named pasteboard so that other processes may access it.
Pasteboard.h
Determines the location in which to paste promised data.
OSStatus PasteboardCopyPasteLocation ( PasteboardRef inPasteboard, CFURLRef *outPasteLocation );
The pasteboard whose paste location you want to determine.
On return, outPasteLocation
points
to a CFURL indicating the paste location. You must release this
URL when you are done with it by calling CFRelease
.
A result code. See “Pasteboard Manager Result Codes.”
You typically call this function from your promise keeper callback function to determine where to deliver a promised file. It is also used to tell a translation service where to place a translated file.
This function is analogous to the Drag Manager function GetDropLocation
.
Pasteboard.h
Creates a reference to the specified global pasteboard.
OSStatus PasteboardCreate ( CFStringRef inName, PasteboardRef *outPasteboard );
The name of the pasteboard to reference. To create a new pasteboard, specify a unique name. Pasteboard names should have a reverse DNS-style name to ensure uniqueness. You may also pass one of the following constants:
kPasteboardFind
to obtain a reference to the global Find pasteboard
kPasteboardClipboard
to obtain a reference to the global Clipboard
kPasteboardUniqueName
to ask the Pasteboard Manager to create a new pasteboard with a unique name
A pointer to a PasteboardRef
variable allocated by the caller. On return, the variable refers to the pasteboard specified in the inName parameter.
When you are finished using the pasteboard, you can call CFRelease
to release the reference. If you do not release the reference, the pasteboard continues to exist even after your application terminates. A subsequently launched application can find a previously created pasteboard by name and examine the data within it.
A result code. See “Pasteboard Manager Result Codes.”
You can use this function to create a reference to a new or existing pasteboard.
Pasteboard.h
Obtains the number of data items in the specified pasteboard.
OSStatus PasteboardGetItemCount ( PasteboardRef inPasteboard, ItemCount *outItemCount );
The pasteboard whose items you want to count.
On return, outItemCount
points
to the number of items in the pasteboard.
A result code. See “Pasteboard Manager Result Codes.”
You usually call this function before calling PasteboardGetItemIdentifier
.
Pasteboard.h
Obtains the flags for a given flavor.
OSStatus PasteboardGetItemFlavorFlags ( PasteboardRef inPasteboard, PasteboardItemID inItem, CFStringRef inFlavorType, PasteboardFlavorFlags *outFlags );
The pasteboard containing the data.
The identifier for the item whose flavor flags you want to obtain.
The flavor whose flags you want to obtain.
On return, outFlags
points
to a bit field containing the flavor flags. See “Pasteboard Flavor Flags” for
a list of possible values.
A result code. See “Pasteboard Manager Result Codes.”
Pasteboard.h
Obtains the item identifier for an item in a pasteboard.
OSStatus PasteboardGetItemIdentifier ( PasteboardRef inPasteboard, CFIndex inIndex, PasteboardItemID *outItem );
The pasteboard containing the data.
The one-based index number of the data item whose identifier you want to obtain.
On return, outItem
points
to the item identifier for the data item at index inIndex
.
A result code. See “Pasteboard Manager Result Codes.”
The item index is one-based to match the convention used by the Drag Manager.
Pasteboard.h
Adds flavor data or a promise to the specified pasteboard.
OSStatus PasteboardPutItemFlavor ( PasteboardRef inPasteboard, PasteboardItemID inItem, CFStringRef inFlavorType, CFDataRef inData, PasteboardFlavorFlags inFlags );
The pasteboard to which to add flavor data or a promise.
The identifier for the item to which to add flavor data or a promise.
The flavor type of the data or promise you are adding, specified as a uniform type identifier.
The data to add, or a promise to supply the data later. If you pass a CFData object, you may safely release the object when this function returns. To indicate that the data is promised, pass kPasteboardPromisedData
. For more information about promised data, see the Discussion below.
A bit field of flags for the specified flavor.
A result code. See “Pasteboard Manager Result Codes.”
If you promise data, you must implement a promise keeper callback to deliver the data when asked for it (see PasteboardPromiseKeeperProcPtr
for more details). Typically, you store promises instead of the actual data when the data requires a large overhead to generate. You can call this function multiple times to add multiple flavors to a given item. You should add the flavors in your application’s order of preference or richness.
Pasteboard.h
Resolves all promises to a given pasteboard.
OSStatus PasteboardResolvePromises ( PasteboardRef inPasteboard );
The pasteboard whose promises your application wants to resolve. If you pass kPasteboardResolveAllPromises
, all the promises for all pasteboards handled by the application are resolved.
A result code. See “Pasteboard Manager Result Codes.”
You should call this function when your application quits or otherwise becomes unavailable.
Pasteboard.h
Sets the paste location before requesting flavor data.
OSStatus PasteboardSetPasteLocation ( PasteboardRef inPasteboard, CFURLRef inPasteLocation );
The pasteboard you want to obtain flavor data from.
A Core Foundation URL indicating where to put the data.
A result code. See “Pasteboard Manager Result Codes.”
Applications that receive pasteboard data in the form of a
file should call this function before calling PasteboardCopyItemFlavorData
, so the
sender knows where to place the promised data. If the requested
data was promised by the sender, the sending application calls PasteboardCopyPasteLocation
to
determine where to put it.
If a paste location is not applicable for your application, you don’t need to call this function.
This function is analogous to the Drag Manager function SetDropLocation
.
Pasteboard.h
Registers the promise keeper callback function for a pasteboard.
OSStatus PasteboardSetPromiseKeeper ( PasteboardRef inPasteboard, PasteboardPromiseKeeperProcPtr inPromiseKeeper, void *inContext );
The pasteboard to assign the promise keeper callback. If you have multiple pasteboards, you can assign multiple callbacks.
A pointer to your promise keeper callback
function. See PasteboardPromiseKeeperProcPtr
for
more information about implementing the callback.
A pointer to application-defined data. The value you pass in this parameter is passed to your promise keeper callback function when it is called.
A result code. See “Pasteboard Manager Result Codes.”
You must have registered a promise keeper callback function before promising any data on the specified pasteboard.
Pasteboard.h
Synchronizes the local pasteboard reference to reflect the contents of the global pasteboard.
PasteboardSyncFlags PasteboardSynchronize ( PasteboardRef inPasteboard );
The pasteboard you want to synchronize.
A flag indicating what synchronization actions occurred.
Calling this function compares the local pasteboard reference with its global pasteboard. If the global pasteboard was modified, it updates the local pasteboard reference to reflect this change. You typically call this function whenever your application becomes active, so that its pasteboard information reflects any changes that occurred while it was in the background. This function has low overhead, so you should call it whenever you suspect a global pasteboard may have been changed.
Pasteboard.h
Defines a pointer to a callback function that supplies the actual data promised on the pasteboard.
typedef OSStatus (*PasteboardPromiseKeeperProcPtr) ( PasteboardRef pasteboard, PasteboardItemID item, CFStringRef flavorType, void* context );
You would declare your promise keeper callback function named MyPromiseKeeper
like this:
OSStatus MyPromiseKeeper ( PasteboardRef pasteboard, PasteboardItemID item, CFStringRef flavorType, void* context );
The pasteboard whose promise you need to fulfill.
The pasteboard item identifier containing the promised flavor.
The flavor of the data being requested, specified as a uniform type identifier.
The pointer you passed to PasteboardSetPromiseKeeper
in the inContext
parameter.
When promising any flavor data on a pasteboard using PasteboardPutItemFlavor
,
you must implement a callback function to fulfill that promise.
If your application delivers the promised data as a file,
your callback should call PasteboardCopyPasteLocation
to
determine where to deliver the requested data and then take the
necessary steps to do so.
Pasteboard.h
Defines an opaque type that represents a pasteboard.
typedef struct OpaquePasteboardRef *PasteboardRef;
This is a Core Foundation type. For more information, see CFType Reference.
Pasteboard.h
Defines a pasteboard item identifier.
typedef void* PasteboardItemID;
You can use any arbitrary (but unique) ID to identify your pasteboard items when placing them on a pasteboard. For example, you may want to identify items by their internal memory address. Only the owning application should interpret its pasteboard item identifiers.
When your application’s promise keeper callback function is invoked, it receives a pasteboard item ID, and your application must be able to map that ID to the corresponding promised data.
Pasteboard.h
Define the pasteboard names used when calling PasteboardCreate
.
#define kPasteboardClipboard CFSTR("com.apple.pasteboard.clipboard") #define kPasteboardFind CFSTR("com.apple.pasteboard.find") #define kPasteboardUniqueName (CFStringRef)NULL
kPasteboardClipboard
The global Clipboard (used for copy and paste).
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFind
The global Find pasteboard (used for search fields).
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardUniqueName
A system-declared pasteboard that is guaranteed to be unique. Each time you call PasteboardCreate
with this constant, you create a different, unique pasteboard.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
Indicate useful information associated with pasteboard item flavors.
enum { kPasteboardFlavorNoFlags = 0, kPasteboardFlavorSenderOnly = (1 << 0), kPasteboardFlavorSenderTranslated = (1 << 1), kPasteboardFlavorNotSaved = (1 << 2), kPasteboardFlavorRequestOnly = (1 << 3), kPasteboardFlavorSystemTranslated = (1 << 8), kPasteboardFlavorPromised = (1 << 9) }; typedef UInt32 PasteboardFlavorFlags;
kPasteboardFlavorNoFlags
No flag information exists for this flavor.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorSenderOnly
Only the process that added this flavor can see it. Typically used to tag proprietary data that can be cut, dragged, or pasted only within the owning application. This flag is identical to the Drag Manager flavorSenderOnly
flag.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorSenderTranslated
The sender translated this data in some fashion before adding it to the pasteboard. The Finder cannot store flavor items marked with this flag in clipping files. This flag is identical to the Drag Manager flavorSenderTranslated
flag.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorNotSaved
The receiver should not save the data provided
for this flavor. The data may become stale after a drag, or the
flavor may be used only to augment another flavor. For example,
an application may add a flavor whose only purpose is to supply
additional information (say text style) about another flavor. The
Finder cannot store flavor items marked with this flag in clipping
files. This flag is identical to the Drag Manager flavorNotSaved
flag.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorRequestOnly
When the sender sets this flag, this flavor
is hidden from calls to PasteboardCopyItemFlavors
.
However, you can obtain the flavor flags and data by calling PasteboardGetItemFlavorFlags
or PasteboardCopyItemFlavorData
.
The net result is that applications cannot obtain this flavor unless
they are already aware it exists and specifically request it. This
functionality can be useful for copying and pasting proprietary
data within a suite of applications.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorSystemTranslated
This data flavor is available through the Translation
Manager. That is, the Translation Manager must translate the sender’s
data before the receiver can receive it. This flag is set automatically
when appropriate and cannot be set programmatically. The Finder
cannot store flavor items marked with this flag in clipping files.
This flag is identical to the Drag Manager flavorSystemTranslated
flag.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardFlavorPromised
The data associated with this flavor is not
yet on the pasteboard. Typically data is promised to the pasteboard
if it requires a lot of overhead to generate. If the receiver requests
the data, the sender is notified so it can supply the promised data.
This flag is set automatically when appropriate and cannot be set
programmatically. This flag is identical to the Drag Manager flavorDataPromised
flag.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
Indicate the pasteboard status after a call to PasteboardSynchronize
.
enum { kPasteboardModified = (1 << 0), kPasteboardClientIsOwner = (1 << 1) }; typedef UInt32 PasteboardSyncFlags;
kPasteboardModified
The pasteboard was modified since the last time the application accessed it, and the local pasteboard has been synchronized to reflect any changes. Your application should check to see what flavors are now available on the pasteboard and update appropriately (for example, enabling the Paste menu item).
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardClientIsOwner
The application recently cleared the pasteboard and is its current owner. The application can add flavor data to the pasteboard as desired.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
Define constants related to the use of promised data.
#define kPasteboardPromisedData (CFDataRef)NULL #define kPasteboardResolveAllPromises (PasteboardRef)NULL
kPasteboardPromisedData
Indicates a promise that pasteboard data will be supplied later. Used when calling PasteboardPutItemFlavor
.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
kPasteboardResolveAllPromises
Indicates that all promises on all global pasteboard resources owned by this application should be resolved. Used when calling PasteboardResolvePromises
.
Available in Mac OS X v10.3 and later.
Declared in Pasteboard.h
.
The table below lists the most common error codes returned by the Pasteboard Manager.
© 2004, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-06-29)