[comp.windows.x.motif] Getting Selection in List

thomsen@sctc.com (Dan Thomsen) (12/20/90)

How can I get a list of the items that are currently in a List widget?
I can use XtGetValues to find the number of items, but I can't get
the List out.   Most likely I am not setting up the space for the
list correctly.   Has anyone done this, and could they mail me a code
fragment?

Thanks

---
Dan  thomsen@sctc.com

meeks@osf.org (W. Scott Meeks) (12/21/90)

>From: swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!spool2.mu.edu!news.cs.indiana.edu!msi.umn.edu!sctc.com!thomsen@ucsd.edu  (Dan Thomsen)
>
>How can I get a list of the items that are currently in a List widget?
>I can use XtGetValues to find the number of items, but I can't get
>the List out.   Most likely I am not setting up the space for the
>list correctly.   Has anyone done this, and could they mail me a code
>fragment?
>

This works for me:

XmListWidget	List1;
register int	n;
Arg			args[MAX_ARGS];
XmStringTable	ItemTab;
int			count;

    n = 0;
    XtSetArg(args[n], XmNitems, &ItemTab); n++;
    XtSetArg(args[n], XmNitemCount, &count); n++;
    XtGetValues(List1, args, n);


Now you can pull the items out of ItemTab and manipulate them however you
like.  Just don't free these strings or the table.  For example:

for (n = 0; n < count; n++)
	if (XmStringCompare(ItemTab[n], teststr)
	   {
		result = XmStringGetLtoR(ItemTab[n], XmSTRING_DEFAULT_CHARSET, &str);
      
	     if (result) 
		   {
			  printf("Found: %s\n", str);
			}
	      else
		{
		  printf ("Couldn't get string for n = %d\n", n);
		}
	    }

Hope this helps.  If you have any more questions, please ask.

W. Scott Meeks
Open Software Foundation
meeks@osf.org
(617) 621-7229