Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!uhccux!galileo!denault From: denault@galileo.ifa.hawaii.edu (Tony Denault) Newsgroups: comp.windows.x Subject: Re: XView scrolling list usage Message-ID: <10351@uhccux.uhcc.Hawaii.Edu> Date: 20 Nov 90 20:57:24 GMT References: <9011200021.AA02255@zia.aoc.nrao.edu> <5873@pizza.cam.nist.gov> Sender: news@uhccux.uhcc.Hawaii.Edu Organization: Institute For Astronomy, Hawaii Lines: 87 > >I would like to change the contents of the list with one call to xv_set(). >And since my lists will have differing number of items, I was looking for a >way to do this without knowing at compile time how many items are in the >list. > Many months ago I posted a request similar to your. I want to be able to update a scroll list quickly. Using the xv_set() calls to delete and insert items in the list was too slow, because xview redraws the panel item on each xv_set() call. Someone posted a solution ( author unknown, sorry I lost the orginal file ) which I use to set the contents of the scrolling list using an argv-style array of strings. I am posting this function. /*---------------------------------------------------------------------------- * scrolling_list_update: * * Given a scrolling list and an argv-style array of strings, * update the contents of the scrolling list. *---------------------------------------------------------------------------- */ void scrolling_list_update(list, argc, argv) Xv_opaque list; int argc; char **argv; { register int i, j; char **avlist; int rows = xv_get(list, PANEL_LIST_NROWS); /* * Copy the string information to an avlist. */ if (argc > 0) { /* * Allocate memory for the list and fill it in. */ avlist = (char **) malloc((argc + 3) * sizeof (char *)); avlist[0] = (char *) PANEL_LIST_STRINGS; for (i = 0; i < argc; i++) avlist[i + 1] = argv[i]; avlist[++i] = (char *) NULL; /* NULL-terminate strings */ avlist[++i] = (char *) NULL; /* NULL-terminate avlist */ /* * Set the scrolling list and free the avlist. */ xv_set(list, ATTR_LIST, avlist, NULL); free((char *) avlist); } /* * This should not be necessary, but ... clear any entries * in excess of the new entries. */ if (rows > argc) { /* * Set up an avlist with PANEL_LIST_DELETE,index pairs. The * panel entries are deleted from bottom (high index) to * top (low index) which might reduce copying of entries. */ avlist = (char **) malloc(((rows-argc)*2+1) * sizeof (char *)); for (j = 0, i = rows - 1; i >= argc; i--) { avlist[j++] = (char *) PANEL_LIST_DELETE; avlist[j++] = (char *) i; } avlist[j] = (char *) NULL; /* NULL-terminate avlist */ /* * Delete the excess entries and free the avlist. */ xv_set(list, ATTR_LIST, avlist, NULL); free((char *) avlist); } } /------------------------------------------------------------------------\ | Tony Denault, Institute for Astronomy, | denault@uhifa.ifa.hawaii.edu | | 2680 Woodlawn Drive, Honolulu, HI 96789 | (808) 956-6097 | \------------------------------------------------------------------------/ -- /------------------------------------------------------------------------\ | Tony Denault, Institute for Astronomy, | denault@uhifa.ifa.hawaii.edu | | 2680 Woodlawn Drive, Honolulu, HI 96789 | (808) 956-6097 | \------------------------------------------------------------------------/