The application gets the names of all of the files in the current directory We use popen() here, but you should use
opendir() and readdir(). and displays the filenames using Label widgets. Each file has a file or folder image
next to it, depending on whether it is a regular file or a directory. The images are the drag sources for manipulating the
files. If the user presses the middle mouse button over one of the symbols, the pointer changes to a drag icon and he
can drag the file to another application that has a drop site that understands files.
19.4.1 Creating a Drag Source
When the application reads the files in the directory, it creates a global array of structures that contain information
about the files. This information is used to keep track of filenames and file types. For each file, the application creates
two Label widgets: an image that represents the type of the file and a string that specifies the filename. To link the
image Labels to the array, the application passes the index of each file in the array as the XmN-userData resource
for the associated Label. This value can be retrieved and used to access the information in the array.
Depending on whether a file is a regular file or a directory, the application places an image of a file or a folder next to
the filename Label. Each image is created using XmGetPixmap() and specified as the XmN-labelPixmap for the
appropriate image Labels. The images are also used for drag icons during the drag operation, as we describe in the
next ...