Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!decwrl!ucbvax!APOLLO.COM!burati From: burati@APOLLO.COM (Mike Burati) Newsgroups: comp.windows.x.motif Subject: Re: Re: Deleting a whole list? Message-ID: <9008092148.AA19026@BU.EDU> Date: 9 Aug 90 21:48:37 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 68 >> 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 :-) -------