[comp.windows.x] Open Look Text Widgets

pwm@griffin.UUCP (Paul W. McClure) (08/04/89)

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;

	"<Btn1Down>:	myaction()"

Updating the translation table for an Open Look Text Widget does not
seem to work (myaction() is never executed). 
I've also tried adding an event handler for ButtonPressMask. This makes
the coordinates available (through the event structure) but changes
the behavior of Button1. Wipe through selections now begin at (0,0),
rather than where Button1 was pressed.

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

Any suggestions would be appreciated	-thank you
					Paul McClure
					Phoenix Telecom Inc.
					uunet!fenicks!pwm

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/07/89)

> I've tried to add actions and augment or override
> translations, for example;

> 	"<Btn1Down>:	myaction()"

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

Without a short example program, I don't know what the problem is.

> Also for the Text Widget:
> 	- I would like to set compress_motion for the Text Widget and

Unless you are rewriting the widget you REALLY don't want to do this.
Most likely this will break the Text widget.

>      	- access the original translation table 

What does this mean?  If you want to just read the values, I would hope that the
documentation contains an accurate version of the default translation table.  If
you want to change the translation table then simply changing the resources or
using XtOverrideTranslations() or XtAugmentTranslations() should do the trick.


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

pwm@griffin.UUCP (Paul W. McClure) (08/15/89)

	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;

> 	"<Btn1Down>:	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        <stdio.h>
#include        <Intrinsic.h>
#include        <StringDefs.h>
#include        <OpenLook.h>
#include        <Form.h>
#include        <Text.h>

void    Selected_string();
void    QuitCallback();

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

static  char    translation_table[] =
                "<Btn1Up>:       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