45faca58cd5ed057df6853274c060aa68522b3b8
[framework/uifw/elementary.git] / src / edje_externals / elm_gengrid.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Gengrid
6 {
7    Elm_Params base;
8    Eina_Bool multi : 1;
9    Eina_Bool multi_exists : 1;
10    Eina_Bool no_select : 1;
11    Eina_Bool no_select_exists : 1;
12    Eina_Bool always_select : 1;
13    Eina_Bool always_select_exists : 1;
14    Eina_Bool h_bounce:1;
15    Eina_Bool h_bounce_exists:1;
16    Eina_Bool v_bounce:1;
17    Eina_Bool v_bounce_exists:1;
18    double    h_pagerel;
19    Eina_Bool h_pagerel_exists : 1;
20    double    v_pagerel;
21    Eina_Bool v_pagerel_exists : 1;
22    int       h_itemsize;
23    Eina_Bool h_itemsize_exists : 1;
24    int       v_itemsize;
25    Eina_Bool v_itemsize_exists : 1;
26    Eina_Bool horizontal : 1;
27    Eina_Bool horizontal_exists : 1;
28 } Elm_Params_Gengrid;
29
30 static void
31 external_gengrid_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
32 {
33    const Elm_Params_Gengrid *p;
34
35    if (to_params) p = to_params;
36    else if (from_params) p = from_params;
37    else return;
38
39    if (p->multi_exists)
40      elm_gengrid_multi_select_set(obj, p->multi);
41    if (p->no_select_exists)
42      elm_gengrid_no_select_mode_set (obj, p->no_select);
43    if (p->always_select_exists)
44      elm_gengrid_always_select_mode_set (obj, p->always_select);
45    if (p->h_bounce_exists)
46      {
47         Eina_Bool h_bounce, v_bounce;
48         elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
49         elm_gengrid_bounce_set(obj, p->h_bounce, v_bounce);
50      }
51    if (p->v_bounce_exists)
52      {
53         Eina_Bool h_bounce, v_bounce;
54         elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
55         elm_gengrid_bounce_set(obj, h_bounce, p->v_bounce);
56      }
57    if (p->h_pagerel_exists)
58      {
59         double h_pagerel, v_pagerel;
60         elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
61         elm_gengrid_page_relative_set(obj, h_pagerel, p->v_pagerel);
62      }
63    if (p->v_pagerel_exists)
64      {
65         double h_pagerel, v_pagerel;
66         elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
67         elm_gengrid_page_relative_set(obj, p->h_pagerel, v_pagerel);
68      }
69    if (p->h_itemsize_exists)
70      {
71         int h_itemsize, v_itemsize;
72         elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
73         elm_gengrid_item_size_set(obj, h_itemsize, p->v_itemsize);
74      }
75    if (p->v_itemsize_exists)
76      {
77         int h_itemsize, v_itemsize;
78         elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
79         elm_gengrid_item_size_set(obj, p->h_itemsize, v_itemsize);
80      }
81    if (p->horizontal_exists)
82      {
83         elm_gengrid_horizontal_set(obj, p->horizontal);
84      }
85 }
86
87 static Eina_Bool
88 external_gengrid_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
89 {
90    if (!strcmp(param->name, "multi select"))
91      {
92         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
93           {
94              elm_gengrid_multi_select_set(obj, param->i);
95              return EINA_TRUE;
96           }
97      }
98    else if (!strcmp(param->name, "no selected"))
99      {
100         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
101           {
102              elm_gengrid_no_select_mode_set(obj, param->i);
103              return EINA_TRUE;
104           }
105      }
106    else if (!strcmp(param->name, "always select"))
107      {
108         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
109           {
110              elm_gengrid_always_select_mode_set(obj, param->i);
111              return EINA_TRUE;
112           }
113      }
114    else if (!strcmp(param->name, "height bounce"))
115      {
116         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
117           {
118              Eina_Bool h_bounce, v_bounce;
119              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
120              elm_gengrid_bounce_set(obj, param->i, v_bounce);
121              return EINA_TRUE;
122           }
123      }
124    else if (!strcmp(param->name, "width bounce"))
125      {
126         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
127           {
128              Eina_Bool h_bounce, v_bounce;
129              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
130              elm_gengrid_bounce_set(obj, h_bounce, param->i);
131              return EINA_TRUE;
132           }
133      }
134    else if (!strcmp(param->name, "horizontal page relative"))
135      {
136         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
137           {
138              double h_pagerel, v_pagerel;
139              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
140              elm_gengrid_page_relative_set(obj, param->d, v_pagerel);
141              return EINA_TRUE;
142           }
143      }
144    else if (!strcmp(param->name, "vertical page relative"))
145      {
146         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
147           {
148              double h_pagerel, v_pagerel;
149              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
150              elm_gengrid_page_relative_set(obj, h_pagerel, param->d);
151              return EINA_TRUE;
152           }
153      }
154    else if (!strcmp(param->name, "horizontal item size"))
155      {
156         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
157           {
158              int h_itemsize, v_itemsize;
159              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
160              elm_gengrid_item_size_set(obj, param->i, v_itemsize);
161              return EINA_TRUE;
162           }
163      }
164    else if (!strcmp(param->name, "vertical item size"))
165      {
166         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
167           {
168              int h_itemsize, v_itemsize;
169              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
170              elm_gengrid_item_size_set(obj, h_itemsize, param->i);
171              return EINA_TRUE;
172           }
173      }
174    else if (!strcmp(param->name, "horizontal"))
175      {
176         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
177           {
178              elm_gengrid_horizontal_set(obj, param->i);
179              return EINA_TRUE;
180           }
181      }
182
183    ERR("unknown parameter '%s' of type '%s'",
184        param->name, edje_external_param_type_str(param->type));
185
186    return EINA_FALSE;
187 }
188
189 static Eina_Bool
190 external_gengrid_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
191 {
192    if (!strcmp(param->name, "multi select"))
193      {
194         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
195           {
196              param->i = elm_gengrid_multi_select_get(obj);
197              return EINA_TRUE;
198           }
199      }
200    else if (!strcmp(param->name, "no selected"))
201      {
202         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
203           {
204              param->i = elm_gengrid_no_select_mode_get(obj);
205              return EINA_TRUE;
206           }
207      }
208    else if (!strcmp(param->name, "always select"))
209      {
210         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
211           {
212              param->i = elm_gengrid_always_select_mode_get(obj);
213              return EINA_TRUE;
214           }
215      }
216    else if (!strcmp(param->name, "height bounce"))
217      {
218         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
219           {
220              Eina_Bool h_bounce, v_bounce;
221              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
222              param->i = h_bounce;
223              return EINA_TRUE;
224           }
225      }
226    else if (!strcmp(param->name, "width bounce"))
227      {
228         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
229           {
230              Eina_Bool h_bounce, v_bounce;
231              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
232              param->i = v_bounce;
233              return EINA_TRUE;
234           }
235      }
236    else if (!strcmp(param->name, "horizontal page relative"))
237      {
238         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
239           {
240              double h_pagerel, v_pagerel;
241              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
242              param->d = h_pagerel;
243              return EINA_TRUE;
244           }
245      }
246    else if (!strcmp(param->name, "vertical page relative"))
247      {
248         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
249           {
250              double h_pagerel, v_pagerel;
251              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
252              param->d = v_pagerel;
253              return EINA_TRUE;
254           }
255      }
256    else if (!strcmp(param->name, "horizontal item size"))
257      {
258         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
259           {
260              int h_itemsize, v_itemsize;
261              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
262              param->i = h_itemsize;
263              return EINA_TRUE;
264           }
265      }
266    else if (!strcmp(param->name, "vertical item size"))
267      {
268         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
269           {
270              int h_itemsize, v_itemsize;
271              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
272              param->i = v_itemsize;
273              return EINA_TRUE;
274           }
275      }
276    else if (!strcmp(param->name, "horizontal"))
277      {
278         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
279           {
280              param->i = elm_gengrid_horizontal_get(obj);
281              return EINA_TRUE;
282           }
283      }
284
285    ERR("unknown parameter '%s' of type '%s'",
286        param->name, edje_external_param_type_str(param->type));
287
288    return EINA_FALSE;
289 }
290
291 static void *
292 external_gengrid_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
293 {
294    Elm_Params_Gengrid *mem;
295    Edje_External_Param *param;
296    const Eina_List *l;
297
298    mem = ELM_NEW(Elm_Params_Gengrid);
299    if (!mem)
300      return NULL;
301
302    EINA_LIST_FOREACH(params, l, param)
303      {
304         if (!strcmp(param->name, "multi select"))
305           {
306              mem->multi = !!param->i;
307              mem->multi_exists = EINA_TRUE;
308           }
309         else if (!strcmp(param->name, "no selected"))
310           {
311              mem->no_select = !!param->i;
312              mem->no_select_exists = EINA_TRUE;
313           }
314         else if (!strcmp(param->name, "always select"))
315           {
316              mem->always_select = !!param->i;
317              mem->always_select_exists = EINA_TRUE;
318           }
319         else if (!strcmp(param->name, "height bounce"))
320           {
321              mem->h_bounce = !!param->i;
322              mem->h_bounce_exists = EINA_TRUE;
323           }
324         else if (!strcmp(param->name, "width bounce"))
325           {
326              mem->v_bounce = !!param->i;
327              mem->v_bounce_exists = EINA_TRUE;
328           }
329         else if (!strcmp(param->name, "horizontal page relative"))
330           {
331              mem->h_pagerel = param->d;
332              mem->h_pagerel_exists = EINA_TRUE;
333           }
334         else if (!strcmp(param->name, "vertical page relative"))
335           {
336              mem->v_pagerel = param->d;
337              mem->v_pagerel_exists = EINA_TRUE;
338           }
339         else if (!strcmp(param->name, "horizontal item size"))
340           {
341              mem->h_itemsize = param->i;
342              mem->h_itemsize_exists = EINA_TRUE;
343           }
344         else if (!strcmp(param->name, "vertical item size"))
345           {
346              mem->v_itemsize = param->i;
347              mem->v_itemsize_exists = EINA_TRUE;
348           }
349         else if (!strcmp(param->name, "horizontal"))
350           {
351              mem->horizontal = !!param->i;
352              mem->horizontal_exists = EINA_TRUE;
353           }
354      }
355
356    return mem;
357 }
358
359 static Evas_Object *
360 external_gengrid_content_get(void *data __UNUSED__, const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
361 {
362    ERR("No content.");
363    return NULL;
364 }
365
366 static void
367 external_gengrid_params_free(void *params)
368 {
369    Elm_Params_Gengrid *mem = params;
370    free(mem);
371 }
372
373 static Edje_External_Param_Info external_gengrid_params[] = {
374    DEFINE_EXTERNAL_COMMON_PARAMS,
375    EDJE_EXTERNAL_PARAM_INFO_BOOL("multi select"),
376    EDJE_EXTERNAL_PARAM_INFO_BOOL("no select"),
377    EDJE_EXTERNAL_PARAM_INFO_BOOL("always select"),
378    EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
379    EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
380    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("horizontal page relative"),
381    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("vertical page relative"),
382    EDJE_EXTERNAL_PARAM_INFO_INT("horizontal item size"),
383    EDJE_EXTERNAL_PARAM_INFO_INT("vertical item size"),
384    EDJE_EXTERNAL_PARAM_INFO_BOOL("horizontal"),
385    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
386 };
387
388 DEFINE_EXTERNAL_ICON_ADD(gengrid, "gengrid");
389 DEFINE_EXTERNAL_TYPE_SIMPLE(gengrid, "Generic Grid");