ctxpopup: Add get_items, get_last_item, get_first_item, get_next_item and get_prev_item API

Summary: API to get list of ctxpopup items and give the possibility to iterate the ctxpopup items

Reviewers: stanluk, z.kosinski, Hermet, seoz, raster

CC: Hermet, seoz

Differential Revision: https://phab.enlightenment.org/D1055
This commit is contained in:
Michal Jagiello 2014-07-03 13:05:28 +02:00 committed by Lukasz Stanislawski
parent 2b8e6862ac
commit bf3fe85b0d
4 changed files with 232 additions and 29 deletions

View File

@ -35,6 +35,10 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
static Eina_Bool _key_action_escape(Evas_Object *obj, const char *params);
static Elm_Ctxpopup_Item* _item_new(Eo *obj,
Elm_Ctxpopup_Data *sd,
Evas_Smart_Cb func,
const void *data);
static const Elm_Action key_actions[] = {
{"move", _key_action_move},
@ -1254,41 +1258,13 @@ _elm_ctxpopup_item_append(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Eva
{
Elm_Ctxpopup_Item *item;
item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
item = _item_new(obj, sd, func, data);
if (!item) return NULL;
elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
elm_widget_item_disable_hook_set(item, _item_disable_hook);
elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
if (!sd->list)
{
//The first item is appended.
sd->list = elm_list_add(obj);
if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
elm_object_style_set(sd->list, "ctxpopup");
else elm_object_style_set(sd->list, elm_object_style_get(obj));
elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
elm_list_horizontal_set(sd->list, sd->horizontal);
evas_object_event_callback_add
(sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
elm_layout_content_set(obj, "default", sd->list);
}
item->wcb.org_func_cb = func;
item->wcb.org_data = data;
item->wcb.cobj = obj;
item->list_item =
elm_list_item_append(sd->list, label, icon, NULL, _item_wrap_cb, item);
sd->items = eina_list_append(sd->items, item);
sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
if (sd->visible) elm_layout_sizing_eval(obj);
return (Elm_Object_Item *)item;
@ -1346,4 +1322,118 @@ _elm_ctxpopup_class_constructor(Eo_Class *klass)
evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
}
EOLIAN static const Eina_List*
_elm_ctxpopup_items_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
{
return sd->items;
}
EOLIAN static Elm_Object_Item*
_elm_ctxpopup_first_item_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
{
if (!sd->items) return NULL;
return eina_list_data_get(sd->items);
}
EOLIAN static Elm_Object_Item*
_elm_ctxpopup_last_item_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
{
if (!sd->items) return NULL;
return eina_list_data_get(eina_list_last(sd->items));
}
EOLIAN static Elm_Object_Item*
_elm_ctxpopup_item_prepend(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
{
Elm_Ctxpopup_Item *item;
item = _item_new(obj, sd, func, data);
if (!item) return NULL;
item->list_item =
elm_list_item_prepend(sd->list, label, icon, NULL, _item_wrap_cb, item);
sd->items = eina_list_prepend(sd->items, item);
if (sd->visible) elm_layout_sizing_eval(obj);
return (Elm_Object_Item *)item;
}
EAPI Elm_Object_Item *
elm_ctxpopup_item_prev_get(const Elm_Object_Item *it)
{
Eina_List *l;
Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *)it;
ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, NULL);
ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
if (!sd->items) return NULL;
l = eina_list_data_find_list(sd->items, it);
if (l && l->prev) return eina_list_data_get(l->prev);
return NULL;
}
EAPI Elm_Object_Item *
elm_ctxpopup_item_next_get(const Elm_Object_Item *it)
{
Eina_List *l;
Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *)it;
ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, NULL);
ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
if (!sd->items) return NULL;
l = eina_list_data_find_list(sd->items, it);
if (l && l->next) return eina_list_data_get(l->next);
return NULL;
}
static Elm_Ctxpopup_Item*
_item_new(Eo *obj,
Elm_Ctxpopup_Data *sd,
Evas_Smart_Cb func,
const void *data)
{
Elm_Ctxpopup_Item *item;
item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
if (!item) return NULL;
elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
elm_widget_item_disable_hook_set(item, _item_disable_hook);
elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
if (!sd->list)
{
sd->list = elm_list_add(obj);
if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
elm_object_style_set(sd->list, "ctxpopup");
else elm_object_style_set(sd->list, elm_object_style_get(obj));
elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
elm_list_horizontal_set(sd->list, sd->horizontal);
evas_object_event_callback_add
(sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
elm_layout_content_set(obj, "default", sd->list);
}
item->wcb.org_func_cb = func;
item->wcb.org_data = data;
item->wcb.cobj = obj;
sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
return item;
}
#include "elc_ctxpopup.eo.c"

View File

@ -124,6 +124,63 @@ class Elm_Ctxpopup (Elm_Layout)
return Elm_Ctxpopup_Direction;
}
}
items {
get {
/*@
@brief Get the internal list of items in a given ctxpopup widget.
@since 1.11
@return The list of items (#Elm_Object_Item as data) or
@c NULL on errors.
This list is @b not to be modified in any way and must not be
freed. Use the list members with functions like
elm_object_item_text_set(),
elm_object_item_text_get(),
elm_object_item_del().
@warning This list is only valid until @p obj object's internal
items list is changed. It should be fetched again with another
call to this function when changes happen.
@ingroup Ctxpopup */
return const(Eina_List)*;
}
}
first_item {
get {
/*@
Get the first item in the given ctxpopup widget's list of
items.
@since 1.11
@return The first item or @c NULL, if it has no items (and on
errors)
@see elm_ctxpopup_item_append()
@see elm_ctxpopup_last_item_get()
@ingroup Ctxpopup */
return Elm_Object_Item *;
}
}
last_item {
get {
/*@
Get the last item in the given ctxpopup widget's list of
items.
@since 1.11
@return The last item or @c NULL, if it has no items (and on
errors)
@see elm_ctxpopup_item_prepend()
@see elm_ctxpopup_first_item_get()
@ingroup Ctxpopup */
return Elm_Object_Item *;
}
}
}
methods {
dismiss {
@ -155,6 +212,28 @@ class Elm_Ctxpopup (Elm_Layout)
@ingroup Ctxpopup */
return Elm_Object_Item *;
params {
@in const(char)* label; /*@ The Label of the new item */
@in Evas_Object *icon; /*@ Icon to be set on new item */
@in Evas_Smart_Cb func; /*@ Convenience function called when item selected */
@in const(void)* data; /*@ Data passed to @p func */
}
}
item_prepend {
/*@
@brief Prepend a new item to a ctxpopup object.
@since 1.11
@return A handle to the item added or @c NULL, on errors
@warning Ctxpopup can't hold both an item list and a content at the same
time. When an item is added, any previous content will be removed.
@see elm_object_content_set()
@ingroup Ctxpopup */
return Elm_Object_Item *;
params {
@in const(char)* label; /*@ The Label of the new item */

View File

@ -7,3 +7,33 @@ typedef enum
ELM_CTXPOPUP_DIRECTION_UNKNOWN, /**< ctxpopup does not determine it's direction yet*/
} Elm_Ctxpopup_Direction; /**< Direction in which to show the popup */
/**
* Get the item before @p it in a ctxpopup widget's internal list of
* items.
*
* @param it The item to fetch previous from
* @return The item before the @p it in its parent's list. If there is no
* previous item for @p it or there's an error, @c NULL is returned.
*
* @see elm_ctxpopup_item_next_get()
*
* @since 1.11
* @ingroup Ctxpopup
*/
EAPI Elm_Object_Item *elm_ctxpopup_item_prev_get(const Elm_Object_Item *it);
/**
* Get the item after @p it in a ctxpopup widget's
* internal list of items.
*
* @param it The item to fetch next from
* @return The item after the @p it in its parent's list. If there is no next
* item for @p it or there's an error, @c NULL is returned.
*
* @see elm_ctxpopup_item_prev_get()
*
* @since 1.11
* @ingroup Ctxpopup
*/
EAPI Elm_Object_Item *elm_ctxpopup_item_next_get(const Elm_Object_Item *it);

View File

@ -85,4 +85,8 @@ struct _Elm_Ctxpopup_Data
if (EINA_UNLIKELY(!eo_isa((obj), ELM_CTXPOPUP_CLASS))) \
return
#define ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, ...) \
ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
ELM_CTXPOPUP_CHECK(it->base.widget) __VA_ARGS__;
#endif