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,
305 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_right" :
306 "elm.swallow.arrow_left"), sd->arrow);
310 if (y < ((arrow_size.h * 0.5) + base_size.y))
312 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
313 y = base_size.h - arrow_size.h;
315 y = y - base_size.y - (arrow_size.h * 0.5);
316 drag = (double)(y) / (double)(base_size.h - arrow_size.h);
317 edje_object_part_drag_value_set
318 (ELM_WIDGET_DATA(sd)->resize_obj,
319 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_right" :
320 "elm.swallow.arrow_left"), 1, drag);
324 case ELM_CTXPOPUP_DIRECTION_LEFT:
325 edje_object_signal_emit(sd->arrow, "elm,state,right", "elm");
326 edje_object_part_swallow
327 (ELM_WIDGET_DATA(sd)->resize_obj,
328 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_left" :
329 "elm.swallow.arrow_right"), sd->arrow);
333 if (y < ((arrow_size.h * 0.5) + base_size.y))
335 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
336 y = base_size.h - arrow_size.h;
338 y = y - base_size.y - (arrow_size.h * 0.5);
339 drag = (double)(y) / (double)(base_size.h - arrow_size.h);
340 edje_object_part_drag_value_set
341 (ELM_WIDGET_DATA(sd)->resize_obj,
342 (elm_widget_mirrored_get(obj) ? "elm.swallow.arrow_left" :
343 "elm.swallow.arrow_right"), 0, drag);
347 case ELM_CTXPOPUP_DIRECTION_DOWN:
348 edje_object_signal_emit(sd->arrow, "elm,state,top", "elm");
349 edje_object_part_swallow
350 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up",
355 if (x < ((arrow_size.w * 0.5) + base_size.x))
357 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
358 x = base_size.w - arrow_size.w;
360 x = x - base_size.x - (arrow_size.w * 0.5);
361 drag = (double)(x) / (double)(base_size.w - arrow_size.w);
362 edje_object_part_drag_value_set
363 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_up", drag,
368 case ELM_CTXPOPUP_DIRECTION_UP:
369 edje_object_signal_emit(sd->arrow, "elm,state,bottom", "elm");
370 edje_object_part_swallow
371 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
376 if (x < ((arrow_size.w * 0.5) + base_size.x))
378 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
379 x = base_size.w - arrow_size.w;
380 else x = x - base_size.x - (arrow_size.w * 0.5);
381 drag = (double)(x) / (double)(base_size.w - arrow_size.w);
382 edje_object_part_drag_value_set
383 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.swallow.arrow_down",
392 //should be here for getting accurate geometry value
393 evas_object_smart_calculate(ELM_WIDGET_DATA(sd)->resize_obj);
397 _show_signals_emit(Evas_Object *obj,
398 Elm_Ctxpopup_Direction dir)
400 ELM_CTXPOPUP_DATA_GET(obj, sd);
402 if (!sd->visible) return;
403 if ((sd->list) && (!sd->list_visible)) return;
407 case ELM_CTXPOPUP_DIRECTION_UP:
408 elm_layout_signal_emit(obj, "elm,state,show,up", "elm");
411 case ELM_CTXPOPUP_DIRECTION_LEFT:
412 elm_layout_signal_emit(obj,
413 (elm_widget_mirrored_get(obj) ? "elm,state,show,right" :
414 "elm,state,show,left"), "elm");
417 case ELM_CTXPOPUP_DIRECTION_RIGHT:
418 elm_layout_signal_emit(obj,
419 (elm_widget_mirrored_get(obj) ? "elm,state,show,left" :
420 "elm,state,show,right"), "elm");
423 case ELM_CTXPOPUP_DIRECTION_DOWN:
424 elm_layout_signal_emit(obj, "elm,state,show,down", "elm");
431 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
432 elm_layout_signal_emit(obj, "elm,state,show", "elm");
436 _hide_signals_emit(Evas_Object *obj,
437 Elm_Ctxpopup_Direction dir)
439 ELM_CTXPOPUP_DATA_GET(obj, sd);
441 if (!sd->visible) return;
445 case ELM_CTXPOPUP_DIRECTION_UP:
446 elm_layout_signal_emit(obj, "elm,state,hide,up", "elm");
449 case ELM_CTXPOPUP_DIRECTION_LEFT:
450 elm_layout_signal_emit(obj,
451 (elm_widget_mirrored_get(obj) ? "elm,state,hide,right" :
452 "elm,state,hide,left"), "elm");
455 case ELM_CTXPOPUP_DIRECTION_RIGHT:
456 elm_layout_signal_emit(obj,
457 (elm_widget_mirrored_get(obj) ? "elm,state,hide,left" :
458 "elm,state,hide,right"), "elm");
461 case ELM_CTXPOPUP_DIRECTION_DOWN:
462 elm_layout_signal_emit(obj, "elm,state,hide,down", "elm");
469 edje_object_signal_emit(sd->bg, "elm,state,hide", "elm");
473 _base_shift_by_arrow(Evas_Object *arrow,
474 Elm_Ctxpopup_Direction dir,
475 Evas_Coord_Rectangle *rect)
477 Evas_Coord arrow_w, arrow_h;
479 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
482 case ELM_CTXPOPUP_DIRECTION_RIGHT:
486 case ELM_CTXPOPUP_DIRECTION_LEFT:
490 case ELM_CTXPOPUP_DIRECTION_DOWN:
494 case ELM_CTXPOPUP_DIRECTION_UP:
504 _elm_ctxpopup_smart_sub_object_add(Evas_Object *obj,
507 Elm_Widget_Smart_Class *parent_parent;
509 parent_parent = (Elm_Widget_Smart_Class *)((Evas_Smart_Class *)
510 _elm_ctxpopup_parent_sc)->parent;
512 /* skipping layout's code, which registers size hint changing
513 * callback on sub objects. a hack to make ctxpopup live, as it is,
514 * on the new classing schema. this widget needs a total
516 if (!parent_parent->sub_object_add(obj, sobj))
523 _elm_ctxpopup_smart_sizing_eval(Evas_Object *obj)
525 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
526 Evas_Coord_Point list_size = { 0, 0 };
528 ELM_CTXPOPUP_DATA_GET(obj, sd);
530 if (!sd->arrow) return; /* simple way to flag "under deletion" */
533 sd->dir = _base_geometry_calc(obj, &rect);
535 _arrow_update(obj, sd->dir, rect);
537 _base_shift_by_arrow(sd->arrow, sd->dir, &rect);
539 if ((sd->list) && (sd->list_visible))
541 evas_object_geometry_get(sd->list, 0, 0, &list_size.x, &list_size.y);
542 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
544 elm_list_mode_set(sd->list, ELM_LIST_COMPRESS);
545 evas_object_size_hint_min_set(sd->box, rect.w, rect.h);
546 evas_object_size_hint_min_set(obj, rect.w, rect.h);
550 evas_object_move(ELM_WIDGET_DATA(sd)->resize_obj, rect.x, rect.y);
551 evas_object_resize(ELM_WIDGET_DATA(sd)->resize_obj, rect.w, rect.h);
553 _show_signals_emit(obj, sd->dir);
557 _on_parent_del(void *data,
559 Evas_Object *obj __UNUSED__,
560 void *event_info __UNUSED__)
562 evas_object_del(data);
566 _on_parent_move(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 if (sd->visible) elm_layout_sizing_eval(data);
579 _on_parent_resize(void *data,
581 Evas_Object *obj __UNUSED__,
582 void *event_info __UNUSED__)
584 ELM_CTXPOPUP_DATA_GET(data, sd);
586 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
588 evas_object_hide(data);
592 _parent_detach(Evas_Object *obj)
594 ELM_CTXPOPUP_DATA_GET(obj, sd);
596 if (!sd->parent) return;
598 evas_object_event_callback_del_full
599 (sd->parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
600 evas_object_event_callback_del_full
601 (sd->parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
602 evas_object_event_callback_del_full
603 (sd->parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
607 _on_content_resized(void *data,
609 Evas_Object *obj __UNUSED__,
610 void *event_info __UNUSED__)
612 ELM_CTXPOPUP_DATA_GET(data, sd);
614 elm_box_recalculate(sd->box);
615 elm_layout_sizing_eval(data);
618 //FIXME: lost the content size when theme hook is called.
620 _elm_ctxpopup_smart_theme(Evas_Object *obj)
622 ELM_CTXPOPUP_DATA_GET(obj, sd);
624 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->theme(obj))
627 elm_widget_theme_object_set
628 (obj, sd->bg, "ctxpopup", "bg", elm_widget_style_get(obj));
629 elm_widget_theme_object_set
630 (obj, sd->arrow, "ctxpopup", "arrow", elm_widget_style_get(obj));
634 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
635 elm_object_style_set(sd->list, "ctxpopup");
637 elm_object_style_set(sd->list, elm_object_style_get(obj));
640 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
642 if (sd->visible) elm_layout_sizing_eval(obj);
647 /* kind of a big and tricky override here: an internal box will hold
648 * the actual content. content aliases won't be of much help here */
650 _elm_ctxpopup_smart_content_set(Evas_Object *obj,
652 Evas_Object *content)
654 Evas_Coord min_w = -1, min_h = -1;
656 ELM_CTXPOPUP_DATA_GET(obj, sd);
658 if ((part) && (strcmp(part, "default")))
659 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
660 (obj, part, content);
662 if (!content) return EINA_FALSE;
664 if (content == sd->content) return EINA_TRUE;
666 if (sd->content) evas_object_del(sd->content);
667 if (sd->content == sd->list) sd->list = NULL;
669 evas_object_size_hint_weight_set
670 (content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
671 evas_object_size_hint_fill_set
672 (content, EVAS_HINT_FILL, EVAS_HINT_FILL);
674 /* since it's going to be a box content, not a layout's... */
675 evas_object_show(content);
677 evas_object_size_hint_min_get(content, &min_w, &min_h);
678 evas_object_size_hint_min_set(sd->box, min_w, min_h);
679 elm_box_pack_end(sd->box, content);
681 sd->content = content;
682 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
684 if (sd->visible) elm_layout_sizing_eval(obj);
690 _elm_ctxpopup_smart_content_get(const Evas_Object *obj,
693 ELM_CTXPOPUP_DATA_GET(obj, sd);
695 if ((part) && (strcmp(part, "default")))
696 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_get
703 _elm_ctxpopup_smart_content_unset(Evas_Object *obj,
706 Evas_Object *content;
708 ELM_CTXPOPUP_DATA_GET(obj, sd);
710 if ((part) && (strcmp(part, "default")))
711 return ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_unset
714 content = sd->content;
715 if (!content) return NULL;
718 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
720 if (sd->visible) elm_layout_sizing_eval(obj);
726 _item_text_set_hook(Elm_Object_Item *it,
730 Elm_Ctxpopup_Item *ctxpopup_it;
732 if ((part) && (strcmp(part, "default"))) return;
734 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
736 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
738 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
739 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
741 if (sd->visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
745 _item_text_get_hook(const Elm_Object_Item *it,
748 Elm_Ctxpopup_Item *ctxpopup_it;
750 if (part && strcmp(part, "default")) return NULL;
752 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
753 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
757 _item_content_set_hook(Elm_Object_Item *it,
759 Evas_Object *content)
761 Elm_Ctxpopup_Item *ctxpopup_it;
763 if ((part) && (strcmp(part, "icon"))
764 && (strcmp(part, "start"))
765 && (strcmp(part, "end"))) return;
767 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
769 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
771 if ((part) && (!strcmp(part, "end")))
772 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
774 elm_object_item_part_content_set
775 (ctxpopup_it->list_item, "start", content);
777 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
779 if (sd->visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
783 _item_content_get_hook(const Elm_Object_Item *it,
786 Elm_Ctxpopup_Item *ctxpopup_it;
788 if (part && strcmp(part, "icon") && strcmp(part, "start")
789 && strcmp(part, "end")) return NULL;
791 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
793 if (part && !strcmp(part, "end"))
794 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
796 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
800 _item_disable_hook(Elm_Object_Item *it)
802 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
804 elm_object_item_disabled_set
805 (ctxpopup_it->list_item, elm_widget_item_disabled_get(ctxpopup_it));
809 _item_signal_emit_hook(Elm_Object_Item *it,
810 const char *emission,
813 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
815 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
819 _bg_clicked_cb(void *data,
820 Evas_Object *obj __UNUSED__,
821 const char *emission __UNUSED__,
822 const char *source __UNUSED__)
824 ELM_CTXPOPUP_DATA_GET(data, sd);
826 _hide_signals_emit(data, sd->dir);
830 _on_show(void *data __UNUSED__,
833 void *event_info __UNUSED__)
835 ELM_CTXPOPUP_DATA_GET(obj, sd);
839 elm_list_go(sd->list);
840 sd->visible = EINA_TRUE;
841 elm_object_focus_set(obj, EINA_TRUE);
845 if (!sd->content) return;
847 sd->visible = EINA_TRUE;
849 evas_object_show(sd->bg);
850 evas_object_show(sd->arrow);
852 edje_object_signal_emit(sd->bg, "elm,state,show", "elm");
853 elm_layout_signal_emit(obj, "elm,state,show", "elm");
855 elm_layout_sizing_eval(obj);
857 elm_object_focus_set(obj, EINA_TRUE);
861 _on_hide(void *data __UNUSED__,
864 void *event_info __UNUSED__)
866 ELM_CTXPOPUP_DATA_GET(obj, sd);
868 if (!sd->visible) return;
870 evas_object_hide(sd->bg);
871 evas_object_hide(sd->arrow);
873 sd->visible = EINA_FALSE;
874 sd->list_visible = EINA_FALSE;
878 _on_move(void *data __UNUSED__,
881 void *event_info __UNUSED__)
883 ELM_CTXPOPUP_DATA_GET(obj, sd);
885 if (sd->visible) evas_object_show(sd->arrow);
887 elm_layout_sizing_eval(obj);
891 _hide_finished_cb(void *data,
892 Evas_Object *obj __UNUSED__,
893 const char *emission __UNUSED__,
894 const char *source __UNUSED__)
896 evas_object_hide(data);
897 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
901 _list_resize_cb(void *data,
903 Evas_Object *obj __UNUSED__,
904 void *event_info __UNUSED__)
906 ELM_CTXPOPUP_DATA_GET(data, sd);
908 if (!sd->visible) return;
909 if (sd->list_visible) return;
911 sd->list_visible = EINA_TRUE;
913 evas_object_show(sd->bg);
914 evas_object_show(sd->arrow);
916 elm_layout_sizing_eval(data);
920 _ctxpopup_restack_cb(void *data __UNUSED__,
923 void *event_info __UNUSED__)
925 ELM_CTXPOPUP_DATA_GET(obj, sd);
927 evas_object_layer_set(sd->bg, evas_object_layer_get(obj));
931 _list_del(Elm_Ctxpopup_Smart_Data *sd)
933 if (!sd->list) return;
935 evas_object_del(sd->list);
940 _item_del_pre_hook(Elm_Object_Item *it)
943 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
945 ELM_CTXPOPUP_DATA_GET(WIDGET(ctxpopup_it), sd);
947 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
949 list = elm_object_item_widget_get(ctxpopup_it->list_item);
951 if (eina_list_count(elm_list_items_get(list)) < 2)
953 elm_object_item_del(ctxpopup_it->list_item);
954 evas_object_hide(WIDGET(ctxpopup_it));
959 elm_object_item_del(ctxpopup_it->list_item);
960 if (sd->list_visible) elm_layout_sizing_eval(WIDGET(ctxpopup_it));
966 _elm_ctxpopup_smart_disable(Evas_Object *obj)
968 ELM_CTXPOPUP_DATA_GET(obj, sd);
970 if (!ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->disable(obj))
973 elm_object_disabled_set(sd->list, elm_widget_disabled_get(obj));
979 _elm_ctxpopup_smart_add(Evas_Object *obj)
981 EVAS_SMART_DATA_ALLOC(obj, Elm_Ctxpopup_Smart_Data);
983 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.add(obj);
985 elm_layout_theme_set(obj, "ctxpopup", "base", elm_widget_style_get(obj));
986 elm_layout_signal_callback_add
987 (obj, "elm,action,hide,finished", "", _hide_finished_cb, obj);
990 priv->bg = edje_object_add(evas_object_evas_get(obj));
991 elm_widget_theme_object_set(obj, priv->bg, "ctxpopup", "bg", "default");
992 edje_object_signal_callback_add
993 (priv->bg, "elm,action,click", "", _bg_clicked_cb, obj);
995 evas_object_stack_below(priv->bg, obj);
998 priv->arrow = edje_object_add(evas_object_evas_get(obj));
999 elm_widget_theme_object_set
1000 (obj, priv->arrow, "ctxpopup", "arrow", "default");
1002 priv->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1003 priv->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1004 priv->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1005 priv->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1006 priv->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1008 evas_object_event_callback_add
1009 (obj, EVAS_CALLBACK_RESTACK, _ctxpopup_restack_cb, obj);
1011 priv->box = elm_box_add(obj);
1012 evas_object_size_hint_weight_set
1013 (priv->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1015 evas_object_event_callback_add
1016 (priv->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1018 /* box will be our content placeholder, thus the parent's version call */
1019 ELM_CONTAINER_CLASS(_elm_ctxpopup_parent_sc)->content_set
1020 (obj, "elm.swallow.content", priv->box);
1022 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _on_show, NULL);
1023 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _on_hide, NULL);
1024 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _on_move, NULL);
1026 elm_widget_can_focus_set(obj, EINA_TRUE);
1030 _elm_ctxpopup_smart_del(Evas_Object *obj)
1032 ELM_CTXPOPUP_DATA_GET(obj, sd);
1034 evas_object_event_callback_del_full
1035 (sd->box, EVAS_CALLBACK_RESIZE, _on_content_resized, obj);
1036 _parent_detach(obj);
1038 elm_ctxpopup_clear(obj);
1039 evas_object_del(sd->arrow);
1040 sd->arrow = NULL; /* stops _sizing_eval() from going on on deletion */
1042 evas_object_del(sd->bg);
1045 ELM_WIDGET_CLASS(_elm_ctxpopup_parent_sc)->base.del(obj);
1049 _elm_ctxpopup_smart_parent_set(Evas_Object *obj,
1050 Evas_Object *parent)
1052 //default parent is to be hover parent
1053 elm_ctxpopup_hover_parent_set(obj, parent);
1057 _elm_ctxpopup_smart_set_user(Elm_Ctxpopup_Smart_Class *sc)
1059 ELM_WIDGET_CLASS(sc)->base.add = _elm_ctxpopup_smart_add;
1060 ELM_WIDGET_CLASS(sc)->base.del = _elm_ctxpopup_smart_del;
1062 ELM_WIDGET_CLASS(sc)->parent_set = _elm_ctxpopup_smart_parent_set;
1063 ELM_WIDGET_CLASS(sc)->disable = _elm_ctxpopup_smart_disable;
1064 ELM_WIDGET_CLASS(sc)->event = _elm_ctxpopup_smart_event;
1065 ELM_WIDGET_CLASS(sc)->theme = _elm_ctxpopup_smart_theme;
1066 ELM_WIDGET_CLASS(sc)->sub_object_add = _elm_ctxpopup_smart_sub_object_add;
1067 ELM_WIDGET_CLASS(sc)->focus_next = _elm_ctxpopup_smart_focus_next;
1068 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
1070 ELM_CONTAINER_CLASS(sc)->content_get = _elm_ctxpopup_smart_content_get;
1071 ELM_CONTAINER_CLASS(sc)->content_set = _elm_ctxpopup_smart_content_set;
1072 ELM_CONTAINER_CLASS(sc)->content_unset = _elm_ctxpopup_smart_content_unset;
1074 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_ctxpopup_smart_sizing_eval;
1077 EAPI const Elm_Ctxpopup_Smart_Class *
1078 elm_ctxpopup_smart_class_get(void)
1080 static Elm_Ctxpopup_Smart_Class _sc =
1081 ELM_CTXPOPUP_SMART_CLASS_INIT_NAME_VERSION(ELM_CTXPOPUP_SMART_NAME);
1082 static const Elm_Ctxpopup_Smart_Class *class = NULL;
1083 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
1088 _elm_ctxpopup_smart_set(&_sc);
1089 esc->callbacks = _smart_callbacks;
1096 elm_ctxpopup_add(Evas_Object *parent)
1100 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1102 obj = elm_widget_add(_elm_ctxpopup_smart_class_new(), parent);
1103 if (!obj) return NULL;
1105 if (!elm_widget_sub_object_add(parent, obj))
1106 ERR("could not add %p as sub object of %p", obj, parent);
1112 elm_ctxpopup_hover_parent_set(Evas_Object *obj,
1113 Evas_Object *parent)
1115 Evas_Coord x, y, w, h;
1117 ELM_CTXPOPUP_CHECK(obj);
1118 ELM_CTXPOPUP_DATA_GET(obj, sd);
1120 if (!parent) return;
1122 _parent_detach(obj);
1124 evas_object_event_callback_add
1125 (parent, EVAS_CALLBACK_DEL, _on_parent_del, obj);
1126 evas_object_event_callback_add
1127 (parent, EVAS_CALLBACK_MOVE, _on_parent_move, obj);
1128 evas_object_event_callback_add
1129 (parent, EVAS_CALLBACK_RESIZE, _on_parent_resize, obj);
1131 sd->parent = parent;
1134 evas_object_geometry_get(parent, &x, &y, &w, &h);
1135 evas_object_move(sd->bg, x, y);
1136 evas_object_resize(sd->bg, w, h);
1138 if (sd->visible) elm_layout_sizing_eval(obj);
1142 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1144 ELM_CTXPOPUP_CHECK(obj) NULL;
1145 ELM_CTXPOPUP_DATA_GET(obj, sd);
1151 elm_ctxpopup_clear(Evas_Object *obj)
1153 ELM_CTXPOPUP_CHECK(obj);
1154 ELM_CTXPOPUP_DATA_GET(obj, sd);
1157 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1161 elm_ctxpopup_horizontal_set(Evas_Object *obj,
1162 Eina_Bool horizontal)
1164 ELM_CTXPOPUP_CHECK(obj);
1165 ELM_CTXPOPUP_DATA_GET(obj, sd);
1167 sd->horizontal = !!horizontal;
1169 if (!sd->list) return;
1171 elm_list_horizontal_set(sd->list, sd->horizontal);
1173 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1175 if (sd->visible) elm_layout_sizing_eval(obj);
1179 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1181 ELM_CTXPOPUP_CHECK(obj) EINA_FALSE;
1182 ELM_CTXPOPUP_DATA_GET(obj, sd);
1184 return sd->horizontal;
1187 EAPI Elm_Object_Item *
1188 elm_ctxpopup_item_append(Evas_Object *obj,
1194 Elm_Ctxpopup_Item *item;
1196 ELM_CTXPOPUP_CHECK(obj) NULL;
1197 ELM_CTXPOPUP_DATA_GET(obj, sd);
1199 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1200 if (!item) return NULL;
1202 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1203 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1204 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1205 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1206 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1207 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1208 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1212 //The first item is appended.
1213 sd->list = elm_list_add(obj);
1214 elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
1215 elm_list_horizontal_set(sd->list, sd->horizontal);
1216 evas_object_event_callback_add
1217 (sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
1218 elm_layout_content_set(obj, "default", sd->list);
1222 elm_list_item_append(sd->list, label, icon, NULL, func, data);
1224 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1226 if (sd->visible) elm_layout_sizing_eval(obj);
1228 return (Elm_Object_Item *)item;
1232 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1233 Elm_Ctxpopup_Direction first,
1234 Elm_Ctxpopup_Direction second,
1235 Elm_Ctxpopup_Direction third,
1236 Elm_Ctxpopup_Direction fourth)
1238 ELM_CTXPOPUP_CHECK(obj);
1239 ELM_CTXPOPUP_DATA_GET(obj, sd);
1241 sd->dir_priority[0] = first;
1242 sd->dir_priority[1] = second;
1243 sd->dir_priority[2] = third;
1244 sd->dir_priority[3] = fourth;
1246 if (sd->visible) elm_layout_sizing_eval(obj);
1250 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1251 Elm_Ctxpopup_Direction *first,
1252 Elm_Ctxpopup_Direction *second,
1253 Elm_Ctxpopup_Direction *third,
1254 Elm_Ctxpopup_Direction *fourth)
1256 ELM_CTXPOPUP_CHECK(obj);
1257 ELM_CTXPOPUP_DATA_GET(obj, sd);
1259 if (first) *first = sd->dir_priority[0];
1260 if (second) *second = sd->dir_priority[1];
1261 if (third) *third = sd->dir_priority[2];
1262 if (fourth) *fourth = sd->dir_priority[3];
1265 EAPI Elm_Ctxpopup_Direction
1266 elm_ctxpopup_direction_get(const Evas_Object *obj)
1268 ELM_CTXPOPUP_CHECK(obj) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1269 ELM_CTXPOPUP_DATA_GET(obj, sd);
1275 elm_ctxpopup_dismiss(Evas_Object *obj)
1277 ELM_CTXPOPUP_CHECK(obj);
1278 ELM_CTXPOPUP_DATA_GET(obj, sd);
1280 _hide_signals_emit(obj, sd->dir);