/* $Header: /cvsroot/lesstif/lesstif/test/Xm/list/test28.c,v 1.2 2004/08/21 08:37:40 dannybackx Exp $ */ /* > There is an error in XmList... > > Starting condition: You have a list with one item and it's selected. > Call XmListAddItemUnselected() to add another item before it. > Then XmListDeletePos() to delete the old item. > > Problem: When adding the new item, it does not adjust the > List_SelectedIndices, so the list still thinks item 1 (the first > one) is highlighted when actually it's item 2. > > Then when XmListDeletePos() is called, it fails to find the > item being deleted (2) in SelectedIndices and so > List_SelectedItemCount() never gets decremented > > Later a call to XmListGetSelectedPos thinks that the > List_SelectedItemCount == 1, and allocates (but doesn't > clear) an array of that many. It then ignores the > List_SelectedIndices (they're wrong anyway) and goes > through every item, looking for ones where selected is > true. It finds none because it was deleted. As a result, the > caller is told that there is one item selected and the index > of the selected item is random garbage. > > -- Dave Williss */ #include #include #include #include "../../common/Test.h" Widget toplevel, listw, form, b1, b2, b3; void Doit1(Widget w, XtPointer client, XtPointer call) { XmString xms; xms = XmStringCreateSimple("new item"); XmListAddItemUnselected(listw, xms, 1); } void Doit2(Widget w, XtPointer client, XtPointer call) { int sic = 1234; XmListDeletePos(listw, 2); XtVaGetValues(listw, XmNselectedItemCount, &sic, NULL); fprintf(stderr, "SelectedItemCount => %d\n", sic); } void Doit3(Widget w, XtPointer client, XtPointer call) { int nselected, i; int *selected = NULL; (void)XmListGetSelectedPos(listw, &selected, &nselected); fprintf(stderr, "Selected Item Count => %d\n", nselected); fprintf(stderr, "Selected items : {"); for (i=0; i