From: chuck@IMSI.COM (Chuck Ocheret)
Newsgroups: fj.mail-lists.x-window
Subject: translation complication
Date: 17 Dec 92 13:12:39 GMT
Distribution: fj
Organization: Workstation Div., Supermicro Systems Group, Sony Corporation

Date: Tue, 15 Dec 92 14:07:53 EST
Message-Id: <9212151907.AA26253@IMSI.COM>
Errors-To: xpert-request@expo.lcs.mit.edu
Errors-To: xpert-request@expo.lcs.mit.edu
Errors-To: xpert-request@expo.lcs.mit.edu

Can someone please simplify my translations...

I include here source for a simple program to experiment with
translations.  What I want is to be able to distinguish the following
user actions for the following purposes:

	<Btn1Down>		initiate a 'move' operation
	<Btn1Down>(2)		initiate a 'resize' operation
	<Btn1Motion>		do the operation
	Shift<Btn1Motion>	do the operation with constraints
	<Btn1Up>		complete the operation

The program below which demonstrates the problem doesn't actually move
or resize anything.  It provides a single action 'show' which displays
the params passed to the action procedure.

My first attempt at what seemed like a simple and obvious solution
looks like:

static String	translationTable = "\
	<Btn1Down>:		show(move) \n\
	<Btn1Down>(2):		show(resize) \n\
	Shift<Btn1Motion>:	show(constrained) \n\
	<Btn1Motion>:		show(unconstrained) \n\
	<Btn1Up>:		show(finish)";

Problems with this:
	- Neither of the motion translations ever fire.

	- Simply doing a single click causes only <Btn1Down> to fire;
	  the <Btn1Up> doesn't fire.  <Btn1Up> only fires after
	  a <Btn1Down>(2).

After many other attempts I came up with...

static String	translationTable = "\
	<Btn1Up>: \
		show(finish_1) \n\
	<Btn1Down>: \
		show(move) \n\
	<Btn1Down>,<Btn1Up>: \
		show(finish_2) \n\
	<Btn1Down>,Shift<Btn1Motion>(1+): \
		show(constrained_1) \n\
	<Btn1Down>,Shift<Btn1Motion>(1+),<Btn1Motion>(1+): \
		show(unconstrained_1) \n\
	<Btn1Down>,<Btn1Motion>(1+),Shift<Btn1Motion>(1+): \
		show(constrained_2) \n\
	<Btn1Down>,<Btn1Motion>(1+): \
		show(unconstrained_2) \n\
	<Btn1Down>(2): \
		show(resize) \n\
	<Btn1Down>(2),Shift<Btn1Motion>(1+): \
		show(constrained_3) \n\
	<Btn1Down>(2),Shift<Btn1Motion>(1+),<Btn1Motion>(1+): \
		show(unconstrained_3) \n\
	<Btn1Down>(2),<Btn1Motion>(1+),Shift<Btn1Motion>(1+): \
		show(constrained_4) \n\
	<Btn1Down>(2),<Btn1Motion>(1+): \
		show(unconstrained_4)";

which mostly works.  Problems with this:
	- If I move the mouse at all while trying to double click
	  it shows up as two single clicks.

	- I need to do this is many places and it seems too damn
	  complicated for what seems like a simple situation.

Please advise...

---------cut here---------
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

static void
_ShowAction(w, event, params, numParams)
	Widget		w;
	XEvent		*event;
	String		*params;
	Cardinal	*numParams;
{
	int	i;

	(void)fprintf(stderr, "->");
	for (i = 0; i < *numParams; i++)
		(void)fprintf(stderr, "\t%s\n", params[i]);
}

static XtActionsRec actionsTable[] = {
	{ "show",		_ShowAction },
};

static String	translationTable = "\
	<Btn1Up>: \
		show(finish_1) \n\
	<Btn1Down>: \
		show(move) \n\
	<Btn1Down>,<Btn1Up>: \
		show(finish_2) \n\
	<Btn1Down>,Shift<Btn1Motion>(1+): \
		show(constrained_1) \n\
	<Btn1Down>,Shift<Btn1Motion>(1+),<Btn1Motion>(1+): \
		show(unconstrained_1) \n\
	<Btn1Down>,<Btn1Motion>(1+),Shift<Btn1Motion>(1+): \
		show(constrained_2) \n\
	<Btn1Down>,<Btn1Motion>(1+): \
		show(unconstrained_2) \n\
	<Btn1Down>(2): \
		show(resize) \n\
	<Btn1Down>(2),Shift<Btn1Motion>(1+): \
		show(constrained_3) \n\
	<Btn1Down>(2),Shift<Btn1Motion>(1+),<Btn1Motion>(1+): \
		show(unconstrained_3) \n\
	<Btn1Down>(2),<Btn1Motion>(1+),Shift<Btn1Motion>(1+): \
		show(constrained_4) \n\
	<Btn1Down>(2),<Btn1Motion>(1+): \
		show(unconstrained_4)";

main(argc, argv)
	int	argc;
	char	*argv[];
{
	Widget		top, core;
	XtAppContext	app;
	XtTranslations	translations;

	top = XtAppInitialize(&app, "Trans", NULL, 0, &argc, argv,
	    NULL, NULL, 0);

	core = XtVaCreateManagedWidget("core", coreWidgetClass, top,
	    XtNwidth,	500,
	    XtNheight,	500,
	  NULL);

	XtAppAddActions(app, actionsTable, XtNumber(actionsTable));

	translations = XtParseTranslationTable(translationTable);

	XtOverrideTranslations(core, translations);

	XtRealizeWidget(top);
	XtAppMainLoop(app);
}