Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Programmer's Guide to MacApp / Part 1 - MacApp Theory and Architecture
Chapter 5 - Events and Commands


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.

The Clipboard Manager

The TClipboardMgr class is a subclass of TBehavior that manages the application's interaction with the Scrap Manager and maintains a view for the current Clipboard. MacApp creates a single TClipboardMgr object 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 gClipboardMgr at the appropriate time; your application also calls methods of gClipboardMgr 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.

  1. 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 in TYourApplication.
  2. 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's ClaimClipboard 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.
  3. 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);

  4. 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's WriteToDeskScrap method. Any view you install as a Clipboard view should override WriteToDeskScrap to write its private data types and the appropriate standard scrap types as well.
  5. 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 to MakeViewForAlienClipboard, which performs the same function it did in item 1.

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.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
25 JUL 1996