1 #include <Elementary.h>
3 #include "elm_widget_ctxpopup.h"
5 EAPI const char ELM_CTXPOPUP_SMART_NAME[] = "elm_ctxpopup";
7 static const char SIG_DISMISSED[] = "dismissed";
8 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
13 EVAS_SMART_SUBCLASS_NEW
14 (ELM_CTXPOPUP_SMART_NAME, _elm_ctxpopup, Elm_Ctxpopup_Smart_Class,
15 Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
18 _elm_ctxpopup_smart_focus_next(const Evas_Object *obj,
19 Elm_Focus_Direction dir,
22 Eina_List *items = NULL;
23 Eina_List *elist = NULL;
24 Elm_Ctxpopup_Item *it;
26 ELM_CTXPOPUP_DATA_GET(obj, sd);
31 if (eina_list_count(sd->items))
33 EINA_LIST_FOREACH(sd->items, elist, it)
34 items = eina_list_append(items, it->base.access_obj);
36 return elm_widget_focus_list_next_get
37 (obj, items, eina_list_data_get, dir, next);
41 return elm_widget_focus_next_get(sd->box, dir, next);
46 _elm_ctxpopup_smart_event(Evas_Object *obj,
47 Evas_Object *src __UNUSED__,
48 Evas_Callback_Type type,
51 Evas_Event_Key_Down *ev = event_info;
53 ELM_CTXPOPUP_DATA_GET(obj, sd);
55 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
56 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
57 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
59 if (!strcmp(ev->keyname, "Tab"))
61 if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
62 elm_widget_focus_cycle(sd->box, ELM_FOCUS_PREVIOUS);
64 elm_widget_focus_cycle(sd->box, ELM_FOCUS_NEXT);
68 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
70 evas_object_hide(obj);
71 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
76 _freeze_on_cb(void *data __UNUSED__,
78 void *event_info __UNUSED__)
80 ELM_CTXPOPUP_DATA_GET(obj, sd);
82 if ((!sd) || (!sd->scr)) return;
83 elm_object_scroll_freeze_push(sd->scr);
87 _freeze_off_cb(void *data __UNUSED__,
89 void *event_info __UNUSED__)
91 ELM_CTXPOPUP_DATA_GET(obj, sd);
93 if ((!sd) || (!sd->scr)) return;
94 elm_object_scroll_freeze_pop(sd->scr);
98 _hold_on_cb(void *data __UNUSED__,
100 void *event_info __UNUSED__)
102 ELM_CTXPOPUP_DATA_GET(obj, sd);
104 if ((!sd) || (!sd->scr)) return;
105 elm_object_scroll_hold_push(sd->scr);
109 _hold_off_cb(void *data __UNUSED__,
111 void *event_info __UNUSED__)
113 ELM_CTXPOPUP_DATA_GET(obj, sd);
115 if ((!sd) || (!sd->scr)) return;
116 elm_object_scroll_hold_pop(sd->scr);
120 _x_pos_adjust(Evas_Coord_Point *pos,
121 Evas_Coord_Point *base_size,
122 Evas_Coord_Rectangle *hover_area)
124 pos->x -= (base_size->x / 2);
126 if (pos->x < hover_area->x)
127 pos->x = hover_area->x;
128 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
129 pos->x = (hover_area->x + hover_area->w) - base_size->x;
131 if (base_size->x > hover_area->w)
132 base_size->x -= (base_size->x - hover_area->w);
134 if (pos->x < hover_area->x)
135 pos->x = hover_area->x;
139 _y_pos_adjust(Evas_Coord_Point *pos,
140 Evas_Coord_Point *base_size,
141 Evas_Coord_Rectangle *hover_area)
143 pos->y -= (base_size->y / 2);
145 if (pos->y < hover_area->y)
146 pos->y = hover_area->y;
147 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
148 pos->y = hover_area->y + hover_area->h - base_size->y;
150 if (base_size->y > hover_area->h)
151 base_size->y -= (base_size->y - hover_area->h);
153 if (pos->y < hover_area->y)
154 pos->y = hover_area->y;
158 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
159 const char *emission __UNUSED__,
160 const char *source __UNUSED__)
162 Elm_Ctxpopup_Item *item = data;
165 if (elm_widget_item_disabled_get(item)) return;
168 item->func((void*)item->base.data, WIDGET(item), data);
172 _access_info_cb(void *data, Evas_Object *obj __UNUSED__)
174 Elm_Ctxpopup_Item *it = (Elm_Ctxpopup_Item *)data;
175 const char *txt = NULL;
176 Evas_Object *icon = NULL;
177 Eina_Strbuf *buf = NULL;
180 if (!it) return NULL;
182 if ((!txt) && (!icon))
187 else if (!txt) txt = it->label;
188 else if (!icon) icon = it->icon;
192 buf = eina_strbuf_new();
193 eina_strbuf_append(buf, E_("icon "));
194 eina_strbuf_append(buf, txt);
195 str = eina_strbuf_string_steal(buf);
196 eina_strbuf_free(buf);
199 else if ((!txt) && icon) return strdup(E_("icon"));
200 else if (txt && (!icon)) return strdup(txt);
206 _access_state_cb(void *data, Evas_Object *obj __UNUSED__)
208 Elm_Ctxpopup_Item *it = (Elm_Ctxpopup_Item *)data;
209 if (!it) return NULL;
211 if (it->base.disabled)
212 return strdup(E_("State: Disabled"));
218 _access_activate_cb(void *data __UNUSED__,
219 Evas_Object *part_obj __UNUSED__,
220 Elm_Object_Item *item)
222 _item_select_cb(item, NULL, NULL, NULL);
226 _access_widget_item_register(Elm_Ctxpopup_Item *it, Eina_Bool is_access)
230 if (!is_access) _elm_access_widget_item_unregister((Elm_Widget_Item *)it);
233 _elm_access_widget_item_register((Elm_Widget_Item *)it);
235 ai = _elm_access_object_get(it->base.access_obj);
237 _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, it);
238 _elm_access_callback_set(ai, ELM_ACCESS_STATE, _access_state_cb, it);
239 _elm_access_text_set(ai, ELM_ACCESS_TYPE, E_("Contextual Popup"));
240 _elm_access_activate_callback_set(ai, _access_activate_cb, it);
245 _item_new(Elm_Ctxpopup_Item *item,
248 ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
251 VIEW(item) = edje_object_add(evas_object_evas_get(sd->box));
252 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
253 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
254 elm_widget_style_get(WIDGET(item)));
255 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
256 _item_select_cb, item);
257 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
258 evas_object_show(VIEW(item));
261 if (_elm_config->access_mode) _access_widget_item_register(item, EINA_TRUE);
265 _item_icon_set(Elm_Ctxpopup_Item *item,
269 evas_object_del(item->icon);
274 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
275 edje_object_message_signal_process(VIEW(item));
279 _item_label_set(Elm_Ctxpopup_Item *item,
282 if (!eina_stringshare_replace(&item->label, label))
285 edje_object_part_text_set(VIEW(item), "elm.text", label);
286 edje_object_message_signal_process(VIEW(item));
290 _item_del_pre_hook(Elm_Object_Item *it)
292 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
294 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
295 if (!sd) return EINA_FALSE;
297 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
299 if (ctxpopup_it->icon)
300 evas_object_del(ctxpopup_it->icon);
301 if (VIEW(ctxpopup_it))
302 evas_object_del(VIEW(ctxpopup_it));
304 eina_stringshare_del(ctxpopup_it->label);
305 sd->items = eina_list_remove(sd->items, ctxpopup_it);
307 if (eina_list_count(sd->items) < 1)
309 evas_object_hide(WIDGET(ctxpopup_it));
312 if (sd->visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
318 _items_remove(Elm_Ctxpopup_Smart_Data *sd)
321 Elm_Ctxpopup_Item *item;
323 if (!sd->items) return;
325 EINA_LIST_FOREACH(sd->items, elist, item)
327 _item_del_pre_hook((Elm_Object_Item *)item);
334 _scroller_size_reset(Elm_Ctxpopup_Smart_Data *sd)
336 sd->finished = EINA_FALSE;
342 _item_sizing_eval(Elm_Ctxpopup_Item *item)
344 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
348 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
350 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
351 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
354 static Elm_Ctxpopup_Direction
355 _base_geometry_calc(Evas_Object *obj,
356 Evas_Coord_Rectangle *rect)
358 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
359 Evas_Coord_Rectangle hover_area;
360 Evas_Coord_Point pos = {0, 0};
361 Evas_Coord_Point arrow_size;
362 Evas_Coord_Point base_size;
363 Evas_Coord_Point max_size;
364 Evas_Coord_Point min_size;
365 Evas_Coord_Point temp;
368 ELM_CTXPOPUP_DATA_GET(obj, sd);
370 if (!rect) return ELM_CTXPOPUP_DIRECTION_DOWN;
372 edje_object_part_geometry_get
373 (sd->arrow, "ctxpopup_arrow", NULL, NULL, &arrow_size.x, &arrow_size.y);
374 evas_object_resize(sd->arrow, arrow_size.x, arrow_size.y);
376 //Initialize Area Rectangle.
377 evas_object_geometry_get
378 (sd->parent, &hover_area.x, &hover_area.y, &hover_area.w,
381 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
384 edje_object_size_min_calc
385 (ELM_WIDGET_DATA(sd)->resize_obj, &base_size.x, &base_size.y);
386 evas_object_smart_calculate(ELM_WIDGET_DATA(sd)->resize_obj);
389 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
390 if ((max_size.x == -1) || (max_size.y == -1))
391 edje_object_size_max_get(sd->layout, &max_size.x, &max_size.y);
393 if ((max_size.y > 0) && (base_size.y > max_size.y))
394 base_size.y = max_size.y;
396 if ((max_size.x > 0) && (base_size.x > max_size.x))
397 base_size.x = max_size.x;
400 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
401 if ((min_size.x == 0) || (min_size.y == 0))
402 edje_object_size_min_get(sd->layout, &min_size.x, &min_size.y);
404 if ((min_size.y > 0) && (base_size.y < min_size.y))
405 base_size.y = min_size.y;
407 if ((min_size.x > 0) && (base_size.x < min_size.x))
408 base_size.x = min_size.x;
410 //Check the Which direction is available.
411 //If find a avaialble direction, it adjusts position and size.
412 for (idx = 0; idx < 4; idx++)
414 switch (sd->dir_priority[idx])
416 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
418 case ELM_CTXPOPUP_DIRECTION_UP:
419 temp.y = (pos.y - base_size.y);
420 if ((temp.y - arrow_size.y) < hover_area.y)
423 _x_pos_adjust(&pos, &base_size, &hover_area);
424 pos.y -= base_size.y;
425 dir = ELM_CTXPOPUP_DIRECTION_UP;
428 case ELM_CTXPOPUP_DIRECTION_LEFT:
429 temp.x = (pos.x - base_size.x);
430 if ((temp.x - arrow_size.x) < hover_area.x)
433 _y_pos_adjust(&pos, &base_size, &hover_area);
434 pos.x -= base_size.x;
435 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
438 case ELM_CTXPOPUP_DIRECTION_RIGHT:
439 temp.x = (pos.x + base_size.x);
440 if ((temp.x + arrow_size.x) >
441 (hover_area.x + hover_area.w))
444 _y_pos_adjust(&pos, &base_size, &hover_area);
445 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
448 case ELM_CTXPOPUP_DIRECTION_DOWN:
449 temp.y = (pos.y + base_size.y);
450 if ((temp.y + arrow_size.y) >
451 (hover_area.y + hover_area.h))
454 _x_pos_adjust(&pos, &base_size, &hover_area);
455 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
464 //In this case, all directions are invalid because of lack of space.
467 Evas_Coord length[2];
471 length[0] = pos.y - hover_area.y;
472 length[1] = (hover_area.y + hover_area.h) - pos.y;
474 // ELM_CTXPOPUP_DIRECTION_UP
475 if (length[0] > length[1])
477 _x_pos_adjust(&pos, &base_size, &hover_area);
478 pos.y -= base_size.y;
479 dir = ELM_CTXPOPUP_DIRECTION_UP;
480 if (pos.y < (hover_area.y + arrow_size.y))
482 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
483 pos.y = hover_area.y + arrow_size.y;
486 //ELM_CTXPOPUP_DIRECTION_DOWN
489 _x_pos_adjust(&pos, &base_size, &hover_area);
490 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
491 if ((pos.y + arrow_size.y + base_size.y) >
492 (hover_area.y + hover_area.h))
494 ((pos.y + arrow_size.y + base_size.y) -
495 (hover_area.y + hover_area.h));
500 length[0] = pos.x - hover_area.x;
501 length[1] = (hover_area.x + hover_area.w) - pos.x;
503 //ELM_CTXPOPUP_DIRECTION_LEFT
504 if (length[0] > length[1])
506 _y_pos_adjust(&pos, &base_size, &hover_area);
507 pos.x -= base_size.x;
508 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
509 if (pos.x < (hover_area.x + arrow_size.x))
511 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
512 pos.x = hover_area.x + arrow_size.x;
515 //ELM_CTXPOPUP_DIRECTION_RIGHT
518 _y_pos_adjust(&pos, &base_size, &hover_area);
519 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
520 if (pos.x + (arrow_size.x + base_size.x) >
521 hover_area.x + hover_area.w)
523 ((pos.x + arrow_size.x + base_size.x) -
524 (hover_area.x + hover_area.w));
529 //Final position and size.
532 rect->w = base_size.x;
533 rect->h = base_size.y;
539 _arrow_update(Evas_Object *obj,
540 Elm_Ctxpopup_Direction dir,
541 Evas_Coord_Rectangle base_size)
543 Evas_Coord_Rectangle arrow_size;
546 Evas_Coord_Rectangle shadow_left_top, shadow_right_bottom, arrow_padding;
548 ELM_CTXPOPUP_DATA_GET(obj, sd);
550 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
551 evas_object_geometry_get
552 (sd->arrow, NULL, NULL, &arrow_size.w, &arrow_size.h);
554 /* tizen only : since ctxpopup of tizen has shadow, start and end padding of arrow, it should be put together when updating arrow
555 * so there are some differences between open source and tizen */
556 edje_object_part_geometry_get(ELM_WIDGET_DATA(sd)->resize_obj, "frame_shadow_left_top_padding", NULL, NULL, &shadow_left_top.w, &shadow_left_top.h);
557 edje_object_part_geometry_get(ELM_WIDGET_DATA(sd)->resize_obj, "frame_shadow_right_bottom_padding", NULL, NULL, &shadow_right_bottom.w, &shadow_right_bottom.h);
558 edje_object_part_geometry_get(ELM_WIDGET_DATA(sd)->resize_obj, "ctxpopup_frame_left_top", NULL, NULL, &arrow_padding.w, &arrow_padding.h);
560 /* arrow is not being kept as sub-object on purpose, here. the
561 * design of the widget does not help with the contrary */
565 case ELM_CTXPOPUP_DIRECTION_RIGHT:
566 edje_object_signal_emit(sd->arrow, "elm,state,left", "elm");
567 edje_object_part_swallow
568 (ELM_WIDGET_DATA(sd)->resize_obj,
569 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_right" :
570 "elm.swallow.arrow_left"), sd->arrow);
574 if (y <= ((arrow_size.h * 0.5) + base_size.y + shadow_left_top.h + arrow_padding.h))
576 else if (y >= (base_size.y + base_size.h - ((arrow_size.h * 0.5) + shadow_right_bottom.h + arrow_padding.h)))
577 y = base_size.h - (arrow_size.h + shadow_right_bottom.h + shadow_left_top.h + (arrow_padding.h * 2));
579 y = y - base_size.y - ((arrow_size.h * 0.5) + shadow_left_top.h + arrow_padding.h);
580 drag = (double)(y) / (double)(base_size.h - (arrow_size.h + shadow_right_bottom.h + shadow_left_top.h + (arrow_padding.h * 2)));
581 edje_object_part_drag_value_set
582 (ELM_WIDGET_DATA(sd)->resize_obj,
583 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_right" :
584 "elm.swallow.arrow_left"), 1, drag);
588 case ELM_CTXPOPUP_DIRECTION_LEFT:
589 edje_object_signal_emit(sd->arrow, "elm,state,right", "elm");
590 edje_object_part_swallow
591 (ELM_WIDGET_DATA(sd)->resize_obj,
592 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_left" :
593 "elm.swallow.arrow_right"), sd->arrow);
597 if (y <= ((arrow_size.h * 0.5) + base_size.y + shadow_left_top.h + arrow_padding.h))
599 else if (y >= (base_size.y + base_size.h - ((arrow_size.h * 0.5) + shadow_right_bottom.h + arrow_padding.h)))
600 y = base_size.h - (arrow_size.h + shadow_right_bottom.h + shadow_left_top.h + (arrow_padding.h * 2));
602 y = y - base_size.y - ((arrow_size.h * 0.5) + shadow_left_top.h + arrow_padding.h);
603 drag = (double)(y) / (double)(base_size.h - (arrow_size.h + shadow_right_bottom.h + shadow_left_top.h + (arrow_padding.h * 2)));
604 edje_object_part_drag_value_set
605 (ELM_WIDGET_DATA(sd)->resize_obj,
606 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_left" :
607 "elm.swallow.arrow_right"), 0, drag);
611 case ELM_CTXPOPUP_DIRECTION_DOWN:
612 edje_object_signal_emit(sd->arrow, "elm,state,top", "elm");
613 edje_object_part_swallow
614 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up",
619 if (x <= ((arrow_size.w * 0.5) + base_size.x + shadow_left_top.w + arrow_padding.w))
621 else if (x >= (base_size.x + base_size.w - ((arrow_size.w * 0.5) + shadow_right_bottom.w + arrow_padding.w)))
622 x = base_size.w - (arrow_size.w + shadow_right_bottom.w + shadow_left_top.w + (arrow_padding.w * 2));
624 x = x - base_size.x - ((arrow_size.w * 0.5) + shadow_left_top.w + arrow_padding.w);
625 drag = (double)(x) / (double)(base_size.w - (arrow_size.w + shadow_right_bottom.w + shadow_left_top.w + (arrow_padding.w * 2)));
626 edje_object_part_drag_value_set
627 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up",
632 case ELM_CTXPOPUP_DIRECTION_UP:
633 edje_object_signal_emit(sd->arrow, "elm,state,bottom", "elm");
634 edje_object_part_swallow
635 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
640 if (x <= ((arrow_size.w * 0.5) + base_size.x + shadow_left_top.w + arrow_padding.w))
642 else if (x >= (base_size.x + base_size.w - ((arrow_size.w * 0.5) + shadow_right_bottom.w + arrow_padding.w)))
643 x = base_size.w - (arrow_size.w + shadow_right_bottom.w + shadow_left_top.w + (arrow_padding.w * 2));
645 x = x - base_size.x - ((arrow_size.w * 0.5) + shadow_left_top.w + arrow_padding.w);
646 drag = (double)(x) / (double)(base_size.w - (arrow_size.w + shadow_right_bottom.w + shadow_left_top.w + (arrow_padding.w * 2)));
647 edje_object_part_drag_value_set
648 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
657 //should be here for getting accurate geometry value
658 evas_object_smart_calculate(ELM_WIDGET_DATA(sd)->resize_obj);
662 _show_signals_emit(Evas_Object *obj,
663 Elm_Ctxpopup_Direction dir)
665 ELM_CTXPOPUP_DATA_GET(obj, sd);
667 if (!sd->visible) return;
671 case ELM_CTXPOPUP_DIRECTION_UP:
672 edje_object_signal_emit(sd->layout, "elm,state,show,up", "elm");
675 case ELM_CTXPOPUP_DIRECTION_LEFT:
676 edje_object_signal_emit(sd->layout, (elm_widget_mirrored_get(obj) ? "elm,state,show,right" :
677 "elm,state,show,left"), "elm");
680 case ELM_CTXPOPUP_DIRECTION_RIGHT:
681 edje_object_signal_emit(sd->layout, (elm_widget_mirrored_get(obj) ? "elm,state,show,left" :
682 "elm,state,show,right"), "elm");
685 case ELM_CTXPOPUP_DIRECTION_DOWN:
686 edje_object_signal_emit(sd->layout, "elm,state,show,down", "elm");
693 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
694 // elm_layout_signal_emit(obj, "elm,state,show", "elm");
698 _hide_signals_emit(Evas_Object *obj,
699 Elm_Ctxpopup_Direction dir)
701 ELM_CTXPOPUP_DATA_GET(obj, sd);
703 if (!sd->visible) return;
707 case ELM_CTXPOPUP_DIRECTION_UP:
708 edje_object_signal_emit(sd->layout, "elm,state,hide,up", "elm");
711 case ELM_CTXPOPUP_DIRECTION_LEFT:
712 edje_object_signal_emit(sd->layout, (elm_widget_mirrored_get(obj) ? "elm,state,hide,right" :
713 "elm,state,hide,left"), "elm");
716 case ELM_CTXPOPUP_DIRECTION_RIGHT:
717 edje_object_signal_emit(sd->layout, (elm_widget_mirrored_get(obj) ? "elm,state,hide,left" :
718 "elm,state,hide,right"), "elm");
721 case ELM_CTXPOPUP_DIRECTION_DOWN:
722 edje_object_signal_emit(sd->layout, "elm,state,hide,down", "elm");
729 edje_object_signal_emit(sd->bg, "elm,state,hide", "elm");
733 _base_shift_by_arrow(Evas_Object *arrow,
734 Elm_Ctxpopup_Direction dir,
735 Evas_Coord_Rectangle *rect)
737 Evas_Coord arrow_w, arrow_h;
739 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
743 case ELM_CTXPOPUP_DIRECTION_RIGHT:
747 case ELM_CTXPOPUP_DIRECTION_LEFT:
751 case ELM_CTXPOPUP_DIRECTION_DOWN:
755 case ELM_CTXPOPUP_DIRECTION_UP:
764 //TODO: compress item - different from opensource
766 _compress_item(Evas_Object *obj)
769 Elm_Ctxpopup_Item *item;
771 ELM_CTXPOPUP_DATA_GET(obj, sd);
774 EINA_LIST_FOREACH(sd->items, elist, item)
776 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
781 _elm_ctxpopup_smart_sub_object_add(Evas_Object *obj,
784 Elm_Widget_Smart_Class *parent_parent;
786 parent_parent = (Elm_Widget_Smart_Class *)((Evas_Smart_Class *)
787 _elm_ctxpopup_parent_sc)->parent;
789 /* skipping layout's code, which registers size hint changing
790 * callback on sub objects. a hack to make ctxpopup live, as it is,
791 * on the new classing schema. this widget needs a total
793 if (!parent_parent->sub_object_add(obj, sobj))
800 _elm_ctxpopup_smart_sizing_eval(Evas_Object *obj)
803 Elm_Ctxpopup_Item *item;
804 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
805 Evas_Coord_Point box_size = { 0, 0 };
806 Evas_Coord_Point _box_size = { 0, 0 };
808 ELM_CTXPOPUP_DATA_GET(obj, sd);
811 EINA_LIST_FOREACH(sd->items, elist, item)
813 _item_sizing_eval(item);
814 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
817 if (_box_size.x > box_size.x)
818 box_size.x = _box_size.x;
819 if (_box_size.y != -1)
820 box_size.y += _box_size.y;
824 if (_box_size.x != -1)
825 box_size.x += _box_size.x;
826 if (_box_size.y > box_size.y)
827 box_size.y = _box_size.y;
831 if (!sd->arrow) return; /* simple way to flag "under deletion" */
833 if ((!sd->content) && (sd->scr))
835 evas_object_size_hint_min_set(sd->box, box_size.x, box_size.y);
836 elm_scroller_content_min_limit(sd->scr, EINA_TRUE, EINA_TRUE);
837 evas_object_size_hint_min_set(sd->scr, box_size.x, box_size.y);
841 sd->dir = _base_geometry_calc(obj, &rect);
843 //TODO: compress item - different from opensource
844 if (!sd->horizontal && !sd->content)
847 _arrow_update(obj, sd->dir, rect);
848 _base_shift_by_arrow(sd->arrow, sd->dir, &rect);
850 //resize scroller according to final size
851 if ((!sd->content) && (sd->scr))
853 elm_scroller_content_min_limit(sd->scr, EINA_FALSE, EINA_FALSE);
854 evas_object_smart_calculate(sd->scr);
857 evas_object_size_hint_min_set(ELM_WIDGET_DATA(sd)->resize_obj, rect.w, rect.h);
858 evas_object_resize(ELM_WIDGET_DATA(sd)->resize_obj, rect.w, rect.h);
860 evas_object_move(sd->layout, rect.x, rect.y);
861 evas_object_resize(sd->layout, rect.w, rect.h);
863 _show_signals_emit(obj, sd->dir);
867 _on_parent_del(void *data,
869 Evas_Object *obj __UNUSED__,
870 void *event_info __UNUSED__)
872 evas_object_del(data);
876 _on_parent_move(void *data,
878 Evas_Object *obj __UNUSED__,
879 void *event_info __UNUSED__)
881 ELM_CTXPOPUP_DATA_GET(data, sd);
884 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
888 _scroller_size_reset(sd);
889 elm_layout_sizing_eval(data);
894 _on_parent_resize(void *data,
896 Evas_Object *obj __UNUSED__,
897 void *event_info __UNUSED__)
899 ELM_CTXPOPUP_DATA_GET(data, sd);
901 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
903 evas_object_hide(data);
904 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
908 _parent_detach(Evas_Object *obj)
910 ELM_CTXPOPUP_DATA_GET(obj, sd);
912 if (!sd->parent) return;
914 evas_object_event_callback_del_full
915 (sd->parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
916 evas_object_event_callback_del_full
917 (sd->parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
918 evas_object_event_callback_del_full
919 (sd->parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
923 _on_content_resized(void *data,
925 Evas_Object *obj __UNUSED__,
926 void *event_info __UNUSED__)
928 ELM_CTXPOPUP_DATA_GET(data, sd);
930 elm_box_recalculate(sd->box);
931 elm_layout_sizing_eval(data);
934 //FIXME: lost the content size when theme hook is called.
936 _elm_ctxpopup_smart_theme(Evas_Object *obj)
939 Elm_Ctxpopup_Item *item;
943 ELM_CTXPOPUP_DATA_GET(obj, sd);
945 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->theme(obj))
948 rtl = elm_widget_mirrored_get(obj);
950 elm_widget_theme_object_set
951 (obj, sd->bg, "ctxpopup", "bg", elm_widget_style_get(obj));
952 elm_widget_theme_object_set
953 (obj, sd->arrow, "ctxpopup", "arrow", elm_widget_style_get(obj));
954 elm_widget_theme_object_set
955 (obj, sd->layout, "ctxpopup", "layout", elm_widget_style_get(obj));
958 EINA_LIST_FOREACH(sd->items, elist, item)
960 edje_object_mirrored_set(VIEW(item), rtl);
962 if (item->label && item->icon)
963 _elm_theme_object_set
964 (obj, VIEW(item), "ctxpopup", "icon_text_style_item", elm_widget_style_get(obj));
965 else if (item->label)
968 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
969 elm_widget_style_get(obj));
971 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item_horizontal",
972 elm_widget_style_get(obj));
975 _elm_theme_object_set
976 (obj, VIEW(item), "ctxpopup", "icon_style_item", elm_widget_style_get(obj));
978 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
980 if (elm_widget_item_disabled_get(item))
981 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
984 * For separator, if the first item has visible separator,
985 * then it should be aligned with edge of the base part.
986 * In some cases, it gives improper display. Ex) rounded corner
987 * So the first item separator should be invisible.
990 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
992 edje_object_signal_emit(VIEW(item), "elm,state,separator", "elm");
994 edje_object_message_signal_process(VIEW(item));
997 if (evas_object_visible_get(sd->bg))
998 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
1002 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
1003 elm_object_style_set(sd->scr, "ctxpopup");
1005 elm_object_style_set(sd->scr, elm_object_style_get(obj));
1008 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1012 _scroller_size_reset(sd);
1013 _elm_ctxpopup_smart_sizing_eval(obj);
1019 /* kind of a big and tricky override here: an internal box will hold
1020 * the actual content. content aliases won't be of much help here */
1022 _elm_ctxpopup_smart_content_set(Evas_Object *obj,
1024 Evas_Object *content)
1026 Evas_Coord min_w = -1, min_h = -1;
1028 ELM_CTXPOPUP_DATA_GET(obj, sd);
1030 if ((part) && (strcmp(part, "default")))
1031 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1032 (obj, part, content);
1034 if (!content) return EINA_FALSE;
1036 if (content == sd->content) return EINA_TRUE;
1038 if (sd->items) elm_ctxpopup_clear(obj);
1039 if (sd->content) evas_object_del(sd->content);
1044 sd->box = elm_box_add(obj);
1045 evas_object_size_hint_weight_set(sd->box, EVAS_HINT_EXPAND,
1047 evas_object_event_callback_add
1048 (sd->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1049 ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1050 (obj, "elm.swallow.content", sd->box);
1053 evas_object_size_hint_weight_set
1054 (content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1055 evas_object_size_hint_fill_set
1056 (content, EVAS_HINT_FILL, EVAS_HINT_FILL);
1058 /* since it's going to be a box content, not a layout's... */
1059 evas_object_show(content);
1061 evas_object_size_hint_min_get(content, &min_w, &min_h);
1062 evas_object_size_hint_min_set(sd->box, min_w, min_h);
1063 elm_box_pack_end(sd->box, content);
1065 sd->content = content;
1066 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1068 if (sd->visible) elm_layout_sizing_eval(obj);
1073 static Evas_Object *
1074 _elm_ctxpopup_smart_content_get(const Evas_Object *obj,
1077 ELM_CTXPOPUP_DATA_GET(obj, sd);
1079 if ((part) && (strcmp(part, "default")))
1080 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_get
1086 static Evas_Object *
1087 _elm_ctxpopup_smart_content_unset(Evas_Object *obj,
1090 Evas_Object *content;
1092 ELM_CTXPOPUP_DATA_GET(obj, sd);
1094 if ((part) && (strcmp(part, "default")))
1095 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_unset
1098 content = sd->content;
1099 if (!content) return NULL;
1101 evas_object_del(sd->box);
1104 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1106 if (sd->visible) elm_layout_sizing_eval(obj);
1112 _item_text_set_hook(Elm_Object_Item *it,
1116 Elm_Ctxpopup_Item *ctxpopup_it;
1118 if ((part) && (strcmp(part, "default"))) return;
1120 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1122 _item_label_set(ctxpopup_it, label);
1126 _item_text_get_hook(const Elm_Object_Item *it,
1129 Elm_Ctxpopup_Item *ctxpopup_it;
1131 if (part && strcmp(part, "default")) return NULL;
1133 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1134 return ctxpopup_it->label;
1138 _item_content_set_hook(Elm_Object_Item *it,
1140 Evas_Object *content)
1142 Elm_Ctxpopup_Item *ctxpopup_it;
1144 if ((part) && (strcmp(part, "icon"))) return;
1146 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1148 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
1150 _item_icon_set(ctxpopup_it, content);
1151 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1155 _scroller_size_reset(sd);
1156 _elm_ctxpopup_smart_sizing_eval(WIDGET(ctxpopup_it));
1160 static Evas_Object *
1161 _item_content_get_hook(const Elm_Object_Item *it,
1164 Elm_Ctxpopup_Item *ctxpopup_it;
1166 if (part && strcmp(part, "icon")) return NULL;
1168 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1169 return ctxpopup_it->icon;
1173 _item_disable_hook(Elm_Object_Item *it)
1175 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1177 ELM_CTXPOPUP_DATA_GET(WIDGET(it), sd);
1180 if (elm_widget_item_disabled_get(it))
1181 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1183 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1187 _item_signal_emit_hook(Elm_Object_Item *it,
1188 const char *emission,
1191 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1193 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1197 _bg_clicked_cb(void *data,
1198 Evas_Object *obj __UNUSED__,
1199 const char *emission __UNUSED__,
1200 const char *source __UNUSED__)
1202 ELM_CTXPOPUP_DATA_GET(data, sd);
1204 _hide_signals_emit(data, sd->dir);
1208 _on_show(void *data __UNUSED__,
1211 void *event_info __UNUSED__)
1214 Elm_Ctxpopup_Item *item;
1217 ELM_CTXPOPUP_DATA_GET(obj, sd);
1219 if ((!sd->items) && (!sd->content)) return;
1221 sd->visible = EINA_TRUE;
1223 evas_object_show(sd->bg);
1224 evas_object_show(sd->arrow);
1225 evas_object_show(sd->layout);
1227 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
1228 elm_layout_signal_emit(obj, "elm,state,show", "elm");
1230 EINA_LIST_FOREACH(sd->items, elist, item)
1232 if (item->label && !item->icon)
1235 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
1236 elm_widget_style_get(obj));
1238 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item_horizontal",
1239 elm_widget_style_get(obj));
1243 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1245 edje_object_signal_emit(VIEW(item), "elm,state,separator", "elm");
1248 elm_layout_sizing_eval(obj);
1250 elm_object_focus_set(obj, EINA_TRUE);
1254 _on_hide(void *data __UNUSED__,
1257 void *event_info __UNUSED__)
1259 ELM_CTXPOPUP_DATA_GET(obj, sd);
1261 if (!sd->visible) return;
1263 evas_object_hide(sd->bg);
1264 evas_object_hide(sd->arrow);
1265 evas_object_hide(sd->layout);
1267 _scroller_size_reset(sd);
1269 sd->visible = EINA_FALSE;
1273 _on_move(void *data __UNUSED__,
1276 void *event_info __UNUSED__)
1278 ELM_CTXPOPUP_DATA_GET(obj, sd);
1280 if (sd->visible) evas_object_show(sd->arrow);
1282 _scroller_size_reset(sd);
1283 _elm_ctxpopup_smart_sizing_eval(obj);
1287 _hide_finished_cb(void *data,
1288 Evas_Object *obj __UNUSED__,
1289 const char *emission __UNUSED__,
1290 const char *source __UNUSED__)
1292 evas_object_hide(data);
1293 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
1297 _scroller_resize(void *data, Evas *e __UNUSED__,
1299 void *event_info __UNUSED__)
1303 ELM_CTXPOPUP_DATA_GET(data, sd);
1305 if (!sd->visible) return;
1306 if (sd->finished) return;
1308 evas_object_geometry_get(obj, 0, 0, &w, &h);
1310 if (w != 0 && h != 0)
1312 if ((w <= sd->max_sc_w) && (h <= sd->max_sc_h))
1314 _elm_ctxpopup_smart_sizing_eval(data);
1315 sd->finished = EINA_TRUE;
1320 if (sd->max_sc_w < w)
1322 if (sd->max_sc_h < h)
1325 _elm_ctxpopup_smart_sizing_eval(data);
1329 _ctxpopup_restack_cb(void *data __UNUSED__,
1332 void *event_info __UNUSED__)
1334 ELM_CTXPOPUP_DATA_GET(obj, sd);
1335 evas_object_stack_below(sd->bg, obj);
1336 evas_object_stack_below(sd->layout, obj);
1340 _list_del(Elm_Ctxpopup_Smart_Data *sd)
1342 if (!sd->scr) return;
1344 edje_object_part_unswallow(ELM_WIDGET_DATA(sd)->resize_obj, sd->scr);
1345 evas_object_del(sd->scr);
1347 evas_object_del(sd->box);
1352 _list_new(Evas_Object *obj)
1354 ELM_CTXPOPUP_DATA_GET(obj, sd);
1358 sd->scr = elm_scroller_add(obj);
1359 elm_object_style_set(sd->scr, "ctxpopup");
1360 evas_object_size_hint_align_set(sd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1361 evas_object_event_callback_add(sd->scr, EVAS_CALLBACK_RESIZE,
1362 _scroller_resize, obj);
1363 edje_object_part_swallow(ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.content", sd->scr);
1368 sd->box = elm_box_add(obj);
1369 evas_object_size_hint_weight_set(sd->box, EVAS_HINT_EXPAND,
1371 evas_object_event_callback_add
1372 (sd->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1373 ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1374 (obj, "elm.swallow.content", sd->box);
1377 elm_object_content_set(sd->scr, sd->box);
1378 elm_ctxpopup_horizontal_set(obj, sd->horizontal);
1382 _elm_ctxpopup_smart_disable(Evas_Object *obj)
1385 Elm_Object_Item *it;
1387 ELM_CTXPOPUP_DATA_GET(obj, sd);
1389 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->disable(obj))
1392 EINA_LIST_FOREACH(sd->items, l, it)
1393 elm_object_item_disabled_set(it, elm_widget_disabled_get(obj));
1399 _elm_ctxpopup_smart_add(Evas_Object *obj)
1401 EVAS_SMART_DATA_ALLOC(obj, Elm_Ctxpopup_Smart_Data);
1402 ELM_CTXPOPUP_DATA_GET(obj, sd);
1404 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.add(obj);
1406 elm_layout_theme_set(obj, "ctxpopup", "base", elm_widget_style_get(obj));
1407 elm_layout_signal_callback_add
1408 (obj, "elm,action,hide,finished", "", _hide_finished_cb, obj);
1411 priv->bg = edje_object_add(evas_object_evas_get(obj));
1412 elm_widget_theme_object_set(obj, priv->bg, "ctxpopup", "bg", "default");
1413 edje_object_signal_callback_add
1414 (priv->bg, "elm,action,click", "", _bg_clicked_cb, obj);
1416 evas_object_stack_below(priv->bg, obj);
1419 priv->arrow = edje_object_add(evas_object_evas_get(obj));
1420 elm_widget_theme_object_set
1421 (obj, priv->arrow, "ctxpopup", "arrow", "default");
1423 priv->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1424 priv->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1425 priv->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1426 priv->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1427 priv->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1429 evas_object_event_callback_add
1430 (obj, EVAS_CALLBACK_RESTACK, _ctxpopup_restack_cb, obj);
1432 evas_object_smart_callback_add
1433 (obj, "scroll-freeze-on", _freeze_on_cb, obj);
1434 evas_object_smart_callback_add
1435 (obj, "scroll-freeze-off", _freeze_off_cb, obj);
1436 evas_object_smart_callback_add
1437 (obj, "scroll-hold-on", _hold_on_cb, obj);
1438 evas_object_smart_callback_add
1439 (obj, "scroll-hold-off", _hold_off_cb, obj);
1441 priv->box = elm_box_add(obj);
1442 evas_object_size_hint_weight_set
1443 (priv->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1445 evas_object_event_callback_add
1446 (priv->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1448 /* box will be our content placeholder, thus the parent's version call */
1449 ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1450 (obj, "elm.swallow.content", priv->box);
1452 priv->layout = edje_object_add(evas_object_evas_get(obj));
1453 elm_widget_theme_object_set(obj, priv->layout, "ctxpopup", "layout", "default");
1455 edje_object_signal_callback_add
1456 (priv->layout, "elm,action,hide,finished", "", _hide_finished_cb, obj);
1457 edje_object_part_swallow(priv->layout, "swallow", ELM_WIDGET_DATA(sd)->resize_obj);
1458 evas_object_size_hint_weight_set
1459 (priv->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1461 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _on_show, NULL);
1462 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _on_hide, NULL);
1463 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _on_move, NULL);
1465 elm_widget_can_focus_set(obj, EINA_TRUE);
1469 _elm_ctxpopup_smart_del(Evas_Object *obj)
1471 ELM_CTXPOPUP_DATA_GET(obj, sd);
1473 evas_object_event_callback_del_full
1474 (sd->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1475 _parent_detach(obj);
1477 elm_ctxpopup_clear(obj);
1478 evas_object_del(sd->arrow);
1479 sd->arrow = NULL; /* stops _sizing_eval() from going on on deletion */
1481 evas_object_del(sd->bg);
1484 evas_object_del(sd->layout);
1487 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.del(obj);
1491 _elm_ctxpopup_smart_parent_set(Evas_Object *obj,
1492 Evas_Object *parent)
1494 //default parent is to be hover parent
1495 elm_ctxpopup_hover_parent_set(obj, parent);
1499 _elm_ctxpopup_smart_access(Evas_Object *obj, Eina_Bool is_access)
1501 Eina_List *elist = NULL;
1502 Elm_Ctxpopup_Item *it;
1504 ELM_CTXPOPUP_CHECK(obj);
1505 ELM_CTXPOPUP_DATA_GET(obj, sd);
1507 EINA_LIST_FOREACH(sd->items, elist, it)
1508 _access_widget_item_register(it, is_access);
1512 _elm_ctxpopup_smart_set_user(Elm_Ctxpopup_Smart_Class *sc)
1514 ELM_WIDGET_CLASS(sc)->base.add = _elm_ctxpopup_smart_add;
1515 ELM_WIDGET_CLASS(sc)->base.del = _elm_ctxpopup_smart_del;
1517 ELM_WIDGET_CLASS(sc)->parent_set = _elm_ctxpopup_smart_parent_set;
1518 ELM_WIDGET_CLASS(sc)->disable = _elm_ctxpopup_smart_disable;
1519 ELM_WIDGET_CLASS(sc)->event = _elm_ctxpopup_smart_event;
1520 ELM_WIDGET_CLASS(sc)->theme = _elm_ctxpopup_smart_theme;
1521 ELM_WIDGET_CLASS(sc)->sub_object_add = _elm_ctxpopup_smart_sub_object_add;
1522 ELM_WIDGET_CLASS(sc)->focus_next = _elm_ctxpopup_smart_focus_next;
1523 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
1525 ELM_CONTAINER_CLASS(sc)->content_get = _elm_ctxpopup_smart_content_get;
1526 ELM_CONTAINER_CLASS(sc)->content_set = _elm_ctxpopup_smart_content_set;
1527 ELM_CONTAINER_CLASS(sc)->content_unset = _elm_ctxpopup_smart_content_unset;
1529 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_ctxpopup_smart_sizing_eval;
1531 ELM_WIDGET_CLASS(sc)->access = _elm_ctxpopup_smart_access;
1534 EAPI const Elm_Ctxpopup_Smart_Class *
1535 elm_ctxpopup_smart_class_get(void)
1537 static Elm_Ctxpopup_Smart_Class _sc =
1538 ELM_CTXPOPUP_SMART_CLASS_INIT_NAME_VERSION(ELM_CTXPOPUP_SMART_NAME);
1539 static const Elm_Ctxpopup_Smart_Class *class = NULL;
1540 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
1545 _elm_ctxpopup_smart_set(&_sc);
1546 esc->callbacks = _smart_callbacks;
1553 elm_ctxpopup_add(Evas_Object *parent)
1557 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1559 obj = elm_widget_add(_elm_ctxpopup_smart_class_new(), parent);
1560 if (!obj) return NULL;
1562 if (!elm_widget_sub_object_add(parent, obj))
1563 ERR("could not add %p as sub object of %p", obj, parent);
1565 /* access: parent could be any object such as elm_list which does
1566 not know elc_ctxpopup as its child object in the focus_next(); */
1567 ELM_WIDGET_DATA_GET(obj, sd);
1568 sd->highlight_root = EINA_TRUE;
1574 elm_ctxpopup_hover_parent_set(Evas_Object *obj,
1575 Evas_Object *parent)
1577 Evas_Coord x, y, w, h;
1579 ELM_CTXPOPUP_CHECK(obj);
1580 ELM_CTXPOPUP_DATA_GET(obj, sd);
1582 if (!parent) return;
1584 _parent_detach(obj);
1586 evas_object_event_callback_add
1587 (parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
1588 evas_object_event_callback_add
1589 (parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
1590 evas_object_event_callback_add
1591 (parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
1593 sd->parent = parent;
1596 evas_object_geometry_get(parent, &x, &y, &w, &h);
1597 evas_object_move(sd->bg, x, y);
1598 evas_object_resize(sd->bg, w, h);
1600 if (sd->visible) elm_layout_sizing_eval(obj);
1604 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1606 ELM_CTXPOPUP_CHECK(obj) NULL;
1607 ELM_CTXPOPUP_DATA_GET(obj, sd);
1613 elm_ctxpopup_clear(Evas_Object *obj)
1615 ELM_CTXPOPUP_CHECK(obj);
1616 ELM_CTXPOPUP_DATA_GET(obj, sd);
1620 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1624 elm_ctxpopup_horizontal_set(Evas_Object *obj,
1625 Eina_Bool horizontal)
1628 Elm_Ctxpopup_Item *item;
1631 ELM_CTXPOPUP_CHECK(obj);
1632 ELM_CTXPOPUP_DATA_GET(obj, sd);
1634 sd->horizontal = !!horizontal;
1641 elm_box_horizontal_set(sd->box, EINA_FALSE);
1642 elm_scroller_bounce_set(sd->scr, EINA_FALSE, EINA_TRUE);
1646 elm_box_horizontal_set(sd->box, EINA_TRUE);
1647 elm_scroller_bounce_set(sd->scr, EINA_TRUE, EINA_FALSE);
1650 EINA_LIST_FOREACH(sd->items, elist, item)
1652 if (item->label && !item->icon && !horizontal)
1653 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
1654 elm_widget_style_get(obj));
1655 else if (item->label && !item->icon && horizontal)
1656 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item_horizontal",
1657 elm_widget_style_get(obj));
1660 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1662 edje_object_signal_emit(VIEW(item), "elm,state,separator", "elm");
1664 _item_disable_hook((Elm_Object_Item *)item);
1667 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1669 if (sd->visible) elm_layout_sizing_eval(obj);
1673 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1675 ELM_CTXPOPUP_CHECK(obj) EINA_FALSE;
1676 ELM_CTXPOPUP_DATA_GET(obj, sd);
1678 return sd->horizontal;
1681 EAPI Elm_Object_Item *
1682 elm_ctxpopup_item_append(Evas_Object *obj,
1688 Elm_Ctxpopup_Item *item;
1689 Evas_Object *content;
1691 ELM_CTXPOPUP_CHECK(obj) NULL;
1692 ELM_CTXPOPUP_DATA_GET(obj, sd);
1694 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1695 if (!item) return NULL;
1697 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1698 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1699 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1700 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1701 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1702 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1703 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1705 //The first item is appended.
1706 content = elm_object_content_unset(obj);
1707 if (content) evas_object_del(content);
1713 item->base.data = data;
1716 _item_new(item, "icon_text_style_item");
1719 if (!sd->horizontal)
1720 _item_new(item, "text_style_item");
1722 _item_new(item, "text_style_item_horizontal");
1725 _item_new(item, "icon_style_item");
1727 _item_icon_set(item, icon);
1728 _item_label_set(item, label);
1729 elm_box_pack_end(sd->box, VIEW(item));
1730 sd->items = eina_list_append(sd->items, item);
1732 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1736 _scroller_size_reset(sd);
1737 _elm_ctxpopup_smart_sizing_eval(obj);
1741 return (Elm_Object_Item *)item;
1745 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1746 Elm_Ctxpopup_Direction first,
1747 Elm_Ctxpopup_Direction second,
1748 Elm_Ctxpopup_Direction third,
1749 Elm_Ctxpopup_Direction fourth)
1751 ELM_CTXPOPUP_CHECK(obj);
1752 ELM_CTXPOPUP_DATA_GET(obj, sd);
1754 sd->dir_priority[0] = first;
1755 sd->dir_priority[1] = second;
1756 sd->dir_priority[2] = third;
1757 sd->dir_priority[3] = fourth;
1759 if (sd->visible) elm_layout_sizing_eval(obj);
1763 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1764 Elm_Ctxpopup_Direction *first,
1765 Elm_Ctxpopup_Direction *second,
1766 Elm_Ctxpopup_Direction *third,
1767 Elm_Ctxpopup_Direction *fourth)
1769 ELM_CTXPOPUP_CHECK(obj);
1770 ELM_CTXPOPUP_DATA_GET(obj, sd);
1772 if (first) *first = sd->dir_priority[0];
1773 if (second) *second = sd->dir_priority[1];
1774 if (third) *third = sd->dir_priority[2];
1775 if (fourth) *fourth = sd->dir_priority[3];
1778 EAPI Elm_Ctxpopup_Direction
1779 elm_ctxpopup_direction_get(const Evas_Object *obj)
1781 ELM_CTXPOPUP_CHECK(obj) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1782 ELM_CTXPOPUP_DATA_GET(obj, sd);
1788 elm_ctxpopup_dismiss(Evas_Object *obj)
1790 ELM_CTXPOPUP_CHECK(obj);
1791 ELM_CTXPOPUP_DATA_GET(obj, sd);
1793 _hide_signals_emit(obj, sd->dir);