1. Xt and the Athena Widgets

Athena Widgets

Basic Xt Functions

1) XtInitialize

    Widget XtInitialize(shell_name, application_class, options,
	 num_options, argc, argv)
    String         shell_name;
    String         application_name;
    XrmOptionDescRec options[];
    int            num_options;
    int            *argc;
    char           *argv[];

2) XtCreateManagedWidget

3) XtRealizeWidget

4) XtMainLoop

5) XtAddCallback

Example Program


  /*****************************************************
   *
   *                simple.c
   *
   *  A very simple X program that uses the Athena
   *  widgets
   *
   ****************************************************/

  #include < X11/StringDefs.h >
  #include  < X11/Intrinsic.h > 
  #include  < X11/Xaw/Command.h > 

  main(argc,argv)
  int argc;
  char **argv; {
       Widget toplevel;
       Widget command;
       void quit();

       toplevel = XtInitialize(argv[0],"simple",NULL, 0,
		 &argc, argv);

       command = XtCreateManagedWidget("press and die",
		 commandWidgetClass, toplevel, NULL, 0);

       XtAddCallback(command,XtNcallback,quit, NULL);

       XtRealizeWidget(toplevel);

       XtMainLoop();

  }


  void quit(w,client,call)
  Widget w;
  XtPointer client;
  XtPointer call; {

       exit(0);

  }

Setting Resource Values

Example Program

  /*****************************************************
   *
   *                simple.c
   *
   *  A very simple X program that uses the Athena
   *  widgets
   *
   ****************************************************/

  #include  < X11/StringDefs.h > 
  #include  < X11/Intrinsic.h > 
  #include  < X11/Xaw/Command.h > 

  main(argc,argv)
  int argc;
  char **argv; {
       Widget toplevel;
       Widget command;
       void quit();
       Arg  wargs[10];
       int  n;

       toplevel = XtInitialize(argv[0],"simple",NULL, 0,
		 &argc, argv);

       command = XtCreateManagedWidget("command",
		 commandWidgetClass, toplevel, NULL, 0);

       n = 0;
       XtSetArg(wargs[n],XtNheight,200); n++;
       XtSetArg(wargs[n],XtNwidth,200); n++;
       XtSetArg(wargs[n],XtNlabel,"press and die"); n++;
       XtSetValues(command,wargs,n);

       XtAddCallback(command,XtNcallback,quit, NULL);

       XtRealizeWidget(toplevel);

       XtMainLoop();

  }


  void quit(w,client,call)
  Widget w;
  XtPointer client;
  XtPointer call; {

       exit(0);

  }



Example Program


  /*****************************************************
   *
   *                simple.c
   *
   *  A very simple X program that uses the Athena
   *  widgets
   *
   ****************************************************/

  #include  < X11/StringDefs.h > 
  #include  < X11/Intrinsic.h > 
  #include  < X11/Xaw/Box.h > 
  #include  < X11/Xaw/Command.h > 
  #include  < X11/Xaw/Label.h > 

  main(argc,argv)
  int argc;
  char **argv; {
       Widget toplevel;
       Widget box;
       Widget command;
       Widget label;
       void quit();
       Arg  wargs[10];
       int  n;

       toplevel = XtInitialize(argv[0],"simple",NULL, 0,
		 &argc, argv);

       box = XtCreateManagedWidget("box",boxWidgetClass,
		 toplevel, NULL, 0);

       n = 0;
       XtSetArg(wargs[n],XtNorientation,XtorientVertical); n++;
       XtSetArg(wargs[n],XtNvSpace,10); n++;
       XtSetValues(box,wargs,n);

       label = XtCreateManagedWidget("label",
		 labelWidgetClass, box, NULL, 0);

       n = 0;
       XtSetArg(wargs[n],XtNlabel,"Hello World"); n++;
       XtSetValues(label,wargs,n);

       command = XtCreateManagedWidget("command",
		 commandWidgetClass, box, NULL, 0);

       n = 0;
       XtSetArg(wargs[n],XtNlabel,"press and die"); n++;
       XtSetValues(command,wargs,n);

       XtAddCallback(command,XtNcallback,quit, NULL);

       XtRealizeWidget(toplevel);

       XtMainLoop();

  }


  void quit(w,client,call)
  Widget w;
  XtPointer client;
  XtPointer call; {

       exit(0);

  }


Creating and Managing Widgets

Example Program


  /*****************************************************
   *
   *                simple.c
   *
   *  A very simple X program that uses the Athena
   *  widgets
   *
   ****************************************************/

  #include  < X11/StringDefs.h > 
  #include  < X11/Intrinsic.h > 
  #include  < X11/Xaw/Box.h > 
  #include  < X11/Xaw/Command.h > 
  #include  < stdio.h > 

  char *names[] = {
       "button1",
       "button2",
       "button3",
       "button4",
       "button5",
       0
  };


  int values[] = {
       1,
       2,
       3,
       4,
       5
  };


  main(argc,argv)
  int argc;
  char **argv; {
       Widget toplevel;
       Widget box;
       Widget command;
       void quit();
       void bprint();
       Arg  wargs[10];
       int  n;
       Widget    buttons[20];
       int  nbuttons;

       toplevel = XtInitialize(argv[0],"simple",NULL, 0,
		 &argc, argv);

       box = XtCreateManagedWidget("box",boxWidgetClass,
		 toplevel, NULL, 0);

       n = 0;
       XtSetArg(wargs[n],XtNorientation,XtorientVertical); n++;
       XtSetArg(wargs[n],XtNvSpace,10); n++;
       XtSetValues(box,wargs,n);

       command = XtCreateManagedWidget("quit",
		 commandWidgetClass, box, NULL, 0);

       XtAddCallback(command,XtNcallback,quit, NULL);

       nbuttons = 0;
       while(names[nbuttons] != 0) {
	    buttons[nbuttons] = XtCreateWidget(names[nbuttons],
			   commandWidgetClass, box, NULL, 0);

	    XtAddCallback(buttons[nbuttons],XtNcallback,bprint,
			   &values[nbuttons]);

	    nbuttons++;
       }

       XtManageChildren(buttons,nbuttons);

       XtRealizeWidget(toplevel);

       XtMainLoop();

  }


  void quit(w,client,call)
  Widget w;
  XtPointer client;
  XtPointer call; {

       exit(0);

  }


  bprint(w,client,call)
  Widget w;
  int  *client;
  XtPointer call; {

       printf("button %d\n",*client);
  }



  Go to Introduction        Go to Index        Go to Simple Widgets