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