Atom *type_return;
XtPointer *value_return;
unsigned long *length_return;
int *format_return;
{
Display *dpy;
Atom FILE_CONTENTS, FILE_NAME, MOTIF_DROP;
XtPointer ptr;
Widget label;
int i;
char *text;
struct stat s_buf;
FILE *fp;
long length;
String str;
/* intern the Atoms for data targets */
dpy = XtDisplay (widget);
FILE_CONTENTS = XmInternAtom (dpy, "FILE_CONTENTS", False);
FILE_NAME = XmInternAtom (dpy, "FILE_NAME", False);
MOTIF_DROP = XmInternAtom (dpy, "_MOTIF_DROP", False);
/* check if we are dealing with a drop */
if (*selection != MOTIF_DROP)
return False;
/* get the drag source widget */
XtVaGetValues (widget, XmNclientData, &ptr, NULL);
label = (Widget) ptr;
if (label == NULL)
return False;
/* get the index into the file array from XmNuserData from the
* drag source widget.
*/
XtVaGetValues (label, XmNuserData, &ptr, NULL);
i = (int) ptr;
/* this routine processes only file contents and file name */
if (*target == FILE_CONTENTS) {
/* get the contents of the file */
if (stat (files[i].file_name, &s_buf) == −1 ||
(s_buf.st_mode & S_IFMT) != S_IFREG ||
!(fp = fopen (files[i].file_name, "r")))
return False;
length = s_buf.st_size;
if (!(text = XtMalloc ((unsigned) (length + 1))))
return False;
else if (fread (text, sizeof (char), length, fp) != length)
return False;
else
text[length] = 0;
fclose (fp);
/* format the value for transfer */
*type_return = FILE_CONTENTS;
*value_return = (XtPointer) text;
*length_return = length;
*format_return = 8;
19 Drag and Drop 19.4 ...