Add gwinListItemSetText()
This commit is contained in:
parent
a3241b9f39
commit
0e00642bfc
@ -8,6 +8,7 @@ FIX: Fixed recursion bug in console history
|
|||||||
FIX: Multithreading issue with slow window redraws and large images
|
FIX: Multithreading issue with slow window redraws and large images
|
||||||
FIX: Ensure valid thread stack sizes on platforms where it matters
|
FIX: Ensure valid thread stack sizes on platforms where it matters
|
||||||
FEATURE: Add support for a GFILE user provided file system
|
FEATURE: Add support for a GFILE user provided file system
|
||||||
|
FEATURE: Add gwinListItemSetText() to replace text in a GWIN list item
|
||||||
|
|
||||||
|
|
||||||
*** Release 2.7 ***
|
*** Release 2.7 ***
|
||||||
|
@ -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;
|
ListItem *newItem;
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
@ -356,12 +356,12 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (useAlloc) {
|
if (useAlloc) {
|
||||||
size_t len = strlen(item_name)+1;
|
size_t len = strlen(text)+1;
|
||||||
if (!(newItem = gfxAlloc(sizeof(ListItem) + len)))
|
if (!(newItem = gfxAlloc(sizeof(ListItem) + len)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memcpy((char *)(newItem+1), item_name, len);
|
memcpy((char *)(newItem+1), text, len);
|
||||||
item_name = (const char *)(newItem+1);
|
text = (const char *)(newItem+1);
|
||||||
} else {
|
} else {
|
||||||
if (!(newItem = gfxAlloc(sizeof(ListItem))))
|
if (!(newItem = gfxAlloc(sizeof(ListItem))))
|
||||||
return -1;
|
return -1;
|
||||||
@ -370,7 +370,7 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
|||||||
// the item is not selected when added
|
// the item is not selected when added
|
||||||
newItem->flags = 0;
|
newItem->flags = 0;
|
||||||
newItem->param = 0;
|
newItem->param = 0;
|
||||||
newItem->text = item_name;
|
newItem->text = text;
|
||||||
#if GWIN_NEED_LIST_IMAGES
|
#if GWIN_NEED_LIST_IMAGES
|
||||||
newItem->pimg = 0;
|
newItem->pimg = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -391,6 +391,54 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
|||||||
return gh2obj->cnt-1;
|
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 char* gwinListItemGetText(GHandle gh, int item) {
|
||||||
const gfxQueueASyncItem* qi;
|
const gfxQueueASyncItem* qi;
|
||||||
int i;
|
int i;
|
||||||
|
@ -169,14 +169,26 @@ void gwinListSetScroll(GHandle gh, scroll_t flag);
|
|||||||
* reordered.
|
* reordered.
|
||||||
*
|
*
|
||||||
* @param[in] gh The widget handle (must be a list handle)
|
* @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
|
* @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
|
* @return The current ID of the item. The ID might change if you remove items from the middle of the list
|
||||||
*
|
*
|
||||||
* @api
|
* @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
|
* @brief Get the name behind an item with a given ID
|
||||||
|
Loading…
Reference in New Issue
Block a user