diff options
Diffstat (limited to 'src/gwin')
-rw-r--r-- | src/gwin/gwin_list.c | 58 | ||||
-rw-r--r-- | src/gwin/gwin_list.h | 16 |
2 files changed, 67 insertions, 7 deletions
diff --git a/src/gwin/gwin_list.c b/src/gwin/gwin_list.c index e73faf15..754e062b 100644 --- a/src/gwin/gwin_list.c +++ b/src/gwin/gwin_list.c @@ -348,7 +348,7 @@ void gwinListSetScroll(GHandle gh, scroll_t flag) { } } -int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { +int gwinListAddItem(GHandle gh, const char* text, bool_t useAlloc) { ListItem *newItem; // is it a valid handle? @@ -356,12 +356,12 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { return -1; if (useAlloc) { - size_t len = strlen(item_name)+1; + size_t len = strlen(text)+1; if (!(newItem = gfxAlloc(sizeof(ListItem) + len))) return -1; - memcpy((char *)(newItem+1), item_name, len); - item_name = (const char *)(newItem+1); + memcpy((char *)(newItem+1), text, len); + text = (const char *)(newItem+1); } else { if (!(newItem = gfxAlloc(sizeof(ListItem)))) return -1; @@ -370,7 +370,7 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { // the item is not selected when added newItem->flags = 0; newItem->param = 0; - newItem->text = item_name; + newItem->text = text; #if GWIN_NEED_LIST_IMAGES newItem->pimg = 0; #endif @@ -391,6 +391,54 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { return gh2obj->cnt-1; } +void gwinListItemSetText(GHandle gh, int item, const char* text, bool_t useAlloc) { + const gfxQueueASyncItem *qi; + int i; + ListItem *newItem; + + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return; + + // watch out for an invalid item + if (item < 0 || item > (gh2obj->cnt) - 1) + return; + + for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { + if (i == item) { + + // create the new object + if (useAlloc) { + size_t len = strlen(text)+1; + if (!(newItem = gfxAlloc(sizeof(ListItem) + len))) + return; + + memcpy((char *)(newItem+1), text, len); + text = (const char *)(newItem+1); + } else { + if (!(newItem = gfxAlloc(sizeof(ListItem)))) + return; + } + + // copy the info from the existing object + newItem->flags = qi2li->flags; + newItem->param = qi2li->param; + newItem->text = text; + #if GWIN_NEED_LIST_IMAGES + newItem->pimg = qi2li->pimg; + #endif + + // add the new item to the list and remove the old item + gfxQueueASyncInsert(&gh2obj->list_head, &newItem->q_item, &qi2li->q_item); + gfxQueueASyncRemove(&gh2obj->list_head, &qi2li->q_item); + gfxFree(qi2li); + + _gwinUpdate(gh); + break; + } + } +} + const char* gwinListItemGetText(GHandle gh, int item) { const gfxQueueASyncItem* qi; int i; diff --git a/src/gwin/gwin_list.h b/src/gwin/gwin_list.h index a4d8aca7..81db7c34 100644 --- a/src/gwin/gwin_list.h +++ b/src/gwin/gwin_list.h @@ -169,14 +169,26 @@ void gwinListSetScroll(GHandle gh, scroll_t flag); * reordered. * * @param[in] gh The widget handle (must be a list handle) - * @param[in] item The string which shall be displayed in the list afterwards + * @param[in] text The string which shall be displayed in the list afterwards * @param[in] useAlloc If set to TRUE, the string will be dynamically allocated. A static buffer must be passed otherwise * * @return The current ID of the item. The ID might change if you remove items from the middle of the list * * @api */ -int gwinListAddItem(GHandle gh, const char* item, bool_t useAlloc); +int gwinListAddItem(GHandle gh, const char* text, bool_t useAlloc); + +/** + * @brief Set the custom parameter of an item with a given ID + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * @param[in] text The text to replace the existing text + * @param[in] useAlloc If set to TRUE, the string will be dynamically allocated. A static buffer must be passed otherwise + * + * @api + */ +void gwinListItemSetText(GHandle gh, int item, const char* text, bool_t useAlloc); /** * @brief Get the name behind an item with a given ID |