[comp.windows.x] Help with the list widget

jsalter@polyslo.CalPoly.EDU (Notes from the Underground) (04/13/89)

I've tried not to, honest, but I've finally admitted I'm stuck.

Does anyone have any helpful hints or code using the List widget.

I've researched the xman source, but could use something a little
more informative.

-- 
James A. Salter (jim/jsalter)   | Do you think Salman Rushdie's ass would
jsalter@polyslo.CalPoly.EDU     | be better off now if he had put :) :) :)
..!ucbvax!voder!polyslo!jsalter | in his book? -- eli

jlf@earth.cray.COM (John Freeman) (04/13/89)

> Does anyone have any helpful hints or code using the List widget.

Here is a simple program using the list widget - note that it looks
suspiciously like a menu.  Hope this helps.
--------------------------------------------------------------------------------
#include <stdio.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/List.h>

String the_list[] = {
    "select me!",
    "no, me!",
    "but not:",
    "quit",
    NULL
};


/* ARGSUSED */
void Activate(w, closure, listp)
    Widget w;
    caddr_t closure;
    XtListReturnStruct *listp;
{
    /** A practical use would be to use a switch & case here or a jump table **/
printf( "button \"%s\" was pressed, index = %d\n",listp->string, listp->index );
    if (listp->index == 3) {
	printf("List Widget Demo exiting\n");
	exit(0);
    }
}

void main(argc, argv)
    unsigned int argc;
    char **argv;
{
    Widget toplevel;
    static XtCallbackRec callbacks[] = {
      { Activate, NULL },
      { NULL, NULL },
    };

    static Arg argies[] = {
      { XtNlist, (XtArgVal)the_list },
      { XtNdefaultColumns, (XtArgVal)1 },
      { XtNforceColumns, (XtArgVal)True },
      { XtNverticalList, (XtArgVal)True },
      { XtNcallback, (XtArgVal)callbacks },
    };

    toplevel = XtInitialize( NULL, "List Widget Demo", NULL, 0, &argc, argv );

    XtCreateManagedWidget( "list", listWidgetClass, toplevel,
			   argies, XtNumber(argies) );
    
    XtRealizeWidget(toplevel);
    XtMainLoop();
}