NSPasteboardOwner Protocol Reference

Framework
/System/Library/Frameworks/AppKit.framework
Companion guide
Declared in
NSPasteboard.h

Overview

The NSPasteboardOwner informal protocol declares methods that a pasteboard owner should implement to provide data to a pasteboard, and to respond to a change in the pasteboard’s ownership.

Tasks

Providing Data

Noticing Change of Ownership

Instance Methods

pasteboard:provideDataForType:

Implemented by an owner object to provide promised data.

- (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type
Parameters
sender

The pasteboard that requires the specified data for a paste operation.

type

The type of data the owner object must provide.

Discussion

The receiver should have been previously declared in a declareTypes:owner: message.

The requested data should be written to sender using the setData:forType:, setPropertyList:forType:, or setString:forType: method. The pasteboard:provideDataForType: messages may also be sent to the owner when the application is shut down through an application’s terminate: method. This is the method that is invoked in response to a Quit command. Thus the user can copy something to the pasteboard, quit the application, and still paste the data that was copied. A pasteboard:provideDataForType: message is sent only if the specified type of data has not already been supplied to the pasteboard. Instead of writing all data types when the cut or copy operation is done, an application can choose to implement this method to provide the data for certain types only when they are requested.

If an application writes data to the pasteboard in the richest, and therefore most preferred, type at the time of a cut or copy operation, its pasteboard:provideDataForType: method can simply read that data from the pasteboard, convert it to the requested type, and write it back to the pasteboard as the new type.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPasteboard.h

pasteboardChangedOwner:

Notifies a prior owner of the specified pasteboard (and owners of representations on the pasteboard) that the pasteboard has changed owners.

- (void)pasteboardChangedOwner:(NSPasteboard *)sender
Parameters
sender

The pasteboard object whose owner changed.

Discussion

Pasteboard owners only need to implement this method if they need to know when they have lost ownership.

The owner is not able to read the contents of the pasteboard when responding to this method. The owner should be prepared to receive this method at any time, even from within the declareTypes:owner: method used to declare ownership.

Once an owner has provided all of its data for declared types, it will not receive a pasteboardChangedOwner: message. If, therefore, you are maintaining an object just for the purpose of providing data lazily, rather than relying solely on receipt of a pasteboardChangedOwner: message you need to keep track of what types were promised and what types have been provided. When all the types have been provided, you may release the owner.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSPasteboard.h