Blame tests/DragAndDrop/DNDtest1.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
*/ 
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: DNDtest1.c /main/9 1996/10/07 15:17:06 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
/*
Packit b099d7
 *	file: DNDtest1.c
Packit b099d7
 *
Packit b099d7
 *	This is a basic test for DND.
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include <signal.h>
Packit b099d7
#include <stdio.h>
Packit b099d7
Packit b099d7
#include <testlib.h>
Packit b099d7
Packit b099d7
#include <Xm/DragDrop.h>
Packit b099d7
Packit b099d7
#include <X11/keysym.h>
Packit b099d7
#include <X11/Xatom.h>
Packit b099d7
Packit b099d7
/* global variables */
Packit b099d7
Widget	myDC;
Packit b099d7
Atom	COMPOUND_TEXT;
Packit b099d7
Atom	DELETE;
Packit b099d7
Atom	NULL_ATOM;
Packit b099d7
Packit b099d7
Boolean	use_instruction_box;
Packit b099d7
Packit b099d7
FILE	*outfp;
Packit b099d7
Packit b099d7
Packit b099d7
Quit ()
Packit b099d7
{
Packit b099d7
Packit b099d7
	printf("Begin exiting ... please standby ... \n");
Packit b099d7
	fflush(outfp);
Packit b099d7
	fclose(outfp);
Packit b099d7
	exit(0);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
/*ARGSUSED*/
Packit b099d7
static Boolean DragConvertProc(w, selection, target, typeRtn, valueRtn, 
Packit b099d7
							  lengthRtn, formatRtn, max_lengthRtn, 
Packit b099d7
							  client_data, request_id)
Packit b099d7
Widget              w;
Packit b099d7
Atom                *selection;
Packit b099d7
Atom                *target;
Packit b099d7
Atom                *typeRtn;
Packit b099d7
XtPointer           *valueRtn;
Packit b099d7
unsigned long       *lengthRtn;
Packit b099d7
int                 *formatRtn;
Packit b099d7
unsigned long       *max_lengthRtn;
Packit b099d7
XtPointer			client_data;
Packit b099d7
XtRequestId			*request_id;
Packit b099d7
{
Packit b099d7
Packit b099d7
	char	*string = "return value";
Packit b099d7
	int		ok;
Packit b099d7
	XTextProperty tmp_prop;
Packit b099d7
Packit b099d7
	if (*target != COMPOUND_TEXT && *target != DELETE)
Packit b099d7
		return(False);
Packit b099d7
Packit b099d7
	if (*target == COMPOUND_TEXT) {
Packit b099d7
Packit b099d7
		ok = 0;
Packit b099d7
		ok = XmbTextListToTextProperty(display, &string, 1, 
Packit b099d7
									   XCompoundTextStyle, &tmp_prop);
Packit b099d7
		if (ok != Success)
Packit b099d7
			return(False);
Packit b099d7
		
Packit b099d7
		*valueRtn = (char *) tmp_prop.value;
Packit b099d7
		*lengthRtn = tmp_prop.nitems;
Packit b099d7
		*typeRtn = COMPOUND_TEXT;
Packit b099d7
		*formatRtn = 8;
Packit b099d7
		return(True);
Packit b099d7
Packit b099d7
	}
Packit b099d7
	if (*target == DELETE) {
Packit b099d7
#ifdef DEBUG
Packit b099d7
		fprintf(outfp, "DELETE target encountered\n");
Packit b099d7
#endif
Packit b099d7
		*typeRtn = NULL_ATOM;
Packit b099d7
		*valueRtn = NULL;
Packit b099d7
		*lengthRtn = 0;
Packit b099d7
		*formatRtn = 8;
Packit b099d7
		return(True);
Packit b099d7
	}
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DragMotionCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDragContext			dc;
Packit b099d7
	XmDragMotionCallback	DragMotion;
Packit b099d7
Packit b099d7
	dc = (XmDragContext)w;
Packit b099d7
	DragMotion = (XmDragMotionCallback )call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "Drag Motion! \n");
Packit b099d7
	fprintf(outfp, "operation = %d\n", DragMotion->operation);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DragMotion->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "x = %d\n", DragMotion->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", DragMotion->y);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DnDFinishCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDragContext				dc;
Packit b099d7
	XmDragDropFinishCallback	DndFinish;
Packit b099d7
	Widget						source_icon, state_icon, op_icon;
Packit b099d7
	Arg							args[MAX_ARGS];
Packit b099d7
	int							n;
Packit b099d7
Packit b099d7
	dc = (XmDragContext)w;
Packit b099d7
	DndFinish = (XmDragDropFinishCallback )call_data;
Packit b099d7
	source_icon = state_icon = op_icon = NULL;
Packit b099d7
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNsourceCursorIcon, &source_icon); n++;
Packit b099d7
	XtSetArg(args[n], XmNstateCursorIcon, &state_icon); n++;
Packit b099d7
	XtSetArg(args[n], XmNoperationCursorIcon, &op_icon); n++;
Packit b099d7
	XtGetValues((Widget)dc, args, n);
Packit b099d7
Packit b099d7
	if (source_icon != NULL)
Packit b099d7
		XtDestroyWidget(source_icon);
Packit b099d7
	if (state_icon != NULL)
Packit b099d7
		XtDestroyWidget(state_icon);
Packit b099d7
	if (op_icon != NULL)
Packit b099d7
		XtDestroyWidget(op_icon);
Packit b099d7
Packit b099d7
	fprintf(outfp, "DND Finish! \n");
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DropFinishCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDropFinishCallback	DropFinish;
Packit b099d7
	Arg					args[MAX_ARGS];
Packit b099d7
	Cardinal			n;
Packit b099d7
Packit b099d7
Packit b099d7
	DropFinish = (XmDropFinishCallback )call_data;
Packit b099d7
Packit b099d7
Packit b099d7
	fprintf(outfp, "Drop Finish! \n");
Packit b099d7
	fprintf(outfp, "operation = %d\n", DropFinish->operation);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DropFinish->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "dropAction = %d\n", DropFinish->dropAction);
Packit b099d7
	fprintf(outfp, "completionStatus = %d\n", DropFinish->completionStatus);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DropSiteEnterCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDropSiteEnterCallback	DropSiteEnter;
Packit b099d7
Packit b099d7
	DropSiteEnter = (XmDropSiteEnterCallback )call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "Drop Site Enter! \n");
Packit b099d7
	fprintf(outfp, "operation = %d\n", DropSiteEnter->operation);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DropSiteEnter->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "x = %d\n", DropSiteEnter->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", DropSiteEnter->y);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DropSiteLeaveCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDropSiteLeaveCallback	DropSiteLeave;
Packit b099d7
Packit b099d7
Packit b099d7
	DropSiteLeave = (XmDropSiteLeaveCallback )call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "Drop Site Leave! \n");
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DropStartCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDropStartCallback	DropStart;
Packit b099d7
Packit b099d7
	DropStart = (XmDropStartCallback )call_data;
Packit b099d7
Packit b099d7
Packit b099d7
	fprintf(outfp, "Drop Start! \n");
Packit b099d7
	fprintf(outfp, "operation = %d\n", DropStart->operation);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DropStart->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "dropAction = %d\n", DropStart->dropAction);
Packit b099d7
	fprintf(outfp, "x = %d\n", DropStart->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", DropStart->y);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void TopLEnterCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmTopLevelEnterCallback	TopLEnter;
Packit b099d7
Packit b099d7
Packit b099d7
	TopLEnter = (XmTopLevelEnterCallback )call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "TopLevel Enter! \n");
Packit b099d7
	fprintf(outfp, "window = %ld\n", TopLEnter->window);
Packit b099d7
	fprintf(outfp, "x = %d\n", TopLEnter->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", TopLEnter->y);
Packit b099d7
	fprintf(outfp, "dragProtocolStyle = %d\n", TopLEnter->dragProtocolStyle);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void TopLLeaveCallback(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmTopLevelLeaveCallback	TopLLeave;
Packit b099d7
Packit b099d7
Packit b099d7
	TopLLeave = (XmTopLevelLeaveCallback )call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "TopLevel Leave! \n");
Packit b099d7
	fprintf(outfp, "window = %ld\n", TopLLeave->window);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void StartDrag(w, event)
Packit b099d7
Widget	w;
Packit b099d7
XEvent	*event;
Packit b099d7
{
Packit b099d7
Packit b099d7
	Widget	dragSource;
Packit b099d7
	Arg		args[MAX_ARGS];
Packit b099d7
	Cardinal	n;
Packit b099d7
	Atom	exportList[1];
Packit b099d7
	static XtCallbackRec DragMotionCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DragMotionCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec DnDFinishCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DnDFinishCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec DropFinishCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DropFinishCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec DropSiteEnterCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DropSiteEnterCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec DropSiteLeaveCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DropSiteLeaveCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec DropStartCB[2] = 
Packit b099d7
	{
Packit b099d7
		{DropStartCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec TopLEnterCB[2] = 
Packit b099d7
	{
Packit b099d7
		{TopLEnterCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
	static XtCallbackRec TopLLeaveCB[2] = 
Packit b099d7
	{
Packit b099d7
		{TopLLeaveCallback,NULL},
Packit b099d7
		{NULL, NULL}
Packit b099d7
	};
Packit b099d7
Packit b099d7
Packit b099d7
	exportList[0] = COMPOUND_TEXT;
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNconvertProc, DragConvertProc); n++;
Packit b099d7
	XtSetArg(args[n], XmNdragDropFinishCallback, DnDFinishCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNdropFinishCallback, DropFinishCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNdropSiteEnterCallback, DropSiteEnterCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNdropSiteLeaveCallback, DropSiteLeaveCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNdropStartCallback, DropStartCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNtopLevelEnterCallback, TopLEnterCB); n++;
Packit b099d7
	XtSetArg(args[n], XmNtopLevelLeaveCallback, TopLLeaveCB); n++;
Packit b099d7
Packit b099d7
	XtSetArg(args[n], XmNexportTargets, exportList); n++;
Packit b099d7
	XtSetArg(args[n], XmNnumExportTargets, 1); n++;
Packit b099d7
Packit b099d7
	XtSetArg(args[n], XmNdragOperations, XmDROP_COPY); n++;
Packit b099d7
Packit b099d7
	myDC = XmDragStart(w, event, args, n);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void HandleDrag(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDragProcCallback	DragProc;
Packit b099d7
Packit b099d7
	DragProc = (XmDragProcCallback)call_data;
Packit b099d7
Packit b099d7
	fprintf(outfp, "DragProc !\n");
Packit b099d7
	fprintf(outfp, "x = %d\n", DragProc->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", DragProc->y);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DragProc->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "operations = %d\n", DragProc->operations);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void DropTransferCallback(w, closure, seltype, type, value, 
Packit b099d7
								 length, format)
Packit b099d7
Widget 			w;
Packit b099d7
XtPointer 		closure ;
Packit b099d7
Atom 			*seltype ;
Packit b099d7
Atom 			*type ;
Packit b099d7
XtPointer 		value ;
Packit b099d7
unsigned long	*length ;
Packit b099d7
int 			*format ;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XTextProperty	tmp_prop;
Packit b099d7
	int 			num_vals;
Packit b099d7
	int				ok;
Packit b099d7
	char 			*total_tmp_value = NULL;
Packit b099d7
	char 			**tmp_value;
Packit b099d7
	int 			malloc_size = 0;
Packit b099d7
	char 			*actual_value;
Packit b099d7
	int				actual_length = 0;
Packit b099d7
	Cardinal		i;
Packit b099d7
Packit b099d7
Packit b099d7
Packit b099d7
	if (*length)
Packit b099d7
		if (*type == COMPOUND_TEXT) {
Packit b099d7
Packit b099d7
       		tmp_prop.value = (unsigned char *) value;
Packit b099d7
	   		tmp_prop.encoding = *type;
Packit b099d7
			tmp_prop.format = 8;
Packit b099d7
			tmp_prop.nitems = *length;
Packit b099d7
			num_vals = 0;
Packit b099d7
Packit b099d7
			ok = 0;
Packit b099d7
			ok = XmbTextPropertyToTextList(display, &tmp_prop, &tmp_value,
Packit b099d7
										   &num_vals);
Packit b099d7
Packit b099d7
			if (num_vals && (ok == Success || ok > 0)) {
Packit b099d7
Packit b099d7
				for (i = 0; i < num_vals; i++)
Packit b099d7
					malloc_size += strlen(*tmp_value + i);
Packit b099d7
				total_tmp_value = XtMalloc ((unsigned) malloc_size + 1);
Packit b099d7
				total_tmp_value[0] = '\0';
Packit b099d7
				for (i = 0; i < num_vals ; i++)
Packit b099d7
					strcat(total_tmp_value, *tmp_value + i);
Packit b099d7
				actual_value = total_tmp_value;
Packit b099d7
				actual_length = strlen(total_tmp_value);
Packit b099d7
#ifdef DEBUG
Packit b099d7
				fprintf(stderr, "the transfer value is : %s\n", actual_value);
Packit b099d7
				fprintf(stderr, "the length of transfer is : %d\n", 
Packit b099d7
						actual_length);
Packit b099d7
#endif
Packit b099d7
				XFreeStringList(tmp_value);
Packit b099d7
Packit b099d7
			}
Packit b099d7
			else {
Packit b099d7
				if (value) {
Packit b099d7
					XtFree((char *)value);
Packit b099d7
					value = NULL;
Packit b099d7
				}
Packit b099d7
				actual_length = -1;
Packit b099d7
			}
Packit b099d7
Packit b099d7
		}
Packit b099d7
Packit b099d7
#ifdef DEBUG
Packit b099d7
	if (actual_length != -1) {
Packit b099d7
		if (*type == COMPOUND_TEXT)
Packit b099d7
			fprintf(outfp, "the transfer value is : %s\n", actual_value);
Packit b099d7
		else if (*type == XA_PIXMAP)
Packit b099d7
			fprintf(outfp, "the transfer value is of type pixmap\n");
Packit b099d7
		else if (*type == XA_BITMAP)
Packit b099d7
			fprintf(outfp, "the transfer value is of type bitmap\n");
Packit b099d7
		else if (*type == NULL_ATOM)
Packit b099d7
			fprintf(outfp, "the transfer value is of type NULL\n");
Packit b099d7
	}
Packit b099d7
#endif
Packit b099d7
Packit b099d7
	/* You no longer need it, so free it */
Packit b099d7
	if (total_tmp_value != NULL)
Packit b099d7
		XtFree(total_tmp_value);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static void HandleDrop(w, client_data, call_data)
Packit b099d7
Widget		w;
Packit b099d7
XtPointer	client_data, call_data;
Packit b099d7
{
Packit b099d7
Packit b099d7
	XmDropProcCallback		DropProc;
Packit b099d7
	Widget 					dc;
Packit b099d7
	XmDropTransferEntryRec	transferEntries[2];
Packit b099d7
	XmDropTransferEntry		transferList;
Packit b099d7
	Cardinal 				numTransfers = 0;
Packit b099d7
	Cardinal 				numExportTargets;
Packit b099d7
	Atom 					*exportTargets;
Packit b099d7
	Cardinal			 	numImportTargets;
Packit b099d7
	Atom				 	*importTargets;
Packit b099d7
	Arg 					args[MAX_ARGS];
Packit b099d7
	int						n;
Packit b099d7
	char					*string = "TestString";
Packit b099d7
Packit b099d7
Packit b099d7
	DropProc = (XmDropProcCallback)call_data;
Packit b099d7
	dc = DropProc->dragContext;
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNexportTargets, &exportTargets); n++;
Packit b099d7
	XtSetArg(args[n], XmNnumExportTargets, &numExportTargets); n++;
Packit b099d7
	XtGetValues(dc, args, n);
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNimportTargets, &importTargets); n++;
Packit b099d7
	XtSetArg(args[n], XmNnumImportTargets, &numImportTargets); n++;
Packit b099d7
	XmDropSiteRetrieve(w, args, n);
Packit b099d7
Packit b099d7
	fprintf(outfp, "DropProc !\n");
Packit b099d7
	fprintf(outfp, "x = %d\n", DropProc->x);
Packit b099d7
	fprintf(outfp, "y = %d\n", DropProc->y);
Packit b099d7
	fprintf(outfp, "dropSiteStatus = %d\n", DropProc->dropSiteStatus);
Packit b099d7
	fprintf(outfp, "operation = %d\n", DropProc->operation);
Packit b099d7
	fprintf(outfp, "dropAction = %d\n", DropProc->dropAction);
Packit b099d7
Packit b099d7
	transferEntries[0].target = COMPOUND_TEXT;
Packit b099d7
	transferEntries[0].client_data = string;
Packit b099d7
	n = 0;
Packit b099d7
	if (XmTargetsAreCompatible(display, exportTargets, numExportTargets,
Packit b099d7
						   importTargets, numImportTargets) == False) {
Packit b099d7
		XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
Packit b099d7
		XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
Packit b099d7
	}
Packit b099d7
	else {
Packit b099d7
		if (DropProc->operation & XmDROP_MOVE || 
Packit b099d7
			DropProc->operation & XmDROP_COPY) {
Packit b099d7
		
Packit b099d7
			transferList = transferEntries;
Packit b099d7
			numTransfers = 1;
Packit b099d7
			XtSetArg(args[n], XmNdropTransfers, transferList); n++;
Packit b099d7
			XtSetArg(args[n], XmNnumDropTransfers, numTransfers); n++;
Packit b099d7
Packit b099d7
		} 
Packit b099d7
		else {
Packit b099d7
			XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
Packit b099d7
			XtSetArg(args[n], XmNnumDropTransfers, 0); n++;
Packit b099d7
		}
Packit b099d7
	}
Packit b099d7
Packit b099d7
	XtSetArg(args[n], XmNtransferProc, DropTransferCallback); n++;
Packit b099d7
	XmDropTransferStart(dc, args, n);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
static char translations[] = 
Packit b099d7
"#override \
Packit b099d7
  Ctrl<Key>t: XtDisplayTranslations()\n\
Packit b099d7
  Ctrl<Key>a: XtDisplayAccelerators()\n\
Packit b099d7
  Ctrl<Key>i: XtDisplayInstalledAccelerators()\n\
Packit b099d7
  Ctrl<Key>q: Quit()";
Packit b099d7
Packit b099d7
static char dragTranslations[] =
Packit b099d7
"#override \
Packit b099d7
  Ctrl<Key>t: XtDisplayTranslations()\n\
Packit b099d7
  Ctrl<Key>a: XtDisplayAccelerators()\n\
Packit b099d7
  Ctrl<Key>i: XtDisplayInstalledAccelerators()\n\
Packit b099d7
  <Btn2Down>: StartDrag()\n\
Packit b099d7
  Ctrl<Key>q: Quit()";
Packit b099d7
Packit b099d7
static XtActionsRec myactions[] = {
Packit b099d7
	{"Quit", (XtActionProc)Quit},
Packit b099d7
	{"StartDrag", (XtActionProc)StartDrag},
Packit b099d7
};
Packit b099d7
Packit b099d7
Packit b099d7
/*************End of CALLBACK PROCEDURES****************/
Packit b099d7
Packit b099d7
static int ProtoError(dpy, ev)
Packit b099d7
Display	*dpy;
Packit b099d7
XErrorEvent	*ev;
Packit b099d7
{
Packit b099d7
	fprintf(stderr, "Proto Error\n");
Packit b099d7
	fflush(outfp);
Packit b099d7
	fclose(outfp);
Packit b099d7
	exit(0);
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
typedef struct _XlationRepRec{
Packit b099d7
	String		str;
Packit b099d7
	XtTranslations	xlation;
Packit b099d7
}XlationRepRec, *XlationRep;
Packit b099d7
Packit b099d7
typedef struct _AppDataRec{
Packit b099d7
	XlationRepRec	xlation1;
Packit b099d7
	XlationRepRec	xlation2;
Packit b099d7
	Cardinal		numShells, numRows, numCols;
Packit b099d7
	Boolean		applyAccelerators;
Packit b099d7
	Boolean		applyOverrides;
Packit b099d7
}AppDataRec, *AppData;
Packit b099d7
Packit b099d7
XtResource	appResources[] = {
Packit b099d7
	{
Packit b099d7
	"xlations1", XtCTranslations, XtRString, 
Packit b099d7
	sizeof(String), XtOffset(AppData, xlation1.str),
Packit b099d7
	XtRString, (XtPointer)translations,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"xlations1", XtCTranslations, XtRTranslationTable, 
Packit b099d7
	sizeof(XtTranslations), XtOffset(AppData, xlation1.xlation),
Packit b099d7
	XtRString, (XtPointer)translations,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"xlations2", XtCTranslations, XtRString, 
Packit b099d7
	sizeof(String), XtOffset(AppData, xlation2.str),
Packit b099d7
	XtRString, (XtPointer)dragTranslations,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"xlations2", XtCTranslations, XtRTranslationTable, 
Packit b099d7
	sizeof(XtTranslations), XtOffset(AppData, xlation2.xlation),
Packit b099d7
	XtRString, (XtPointer)dragTranslations,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"applyAccelerators", "ApplyAccelerators", XtRBoolean,
Packit b099d7
	sizeof(Boolean), XtOffset(AppData, applyAccelerators),
Packit b099d7
	XtRImmediate, (XtPointer) True,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"applyOverrides", "ApplyOverrides", XtRBoolean,
Packit b099d7
	sizeof(Boolean), XtOffset(AppData, applyOverrides),
Packit b099d7
	XtRImmediate, (XtPointer) True,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"numShells", "NumShells", XtRCardinal,
Packit b099d7
	sizeof(Cardinal), XtOffset(AppData, numShells),
Packit b099d7
	XtRImmediate, (XtPointer) 1,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"numRows", "NumRows", XtRInt,
Packit b099d7
	sizeof(Cardinal), XtOffset(AppData, numRows),
Packit b099d7
	XtRImmediate, (XtPointer) 2,
Packit b099d7
	},
Packit b099d7
	{
Packit b099d7
	"numCols", "NumCols", XtRInt,
Packit b099d7
	sizeof(Cardinal), XtOffset(AppData, numCols),
Packit b099d7
	XtRImmediate, (XtPointer) 3,
Packit b099d7
	},
Packit b099d7
};
Packit b099d7
Packit b099d7
Packit b099d7
void main (argc, argv)
Packit b099d7
unsigned int argc;
Packit b099d7
char **argv;
Packit b099d7
Packit b099d7
{
Packit b099d7
Packit b099d7
	Arg 		args[MAX_ARGS];
Packit b099d7
	int 		n, i, j, k, l;
Packit b099d7
	AppDataRec	appDataRec, *appData;
Packit b099d7
	Widget	 	topLevel, BulletinB, PushBtn, Text;
Packit b099d7
	XEvent		event;
Packit b099d7
	Widget		*buttons;
Packit b099d7
	Cardinal	numButtons;
Packit b099d7
	char		name[80];
Packit b099d7
	Atom		importList[1];
Packit b099d7
Packit b099d7
Packit b099d7
	use_instruction_box = True;
Packit b099d7
Packit b099d7
	appData = &appDataRec;
Packit b099d7
Packit b099d7
	sprintf(name, "%s.out", argv[0]);
Packit b099d7
	if ((outfp = fopen(name, "w+")) == NULL) {
Packit b099d7
Packit b099d7
		fprintf(stderr, "Can not open output file %s.out. Trying in /tmp\n", 
Packit b099d7
				argv[0]);
Packit b099d7
		sprintf(name, "/tmp/%s.out", argv[0]);
Packit b099d7
		if ((outfp = fopen(name, "w+")) == NULL) {
Packit b099d7
			fprintf(stderr, "Can not open output file /tmp/%s.out. Exiting\n", 
Packit b099d7
					argv[0]);
Packit b099d7
			exit(0);
Packit b099d7
		}
Packit b099d7
Packit b099d7
	}
Packit b099d7
Packit b099d7
	XSetErrorHandler(ProtoError);
Packit b099d7
Packit b099d7
	CommonTestInit(argc, argv);
Packit b099d7
Packit b099d7
	if (UserData != NULL)
Packit b099d7
		ProcessCommandArgs();
Packit b099d7
Packit b099d7
	XtAppAddActions(app_context, (XtActionList)myactions, XtNumber(myactions));
Packit b099d7
Packit b099d7
	XtGetApplicationResources(Shell1, (XtPointer)appData, 
Packit b099d7
							  appResources, XtNumber(appResources), NULL, 0);
Packit b099d7
Packit b099d7
	/* try out stuffing the translations directly in */
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNtranslations, appData->xlation1.xlation); n++;
Packit b099d7
	XtSetValues(Shell1, args, n);
Packit b099d7
Packit b099d7
	XtRealizeWidget(Shell1);
Packit b099d7
Packit b099d7
	COMPOUND_TEXT = XmInternAtom(XtDisplay(Shell1), "COMPOUND_TEXT", False);
Packit b099d7
Packit b099d7
	DELETE = XmInternAtom(XtDisplay(Shell1), "DELETE", False);
Packit b099d7
	NULL_ATOM = XmInternAtom(XtDisplay(Shell1), "NULL", False);
Packit b099d7
Packit b099d7
	for (i = 0; i < appData->numShells; i++) {
Packit b099d7
Packit b099d7
		sprintf(name, "topLevel%d",i);
Packit b099d7
		n = 0;
Packit b099d7
		topLevel = XtCreatePopupShell(name, topLevelShellWidgetClass, Shell1, 
Packit b099d7
								   args, n);
Packit b099d7
Packit b099d7
		sprintf(name, "BulletinB%d",i);
Packit b099d7
		n = 0;
Packit b099d7
		BulletinB = XmCreateBulletinBoard(topLevel, name, args, n);
Packit b099d7
		XtManageChild(BulletinB);
Packit b099d7
Packit b099d7
		/* Create numRows x numColumns number of pushButtons */
Packit b099d7
		for (j = 0; j < appData->numCols; j++)
Packit b099d7
			for (k = 0; k < appData->numRows; k++) {
Packit b099d7
Packit b099d7
				n = 0;
Packit b099d7
				XtSetArg(args[n], XtNx, 10 + j * 100); n++;
Packit b099d7
				XtSetArg(args[n], XtNy, 10 + k * 100); n++;
Packit b099d7
				XtSetArg(args[n], XtNwidth, 90); n++;
Packit b099d7
				XtSetArg(args[n], XtNheight, 90); n++;
Packit b099d7
				if (appData->applyOverrides) {
Packit b099d7
					XtSetArg(args[n], XtNtranslations, 
Packit b099d7
							 appData->xlation2.xlation); n++;
Packit b099d7
				}
Packit b099d7
				sprintf(name, "PushBtn%d", (j * appData->numRows) + k);
Packit b099d7
				PushBtn = XmCreatePushButton(BulletinB, name, args, n);
Packit b099d7
				XtManageChild(PushBtn);
Packit b099d7
Packit b099d7
				if (appData->applyAccelerators)
Packit b099d7
					XtInstallAccelerators(PushBtn, BulletinB);
Packit b099d7
Packit b099d7
			}
Packit b099d7
Packit b099d7
		/* Register even numbered buttons as dropSites */
Packit b099d7
		n = 0;
Packit b099d7
		XtSetArg(args[n], XmNchildren, &buttons); n++;
Packit b099d7
		XtSetArg(args[n], XmNnumChildren, &numButtons); n++;
Packit b099d7
		XtGetValues(BulletinB, args, n);
Packit b099d7
		for (l = 0; l < numButtons; l++) {
Packit b099d7
Packit b099d7
			if (l % 2 != 0)
Packit b099d7
				continue;
Packit b099d7
			n = 0;
Packit b099d7
			XtSetArg(args[n], XmNdragProc, HandleDrag); n++;
Packit b099d7
			XtSetArg(args[n], XmNdropProc, HandleDrop); n++;
Packit b099d7
			importList[0] = COMPOUND_TEXT;
Packit b099d7
			if (l != 2) {
Packit b099d7
				XtSetArg(args[n], XmNimportTargets, importList); n++;
Packit b099d7
				XtSetArg(args[n], XmNnumImportTargets, 1); n++;
Packit b099d7
			}
Packit b099d7
			XmDropSiteRegister(buttons[l], args, n);
Packit b099d7
Packit b099d7
		}
Packit b099d7
Packit b099d7
		n = 0;
Packit b099d7
		XtSetArg(args[n], XtNx, 10); n++;
Packit b099d7
		XtSetArg(args[n], XtNy, 10 + k * 100); n++;
Packit b099d7
		XtSetArg(args[n], XtNwidth, k * 100); n++;
Packit b099d7
		XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
Packit b099d7
		sprintf(name, "Text%d",i);
Packit b099d7
		Text = XmCreateText(BulletinB, name, args, n);
Packit b099d7
		XtManageChild(Text);
Packit b099d7
Packit b099d7
		XtPopup(topLevel, XtGrabNone);
Packit b099d7
Packit b099d7
	}
Packit b099d7
Packit b099d7
	if (use_instruction_box == True) {
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
		CommonPause();
Packit b099d7
Packit b099d7
	}
Packit b099d7
Packit b099d7
	XtAppMainLoop(app_context);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
#define	WORD_LEN	32
Packit b099d7
Packit b099d7
ProcessCommandArgs()
Packit b099d7
{
Packit b099d7
Packit b099d7
	char	*user_data;
Packit b099d7
	char	next_word[WORD_LEN + 1];
Packit b099d7
	int     num_spaces;
Packit b099d7
Packit b099d7
	user_data = UserData;
Packit b099d7
Packit b099d7
	while (*user_data != '\0') {
Packit b099d7
Packit b099d7
		get_next_word(user_data, next_word, &num_spaces);
Packit b099d7
		user_data += (strlen(next_word) + num_spaces);
Packit b099d7
Packit b099d7
		if (strcmp(next_word, "-noinstruct") == 0) {
Packit b099d7
			use_instruction_box = False;
Packit b099d7
			continue;
Packit b099d7
Packit b099d7
		}
Packit b099d7
Packit b099d7
	}
Packit b099d7
Packit b099d7
	free(UserData);
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7
get_next_word(source, dest, spaces)
Packit b099d7
char	*source;
Packit b099d7
char	*dest;
Packit b099d7
int		*spaces;
Packit b099d7
{
Packit b099d7
Packit b099d7
	int	n;
Packit b099d7
	int	space_count;
Packit b099d7
Packit b099d7
	space_count = 0;
Packit b099d7
Packit b099d7
	while (isspace(*source)) {
Packit b099d7
		source++;
Packit b099d7
		space_count++;
Packit b099d7
	}
Packit b099d7
Packit b099d7
	n = 0;
Packit b099d7
	while (!isspace(*source) && *source != '\0' && n < WORD_LEN) {
Packit b099d7
		*dest++ = *source++;
Packit b099d7
		n++;
Packit b099d7
	}
Packit b099d7
	*dest = '\0';
Packit b099d7
	*spaces = space_count;
Packit b099d7
Packit b099d7
}