summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-10-24 16:53:18 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-25 22:54:52 +0900
commit585be9e24f10d683b955be43a31632ac7067cbd2 (patch)
treef2ba0c4ed4a424634bed22ca09b919d85a12eff8
parent6c8ca79ff2dabbf905952a7a073589fa2a72eef4 (diff)
genlist: Simplify some logic
Item prev/next/first/last. If true, break, else, break. EO_OBJ(x) is safe on NULL. Add a simple macro to simplify inlist handling. Overall simplify the code.
-rw-r--r--src/lib/elementary/elm_gen_common.h3
-rw-r--r--src/lib/elementary/elm_genlist.c101
2 files changed, 28 insertions, 76 deletions
diff --git a/src/lib/elementary/elm_gen_common.h b/src/lib/elementary/elm_gen_common.h
index c980819e24..3c795a2e1c 100644
--- a/src/lib/elementary/elm_gen_common.h
+++ b/src/lib/elementary/elm_gen_common.h
@@ -7,6 +7,9 @@
7#define ELM_GEN_ITEM_FROM_INLIST(it) \ 7#define ELM_GEN_ITEM_FROM_INLIST(it) \
8 ((it) ? EINA_INLIST_CONTAINER_GET(it, Elm_Gen_Item) : NULL) 8 ((it) ? EINA_INLIST_CONTAINER_GET(it, Elm_Gen_Item) : NULL)
9 9
10#define ELM_GEN_ITEM_PREV(_it) ((_it) ? ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->prev) : NULL)
11#define ELM_GEN_ITEM_NEXT(_it) ((_it) ? ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->next) : NULL)
12
10#define SWIPE_MOVES 12 13#define SWIPE_MOVES 12
11 14
12/* common item handles for genlist/gengrid */ 15/* common item handles for genlist/gengrid */
diff --git a/src/lib/elementary/elm_genlist.c b/src/lib/elementary/elm_genlist.c
index c03ab105c6..a0706abc2b 100644
--- a/src/lib/elementary/elm_genlist.c
+++ b/src/lib/elementary/elm_genlist.c
@@ -2608,7 +2608,7 @@ _item_multi_select_up(Elm_Genlist_Data *sd)
2608 if ((!_is_no_select(prev)) && 2608 if ((!_is_no_select(prev)) &&
2609 (!elm_object_item_disabled_get(eo_prev)) && (!prev->hide)) 2609 (!elm_object_item_disabled_get(eo_prev)) && (!prev->hide))
2610 break; 2610 break;
2611 eo_prev = EO_OBJ(ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev)); 2611 eo_prev = EO_OBJ(ELM_GEN_ITEM_PREV(prev));
2612 } 2612 }
2613 if (!eo_prev) return EINA_TRUE; 2613 if (!eo_prev) return EINA_TRUE;
2614 2614
@@ -2639,7 +2639,7 @@ _item_multi_select_down(Elm_Genlist_Data *sd)
2639 if ((!_is_no_select(next)) && 2639 if ((!_is_no_select(next)) &&
2640 (!elm_object_item_disabled_get(eo_next)) && (!next->hide)) 2640 (!elm_object_item_disabled_get(eo_next)) && (!next->hide))
2641 break; 2641 break;
2642 eo_next = EO_OBJ(ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next)); 2642 eo_next = EO_OBJ(ELM_GEN_ITEM_NEXT(next));
2643 } 2643 }
2644 if (!eo_next) return EINA_TRUE; 2644 if (!eo_next) return EINA_TRUE;
2645 2645
@@ -2692,7 +2692,7 @@ _item_single_select_up(Elm_Genlist_Data *sd)
2692 if ((!_is_no_select(prev)) && 2692 if ((!_is_no_select(prev)) &&
2693 (!elm_object_item_disabled_get(EO_OBJ(prev))) && (!prev->hide)) 2693 (!elm_object_item_disabled_get(EO_OBJ(prev))) && (!prev->hide))
2694 break; 2694 break;
2695 prev = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev); 2695 prev = ELM_GEN_ITEM_PREV(prev);
2696 } 2696 }
2697 2697
2698 if (!prev) return EINA_FALSE; 2698 if (!prev) return EINA_FALSE;
@@ -2722,7 +2722,7 @@ _item_single_select_down(Elm_Genlist_Data *sd)
2722 if ((!_is_no_select(next)) && 2722 if ((!_is_no_select(next)) &&
2723 (!elm_object_item_disabled_get(EO_OBJ(next))) && (!next->hide)) 2723 (!elm_object_item_disabled_get(EO_OBJ(next))) && (!next->hide))
2724 break; 2724 break;
2725 next = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next); 2725 next = ELM_GEN_ITEM_NEXT(next);
2726 } 2726 }
2727 2727
2728 if (!next) return EINA_FALSE; 2728 if (!next) return EINA_FALSE;
@@ -2818,7 +2818,7 @@ _item_focused_next(Evas_Object *obj, Elm_Focus_Direction dir)
2818 while ((next) && 2818 while ((next) &&
2819 ((elm_wdg_item_disabled_get(EO_OBJ(next))) || 2819 ((elm_wdg_item_disabled_get(EO_OBJ(next))) ||
2820 (_is_no_select(next)))) 2820 (_is_no_select(next))))
2821 if (!next->hide) next = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next); 2821 if (!next->hide) next = ELM_GEN_ITEM_NEXT(next);
2822 } 2822 }
2823 else 2823 else
2824 { 2824 {
@@ -3327,7 +3327,7 @@ _elm_genlist_elm_widget_on_focus_update(Eo *obj, Elm_Genlist_Data *sd, Elm_Objec
3327 ELM_GENLIST_ITEM_DATA_GET(eo_it, it); 3327 ELM_GENLIST_ITEM_DATA_GET(eo_it, it);
3328 if ((!_is_no_select(it)) && (!elm_object_item_disabled_get(eo_it))) 3328 if ((!_is_no_select(it)) && (!elm_object_item_disabled_get(eo_it)))
3329 break; 3329 break;
3330 eo_it = EO_OBJ(ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next)); 3330 eo_it = EO_OBJ(ELM_GEN_ITEM_NEXT(it));
3331 } 3331 }
3332 3332
3333 if (eo_it) 3333 if (eo_it)
@@ -3703,10 +3703,10 @@ _item_del(Elm_Gen_Item *it)
3703 sd->queue = eina_list_remove(sd->queue, it); 3703 sd->queue = eina_list_remove(sd->queue, it);
3704 if (sd->anchor_item == it) 3704 if (sd->anchor_item == it)
3705 { 3705 {
3706 sd->anchor_item = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); 3706 sd->anchor_item = ELM_GEN_ITEM_NEXT(it);
3707 if (!sd->anchor_item) 3707 if (!sd->anchor_item)
3708 sd->anchor_item = 3708 sd->anchor_item =
3709 ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); 3709 ELM_GEN_ITEM_PREV(it);
3710 } 3710 }
3711 if (sd->expanded_item == it) 3711 if (sd->expanded_item == it)
3712 { 3712 {
@@ -6495,12 +6495,12 @@ _elm_genlist_item_sorted_insert(Eo *obj, Elm_Genlist_Data *sd, const Elm_Genlist
6495 6495
6496 if (EINA_INLIST_GET(it)->next) 6496 if (EINA_INLIST_GET(it)->next)
6497 { 6497 {
6498 rel = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); 6498 rel = ELM_GEN_ITEM_NEXT(it);
6499 it->item->before = EINA_TRUE; 6499 it->item->before = EINA_TRUE;
6500 } 6500 }
6501 else if (EINA_INLIST_GET(it)->prev) 6501 else if (EINA_INLIST_GET(it)->prev)
6502 { 6502 {
6503 rel = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); 6503 rel = ELM_GEN_ITEM_PREV(it);
6504 it->item->before = EINA_FALSE; 6504 it->item->before = EINA_FALSE;
6505 } 6505 }
6506 } 6506 }
@@ -6709,20 +6709,10 @@ _elm_genlist_first_item_get(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd)
6709{ 6709{
6710 Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(sd->items); 6710 Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(sd->items);
6711 6711
6712 if (!sd->filter) 6712 while (it && sd->filter && !_item_filtered_get(it))
6713 { 6713 it = ELM_GEN_ITEM_NEXT(it);
6714 return EO_OBJ(it); 6714
6715 } 6715 return EO_OBJ(it);
6716 else
6717 {
6718 while (it)
6719 {
6720 if (_item_filtered_get(it)) break;
6721 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
6722 }
6723 if (it) return EO_OBJ(it);
6724 return NULL;
6725 }
6726} 6716}
6727 6717
6728EOLIAN static Elm_Object_Item* 6718EOLIAN static Elm_Object_Item*
@@ -6733,74 +6723,32 @@ _elm_genlist_last_item_get(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd)
6733 if (!sd->items) return NULL; 6723 if (!sd->items) return NULL;
6734 it = ELM_GEN_ITEM_FROM_INLIST(sd->items->last); 6724 it = ELM_GEN_ITEM_FROM_INLIST(sd->items->last);
6735 6725
6736 if (!sd->filter) 6726 while (it && sd->filter && !_item_filtered_get(it))
6737 { 6727 it = ELM_GEN_ITEM_PREV(it);
6738 return EO_OBJ(it); 6728
6739 } 6729 return EO_OBJ(it);
6740 else
6741 {
6742 while (it)
6743 {
6744 if (_item_filtered_get(it)) break;
6745 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
6746 }
6747 if (it) return EO_OBJ(it);
6748 return NULL;
6749 }
6750} 6730}
6751 6731
6752EOLIAN static Elm_Object_Item * 6732EOLIAN static Elm_Object_Item *
6753_elm_genlist_item_next_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it) 6733_elm_genlist_item_next_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it)
6754{ 6734{
6755 if (!it) return NULL;
6756 ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd); 6735 ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd);
6757 6736
6758 if (!sd->filter) 6737 do it = ELM_GEN_ITEM_NEXT(it);
6759 { 6738 while (it && sd->filter && !_item_filtered_get(it));
6760 while (it)
6761 {
6762 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
6763 if (it) break;
6764 }
6765 }
6766 else
6767 {
6768 while (it)
6769 {
6770 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
6771 if (it && _item_filtered_get(it)) break;
6772 }
6773 }
6774 6739
6775 if (it) return EO_OBJ(it); 6740 return EO_OBJ(it);
6776 else return NULL;
6777} 6741}
6778 6742
6779EOLIAN static Elm_Object_Item * 6743EOLIAN static Elm_Object_Item *
6780_elm_genlist_item_prev_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it) 6744_elm_genlist_item_prev_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it)
6781{ 6745{
6782 if (!it) return NULL;
6783 ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd); 6746 ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd);
6784 6747
6785 if (!sd->filter) 6748 do it = ELM_GEN_ITEM_PREV(it);
6786 { 6749 while (it && sd->filter && !_item_filtered_get(it));
6787 while (it)
6788 {
6789 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
6790 if (it) break;
6791 }
6792 }
6793 else
6794 {
6795 while (it)
6796 {
6797 it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
6798 if (it && _item_filtered_get(it)) break;
6799 }
6800 }
6801 6750
6802 if (it) return EO_OBJ(it); 6751 return EO_OBJ(it);
6803 else return NULL;
6804} 6752}
6805 6753
6806EOLIAN static Elm_Object_Item * 6754EOLIAN static Elm_Object_Item *
@@ -7650,6 +7598,7 @@ _filter_item_internal(Elm_Gen_Item *it)
7650 sd->processed_count++; 7598 sd->processed_count++;
7651} 7599}
7652 7600
7601// Returns true if the item is not filtered out, but remains visible.
7653static Eina_Bool 7602static Eina_Bool
7654_item_filtered_get(Elm_Gen_Item *it) 7603_item_filtered_get(Elm_Gen_Item *it)
7655{ 7604{