[comp.windows.x] asciiDisk Athena Widget

pusateri@macbeth.cs.duke.edu (Thomas J. Pusateri) (11/29/89)

I thought I finally figured out the Athena Text widgets and so I wrote
this short program which should act like an editor. It uses the
asciiDiskWidgetClass. However, the program will not let me input any
text from the keyboard. It just beeps at me.  Any one have any helpful
hints?

I have compiled the following program on a sun3 and a sun4 (OS 4.0.3)
and ran it using the OpenWindows 1.0 beta2 window manager.

Feel free to modify it any way you like!

Tom Pusateri

pusateri@nbsr.duke.edu


---------------------- Cut Here -------------------------------------
#include <stdio.h>		/* C standard I/O library	   */
#include <X11/Intrinsic.h>	/* X toolkit initrinsics	   */
#include <X11/StringDefs.h>	/* X String definitions		   */
#include <X11/Shell.h>		/* X top level shell definitions   */
#include <X11/Cardinals.h>	/* X type definitions		   */
#include <X11/Form.h>		/* Athena form widget defs	   */
#include <X11/Command.h>	/* Athena command widget defs	   */
#include <X11/AsciiText.h>	/* More Athena text widget defs	   */

#ifndef lint
static char RCSid[]=
"$Id: test.c,v 1.1 89/11/28 17:29:55 pusateri Exp $";
#endif

main(argc, argv)
int argc;
char *argv[];
{
    void quit_callback();	/* quit command button event handler */	

    char Temporary[16];		/* name of temporary text widget file */
    FILE *fp;			/* text widget temporary file */
    unsigned int n;
    Arg arg[20];

    Widget toplevel,
	   form,
	   annot,
	   quit;

    (void) strcpy(Temporary, "tmpfile");

    if ((fp=fopen(Temporary,"w")) == NULL) {
	fprintf(stderr,"%s: unable to open %s\n",argv[0],Temporary);
	exit(1);
    }
    (void) fclose(fp);

 		/* initialize X Display */
    toplevel = XtInitialize(NULL, "testing", NULL, ZERO, &argc, argv);

    n = 0;
    XtSetArg(arg[n], XtNinput, True);			n++;
    XtSetValues(toplevel, arg, n);

    form = XtCreateManagedWidget("form",formWidgetClass,
	toplevel,(Arg *)NULL,0);

    n = 0;		/* display annotation */
    XtSetArg(arg[n], XtNheight, (Dimension) 200);	n++;
    XtSetArg(arg[n], XtNwidth, (Dimension) 500);	n++;
    XtSetArg(arg[n], XtNfile, Temporary);		n++;
    XtSetArg(arg[n], XtNeditType, XttextEdit);		n++;
    XtSetArg(arg[n], XtNtextOptions,
	editable|scrollVertical|wordBreak|scrollOnOverflow);	n++;
    annot = XtCreateManagedWidget("annot", asciiDiskWidgetClass, form, arg, n);

    n = 0;		/* quit command button */
    XtSetArg(arg[n], XtNvertDistance, 20);		n++;
    XtSetArg(arg[n], XtNfromVert, annot);		n++;
    XtSetArg(arg[n], XtNhorizDistance, 250);		n++;
    XtSetArg(arg[n], XtNfromHoriz, NULL);		n++;
    XtSetArg(arg[n], XtNlabel, "Quit");			n++;
    quit=XtCreateManagedWidget("quit", commandWidgetClass, form,arg,n);
    XtAddCallback(quit, XtNcallback, quit_callback,(caddr_t) toplevel);

    XtRealizeWidget(toplevel);

    XtMainLoop();			  /* let X windows process events */

}

void quit_callback(widget, clientData, callData)
Widget widget;                  /* unused */
caddr_t clientData;             /* toplevel */
caddr_t callData;               /* unused */
{
    Widget toplevel = (Widget) clientData;

    XtUnmapWidget(toplevel);
    exit(0);
}

/*
   Thomas Pusateri
   pusateri@nbsr.duke.edu

 */