1 #ifndef ELM_WIDGET_GENGRID_H
2 #define ELM_WIDGET_GENGRID_H
3 
4 #include "elm_gen_common.h"
5 #include "Elementary.h"
6 
7 /* DO NOT USE THIS HEADER UNLESS YOU ARE PREPARED FOR BREAKING OF YOUR
8  * CODE. THIS IS ELEMENTARY'S INTERNAL WIDGET API (for now) AND IS NOT
9  * FINAL. CALL elm_widget_api_check(ELM_INTERNAL_API_VERSION) TO CHECK
10  * IT AT RUNTIME.
11  */
12 
13 /**
14  * @addtogroup Widget
15  * @{
16  *
17  * @section elm-gengrid-class The Elementary Gengrid Class
18  *
19  * Elementary, besides having the @ref Gengrid widget, exposes its
20  * foundation -- the Elementary Gengrid Class -- in order to create
21  * other widgets which are a gengrid with some more logic on top.
22  */
23 
24 /**
25  * Base widget smart data extended with gengrid instance data.
26  */
27 typedef struct _Elm_Gengrid_Data Elm_Gengrid_Data;
28 struct _Elm_Gengrid_Data
29 {
30    Eina_Inlist_Sorted_State             *state;
31    Evas_Object                          *hit_rect;
32    Evas_Object                          *pan_obj;
33    Evas_Object                          *obj; // the object itself
34    Evas_Object                          *stack; // stacking markers in pan for selectraise feature
35 
36    Eina_List                            *selected; /* a list of
37                                                     * selected
38                                                     * items */
39    Eina_List                            *group_items; /* a list of
40                                                        * groups index
41                                                        * items */
42    Eina_Inlist                          *items; /* an inlist of all items */
43    Elm_Gen_Item                         *reorder_it; /* item currently
44                                                      * being
45                                                      * repositioned */
46    Elm_Object_Item                      *last_selected_item;
47    Elm_Object_Item                      *focused_item; /**< a focused item by keypad arrow or mouse. This is set to NULL if widget looses focus. */
48    Elm_Object_Item                      *last_focused_item; /**< This records the last focused item when widget looses focus. This is required to set the focus on last focused item when widgets gets focus. */
49    Elm_Object_Item                      *show_it;
50    Elm_Object_Item                      *bring_in_it;
51    Elm_Gengrid_Item_Scrollto_Type        scroll_to_type;
52 
53    Eina_Hash                            *content_item_map;
54    Eo                                   *provider;
55    Elm_Gen_Item                         *focus_on_realization;
56 
57    Ecore_Job                            *calc_job;
58    int                                   walking;
59    int                                   item_width, item_height;
60    int                                   group_item_width, group_item_height;
61    int                                   minw, minh;
62    unsigned int                          item_count;
63    Evas_Coord                            pan_x, pan_y;
64    Elm_Object_Select_Mode                select_mode;
65    Elm_Object_Multi_Select_Mode          multi_select_mode; /**< select mode for multiple selection */
66 
67    Ecore_Cb                              calc_cb;
68    Ecore_Cb                              clear_cb;
69 
70    /* longpress timeout. this value comes from _elm_config by
71     * default. this can be changed by
72     * elm_config_longpress_timeout_set() */
73    double                                longpress_timeout;
74 
75    /* a generation of gengrid. when gengrid is cleared, this value
76     * will be increased and a new generation will start */
77    int                                   generation;
78    Eina_Compare_Cb                       item_compare_cb;
79 
80    /* The stuff below directly come from gengrid without any thinking */
81    unsigned int                          nmax;
82    Evas_Coord                            reorder_item_x, reorder_item_y;
83    Evas_Coord                            old_pan_x, old_pan_y;
84    long                                  items_lost;
85    double                                align_x, align_y;
86 
87    struct
88    {
89       Elm_Gen_Item                          *it1, *it2; /**< The items which are getting swapped */
90       void                                  *data; /**< This is the data used to store information related to animation */
91       Elm_Focus_Direction                   dir; /**< focus key direction */
92       Ecore_Pos_Map                         tween_mode; /**< Position mappings for animation */
93       Evas_Coord                            x1, y1, x2, y2; /**< Coordinates of it1 and it2 */
94       Elm_Gengrid_Reorder_Type              type; /**< Reorder type */
95       Eina_Bool                             running : 1; /**< animation is happening */
96    } reorder;
97    Elm_Focus_Region_Show_Mode            mode; /**< the mode which describes which rectangle should be returned in the interest region getter*/
98 
99 
100    Eina_Bool                             reorder_item_changed : 1;
101    Eina_Bool                             move_effect_enabled : 1;
102 
103    Eina_Bool                             old_h_bounce;
104    Eina_Bool                             old_v_bounce;
105 
106    /* a flag for reorder mode enable/disable */
107    Eina_Bool                             reorder_mode : 1;
108    Eina_Bool                             was_selected : 1;
109 
110    Eina_Bool                             longpressed : 1;
111    Eina_Bool                             pan_changed : 1;
112    Eina_Bool                             horizontal : 1;
113 
114    /* a flag for items can be highlighted or not. by default this flag
115     * is true. */
116    Eina_Bool                             highlight : 1;
117 
118    Eina_Bool                             clear_me : 1; /**< a flag whether
119                                                         * gengrid is marked
120                                                         * as to be cleared or
121                                                         * not. if this flag
122                                                         * is true, gengrid
123                                                         * clear was already
124                                                         * deferred.  */
125 
126    Eina_Bool                             on_hold : 1;
127 
128    Eina_Bool                             filled : 1;
129    Eina_Bool                             multi : 1; /* a flag for item
130                                                      * multi
131                                                      * selection */
132    Eina_Bool                             show_region : 1;
133    Eina_Bool                             bring_in : 1;
134    Eina_Bool                             mouse_down : 1; /**< a flag that mouse is down on the list at the moment. this flag is set to true on mouse and reset to false on mouse up */
135    /**< value whether item loop feature is enabled or not. */
136    Eina_Bool                             item_loop_enable : 1;
137 
138    Eina_Inlist                          *item_cache; /* an inlist of
139                                                       * edje object it
140                                                       * cache. */
141    int                                   item_cache_count;
142    int                                   item_cache_max;
143 
144    /* custom dimensions may be set for any item.
145     * the logic for placing items requires that either item widths
146     * for horizontal gengrid or item height for vertical gengrid
147     * may be varied at once. */
148 
149    Eina_Bool                          custom_size_mode : 1; /* a flag that items have custom sizes */
150    unsigned int                       *custom_size_sum; /* array to store sum of the widths for items placed already for each row or sum of heights for each column. this is to find location of next item. */
151    unsigned int                       *custom_tot_sum; /* array to store total sum of all widths or heights. this is used for item alignment calculations. */
152    unsigned int                       custom_tot_max; /* maximum of the total sums over all rows or columns. this is also used for item alignment calculations. */
153    unsigned int                       custom_alloc_size; /* amount of memory allocated to above dynamic arrays in terms of number of rows or columns. */
154 
155    Eina_Bool                          scr_minw;
156    Eina_Bool                          scr_minh;
157    Eina_Bool                          order_dirty; /* boolean flag indicating if there needs to be an update to the focus_order of the widget.*/
158 };
159 
160 struct Elm_Gen_Item_Type
161 {
162    Elm_Gen_Item           *it;
163 
164    Elm_Gengrid_Data       *wsd;
165 
166    Ecore_Animator         *item_reorder_move_animator;
167    Evas_Coord              gx, gy, ox, oy, tx, ty, rx, ry;
168    unsigned int            moving_effect_start_time;
169    int                     prev_group;
170 
171    Eina_Bool               group_realized : 1;
172    Eina_Bool               moving : 1;
173    Eina_Bool               nocache_once : 1; /* do not use cache for
174                                               * this item only once */
175    Eina_Bool               nocache : 1; /* do not use cache for this item */
176 
177    /* for non homogeneous items */
178    Evas_Coord              w, h, sw, sh;
179 };
180 
181 typedef struct _Item_Cache Item_Cache;
182 struct _Item_Cache
183 {
184    EINA_INLIST;
185    Evas_Object *base_view, *spacer;
186    const char  *item_style; // it->itc->item_style
187    Eina_List *contents;
188 };
189 
190 typedef struct _Elm_Gengrid_Pan_Data Elm_Gengrid_Pan_Data;
191 struct _Elm_Gengrid_Pan_Data
192 {
193    Evas_Object            *wobj;
194    Elm_Gengrid_Data       *wsd;
195    Ecore_Job              *resize_job;
196 };
197 
198 /**
199  * @}
200  */
201 
202 #define GG_IT(_it) (_it->item)
203 
204 #define ELM_GENGRID_DATA_GET(o, sd) \
205   Elm_Gengrid_Data * sd = efl_data_scope_get(o, ELM_GENGRID_CLASS)
206 
207 #define ELM_GENGRID_PAN_DATA_GET(o, sd) \
208   Elm_Gengrid_Pan_Data * sd = efl_data_scope_get(o, ELM_GENGRID_PAN_CLASS)
209 
210 #define ELM_GENGRID_DATA_GET_FROM_ITEM(it, sd) \
211   Elm_Gengrid_Data * sd = GG_IT(it)->wsd
212 
213 #define ELM_GENGRID_DATA_GET_OR_RETURN(o, ptr)       \
214   ELM_GENGRID_DATA_GET(o, ptr);                      \
215   if (EINA_UNLIKELY(!ptr))                           \
216     {                                                \
217        ERR("No widget data for object %p (%s)",      \
218            o, evas_object_type_get(o));              \
219        return;                                       \
220     }
221 
222 #define ELM_GENGRID_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
223   ELM_GENGRID_DATA_GET(o, ptr);                         \
224   if (EINA_UNLIKELY(!ptr))                              \
225     {                                                   \
226        ERR("No widget data for object %p (%s)",         \
227            o, evas_object_type_get(o));                 \
228        return val;                                      \
229     }
230 
231 #define ELM_GENGRID_CHECK(obj)                              \
232   if (EINA_UNLIKELY(!efl_isa((obj), ELM_GENGRID_CLASS))) \
233     return
234 
235 #define ELM_GENGRID_ITEM_CHECK(it)                          \
236   ELM_WIDGET_ITEM_CHECK_OR_RETURN(it->base, ); \
237   ELM_GENGRID_CHECK(it->base->widget);
238 
239 #define ELM_GENGRID_ITEM_CHECK_OR_RETURN(it, ...)                      \
240   ELM_WIDGET_ITEM_CHECK_OR_RETURN(it->base, __VA_ARGS__); \
241   ELM_GENGRID_CHECK(it->base->widget) __VA_ARGS__;
242 
243 #define ELM_GENGRID_ITEM_CHECK_OR_GOTO(it, label)              \
244   ELM_WIDGET_ITEM_CHECK_OR_GOTO(it->base, label); \
245   if (!it->base->widget || !efl_isa                              \
246         ((it->base->widget), ELM_GENGRID_CLASS)) goto label;
247 
248 #define ELM_GENGRID_ITEM_DATA_GET(o, sd) \
249   Elm_Gen_Item* sd = efl_data_scope_get(o, ELM_GENGRID_ITEM_CLASS)
250 
251 #endif
252