Path: utzoo!utgpu!watmath!att!dptg!rutgers!mailrus!wasatch!cs.utexas.edu!uunet!griffin!pwm
From: pwm@griffin.UUCP (Paul W. McClure)
Newsgroups: comp.windows.x
Subject: Re: Open Look Text Widgets
Message-ID: <207@griffin.UUCP>
Date: 15 Aug 89 13:52:05 GMT
References: <206@griffin.UUCP> <8908071605.AA14931@expo.lcs.mit.edu>
Organization: Phoenix Telecom, Inc.,  Rochester, NY
Lines: 150



	Thank you for your follow-up to my article regarding Open Look
	Text Widgets (Chris Peterson).
	I'm responding with more information as you suggested

> I'm using Open Look with X11R2 and have a question regarding
> Text Widgets. It is similar to a recent posting for the Athena
> toolkit. I need access to selected text and its beginning coordinates
> in my application. I've tried to add actions and augment or override
> translations, for example;

> 	":	myaction()"

> Updating the translation table for an Open Look Text Widget does not
> seem to work (myaction() is never executed). 


/*	This is an example program (Selected_string() is never executed)    */
/* 	****************************************************************    */

#include        
#include        
#include        
#include        
#include        
#include        

void    Selected_string();
void    QuitCallback();

static  XtActionsRec    actionsTable[] = {
                                {"Selected_string",     Selected_string},
                        };

static  char    translation_table[] =
                ":       Selected_string()";

Widget  toplevel,
        form,
        textpane;

int
main(ac,av)
int     ac;
char    *av[];
{
        Arg             args[8];
        register        n;
        XtTranslations  new_translations;

        if(ac != 2) {
                fprintf(stderr,"Usage: %s text_filename\n",*av);
                exit(1);
        }

        toplevel = OlInitialize(*av, "Test", NULL, 0, &ac, av);

        XtAddActions(actionsTable, XtNumber(actionsTable));
        new_translations = XtParseTranslationTable(translation_table);

        n = 0;
        XtSetArg(args[n], XtNxResizable, TRUE);                         n++;
        XtSetArg(args[n], XtNyResizable, TRUE);                         n++;
        form = XtCreateManagedWidget("form", formWidgetClass, toplevel,
                                                                args, n);

        create_text_area(form,av[1]);

        XtOverrideTranslations(textpane, new_translations);

        XtRealizeWidget(toplevel);

        XtMainLoop();
}

create_text_area(parent,textfile)
Widget  parent;
char    *textfile;
{
        register  n;
        Arg       args[32];

        n = 0;
        XtSetArg(args[n], XtNborderWidth, 0);                           n++;
        XtSetArg(args[n], XtNbackground, (Pixel)2);                     n++;
        XtSetArg(args[n], XtNfontColor, (Pixel)12);                     n++;
        XtSetArg(args[n], XtNeditType, OL_TEXT_READ);                   n++;
        XtSetArg(args[n], XtNfile, textfile);                           n++;
        XtSetArg(args[n], XtNverticalSB, TRUE);                         n++;
        XtSetArg(args[n], XtNgrow, OL_GROW_HORIZONTAL);                 n++;
        XtSetArg(args[n], XtNwrap, FALSE);                              n++;
        XtSetArg(args[n], XtNsourceType, OL_DISK_SOURCE);               n++;

        /* Form Constraints */

        XtSetArg(args[n], XtNxAttachRight, TRUE);                       n++;
        XtSetArg(args[n], XtNyAttachBottom, TRUE);                      n++;
        XtSetArg(args[n], XtNxVaryOffset, FALSE);                       n++;
        XtSetArg(args[n], XtNyVaryOffset, FALSE);                       n++;
        XtSetArg(args[n], XtNyOffset, 58);                              n++;
        XtSetArg(args[n], XtNxOffset, 49);                              n++;
        XtSetArg(args[n], XtNxResizable, TRUE);                         n++;
        XtSetArg(args[n], XtNyResizable, TRUE);                         n++;

        textpane = XtCreateManagedWidget("textpane", textWidgetClass,
                                                        parent, args, n);

        XtAddCallback(textpane, XtNleaveVerification, QuitCallback, textpane);

}

void
Selected_string(w, event, parms, nparms)
Widget  w;
XEvent  *event;
String  *parms;
int     nparms;
{
        printf("Selected_string(): it works\n");
        exit(0);
}

void
QuitCallback(w, clientData, callData)
Widget  w;
caddr_t clientData,
        callData;
{
        printf("QuitCallback(): bye\n");
        exit(0);
}


> Also for the Text Widget:
> 	- I would like to access the original translation table 
> but have not had any luck doing so.

I cannot find a description of the Text Widget's default translation table
in the documentation I have for Open Look. I would like to read the 
default translations so that I can include default actions in my new
table. I don't want to override the original action for the event, I
only want to add another action. According to my X Toolkit documentation,
XtAugmentTranslations will not help me if the event already exists in the
widget's translations.

			Thank you 
					Paul McClure
					Phoenix Telecom Inc.
					uunet!fenicks!pwm