Beruflich Dokumente
Kultur Dokumente
5
As of MicroStation V8.5, MicroStation dialog items can be Drag and Drop sources and targets. Data objects can be dragged within or among dialog items, or can be dragged to or from sources or targets outside MicroStation.
ListBoxes, Trees and Text items can be drop targets. To identify a ListBox or Tree as a drop target, add the EXTINTATTR_DROPTARGET attribute to its dialog item resource definition. All Text items are potentially drop targets without any changes to the resource definition. See more information about these items as drop targets in the Drop Target Processing section below.
DItem_abcRsc abcID_yourItem = { ... } extendedIntAttributes { { {EXTINTATTR_DROPTARGET, 1} } };
Clipboard Formats
Drag and Drop applications use Windows clipboard formats to identify the type of data being dragged. The same clipboard format must be registered by both the drop source and drop target. Clipboard formats are registered using the mdlClipboard_registerClipboardFormat function.
/* Same code is used by both the Drop Source and Drop Target */ #define CLIPBOARD_FORMAT_MINE "My Clipboard Format Text" UShort cfFormat;
The data object created will be available to the item hook in subsequent DITEM_MESSAGE_DROPSOURCE messages and is used in other mdlDataObject function calls, such as mdlDataObject_destroy.
mdlDataObject_destroy (dimP->u.dropSource.pDataObject);
Responsibilities below for more details. GUIDROPSOURCEMSG_QUERY received as the user drags the mouse GUIDROPSOURCEMSG_PRECANCEL received after the user cancels the drag operation but before the END message GUIDROPSOURCEMSG_PREDROP received after the user releases the mouse for the drop operation but before the DROP message GUIDROPSOURCEMSG_DROP received after the user releases the mouse for the drop operation. See DROP Responsibilities below for more details. GUIDROPSOURCEMSG_END received as a final message after the drag and drop operation has occurred. This message subtype is used to clean up the data object packaged during BEGIN processing. See END Responsibilities below for more details.
BEGIN Responsibilities
As mentioned previously, the item hook must package the data to be dropped. Additionally, the hook must establish the possible drop effects and set the drag and drop status to OK:
dimP->u.dropSource.pDataObject = mdlDataObject_create (cfFormat, pMyData, dataLen); dimP->u.dropSource.guiDropEffect =
DROP Responsibilities
If the drop effect (guiDropEffect) includes GUIDROPEFFECT_MOVE and the drop target hasnt completely handled the move operation, the drop source item hook must remove or delete the data corresponding to the data object since it has been added to the drop target.
END Responsibilities
As the data object is created in the BEGIN processing, the data object must be destroyed in the END processing:
mdlDataObject_destroy (dimP->u.dropSource.pDataObject);
If the target item can accept the data object, a copy of the data is obtained using the mdlDataObject_getData function. This copy must be freed when no longer needed by calling the dlmSystem_mdlFree function.
/* Get a copy of the data from the data object */ pData = mdlDataObject_getData (dimP->u.dropTarget.pDataObject, cfFormat); ... /* When no longer needed */ dlmSystem_mdlFree (pData);
If, for some reason, the target item does not want to accept the data object, the Drop Effect variable should be set to None: Otherwise, the drag and drop subsystem will consider the item a valid drop target.
dimP->u.dropTarget.guiDropEffect = GUIDROPEFFECT_NONE;
GUIDROPTARGETMSG msgType; void *pDataObject; UInt32 dwKeyState; Point2d localPt; UInt32 guiDropEffect; int iRow; /* For ListBoxes and Trees */ int iCol; } dropTarget;
DROP Responsibilities
If the message type is DROP, the target can add the data object to itself in an appropriate manner for the application.
/* If clipboard format is not available, disallow */ if (!mdlDataObject_isFormatAvailable (dimP->u.dropTarget.pDataObject, cfFormat)) dimP->u.dropTarget.guiDropEffect = GUIDROPEFFECT_NONE; /* If can't get the drop entry, disallow */ else if (NULL == (pMyData = (MyData *) mdlDataObject_getData (dimP->u.dropTarget.pDataObject, cfFormat))) dimP->u.dropTarget.guiDropEffect = GUIDROPEFFECT_NONE; else { /* May further determine if this item can accept the data */ /* If it cannot accept, set the guiDropEffect to GUIDROPEFFECT_NONE */ ... /* Use the copy of the data to add its contents to myself */ if (GUIDROPTARGETMSG_DROP == dimP->u.dropTarget.msgType) { ... } /* Free the copy from the Drag and Drop system */ dlmSystem_mdlFree (pMyData); }
mdlDataObject Functions
The Dialog Item Drag and Drop subsystem in MicroStation utilizes the Windows DoDragDrop function and the IDataObject, IDropSource and IDropTarget COM interfaces. The data object packaged by the drop source must implement the IDataObject interface. The data object created by the mdlDataObject_create function creates such an object. Other mdlDataObject functions are also provided which are simply front-ends to the IDataObject interface. If your application is written in C++, you may very well want to create your own class derived from IDataObject instead of using the mdlDataObject functions. This is quite acceptable. The following is a brief overview of the mdlDataObject functions, which are prototyped in msdragdrop.fdf. The GuiDataObject type is simply void. mdlDataObject_create - Creates a GuiDataObject to be used in further Drag and Drop functions. A pointer to application data is passed in and associated with the GuiDataObject. The application retains ownership of the application data and is responsible for freeing the data after the drag and drop operation ends (see GUIDROPSOURCEMSG_END). A pointer to this data is retrieved using mdlDataObject_getApplicationData. mdlDataObject_destroy - Destroys a GuiDataObject mdlDataObject_getApplicationData Retrieves a pointer to the application data provided to mdlDataObject_create mdlDataObject_addFormat - Adds a clipboard format and associated data to the GuiDataObject. (not currently implemented) mdlDataObject_isFormatAvailable - Determines whether a particular clipboard format is associated with the GuiDataObject. mdlDataObject_getData - Retrieves a copy of the data from the GuiDataObject. mdlDataObject_getDataHere - Retrieves the data from the GuiDataObject and copies it into the caller-supplied buffer. mdlDataObject_getIDataObject - Retrieves the Windows IDataObject interface pointer. mdlDataObject_getDragFileCount - Retrieves the number of files listed in a CF_HDROP data object. mdlDataObject_getDragFile - Retrieves the file name at a certain index within a CF_HDROP data object.