const char *label;
Evas_Object *icon;
Evas_Smart_Cb func;
- Eina_Bool disabled:1;
};
struct _Widget_Data
Evas_Coord_Rectangle *hover_area);
static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
Evas_Coord_Rectangle *rect);
-static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
+static void _update_arrow(Evas_Object *obj,
+ Elm_Ctxpopup_Direction dir,
+ Evas_Coord_Rectangle rect);
static void _sizing_eval(Evas_Object *obj);
+static void _hide_signal_emit(Evas_Object *obj,
+ Elm_Ctxpopup_Direction dir);
+static void _show_signal_emit(Evas_Object *obj,
+ Elm_Ctxpopup_Direction dir);
static void _shift_base_by_arrow(Evas_Object *arrow,
Elm_Ctxpopup_Direction dir,
Evas_Coord_Rectangle *rect);
const char *part__);
static Evas_Object * _content_get_hook(const Evas_Object *obj,
const char *part);
+static void _item_text_set_hook(Elm_Object_Item *it,
+ const char *part,
+ const char *label);
+static const char * _item_text_get_hook(const Elm_Object_Item *it,
+ const char *part);
+static void _item_content_set_hook(Elm_Object_Item *it,
+ const char *part,
+ Evas_Object *content);
+static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
+ const char *part);
+static void _item_disable_hook(Elm_Object_Item *it);
+static void _item_signal_emit_hook(Elm_Object_Item *it,
+ const char *emission,
+ const char *source);
static void _bg_clicked_cb(void *data, Evas_Object *obj,
const char *emission,
const char *source);
Evas *e,
Evas_Object *obj,
void *event_info);
-static void _hide(Evas_Object *obj);
+static void _hide_finished(void *data,
+ Evas_Object *obj,
+ const char *emission,
+ const char *source __UNUSED__);
static void _ctxpopup_hide(void *data,
Evas *e,
Evas_Object *obj,
void *event_info);
+static void _content_resize(void *data,
+ Evas *e,
+ Evas_Object *obj,
+ void *event_info);
static void _scroller_resize(void *data,
Evas *e,
Evas_Object *obj,
Evas *e,
Evas_Object *obj,
void *event_info);
+static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _item_select_cb(void *data, Evas_Object *obj,
const char *emission,
const char *source);
static void _list_del(Widget_Data *wd);
static void _list_new(Evas_Object *obj);
static void _remove_items(Widget_Data * wd);
+static void _disable_hook(Evas_Object *obj);
+static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
+static void _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
+static void _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
static const char SIG_DISMISSED[] = "dismissed";
}
static Eina_Bool
-_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
+_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
+ Evas_Callback_Type type, void *event_info)
{
Evas_Event_Key_Down *ev;
Widget_Data *wd;
wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
- _hide(data);
+ evas_object_hide(data);
}
static void
if (!item) return;
- edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
+ edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
min_h);
- evas_object_size_hint_min_set(item->base.view, min_w, min_h);
- evas_object_size_hint_max_set(item->base.view, max_w, max_h);
+ evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
+ evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
}
static void
}
static void
-_update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
+_update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
+ Evas_Coord_Rectangle base_size)
{
Evas_Coord x, y;
Evas_Coord_Rectangle arrow_size;
- Evas_Coord_Rectangle base_size;
Widget_Data *wd;
+ double drag;
wd = elm_widget_data_get(obj);
if (!wd) return;
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
&arrow_size.h);
- evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
- &base_size.w, &base_size.h);
edje_object_part_unswallow(wd->base, wd->arrow);
{
case ELM_CTXPOPUP_DIRECTION_RIGHT:
edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
- edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
+ edje_object_part_swallow(wd->base,
+ "elm.swallow.arrow_left",
+ wd->arrow);
if (base_size.h > 0)
{
if (y < ((arrow_size.h * 0.5) + base_size.y))
y = base_size.h - arrow_size.h;
else
y = y - base_size.y - (arrow_size.h * 0.5);
- edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
- (double) (y) / (double) (base_size.h - arrow_size.h));
+ drag = (double) (y) / (double) (base_size.h - arrow_size.h);
+ edje_object_part_drag_value_set(wd->base,
+ "elm.swallow.arrow_left",
+ 1,
+ drag);
}
break;
case ELM_CTXPOPUP_DIRECTION_LEFT:
edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
- edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
+ edje_object_part_swallow(wd->base,
+ "elm.swallow.arrow_right",
+ wd->arrow);
if (base_size.h > 0)
- {
- if (y < (arrow_size.h * 0.5) + base_size.y)
+ {
+ if (y < ((arrow_size.h * 0.5) + base_size.y))
y = 0;
else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
y = base_size.h - arrow_size.h;
- else y = y - base_size.y - (arrow_size.h * 0.5);
- edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
- (double) (y) / (double) (base_size.h - arrow_size.h));
- }
+ else
+ y = y - base_size.y - (arrow_size.h * 0.5);
+ drag = (double) (y) / (double) (base_size.h - arrow_size.h);
+ edje_object_part_drag_value_set(wd->base,
+ "elm.swallow.arrow_right",
+ 0,
+ drag);
+ }
break;
case ELM_CTXPOPUP_DIRECTION_DOWN:
edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
if (base_size.w > 0)
{
- if (x < (arrow_size.w * 0.5) + base_size.x)
+ if (x < ((arrow_size.w * 0.5) + base_size.x))
x = 0;
else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
x = base_size.w - arrow_size.w;
else
x = x - base_size.x - (arrow_size.w * 0.5);
- edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
- (double) (x) / (double) (base_size.w - arrow_size.w), 1);
+ drag = (double) (x) / (double) (base_size.w - arrow_size.w);
+ edje_object_part_drag_value_set(wd->base,
+ "elm.swallow.arrow_up",
+ drag,
+ 1);
}
break;
case ELM_CTXPOPUP_DIRECTION_UP:
edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
- edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
+ edje_object_part_swallow(wd->base,
+ "elm.swallow.arrow_down",
+ wd->arrow);
if (base_size.w > 0)
{
- if (x < (arrow_size.w * 0.5) + base_size.x)
+ if (x < ((arrow_size.w * 0.5) + base_size.x))
x = 0;
else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
x = base_size.w - arrow_size.w;
else x = x - base_size.x - (arrow_size.w * 0.5);
- edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
- (double) (x) / (double) (base_size.w - arrow_size.w), 0);
+ drag = (double) (x) / (double) (base_size.w - arrow_size.w);
+ edje_object_part_drag_value_set(wd->base,
+ "elm.swallow.arrow_down",
+ drag,
+ 0);
}
break;
default:
}
}
+//TODO: compress item - different from opensource
+static void
+_compress_item(Evas_Object *obj)
+{
+ Widget_Data *wd;
+ Eina_List *elist;
+ Elm_Ctxpopup_Item *item;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ EINA_LIST_FOREACH(wd->items, elist, item)
+ {
+ edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
+ }
+}
+
+static void
+_hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
+{
+ Widget_Data *wd;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd->visible) return;
+
+ switch (dir)
+ {
+ case ELM_CTXPOPUP_DIRECTION_UP:
+ edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
+ break;
+ case ELM_CTXPOPUP_DIRECTION_LEFT:
+ edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
+ break;
+ case ELM_CTXPOPUP_DIRECTION_RIGHT:
+ edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
+ break;
+ case ELM_CTXPOPUP_DIRECTION_DOWN:
+ edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
+ break;
+ default:
+ break;
+ }
+
+ edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
+}
+
static void
_show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
{
Widget_Data *wd;
wd = elm_widget_data_get(obj);
- if (!wd || wd->visible) return;
+ if (wd->visible) return;
switch (dir)
{
wd = elm_widget_data_get(obj);
if (!wd) return;
+ if (!wd->parent) return;
//Box, Scroller
EINA_LIST_FOREACH(wd->items, elist, item)
{
_item_sizing_eval(item);
- evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
+ evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
if (!wd->horizontal)
{
if (_box_size.x > box_size.x)
//Base
wd->dir = _calc_base_geometry(obj, &rect);
+
+ //TODO: compress item - different from opensource
+ if (!wd->horizontal && !wd->content)
+ _compress_item(obj);
+
_show_signal_emit(obj, wd->dir);
- _update_arrow(obj, wd->dir);
+ _update_arrow(obj, wd->dir, rect);
_shift_base_by_arrow(wd->arrow, wd->dir, &rect);
//resize scroller according to final size.
wd = elm_widget_data_get(obj);
if (!wd) return;
+ evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
+ _parent_resize, obj);
+ evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
+ _content_resize, obj);
+
_parent_cut_off(obj);
}
free(wd);
}
+//FIXME: lost the content size when theme hook is called.
static void
_theme_hook(Evas_Object *obj)
{
Widget_Data *wd;
Eina_List *elist;
Elm_Ctxpopup_Item *item;
+ int idx = 0;
+ Eina_Bool rtl;
wd = elm_widget_data_get(obj);
if (!wd) return;
+ _elm_widget_mirrored_reload(obj);
+ rtl = elm_widget_mirrored_get(obj);
+
+ _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
+ elm_widget_style_get(obj));
+ _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
+ elm_widget_style_get(obj));
+ _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
+ elm_widget_style_get(obj));
+
//Items
EINA_LIST_FOREACH(wd->items, elist, item)
{
+ edje_object_mirrored_set(VIEW(item), rtl);
+
if (item->label && item->icon)
- _elm_theme_object_set(obj, item->base.view, "ctxpopup",
+ _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
"icon_text_style_item",
elm_widget_style_get(obj));
else if (item->label)
- _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
+ _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
elm_widget_style_get(obj));
else if (item->icon)
- _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
+ _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
elm_widget_style_get(obj));
if (item->label)
- edje_object_part_text_set(item->base.view, "elm.text", item->label);
-
- if (item->disabled)
- edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
-
- edje_object_message_signal_process(item->base.view);
+ edje_object_part_text_set(VIEW(item), "elm.text", item->label);
+
+ if (elm_widget_item_disabled_get(item))
+ edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
+
+ /*
+ * For separator, if the first item has visible separator,
+ * then it should be aligned with edge of the base part.
+ * In some cases, it gives improper display. Ex) rounded corner
+ * So the first item separator should be invisible.
+ */
+ if ((idx++) == 0)
+ edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
+ else
+ {
+ if(!wd->horizontal)
+ edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
+ else
+ edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
+ }
+
+ edje_object_message_signal_process(VIEW(item));
}
- _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
- elm_widget_style_get(obj));
- _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
- elm_widget_style_get(obj));
- _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
- elm_widget_style_get(obj));
+ if (evas_object_visible_get(wd->bg))
+ edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
if (wd->scr)
{
- if (!strncmp(elm_object_style_get(obj), "default",
- strlen("default")))
+ if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
elm_object_style_set(wd->scr, "ctxpopup");
else
elm_object_style_set(wd->scr, elm_object_style_get(obj));
}
static void
-_content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
- Evas_Object *content)
+_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
{
ELM_CHECK_WIDTYPE(obj, widtype);
+ Evas_Coord min_w = -1, min_h = -1;
Widget_Data *wd;
+ if (part && strcmp(part, "default")) return;
+
wd = elm_widget_data_get(obj);
if ((!wd) || (!content)) return;
if (wd->items) elm_ctxpopup_clear(obj);
if (wd->content) evas_object_del(wd->content);
- evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
- obj);
+ //Use Box
+ wd->box = elm_box_add(obj);
+ evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
+ EVAS_HINT_FILL);
+ evas_object_show(content);
+ evas_object_size_hint_min_get(content, &min_w, &min_h);
+ evas_object_size_hint_min_set(wd->box, min_w, min_h);
+ elm_box_pack_end(wd->box, content);
- elm_widget_sub_object_add(obj, content);
- edje_object_part_swallow(wd->base, "elm.swallow.content", content);
+ evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
+ _content_resize, obj);
+ evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
+ _content_del, obj);
- wd->content = content;
+ elm_widget_sub_object_add(obj, wd->box);
+ edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
+ wd->content = content;
wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
if (wd->visible)
}
static Evas_Object *
-_content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
+_content_unset_hook(Evas_Object *obj, const char *part)
{
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd;
Evas_Object *content;
-
+ if (part && strcmp(part, "default")) return NULL;
wd = elm_widget_data_get(obj);
if (!wd) return NULL;
content = wd->content;
- if (!content) return NULL;
+ if (!content || !wd->box) return NULL;
- edje_object_part_unswallow(wd->base, content);
- elm_widget_sub_object_del(obj, content);
- evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
+ edje_object_part_unswallow(wd->base, wd->box);
+ elm_widget_sub_object_del(obj, wd->box);
+ evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
+ evas_object_del(wd->box);
+ wd->box = NULL;
wd->content = NULL;
wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
return content;
-
}
static Evas_Object *
-_content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
+_content_get_hook(const Evas_Object *obj, const char *part)
{
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-
- Widget_Data *wd = elm_widget_data_get(obj);
+ Widget_Data *wd;
+ if (part && strcmp(part, "default")) return NULL;
+ wd = elm_widget_data_get(obj);
if (!wd) return NULL;
return wd->content;
}
static void
+_item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
+{
+ Widget_Data *wd;
+ Elm_Ctxpopup_Item *ctxpopup_it;
+
+ if (part && strcmp(part, "default")) return;
+
+ ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+
+ wd = elm_widget_data_get(WIDGET(ctxpopup_it));
+ if (!wd) return;
+
+ _item_label_set(ctxpopup_it, label);
+ wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
+
+ if (wd->visible)
+ {
+ _scroller_size_reset(wd);
+ _sizing_eval(WIDGET(ctxpopup_it));
+ }
+}
+
+static const char *
+_item_text_get_hook(const Elm_Object_Item *it, const char *part)
+{
+ Elm_Ctxpopup_Item *ctxpopup_it;
+ if (part && strcmp(part, "default")) return NULL;
+ ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+ return ctxpopup_it->label;
+}
+
+static void
+_item_content_set_hook(Elm_Object_Item *it,
+ const char *part,
+ Evas_Object *content)
+{
+ Widget_Data *wd;
+ Elm_Ctxpopup_Item *ctxpopup_it;
+
+ if (part && strcmp(part, "icon")) return;
+
+ ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+
+ wd = elm_widget_data_get(WIDGET(ctxpopup_it));
+ if (!wd) return;
+
+ _item_icon_set(ctxpopup_it, content);
+ wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
+
+ if (wd->visible)
+ {
+ _scroller_size_reset(wd);
+ _sizing_eval(WIDGET(ctxpopup_it));
+ }
+}
+
+static Evas_Object *
+_item_content_get_hook(const Elm_Object_Item *it, const char *part)
+{
+ Elm_Ctxpopup_Item *ctxpopup_it;
+ if (part && strcmp(part, "icon")) return NULL;
+ ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+ return ctxpopup_it->icon;
+}
+
+static void
+_item_disable_hook(Elm_Object_Item *it)
+{
+ Widget_Data *wd;
+ Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+
+ wd = elm_widget_data_get(WIDGET(ctxpopup_it));
+ if (!wd) return;
+
+ if (elm_widget_item_disabled_get(it))
+ edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
+ else
+ edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
+}
+
+static void
+_item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
+ const char *source)
+{
+ Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+ edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
+}
+
+static void
_bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
- evas_object_hide(data);
+ Widget_Data *wd = elm_widget_data_get(data);
+ if (!wd) return;
+ _hide_signal_emit(data, wd->dir);
}
static void
void *event_info __UNUSED__)
{
Widget_Data *wd;
+ Eina_List *elist;
+ Elm_Ctxpopup_Item *item;
+ int idx = 0;
wd = elm_widget_data_get(obj);
if (!wd) return;
evas_object_show(wd->arrow);
edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
+
+ EINA_LIST_FOREACH(wd->items, elist, item)
+ {
+ if (idx++ == 0)
+ edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
+ else
+ {
+ if(!wd->horizontal)
+ edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
+ else
+ edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
+ }
+ }
+
edje_object_signal_emit(wd->base, "elm,state,show", "elm");
_sizing_eval(obj);
}
static void
-_hide(Evas_Object *obj)
+_hide_finished(void *data, Evas_Object *obj __UNUSED__,
+ const char *emission __UNUSED__, const char *source __UNUSED__)
{
- Widget_Data *wd = elm_widget_data_get(obj);
+ evas_object_hide(data);
+ evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
+}
+static void
+_ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
+ void *event_info __UNUSED__)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
if ((!wd) || (!wd->visible)) return;
evas_object_hide(wd->bg);
_scroller_size_reset(wd);
- evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
wd->visible = EINA_FALSE;
}
static void
-_ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
- void *event_info __UNUSED__)
+_content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
+ void *event_info __UNUSED__)
{
- _hide(obj);
+ Widget_Data *wd = elm_widget_data_get(data);
+ if (!wd) return;
+ elm_box_recalculate(wd->box);
+ _sizing_eval(data);
}
static void
}
static void
+_restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ evas_object_layer_set(wd->bg,
+ evas_object_layer_get(obj));
+ evas_object_layer_set(wd->base,
+ evas_object_layer_get(obj));
+}
+
+static void
_item_select_cb(void *data, Evas_Object *obj __UNUSED__,
const char *emission __UNUSED__, const char *source __UNUSED__)
{
Elm_Ctxpopup_Item *item = data;
if (!item) return;
- if (item->disabled) return;
+ if (elm_widget_item_disabled_get(item)) return;
if (item->func)
- item->func((void*) item->base.data, item->base.widget, data);
+ item->func((void*)item->base.data, WIDGET(item), data);
}
static void
item->icon = icon;
if (!icon) return;
- edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
- edje_object_message_signal_process(item->base.view);
+ edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
+ edje_object_message_signal_process(VIEW(item));
}
static void
if (!eina_stringshare_replace(&item->label, label))
return;
- edje_object_part_text_set(item->base.view, "elm.text", label);
- edje_object_message_signal_process(item->base.view);
+ edje_object_part_text_set(VIEW(item), "elm.text", label);
+ edje_object_message_signal_process(VIEW(item));
}
static void
{
Widget_Data *wd;
- wd = elm_widget_data_get(item->base.widget);
+ wd = elm_widget_data_get(WIDGET(item));
if (!wd) return;
- item->base.view = edje_object_add(evas_object_evas_get(wd->base));
- _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
- elm_widget_style_get(item->base.widget));
- edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
+ VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
+ edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
+ _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
+ elm_widget_style_get(WIDGET(item)));
+ edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
_item_select_cb, item);
- evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(item->base.view);
+ evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(VIEW(item));
}
static void
evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
- elm_scroller_content_set(wd->scr, wd->box);
+ elm_object_content_set(wd->scr, wd->box);
elm_ctxpopup_horizontal_set(obj, wd->horizontal);
}
if (item->icon)
evas_object_del(item->icon);
wd->items = eina_list_remove(wd->items, item);
- free(item);
+ elm_widget_item_free(item);
}
wd->items = NULL;
}
+static Eina_Bool
+_item_del_pre_hook(Elm_Object_Item *it)
+{
+ Widget_Data *wd;
+ Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
+
+ wd = elm_widget_data_get(WIDGET(ctxpopup_it));
+ if (!wd) return EINA_FALSE;
+
+ if (ctxpopup_it->icon)
+ evas_object_del(ctxpopup_it->icon);
+ if (VIEW(ctxpopup_it))
+ evas_object_del(VIEW(ctxpopup_it));
+
+ eina_stringshare_del(ctxpopup_it->label);
+
+ wd->items = eina_list_remove(wd->items, ctxpopup_it);
+
+ wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
+
+ if (eina_list_count(wd->items) < 1)
+ {
+ evas_object_hide(WIDGET(ctxpopup_it));
+ return EINA_TRUE;
+ }
+
+ if (wd->visible)
+ _sizing_eval(WIDGET(ctxpopup_it));
+
+ return EINA_TRUE;
+}
+
+static void
+_disable_hook(Evas_Object *obj)
+{
+ Eina_List *l;
+ Elm_Object_Item *it;
+
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ EINA_LIST_FOREACH(wd->items, l, it)
+ elm_object_item_disabled_set(it, elm_widget_disabled_get(obj));
+}
+
+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;
+ edje_object_signal_emit(wd->base, emission, source);
+}
+
+static void
+_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
+}
+
+static void
+_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ edje_object_signal_callback_del_full(wd->base, emission, source, func_cb, data);
+}
+
EAPI Evas_Object *
elm_ctxpopup_add(Evas_Object *parent)
{
elm_widget_content_set_hook_set(obj, _content_set_hook);
elm_widget_content_unset_hook_set(obj, _content_unset_hook);
elm_widget_content_get_hook_set(obj, _content_get_hook);
+ elm_widget_disable_hook_set(obj, _disable_hook);
+ 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);
//Background
wd->bg = edje_object_add(e);
wd->base = edje_object_add(e);
elm_widget_sub_object_add(obj, wd->base);
_elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
+ edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
+ _hide_finished, obj);
//Arrow
wd->arrow = edje_object_add(e);
NULL);
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
NULL);
+ evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
return obj;
}
-EAPI Evas_Object *
-elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
- return ctxpopup_it->icon;
-}
-
-EAPI void
-elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
-
- Widget_Data *wd;
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
-
- wd = elm_widget_data_get(ctxpopup_it->base.widget);
- if (!wd) return;
-
- _item_icon_set(ctxpopup_it, icon);
- wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
-
- if (wd->visible)
- {
- _scroller_size_reset(wd);
- _sizing_eval(ctxpopup_it->base.widget);
- }
-}
-
-EAPI const char *
-elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
- return ctxpopup_it->label;
-}
-
-EAPI void
-elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
-
- Widget_Data *wd;
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
-
- wd = elm_widget_data_get(ctxpopup_it->base.widget);
- if (!wd) return;
-
- _item_label_set(ctxpopup_it, label);
- wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
-
- if (wd->visible)
- {
- _scroller_size_reset(wd);
- _sizing_eval(ctxpopup_it->base.widget);
- }
-}
-
EAPI void
elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd;
+ Eina_List *elist;
+ Elm_Ctxpopup_Item *item;
+ int idx = 0;
wd = elm_widget_data_get(obj);
if (!wd) return;
{
elm_box_horizontal_set(wd->box, EINA_FALSE);
elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
+
+ EINA_LIST_FOREACH(wd->items, elist, item)
+ {
+ if (idx++ == 0)
+ edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
+ else
+ edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
+ }
}
else
{
elm_box_horizontal_set(wd->box, EINA_TRUE);
elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
+
+ EINA_LIST_FOREACH(wd->items, elist, item)
+ {
+ if (idx++ == 0)
+ edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
+ else
+ edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
+ }
}
wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
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);
+
//The first item is appended.
content = elm_object_content_unset(obj);
if (content) evas_object_del(content);
_item_icon_set(item, icon);
_item_label_set(item, label);
- elm_box_pack_end(wd->box, item->base.view);
+ elm_box_pack_end(wd->box, VIEW(item));
wd->items = eina_list_append(wd->items, item);
wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
_sizing_eval(obj);
}
- return (Elm_Object_Item *) item;
-}
-
-EAPI void
-elm_ctxpopup_item_del(Elm_Object_Item *it)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
-
- Widget_Data *wd;
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
-
- wd = elm_widget_data_get(ctxpopup_it->base.widget);
- if (!wd) return;
-
- if (ctxpopup_it->icon)
- evas_object_del(ctxpopup_it->icon);
- if (ctxpopup_it->base.view)
- evas_object_del(ctxpopup_it->base.view);
-
- eina_stringshare_del(ctxpopup_it->label);
-
- wd->items = eina_list_remove(wd->items, ctxpopup_it);
-
- wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
-
- elm_widget_item_del(ctxpopup_it);
-
- if (eina_list_count(wd->items) < 1)
- {
- evas_object_hide(ctxpopup_it->base.widget);
- return;
- }
-
- if (wd->visible)
- _sizing_eval(ctxpopup_it->base.widget);
-
-}
-
-EAPI void
-elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
-
- Widget_Data *wd;
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
-
- wd = elm_widget_data_get(ctxpopup_it->base.widget);
- if (!wd) return;
-
- if (disabled == ctxpopup_it->disabled)
- return;
-
- if (disabled)
- edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
- else
- edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
-
- ctxpopup_it->disabled = !!disabled;
-}
-
-EAPI Eina_Bool
-elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
-{
- ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
- Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
- return ctxpopup_it->disabled;
-}
-
-EAPI void
-elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
-{
- elm_object_content_set(obj, content);
-}
-
-EAPI Evas_Object *
-elm_ctxpopup_content_unset(Evas_Object *obj)
-{
- return elm_object_content_unset(obj);
+ return (Elm_Object_Item *)item;
}
EAPI void
if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
return wd->dir;
}
+
+EAPI void
+elm_ctxpopup_dismiss(Evas_Object *obj)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ _hide_signal_emit(obj, wd->dir);
+}