elm genlist: Fixed genlist auto scroll bug. Patch by Chanwook Jung <joey.jung@samsung...
[framework/uifw/elementary.git] / src / lib / elm_genlist.h
1 #ifndef ELM_GEN_H_
2 # define ELM_GEN_H_
3
4 #include <Elementary.h>
5 #include <Elementary_Cursor.h>
6 #include "elm_priv.h"
7
8 #define ELM_GEN_ITEM_FROM_INLIST(it) \
9    ((it) ? EINA_INLIST_CONTAINER_GET(it, Elm_Gen_Item) : NULL)
10
11 #define SWIPE_MOVES         12
12
13 typedef struct Elm_Gen_Item_Type Elm_Gen_Item_Type;
14 typedef struct Elm_Gen_Item_Tooltip Elm_Gen_Item_Tooltip;
15 typedef struct _Widget_Data Widget_Data;
16
17 typedef enum _Elm_Genlist_Item_Scrollto_Type
18   {
19      ELM_GENLIST_ITEM_SCROLLTO_NONE = 0, /**< no scrollto */
20      ELM_GENLIST_ITEM_SCROLLTO_IN = (1 << 0), /**< show, bring in */
21      ELM_GENLIST_ITEM_SCROLLTO_TOP = (1 << 1), /**< top show, top bring in */
22      ELM_GENLIST_ITEM_SCROLLTO_MIDDLE = (1 << 2) /**< middle show, middle bring in */
23   } Elm_Genlist_Item_Scrollto_Type;
24
25 struct Elm_Gen_Item_Tooltip
26 {
27    const void                 *data;
28    Elm_Tooltip_Item_Content_Cb content_cb;
29    Evas_Smart_Cb               del_cb;
30    const char                 *style;
31    Eina_Bool                   free_size : 1;
32 };
33
34 struct Elm_Gen_Item
35 {
36    ELM_WIDGET_ITEM;
37    EINA_INLIST;
38    Widget_Data                  *wd;
39    Elm_Gen_Item_Type            *item;
40    const Elm_Gen_Item_Class     *itc;
41    Evas_Coord                    x, y, dx, dy;
42    Evas_Object                  *spacer;
43    Elm_Gen_Item                 *parent;
44    Eina_List                    *texts, *contents, *states, *content_objs;
45    Ecore_Timer                  *long_timer;
46    int                           relcount;
47    int                           walking;
48    int                           generation; /* a generation of an item. when the item is created, this value is set to the value of genlist generation. this value will be decreased when the item is going to be deleted */
49    const char                   *mouse_cursor;
50
51    struct
52    {
53       Evas_Smart_Cb func;
54       const void   *data;
55    } func;
56
57    Elm_Gen_Item_Tooltip tooltip;
58    Ecore_Cb    del_cb, sel_cb, highlight_cb;
59    Ecore_Cb    unsel_cb, unhighlight_cb, unrealize_cb;
60
61    Eina_Bool   want_unrealize : 1;
62    Eina_Bool   display_only : 1;
63    Eina_Bool   realized : 1;
64    Eina_Bool   selected : 1;
65    Eina_Bool   highlighted : 1;
66    Eina_Bool   disabled : 1;
67    Eina_Bool   dragging : 1;
68    Eina_Bool   down : 1;
69    Eina_Bool   group : 1;
70    Eina_Bool   reorder : 1;
71    Eina_Bool   mode_set : 1; /* item uses style mode for highlight/select */
72 };
73
74 typedef struct _Pan Pan;
75 struct _Pan
76 {
77    Evas_Object_Smart_Clipped_Data  __clipped_data;
78    Widget_Data                    *wd;
79    Ecore_Job                      *resize_job;
80 };
81
82 struct _Widget_Data
83 {
84    Eina_Inlist_Sorted_State *state;
85    Evas_Object      *obj; /* the genlist object */
86    Evas_Object      *scr; /* a smart scroller object which is used internally in genlist */
87    Evas_Object      *pan_smart; /* "elm_genlist_pan" evas smart object. this is an extern pan of smart scroller(scr). */
88    Eina_List        *selected;
89    Eina_List        *group_items; /* list of groups index items */
90    Eina_Inlist      *items; /* inlist of all items */
91    Elm_Gen_Item     *reorder_it; /* item currently being repositioned */
92    Elm_Gen_Item     *last_selected_item;
93    Pan              *pan; /* pan_smart object's smart data */
94    Ecore_Job        *calc_job;
95    int               walking;
96    int               item_width, item_height;
97    int               group_item_width, group_item_height;
98    int               minw, minh;
99    long              count;
100    Evas_Coord        pan_x, pan_y;
101    Eina_Bool         reorder_mode : 1; /* a flag for reorder mode enable/disable */
102    Eina_Bool         on_hold : 1;
103    Eina_Bool         multi : 1; /* a flag for item multi selection */
104    Eina_Bool         no_select : 1;
105    Eina_Bool         wasselected : 1;
106    Eina_Bool         always_select : 1;
107    Eina_Bool         clear_me : 1; /* a flag whether genlist is marked as to be cleared or not. if this flag is true, genlist clear was already deferred.  */
108    Eina_Bool         h_bounce : 1;
109    Eina_Bool         v_bounce : 1;
110    Ecore_Cb          del_cb, calc_cb, sizing_cb;
111    Ecore_Cb          clear_cb;
112    ////////////////////////////////////
113    Eina_Inlist      *blocks; /* inlist of all blocks. a block consists of a certain number of items. maximum number of items in a block is 'max_items_per_block'. */
114    Evas_Coord        reorder_old_pan_y, w, h, realminw, prev_viewport_w;
115    Ecore_Job        *update_job;
116    Ecore_Idle_Enterer *queue_idle_enterer;
117    Ecore_Idler        *must_recalc_idler;
118    Eina_List        *queue;
119    Elm_Gen_Item     *show_item, *anchor_item, *mode_item, *reorder_rel, *expanded_item;
120    Eina_Inlist      *item_cache; /* an inlist of edje object it cache. */
121    Evas_Coord        anchor_y;
122    Evas_Coord        reorder_start_y; /* reorder it's initial y coordinate in the pan. */
123    Elm_List_Mode     mode;
124    Ecore_Timer      *multi_timer, *scr_hold_timer;
125    Ecore_Animator   *reorder_move_animator;
126    const char       *mode_type;
127    const char       *mode_item_style;
128    unsigned int      start_time;
129    Evas_Coord        prev_x, prev_y, prev_mx, prev_my;
130    Evas_Coord        cur_x, cur_y, cur_mx, cur_my;
131    Eina_Bool         mouse_down : 1;
132    Eina_Bool         multi_down : 1;
133    Eina_Bool         multi_timeout : 1;
134    Eina_Bool         multitouched : 1;
135    Eina_Bool         longpressed : 1;
136    Eina_Bool         bring_in : 1; /* a flag to describe the scroll animation. (show, bring in) */
137    Eina_Bool         compress : 1;
138    Eina_Bool         height_for_width : 1;
139    Eina_Bool         homogeneous : 1;
140    Eina_Bool         swipe : 1;
141    Eina_Bool         reorder_pan_move : 1;
142    Eina_Bool         auto_scroll_enabled : 1;
143    Eina_Bool         pan_changed : 1;
144    Eina_Bool         requeued : 1; /* this is set to EINA_TRUE when the item is re-queued. this happens when the item is un-queued but the rel item is still in the queue. this item will be processed later. */
145    Eina_Bool         check_scroll : 1; /* this flag means genlist is supposed to be scrolled. if this flag is set to EINA_TRUE, genlist checks whether it's ok to scroll genlist now or not. */
146    struct
147    {
148       Evas_Coord x, y;
149    } history[SWIPE_MOVES];
150    int               multi_device;
151    int               item_cache_count;
152    int               item_cache_max; /* maximum number of cached items */
153    int               movements;
154    int               max_items_per_block; /* maximum number of items per block */
155    double            longpress_timeout; /* longpress timeout. this value comes from _elm_config by default. this can be changed by elm_genlist_longpress_timeout_set() */
156    int               generation; /* a generation of genlist. when genlist is cleared, this value will be increased and a new generation will start */
157    Eina_Compare_Cb   item_compare_cb;
158    Eina_Compare_Cb   item_compare_data_cb;
159    Elm_Genlist_Item_Scrollto_Type scrollto_type; /* a scrollto type which remembers where to scroll ex) in, top, middle */
160
161    /* The stuff below directly come from gengrid without any thinking */
162    unsigned int      nmax;
163    Evas_Coord        reorder_item_x, reorder_item_y;
164    Evas_Coord        old_pan_x, old_pan_y;
165    long              items_lost;
166    double            align_x, align_y;
167
168    Eina_Bool         horizontal : 1;
169    Eina_Bool         move_effect_enabled : 1;
170    Eina_Bool         reorder_item_changed : 1;
171 };
172
173 Elm_Gen_Item *
174 _elm_genlist_item_new(Widget_Data              *wd,
175                       const Elm_Gen_Item_Class *itc,
176                       const void               *data,
177                       Elm_Gen_Item             *parent,
178                       Evas_Smart_Cb             func,
179                       const void               *func_data);
180
181 Evas_Object *
182 _elm_genlist_item_widget_get(const Elm_Gen_Item *it);
183
184 void
185 _elm_genlist_page_relative_set(Evas_Object *obj,
186                                double       h_pagerel,
187                                double       v_pagerel);
188
189 void
190 _elm_genlist_page_relative_get(const Evas_Object *obj,
191                                double            *h_pagerel,
192                                double            *v_pagerel);
193
194 void
195 _elm_genlist_page_size_set(Evas_Object *obj,
196                            Evas_Coord   h_pagesize,
197                            Evas_Coord   v_pagesize);
198
199 void
200 _elm_genlist_current_page_get(const Evas_Object *obj,
201                               int               *h_pagenumber,
202                               int               *v_pagenumber);
203
204 void
205 _elm_genlist_last_page_get(const Evas_Object *obj,
206                            int               *h_pagenumber,
207                            int               *v_pagenumber);
208
209 void
210 _elm_genlist_page_show(const Evas_Object *obj,
211                        int                h_pagenumber,
212                        int                v_pagenumber);
213
214 void
215 _elm_genlist_page_bring_in(const Evas_Object *obj,
216                            int                h_pagenumber,
217                            int                v_pagenumber);
218
219 void
220 _elm_genlist_item_unrealize(Elm_Gen_Item *it,
221                             Eina_Bool     calc);
222 void
223 _elm_genlist_item_del_serious(Elm_Gen_Item *it);
224
225 void
226 _elm_genlist_item_del_notserious(Elm_Gen_Item *it);
227
228 #endif