From 8de9f9d04b5c52b46070998367df8e22c69dbfb1 Mon Sep 17 00:00:00 2001 From: Leonard Ritter Date: Sat, 16 Aug 2014 14:32:51 +0200 Subject: [PATCH] oui: support for extending items by event --- oui.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/oui.h b/oui.h index 13164d3..74084b2 100644 --- a/oui.h +++ b/oui.h @@ -265,15 +265,18 @@ typedef enum UIevent { // as they appear. UI_APPEND = 0x0100, // item is focused and has received a key-down event - // the respective key can be queried using uiGetActiveKey() + // the respective key can be queried using uiGetKey() and uiGetModifier() UI_KEY_DOWN = 0x0200, // item is focused and has received a key-up event - // the respective key can be queried using uiGetActiveKey() + // the respective key can be queried using uiGetKey() and uiGetModifier() UI_KEY_UP = 0x0400, // item is focused and has received a character event - // the respective character can be queried using uiGetActiveKey() + // the respective character can be queried using uiGetKey() UI_CHAR = 0x0800, - + // item is requested to fill a container with additional items, + // usually menuitems for a context menu. + // the respective container can be queried using uiGetExtendItem() + UI_EXTEND = 0x1000, } UIevent; // handler callback; event is one of UI_EVENT_* @@ -511,6 +514,8 @@ int uiGetHandlerFlags(int item); unsigned int uiGetKey(); // when handling a KEY_DOWN/KEY_UP event: the key that triggered this event unsigned int uiGetModifier(); +// when handling an EXTEND event; the container which to add items to +int uiGetExtendItem(); // returns the number of child items a container item contains. If the item // is not a container or does not contain any items, 0 is returned. @@ -693,6 +698,7 @@ struct UIcontext { int hot_item; unsigned int active_key; unsigned int active_modifier; + int extend_item; int count; int datasize; @@ -902,6 +908,11 @@ unsigned int uiGetModifier() { return ui_context->active_modifier; } +int uiGetExtendItem() { + assert(ui_context); + return ui_context->extend_item; +} + UIitem *uiItemPtr(int item) { assert(ui_context && (item >= 0) && (item < ui_context->count)); return ui_context->items + item; @@ -954,6 +965,12 @@ void uiNotifyItem(int item, UIevent event) { } } +void uiExtend(int parent, int from_item) { + assert(ui_context); + ui_context->extend_item = parent; + uiNotifyItem(from_item, UI_EXTEND); +} + int uiAppend(int item, int child) { assert(child > 0); assert(uiParent(child) == -1);