2014-10-24 22:38:30 +00:00
|
|
|
#ifndef _BEMENU_H_
|
|
|
|
#define _BEMENU_H_
|
|
|
|
|
2014-03-28 19:33:20 +00:00
|
|
|
/**
|
|
|
|
* @file bemenu.h
|
|
|
|
*
|
2014-04-10 14:26:42 +00:00
|
|
|
* Public API header.
|
2014-03-28 19:33:20 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_renderer;
|
|
|
|
struct bm_menu;
|
|
|
|
struct bm_item;
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2014-04-10 14:26:42 +00:00
|
|
|
|
2014-04-12 21:12:31 +00:00
|
|
|
/**
|
|
|
|
* @defgroup Library
|
|
|
|
* @brief Library functions.
|
|
|
|
*
|
|
|
|
* Query library version, etc...
|
|
|
|
*/
|
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/**
|
|
|
|
* @defgroup Menu
|
|
|
|
* @brief Menu container.
|
|
|
|
*
|
|
|
|
* Holds all the items, runs logic and gets rendered.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup Item
|
|
|
|
* @brief Item container.
|
|
|
|
*
|
|
|
|
* Contains properties for visual representation of item.
|
|
|
|
*/
|
|
|
|
|
2014-04-12 19:12:44 +00:00
|
|
|
/**
|
2014-04-12 21:12:31 +00:00
|
|
|
* @addtogroup Library
|
2014-04-12 19:12:44 +00:00
|
|
|
* @{ */
|
|
|
|
|
2014-10-22 19:46:51 +00:00
|
|
|
/**
|
|
|
|
* @name Library Initialization
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init bemenu.
|
|
|
|
* Loads up the renderers.
|
|
|
|
*
|
|
|
|
* @return true on success, false on failure.
|
|
|
|
*/
|
|
|
|
bool bm_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of available renderers.
|
|
|
|
*
|
|
|
|
* @param out_nmemb Reference to uint32_t where total count of returned renderers will be stored.
|
|
|
|
* @return Pointer to array of bm_renderer instances.
|
|
|
|
*/
|
|
|
|
const struct bm_renderer** bm_get_renderers(uint32_t *out_nmemb);
|
|
|
|
|
|
|
|
/** @} Library Initialization */
|
|
|
|
|
2014-04-12 19:12:44 +00:00
|
|
|
/**
|
|
|
|
* @name Library Version
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get version of the library in 'major.minor.patch' format.
|
|
|
|
*
|
|
|
|
* @see @link http://semver.org/ Semantic Versioning @endlink
|
|
|
|
*
|
|
|
|
* @return Null terminated C "string" to version string.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
const char* bm_version(void);
|
2014-04-12 19:12:44 +00:00
|
|
|
|
|
|
|
/** @} Library Version */
|
|
|
|
|
|
|
|
/** @} Library */
|
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* @addtogroup Renderer
|
2014-04-10 14:26:42 +00:00
|
|
|
* @{ */
|
|
|
|
|
2014-10-24 22:38:30 +00:00
|
|
|
/**
|
|
|
|
* Prioritories for renderer plugins.
|
|
|
|
*/
|
|
|
|
enum bm_prioritory {
|
|
|
|
/**
|
|
|
|
* Do not use this in renderers.
|
|
|
|
* This flag is for bm_menu_new, if any renderer is fine.
|
|
|
|
*/
|
|
|
|
BM_PRIO_ANY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renderer runs in terminal.
|
|
|
|
*/
|
|
|
|
BM_PRIO_TERMINAL,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renderer runs in GUI.
|
|
|
|
*/
|
|
|
|
BM_PRIO_GUI,
|
|
|
|
};
|
|
|
|
|
2014-03-28 19:33:20 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get name of the renderer.
|
2014-03-28 19:59:34 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param renderer bm_renderer instance.
|
|
|
|
* @return Null terminated C "string" to renderer's name.
|
2014-03-28 19:33:20 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
const char* bm_renderer_get_name(const struct bm_renderer *renderer);
|
|
|
|
|
2014-10-24 22:38:30 +00:00
|
|
|
/**
|
|
|
|
* Get prioritory of the renderer.
|
|
|
|
*
|
|
|
|
* @param renderer bm_renderer instance.
|
|
|
|
* @return bm_prioritory enum value.
|
|
|
|
*/
|
|
|
|
enum bm_prioritory bm_renderer_get_prioritory(const struct bm_renderer *renderer);
|
|
|
|
|
2014-10-22 19:46:51 +00:00
|
|
|
/**
|
|
|
|
* @} Renderer */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Menu
|
|
|
|
* @{ */
|
2014-03-28 19:33:20 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Filter mode constants for bm_menu instance filter mode.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @link ::bm_filter_mode BM_FILTER_MODE_LAST @endlink is provided for enumerating filter modes.
|
2014-04-09 22:09:35 +00:00
|
|
|
* Using it as filter mode however provides exactly same functionality as BM_FILTER_MODE_DMENU.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_filter_mode {
|
2014-04-09 22:09:35 +00:00
|
|
|
BM_FILTER_MODE_DMENU,
|
|
|
|
BM_FILTER_MODE_DMENU_CASE_INSENSITIVE,
|
|
|
|
BM_FILTER_MODE_LAST
|
2014-10-22 19:46:51 +00:00
|
|
|
};
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Result constants from bm_menu_run_with_key function.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* - @link ::bm_run_result BM_RUN_RESULT_RUNNING @endlink means that menu is running and thus should be still renderer && ran.
|
|
|
|
* - @link ::bm_run_result BM_RUN_RESULT_SELECTED @endlink means that menu was closed and items were selected.
|
|
|
|
* - @link ::bm_run_result BM_RUN_RESULT_CANCEL @endlink means that menu was closed and selection was canceled.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_run_result {
|
2014-04-09 22:09:35 +00:00
|
|
|
BM_RUN_RESULT_RUNNING,
|
|
|
|
BM_RUN_RESULT_SELECTED,
|
|
|
|
BM_RUN_RESULT_CANCEL,
|
2014-10-22 19:46:51 +00:00
|
|
|
};
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Key constants.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @link ::bm_key BM_KEY_LAST @endlink is provided for enumerating keys.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_key {
|
2014-04-09 22:09:35 +00:00
|
|
|
BM_KEY_NONE,
|
|
|
|
BM_KEY_UP,
|
|
|
|
BM_KEY_DOWN,
|
|
|
|
BM_KEY_LEFT,
|
|
|
|
BM_KEY_RIGHT,
|
|
|
|
BM_KEY_HOME,
|
|
|
|
BM_KEY_END,
|
|
|
|
BM_KEY_PAGE_UP,
|
|
|
|
BM_KEY_PAGE_DOWN,
|
2014-04-12 15:42:30 +00:00
|
|
|
BM_KEY_SHIFT_PAGE_UP,
|
|
|
|
BM_KEY_SHIFT_PAGE_DOWN,
|
2014-04-09 22:09:35 +00:00
|
|
|
BM_KEY_BACKSPACE,
|
|
|
|
BM_KEY_DELETE,
|
|
|
|
BM_KEY_LINE_DELETE_LEFT,
|
|
|
|
BM_KEY_LINE_DELETE_RIGHT,
|
|
|
|
BM_KEY_WORD_DELETE,
|
|
|
|
BM_KEY_TAB,
|
|
|
|
BM_KEY_ESCAPE,
|
|
|
|
BM_KEY_RETURN,
|
2014-04-10 17:04:06 +00:00
|
|
|
BM_KEY_SHIFT_RETURN,
|
2014-04-12 15:44:03 +00:00
|
|
|
BM_KEY_CONTROL_RETURN,
|
2014-04-09 22:09:35 +00:00
|
|
|
BM_KEY_UNICODE,
|
|
|
|
BM_KEY_LAST
|
2014-10-22 19:46:51 +00:00
|
|
|
};
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/**
|
|
|
|
* @name Menu Memory
|
|
|
|
* @{ */
|
2014-03-28 19:33:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Create new bm_menu instance.
|
2014-03-28 19:33:20 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param renderer Name of renderer to be used for this instance, pass **NULL** for auto-detection.
|
2014-10-24 22:38:30 +00:00
|
|
|
* @param prioritory @link ::bm_prioritory @endlink enum for which kind of renderer is wanted. Pass BM_PRIO_ANY, for anything.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return bm_menu for new menu instance, **NULL** if creation failed.
|
2014-03-28 19:33:20 +00:00
|
|
|
*/
|
2014-10-24 22:38:30 +00:00
|
|
|
struct bm_menu* bm_menu_new(const char *renderer, enum bm_prioritory prioritory);
|
2014-03-28 19:33:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Release bm_menu instance.
|
2014-03-28 19:33:20 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance to be freed from memory.
|
2014-03-28 19:33:20 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_free(struct bm_menu *menu);
|
2014-03-28 19:33:20 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Release items inside bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance which items will be freed from memory.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_free_items(struct bm_menu *menu);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Menu Memory */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Menu Properties
|
|
|
|
* @{ */
|
|
|
|
|
2014-04-10 17:09:34 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set userdata pointer to bm_menu instance.
|
2014-04-10 17:09:34 +00:00
|
|
|
* Userdata will be carried unmodified by the instance.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to set userdata pointer.
|
2014-04-10 17:09:34 +00:00
|
|
|
* @param userdata Pointer to userdata.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_set_userdata(struct bm_menu *menu, void *userdata);
|
2014-04-10 17:09:34 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get userdata pointer from bm_menu instance.
|
2014-04-10 17:09:34 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance which userdata pointer to get.
|
2014-04-10 17:09:34 +00:00
|
|
|
* @return Pointer for unmodified userdata.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void* bm_menu_get_userdata(struct bm_menu *menu);
|
2014-04-10 17:09:34 +00:00
|
|
|
|
2014-04-14 16:25:04 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set filter text to bm_menu instance.
|
2014-04-14 16:25:04 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to set filter.
|
2014-04-14 16:25:04 +00:00
|
|
|
* @param filter Null terminated C "string" to act as filter.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_set_filter(struct bm_menu *menu, const char *filter);
|
2014-04-14 16:25:04 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get filter text from bm_menu instance.
|
2014-04-14 16:25:04 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to get filter.
|
2014-04-14 16:25:04 +00:00
|
|
|
* @return Const pointer to current filter text, may be **NULL** if empty.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
const char* bm_menu_get_filter(struct bm_menu *menu);
|
2014-04-14 16:25:04 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set active filter mode to bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to set filter mode.
|
|
|
|
* @param mode bm_filter_mode constant.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_set_filter_mode(struct bm_menu *menu, enum bm_filter_mode mode);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get active filter mode from bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to get filter mode.
|
|
|
|
* @return bm_filter_mode constant.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_filter_mode bm_menu_get_filter_mode(const struct bm_menu *menu);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-14 16:25:16 +00:00
|
|
|
/**
|
|
|
|
* Set selection wrapping on/off.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to toggle selection wrapping.
|
|
|
|
* @param bool true/false.
|
2014-04-14 16:25:16 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_set_wrap(struct bm_menu *menu, bool wrap);
|
2014-04-14 16:25:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get selection wrapping state.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to get selection wrapping state.
|
2014-04-14 16:25:16 +00:00
|
|
|
* @return int for wrap state.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_get_wrap(const struct bm_menu *menu);
|
2014-04-14 16:25:16 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set title to bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to set title.
|
2014-04-10 14:26:42 +00:00
|
|
|
* @param title C "string" to set as title, can be **NULL** for empty title.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true if set was succesful, false if out of memory.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_set_title(struct bm_menu *menu, const char *title);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get title from bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where to get title from.
|
2014-04-10 14:26:42 +00:00
|
|
|
* @return Pointer to null terminated C "string", can be **NULL** for empty title.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
const char* bm_menu_get_title(const struct bm_menu *menu);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Properties */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Menu Items
|
|
|
|
* @{ */
|
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Add item to bm_menu instance at specific index.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where item will be added.
|
|
|
|
* @param item bm_item instance to add.
|
2014-04-09 22:09:35 +00:00
|
|
|
* @param index Index where item will be added.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true on successful add, false on failure.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_add_item_at(struct bm_menu *menu, struct bm_item *item, uint32_t index);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Add item to bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where item will be added.
|
|
|
|
* @param item bm_item instance to add.
|
|
|
|
* @return true on successful add, false on failure.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_add_item(struct bm_menu *menu, struct bm_item *item);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Remove item from bm_menu instance at specific index.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @warning The item won't be freed, use bm_item_free to do that.
|
2014-04-10 14:26:42 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where item will be removed.
|
2014-04-09 22:09:35 +00:00
|
|
|
* @param index Index of item to remove.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true on successful add, false on failure.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_remove_item_at(struct bm_menu *menu, uint32_t index);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Remove item from bm_menu instance.
|
2014-04-10 14:26:42 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @warning The item won't be freed, use bm_item_free to do that.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where item will be removed.
|
|
|
|
* @param item bm_item instance to remove.
|
|
|
|
* @return true on successful add, false on failure.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_remove_item(struct bm_menu *menu, struct bm_item *item);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-10 17:04:06 +00:00
|
|
|
* Highlight item in menu by index.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to highlight item.
|
2014-04-10 17:12:42 +00:00
|
|
|
* @param index Index of item to highlight.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true on successful highlight, false on failure.
|
2014-04-10 17:04:06 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_set_highlighted_index(struct bm_menu *menu, uint32_t index);
|
2014-04-10 17:04:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlight item in menu.
|
2014-04-10 14:26:42 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to highlight item.
|
|
|
|
* @param item bm_item instance to highlight.
|
|
|
|
* @return true on successful highlight, false on failure.
|
2014-04-10 17:04:06 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_set_highlighted_item(struct bm_menu *menu, struct bm_item *item);
|
2014-04-10 17:04:06 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get highlighted item from bm_menu instance.
|
2014-04-10 17:04:06 +00:00
|
|
|
*
|
2014-04-10 17:19:15 +00:00
|
|
|
* @warning The pointer returned by this function may be invalid after items change.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to get highlighted item.
|
|
|
|
* @return Selected bm_item instance, **NULL** if none highlighted.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_item* bm_menu_get_highlighted_item(const struct bm_menu *menu);
|
2014-04-10 17:04:06 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set selected items to bm_menu instance.
|
2014-04-10 17:04:06 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where items will be set.
|
|
|
|
* @param items Array of bm_item pointers to set.
|
2014-04-10 17:04:06 +00:00
|
|
|
* @param nmemb Total count of items in array.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true on successful set, false on failure.
|
2014-04-10 17:04:06 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_set_selected_items(struct bm_menu *menu, struct bm_item **items, uint32_t nmemb);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get selected items from bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-04-10 17:19:15 +00:00
|
|
|
* @warning The pointer returned by this function may be invalid after selection or items change.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to get selected items.
|
|
|
|
* @param out_nmemb Reference to uint32_t where total count of returned items will be stored.
|
|
|
|
* @return Pointer to array of bm_item pointers.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_item** bm_menu_get_selected_items(const struct bm_menu *menu, uint32_t *out_nmemb);
|
2014-04-10 17:11:41 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set items to bm_menu instance.
|
|
|
|
* Will replace all the old items on bm_menu instance.
|
2014-04-10 17:11:41 +00:00
|
|
|
*
|
|
|
|
* If items is **NULL**, or nmemb is zero, all items will be freed from the menu.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance where items will be set.
|
|
|
|
* @param items Array of bm_item pointers to set.
|
2014-04-10 17:11:41 +00:00
|
|
|
* @param nmemb Total count of items in array.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true on successful set, false on failure.
|
2014-04-10 17:11:41 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_menu_set_items(struct bm_menu *menu, const struct bm_item **items, uint32_t nmemb);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 17:04:06 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get items from bm_menu instance.
|
2014-04-10 17:04:06 +00:00
|
|
|
*
|
|
|
|
* @warning The pointer returned by this function may be invalid after removing or adding new items.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to get items.
|
|
|
|
* @param out_nmemb Reference to uint32_t where total count of returned items will be stored.
|
|
|
|
* @return Pointer to array of bm_item pointers.
|
2014-04-10 17:04:06 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_item** bm_menu_get_items(const struct bm_menu *menu, uint32_t *out_nmemb);
|
2014-04-10 17:04:06 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get filtered (displayed) items from bm_menu instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-04-10 17:11:41 +00:00
|
|
|
* @warning The pointer returned by this function _will_ be invalid when menu internally filters its list again.
|
|
|
|
* Do not store this pointer.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from where to get filtered items.
|
|
|
|
* @param out_nmemb Reference to uint32_t where total count of returned items will be stored.
|
|
|
|
* @return Pointer to array of bm_item pointers.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_item** bm_menu_get_filtered_items(const struct bm_menu *menu, uint32_t *out_nmemb);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Menu Items */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Menu Logic
|
|
|
|
* @{ */
|
|
|
|
|
2014-03-28 19:33:20 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Render bm_menu instance using chosen renderer.
|
2014-03-28 19:33:20 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance to be rendered.
|
2014-03-28 19:33:20 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_render(const struct bm_menu *menu);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 20:05:13 +00:00
|
|
|
/**
|
|
|
|
* Trigger filtering of menu manually.
|
|
|
|
* This is useful when adding new items and want to dynamically see them filtered.
|
|
|
|
*
|
|
|
|
* Do note that filtering might be heavy, so you should only call it after batch manipulation of items.
|
|
|
|
* Not after manipulation of each single item.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance which to filter.
|
2014-04-10 20:05:13 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_menu_filter(struct bm_menu *menu);
|
2014-04-10 20:05:13 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
|
|
|
* Poll key and unicode from underlying UI toolkit.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* This function will block on **curses** renderer.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance from which to poll.
|
|
|
|
* @param out_unicode Reference to uint32_t.
|
|
|
|
* @return bm_key for polled key.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_key bm_menu_poll_key(struct bm_menu *menu, uint32_t *out_unicode);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances menu logic with key and unicode as input.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param menu bm_menu instance to be advanced.
|
2014-04-10 10:08:38 +00:00
|
|
|
* @param key Key input that will advance menu logic.
|
|
|
|
* @param unicode Unicode input that will advance menu logic.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return bm_run_result for menu state.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
enum bm_run_result bm_menu_run_with_key(struct bm_menu *menu, enum bm_key key, uint32_t unicode);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Menu Logic */
|
|
|
|
|
|
|
|
/** @} Menu */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Item
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Item Memory
|
|
|
|
* @{ */
|
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
|
|
|
* Allocate a new item.
|
|
|
|
*
|
2014-04-10 14:26:42 +00:00
|
|
|
* @param text Pointer to null terminated C "string", can be **NULL** for empty text.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return bm_item for new item instance, **NULL** if creation failed.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
struct bm_item* bm_item_new(const char *text);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Release bm_item instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param item bm_item instance to be freed from memory.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_item_free(struct bm_item *item);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Item Memory */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Item Properties
|
|
|
|
* @{ */
|
|
|
|
|
2014-04-10 17:09:34 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set userdata pointer to bm_item instance.
|
2014-04-10 17:09:34 +00:00
|
|
|
* Userdata will be carried unmodified by the instance.
|
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param item bm_item instance where to set userdata pointer.
|
2014-04-10 17:09:34 +00:00
|
|
|
* @param userdata Pointer to userdata.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void bm_item_set_userdata(struct bm_item *item, void *userdata);
|
2014-04-10 17:09:34 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get userdata pointer from bm_item instance.
|
2014-04-10 17:09:34 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param item bm_item instance which userdata pointer to get.
|
2014-04-10 17:09:34 +00:00
|
|
|
* @return Pointer for unmodified userdata.
|
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
void* bm_item_get_userdata(struct bm_item *item);
|
2014-04-10 17:09:34 +00:00
|
|
|
|
2014-04-09 22:09:35 +00:00
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Set text to bm_item instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param item bm_item instance where to set text.
|
2014-04-10 14:26:42 +00:00
|
|
|
* @param text C "string" to set as text, can be **NULL** for empty text.
|
2014-10-22 19:46:51 +00:00
|
|
|
* @return true if set was succesful, false if out of memory.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
bool bm_item_set_text(struct bm_item *item, const char *text);
|
2014-04-09 22:09:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-22 19:46:51 +00:00
|
|
|
* Get text from bm_item instance.
|
2014-04-09 22:09:35 +00:00
|
|
|
*
|
2014-10-22 19:46:51 +00:00
|
|
|
* @param item bm_item instance where to get text from.
|
2014-04-10 14:26:42 +00:00
|
|
|
* @return Pointer to null terminated C "string", can be **NULL** for empty text.
|
2014-04-09 22:09:35 +00:00
|
|
|
*/
|
2014-10-22 19:46:51 +00:00
|
|
|
const char* bm_item_get_text(const struct bm_item *item);
|
2014-03-28 19:33:20 +00:00
|
|
|
|
2014-04-10 14:26:42 +00:00
|
|
|
/** @} Item Properties */
|
|
|
|
|
|
|
|
/** @} Item */
|
|
|
|
|
2014-10-24 22:38:30 +00:00
|
|
|
#endif /* _BEMENU_H_ */
|
|
|
|
|
2014-03-28 19:33:20 +00:00
|
|
|
/* vim: set ts=8 sw=4 tw=0 :*/
|