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);
17 _elm_ctxpopup_smart_focus_next(const Evas_Object *obj,
18 Elm_Focus_Direction dir,
21 ELM_CTXPOPUP_DATA_GET(obj, sd);
26 if (!elm_widget_focus_next_get(sd->box, dir, next))
28 elm_widget_focused_object_clear(sd->box);
29 elm_widget_focus_next_get(sd->box, dir, next);
36 _elm_ctxpopup_smart_event(Evas_Object *obj,
37 Evas_Object *src __UNUSED__,
38 Evas_Callback_Type type,
41 Evas_Event_Key_Down *ev = event_info;
43 ELM_CTXPOPUP_DATA_GET(obj, sd);
45 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
46 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
47 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
49 if (!strcmp(ev->keyname, "Tab"))
51 if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
52 elm_widget_focus_cycle(sd->box, ELM_FOCUS_PREVIOUS);
54 elm_widget_focus_cycle(sd->box, ELM_FOCUS_NEXT);
58 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
60 evas_object_hide(obj);
61 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
66 _x_pos_adjust(Evas_Coord_Point *pos,
67 Evas_Coord_Point *base_size,
68 Evas_Coord_Rectangle *hover_area)
70 pos->x -= (base_size->x / 2);
72 if (pos->x < hover_area->x)
73 pos->x = hover_area->x;
74 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
75 pos->x = (hover_area->x + hover_area->w) - base_size->x;
77 if (base_size->x > hover_area->w)
78 base_size->x -= (base_size->x - hover_area->w);
80 if (pos->x < hover_area->x)
81 pos->x = hover_area->x;
85 _y_pos_adjust(Evas_Coord_Point *pos,
86 Evas_Coord_Point *base_size,
87 Evas_Coord_Rectangle *hover_area)
89 pos->y -= (base_size->y / 2);
91 if (pos->y < hover_area->y)
92 pos->y = hover_area->y;
93 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
94 pos->y = hover_area->y + hover_area->h - base_size->y;
96 if (base_size->y > hover_area->h)
97 base_size->y -= (base_size->y - hover_area->h);
99 if (pos->y < hover_area->y)
100 pos->y = hover_area->y;
103 static Elm_Ctxpopup_Direction
104 _base_geometry_calc(Evas_Object *obj,
105 Evas_Coord_Rectangle *rect)
107 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
108 Evas_Coord_Rectangle hover_area;
109 Evas_Coord_Point pos = {0, 0};
110 Evas_Coord_Point arrow_size;
111 Evas_Coord_Point base_size;
112 Evas_Coord_Point max_size;
113 Evas_Coord_Point min_size;
114 Evas_Coord_Point temp;
117 ELM_CTXPOPUP_DATA_GET(obj, sd);
119 if (!rect) return ELM_CTXPOPUP_DIRECTION_DOWN;
121 edje_object_part_geometry_get
122 (sd->arrow, "ctxpopup_arrow", NULL, NULL, &arrow_size.x, &arrow_size.y);
123 evas_object_resize(sd->arrow, arrow_size.x, arrow_size.y);
125 //Initialize Area Rectangle.
126 evas_object_geometry_get
127 (sd->parent, &hover_area.x, &hover_area.y, &hover_area.w,
130 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
133 edje_object_size_min_calc
134 (ELM_WIDGET_DATA(sd)->resize_obj, &base_size.x, &base_size.y);
135 evas_object_smart_calculate(ELM_WIDGET_DATA(sd)->resize_obj);
138 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
140 if ((max_size.y > 0) && (base_size.y > max_size.y))
141 base_size.y = max_size.y;
143 if ((max_size.x > 0) && (base_size.x > max_size.x))
144 base_size.x = max_size.x;
147 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
149 if ((min_size.y > 0) && (base_size.y < min_size.y))
150 base_size.y = min_size.y;
152 if ((min_size.x > 0) && (base_size.x < min_size.x))
153 base_size.x = min_size.x;
155 //Check the Which direction is available.
156 //If find a avaialble direction, it adjusts position and size.
157 for (idx = 0; idx < 4; idx++)
159 switch (sd->dir_priority[idx])
161 case ELM_CTXPOPUP_DIRECTION_UP:
162 temp.y = (pos.y - base_size.y);
163 if ((temp.y - arrow_size.y) < hover_area.y)
166 _x_pos_adjust(&pos, &base_size, &hover_area);
167 pos.y -= base_size.y;
168 dir = ELM_CTXPOPUP_DIRECTION_UP;
171 case ELM_CTXPOPUP_DIRECTION_LEFT:
172 temp.x = (pos.x - base_size.x);
173 if ((temp.x - arrow_size.x) < hover_area.x)
176 _y_pos_adjust(&pos, &base_size, &hover_area);
177 pos.x -= base_size.x;
178 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
181 case ELM_CTXPOPUP_DIRECTION_RIGHT:
182 temp.x = (pos.x + base_size.x);
183 if ((temp.x + arrow_size.x) >
184 (hover_area.x + hover_area.w))
187 _y_pos_adjust(&pos, &base_size, &hover_area);
188 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
191 case ELM_CTXPOPUP_DIRECTION_DOWN:
192 temp.y = (pos.y + base_size.y);
193 if ((temp.y + arrow_size.y) >
194 (hover_area.y + hover_area.h))
197 _x_pos_adjust(&pos, &base_size, &hover_area);
198 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
207 //In this case, all directions are invalid because of lack of space.
210 Evas_Coord length[2];
214 length[0] = pos.y - hover_area.y;
215 length[1] = (hover_area.y + hover_area.h) - pos.y;
217 // ELM_CTXPOPUP_DIRECTION_UP
218 if (length[0] > length[1])
220 _x_pos_adjust(&pos, &base_size, &hover_area);
221 pos.y -= base_size.y;
222 dir = ELM_CTXPOPUP_DIRECTION_UP;
223 if (pos.y < (hover_area.y + arrow_size.y))
225 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
226 pos.y = hover_area.y + arrow_size.y;
229 //ELM_CTXPOPUP_DIRECTION_DOWN
232 _x_pos_adjust(&pos, &base_size, &hover_area);
233 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
234 if ((pos.y + arrow_size.y + base_size.y) >
235 (hover_area.y + hover_area.h))
237 ((pos.y + arrow_size.y + base_size.y) -
238 (hover_area.y + hover_area.h));
243 length[0] = pos.x - hover_area.x;
244 length[1] = (hover_area.x + hover_area.w) - pos.x;
246 //ELM_CTXPOPUP_DIRECTION_LEFT
247 if (length[0] > length[1])
249 _y_pos_adjust(&pos, &base_size, &hover_area);
250 pos.x -= base_size.x;
251 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
252 if (pos.x < (hover_area.x + arrow_size.x))
254 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
255 pos.x = hover_area.x + arrow_size.x;
258 //ELM_CTXPOPUP_DIRECTION_RIGHT
261 _y_pos_adjust(&pos, &base_size, &hover_area);
262 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
263 if (pos.x + (arrow_size.x + base_size.x) >
264 hover_area.x + hover_area.w)
266 ((pos.x + arrow_size.x + base_size.x) -
267 (hover_area.x + hover_area.w));
272 //Final position and size.
275 rect->w = base_size.x;
276 rect->h = base_size.y;
282 _arrow_update(Evas_Object *obj,
283 Elm_Ctxpopup_Direction dir,
284 Evas_Coord_Rectangle base_size)
286 Evas_Coord_Rectangle arrow_size;
290 ELM_CTXPOPUP_DATA_GET(obj, sd);
292 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
293 evas_object_geometry_get
294 (sd->arrow, NULL, NULL, &arrow_size.w, &arrow_size.h);
296 /* arrow is not being kept as sub-object on purpose, here. the
297 * design of the widget does not help with the contrary */
301 case ELM_CTXPOPUP_DIRECTION_RIGHT:
302 edje_object_signal_emit(sd->arrow, "elm,state,left", "elm");
303 edje_object_part_swallow
304 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_left",
308 if (y < ((arrow_size.h * 0.5) + base_size.y))
310 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
311 y = base_size.h - arrow_size.h;
313 y = y - base_size.y - (arrow_size.h * 0.5);
314 drag = (double)(y) / (double)(base_size.h - arrow_size.h);
315 edje_object_part_drag_value_set
316 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_left", 1,
321 case ELM_CTXPOPUP_DIRECTION_LEFT:
322 edje_object_signal_emit(sd->arrow, "elm,state,right", "elm");
323 edje_object_part_swallow
324 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_right",
329 if (y < ((arrow_size.h * 0.5) + base_size.y))
331 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
332 y = base_size.h - arrow_size.h;
334 y = y - base_size.y - (arrow_size.h * 0.5);
335 drag = (double)(y) / (double)(base_size.h - arrow_size.h);
336 edje_object_part_drag_value_set
337 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_right", 0,
342 case ELM_CTXPOPUP_DIRECTION_DOWN:
343 edje_object_signal_emit(sd->arrow, "elm,state,top", "elm");
344 edje_object_part_swallow
345 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up",
350 if (x < ((arrow_size.w * 0.5) + base_size.x))
352 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
353 x = base_size.w - arrow_size.w;
355 x = x - base_size.x - (arrow_size.w * 0.5);
356 drag = (double)(x) / (double)(base_size.w - arrow_size.w);
357 edje_object_part_drag_value_set
358 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up", drag,
363 case ELM_CTXPOPUP_DIRECTION_UP:
364 edje_object_signal_emit(sd->arrow, "elm,state,bottom", "elm");
365 edje_object_part_swallow
366 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
371 if (x < ((arrow_size.w * 0.5) + base_size.x))
373 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
374 x = base_size.w - arrow_size.w;
375 else x = x - base_size.x - (arrow_size.w * 0.5);
376 drag = (double)(x) / (double)(base_size.w - arrow_size.w);
377 edje_object_part_drag_value_set
378 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
387 //should be here for getting accurate geometry value
388 evas_object_smart_calculate(ELM_WIDGET_DATA(sd)->resize_obj);
392 _show_signals_emit(Evas_Object *obj,
393 Elm_Ctxpopup_Direction dir)
395 ELM_CTXPOPUP_DATA_GET(obj, sd);
397 if (!sd->visible) return;
398 if ((sd->list) && (!sd->list_visible)) return;
402 case ELM_CTXPOPUP_DIRECTION_UP:
403 elm_layout_signal_emit(obj, "elm,state,show,up", "elm");
406 case ELM_CTXPOPUP_DIRECTION_LEFT:
407 elm_layout_signal_emit(obj, "elm,state,show,left", "elm");
410 case ELM_CTXPOPUP_DIRECTION_RIGHT:
411 elm_layout_signal_emit(obj, "elm,state,show,right", "elm");
414 case ELM_CTXPOPUP_DIRECTION_DOWN:
415 elm_layout_signal_emit(obj, "elm,state,show,down", "elm");
422 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
423 elm_layout_signal_emit(obj, "elm,state,show", "elm");
427 _hide_signals_emit(Evas_Object *obj,
428 Elm_Ctxpopup_Direction dir)
430 ELM_CTXPOPUP_DATA_GET(obj, sd);
432 if (!sd->visible) return;
436 case ELM_CTXPOPUP_DIRECTION_UP:
437 elm_layout_signal_emit(obj, "elm,state,hide,up", "elm");
440 case ELM_CTXPOPUP_DIRECTION_LEFT:
441 elm_layout_signal_emit(obj, "elm,state,hide,left", "elm");
444 case ELM_CTXPOPUP_DIRECTION_RIGHT:
445 elm_layout_signal_emit(obj, "elm,state,hide,right", "elm");
448 case ELM_CTXPOPUP_DIRECTION_DOWN:
449 elm_layout_signal_emit(obj, "elm,state,hide,down", "elm");
456 edje_object_signal_emit(sd->bg, "elm,state,hide", "elm");
460 _base_shift_by_arrow(Evas_Object *arrow,
461 Elm_Ctxpopup_Direction dir,
462 Evas_Coord_Rectangle *rect)
464 Evas_Coord arrow_w, arrow_h;
466 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
469 case ELM_CTXPOPUP_DIRECTION_RIGHT:
473 case ELM_CTXPOPUP_DIRECTION_LEFT:
477 case ELM_CTXPOPUP_DIRECTION_DOWN:
481 case ELM_CTXPOPUP_DIRECTION_UP:
491 _elm_ctxpopup_smart_sub_object_add(Evas_Object *obj,
494 Elm_Widget_Smart_Class *parent_parent;
496 parent_parent = (Elm_Widget_Smart_Class *)((Evas_Smart_Class *)
497 _elm_ctxpopup_parent_sc)->parent;
499 /* skipping layout's code, which registers size hint changing
500 * callback on sub objects. a hack to make ctxpopup live, as it is,
501 * on the new classing schema. this widget needs a total
503 if (!parent_parent->sub_object_add(obj, sobj))
510 _elm_ctxpopup_smart_sizing_eval(Evas_Object *obj)
512 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
513 Evas_Coord_Point list_size = { 0, 0 };
515 ELM_CTXPOPUP_DATA_GET(obj, sd);
517 if (!sd->arrow) return; /* simple way to flag "under deletion" */
520 sd->dir = _base_geometry_calc(obj, &rect);
522 _arrow_update(obj, sd->dir, rect);
524 _base_shift_by_arrow(sd->arrow, sd->dir, &rect);
526 if ((sd->list) && (sd->list_visible))
528 evas_object_geometry_get(sd->list, 0, 0, &list_size.x, &list_size.y);
529 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
531 elm_list_mode_set(sd->list, ELM_LIST_COMPRESS);
532 evas_object_size_hint_min_set(sd->box, rect.w, rect.h);
533 evas_object_size_hint_min_set(obj, rect.w, rect.h);
537 evas_object_move(ELM_WIDGET_DATA(sd)->resize_obj, rect.x, rect.y);
538 evas_object_resize(ELM_WIDGET_DATA(sd)->resize_obj, rect.w, rect.h);
540 _show_signals_emit(obj, sd->dir);
544 _on_parent_del(void *data,
546 Evas_Object *obj __UNUSED__,
547 void *event_info __UNUSED__)
549 evas_object_del(data);
553 _on_parent_move(void *data,
555 Evas_Object *obj __UNUSED__,
556 void *event_info __UNUSED__)
558 ELM_CTXPOPUP_DATA_GET(data, sd);
560 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
562 if (sd->visible) elm_layout_sizing_eval(data);
566 _on_parent_resize(void *data,
568 Evas_Object *obj __UNUSED__,
569 void *event_info __UNUSED__)
571 ELM_CTXPOPUP_DATA_GET(data, sd);
573 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
575 evas_object_hide(data);
579 _parent_detach(Evas_Object *obj)
581 ELM_CTXPOPUP_DATA_GET(obj, sd);
583 if (!sd->parent) return;
585 evas_object_event_callback_del_full
586 (sd->parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
587 evas_object_event_callback_del_full
588 (sd->parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
589 evas_object_event_callback_del_full
590 (sd->parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
594 _on_content_resized(void *data,
596 Evas_Object *obj __UNUSED__,
597 void *event_info __UNUSED__)
599 ELM_CTXPOPUP_DATA_GET(data, sd);
601 elm_box_recalculate(sd->box);
602 elm_layout_sizing_eval(data);
605 //FIXME: lost the content size when theme hook is called.
607 _elm_ctxpopup_smart_theme(Evas_Object *obj)
609 ELM_CTXPOPUP_DATA_GET(obj, sd);
611 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->theme(obj))
614 elm_widget_theme_object_set
615 (obj, sd->bg, "ctxpopup", "bg", elm_widget_style_get(obj));
616 elm_widget_theme_object_set
617 (obj, sd->arrow, "ctxpopup", "arrow", elm_widget_style_get(obj));
621 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
622 elm_object_style_set(sd->list, "ctxpopup");
624 elm_object_style_set(sd->list, elm_object_style_get(obj));
627 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
629 if (sd->visible) elm_layout_sizing_eval(obj);
634 /* kind of a big and tricky override here: an internal box will hold
635 * the actual content. content aliases won't be of much help here */
637 _elm_ctxpopup_smart_content_set(Evas_Object *obj,
639 Evas_Object *content)
641 Evas_Coord min_w = -1, min_h = -1;
643 ELM_CTXPOPUP_DATA_GET(obj, sd);
645 if ((part) && (strcmp(part, "default")))
646 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
647 (obj, part, content);
649 if (!content) return EINA_FALSE;
651 if (content == sd->content) return EINA_TRUE;
653 if (sd->content) evas_object_del(sd->content);
654 if (sd->content == sd->list) sd->list = NULL;
656 evas_object_size_hint_weight_set
657 (content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
658 evas_object_size_hint_fill_set
659 (content, EVAS_HINT_FILL, EVAS_HINT_FILL);
661 /* since it's going to be a box content, not a layout's... */
662 evas_object_show(content);
664 evas_object_size_hint_min_get(content, &min_w, &min_h);
665 evas_object_size_hint_min_set(sd->box, min_w, min_h);
666 elm_box_pack_end(sd->box, content);
668 sd->content = content;
669 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
671 if (sd->visible) elm_layout_sizing_eval(obj);
677 _elm_ctxpopup_smart_content_get(const Evas_Object *obj,
680 ELM_CTXPOPUP_DATA_GET(obj, sd);
682 if ((part) && (strcmp(part, "default")))
683 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_get
690 _elm_ctxpopup_smart_content_unset(Evas_Object *obj,
693 Evas_Object *content;
695 ELM_CTXPOPUP_DATA_GET(obj, sd);
697 if ((part) && (strcmp(part, "default")))
698 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_unset
701 content = sd->content;
702 if (!content) return NULL;
705 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
707 if (sd->visible) elm_layout_sizing_eval(obj);
713 _item_text_set_hook(Elm_Object_Item *it,
717 Elm_Ctxpopup_Item *ctxpopup_it;
719 if ((part) && (strcmp(part, "default"))) return;
721 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
723 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
725 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
726 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
728 if (sd->visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
732 _item_text_get_hook(const Elm_Object_Item *it,
735 Elm_Ctxpopup_Item *ctxpopup_it;
737 if (part && strcmp(part, "default")) return NULL;
739 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
740 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
744 _item_content_set_hook(Elm_Object_Item *it,
746 Evas_Object *content)
748 Elm_Ctxpopup_Item *ctxpopup_it;
750 if ((part) && (strcmp(part, "icon"))
751 && (strcmp(part, "start"))
752 && (strcmp(part, "end"))) return;
754 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
756 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
758 if ((part) && (!strcmp(part, "end")))
759 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
761 elm_object_item_part_content_set
762 (ctxpopup_it->list_item, "start", content);
764 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
766 if (sd->visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
770 _item_content_get_hook(const Elm_Object_Item *it,
773 Elm_Ctxpopup_Item *ctxpopup_it;
775 if (part && strcmp(part, "icon") && strcmp(part, "start")
776 && strcmp(part, "end")) return NULL;
778 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
780 if (part && !strcmp(part, "end"))
781 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
783 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
787 _item_disable_hook(Elm_Object_Item *it)
789 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
791 elm_object_item_disabled_set
792 (ctxpopup_it->list_item, elm_widget_item_disabled_get(ctxpopup_it));
796 _item_signal_emit_hook(Elm_Object_Item *it,
797 const char *emission,
800 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
802 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
806 _bg_clicked_cb(void *data,
807 Evas_Object *obj __UNUSED__,
808 const char *emission __UNUSED__,
809 const char *source __UNUSED__)
811 ELM_CTXPOPUP_DATA_GET(data, sd);
813 _hide_signals_emit(data, sd->dir);
817 _on_show(void *data __UNUSED__,
820 void *event_info __UNUSED__)
822 ELM_CTXPOPUP_DATA_GET(obj, sd);
826 elm_list_go(sd->list);
827 sd->visible = EINA_TRUE;
828 elm_object_focus_set(obj, EINA_TRUE);
832 if (!sd->content) return;
834 sd->visible = EINA_TRUE;
836 evas_object_show(sd->bg);
837 evas_object_show(sd->arrow);
839 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
840 elm_layout_signal_emit(obj, "elm,state,show", "elm");
842 elm_layout_sizing_eval(obj);
844 elm_object_focus_set(obj, EINA_TRUE);
848 _on_hide(void *data __UNUSED__,
851 void *event_info __UNUSED__)
853 ELM_CTXPOPUP_DATA_GET(obj, sd);
855 if (!sd->visible) return;
857 evas_object_hide(sd->bg);
858 evas_object_hide(sd->arrow);
860 sd->visible = EINA_FALSE;
861 sd->list_visible = EINA_FALSE;
865 _on_move(void *data __UNUSED__,
868 void *event_info __UNUSED__)
870 ELM_CTXPOPUP_DATA_GET(obj, sd);
872 if (sd->visible) evas_object_show(sd->arrow);
874 elm_layout_sizing_eval(obj);
878 _hide_finished_cb(void *data,
879 Evas_Object *obj __UNUSED__,
880 const char *emission __UNUSED__,
881 const char *source __UNUSED__)
883 evas_object_hide(data);
884 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
888 _list_resize_cb(void *data,
890 Evas_Object *obj __UNUSED__,
891 void *event_info __UNUSED__)
893 ELM_CTXPOPUP_DATA_GET(data, sd);
895 if (!sd->visible) return;
896 if (sd->list_visible) return;
898 sd->list_visible = EINA_TRUE;
900 evas_object_show(sd->bg);
901 evas_object_show(sd->arrow);
903 elm_layout_sizing_eval(data);
907 _ctxpopup_restack_cb(void *data __UNUSED__,
910 void *event_info __UNUSED__)
912 ELM_CTXPOPUP_DATA_GET(obj, sd);
914 evas_object_layer_set(sd->bg, evas_object_layer_get(obj));
918 _list_del(Elm_Ctxpopup_Smart_Data *sd)
920 if (!sd->list) return;
922 evas_object_del(sd->list);
927 _item_del_pre_hook(Elm_Object_Item *it)
930 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
932 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
934 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
936 list = elm_object_item_widget_get(ctxpopup_it->list_item);
938 if (eina_list_count(elm_list_items_get(list)) < 2)
940 elm_object_item_del(ctxpopup_it->list_item);
941 evas_object_hide(WIDGET(ctxpopup_it));
946 elm_object_item_del(ctxpopup_it->list_item);
947 if (sd->list_visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
953 _elm_ctxpopup_smart_disable(Evas_Object *obj)
955 ELM_CTXPOPUP_DATA_GET(obj, sd);
957 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->disable(obj))
960 elm_object_disabled_set(sd->list, elm_widget_disabled_get(obj));
966 _elm_ctxpopup_smart_add(Evas_Object *obj)
968 EVAS_SMART_DATA_ALLOC(obj, Elm_Ctxpopup_Smart_Data);
970 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.add(obj);
972 elm_layout_theme_set(obj, "ctxpopup", "base", elm_widget_style_get(obj));
973 elm_layout_signal_callback_add
974 (obj, "elm,action,hide,finished", "", _hide_finished_cb, obj);
977 priv->bg = edje_object_add(evas_object_evas_get(obj));
978 elm_widget_theme_object_set(obj, priv->bg, "ctxpopup", "bg", "default");
979 edje_object_signal_callback_add
980 (priv->bg, "elm,action,click", "", _bg_clicked_cb, obj);
982 evas_object_stack_below(priv->bg, obj);
985 priv->arrow = edje_object_add(evas_object_evas_get(obj));
986 elm_widget_theme_object_set
987 (obj, priv->arrow, "ctxpopup", "arrow", "default");
989 priv->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
990 priv->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
991 priv->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
992 priv->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
993 priv->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
995 evas_object_event_callback_add
996 (obj, EVAS_CALLBACK_RESTACK, _ctxpopup_restack_cb, obj);
998 priv->box = elm_box_add(obj);
999 evas_object_size_hint_weight_set
1000 (priv->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1002 evas_object_event_callback_add
1003 (priv->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1005 /* box will be our content placeholder, thus the parent's version call */
1006 ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1007 (obj, "elm.swallow.content", priv->box);
1009 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _on_show, NULL);
1010 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _on_hide, NULL);
1011 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _on_move, NULL);
1013 elm_widget_can_focus_set(obj, EINA_TRUE);
1017 _elm_ctxpopup_smart_del(Evas_Object *obj)
1019 ELM_CTXPOPUP_DATA_GET(obj, sd);
1021 evas_object_event_callback_del_full
1022 (sd->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1023 _parent_detach(obj);
1025 elm_ctxpopup_clear(obj);
1026 evas_object_del(sd->arrow);
1027 sd->arrow = NULL; /* stops _sizing_eval() from going on on deletion */
1029 evas_object_del(sd->bg);
1032 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.del(obj);
1036 _elm_ctxpopup_smart_parent_set(Evas_Object *obj,
1037 Evas_Object *parent)
1039 //default parent is to be hover parent
1040 elm_ctxpopup_hover_parent_set(obj, parent);
1044 _elm_ctxpopup_smart_set_user(Elm_Ctxpopup_Smart_Class *sc)
1046 ELM_WIDGET_CLASS(sc)->base.add = _elm_ctxpopup_smart_add;
1047 ELM_WIDGET_CLASS(sc)->base.del = _elm_ctxpopup_smart_del;
1049 ELM_WIDGET_CLASS(sc)->parent_set = _elm_ctxpopup_smart_parent_set;
1050 ELM_WIDGET_CLASS(sc)->disable = _elm_ctxpopup_smart_disable;
1051 ELM_WIDGET_CLASS(sc)->event = _elm_ctxpopup_smart_event;
1052 ELM_WIDGET_CLASS(sc)->theme = _elm_ctxpopup_smart_theme;
1053 ELM_WIDGET_CLASS(sc)->sub_object_add = _elm_ctxpopup_smart_sub_object_add;
1054 ELM_WIDGET_CLASS(sc)->focus_next = _elm_ctxpopup_smart_focus_next;
1055 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
1057 ELM_CONTAINER_CLASS(sc)->content_get = _elm_ctxpopup_smart_content_get;
1058 ELM_CONTAINER_CLASS(sc)->content_set = _elm_ctxpopup_smart_content_set;
1059 ELM_CONTAINER_CLASS(sc)->content_unset = _elm_ctxpopup_smart_content_unset;
1061 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_ctxpopup_smart_sizing_eval;
1064 EAPI const Elm_Ctxpopup_Smart_Class *
1065 elm_ctxpopup_smart_class_get(void)
1067 static Elm_Ctxpopup_Smart_Class _sc =
1068 ELM_CTXPOPUP_SMART_CLASS_INIT_NAME_VERSION(ELM_CTXPOPUP_SMART_NAME);
1069 static const Elm_Ctxpopup_Smart_Class *class = NULL;
1070 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
1075 _elm_ctxpopup_smart_set(&_sc);
1076 esc->callbacks = _smart_callbacks;
1083 elm_ctxpopup_add(Evas_Object *parent)
1087 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1089 obj = elm_widget_add(_elm_ctxpopup_smart_class_new(), parent);
1090 if (!obj) return NULL;
1092 if (!elm_widget_sub_object_add(parent, obj))
1093 ERR("could not add %p as sub object of %p", obj, parent);
1099 elm_ctxpopup_hover_parent_set(Evas_Object *obj,
1100 Evas_Object *parent)
1102 Evas_Coord x, y, w, h;
1104 ELM_CTXPOPUP_CHECK(obj);
1105 ELM_CTXPOPUP_DATA_GET(obj, sd);
1107 if (!parent) return;
1109 _parent_detach(obj);
1111 evas_object_event_callback_add
1112 (parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
1113 evas_object_event_callback_add
1114 (parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
1115 evas_object_event_callback_add
1116 (parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
1118 sd->parent = parent;
1121 evas_object_geometry_get(parent, &x, &y, &w, &h);
1122 evas_object_move(sd->bg, x, y);
1123 evas_object_resize(sd->bg, w, h);
1125 if (sd->visible) elm_layout_sizing_eval(obj);
1129 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1131 ELM_CTXPOPUP_CHECK(obj) NULL;
1132 ELM_CTXPOPUP_DATA_GET(obj, sd);
1138 elm_ctxpopup_clear(Evas_Object *obj)
1140 ELM_CTXPOPUP_CHECK(obj);
1141 ELM_CTXPOPUP_DATA_GET(obj, sd);
1144 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1148 elm_ctxpopup_horizontal_set(Evas_Object *obj,
1149 Eina_Bool horizontal)
1151 ELM_CTXPOPUP_CHECK(obj);
1152 ELM_CTXPOPUP_DATA_GET(obj, sd);
1154 sd->horizontal = !!horizontal;
1156 if (!sd->list) return;
1158 elm_list_horizontal_set(sd->list, sd->horizontal);
1160 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1162 if (sd->visible) elm_layout_sizing_eval(obj);
1166 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1168 ELM_CTXPOPUP_CHECK(obj) EINA_FALSE;
1169 ELM_CTXPOPUP_DATA_GET(obj, sd);
1171 return sd->horizontal;
1174 EAPI Elm_Object_Item *
1175 elm_ctxpopup_item_append(Evas_Object *obj,
1181 Elm_Ctxpopup_Item *item;
1183 ELM_CTXPOPUP_CHECK(obj) NULL;
1184 ELM_CTXPOPUP_DATA_GET(obj, sd);
1186 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1187 if (!item) return NULL;
1189 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1190 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1191 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1192 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1193 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1194 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1195 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1199 //The first item is appended.
1200 sd->list = elm_list_add(obj);
1201 elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
1202 elm_list_horizontal_set(sd->list, sd->horizontal);
1203 evas_object_event_callback_add
1204 (sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
1205 elm_layout_content_set(obj, "default", sd->list);
1209 elm_list_item_append(sd->list, label, icon, NULL, func, data);
1211 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1213 if (sd->visible) elm_layout_sizing_eval(obj);
1215 return (Elm_Object_Item *)item;
1219 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1220 Elm_Ctxpopup_Direction first,
1221 Elm_Ctxpopup_Direction second,
1222 Elm_Ctxpopup_Direction third,
1223 Elm_Ctxpopup_Direction fourth)
1225 ELM_CTXPOPUP_CHECK(obj);
1226 ELM_CTXPOPUP_DATA_GET(obj, sd);
1228 sd->dir_priority[0] = first;
1229 sd->dir_priority[1] = second;
1230 sd->dir_priority[2] = third;
1231 sd->dir_priority[3] = fourth;
1233 if (sd->visible) elm_layout_sizing_eval(obj);
1237 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1238 Elm_Ctxpopup_Direction *first,
1239 Elm_Ctxpopup_Direction *second,
1240 Elm_Ctxpopup_Direction *third,
1241 Elm_Ctxpopup_Direction *fourth)
1243 ELM_CTXPOPUP_CHECK(obj);
1244 ELM_CTXPOPUP_DATA_GET(obj, sd);
1246 if (first) *first = sd->dir_priority[0];
1247 if (second) *second = sd->dir_priority[1];
1248 if (third) *third = sd->dir_priority[2];
1249 if (fourth) *fourth = sd->dir_priority[3];
1252 EAPI Elm_Ctxpopup_Direction
1253 elm_ctxpopup_direction_get(const Evas_Object *obj)
1255 ELM_CTXPOPUP_CHECK(obj) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1256 ELM_CTXPOPUP_DATA_GET(obj, sd);
1262 elm_ctxpopup_dismiss(Evas_Object *obj)
1264 ELM_CTXPOPUP_CHECK(obj);
1265 ELM_CTXPOPUP_DATA_GET(obj, sd);
1267 _hide_signals_emit(obj, sd->dir);