Introduction
Drag & drop and copy & paste are convenient and intuitive methods of exchanging data between applications. The ESRI ArcGIS Desktop applications ArcCatalog, ArcMap, ArcScene and ArcGlobe have limited support for data exchange with each other and windows explorer.
This table below summarizes the drag and drop capabilities between ArcGIS Desktop applications and windows explorer.
From\To | ArcCatalog | ArcMap | ArcScene | ArcGlobe | Windows Explorer |
ArcCatalog1 | ü | ü | ü | ü | ü |
ArcMap2 | û | ü | û | û | û |
ArcScene2 | û | û | û | û | û |
ArcGlobe2 | û | û | û | û | û |
Windows Explorer3 | û | ü | ü | û | ü |
Notes:
- Any dataset or layer file or target specific document (ie mxd, sxd or 3dd).
- Drag a layer from the display tab in the table of contents.
- Drag a geographic file such as a image (eg jpg, png, tiff), layer file (lyr) or target specific document (ie mxd, sxd or 3dd).
ArcGIS Desktop applications use standard windows behavior for drag/drop and copy/paste operations. This means, to a limited extent, that developers can build applications that interact with ArcGIS Desktop applications.
From a developer's perspective, drag/drop and copy/paste operations are very similar. Both operations require the construction of a DataObject. The distinction is how a DataObject is exchanged between the source and target. In the case of drag/drop, the source control must use the DoDragDrop method against the DataObject and a target must "listen" for DragDrop events. Copy/paste is much simpler as the DataObject is simply added and retrieved from the clipboard by the source and target respectively.
With regard to drag/drop and copy/paste operations, ArcGIS Desktop applications create one of two flavors of DataObjects. When an operation starts from ArcCatalog, a DataObject is created containing data in the "ESRI Names" format. When an operation starts from ArcMap, a DataObjects is created containing data in the "ESRI Layers" format. These clipboard formats are registered with the computer when ArcGIS Desktop is installed.
The "ESRI Names" clipboard format is used to represent data containing a collection of ESRI named objects, namely, NamesEnumerator class.
The "ESRI Layers" clipboard format is used to represent data containing a collection of ESRI layers and tables.
ArcGIS Desktop developers have a choice of customizing a desktop application (e.g. ArcMap) or creating a standalone application (e.g. ArcGIS Diagrammer). Both types of customizations can present windows for users to interact with and, optionally, participate in drag/drop or copy/paste operations with desktop applications.
The following sections will provide specific information on how to develop either a drag/drop source or target.
Creating a drop target for an "ESRI Names" DataObject
This is probably the easy operation to implement. In the control that is designated to be the drop target listen for the DragDrop event, use the INameFactory::UpackageNames method to convert the DataObject into a collection of objects that implement the IName interface. This EDN example is useful but please ensure that use "ESRI Names" as the clipboard format.
An alternative approach is to use the DataObjectHelper.
http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSystemUI/IDataObjectHelper.htm
Creating a drop source for an "ESRI Names" DataObject
The ESRI Prototype Lab has recently published a sample on ArcScripts called DataObject Helper for ArcGIS Desktop that demonstrates this. The sample includes a small C++ DLL called "BnchMrkDragDropNames.dll" that can be used to convert a collection of IName objects into an "ESRI Names" DataObject.
Creating a drop target for an "ESRI Layers" DataObject
Fortunately this topic is already covered in a detail here.
Creating a drop source for an "ESRI Layers" DataObject
Unfortunately, there is no solution to provide this capability at this time.
Example
This following screenshot demonstrates a sample application available from ArcScripts. The sample allows the user to build a list of datasets using the Add and Remove buttons. One or more of the selected datasets in the list can then be added to ArcMap (or ArcGlobe) using a standard drop/drop operation as shown below.
The application references a small DLL called "BnchMrkDragDropNames.dll". This DLL creates an ArcMap/ArcGlobe friendly DataObject that can be used drop/drop or copy/paste operations. Here is how is a code snippet.
private void ListView_ItemDrag(object sender, ItemDragEventArgs e) {
// Exit if nothing selected
if(this.listViewNames.SelectedItems.Count == 0) { return; }
// Create New ESRI Name Enumeration
IEnumName enumName = new NamesEnumeratorClass();
// Cast to IEnumNameEdit to allow addition of IName objects
IEnumNameEdit enumNameEdit = (IEnumNameEdit)enumName;
// Add IName objects to the enumertion
IName name1 = <...>;
IName name2 = <...>;
enumNameEdit.Add(name1);
enumNameEdit.Add(name2);
// Create Prototype Lab's DragDropNames class
IDragDropNames dragDropNames = new DragDropNamesClass();
// Assign the IName Enumeration to the Names property
dragDropNames.Names = enumName;
// Perform a Control::DoDragDrop using the APL's DragDropNames class
this.listViewNames.DoDragDrop(dragDropNames, DragDropEffects.All);
}
No comments:
Post a Comment