pjs@aristotle.JPL.NASA.gov (Peter Scott) (08/06/90)
I have an application which wishes to switch the contents of a list upon command. The only way I have found to do this is to call XmListDeleteItem() on every previous item and then XmListAddItemUnselected() on the new ones. Since the lists are ~70 items long, this produces some spectacular pyrotechnics which are unfortunately not worth the time they consume. Any ideas for more rapid solutions? This is news. This is your | Peter Scott, NASA/JPL/Caltech brain on news. Any questions? | (pjs@aristotle.jpl.nasa.gov)
pjs@aristotle.JPL.NASA.gov (Peter Scott) (08/07/90)
Since this particular case involved switching between only two lists, both of which can be set up at compile time, I tried the following: list1 = XmCreateScrolledList (...) ; XtManageChild (list1); list2 = XmCreateList (XtParent(list1) ...); /* Add items to both lists */ In the list-switch callback, I unmanage the list that's currently managed, then manage the other one. I have also tried managing both lists, then unmanaging the one I don't want initially after realizing the widget tree. Unfortunately, this produces some extremely weird results; like two scroll bars in the window, one shorter than the other; one of them vanishes on the callback; one of the lists fills the scrolled window with items whereas the other shows only one line and doesn't scroll... ugly, ugly. Surely the basic approach should work? What am I missing? This is news. This is your | Peter Scott, NASA/JPL/Caltech brain on news. Any questions? | (pjs@aristotle.jpl.nasa.gov)
burati@APOLLO.COM (Mike Burati) (08/10/90)
>> I have an application which wishes to switch the contents of a list >> upon command. The only way I have found to do this is to call >> XmListDeleteItem() on every previous item and then XmListAddItemUnselected() >Directly set the resources which claim to be pointers to the list elements. > >Unmanage the list, do the deletions and additions, remanage it (this >will probably take the same amount of time, but it will look prettier). >I currently do this when adding a lot of text to an empty text widget. >The stupid thing adds one line at a time and the results are horrendous. >... If you're doing what I think you're trying to do, then this sounds like a lot of work. It might be needed for text widgets, but for a List, you should be able to set the XmNitems and XmNitemCount via XtSetValues (not the cleanest way, but it works). I'm currently doing this with three buffers of XmStrings that I need to switch between (the pushbutton at the top of the list toggles between the three lists). Assuming you know ahead of time what the contents of each list is, create an array of XmStrings for each list. I haven't tried the code below, but use something similar to it, which sort of works... init_lists() { ... for (i = 0; i < num_items1; i++) list1[i] = XmStringCreateLtoR(list_strings1[i], XmSTRING_DEFAULT_CHARSET); for (i = 0; i < num_items2; i++) list2[i] = XmStringCreateLtoR(list_strings2[i], XmSTRING_DEFAULT_CHARSET); } toggle_lists() { ... switch(current_list) { case LIST1 : n = 0; XtSetArg (args[n], XmNitems, list2); n++ XtSetArg (args[n], XmNitemCount, num_items2); n++; XtSetValues (mylistwidget, args, n); current_list = LIST2; break; case LIST2 : n = 0; XtSetArg (args[n], XmNitems, list1); n++ XtSetArg (args[n], XmNitemCount, num_items1); n++; XtSetValues (mylistwidget, args, n); current_list = LIST2; break; } } If the above isn't correct use of lists or causes you problems, let me know. I'm having a small problem with it when list 1 (of many) is over 400 items long, where a couple items wind up being funny looking characters or the character "/" instead of the 2-40 character strings I intended, but I'm hoping it's the way I allocated the arrays of chars that I had passed to XmStringCreate... ..Mike burati@apollo.HP.COM ps: Disclaimer? No one would claim to believe my ideas anyway, nevermind trust example code I posted without trying it :-) -------