From 702d808b285931850e66900bd6c7c7319ae6d73c Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Thu, 10 Apr 2014 20:09:34 +0300 Subject: Make it possible to set and get userdata pointers. --- lib/bemenu.h | 34 ++++++++++++++++++++++++++++++++++ lib/internal.h | 12 ++++++++++++ lib/item.c | 25 +++++++++++++++++++++++++ lib/menu.c | 25 +++++++++++++++++++++++++ 4 files changed, 96 insertions(+) (limited to 'lib') diff --git a/lib/bemenu.h b/lib/bemenu.h index 250ad53..65625b3 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -122,6 +122,23 @@ void bmMenuFreeItems(bmMenu *menu); * @name Menu Properties * @{ */ +/** + * Set userdata pointer to bmMenu instance. + * Userdata will be carried unmodified by the instance. + * + * @param menu bmMenu instance where to set userdata pointer. + * @param userdata Pointer to userdata. + */ +void bmMenuSetUserdata(bmMenu *menu, void *userdata); + +/** + * Get userdata pointer from bmMenu instance. + * + * @param menu bmMenu instance which userdata pointer to get. + * @return Pointer for unmodified userdata. + */ +void* bmMenuGetUserdata(bmMenu *menu); + /** * Set active filter mode to bmMenu instance. * @@ -351,6 +368,23 @@ void bmItemFree(bmItem *item); * @name Item Properties * @{ */ +/** + * Set userdata pointer to bmItem instance. + * Userdata will be carried unmodified by the instance. + * + * @param item bmItem instance where to set userdata pointer. + * @param userdata Pointer to userdata. + */ +void bmItemSetUserdata(bmItem *item, void *userdata); + +/** + * Get userdata pointer from bmItem instance. + * + * @param item bmItem instance which userdata pointer to get. + * @return Pointer for unmodified userdata. + */ +void* bmItemGetUserdata(bmItem *item); + /** * Set text to bmItem instance. * diff --git a/lib/internal.h b/lib/internal.h index d0a9848..790b4ed 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -9,6 +9,12 @@ * Represents a single item in menu. */ struct _bmItem { + /** + * Userdata pointer. + * This pointer will be passed around with the item untouched. + */ + void *userdata; + /** * Primary text shown on item as null terminated C "string". * Matching will be done against this text as well. @@ -59,6 +65,12 @@ struct _bmItemList { * Internal bmMenu struct that is not exposed to public. */ struct _bmMenu { + /** + * Userdata pointer. + * This pointer will be passed around with the menu untouched. + */ + void *userdata; + /** * Underlying renderer access. */ diff --git a/lib/item.c b/lib/item.c index e6ccc7a..f2a879a 100644 --- a/lib/item.c +++ b/lib/item.c @@ -35,6 +35,31 @@ void bmItemFree(bmItem *item) free(item); } +/** + * Set userdata pointer to bmItem instance. + * Userdata will be carried unmodified by the instance. + * + * @param item bmItem instance where to set userdata pointer. + * @param userdata Pointer to userdata. + */ +void bmItemSetUserdata(bmItem *item, void *userdata) +{ + assert(item); + item->userdata = userdata; +} + +/** + * Get userdata pointer from bmItem instance. + * + * @param item bmItem instance which userdata pointer to get. + * @return Pointer for unmodified userdata. + */ +void* bmItemGetUserdata(bmItem *item) +{ + assert(item); + return item->userdata; +} + /** * Set text to bmItem instance. * diff --git a/lib/menu.c b/lib/menu.c index 6274fe3..a011194 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -102,6 +102,31 @@ void bmMenuFreeItems(bmMenu *menu) _bmItemListFreeItems(&menu->items); } +/** + * Set userdata pointer to bmMenu instance. + * Userdata will be carried unmodified by the instance. + * + * @param menu bmMenu instance where to set userdata pointer. + * @param userdata Pointer to userdata. + */ +void bmMenuSetUserdata(bmMenu *menu, void *userdata) +{ + assert(menu); + menu->userdata = userdata; +} + +/** + * Get userdata pointer from bmMenu instance. + * + * @param menu bmMenu instance which userdata pointer to get. + * @return Pointer for unmodified userdata. + */ +void* bmMenuGetUserdata(bmMenu *menu) +{ + assert(menu); + return menu->userdata; +} + /** * Set active filter mode to bmMenu instance. * -- cgit v1.2.3-70-g09d2