Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!karln!karln!karln From: karln@uunet.uu.net Newsgroups: comp.windows.open-look Subject: Re: List Selection Bug Message-ID: <1991Apr19.165038.6774@uunet.uu.net> Date: 19 Apr 91 16:50:38 GMT References: <1991Apr17.222421.19223@parc.xerox.com> Reply-To: karln@karln.UUCP () Organization: Sam76 - Pennington NJ Lines: 148 In article <1991Apr17.222421.19223@parc.xerox.com> Lovstrand@EuroPARC.Xerox.COM (Lennart Lovstrand) writes: >Argh, I've just come across Yet Another XView Bug -- this time it's >the PANEL_LIST selection mechanism that is broken. Try this: > [Deleted description] > >If anyone else out there have any other ideas, I would sure like to >know. > >Here's a sample program for curious and core-less: > >--Lennart > Greetings Lennart, I not *entirely* sure what your problem was, but I did get your code to work. A few suggestions in general about programming ... 1: I personally *NEVER* put in malloc's without the properly executed free's Certainly I never put mallocs in without frees at all. 2: I do not have a lot of experience with XV_KEY_DATA, but it *seems* illogical to start putting key data into number 12345. I changed it to start at 1. It makes more sense to start with the obvious, get it working, then try to break it, if you have nothing better to do. Here is the code as I modified it. You will find that the changes were minimal. Incedently, I was having problems this very morning with PANEL_LIST & PANEL_LIST_ONE & PANEL_LIST_NONE = TRUE, and was just about to give up when I figured I would just settle down a bit and read to news for a few minutes. Your article and program showed me that what I thought should work did in fact work, so I figured I owed it to you to take a look at your problem. Thanks, really :-). Karl Nicholas. #include #include #include #define KEY_LIST 1 char *list_strings[] = { "hej", "hopp", "alla", "feta", "nyllen", NULL }; void refill_list(button, event) Panel_item button; Event *event; { Panel_item list; int i; list = xv_get(button, XV_KEY_DATA, KEY_LIST); /* delete all existing rows */ for (i = xv_get(list, PANEL_LIST_NROWS); i > 0; i--) xv_set(list, PANEL_LIST_DELETE, i - 1, NULL); /* waste some space... */ /* what is this ? block = (int *) malloc(20 * sizeof(int)); for (i = 0; i < 20; i++) block[i] = 0x12345678; */ /* fill with new, fresh ones */ for (i = 0; list_strings[i] != NULL; i++) xv_set(list, PANEL_LIST_STRING, i, list_strings[i], NULL); } void list_notifier(list, string, data, op, event) Panel_item list; char *string; caddr_t data; Panel_list_op op; Event *event; { char *strop; int i; switch (op) { case PANEL_LIST_OP_SELECT: strop = "selected"; break; case PANEL_LIST_OP_DESELECT: strop = "deselected"; break; default: strop = ""; break; } printf("-- %#x %s\n", string, strop); printf("[%s]\n", string); } main(argc, argv) int argc; char **argv; { Frame frame; Panel panel; Panel_item button, list; char **strp; xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0); frame = xv_create(NULL, FRAME, NULL); panel = xv_create(frame, PANEL, NULL); list = xv_create(panel, PANEL_LIST, PANEL_LIST_DISPLAY_ROWS, 8, PANEL_LIST_WIDTH, 100, PANEL_NOTIFY_PROC, list_notifier, PANEL_CHOOSE_ONE, TRUE, PANEL_CHOOSE_NONE, TRUE, NULL); button = xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Refill list", PANEL_NOTIFY_PROC, refill_list, XV_KEY_DATA, KEY_LIST, list, NULL); for (strp = list_strings; *strp != NULL; strp++) printf("%#x: %s\n", *strp, *strp); xv_main_loop(frame); } -- *********************************************************************** | Karl Nicholas | A recent Gallop Poll showed that 1 in 6 | | karln!karln@uunet.uu.net | Americans have spoken to a dead person. | ***********************************************************************