Important: The information in this document is obsolete and should not be used for new development.
The Clipboard
MacApp's Clipboard support is designed to help your application manage a private scrap. It provides facilities to
MacApp provides a mechanism for getting and displaying the standard scrap types and for switching between a Do and an Undo Clipboard view when the user does or undoes a command that changes the Clipboard. Clipboard terms are defined beginning on page 500.
- support commands that cut, copy, clear, and paste data
- manage a Clipboard view to display the current Clipboard data
- interact with the desk scrap to get data when your application is switched in or put data when your application is switched out
- work with the standard desk scrap data types,
'TEXT'
and'PICT'
The Clipboard Manager
TheTClipboardMgr
class is a subclass ofTBehavior
that manages the application's interaction with the Scrap Manager and maintains a view for the current Clipboard. MacApp creates a singleTClipboardMgr
object during initialization of your application and assigns it to the global variablegClipboardMgr
. For more information on how the Clipboard manager is initialized, see Chapter 4, "Launching and Terminating an Application." MacApp calls methods ofgClipboardMgr
at the appropriate time; your application also calls methods ofgClipboardMgr
during Clipboard operations.The following section describes how your application interacts with the Macintosh Clipboard.
Interacting With the Clipboard
This scenario describes how a MacApp application interacts with the Clipboard.
Chapter 22, "Working With the Clipboard," provides additional detail on MacApp's Clipboard support, along with recipes and sample code for adding Clipboard support to your application.
- When the application is first launched, it looks on the desk scrap for data of its own private desk scrap type(s). If it finds any, it extracts the data and creates a view to display it. It may or may not need to create a document object to associate with the view. To perform these actions, you override the
MakeViewForAlienClipboard
method inTYourApplication
.- When a user cuts or copies data to the Clipboard, the application normally creates a command to handle the operation. The command's
DoIt
method creates a view to display the cut or copied data, then calls the command'sClaimClipboard
method to install the view as the command's current Clipboard view (and also as the Clipboard manager's current Clipboard view). If the user chooses to undo or redo the command, MacApp takes care of switching between the current and undo Clipboard views, as appropriate.- Any application view that allows pasting overrides
DoSetupMenus
and, for each kind of private or public data type it can paste, starting with its preferred type, makes a call similar to the following:
gClipboardMgr->CanPaste(kDataTypeIUnderstand);
- When a user quits the application, switches to another application, or starts a desk accessory, MacApp calls the Clipboard manager's
AboutToLoseControl
method. That method calls the current Clipboard view'sWriteToDeskScrap
method. Any view you install as a Clipboard view should overrideWriteToDeskScrap
to write its private data types and the appropriate standard scrap types as well.- When the application is switched in, MacApp calls the Clipboard manager's
RegainControl
method. If the data on the desk scrap has changed,RegainControl
generates a call toMakeViewForAlienClipboard
, which performs the same function it did in item 1.