elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_widget_gengrid.h
1 #ifndef ELM_WIDGET_GENGRID_H
2 #define ELM_WIDGET_GENGRID_H
3
4 #include "elm_gen_common.h"
5 #include "elm_interface_scrollable.h"
6 #include "elm_widget_layout.h"
7
8 #define GENGRID_FX_SUPPORT 1
9
10 /**
11  * @addtogroup Widget
12  * @{
13  *
14  * @section elm-gengrid-class The Elementary Gengrid Class
15  *
16  * Elementary, besides having the @ref Gengrid widget, exposes its
17  * foundation -- the Elementary Gengrid Class -- in order to create
18  * other widgets which are a gengrid with some more logic on top.
19  */
20
21 /**
22  * @def ELM_GENGRID_CLASS
23  *
24  * Use this macro to cast whichever subclass of
25  * #Elm_Gengrid_Smart_Class into it, so to access its fields.
26  *
27  * @ingroup Widget
28  */
29 #define ELM_GENGRID_CLASS(x) ((Elm_Gengrid_Smart_Class *)x)
30
31 /**
32  * @def ELM_GENGRID_DATA
33  *
34  * Use this macro to cast whichever subdata of
35  * #Elm_Gengrid_Smart_Data into it, so to access its fields.
36  *
37  * @ingroup Widget
38  */
39 #define ELM_GENGRID_DATA(x)  ((Elm_Gengrid_Smart_Data *)x)
40
41 /**
42  * @def ELM_GENGRID_SMART_CLASS_VERSION
43  *
44  * Current version for Elementary gengrid @b base smart class, a value
45  * which goes to _Elm_Gengrid_Smart_Class::version.
46  *
47  * @ingroup Widget
48  */
49 #define ELM_GENGRID_SMART_CLASS_VERSION 1
50
51 /**
52  * @def ELM_GENGRID_SMART_CLASS_INIT
53  *
54  * Initializer for a whole #Elm_Gengrid_Smart_Class structure, with
55  * @c NULL values on its specific fields.
56  *
57  * @param smart_class_init initializer to use for the "base" field
58  * (#Evas_Smart_Class).
59  *
60  * @see EVAS_SMART_CLASS_INIT_NULL
61  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
62  * @see ELM_GENGRID_SMART_CLASS_INIT_NULL
63  * @see ELM_GENGRID_SMART_CLASS_INIT_NAME_VERSION
64  *
65  * @ingroup Widget
66  */
67 #define ELM_GENGRID_SMART_CLASS_INIT(smart_class_init) \
68   {smart_class_init, ELM_GENGRID_SMART_CLASS_VERSION}
69
70 /**
71  * @def ELM_GENGRID_SMART_CLASS_INIT_NULL
72  *
73  * Initializer to zero out a whole #Elm_Gengrid_Smart_Class structure.
74  *
75  * @see ELM_GENGRID_SMART_CLASS_INIT_NAME_VERSION
76  * @see ELM_GENGRID_SMART_CLASS_INIT
77  *
78  * @ingroup Widget
79  */
80 #define ELM_GENGRID_SMART_CLASS_INIT_NULL \
81   ELM_GENGRID_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
82
83 /**
84  * @def ELM_GENGRID_SMART_CLASS_INIT_NAME_VERSION
85  *
86  * Initializer to zero out a whole #Elm_Gengrid_Smart_Class structure and
87  * set its name and version.
88  *
89  * This is similar to #ELM_GENGRID_SMART_CLASS_INIT_NULL, but it will
90  * also set the version field of #Elm_Gengrid_Smart_Class (base field)
91  * to the latest #ELM_GENGRID_SMART_CLASS_VERSION and name it to the
92  * specific value.
93  *
94  * It will keep a reference to the name field as a <c>"const char *"</c>,
95  * i.e., the name must be available while the structure is
96  * used (hint: static or global variable!) and must not be modified.
97  *
98  * @see ELM_GENGRID_SMART_CLASS_INIT_NULL
99  * @see ELM_GENGRID_SMART_CLASS_INIT
100  *
101  * @ingroup Widget
102  */
103 #define ELM_GENGRID_SMART_CLASS_INIT_NAME_VERSION(name) \
104   ELM_GENGRID_SMART_CLASS_INIT                          \
105     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
106
107 /**
108  * Elementary gengrid base smart class. This inherits directly from
109  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
110  * behavior of a gengrid.
111  *
112  * All of the functions listed on @ref Gengrid namespace will work for
113  * objects deriving from #Elm_Gengrid_Smart_Class.
114  */
115 typedef struct _Elm_Gengrid_Smart_Class
116 {
117    Elm_Layout_Smart_Class base;
118
119    int                    version;    /**< Version of this smart class definition */
120 } Elm_Gengrid_Smart_Class;
121
122 /**
123  * Base widget smart data extended with gengrid instance data.
124  */
125 typedef struct _Elm_Gengrid_Smart_Data Elm_Gengrid_Smart_Data;
126 struct _Elm_Gengrid_Smart_Data
127 {
128    Elm_Layout_Smart_Data                 base; /* base widget smart data as
129                                                 * first member obligatory, as
130                                                 * we're inheriting from it */
131
132    const Elm_Scrollable_Smart_Interface *s_iface;
133
134    Eina_Inlist_Sorted_State             *state;
135    Evas_Object                          *hit_rect;
136    Evas_Object                          *pan_obj;
137
138    Eina_List                            *selected; /* a list of
139                                                     * selected
140                                                     * items */
141    Eina_List                            *group_items; /* a list of
142                                                        * groups index
143                                                        * items */
144    Eina_Inlist                          *items; /* an inlist of all items */
145    Elm_Gen_Item                         *reorder_it; /* item currently
146                                                      * being
147                                                      * repositioned */
148    Elm_Object_Item                      *last_selected_item;
149    Elm_Gen_Item                         *show_it;
150    Elm_Gen_Item                         *bring_in_it;
151
152    Ecore_Job                            *calc_job;
153    int                                   walking;
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    Ecore_Cb                              calc_cb;
162    Ecore_Cb                              clear_cb;
163
164    /* longpress timeout. this value comes from _elm_config by
165     * default. this can be changed by
166     * elm_gengrid_longpress_timeout_set() */
167    double                                longpress_timeout;
168
169    /* a generation of gengrid. when gengrid is cleared, this value
170     * will be increased and a new generation will start */
171    int                                   generation;
172    Eina_Compare_Cb                       item_compare_cb;
173
174    /* The stuff below directly come from gengrid without any thinking */
175    unsigned int                          nmax;
176    Evas_Coord                            reorder_item_x, reorder_item_y;
177    Evas_Coord                            old_pan_x, old_pan_y;
178    long                                  items_lost;
179    double                                align_x, align_y;
180
181 #if GENGRID_FX_SUPPORT
182    Evas_Object                          *alpha_bg;
183    Eina_List                            *fx_items;
184    Eina_List                            *capture_before_items, *capture_after_items;
185    Eina_List                            *pending_del_items, *pending_unrealized_items;
186    Elm_Gen_Item                         *realized_top_item;
187 #endif
188
189    Eina_Bool                             reorder_item_changed : 1;
190    Eina_Bool                             move_effect_enabled : 1;
191
192    Eina_Bool                             old_h_bounce;
193    Eina_Bool                             old_v_bounce;
194
195    /* a flag for reorder mode enable/disable */
196    Eina_Bool                             reorder_mode : 1;
197    Eina_Bool                             was_selected : 1;
198
199    Eina_Bool                             longpressed : 1;
200    Eina_Bool                             pan_changed : 1;
201    Eina_Bool                             horizontal : 1;
202
203    /* a flag for items can be highlighted or not. by default this flag
204     * is true. */
205    Eina_Bool                             highlight : 1;
206
207    Eina_Bool                             clear_me : 1; /**< a flag whether
208                                                         * gengrid is marked
209                                                         * as to be cleared or
210                                                         * not. if this flag
211                                                         * is true, gengrid
212                                                         * clear was already
213                                                         * deferred.  */
214
215    Eina_Bool                             on_hold : 1;
216
217    Eina_Bool                             filled : 1;
218    Eina_Bool                             multi : 1; /* a flag for item
219                                                      * multi
220                                                      * selection */
221    Eina_Bool                             show_region : 1;
222    Eina_Bool                             bring_in : 1;
223
224 #if GENGRID_FX_SUPPORT
225    Eina_Bool                             fx_mode : 1;
226    Eina_Bool                             fx_first_captured : 1;
227    Eina_Bool                             fx_playing : 1;
228    Eina_Bool                             rendered : 1;
229    Eina_Bool                             fx_items_deleted : 1;
230    Eina_Bool                             gengrid_clearing : 1;
231 #endif
232 };
233
234 struct Elm_Gen_Item_Type
235 {
236    Elm_Gen_Item           *it;
237
238    Elm_Gengrid_Smart_Data *wsd;
239
240    Ecore_Animator         *item_reorder_move_animator;
241    Evas_Coord              gx, gy, ox, oy, tx, ty, rx, ry;
242    unsigned int            moving_effect_start_time;
243    int                     prev_group;
244 #if GENGRID_FX_SUPPORT
245    Evas_Coord              scrl_x, scrl_y, w, h;
246    Elm_Gen_FX_Item         *fi;
247    int                     num;
248    Eina_Bool               has_proxy_it : 1;
249 #endif
250    Eina_Bool               group_realized : 1;
251    Eina_Bool               moving : 1;
252 };
253
254 typedef struct _Elm_Gengrid_Pan_Smart_Class
255 {
256    Elm_Pan_Smart_Class base;
257 } Elm_Gengrid_Pan_Smart_Class;
258
259 typedef struct _Elm_Gengrid_Pan_Smart_Data Elm_Gengrid_Pan_Smart_Data;
260 struct _Elm_Gengrid_Pan_Smart_Data
261 {
262    Elm_Pan_Smart_Data      base;
263    Elm_Gengrid_Smart_Data *wsd;
264    Ecore_Job              *resize_job;
265 };
266
267 /**
268  * @}
269  */
270
271 EAPI extern const char ELM_GENGRID_SMART_NAME[];
272 EAPI const Elm_Gengrid_Smart_Class *elm_gengrid_smart_class_get(void);
273
274 #define ELM_GENGRID_DATA_GET(o, sd) \
275   Elm_Gengrid_Smart_Data * sd = evas_object_smart_data_get(o)
276
277 #define ELM_GENGRID_PAN_DATA_GET(o, sd) \
278   Elm_Gengrid_Pan_Smart_Data * sd = evas_object_smart_data_get(o)
279
280 #define ELM_GENGRID_DATA_GET_OR_RETURN(o, ptr)       \
281   ELM_GENGRID_DATA_GET(o, ptr);                      \
282   if (!ptr)                                          \
283     {                                                \
284        CRITICAL("No widget data for object %p (%s)", \
285                 o, evas_object_type_get(o));         \
286        return;                                       \
287     }
288
289 #define ELM_GENGRID_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
290   ELM_GENGRID_DATA_GET(o, ptr);                         \
291   if (!ptr)                                             \
292     {                                                   \
293        CRITICAL("No widget data for object %p (%s)",    \
294                 o, evas_object_type_get(o));            \
295        return val;                                      \
296     }
297
298 #define ELM_GENGRID_CHECK(obj)                                                 \
299   if (!obj || !elm_widget_type_check((obj), ELM_GENGRID_SMART_NAME, __func__)) \
300     return
301
302 #define ELM_GENGRID_ITEM_CHECK(it)                          \
303   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
304   ELM_GENGRID_CHECK(it->base.widget);
305
306 #define ELM_GENGRID_ITEM_CHECK_OR_RETURN(it, ...)                      \
307   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
308   ELM_GENGRID_CHECK(it->base.widget) __VA_ARGS__;
309
310 #define ELM_GENGRID_ITEM_CHECK_OR_GOTO(it, label)              \
311   ELM_WIDGET_ITEM_CHECK_OR_GOTO((Elm_Widget_Item *)it, label); \
312   if (!it->base.widget || !elm_widget_type_check               \
313         ((it->base.widget), ELM_GENGRID_SMART_NAME, __func__)) goto label;
314
315 #endif