[comp.windows.x] Having trouble using XtAugmentTranslations

snl@edrc.cmu.edu (Sean Levy) (06/14/89)

I've implimented a simple run-time widget resource editor. I have
things set up so that you can register an action called ResEdit that
takes two parameters: the name of a shell to create the ResEdit popup
under (typically the name of your top-level shell) and an optional
font name to use in ResEdit.  I'm able to register the action without
problem, but I'm having trouble getting it invoked by the translation
manager. I have a translation:

   static String my_translations = "Ctrl <Btn2Down>: ResEdit(foo, 9x15)";

(for instance). After I call XtInitialize() and XtAppAddActions(), I
create a popup shell with a box in it, into which I stick various
widgets (one of my own devising, a couple Athena Label and Command
widgets). After every XtCreateManagedWidget(), I immediately do an
XtAugmentTranslations() with my translations (which compiled fine, I
believe -- how do you tell?  the type XtTranslations is opaque...).

All of this augmenting is, however, to no avail, as the
Ctrl/Button2Down sequence does not even call have the desired effect
(ResEdit never even gets called).  I've tried various other sequences
(Meta-E, various modifiers on various buttonpresses), all with no
effect. As it stands, I have to wire a Command widget to a callback
that explicitly calls the resource editor proper on a particular
widget (well, I _could_ play with that), which is grody and surely
uneccessary...

What am I doing wrong?

TIA,

sean levy - research programmer / engineering design research center / cmu
  internet: snl@edrc.cmu.edu           bitnet: snl@edrc.cmu.edu%CMCCVMA
      uucp: ...!harvard!cs.cmu.edu!snl  2wire: 412 268 2257
      dirt: edrc / cmu / doherty hall a219 / pittsburgh pa 15213
-- 
sean levy - research programmer / engineering design research center / cmu
  internet: snl@edrc.cmu.edu           bitnet: snl@edrc.cmu.edu%CMCCVMA
      uucp: ...!harvard!cs.cmu.edu!snl  2wire: 412 268 2257
      dirt: edrc / cmu / doherty hall a219 / pittsburgh pa 15213
-- 

converse@EXPO.LCS.MIT.EDU (Donna Converse) (06/15/89)

> I have a translation:
> 
>   static String my_translations = "Ctrl <Btn2Down>: ResEdit(foo, 9x15)";
>
	[description of organization of the interface code, and the
	order of Xt calls]

> ... to no avail, as the
> Ctrl/Button2Down sequence does not even call have the desired effect
> (ResEdit never even gets called).


I cannot duplicate this problem.
Try this sample code: it works here.

Donna Converse
converse@expo.lcs.mit.edu
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Box.h>
#include <X11/Command.h>

Syntax(call)
    char	*call;
{
    fprintf(stderr, "Usage: %s\n", call);
    fprintf(stderr, "press mouse button 1 in the first button.\n");
    fprintf(stderr, "press control-mouse button 2 in the second button.\n");
    exit(1);
}

/*ARGSUSED*/
void ActionProc(w, event, vector, count)
    Widget      w;		/* unused */
    XEvent	*event;		/* unused */
    String	*vector;
    Cardinal	*count;
{
    int i;
    printf("Hello World!\n");
    for (i=0; i < *count; i++)		/* demonstrate parameters */
	printf("%s\t", vector[i]);
    printf("\n");
}

XtActionsRec actionTable[] = {
    {"ActionProc",	ActionProc},
};

/*ARGSUSED*/
void CallbackProc(w, client_data, call_data)
    Widget      w;		/* unused */
    caddr_t     client_data;    
    caddr_t     call_data;      /* unused */
{
    Widget ws = (Widget) client_data;
    XtPopup(ws, XtGrabNonexclusive);
}


void main(argc, argv)
    unsigned int	argc;
    char		**argv;
{
    Widget	toplevel, shell, box, button1, button2;
    Arg		args[3];
    Cardinal	i;
    static XtCallbackRec callbacks[] = {
    {CallbackProc, NULL},
    {NULL, NULL},
    };

    toplevel = XtInitialize("main", "Demo", NULL, 0, &argc, argv);
    if (argc != 1) Syntax(argv[0]);

    XtAppAddActions(XtWidgetToApplicationContext(toplevel), actionTable,
		    XtNumber(actionTable));

    shell = XtCreatePopupShell("popup", applicationShellWidgetClass,
			       toplevel, NULL, (Cardinal)0);
    
    i = 0;
    XtSetArg(args[i], XtNwidth, 100);		i++;
    XtSetArg(args[i], XtNheight, 100);		i++;
    callbacks[0].closure = (caddr_t) shell;
    XtSetArg(args[i], XtNcallback, callbacks);	i++;
    button1 = XtCreateManagedWidget("button1", commandWidgetClass, 
				    toplevel, args, i);

    box = XtCreateManagedWidget("box", boxWidgetClass, shell, NULL, 
				(Cardinal) 0);

    i = 0;
    XtSetArg(args[i], XtNwidth, 100);		i++;
    XtSetArg(args[i], XtNheight, 100);		i++;
    button2 = XtCreateManagedWidget("button2", commandWidgetClass, box,
				   args, i);

    XtAugmentTranslations(button2, XtParseTranslationTable
			  ("Ctrl<Btn2Down>:ActionProc(foo, 9x15)\n"));
    
    XtRealizeWidget(toplevel);
    XtMainLoop(); 
}

swick@ATHENA.MIT.EDU (Ralph R. Swick) (06/16/89)

> Date: 13 Jun 89 22:23:33 GMT
> From: edrc.cmu.edu!snl@pt.cs.cmu.edu  (Sean Levy)
>...
> translations (which compiled fine, I
> believe -- how do you tell?

There are no error messages displayed (or calls to your XtWarningMsgHandler)
and the return value is not NULL.

> All of this augmenting is, however, to no avail

Does it make any difference if you override instead?  You've not
given enough description to tell what else might be going on.
What you're trying to do has certainly been successfully done elsewhere.