When deriving from TDocumentScrapItemAcceptor, you override two functions: ChoosePreferredTypeForDocument, and AcceptScrapItemForDocument.
ChoosePreferredTypeForDocument is called when the user releases the mouse button over the destination of the drag operation. It is part of the type negotiation process that takes place between the drag source and the drop acceptor. Typically, the drop acceptor is handed a set of available types, selects a preferred type, and returns True. If no matching type is found, ChoosePreferredTypeForDocument should return False.
After the acceptor indicates its preferred type, AcceptScrapItemForDocument is called to perform the actual acceptance of the dragged document.
AcceptScrapItemForDocument takes the following parameters:
Overriding ChoosePreferredType
ForDocument
ChoosePreferredTypeForDocument takes the following parameters: virtual Boolean ChoosePreferredTypeForDocument(
const TDocumentReference& representedDocument,
const TPlaceReference& placeContext,
TSequenceOf<TTypeDescription> availableTypes,
TTypeDescription& chosenType) const = 0;
Overriding AcceptScrapItem
ForDocument
virtual Boolean AcceptScrapItemForDocument(
const TDocumentReference& representedDocument,
const TPlaceReference& placeContext,
const TTypeDescription& type,
const TScrapItem& scrapItem) = 0;
This function should perform whatever action is appropriate for the drag and drop gesture. For example, if the TScrapItem is a printable entity that was dragged onto a printer, this function should actually print the document; if the TScrapItem is a document that was dragged from one folder to another, this function should move the document into the destination folder.
Instances of classes derived from TDocumentScrapItemAcceptor are copied and stored with a document's attribute set. When deriving a new class from TDocumentScrapItemSource, you also have to properly define streaming operators, a default constructor, and a copy constructor.
Classes derived from TDocumentScrapItemAcceptor also need to support dynamic casting. See OS Services for more information about the dynamic casting mechanism supported by the CommonPoint runtime system.
Once you have an object of the appropriate type in the Workspace, attach your drop acceptor to it using the utility program AddWorkspaceDropAcceptor:
AddWorkspaceDropAcceptor takes the following parameters:
NOTE
You can also use this technique to propagate other attributes. For example, if you attach an icon to a particular document instance, and then create a stationery from that instance, all documents created from the stationery will carry the icon of the original document.
You can attach multiple drop acceptors to a Workspace entity with AddWorkspaceDropAcceptor. It attaches a new instance of a drop acceptor every time you run it. During the type negotiation that occurs during a drag and drop interaction, the drop acceptors are processed in the order that they were added to the document. The system iterates through the list until the type negotiation succeeds.
Supporting streaming and dynamic casting
Attaching a scrap
item acceptor to a Workspace entity
Once you've written a document scrap item acceptor, you attach it to a Workspace entity. To do this, the Workspace must be running, and a document instance of the appropriate type must be available. You can use the RunDocument utility to create a document instance from a stationery. (See the Tools guide for more information about using RunDocument.)
Note that you must be in $TaligentRoot/SharedLibs to run AddWorkspaceDropAcceptor.
% cd $TaligentRoot/SharedLibs
% AddWorkspaceDropAcceptor entityName -c dropAcceptorClassName dropAcceptorSharedLib
This operation only affects the specified document instance. If you use the Workspace user command to create a stationery from the specified instance, the drop acceptor behavior is inherited by all documents created from the stationery. Removing a drop
acceptor from a Workspace entity
To remove an acceptor, use the utility program RemoveWorkspaceDropAcceptor:
This tool iterates backward through the list of added drop acceptors and removes the first one that accepts the specified scrap type. The third parameter,
% cd $TaligentRoot/SharedLibs
% RemoveWorkspaceDropAcceptor entityName scrapType sharedLib
sharedLib
, indicates the name of the shared library where scrapType
is defined. Viewing the current
drop acceptors
To see what drop acceptors are currently attached to a Workspace entity, you can use the utility program WorkspaceDragAndDropInfo. To list the current drop acceptors for an entity:
This prints a list of the acceptors that can accept the specified scrap type. % cd $TaligentRoot/SharedLibs
% WorkspaceDragAndDropInfo entityName ScrapType
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Generated with WebMaker