Path: utzoo!attcan!uunet!cme!durer!warsaw From: warsaw@cme.nist.gov (Barry A. Warsaw) Newsgroups: comp.windows.x Subject: Re: XView: Help w/ attaching client data Message-ID: Date: 15 Mar 90 15:50:24 GMT References: Sender: news@cme.nist.gov Organization: National Institute of Standards and Technology Lines: 134 In-reply-to: warsaw@cme.nist.gov's message of 14 Mar 90 17:18:13 GMT >>>>> "Barry" == Barry A. Warsaw writes: Barry> I'm trying to attach client data to PANEL_LIST type panel items Barry> in XView, but I can't quite figure out how to set and later Barry> retrieve the data in the notify procedure. I spent some time scanning through the source (after all those years of sunview hacking with no source, its a real treat to have the xview source! Thanks, Sun) and came up with a few routines that help with attaching and retrieving data on PANEL_LIST items. These aren't the best solutions (I still think the data should hang off of some attribute, or the list item should be passed to the notify proc), but they do the job... Say you have a PANEL_LIST item created as such: list = xv_create(panel, PANEL_LIST, PANEL_NOTIFY_PROC, my_list_notify_proc, ... NULL); And later you add items to the list: xv_set(list, PANEL_LIST_INSERT, insert_index, PANEL_LIST_STRING, insert_index, string_name, PANEL_LIST_CLIENT_DATA, insert_index, client_data, NULL); When an item is selected, this function is called: void my_list_notify_proc(item, op, event) Panel_item item; Panel_list_op op; Event *event; { int row = get_pli_row(item); Xv_opaque client_data = get_pli_client_data(item); Panel_item list = get_pli_parent_list(item); } Here are the three useful routines: #include /* very important */ int get_pli_row(item) Panel_item item; { Panel_list_info *pli; Row_info *row; pli = (Panel_list_info *) xv_get(item, PANEL_CLIENT_DATA); for (row = pli->rows; row; row = row->next) if (row->string_item == item) break; if (!row) return -1; return row->row; } Xv_opaque get_pli_client_data(item) Panel_item item; { Panel_list_info *pli; pli = (Panel_list_info *) xv_get(item, PANEL_CLIENT_DATA); return xv_get(pli->public_self, PANEL_LIST_CLIENT_DATA, get_pli_row(item)); } Panel_item get_pli_parent_list(item) Panel_item item; { Panel_list_info *pli; pli = (Panel_list_info *) xv_get(item, PANEL_CLIENT_DATA); return pli->public_self; } Barry> 1) In the notify proc we can't find the row number Barry> corresponding to the PANEL_MESSAGE item selected so that we Barry> could do an xv_get(list, PANEL_LIST_CLIENT_DATA, row). We have Barry> to brute-force to find the row number of the selected item. Barry> Something like PANEL_LIST_ROW_SELECTED on the PANEL_LIST would Barry> do the trick. Still need to brute force it (see get_pli_row above), but you can cut down on the number of globals needed by using some xview "secrets". Barry> 2) Can't find the total number of rows in the PANEL_LIST item, Barry> so we don't bomb out "for" loops when brute-force searching for Barry> the message item. We'd have to keep a global variable for Barry> this. Something like PANEL_LIST_ROWS_N would be needed. Sorry, should have read TFM a little more closely, try attribute PANEL_LIST_NROWS. Barry> 3) Also in the notify proc, we can't find the PANEL_LIST item Barry> which contains the PANEL_MESSAGE item selected, forcing me to Barry> keep "list" around as a global variable. Something like Barry> PANEL_LIST_PARENT_LIST would be appropriate here. See get_pli_parent_list above. Barry> 4) The client data set on the list via PANEL_LIST_CLIENT_DATA Barry> could be placed on the item's PANEL_CLIENT_DATA attribute so Barry> that it can be retrieved in the notify proc. I see why this can't be done, since xview uses the item's PANEL_CLIENT_DATA attribute to store a structure of data pertaining to the parent PANEL_LIST item. Barry> 5) Really, the parameters passed to the notify procedure are Barry> not the right ones. Ideally it should be passed the PANEL_LIST Barry> item containing the selection, the row number of the selected Barry> item and a pointer to the event, much like PANEL_CHOICE Barry> notification. I still think this is the preferred way of notification since its highly likely that the notification proc will need info about the parent list. Hope this helps... -Barry NAME: Barry A. Warsaw USMAIL: National Institute of Standards TELE: (301) 975-3460 and Technology (formerly NBS) UUCP: {...}!uunet!cme-durer!warsaw Rm. B-124, Bldg. 220 ARPA: warsaw@cme.nist.gov Gaithersburg, MD 20899