summaryrefslogtreecommitdiff
path: root/legacy/elementary
diff options
context:
space:
mode:
authorcnook <kimcinoo@gmail.com>2012-03-22 10:14:58 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-03-22 10:14:58 +0000
commit047fcff3c303dbf1abdf28a6c96d41720e9cc7cf (patch)
treeba58595c2c7f8496dcbad39a46812aa9b77f0374 /legacy/elementary
parent146f1344139d1e4cbf1056ac92e5c6bb3d7713ef (diff)
From: cnook <kimcinoo@gmail.com>
Subject: [E-devel] [Patch][elementary] elc_ctxpopup using elm_list internally. The patch is for using elm_list as a item controller of elc_ctxpopup. I have learned that there was an opinion to change the internal structure of ctxpopup using the list. It would be able to match up to your expectation. but it is just a draft version of using list in ctxpopup. So, It would be pretty good to me if you give any feedback on this. Thanks. SVN revision: 69561
Diffstat (limited to 'legacy/elementary')
-rw-r--r--legacy/elementary/src/lib/elc_ctxpopup.c426
1 files changed, 111 insertions, 315 deletions
diff --git a/legacy/elementary/src/lib/elc_ctxpopup.c b/legacy/elementary/src/lib/elc_ctxpopup.c
index 6a6fb74aaf..61b57c3b3a 100644
--- a/legacy/elementary/src/lib/elc_ctxpopup.c
+++ b/legacy/elementary/src/lib/elc_ctxpopup.c
@@ -7,9 +7,7 @@ typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
7struct _Elm_Ctxpopup_Item 7struct _Elm_Ctxpopup_Item
8{ 8{
9 ELM_WIDGET_ITEM; 9 ELM_WIDGET_ITEM;
10 const char *label; 10 Elm_Object_Item *list_item;
11 Evas_Object *icon;
12 Evas_Smart_Cb func;
13}; 11};
14 12
15struct _Widget_Data 13struct _Widget_Data
@@ -17,16 +15,15 @@ struct _Widget_Data
17 Evas_Object *parent; 15 Evas_Object *parent;
18 Evas_Object *base; 16 Evas_Object *base;
19 Evas_Object *content; 17 Evas_Object *content;
18 Evas_Object *list;
20 Evas_Object *box; 19 Evas_Object *box;
21 Evas_Object *arrow; 20 Evas_Object *arrow;
22 Evas_Object *scr;
23 Evas_Object *bg; 21 Evas_Object *bg;
24 Eina_List *items;
25 Elm_Ctxpopup_Direction dir; 22 Elm_Ctxpopup_Direction dir;
26 Elm_Ctxpopup_Direction dir_priority[4]; 23 Elm_Ctxpopup_Direction dir_priority[4];
27 Evas_Coord max_sc_w, max_sc_h;
28 Eina_Bool horizontal:1; 24 Eina_Bool horizontal:1;
29 Eina_Bool visible:1; 25 Eina_Bool visible:1;
26 Eina_Bool list_visible:1;
30 Eina_Bool finished:1; 27 Eina_Bool finished:1;
31}; 28};
32 29
@@ -36,7 +33,6 @@ static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
36static void _freeze_off(void *data, Evas_Object *obj, void *event_info); 33static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
37static void _hold_on(void *data, Evas_Object *obj, void *event_info); 34static void _hold_on(void *data, Evas_Object *obj, void *event_info);
38static void _hold_off(void *data, Evas_Object *obj, void *event_info); 35static void _hold_off(void *data, Evas_Object *obj, void *event_info);
39static void _scroller_size_reset(Widget_Data *wd);
40static void _on_focus_hook(void *data, Evas_Object *obj); 36static void _on_focus_hook(void *data, Evas_Object *obj);
41static Eina_Bool _event_hook(Evas_Object *obj, 37static Eina_Bool _event_hook(Evas_Object *obj,
42 Evas_Object *src, 38 Evas_Object *src,
@@ -55,7 +51,6 @@ static void _parent_del(void *data,
55 Evas *e, 51 Evas *e,
56 Evas_Object *obj, 52 Evas_Object *obj,
57 void *event_info); 53 void *event_info);
58static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59static void _adjust_pos_x(Evas_Coord_Point *pos, 54static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size, 55 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area); 56 Evas_Coord_Rectangle *hover_area);
@@ -118,28 +113,16 @@ static void _content_resize(void *data,
118 Evas *e, 113 Evas *e,
119 Evas_Object *obj, 114 Evas_Object *obj,
120 void *event_info); 115 void *event_info);
121static void _scroller_resize(void *data,
122 Evas *e,
123 Evas_Object *obj,
124 void *event_info);
125static void _ctxpopup_move(void *data, 116static void _ctxpopup_move(void *data,
126 Evas *e, 117 Evas *e,
127 Evas_Object *obj, 118 Evas_Object *obj,
128 void *event_info); 119 void *event_info);
129static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info); 120static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
130static void _item_select_cb(void *data, Evas_Object *obj,
131 const char *emission,
132 const char *source);
133static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
134static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
135static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
136static void _content_del(void *data, 121static void _content_del(void *data,
137 Evas *e, 122 Evas *e,
138 Evas_Object *obj, 123 Evas_Object *obj,
139 void *event_info); 124 void *event_info);
140static void _list_del(Widget_Data *wd); 125static void _list_del(Widget_Data *wd);
141static void _list_new(Evas_Object *obj);
142static void _remove_items(Widget_Data * wd);
143static void _disable_hook(Evas_Object *obj); 126static void _disable_hook(Evas_Object *obj);
144static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source); 127static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
145static void _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data); 128static void _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
@@ -158,8 +141,8 @@ _freeze_on(void *data __UNUSED__, Evas_Object *obj,
158{ 141{
159 Widget_Data *wd = elm_widget_data_get(obj); 142 Widget_Data *wd = elm_widget_data_get(obj);
160 143
161 if ((!wd) || (!wd->scr)) return; 144 if ((!wd) || (!wd->list)) return;
162 elm_object_scroll_freeze_push(wd->scr); 145 elm_widget_scroll_freeze_push(wd->list);
163} 146}
164 147
165static void 148static void
@@ -168,8 +151,8 @@ _freeze_off(void *data __UNUSED__, Evas_Object *obj,
168{ 151{
169 Widget_Data *wd = elm_widget_data_get(obj); 152 Widget_Data *wd = elm_widget_data_get(obj);
170 153
171 if ((!wd) || (!wd->scr)) return; 154 if ((!wd) || (!wd->list)) return;
172 elm_object_scroll_freeze_pop(wd->scr); 155 elm_widget_scroll_freeze_pop(wd->list);
173} 156}
174 157
175static void 158static void
@@ -177,8 +160,8 @@ _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
177{ 160{
178 Widget_Data *wd = elm_widget_data_get(obj); 161 Widget_Data *wd = elm_widget_data_get(obj);
179 162
180 if ((!wd) || (!wd->scr)) return; 163 if ((!wd) || (!wd->list)) return;
181 elm_object_scroll_hold_push(wd->scr); 164 elm_widget_scroll_hold_push(wd->list);
182} 165}
183 166
184static void 167static void
@@ -186,16 +169,8 @@ _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
186{ 169{
187 Widget_Data *wd = elm_widget_data_get(obj); 170 Widget_Data *wd = elm_widget_data_get(obj);
188 171
189 if ((!wd) || (!wd->scr)) return; 172 if ((!wd) || (!wd->list)) return;
190 elm_object_scroll_hold_pop(wd->scr); 173 elm_widget_scroll_hold_pop(wd->list);
191}
192
193static void
194_scroller_size_reset(Widget_Data *wd)
195{
196 wd->finished = EINA_FALSE;
197 wd->max_sc_h = -1;
198 wd->max_sc_w = -1;
199} 174}
200 175
201static void 176static void
@@ -204,6 +179,7 @@ _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
204 Widget_Data *wd = elm_widget_data_get(obj); 179 Widget_Data *wd = elm_widget_data_get(obj);
205 if (!wd) return; 180 if (!wd) return;
206 181
182
207 if (elm_widget_focus_get(obj)) 183 if (elm_widget_focus_get(obj))
208 { 184 {
209 //FIXME: 185 //FIXME:
@@ -286,7 +262,6 @@ _parent_move(void *data,
286 262
287 if (wd->visible) 263 if (wd->visible)
288 { 264 {
289 _scroller_size_reset(wd);
290 _sizing_eval(obj); 265 _sizing_eval(obj);
291 } 266 }
292} 267}
@@ -301,19 +276,6 @@ _parent_del(void *data,
301} 276}
302 277
303static void 278static void
304_item_sizing_eval(Elm_Ctxpopup_Item *item)
305{
306 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
307
308 if (!item) return;
309
310 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
311 min_h);
312 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
313 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
314}
315
316static void
317_adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size, 279_adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
318 Evas_Coord_Rectangle *hover_area) 280 Evas_Coord_Rectangle *hover_area)
319{ 281{
@@ -394,6 +356,7 @@ _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
394 if ((max_size.x > 0) && (base_size.x > max_size.x)) 356 if ((max_size.x > 0) && (base_size.x > max_size.x))
395 base_size.x = max_size.x; 357 base_size.x = max_size.x;
396 358
359
397 //Limit to Min Size 360 //Limit to Min Size
398 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y); 361 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
399 362
@@ -453,7 +416,7 @@ _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
453 { 416 {
454 Evas_Coord length[2]; 417 Evas_Coord length[2];
455 418
456 if(!wd->horizontal) 419 if (!wd->horizontal)
457 { 420 {
458 length[0] = pos.y - hover_area.y; 421 length[0] = pos.y - hover_area.y;
459 length[1] = (hover_area.y + hover_area.h) - pos.y; 422 length[1] = (hover_area.y + hover_area.h) - pos.y;
@@ -538,7 +501,7 @@ _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
538 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w, 501 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
539 &arrow_size.h); 502 &arrow_size.h);
540 503
541 edje_object_part_unswallow(wd->base, wd->arrow); 504 //edje_object_part_unswallow(wd->base, wd->arrow);
542 505
543 switch (dir) 506 switch (dir)
544 { 507 {
@@ -622,6 +585,9 @@ _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
622 default: 585 default:
623 break; 586 break;
624 } 587 }
588
589 //should be here for getting accurate geometry value
590 evas_object_smart_calculate(wd->base);
625} 591}
626 592
627static void 593static void
@@ -659,7 +625,8 @@ _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
659 Widget_Data *wd; 625 Widget_Data *wd;
660 626
661 wd = elm_widget_data_get(obj); 627 wd = elm_widget_data_get(obj);
662 if (wd->visible) return; 628 if (!wd->visible) return;
629 if ((wd->list) && (!wd->list_visible)) return;
663 630
664 switch (dir) 631 switch (dir)
665 { 632 {
@@ -678,60 +645,39 @@ _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
678 default: 645 default:
679 break; 646 break;
680 } 647 }
648 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
649 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
681} 650}
682 651
683static void 652static void
684_sizing_eval(Evas_Object *obj) 653_sizing_eval(Evas_Object *obj)
685{ 654{
686 Widget_Data *wd; 655 Widget_Data *wd;
687 Eina_List *elist;
688 Elm_Ctxpopup_Item *item;
689 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 }; 656 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
690 Evas_Coord_Point box_size = { 0, 0 }; 657 Evas_Coord_Point list_size = { 0, 0 };
691 Evas_Coord_Point _box_size = { 0, 0 };
692 658
693 wd = elm_widget_data_get(obj); 659 wd = elm_widget_data_get(obj);
694 if (!wd) return; 660 if (!wd) return;
695 661
696 //Box, Scroller
697 EINA_LIST_FOREACH(wd->items, elist, item)
698 {
699 _item_sizing_eval(item);
700 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
701 if (!wd->horizontal)
702 {
703 if (_box_size.x > box_size.x)
704 box_size.x = _box_size.x;
705 if (_box_size.y != -1)
706 box_size.y += _box_size.y;
707 }
708 else
709 {
710 if (_box_size.x != -1)
711 box_size.x += _box_size.x;
712 if (_box_size.y > box_size.y)
713 box_size.y = _box_size.y;
714 }
715 }
716
717 if (!wd->content)
718 {
719 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
720 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
721 }
722
723 //Base 662 //Base
724 wd->dir = _calc_base_geometry(obj, &rect); 663 wd->dir = _calc_base_geometry(obj, &rect);
725 _show_signal_emit(obj, wd->dir);
726 _update_arrow(obj, wd->dir, rect); 664 _update_arrow(obj, wd->dir, rect);
727 _shift_base_by_arrow(wd->arrow, wd->dir, &rect); 665 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
728 666
729 //resize scroller according to final size. 667 if ((wd->list) && (wd->list_visible))
730 if (!wd->content) 668 {
731 evas_object_smart_calculate(wd->scr); 669 evas_object_geometry_get(wd->list, 0, 0, &list_size.x, &list_size.y);
670 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
671 {
672 elm_list_mode_set(wd->list, ELM_LIST_COMPRESS);
673 evas_object_size_hint_min_set(wd->box, rect.w, rect.h);
674 evas_object_size_hint_min_set(obj, rect.w, rect.h);
675 }
676 }
732 677
733 evas_object_move(wd->base, rect.x, rect.y); 678 evas_object_move(wd->base, rect.x, rect.y);
734 evas_object_resize(wd->base, rect.w, rect.h); 679 evas_object_resize(wd->base, rect.w, rect.h);
680 _show_signal_emit(obj, wd->dir);
735} 681}
736 682
737static void 683static void
@@ -741,7 +687,6 @@ _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
741 Evas_Coord arrow_w, arrow_h; 687 Evas_Coord arrow_w, arrow_h;
742 688
743 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h); 689 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
744
745 switch (dir) 690 switch (dir)
746 { 691 {
747 case ELM_CTXPOPUP_DIRECTION_RIGHT: 692 case ELM_CTXPOPUP_DIRECTION_RIGHT:
@@ -793,8 +738,6 @@ static void
793_theme_hook(Evas_Object *obj) 738_theme_hook(Evas_Object *obj)
794{ 739{
795 Widget_Data *wd; 740 Widget_Data *wd;
796 Eina_List *elist;
797 Elm_Ctxpopup_Item *item;
798 Eina_Bool rtl; 741 Eina_Bool rtl;
799 742
800 wd = elm_widget_data_get(obj); 743 wd = elm_widget_data_get(obj);
@@ -810,43 +753,18 @@ _theme_hook(Evas_Object *obj)
810 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", 753 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
811 elm_widget_style_get(obj)); 754 elm_widget_style_get(obj));
812 755
813 //Items 756 if (wd->list)
814 EINA_LIST_FOREACH(wd->items, elist, item)
815 {
816 edje_object_mirrored_set(VIEW(item), rtl);
817
818 if (item->label && item->icon)
819 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
820 "icon_text_style_item",
821 elm_widget_style_get(obj));
822 else if (item->label)
823 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
824 elm_widget_style_get(obj));
825 else if (item->icon)
826 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
827 elm_widget_style_get(obj));
828 if (item->label)
829 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
830
831 if (elm_widget_item_disabled_get(item))
832 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
833
834 edje_object_message_signal_process(VIEW(item));
835 }
836
837 if (wd->scr)
838 { 757 {
839 if (!strncmp(elm_object_style_get(obj), "default", strlen("default"))) 758 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
840 elm_object_style_set(wd->scr, "ctxpopup"); 759 elm_object_style_set(wd->list, "ctxpopup");
841 else 760 else
842 elm_object_style_set(wd->scr, elm_object_style_get(obj)); 761 elm_object_style_set(wd->list, elm_object_style_get(obj));
843 } 762 }
844 763
845 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 764 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
846 765
847 if (wd->visible) 766 if (wd->visible)
848 { 767 {
849 _scroller_size_reset(wd);
850 _sizing_eval(obj); 768 _sizing_eval(obj);
851 } 769 }
852} 770}
@@ -859,12 +777,12 @@ _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
859 777
860 Widget_Data *wd; 778 Widget_Data *wd;
861 779
862 if (part && strcmp(part, "default")) return; 780 if ((part) && (strcmp(part, "default"))) return;
863 781
864 wd = elm_widget_data_get(obj); 782 wd = elm_widget_data_get(obj);
865 if ((!wd) || (!content)) return; 783 if ((!wd) || (!content)) return;
866 784
867 if (wd->items) elm_ctxpopup_clear(obj); 785 //TODO: wd->list
868 if (wd->content) evas_object_del(wd->content); 786 if (wd->content) evas_object_del(wd->content);
869 787
870 //Use Box 788 //Use Box
@@ -902,12 +820,12 @@ _content_unset_hook(Evas_Object *obj, const char *part)
902 820
903 Widget_Data *wd; 821 Widget_Data *wd;
904 Evas_Object *content; 822 Evas_Object *content;
905 if (part && strcmp(part, "default")) return NULL; 823 if ((part) && (strcmp(part, "default"))) return NULL;
906 wd = elm_widget_data_get(obj); 824 wd = elm_widget_data_get(obj);
907 if (!wd) return NULL; 825 if (!wd) return NULL;
908 826
909 content = wd->content; 827 content = wd->content;
910 if (!content || !wd->box) return NULL; 828 if ((!content) || (!wd->box)) return NULL;
911 829
912 edje_object_part_unswallow(wd->base, wd->box); 830 edje_object_part_unswallow(wd->base, wd->box);
913 elm_widget_sub_object_del(obj, wd->box); 831 elm_widget_sub_object_del(obj, wd->box);
@@ -927,7 +845,7 @@ _content_get_hook(const Evas_Object *obj, const char *part)
927{ 845{
928 ELM_CHECK_WIDTYPE(obj, widtype) NULL; 846 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
929 Widget_Data *wd; 847 Widget_Data *wd;
930 if (part && strcmp(part, "default")) return NULL; 848 if ((part) && (strcmp(part, "default"))) return NULL;
931 wd = elm_widget_data_get(obj); 849 wd = elm_widget_data_get(obj);
932 if (!wd) return NULL; 850 if (!wd) return NULL;
933 return wd->content; 851 return wd->content;
@@ -939,19 +857,18 @@ _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
939 Widget_Data *wd; 857 Widget_Data *wd;
940 Elm_Ctxpopup_Item *ctxpopup_it; 858 Elm_Ctxpopup_Item *ctxpopup_it;
941 859
942 if (part && strcmp(part, "default")) return; 860 if ((part) && (strcmp(part, "default"))) return;
943 861
944 ctxpopup_it = (Elm_Ctxpopup_Item *)it; 862 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
945 863
946 wd = elm_widget_data_get(WIDGET(ctxpopup_it)); 864 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
947 if (!wd) return; 865 if (!wd) return;
948 866
949 _item_label_set(ctxpopup_it, label); 867 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
950 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 868 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
951 869
952 if (wd->visible) 870 if (wd->visible)
953 { 871 {
954 _scroller_size_reset(wd);
955 _sizing_eval(WIDGET(ctxpopup_it)); 872 _sizing_eval(WIDGET(ctxpopup_it));
956 } 873 }
957} 874}
@@ -962,7 +879,7 @@ _item_text_get_hook(const Elm_Object_Item *it, const char *part)
962 Elm_Ctxpopup_Item *ctxpopup_it; 879 Elm_Ctxpopup_Item *ctxpopup_it;
963 if (part && strcmp(part, "default")) return NULL; 880 if (part && strcmp(part, "default")) return NULL;
964 ctxpopup_it = (Elm_Ctxpopup_Item *)it; 881 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
965 return ctxpopup_it->label; 882 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
966} 883}
967 884
968static void 885static void
@@ -973,19 +890,24 @@ _item_content_set_hook(Elm_Object_Item *it,
973 Widget_Data *wd; 890 Widget_Data *wd;
974 Elm_Ctxpopup_Item *ctxpopup_it; 891 Elm_Ctxpopup_Item *ctxpopup_it;
975 892
976 if (part && strcmp(part, "icon")) return; 893 if ((part) && (strcmp(part, "icon"))
894 && (strcmp(part, "start"))
895 && (strcmp(part, "end"))) return;
977 896
978 ctxpopup_it = (Elm_Ctxpopup_Item *)it; 897 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
979 898
980 wd = elm_widget_data_get(WIDGET(ctxpopup_it)); 899 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
981 if (!wd) return; 900 if (!wd) return;
982 901
983 _item_icon_set(ctxpopup_it, content); 902 if ((part) && (!strcmp(part, "end")))
903 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
904 else
905 elm_object_item_part_content_set(ctxpopup_it->list_item, "start", content);
906
984 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 907 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
985 908
986 if (wd->visible) 909 if (wd->visible)
987 { 910 {
988 _scroller_size_reset(wd);
989 _sizing_eval(WIDGET(ctxpopup_it)); 911 _sizing_eval(WIDGET(ctxpopup_it));
990 } 912 }
991} 913}
@@ -994,9 +916,16 @@ static Evas_Object *
994_item_content_get_hook(const Elm_Object_Item *it, const char *part) 916_item_content_get_hook(const Elm_Object_Item *it, const char *part)
995{ 917{
996 Elm_Ctxpopup_Item *ctxpopup_it; 918 Elm_Ctxpopup_Item *ctxpopup_it;
997 if (part && strcmp(part, "icon")) return NULL; 919
920 if (part && strcmp(part, "icon") && strcmp(part, "start")
921 && strcmp(part, "end")) return NULL;
922
998 ctxpopup_it = (Elm_Ctxpopup_Item *)it; 923 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
999 return ctxpopup_it->icon; 924
925 if (part && !strcmp(part, "end"))
926 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
927 else
928 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
1000} 929}
1001 930
1002static void 931static void
@@ -1008,10 +937,8 @@ _item_disable_hook(Elm_Object_Item *it)
1008 wd = elm_widget_data_get(WIDGET(ctxpopup_it)); 937 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1009 if (!wd) return; 938 if (!wd) return;
1010 939
1011 if (elm_widget_item_disabled_get(it)) 940 elm_object_item_disabled_set(ctxpopup_it->list_item,
1012 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm"); 941 elm_widget_item_disabled_get(ctxpopup_it));
1013 else
1014 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1015} 942}
1016 943
1017static void 944static void
@@ -1019,7 +946,7 @@ _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
1019 const char *source) 946 const char *source)
1020{ 947{
1021 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it; 948 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1022 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source); 949 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
1023} 950}
1024 951
1025static void 952static void
@@ -1040,7 +967,14 @@ _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1040 wd = elm_widget_data_get(obj); 967 wd = elm_widget_data_get(obj);
1041 if (!wd) return; 968 if (!wd) return;
1042 969
1043 if ((!wd->items) && (!wd->content)) return; 970 if ((!wd->list) && (!wd->content)) return;
971
972 if (wd->list)
973 {
974 elm_list_go(wd->list);
975 wd->visible = EINA_TRUE;
976 return;
977 }
1044 978
1045 wd->visible = EINA_TRUE; 979 wd->visible = EINA_TRUE;
1046 980
@@ -1075,9 +1009,8 @@ _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1075 evas_object_hide(wd->arrow); 1009 evas_object_hide(wd->arrow);
1076 evas_object_hide(wd->base); 1010 evas_object_hide(wd->base);
1077 1011
1078 _scroller_size_reset(wd);
1079
1080 wd->visible = EINA_FALSE; 1012 wd->visible = EINA_FALSE;
1013 wd->list_visible = EINA_FALSE;
1081} 1014}
1082 1015
1083static void 1016static void
@@ -1091,35 +1024,20 @@ _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1091} 1024}
1092 1025
1093static void 1026static void
1094_scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, 1027_list_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1095 void *event_info __UNUSED__) 1028 void *event_info __UNUSED__)
1096{ 1029{
1097 Widget_Data *wd; 1030 Widget_Data *wd = elm_widget_data_get(data);
1098 Evas_Coord w, h;
1099
1100 wd = elm_widget_data_get(data);
1101 if (!wd) return; 1031 if (!wd) return;
1102 if (!wd->visible) return; 1032 if (!wd->visible) return;
1103 if (wd->finished) return; 1033 if (wd->list_visible) return;
1104 1034
1105 evas_object_geometry_get(obj, 0, 0, &w, &h); 1035 wd->list_visible = EINA_TRUE;
1106 1036
1107 if (w != 0 && h != 0) 1037 evas_object_show(wd->bg);
1108 { 1038 evas_object_show(wd->base);
1109 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h)) 1039 evas_object_show(wd->arrow);
1110 { 1040 _sizing_eval(obj);
1111 _sizing_eval(data);
1112 wd->finished = EINA_TRUE;
1113 return;
1114 }
1115 }
1116
1117 if (wd->max_sc_w < w)
1118 wd->max_sc_w = w;
1119 if (wd->max_sc_h < h)
1120 wd->max_sc_h = h;
1121
1122 _sizing_eval(data);
1123} 1041}
1124 1042
1125static void 1043static void
@@ -1135,7 +1053,6 @@ _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1135 if (wd->visible) 1053 if (wd->visible)
1136 evas_object_show(wd->arrow); 1054 evas_object_show(wd->arrow);
1137 1055
1138 _scroller_size_reset(wd);
1139 _sizing_eval(obj); 1056 _sizing_eval(obj);
1140} 1057}
1141 1058
@@ -1151,60 +1068,6 @@ _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *even
1151} 1068}
1152 1069
1153static void 1070static void
1154_item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1155 const char *emission __UNUSED__, const char *source __UNUSED__)
1156{
1157 Elm_Ctxpopup_Item *item = data;
1158
1159 if (!item) return;
1160 if (elm_widget_item_disabled_get(item)) return;
1161
1162 if (item->func)
1163 item->func((void*)item->base.data, WIDGET(item), data);
1164}
1165
1166static void
1167_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1168{
1169 if (item->icon)
1170 evas_object_del(item->icon);
1171
1172 item->icon = icon;
1173 if (!icon) return;
1174
1175 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1176 edje_object_message_signal_process(VIEW(item));
1177}
1178
1179static void
1180_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1181{
1182 if (!eina_stringshare_replace(&item->label, label))
1183 return;
1184
1185 edje_object_part_text_set(VIEW(item), "elm.text", label);
1186 edje_object_message_signal_process(VIEW(item));
1187}
1188
1189static void
1190_item_new(Elm_Ctxpopup_Item *item, char *group_name)
1191{
1192 Widget_Data *wd;
1193
1194 wd = elm_widget_data_get(WIDGET(item));
1195 if (!wd) return;
1196
1197 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1198 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1199 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1200 elm_widget_style_get(WIDGET(item)));
1201 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1202 _item_select_cb, item);
1203 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1204 evas_object_show(VIEW(item));
1205}
1206
1207static void
1208_content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, 1071_content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1209 void *event_info __UNUSED__) 1072 void *event_info __UNUSED__)
1210{ 1073{
@@ -1214,86 +1077,38 @@ _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1214static void 1077static void
1215_list_del(Widget_Data *wd) 1078_list_del(Widget_Data *wd)
1216{ 1079{
1217 if (!wd->scr) return; 1080 if (!wd->list) return;
1218 1081
1219 edje_object_part_unswallow(wd->base, wd->scr); 1082 edje_object_part_unswallow(wd->base, wd->box);
1220 evas_object_del(wd->scr); 1083 elm_box_unpack(wd->box, wd->list);
1221 wd->scr = NULL; 1084 evas_object_del(wd->list);
1085 wd->list = NULL;
1222 wd->box = NULL; 1086 wd->box = NULL;
1223} 1087}
1224 1088
1225static void
1226_list_new(Evas_Object *obj)
1227{
1228 Widget_Data *wd;
1229 wd = elm_widget_data_get(obj);
1230 if (!wd) return;
1231
1232 //scroller
1233 wd->scr = elm_scroller_add(obj);
1234 elm_object_style_set(wd->scr, "ctxpopup");
1235 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1236 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1237 _scroller_resize, obj);
1238 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1239
1240 //box
1241 wd->box = elm_box_add(obj);
1242 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1243 EVAS_HINT_EXPAND);
1244
1245 elm_object_content_set(wd->scr, wd->box);
1246 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1247}
1248
1249static void
1250_remove_items(Widget_Data *wd)
1251{
1252 Eina_List *elist;
1253 Elm_Ctxpopup_Item *item;
1254
1255 if (!wd->items) return;
1256
1257 EINA_LIST_FOREACH(wd->items, elist, item)
1258 {
1259 if (item->label)
1260 eina_stringshare_del(item->label);
1261 if (item->icon)
1262 evas_object_del(item->icon);
1263 wd->items = eina_list_remove(wd->items, item);
1264 elm_widget_item_free(item);
1265 }
1266
1267 wd->items = NULL;
1268}
1269
1270static Eina_Bool 1089static Eina_Bool
1271_item_del_pre_hook(Elm_Object_Item *it) 1090_item_del_pre_hook(Elm_Object_Item *it)
1272{ 1091{
1092 Evas_Object *list;
1273 Widget_Data *wd; 1093 Widget_Data *wd;
1274 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it; 1094 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1275 1095
1276 wd = elm_widget_data_get(WIDGET(ctxpopup_it)); 1096 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1277 if (!wd) return EINA_FALSE; 1097 if (!wd) return EINA_FALSE;
1278 1098
1279 if (ctxpopup_it->icon)
1280 evas_object_del(ctxpopup_it->icon);
1281 if (VIEW(ctxpopup_it))
1282 evas_object_del(VIEW(ctxpopup_it));
1283
1284 eina_stringshare_del(ctxpopup_it->label);
1285
1286 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1287
1288 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 1099 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1289 1100
1290 if (eina_list_count(wd->items) < 1) 1101 list = elm_object_item_widget_get(ctxpopup_it->list_item);
1102
1103 if (eina_list_count(elm_list_items_get(list)) < 2)
1291 { 1104 {
1105 elm_object_item_del(ctxpopup_it->list_item);
1292 evas_object_hide(WIDGET(ctxpopup_it)); 1106 evas_object_hide(WIDGET(ctxpopup_it));
1293 return EINA_TRUE; 1107 return EINA_TRUE;
1294 } 1108 }
1295 1109
1296 if (wd->visible) 1110 elm_object_item_del(ctxpopup_it->list_item);
1111 if (wd->list_visible)
1297 _sizing_eval(WIDGET(ctxpopup_it)); 1112 _sizing_eval(WIDGET(ctxpopup_it));
1298 1113
1299 return EINA_TRUE; 1114 return EINA_TRUE;
@@ -1302,14 +1117,11 @@ _item_del_pre_hook(Elm_Object_Item *it)
1302static void 1117static void
1303_disable_hook(Evas_Object *obj) 1118_disable_hook(Evas_Object *obj)
1304{ 1119{
1305 Eina_List *l; 1120 //TODO: elm_object_disabled_set(); does not ignite this part
1306 Elm_Object_Item *it;
1307
1308 Widget_Data *wd = elm_widget_data_get(obj); 1121 Widget_Data *wd = elm_widget_data_get(obj);
1309 if (!wd) return; 1122 if (!wd) return;
1310 1123
1311 EINA_LIST_FOREACH(wd->items, l, it) 1124 elm_object_disabled_set(wd->list, elm_widget_disabled_get(obj));
1312 elm_object_item_disabled_set(it, elm_widget_disabled_get(obj));
1313} 1125}
1314 1126
1315static void 1127static void
@@ -1470,7 +1282,6 @@ elm_ctxpopup_clear(Evas_Object * obj)
1470 Widget_Data *wd = elm_widget_data_get(obj); 1282 Widget_Data *wd = elm_widget_data_get(obj);
1471 if (!wd) return; 1283 if (!wd) return;
1472 1284
1473 _remove_items(wd);
1474 _list_del(wd); 1285 _list_del(wd);
1475 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 1286 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1476} 1287}
@@ -1487,18 +1298,16 @@ elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1487 1298
1488 wd->horizontal = !!horizontal; 1299 wd->horizontal = !!horizontal;
1489 1300
1490 if ((!wd->scr) && (!wd->box)) 1301 if ((!wd->list))
1491 return; 1302 return;
1492 1303
1493 if (!horizontal) 1304 if (!horizontal)
1494 { 1305 {
1495 elm_box_horizontal_set(wd->box, EINA_FALSE); 1306 elm_list_horizontal_set(wd->list, wd->horizontal);
1496 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1497 } 1307 }
1498 else 1308 else
1499 { 1309 {
1500 elm_box_horizontal_set(wd->box, EINA_TRUE); 1310 elm_list_horizontal_set(wd->list, wd->horizontal);
1501 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1502 } 1311 }
1503 1312
1504 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 1313 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
@@ -1528,7 +1337,6 @@ elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1528 ELM_CHECK_WIDTYPE(obj, widtype) NULL; 1337 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1529 1338
1530 Widget_Data *wd; 1339 Widget_Data *wd;
1531 Evas_Object *content;
1532 Elm_Ctxpopup_Item *item; 1340 Elm_Ctxpopup_Item *item;
1533 1341
1534 wd = elm_widget_data_get(obj); 1342 wd = elm_widget_data_get(obj);
@@ -1545,34 +1353,22 @@ elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1545 elm_widget_item_content_get_hook_set(item, _item_content_get_hook); 1353 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1546 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook); 1354 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1547 1355
1548 //The first item is appended. 1356 if (!wd->list)
1549 content = elm_object_content_unset(obj); 1357 {
1550 if (content) evas_object_del(content); 1358 //The first item is appended.
1551 1359 wd->list = elm_list_add(obj);
1552 if (!wd->items) 1360 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1553 _list_new(obj); 1361 elm_list_horizontal_set(wd->list, wd->horizontal);
1554 1362 evas_object_event_callback_add(wd->list, EVAS_CALLBACK_RESIZE,
1555 item->func = func; 1363 _list_resize, obj);
1556 item->base.data = data; 1364 _content_set_hook(obj, "default", wd->list);
1365 }
1557 1366
1558 if (icon && label) 1367 item->list_item = elm_list_item_append(wd->list, label, icon, NULL, func, data);
1559 _item_new(item, "icon_text_style_item");
1560 else if (label)
1561 _item_new(item, "text_style_item");
1562 else
1563 _item_new(item, "icon_style_item");
1564 1368
1565 _item_icon_set(item, icon);
1566 _item_label_set(item, label);
1567 elm_box_pack_end(wd->box, VIEW(item));
1568 wd->items = eina_list_append(wd->items, item);
1569 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; 1369 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1570 1370
1571 if (wd->visible) 1371 if (wd->visible) _sizing_eval(obj);
1572 {
1573 _scroller_size_reset(wd);
1574 _sizing_eval(obj);
1575 }
1576 1372
1577 return (Elm_Object_Item *)item; 1373 return (Elm_Object_Item *)item;
1578} 1374}