2010-10-19 13:21:53 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* @defgroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* A ctxpopup is a widget that, when show, pops up a list of items.
|
2010-10-19 13:21:53 -07:00
|
|
|
* It automatically chooses an area inside its parent object's view
|
2010-11-30 22:52:46 -08:00
|
|
|
* (set via elm_ctxpopup_add() and elm_ctxpopup_hover_parent_set())
|
2010-10-19 13:21:53 -07:00
|
|
|
* to optimally fit into it. In the default theme, it will also point
|
2010-11-30 22:52:46 -08:00
|
|
|
* an arrow to the cursor position at the time one shows it. Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
* items have a label and/or an icon. It is intended for a small
|
|
|
|
* number of items (hence the use of list, not genlist).
|
|
|
|
*
|
|
|
|
* Signals that you can add callbacks for are:
|
|
|
|
*
|
|
|
|
* dismissed - the hover was dismissed
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
struct _Elm_Ctxpopup_Item
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
Elm_Widget_Item base;
|
|
|
|
|
|
|
|
Elm_List_Item *lptr;
|
|
|
|
|
|
|
|
const char *label;
|
|
|
|
Evas_Object *icon;
|
|
|
|
|
|
|
|
Evas_Smart_Cb func;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
Eina_Bool disabled : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Widget_Data
|
|
|
|
{
|
|
|
|
Evas_Object *hover_parent;
|
|
|
|
Evas_Object *list;
|
|
|
|
Evas_Object *target;
|
|
|
|
Evas_Object *hover;
|
|
|
|
Evas *evas;
|
|
|
|
|
|
|
|
Eina_List *items;
|
|
|
|
|
|
|
|
Eina_Bool scroller_disabled : 1;
|
|
|
|
Eina_Bool horizontal : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *widtype = NULL;
|
|
|
|
static void _del_hook(Evas_Object *obj);
|
|
|
|
static void _del_pre_hook(Evas_Object *obj);
|
|
|
|
static void _theme_hook(Evas_Object *obj);
|
|
|
|
static void _hover_clicked_cb(void *data, Evas_Object *obj, void *event_info);
|
|
|
|
static void _parent_resize_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info);
|
2010-11-30 22:52:46 -08:00
|
|
|
static void _ctxpopup_show(void *data, Evas *evas, Evas_Object *obj, void *event_info);
|
|
|
|
static void _ctxpopup_hide(void *data, Evas *evas, Evas_Object *obj, void *event_info);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
static const char SIG_DISMISSED[] = "dismissed";
|
|
|
|
static const Evas_Smart_Cb_Description _signals[] = {
|
|
|
|
{SIG_DISMISSED, ""},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
#define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
|
2010-10-19 13:21:53 -07:00
|
|
|
ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
|
|
|
|
ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
static Elm_Ctxpopup_Item *
|
2010-10-19 13:21:53 -07:00
|
|
|
_item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
|
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
Elm_Ctxpopup_Item *it;
|
2010-10-19 13:21:53 -07:00
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
it = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
|
2010-10-19 13:21:53 -07:00
|
|
|
if (!it)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
it->label = eina_stringshare_add(label);
|
|
|
|
it->icon = icon;
|
|
|
|
it->func = func;
|
|
|
|
it->base.data = data;
|
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-11-30 22:52:46 -08:00
|
|
|
_item_free(Elm_Ctxpopup_Item *it)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
eina_stringshare_del(it->label);
|
|
|
|
elm_widget_item_del(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_del_pre_hook(Evas_Object* obj)
|
|
|
|
{
|
|
|
|
Widget_Data * wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
|
|
|
|
_parent_resize_cb, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object* obj)
|
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
Elm_Ctxpopup_Item *it;
|
2010-10-19 13:21:53 -07:00
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(wd->items, it)
|
|
|
|
_item_free(it);
|
|
|
|
|
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
|
|
|
|
{
|
|
|
|
if (type != EVAS_CALLBACK_KEY_DOWN)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
|
|
|
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
if (strcmp(ev->keyname, "Escape"))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
evas_object_hide(obj);
|
|
|
|
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (elm_widget_focus_get(obj))
|
|
|
|
{
|
2010-12-07 11:18:22 -08:00
|
|
|
elm_object_signal_emit(wd->list, "elm,action,focus", "elm");
|
2010-10-19 13:21:53 -07:00
|
|
|
evas_object_focus_set(wd->list, EINA_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-07 11:18:22 -08:00
|
|
|
elm_object_signal_emit(wd->list, "elm,action,unfocus", "elm");
|
2010-10-19 13:21:53 -07:00
|
|
|
evas_object_focus_set(wd->list, EINA_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object* obj)
|
|
|
|
{
|
|
|
|
Widget_Data* wd;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_widget_style_set(wd->list, "ctxpopup");
|
2010-10-19 13:21:53 -07:00
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
snprintf(buf, sizeof(buf), "ctxpopup/%s", elm_widget_style_get(obj));
|
2010-10-19 13:21:53 -07:00
|
|
|
elm_object_style_set(wd->hover, buf);
|
|
|
|
}
|
|
|
|
|
2010-11-18 04:55:28 -08:00
|
|
|
static void
|
|
|
|
_signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
elm_object_signal_emit(wd->list, emission, source);
|
|
|
|
elm_object_signal_emit(wd->hover, emission, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
elm_object_signal_callback_add(wd->list, emission, source, func_cb, data);
|
|
|
|
elm_object_signal_callback_add(wd->hover, emission, source, func_cb, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data __UNUSED__)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
elm_object_signal_callback_del(wd->list, emission, source, func_cb);
|
|
|
|
elm_object_signal_callback_del(wd->hover, emission, source, func_cb);
|
|
|
|
}
|
|
|
|
|
2010-10-19 13:21:53 -07:00
|
|
|
static void
|
|
|
|
_item_func_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
|
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
Elm_Ctxpopup_Item *it;
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
elm_list_item_selected_set(event_info, EINA_FALSE);
|
|
|
|
|
|
|
|
it = data;
|
|
|
|
if (it->func)
|
|
|
|
it->func((void *)it->base.data, it->base.widget, it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_hover_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
evas_object_hide(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_content_placement_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
|
|
|
|
{
|
|
|
|
const char *new_slot;
|
|
|
|
Widget_Data *wd;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(data);
|
|
|
|
new_slot = event_info;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "elm,action,slot,%s,show", new_slot);
|
|
|
|
elm_widget_signal_emit(wd->hover, buf, "elm");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-30 22:52:46 -08:00
|
|
|
_ctxpopup_show(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
Widget_Data* wd;
|
|
|
|
int px, py;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (eina_list_count(wd->items) < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm_widget_focus_steal(obj);
|
|
|
|
|
|
|
|
evas_pointer_canvas_xy_get(wd->evas, &px, &py);
|
|
|
|
evas_object_geometry_get(wd->target, NULL, NULL, &w, &h);
|
|
|
|
evas_object_move(wd->target, px - (w / 2), py - (h / 2));
|
|
|
|
|
|
|
|
/* reset list */
|
|
|
|
elm_list_item_show(eina_list_data_get(elm_list_items_get(wd->list)));
|
|
|
|
|
|
|
|
evas_object_show(wd->hover);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-30 22:52:46 -08:00
|
|
|
_ctxpopup_hide(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
evas_object_hide(wd->hover);
|
|
|
|
evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wd->hover_parent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_parent_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Widget_Data *wd;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(data);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
evas_object_geometry_get(wd->hover_parent, NULL, NULL, &w, &h);
|
|
|
|
evas_object_size_hint_max_set(wd->list, w * 0.666667, h/2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Add a new Ctxpopup object to the parent.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
|
|
|
* @param parent Parent object
|
|
|
|
* @return New object or @c NULL, if it cannot be created
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI Evas_Object*
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_add(Evas_Object* parent)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
Evas_Object* obj;
|
|
|
|
Widget_Data* wd;
|
|
|
|
char buf[1024];
|
|
|
|
|
2010-12-03 06:08:33 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
|
|
|
|
2010-10-19 13:21:53 -07:00
|
|
|
wd = ELM_NEW(Widget_Data);
|
|
|
|
wd->evas = evas_object_evas_get(parent);
|
|
|
|
obj = elm_widget_add(wd->evas);
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "ctxpopup");
|
|
|
|
elm_widget_type_set(obj, "ctxpopup");
|
2010-10-19 13:21:53 -07:00
|
|
|
elm_widget_sub_object_add(parent, obj);
|
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
|
|
|
|
elm_widget_can_focus_set(obj, EINA_TRUE);
|
|
|
|
elm_widget_del_pre_hook_set(obj, _del_pre_hook);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
|
|
|
elm_widget_theme_hook_set(obj, _theme_hook);
|
|
|
|
elm_widget_event_hook_set(obj, _event_hook);
|
2010-11-18 04:55:28 -08:00
|
|
|
elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
|
|
|
|
elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
|
|
|
|
elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
wd->list = elm_list_add(obj);
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_widget_style_set(wd->list, "ctxpopup");
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
|
|
|
|
evas_object_show(wd->list);
|
|
|
|
|
|
|
|
wd->target = elm_icon_add(obj); /* has to be an elm_widget (dummy,
|
|
|
|
in this case) because we gotta
|
|
|
|
make it work with
|
|
|
|
elm_widget_hover_object_set() */
|
|
|
|
evas_object_resize(wd->target, elm_finger_size_get(),
|
|
|
|
elm_finger_size_get());
|
|
|
|
evas_object_show(wd->target);
|
2010-10-20 05:05:39 -07:00
|
|
|
evas_object_layer_set(wd->target, EVAS_LAYER_MIN);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
wd->hover = elm_hover_add(obj);
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
snprintf(buf, sizeof(buf), "ctxpopup/%s", elm_widget_style_get(obj));
|
2010-10-19 13:21:53 -07:00
|
|
|
elm_object_style_set(wd->hover, buf);
|
|
|
|
|
|
|
|
evas_object_smart_callback_add(wd->hover, "smart,changed",
|
|
|
|
_content_placement_changed_cb, obj);
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_hover_parent_set(obj, parent);
|
2010-10-19 13:21:53 -07:00
|
|
|
elm_hover_target_set(wd->hover, wd->target);
|
|
|
|
|
|
|
|
evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked_cb, obj);
|
|
|
|
elm_hover_content_set(wd->hover, "smart", wd->list);
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
|
2010-10-19 13:21:53 -07:00
|
|
|
NULL);
|
2010-11-30 22:52:46 -08:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
|
2010-10-19 13:21:53 -07:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
elm_widget_sub_object_add(obj, wd->list);
|
|
|
|
elm_widget_sub_object_add(obj, wd->hover);
|
|
|
|
elm_widget_sub_object_add(obj, wd->target);
|
2010-11-16 07:51:03 -08:00
|
|
|
evas_object_smart_callbacks_descriptions_set(obj, _signals);
|
2010-10-19 13:21:53 -07:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* This ends the Ctxpopup's popup as if the user had clicked
|
2010-10-19 13:21:53 -07:00
|
|
|
* outside the hover.
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj The ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_hover_end(Evas_Object *obj)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!wd->hover)
|
|
|
|
return;
|
|
|
|
|
|
|
|
evas_object_hide(wd->hover);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Get the icon object for the given ctxpopup item.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item
|
2010-10-19 13:21:53 -07:00
|
|
|
* @return icon object or @c NULL, if the item does not have icon or
|
|
|
|
* an error occured
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI Evas_Object *
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
|
2010-10-19 13:21:53 -07:00
|
|
|
return item->icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Sets the side icon associated with the ctxpopup item.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
|
|
|
* Once the icon object is set, a previously set one will be deleted.
|
|
|
|
* You probably don't want, then, to have the <b>same</b> icon object
|
|
|
|
* set for more than one item of the list (when replacing one of its
|
|
|
|
* instances).
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param icon Icon object to be set
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(item->base.widget);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (item->icon)
|
|
|
|
{
|
|
|
|
evas_object_del(item->icon);
|
|
|
|
item->icon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->icon = icon;
|
|
|
|
elm_list_item_icon_set(item->lptr, icon);
|
|
|
|
elm_list_go(wd->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Get the label object for the given ctxpopup item.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item
|
2010-10-19 13:21:53 -07:00
|
|
|
* @return label object or @c NULL, if the item does not have label or
|
|
|
|
* an error occured
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI const char *
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
|
2010-10-19 13:21:53 -07:00
|
|
|
return item->label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* (Re)set the label on the given ctxpopup item.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj Ctxpopup item
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param label String to set as label
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(item->base.widget);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!eina_stringshare_replace(&item->label, label))
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm_list_item_label_set(item->lptr, label);
|
|
|
|
elm_list_go(wd->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Set the Ctxpopup's parent.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
|
|
|
* Sets the hover's parent object (it would much probably be the
|
2010-11-30 22:52:46 -08:00
|
|
|
* window that the ctxpopup is in). See Hover objects for more
|
2010-10-19 13:21:53 -07:00
|
|
|
* information.
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj The ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param parent The parent to use
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @note elm_ctxpopup_add() will automatically call this function
|
2010-10-19 13:21:53 -07:00
|
|
|
* with its @c parent argument.
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
2010-12-03 06:08:33 -08:00
|
|
|
if (!wd)
|
2010-10-19 13:21:53 -07:00
|
|
|
return;
|
|
|
|
|
2010-12-03 06:08:33 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(parent);
|
|
|
|
|
2010-10-19 13:21:53 -07:00
|
|
|
elm_hover_parent_set(wd->hover, parent);
|
|
|
|
|
|
|
|
if (wd->hover_parent)
|
|
|
|
{
|
|
|
|
evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
|
|
|
|
_parent_del, obj);
|
|
|
|
evas_object_event_callback_del_full(wd->hover_parent,
|
|
|
|
EVAS_CALLBACK_RESIZE,
|
|
|
|
_parent_resize_cb, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
wd->hover_parent = parent;
|
|
|
|
evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_DEL,
|
|
|
|
_parent_del, obj);
|
|
|
|
evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_RESIZE,
|
|
|
|
_parent_resize_cb, obj);
|
|
|
|
|
|
|
|
_parent_resize_cb(obj, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Get the Ctxpopup's parent object.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj The ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param parent The parent to use
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* See elm_ctxpopup_hover_parent_set() for more information.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI Evas_Object *
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return wd->hover_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Clear all items in the given ctxpopup object.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj Ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_clear(Evas_Object* obj)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
Elm_Ctxpopup_Item *item;
|
2010-10-19 13:21:53 -07:00
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
2010-10-22 14:41:22 -07:00
|
|
|
if ((!wd) || (!wd->items))
|
2010-10-19 13:21:53 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(wd->items, item)
|
|
|
|
{
|
|
|
|
elm_list_item_del(item->lptr);
|
|
|
|
_item_free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
evas_object_hide(wd->hover);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Change the ctxpopup's orientation to horizontal or vertical.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj Ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE
|
|
|
|
* for vertical
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_horizontal_set(Evas_Object* obj, Eina_Bool horizontal)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wd->horizontal == horizontal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wd->horizontal = horizontal;
|
|
|
|
elm_list_horizontal_set(wd->list, horizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Get the value of current ctxpopup object's orientation.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj Ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
* @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for
|
|
|
|
* vertical mode (or errors)
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_horizontal_get(const Evas_Object *obj)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get( obj );
|
|
|
|
if (!wd)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
return wd->horizontal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Append a new item to a ctxpopup object.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param obj Ctxpopup object
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param label The label of the new item
|
|
|
|
* @param icon Icon to be set on new item
|
|
|
|
* @param func Convenience function called when item selected
|
|
|
|
* @param data Data passed to @p func above
|
|
|
|
* @return A handle to the item added or @c NULL, on errors
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
2010-11-30 22:52:46 -08:00
|
|
|
EAPI Elm_Ctxpopup_Item *
|
|
|
|
elm_ctxpopup_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
|
|
|
|
2010-11-30 22:52:46 -08:00
|
|
|
Elm_Ctxpopup_Item* item;
|
2010-10-19 13:21:53 -07:00
|
|
|
Widget_Data* wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
item = _item_new(obj, label, icon, func, data);
|
|
|
|
if (!item)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wd->items = eina_list_append(wd->items, item);
|
|
|
|
item->lptr = elm_list_item_append(wd->list, label, icon, NULL,
|
|
|
|
_item_func_cb, item);
|
|
|
|
elm_list_go(wd->list);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Delete the given item in a ctxpopup object.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item to be deleted
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(item->base.widget);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wd->items = eina_list_remove(wd->items, item);
|
|
|
|
|
|
|
|
elm_list_item_del(item->lptr);
|
|
|
|
item->lptr = NULL;
|
|
|
|
|
|
|
|
if (eina_list_count(wd->items) < 1)
|
|
|
|
evas_object_hide(wd->hover);
|
|
|
|
|
|
|
|
_item_free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Set the ctxpopup item's state as disabled or enabled
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item to be enabled/disabled
|
2010-10-19 13:21:53 -07:00
|
|
|
* @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
wd = elm_widget_data_get(item->base.widget);
|
|
|
|
if (!wd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (disabled == item->disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
item->disabled = disabled;
|
|
|
|
elm_list_item_disabled_set(item->lptr, disabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-30 22:52:46 -08:00
|
|
|
* Get the ctxpopup item's disabled/enabled state.
|
2010-10-19 13:21:53 -07:00
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @param item Ctxpopup item to be enabled/disabled
|
2010-10-19 13:21:53 -07:00
|
|
|
* @return @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
|
|
|
|
*
|
2010-11-30 22:52:46 -08:00
|
|
|
* @ingroup Ctxpopup
|
2010-10-19 13:21:53 -07:00
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
2010-11-30 22:52:46 -08:00
|
|
|
elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
|
2010-10-19 13:21:53 -07:00
|
|
|
{
|
2010-11-30 22:52:46 -08:00
|
|
|
ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
|
2010-10-19 13:21:53 -07:00
|
|
|
|
|
|
|
return item->disabled;
|
|
|
|
}
|