[comp.windows.x] Help with XView`s PANEL_LIST

denault@wirth.ifa.hawaii.EDU (Anthony Denault) (01/23/91)

> 1.  I'm xv_create(ing) a PANEL_LIST.  Whenever I insert or delete items,
>it appears as if OW redraws the entire list.  This causes a "flashing"
>that is very annoying (especially since I update the list frequently).
>I'm hoping that there is a way around this... Any clues?

 
I got this function from the net. Original author is not knowned. It sets the
contents of a scrolling list from a list of string in an argc-style parameter.
 
Since it update the entire list at once, there is no "flashing" for each 
insert or delete. (There is only 1 re-draw of the list).

 
/*----------------------------------------------------------------------------
 * 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
/------------------------------------------------------------------------\
| Tony Denault, Institute for Astronomy,  | denault@uhifa.ifa.hawaii.edu |
| 2680 Woodlawn Drive, Honolulu, HI 96789 |               (808) 956-6097 |
\------------------------------------------------------------------------/

fgreco@govt.shearson.COM (Frank Greco) (01/24/91)

> 
> > 1.  I'm xv_create(ing) a PANEL_LIST.  Whenever I insert or delete items,
> >it appears as if OW redraws the entire list.  This causes a "flashing"
> >that is very annoying (especially since I update the list frequently).
> >I'm hoping that there is a way around this... Any clues?
> 
>  
> I got this function from the net. Original author is not knowned. It sets the
> contents of a scrolling list from a list of string in an argc-style parameter.
>  
> Since it update the entire list at once, there is no "flashing" for each 
> insert or delete. (There is only 1 re-draw of the list).
> 
>src follows...


	This works only if the number of attributes passed to xv_set()
	is less than 250 (value of ATTR_STANDARD_SIZE).  For more than
	that (eg, loading the list from a database where you don't
	know a priori the size of the list) you would have to either
	batch groups of xv_set()'s or, punt and "turn show off, load
	the list and then turn show back on".

	How about adding PANEL_LIST_STRINGLIST to a new version of XView
	that accepted a null-terminated list of char *?  It would be
	free from the ATTR_STANDARD_SIZE limitation.


	Frank G.

ed@klg.UUCP ( KL Group Inc.) (01/24/91)

In article <9101231625.AA03709@fis1.shearson.com> fgreco@govt.shearson.COM (Frank Greco) writes:
>> 
>> > 1.  I'm xv_create(ing) a PANEL_LIST.  Whenever I insert or delete items,
>> >it appears as if OW redraws the entire list.  This causes a "flashing"
>> >that is very annoying (especially since I update the list frequently).
>> >I'm hoping that there is a way around this... Any clues?
>> 
>>  
>> I got this function from the net. Original author is not knowned. It sets the
>> contents of a scrolling list from a list of string in an argc-style parameter.
>>  
>> Since it update the entire list at once, there is no "flashing" for each 
>> insert or delete. (There is only 1 re-draw of the list).
>> 

Another solution is to use the PANEL_PAINT attribute; every time you insert an
item into the list, do this:

    for (i=0; i<NSTRINGS; i++)  {
        xv_set(object,
            PANEL_LIST_INSERT,      i,
            PANEL_LIST_STRING,      i, string,
            PANEL_PAINT,            PANEL_NONE,
        0);
    }

Once all insertions have taken place, set PANEL_PAINT to PANEL_CLEAR:

    xv_set(object,
        PANEL_PAINT,    PANEL_CLEAR,
    0);

Ed Lycklama

KL Group Inc.                       | Phone: (416) 594-1026 
134 Adelaide St. E, Suite 204       | Fax:   (416) 594-1919
Toronto, Ontario, M5C 1K9           | UUCP:  ut{zoo|csri}!suncan!klg!ed
CANADA