summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2014-04-10 20:11:41 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2014-04-10 20:11:41 +0300
commit9525c77f553c2e188f6f99d3b6c01d5ec671a76e (patch)
tree8f5854db16645badd425b250f801da7e082055ee /lib
parent702d808b285931850e66900bd6c7c7319ae6d73c (diff)
downloadbemenu-9525c77f553c2e188f6f99d3b6c01d5ec671a76e.tar.gz
bemenu-9525c77f553c2e188f6f99d3b6c01d5ec671a76e.tar.bz2
bemenu-9525c77f553c2e188f6f99d3b6c01d5ec671a76e.zip
Setter first, then getter.
Diffstat (limited to 'lib')
-rw-r--r--lib/bemenu.h55
-rw-r--r--lib/menu.c98
2 files changed, 76 insertions, 77 deletions
diff --git a/lib/bemenu.h b/lib/bemenu.h
index 65625b3..7d96d2c 100644
--- a/lib/bemenu.h
+++ b/lib/bemenu.h
@@ -218,15 +218,6 @@ int bmMenuRemoveItemAt(bmMenu *menu, unsigned int index);
*/
int bmMenuRemoveItem(bmMenu *menu, bmItem *item);
-
-/**
- * Get highlighted item from bmMenu instance.
- *
- * @param menu bmMenu instance from where to get highlighted item.
- * @return Selected bmItem instance, **NULL** if none highlighted.
- */
-bmItem* bmMenuGetHighlightedItem(const bmMenu *menu);
-
/**
* Highlight item in menu by index.
*
@@ -245,13 +236,12 @@ int bmMenuSetHighlightedIndex(bmMenu *menu, unsigned int index);
int bmMenuSetHighlighted(bmMenu *menu, bmItem *item);
/**
- * Get selected items from bmMenu instance.
+ * Get highlighted item from bmMenu instance.
*
- * @param menu bmMenu instance from where to get selected items.
- * @param outNmemb Reference to unsigned int where total count of returned items will be stored.
- * @return Pointer to array of bmItem pointers.
+ * @param menu bmMenu instance from where to get highlighted item.
+ * @return Selected bmItem instance, **NULL** if none highlighted.
*/
-bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
+bmItem* bmMenuGetHighlightedItem(const bmMenu *menu);
/**
* Set selected items to bmMenu instance.
@@ -266,16 +256,26 @@ bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
int bmMenuSetSelectedItems(bmMenu *menu, bmItem **items, unsigned int nmemb);
/**
- * Get filtered (displayed) items from bmMenu instance.
- *
- * @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
- * Do not store this pointer.
+ * Get selected items from bmMenu instance.
*
- * @param menu bmMenu instance from where to get filtered items.
+ * @param menu bmMenu instance from where to get selected items.
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
* @return Pointer to array of bmItem pointers.
*/
-bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb);
+bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb);
+
+/**
+ * Set items to bmMenu instance.
+ * Will replace all the old items on bmMenu instance.
+ *
+ * If items is **NULL**, or nmemb is zero, all items will be freed from the menu.
+ *
+ * @param menu bmMenu instance where items will be set.
+ * @param items Array of bmItem pointers to set.
+ * @param nmemb Total count of items in array.
+ * @return 1 on successful set, 0 on failure.
+ */
+int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb);
/**
* Get items from bmMenu instance.
@@ -289,17 +289,16 @@ bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb);
bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb);
/**
- * Set items to bmMenu instance.
- * Will replace all the old items on bmMenu instance.
+ * Get filtered (displayed) items from bmMenu instance.
*
- * If items is **NULL**, or nmemb is zero, all items will be freed from the menu.
+ * @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
+ * Do not store this pointer.
*
- * @param menu bmMenu instance where items will be set.
- * @param items Array of bmItem pointers to set.
- * @param nmemb Total count of items in array.
- * @return 1 on successful set, 0 on failure.
+ * @param menu bmMenu instance from where to get filtered items.
+ * @param outNmemb Reference to unsigned int where total count of returned items will be stored.
+ * @return Pointer to array of bmItem pointers.
*/
-int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb);
+bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb);
/** @} Menu Items */
diff --git a/lib/menu.c b/lib/menu.c
index a011194..f0a8149 100644
--- a/lib/menu.c
+++ b/lib/menu.c
@@ -266,25 +266,6 @@ int bmMenuRemoveItem(bmMenu *menu, bmItem *item)
}
/**
- * Get highlighted item from bmMenu instance.
- *
- * @param menu bmMenu instance from where to get highlighted item.
- * @return Selected bmItem instance, **NULL** if none highlighted.
- */
-bmItem* bmMenuGetHighlightedItem(const bmMenu *menu)
-{
- assert(menu);
-
- unsigned int count;
- bmItem **items = bmMenuGetFilteredItems(menu, &count);
-
- if (!items || count <= menu->index)
- return NULL;
-
- return items[menu->index];
-}
-
-/**
* Highlight item in menu by index.
*
* @param menu bmMenu instance from where to highlight item.
@@ -323,16 +304,22 @@ int bmMenuSetHighlighted(bmMenu *menu, bmItem *item)
}
/**
- * Get selected items from bmMenu instance.
+ * Get highlighted item from bmMenu instance.
*
- * @param menu bmMenu instance from where to get selected items.
- * @param outNmemb Reference to unsigned int where total count of returned items will be stored.
- * @return Pointer to array of bmItem pointers.
+ * @param menu bmMenu instance from where to get highlighted item.
+ * @return Selected bmItem instance, **NULL** if none highlighted.
*/
-bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb)
+bmItem* bmMenuGetHighlightedItem(const bmMenu *menu)
{
assert(menu);
- return _bmItemListGetItems(&menu->selection, outNmemb);
+
+ unsigned int count;
+ bmItem **items = bmMenuGetFilteredItems(menu, &count);
+
+ if (!items || count <= menu->index)
+ return NULL;
+
+ return items[menu->index];
}
/**
@@ -352,23 +339,41 @@ int bmMenuSetSelectedItems(bmMenu *menu, bmItem **items, unsigned int nmemb)
}
/**
- * Get filtered (displayed) items from bmMenu instance.
- *
- * @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
- * Do not store this pointer.
+ * Get selected items from bmMenu instance.
*
- * @param menu bmMenu instance from where to get filtered items.
+ * @param menu bmMenu instance from where to get selected items.
* @param outNmemb Reference to unsigned int where total count of returned items will be stored.
* @return Pointer to array of bmItem pointers.
*/
-bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb)
+bmItem** bmMenuGetSelectedItems(const bmMenu *menu, unsigned int *outNmemb)
{
assert(menu);
+ return _bmItemListGetItems(&menu->selection, outNmemb);
+}
- if (menu->filtered.list)
- return _bmItemListGetItems(&menu->filtered, outNmemb);
+/**
+ * Set items to bmMenu instance.
+ * Will replace all the old items on bmMenu instance.
+ *
+ * If items is **NULL**, or nmemb is zero, all items will be freed from the menu.
+ *
+ * @param menu bmMenu instance where items will be set.
+ * @param items Array of bmItem pointers to set.
+ * @param nmemb Total count of items in array.
+ * @return 1 on successful set, 0 on failure.
+ */
+int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb)
+{
+ assert(menu);
- return _bmItemListGetItems(&menu->items, outNmemb);
+ int ret = _bmItemListSetItems(&menu->items, items, nmemb);
+
+ if (ret) {
+ _bmItemListFreeList(&menu->selection);
+ _bmItemListFreeList(&menu->filtered);
+ }
+
+ return ret;
}
/**
@@ -387,28 +392,23 @@ bmItem** bmMenuGetItems(const bmMenu *menu, unsigned int *outNmemb)
}
/**
- * Set items to bmMenu instance.
- * Will replace all the old items on bmMenu instance.
+ * Get filtered (displayed) items from bmMenu instance.
*
- * If items is **NULL**, or nmemb is zero, all items will be freed from the menu.
+ * @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
+ * Do not store this pointer.
*
- * @param menu bmMenu instance where items will be set.
- * @param items Array of bmItem pointers to set.
- * @param nmemb Total count of items in array.
- * @return 1 on successful set, 0 on failure.
+ * @param menu bmMenu instance from where to get filtered items.
+ * @param outNmemb Reference to unsigned int where total count of returned items will be stored.
+ * @return Pointer to array of bmItem pointers.
*/
-int bmMenuSetItems(bmMenu *menu, const bmItem **items, unsigned int nmemb)
+bmItem** bmMenuGetFilteredItems(const bmMenu *menu, unsigned int *outNmemb)
{
assert(menu);
- int ret = _bmItemListSetItems(&menu->items, items, nmemb);
-
- if (ret) {
- _bmItemListFreeList(&menu->selection);
- _bmItemListFreeList(&menu->filtered);
- }
+ if (menu->filtered.list)
+ return _bmItemListGetItems(&menu->filtered, outNmemb);
- return ret;
+ return _bmItemListGetItems(&menu->items, outNmemb);
}
/**