Adding Images to Drag Items

When you drag an object, a visual image is displayed for that object. The Open Class Library provides default system images, or you can change the image style and provide your own images.

To change the drag image style, use the IDMSourceOperation::setImageStyle member function. We recommend that you call setImageStyle from the IDMItem::generateSourceItems member function of the application's derived item class.

The following table describes the IDMImage styles and the steps you must take to use them:

IDMImage Style Description What to Code
systemImages If one item is dragged, the ISystemPointerHandle::singleFile icon is used. For more than one item, the ISystemPointerHandle::multipleFile icon is used. Any images supplied with drag items are ignored. Default
allStacked Shows each image provided in each drag item. If no images are specified, system images are used. Attach IDMImage objects to each IDMItem object
stack3AndFade Shows the first three images provided in the drag items and then shows a special icon that looks like the rest of the images fading out. This is optimal when the user can drag more than three items. If no images are specified, system images are used. Attach IDMImage objects to three IDMItem objects.

You can use the IDMSourceOperation::setStackingPercentage member function to define the stacking percentage used to calculate the placement of the next stacked image when the image style, IDM::stack3AndFade or IDM::allStacked, is specified. By default, the percentage for both the x- and y- axis is defined as 50 percent of the current image's size, which results in the placement of the origin (bottom left-hand corner for OS/2 applications) of the next image in the center of the current image. The placement of the first image is determined by the position of the mouse pointer. The default direction of stacking is toward the upper right. Increase the stacking percentage to expand the stacking of images, and conversely, decrease the stacking percentage to compress the stacking of images. Also, you can alter the direction of stacking using negative percentages as shown below:

IDMSourceOperation::setStackingPercentage( IPair( x, y ) );   //stacking direction is upper right
IDMSourceOperation::setStackingPercentage( IPair( -x, y ) );  //stacking direction is upper left
IDMSourceOperation::setStackingPercentage( IPair( -x, -y ) ); //stacking direction is lower left
IDMSourceOperation::setStackingPercentage( IPair( x, -y ) );  //stacking direction is lower right

Here, x is the stacking percentage for the x-axis and y is the stacking percentage for the y-axis.

You can set this function only once per each drag operation.

The drag4 sample contains a simple illustration of the use of the IDMSourceOperation::setStackingPercentage function.

You can attach IDMImage objects to IDMItem objects by using the IDMItem::setImage member function in the following:

The following example adds the text I-beam pointer as an image to a derived IDMItem in its constructor:

MyItem::MyItem (IDMSourceOperation* pIDMSrcOp)
{

 IDMImage image = IDMImage(ISystemPointerHandle(
                           ISystemPointerHandle::text));
 setImage(image);
 }

Drag Image Resources for stack3AndFade

When you use the IDMItem::stack3AndFade style, the Open Class Library uses a fade icon that looks like the images are fading out. If your application is shipped as a product and uses the stack3AndFade option, you need to ensure its availability to your application.

The fade icon is stored in the Open Class Library resource dynamic link library.

If your application is dynamically linked to the Open Class Library, follow these steps to use the fade icon:

  1. Rename the resource DLL with the DLLRNAME tool shipped with the IBM VisualAge for C++ compiler.
  2. Call ICurrentApplication::setResourceLibrary with the new DLL name as its argument. Refer to ICurrentApplication in the Open Class Library Reference for more information about setResourceLibrary.

If your application is linked to Open Class Library static libraries, follow these steps to use the fade icon:

  1. Bind the fade icon to your application .EXE file. The fade icon, fade.ico, and its resource file are in the \ibmcppw\include directory on the drive you installed the product on.
  2. Call ICurrentApplication::setResourceLibrary with 0 as its argument. The parameter 0 indicates that the fade icon is in the application. Refer to ICurrentApplication in the Open Class Library Reference for more information about setResourceLibrary.



Direct Manipulation


Enabling Direct Manipulation
Using Default Direct Manipulation


IDMCnrItem
IDMHandler
IDMItem
IDMItemProvider
IDMItemProviderFor
IDMSourceDiscardEvent
IDMSourceOperation
IDMTargetDropEvent
IDMTargetEvent