elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_widget_genlist.h
1 #ifndef ELM_WIDGET_GENLIST_H
2 #define ELM_WIDGET_GENLIST_H
3
4 #include "elm_gen_common.h"
5 #include "elm_interface_scrollable.h"
6 #include "elm_widget_layout.h"
7
8 // FIXME: Difference from upstream
9 #define GENLIST_ENTRY_SUPPORT 1
10 #define GENLIST_FX_SUPPORT 1
11 #define GENLIST_PINCH_ZOOM_SUPPORT 1
12
13 /**
14  * @addtogroup Widget
15  * @{
16  *
17  * @section elm-genlist-class The Elementary Genlist Class
18  *
19  * Elementary, besides having the @ref Genlist widget, exposes its
20  * foundation -- the Elementary Genlist Class -- in order to create
21  * other widgets which are a genlist with some more logic on top.
22  */
23
24 /**
25  * @def ELM_GENLIST_CLASS
26  *
27  * Use this macro to cast whichever subclass of
28  * #Elm_Genlist_Smart_Class into it, so to access its fields.
29  *
30  * @ingroup Widget
31  */
32 #define ELM_GENLIST_CLASS(x) ((Elm_Genlist_Smart_Class *)x)
33
34 /**
35  * @def ELM_GENLIST_DATA
36  *
37  * Use this macro to cast whichever subdata of
38  * #Elm_Genlist_Smart_Data into it, so to access its fields.
39  *
40  * @ingroup Widget
41  */
42 #define ELM_GENLIST_DATA(x)  ((Elm_Genlist_Smart_Data *)x)
43
44 /**
45  * @def ELM_GENLIST_SMART_CLASS_VERSION
46  *
47  * Current version for Elementary genlist @b base smart class, a value
48  * which goes to _Elm_Genlist_Smart_Class::version.
49  *
50  * @ingroup Widget
51  */
52 #define ELM_GENLIST_SMART_CLASS_VERSION 1
53
54 /**
55  * @def ELM_GENLIST_SMART_CLASS_INIT
56  *
57  * Initializer for a whole #Elm_Genlist_Smart_Class structure, with
58  * @c NULL values on its specific fields.
59  *
60  * @param smart_class_init initializer to use for the "base" field
61  * (#Evas_Smart_Class).
62  *
63  * @see EVAS_SMART_CLASS_INIT_NULL
64  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
65  * @see ELM_GENLIST_SMART_CLASS_INIT_NULL
66  * @see ELM_GENLIST_SMART_CLASS_INIT_NAME_VERSION
67  *
68  * @ingroup Widget
69  */
70 #define ELM_GENLIST_SMART_CLASS_INIT(smart_class_init) \
71   {smart_class_init, ELM_GENLIST_SMART_CLASS_VERSION}
72
73 /**
74  * @def ELM_GENLIST_SMART_CLASS_INIT_NULL
75  *
76  * Initializer to zero out a whole #Elm_Genlist_Smart_Class structure.
77  *
78  * @see ELM_GENLIST_SMART_CLASS_INIT_NAME_VERSION
79  * @see ELM_GENLIST_SMART_CLASS_INIT
80  *
81  * @ingroup Widget
82  */
83 #define ELM_GENLIST_SMART_CLASS_INIT_NULL \
84   ELM_GENLIST_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
85
86 /**
87  * @def ELM_GENLIST_SMART_CLASS_INIT_NAME_VERSION
88  *
89  * Initializer to zero out a whole #Elm_Genlist_Smart_Class structure and
90  * set its name and version.
91  *
92  * This is similar to #ELM_GENLIST_SMART_CLASS_INIT_NULL, but it will
93  * also set the version field of #Elm_Genlist_Smart_Class (base field)
94  * to the latest #ELM_GENLIST_SMART_CLASS_VERSION and name it to the
95  * specific value.
96  *
97  * It will keep a reference to the name field as a <c>"const char *"</c>,
98  * i.e., the name must be available while the structure is
99  * used (hint: static or global variable!) and must not be modified.
100  *
101  * @see ELM_GENLIST_SMART_CLASS_INIT_NULL
102  * @see ELM_GENLIST_SMART_CLASS_INIT
103  *
104  * @ingroup Widget
105  */
106 #define ELM_GENLIST_SMART_CLASS_INIT_NAME_VERSION(name) \
107   ELM_GENLIST_SMART_CLASS_INIT                          \
108     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
109
110 /**
111  * Elementary genlist base smart class. This inherits directly from
112  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
113  * behavior of a genlist.
114  *
115  * All of the functions listed on @ref Genlist namespace will work for
116  * objects deriving from #Elm_Genlist_Smart_Class.
117  */
118 typedef struct _Elm_Genlist_Smart_Class
119 {
120    Elm_Layout_Smart_Class base;
121
122    int                    version;    /**< Version of this smart class definition */
123 } Elm_Genlist_Smart_Class;
124
125 /**
126  * Base widget smart data extended with genlist instance data.
127  */
128 typedef struct _Elm_Genlist_Smart_Data Elm_Genlist_Smart_Data;
129
130 struct _Elm_Genlist_Smart_Data
131 {
132    Elm_Layout_Smart_Data                 base; /* base widget smart data as
133                                                 * first member obligatory, as
134                                                 * we're inheriting from it */
135
136    const Elm_Scrollable_Smart_Interface *s_iface;
137
138    Eina_Inlist_Sorted_State             *state;
139    Evas_Object                          *hit_rect;
140    Evas_Object                          *pan_obj;
141
142    Eina_List                            *selected; /* a list of
143                                                     * selected
144                                                     * items */
145    Eina_List                            *group_items; /* a list of
146                                                        * groups index
147                                                        * items */
148    Eina_Inlist                          *items; /* an inlist of all items */
149    Elm_Gen_Item                         *reorder_it; /* item currently
150                                                      * being
151                                                      * repositioned */
152    Elm_Object_Item                      *last_selected_item;
153    Ecore_Job                            *calc_job;
154    int                                   item_width, item_height;
155    int                                   group_item_width, group_item_height;
156    int                                   minw, minh;
157    unsigned int                          item_count;
158    Evas_Coord                            pan_x, pan_y;
159    Elm_Object_Select_Mode                select_mode;
160
161    Eina_Inlist                          *blocks; /* an inlist of all
162                                                   * blocks. a block
163                                                   * consists of a
164                                                   * certain number of
165                                                   * items. maximum
166                                                   * number of items in
167                                                   * a block is
168                                                   * 'max_items_per_block'. */
169    Evas_Coord                            reorder_old_pan_y, w, h, realminw,
170                                          prev_viewport_w;
171    Ecore_Job                            *update_job;
172    Ecore_Idle_Enterer                   *queue_idle_enterer;
173    Ecore_Idler                          *must_recalc_idler;
174    Eina_List                            *queue;
175    Elm_Gen_Item                         *show_item, *anchor_item, *mode_item,
176                                         *reorder_rel, *expanded_item;
177    Eina_Inlist                          *item_cache; /* an inlist of
178                                                       * edje object it
179                                                       * cache. */
180    Evas_Coord                            anchor_y;
181    Evas_Coord                            reorder_start_y; /* reorder
182                                                            * it's
183                                                            * initial y
184                                                            * coordinate
185                                                            * in the
186                                                            * pan. */
187    Elm_List_Mode                         mode;
188    Ecore_Timer                          *multi_timer, *scr_hold_timer;
189    Ecore_Animator                       *reorder_move_animator;
190    const char                           *decorate_it_type;
191    double                                start_time;
192    Evas_Coord                            prev_x, prev_y, prev_mx, prev_my;
193    Evas_Coord                            cur_x, cur_y, cur_mx, cur_my;
194
195    struct
196    {
197       Evas_Coord x, y;
198    } history[SWIPE_MOVES];
199
200    int                                   multi_device;
201    int                                   item_cache_count;
202    int                                   item_cache_max; /* maximum
203                                                          * number of
204                                                          * cached
205                                                          * items */
206    int                                   movements;
207
208    /* maximum number of items per block */
209    int                                   max_items_per_block;
210
211    /* longpress timeout. this value comes from _elm_config by
212     * default. this can be changed by
213     * elm_genlist_longpress_timeout_set() */
214    double                                longpress_timeout;
215    Eina_Compare_Cb                       item_compare_cb;
216    Eina_Compare_Cb                       item_compare_data_cb;
217
218    /* a scrollto type which remembers where to scroll ex) in, top,
219     * middle */
220    Elm_Genlist_Item_Scrollto_Type        scroll_to_type;
221    Evas_Object                          *alpha_bg; /* not to receive
222                                                     * event when tree
223                                                     * effect is not
224                                                     * finished */
225    Elm_Gen_Item                         *expanded_next_item;
226    int                                   reorder_fast;
227
228 #if GENLIST_FX_SUPPORT
229    Eina_List                            *fx_items;
230    Eina_List                            *capture_before_items, *capture_after_items;
231    Eina_List                            *pending_del_items, *pending_unrealized_items;
232    Eina_List                            *pending_unrealized_decorate_all_items;
233    Elm_Gen_Item                         *realized_top_item;
234    Ecore_Timer                          *fx_timer;
235 #endif
236
237    Eina_Bool                             auto_scroll_enabled : 1;
238    Eina_Bool                             decorate_all_mode : 1;
239    Eina_Bool                             height_for_width : 1;
240    Eina_Bool                             reorder_pan_move : 1;
241    Eina_Bool                             multi_timeout : 1;
242    Eina_Bool                             multi_touched : 1;
243    Eina_Bool                             reorder_mode : 1; /* a flag
244                                                             * for
245                                                             * reorder
246                                                             * mode
247                                                             * enable/disable */
248    /* this flag means genlist is supposed to be scrolled. if this flag
249     * is set to EINA_TRUE, genlist checks whether it's ok to scroll
250     * genlist now or not. */
251    Eina_Bool                             check_scroll : 1;
252    Eina_Bool                             pan_changed : 1;
253    Eina_Bool                             wasselected : 1;
254    Eina_Bool                             homogeneous : 1;
255    Eina_Bool                             longpressed : 1;
256
257    Eina_Bool                             mouse_down : 1;
258    Eina_Bool                             multi_down : 1;
259    Eina_Bool                             on_sub_del : 1;
260
261    /* a flag for items can be highlighted or not. by default this flag
262     * is true. */
263    Eina_Bool                             highlight : 1;
264    Eina_Bool                             h_bounce : 1;
265    Eina_Bool                             v_bounce : 1;
266    Eina_Bool                             bring_in : 1; /* a flag to
267                                                         * describe the
268                                                         * scroll
269                                                         * animation. (show,
270                                                         * bring in) */
271
272    /* this is set to EINA_TRUE when the item is re-queued. this
273     * happens when the item is un-queued but the rel item is still in
274     * the queue. this item will be processed later. */
275    Eina_Bool                             requeued : 1;
276    Eina_Bool                             on_hold : 1;
277    Eina_Bool                             multi : 1; /* a flag for item
278                                                      * multi
279                                                      * selection */
280
281    Eina_Bool                             swipe : 1;
282 #if GENLIST_ENTRY_SUPPORT
283    Eina_Bool                             size_changed : 1;
284 #endif
285
286 #if GENLIST_FX_SUPPORT
287    Eina_Bool                             fx_mode : 1;
288    Eina_Bool                             fx_first_captured : 1;
289    Eina_Bool                             fx_playing : 1;
290    Eina_Bool                             rendered : 1;
291    Eina_Bool                             fx_items_deleted : 1;
292    Eina_Bool                             genlist_clearing : 1;
293 #endif
294 #if GENLIST_PINCH_ZOOM_SUPPORT
295    Elm_Gen_Pinch_Zoom_Mode               pinch_zoom_mode;
296    Evas_Coord                            pinch_pan_y, pinch_zoom_h;
297 #endif
298    Eina_Bool                             sorting : 1;
299 };
300
301 typedef struct _Item_Block Item_Block;
302 typedef struct _Item_Cache Item_Cache;
303
304 struct Elm_Gen_Item_Type
305 {
306    Elm_Gen_Item           *it;
307
308    Elm_Genlist_Smart_Data *wsd;
309
310    Item_Block             *block;
311    Eina_List              *items;
312    Evas_Coord              w, h, minw, minh;
313    Elm_Gen_Item           *group_item;
314    Elm_Genlist_Item_Type   type;
315    Eina_List              *deco_it_texts, *deco_it_contents,
316                           *deco_it_states, *deco_it_content_objs;
317    Eina_List              *deco_all_texts, *deco_all_contents,
318                           *deco_all_states, *deco_all_content_objs;
319    Eina_List              *flip_contents, *flip_content_objs;
320    Ecore_Timer            *swipe_timer;
321    Evas_Coord              scrl_x, scrl_y, old_scrl_y;
322
323    Elm_Gen_Item           *rel;
324    Eina_List              *rel_revs; // FIXME: find better way not to use this
325    Evas_Object            *deco_it_view;
326 #if GENLIST_FX_SUPPORT
327    Elm_Gen_FX_Item         *fi;
328    int                     num;
329 #endif
330 #if GENLIST_PINCH_ZOOM_SUPPORT
331    Evas_Coord              pan_scrl_y;
332 #endif
333    int                     expanded_depth;
334    int                     order_num_in;
335
336    Eina_Bool               decorate_all_item_realized : 1;
337    Eina_Bool               move_effect_enabled : 1;
338
339    Eina_Bool               stacking_even : 1;
340    Eina_Bool               want_realize : 1;
341    Eina_Bool               nocache_once : 1; /* do not use cache for
342                                               * this item only once */
343    Eina_Bool               nostacking : 1;
344    Eina_Bool               expanded : 1;
345    Eina_Bool               mincalcd : 1;
346    Eina_Bool               updateme : 1;
347    Eina_Bool               nocache : 1; /* do not use cache for this item */
348    Eina_Bool               queued : 1;
349    Eina_Bool               before : 1;
350    Eina_Bool               show_me : 1;
351    /* if item is realized once, it is not unrealized & realized again. */
352    Eina_Bool               unrealize_disabled: 1;
353 #if GENLIST_FX_SUPPORT
354    Eina_Bool               has_proxy_it : 1;
355 #endif
356 };
357
358 struct _Item_Block
359 {
360    EINA_INLIST;
361
362    int                     count;
363    int                     num;
364    int                     reorder_offset;
365    Elm_Genlist_Smart_Data *sd;
366    Eina_List              *items;
367    Evas_Coord              x, y, w, h, minw, minh;
368    int                     position;
369    int                     item_position_stamp;
370
371    Eina_Bool               position_update : 1;
372    Eina_Bool               want_unrealize : 1;
373    Eina_Bool               must_recalc : 1;
374    Eina_Bool               realized : 1;
375    Eina_Bool               updateme : 1;
376    Eina_Bool               changed : 1;
377    Eina_Bool               show_me : 1;
378 };
379
380 struct _Item_Cache
381 {
382    EINA_INLIST;
383
384    Evas_Object *base_view, *spacer;
385
386    const char  *item_style; // it->itc->item_style
387
388    Eina_Bool    selected : 1; // it->selected
389    Eina_Bool    disabled : 1; // it->disabled
390    Eina_Bool    expanded : 1; // it->item->expanded
391    Eina_Bool    tree : 1; // it->group
392 };
393
394 typedef struct _Elm_Genlist_Pan_Smart_Class
395 {
396    Elm_Pan_Smart_Class base;
397 } Elm_Genlist_Pan_Smart_Class;
398
399 typedef struct _Elm_Genlist_Pan_Smart_Data Elm_Genlist_Pan_Smart_Data;
400 struct _Elm_Genlist_Pan_Smart_Data
401 {
402    Elm_Pan_Smart_Data      base;
403    Elm_Genlist_Smart_Data *wsd;
404    Ecore_Job              *resize_job;
405 };
406
407 /**
408  * @}
409  */
410
411 EAPI extern const char ELM_GENLIST_SMART_NAME[];
412 EAPI const Elm_Genlist_Smart_Class *elm_genlist_smart_class_get(void);
413
414 #define ELM_GENLIST_DATA_GET(o, sd) \
415   Elm_Genlist_Smart_Data * sd = evas_object_smart_data_get(o)
416
417 #define ELM_GENLIST_PAN_DATA_GET(o, sd) \
418   Elm_Genlist_Pan_Smart_Data * sd = evas_object_smart_data_get(o)
419
420 #define ELM_GENLIST_DATA_GET_OR_RETURN(o, ptr)       \
421   ELM_GENLIST_DATA_GET(o, ptr);                      \
422   if (!ptr)                                          \
423     {                                                \
424        CRITICAL("No widget data for object %p (%s)", \
425                 o, evas_object_type_get(o));         \
426        return;                                       \
427     }
428
429 #define ELM_GENLIST_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
430   ELM_GENLIST_DATA_GET(o, ptr);                         \
431   if (!ptr)                                             \
432     {                                                   \
433        CRITICAL("No widget data for object %p (%s)",    \
434                 o, evas_object_type_get(o));            \
435        return val;                                      \
436     }
437
438 #define ELM_GENLIST_CHECK(obj)                                                 \
439   if (!obj || !elm_widget_type_check((obj), ELM_GENLIST_SMART_NAME, __func__)) \
440     return
441
442 #define ELM_GENLIST_ITEM_CHECK(it)                          \
443   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
444   ELM_GENLIST_CHECK(it->base.widget);
445
446 #define ELM_GENLIST_ITEM_CHECK_OR_RETURN(it, ...)                        \
447   ELM_WIDGET_ITEM_CHECK_OR_RETURN(((Elm_Widget_Item *)it), __VA_ARGS__); \
448   ELM_WIDGET_ITEM_RETURN_IF_ONDEL(((Elm_Widget_Item *)it), __VA_ARGS__); \
449   ELM_GENLIST_CHECK(it->base.widget) __VA_ARGS__;
450
451 #define ELM_GENLIST_ITEM_CHECK_OR_GOTO(it, label)              \
452   ELM_WIDGET_ITEM_CHECK_OR_GOTO(((Elm_Widget_Item *)it), label); \
453   ELM_WIDGET_ITEM_GOTO_IF_ONDEL(((Elm_Widget_Item *)it), label); \
454   if (!it->base.widget || !elm_widget_type_check               \
455         ((it->base.widget), ELM_GENLIST_SMART_NAME, __func__)) goto label;
456
457 #endif