summaryrefslogtreecommitdiff
path: root/src/lib/items/elm_items_list.c
blob: 1aed339aa2465270eadb19784cad9256d60a53c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "elm_items_priv.h"

//XXX: For now everything works just for strait items, no children or something will be displayed

typedef struct {
   Eo *root;
   Eina_Bool unselect_barrier;
   Evas_Object *pan;
   Eina_List *realitems;
   Ecore_Idler *flush_idle;
} Elm_Items_List_Data;

typedef struct {
   Eo *obj;
   Evas_Box *box;
   unsigned int old_first, old_last;
   Eina_List *realitems;
} Elm_Items_List_Pan_Data;

#define HACKY_HEIGHT 30
//==================================
// Pan implement
//==================================

EOLIAN static void
_elm_items_list_pan_elm_items_pan_realitems(Eo *obj EINA_UNUSED, Elm_Items_List_Pan_Data *pd, Eina_List *list)
{
   pd->realitems = list;
   eo_do_super(obj, ELM_ITEMS_LIST_PAN_CLASS, elm_items_pan_realitems(list));
}

EOLIAN static void
_elm_items_list_pan_elm_items_pan_content_size_get(Eo *obj EINA_UNUSED, Elm_Items_List_Pan_Data *pd, int *w, int *h)
{
   *w = 0;
   *h = eina_list_count(pd->realitems) * HACKY_HEIGHT;
}

EOLIAN static void
_elm_items_list_pan_elm_items_pan_viewport_changed(Eo *obj, Elm_Items_List_Pan_Data *pd, Elm_Items_Rect viewport, Elm_Items_Position position)
{
   unsigned int first_item, last_item;
   int gap;
   Eina_List *realizes = NULL;

   gap = position.y % (HACKY_HEIGHT);
   first_item = position.y / HACKY_HEIGHT;
   last_item = ((position.y + viewport.h) / HACKY_HEIGHT);

   if (last_item > eina_list_count(pd->realitems))
     last_item = eina_list_count(pd->realitems);

   DBG("Size : (%d-%d-%d-%d) Pos :(%d-%d) Items:(%d-%d)\n", viewport.pos.x, viewport.pos.y, viewport.w, viewport.h, position.x, position.y, first_item, last_item);

   //remove all children from the box if we have new items
   if (pd->old_last != last_item || pd->old_first != first_item)
     evas_object_box_remove_all(pd->box, EINA_FALSE);

   //move the box to the new position
   evas_object_move(pd->box, viewport.pos.x, viewport.pos.y - (gap));
   evas_object_resize(pd->box, viewport.w, (last_item - first_item) * HACKY_HEIGHT);

   if (pd->old_last != last_item || pd->old_first != first_item)
     {
        Eina_List *itemlist;
        //add the new items
        itemlist = eina_list_nth_list(pd->realitems, first_item);

        for (unsigned int i = first_item; i <= last_item; i++)
          {
             Eo *item;

             item = eina_list_data_get(itemlist);

             evas_object_box_append(pd->box, item);
             realizes = eina_list_append(realizes, item);
             itemlist = eina_list_next(itemlist);
          }
        //update old items
        pd->old_first = first_item;
        pd->old_last = last_item;
        //set new realizes
        eo_do(obj, elm_items_pan_realizes_set(realizes));
     }
}

EOLIAN static void
_elm_items_list_pan_evas_object_smart_add(Eo *obj, Elm_Items_List_Pan_Data *pd)
{
   eo_do_super(obj, ELM_ITEMS_LIST_PAN_CLASS, evas_obj_smart_add());

   pd->box = evas_object_box_add(evas_object_evas_get(obj));
   evas_object_smart_member_add(pd->box, obj);
   evas_object_box_layout_set(pd->box, evas_object_box_layout_vertical, pd->box, NULL);
   evas_object_box_align_set(pd->box, 0.0, 0.0);
   evas_object_show(pd->box);
}

//==================================
// List implement
//==================================

EOLIAN static void
_elm_items_list_elm_items_display_sel_move(Eo *obj, Elm_Items_List_Data *pd, Elm_Items_Move_Dir direction)
{

}

EOLIAN static void
_elm_items_list_evas_object_smart_add(Eo *obj, Elm_Items_List_Data *pd EINA_UNUSED)
{
   eo_do_super(obj, ELM_ITEMS_LIST_CLASS, evas_obj_smart_add());

   pd->pan = eo_add(ELM_ITEMS_LIST_PAN_CLASS, obj);

   {
      Elm_Items_List_Pan_Data *pdpan = eo_data_scope_get(pd->pan, ELM_ITEMS_LIST_PAN_CLASS);
      pdpan->obj = obj;
      evas_object_show(pd->pan);
      //set pan object
      Elm_Items_Display_Data *display_pd = eo_data_scope_get(obj, ELM_ITEMS_DISPLAY_CLASS);
      display_pd->pan = pd->pan;
   }

}

static Eina_Bool
_selected(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event EINA_UNUSED)
{
   Elm_Items_List_Data *pd;
   Elm_Items_Item *sel;
   const Evas_Modifier *mods;
   Eina_List *selection;

   pd = eo_data_scope_get(data, ELM_ITEMS_LIST_CLASS);
   eo_do(data, selection = elm_items_display_selected_get());

   mods = evas_key_modifier_get(evas_object_evas_get(obj));

   if (!evas_key_modifier_is_set(mods, "Control"))
     {
        Eina_List *selected;

        selected = eina_list_clone(selection);
        //stop unselecting work
        pd->unselect_barrier = EINA_TRUE;
        EINA_LIST_FREE(selected, sel)
          {
             if (sel == obj) continue;
             eo_do(sel, elm_items_item_selected_set(EINA_FALSE));
          }
        //restart unselecting work
        pd->unselect_barrier = EINA_FALSE;
     }
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_unselected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event EINA_UNUSED)
{
   Elm_Items_List_Data *pd;
   const Evas_Modifier *mods;
   Eina_List *selection;

   pd = eo_data_scope_get(data, ELM_ITEMS_LIST_CLASS);
   eo_do(data, selection = elm_items_display_selected_get());
   if (pd->unselect_barrier) return EO_CALLBACK_CONTINUE;

   mods = evas_key_modifier_get(evas_object_evas_get(data));

   if (!evas_key_modifier_is_set(mods, "Control"))
     {
        if (eina_list_count(selection) > 1)
          eo_do(obj, elm_items_item_selected_set(EINA_TRUE));

     }
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_add(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event)
{
   Eo *good;

   eo_do(event, good = efl_tree_base_carry_get());
   //subscribe to item events
   eo_do(good, eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
               eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
        );

   //set hints
   evas_object_size_hint_min_set(good, 1, HACKY_HEIGHT);
   evas_object_size_hint_align_set(good, EVAS_HINT_FILL, 1.0);
   evas_object_size_hint_weight_set(good, EVAS_HINT_EXPAND, 0.0);

   //show the item
   evas_object_show(good);

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event)
{
   Eo *good;

   eo_do(event, good = efl_tree_base_carry_get());

   eo_do(good, eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
               eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
        );

   return EO_CALLBACK_CONTINUE;
}

EOLIAN static Eo_Base *
_elm_items_list_eo_base_constructor(Eo *obj, Elm_Items_List_Data *pd)
{
   Eo *eo;

   eo_do_super(obj, ELM_ITEMS_LIST_CLASS, eo = eo_constructor());

   if (!eo)
     return NULL;

   //set pan
   eo_do(obj, elm_interface_scrollable_extern_pan_set(pd->pan));

   //get the root
   eo_do(obj, pd->root = elm_items_display_tree_get());

   //monitor changes on the tree
   eo_do(pd->root,
            eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj);
            eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj);
        );
   return eo;
}

#include "elm_items_list.eo.x"
#include "elm_items_list_pan.eo.x"