From 6cc80926f00ce8d6533298cbb5ea061c1446287b Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 23 Oct 2013 00:18:03 +0200 Subject: [PATCH] Added gwinListGetSelectedText() --- include/gwin/list.h | 13 +++++++++++++ src/gwin/list.c | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/gwin/list.h b/include/gwin/list.h index fc189658..05433e87 100644 --- a/include/gwin/list.h +++ b/include/gwin/list.h @@ -205,6 +205,19 @@ bool_t gwinListItemIsSelected(GHandle gh, int item); */ int gwinListGetSelected(GHandle gh); +/** + * @brief Get the text of the selected item + * + * @param[in] gh The widget handle (must be a list handle) + * + * @return The test of the selected list item for a single-select list. + * + * @note It always returns NULL (nothing selected) for a multi-select list. + * + * @api + */ +const char* gwinListGetSelectedText(GHandle gh); + #if GWIN_NEED_LIST_IMAGES || defined(__DOXYGEN__) /** * @brief Set the image for a list item diff --git a/src/gwin/list.c b/src/gwin/list.c index 5407cb36..cf0bebc4 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -536,6 +536,18 @@ int gwinListItemCount(GHandle gh) { return gh2obj->cnt; } +const char* gwinListGetSelectedText(GHandle gh) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return 0; + + // return NULL if nothing is selected (or multi-select) + if (gwinListGetSelected(gh) < 0) + return 0; + + return gwinListItemGetText(gh, gwinListGetSelected(gh)); +} + #if GWIN_NEED_LIST_IMAGES void gwinListItemSetImage(GHandle gh, int item, gdispImage *pimg) { const gfxQueueASyncItem * qi;