The ClipboardMacApp'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,
The Clipboard ManagerThe
TClipboardMgrclass is a subclass of
TBehaviorthat manages the application's interaction with the Scrap Manager and maintains a view for the current Clipboard. MacApp creates a single
TClipboardMgrobject during initialization of your application and assigns it to the global variable
gClipboardMgr. For more information on how the Clipboard manager is initialized, see Chapter 4, "Launching and Terminating an Application." MacApp calls methods of
gClipboardMgrat the appropriate time; your application also calls methods of
gClipboardMgrduring Clipboard operations.
The following section describes how your application interacts with the Macintosh Clipboard.
Interacting With the ClipboardThis 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
- When a user cuts or copies data to the Clipboard, the application normally creates a command to handle the operation. The command's
DoItmethod creates a view to display the cut or copied data, then calls the command's
ClaimClipboardmethod 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
DoSetupMenusand, for each kind of private or public data type it can paste, starting with its preferred type, makes a call similar to the following:
- When a user quits the application, switches to another application, or starts a desk accessory, MacApp calls the Clipboard manager's
AboutToLoseControlmethod. That method calls the current Clipboard view's
WriteToDeskScrapmethod. Any view you install as a Clipboard view should override
WriteToDeskScrapto 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
RegainControlmethod. If the data on the desk scrap has changed,
RegainControlgenerates a call to
MakeViewForAlienClipboard, which performs the same function it did in item 1.