9319d5e08d7ee742b48968ae7fd847a4b6614fa4
[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    Eina_Bool align_x_exists;
29    double align_x;
30    Eina_Bool align_y_exists;
31    double align_y;
32 } Elm_Params_Gengrid;
33
34 static void
35 external_gengrid_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
36 {
37    const Elm_Params_Gengrid *p;
38
39    if (to_params) p = to_params;
40    else if (from_params) p = from_params;
41    else return;
42
43    if (p->multi_exists)
44      elm_gengrid_multi_select_set(obj, p->multi);
45    if (p->no_select_exists)
46      {
47         if (p->no_select)
48           elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
49         else
50           elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
51      }
52    if (p->always_select_exists)
53      {
54         if (p->always_select)
55           elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
56         else
57           elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
58      }
59    if (p->h_bounce_exists)
60      {
61         Eina_Bool h_bounce, v_bounce;
62         elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
63         elm_gengrid_bounce_set(obj, p->h_bounce, v_bounce);
64      }
65    if (p->v_bounce_exists)
66      {
67         Eina_Bool h_bounce, v_bounce;
68         elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
69         elm_gengrid_bounce_set(obj, h_bounce, p->v_bounce);
70      }
71    if (p->h_pagerel_exists)
72      {
73         double h_pagerel, v_pagerel;
74         elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
75         elm_gengrid_page_relative_set(obj, h_pagerel, p->v_pagerel);
76      }
77    if (p->v_pagerel_exists)
78      {
79         double h_pagerel, v_pagerel;
80         elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
81         elm_gengrid_page_relative_set(obj, p->h_pagerel, v_pagerel);
82      }
83    if (p->h_itemsize_exists)
84      {
85         int h_itemsize, v_itemsize;
86         elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
87         elm_gengrid_item_size_set(obj, h_itemsize, p->v_itemsize);
88      }
89    if (p->v_itemsize_exists)
90      {
91         int h_itemsize, v_itemsize;
92         elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
93         elm_gengrid_item_size_set(obj, p->h_itemsize, v_itemsize);
94      }
95    else if (p->align_x_exists || p->align_y_exists)
96      {
97         double x, y;
98         elm_gengrid_align_get(obj, &x, &y);
99         if (p->align_x_exists)
100           elm_gengrid_align_set(obj, p->align_x, y);
101         else
102           elm_gengrid_align_set(obj, x, p->align_y);
103      }
104    if (p->horizontal_exists)
105      {
106         elm_gengrid_horizontal_set(obj, p->horizontal);
107      }
108 }
109
110 static Eina_Bool
111 external_gengrid_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
112 {
113    if (!strcmp(param->name, "multi select"))
114      {
115         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
116           {
117              elm_gengrid_multi_select_set(obj, param->i);
118              return EINA_TRUE;
119           }
120      }
121    else if (!strcmp(param->name, "no selected"))
122      {
123         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
124           {
125              if (param->i)
126                elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_NONE);
127              else
128                elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
129              return EINA_TRUE;
130           }
131      }
132    else if (!strcmp(param->name, "always select"))
133      {
134         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
135           {
136              if (param->i)
137                elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
138              else
139                elm_gengrid_select_mode_set (obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
140              return EINA_TRUE;
141           }
142      }
143    else if (!strcmp(param->name, "height bounce"))
144      {
145         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
146           {
147              Eina_Bool h_bounce, v_bounce;
148              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
149              elm_gengrid_bounce_set(obj, param->i, v_bounce);
150              return EINA_TRUE;
151           }
152      }
153    else if (!strcmp(param->name, "width bounce"))
154      {
155         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
156           {
157              Eina_Bool h_bounce, v_bounce;
158              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
159              elm_gengrid_bounce_set(obj, h_bounce, param->i);
160              return EINA_TRUE;
161           }
162      }
163    else if (!strcmp(param->name, "horizontal page relative"))
164      {
165         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
166           {
167              double h_pagerel, v_pagerel;
168              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
169              elm_gengrid_page_relative_set(obj, param->d, v_pagerel);
170              return EINA_TRUE;
171           }
172      }
173    else if (!strcmp(param->name, "vertical page relative"))
174      {
175         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
176           {
177              double h_pagerel, v_pagerel;
178              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
179              elm_gengrid_page_relative_set(obj, h_pagerel, param->d);
180              return EINA_TRUE;
181           }
182      }
183    else if (!strcmp(param->name, "horizontal item size"))
184      {
185         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
186           {
187              int h_itemsize, v_itemsize;
188              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
189              elm_gengrid_item_size_set(obj, param->i, v_itemsize);
190              return EINA_TRUE;
191           }
192      }
193    else if (!strcmp(param->name, "vertical item size"))
194      {
195         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
196           {
197              int h_itemsize, v_itemsize;
198              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
199              elm_gengrid_item_size_set(obj, h_itemsize, param->i);
200              return EINA_TRUE;
201           }
202      }
203    else if (!strcmp(param->name, "horizontal"))
204      {
205         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
206           {
207              elm_gengrid_horizontal_set(obj, param->i);
208              return EINA_TRUE;
209           }
210      }
211    else if (!strcmp(param->name, "align x")
212             && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
213      {
214         double x, y;
215         elm_gengrid_align_get(obj, &x, &y);
216         elm_gengrid_align_set(obj, param->d, y);
217         return EINA_TRUE;
218      }
219    else if (!strcmp(param->name, "align y")
220             && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
221      {
222         double x, y;
223         elm_gengrid_align_get(obj, &x, &y);
224         elm_gengrid_align_set(obj, x, param->d);
225         return EINA_TRUE;
226      }
227    ERR("unknown parameter '%s' of type '%s'",
228        param->name, edje_external_param_type_str(param->type));
229
230    return EINA_FALSE;
231 }
232
233 static Eina_Bool
234 external_gengrid_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
235 {
236    if (!strcmp(param->name, "multi select"))
237      {
238         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
239           {
240              param->i = elm_gengrid_multi_select_get(obj);
241              return EINA_TRUE;
242           }
243      }
244    else if (!strcmp(param->name, "no selected"))
245      {
246         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
247           {
248              if (elm_gengrid_select_mode_get (obj) ==
249                  ELM_OBJECT_SELECT_MODE_NONE)
250                param->i = EINA_TRUE;
251              else
252                param->i = EINA_FALSE;
253              return EINA_TRUE;
254           }
255      }
256    else if (!strcmp(param->name, "always select"))
257      {
258         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
259           {
260              if (elm_gengrid_select_mode_get (obj) ==
261                  ELM_OBJECT_SELECT_MODE_ALWAYS)
262                param->i = EINA_TRUE;
263              else
264                param->i = EINA_FALSE;
265              return EINA_TRUE;
266           }
267      }
268    else if (!strcmp(param->name, "height bounce"))
269      {
270         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
271           {
272              Eina_Bool h_bounce, v_bounce;
273              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
274              param->i = h_bounce;
275              return EINA_TRUE;
276           }
277      }
278    else if (!strcmp(param->name, "width bounce"))
279      {
280         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
281           {
282              Eina_Bool h_bounce, v_bounce;
283              elm_gengrid_bounce_get(obj, &h_bounce, &v_bounce);
284              param->i = v_bounce;
285              return EINA_TRUE;
286           }
287      }
288    else if (!strcmp(param->name, "horizontal page relative"))
289      {
290         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
291           {
292              double h_pagerel, v_pagerel;
293              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
294              param->d = h_pagerel;
295              return EINA_TRUE;
296           }
297      }
298    else if (!strcmp(param->name, "vertical page relative"))
299      {
300         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
301           {
302              double h_pagerel, v_pagerel;
303              elm_gengrid_page_relative_get(obj, &h_pagerel, &v_pagerel);
304              param->d = v_pagerel;
305              return EINA_TRUE;
306           }
307      }
308    else if (!strcmp(param->name, "horizontal item size"))
309      {
310         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
311           {
312              int h_itemsize, v_itemsize;
313              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
314              param->i = h_itemsize;
315              return EINA_TRUE;
316           }
317      }
318    else if (!strcmp(param->name, "vertical item size"))
319      {
320         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
321           {
322              int h_itemsize, v_itemsize;
323              elm_gengrid_item_size_get(obj, &h_itemsize, &v_itemsize);
324              param->i = v_itemsize;
325              return EINA_TRUE;
326           }
327      }
328    else if (!strcmp(param->name, "horizontal"))
329      {
330         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
331           {
332              param->i = elm_gengrid_horizontal_get(obj);
333              return EINA_TRUE;
334           }
335      }
336    else if (!strcmp(param->name, "align x")
337             && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
338      {
339         double x, y;
340         elm_gengrid_align_get(obj, &x, &y);
341         param->d = x;
342         return EINA_TRUE;
343      }
344    else if (!strcmp(param->name, "align y")
345             && param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
346      {
347         double x, y;
348         elm_gengrid_align_get(obj, &x, &y);
349         param->d = y;
350         return EINA_TRUE;
351      }
352    ERR("unknown parameter '%s' of type '%s'",
353        param->name, edje_external_param_type_str(param->type));
354
355    return EINA_FALSE;
356 }
357
358 static void *
359 external_gengrid_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
360 {
361    Elm_Params_Gengrid *mem;
362    Edje_External_Param *param;
363    const Eina_List *l;
364
365    mem = ELM_NEW(Elm_Params_Gengrid);
366    if (!mem)
367      return NULL;
368
369    EINA_LIST_FOREACH(params, l, param)
370      {
371         if (!strcmp(param->name, "multi select"))
372           {
373              mem->multi = !!param->i;
374              mem->multi_exists = EINA_TRUE;
375           }
376         else if (!strcmp(param->name, "no selected"))
377           {
378              mem->no_select = !!param->i;
379              mem->no_select_exists = EINA_TRUE;
380           }
381         else if (!strcmp(param->name, "always select"))
382           {
383              mem->always_select = !!param->i;
384              mem->always_select_exists = EINA_TRUE;
385           }
386         else if (!strcmp(param->name, "height bounce"))
387           {
388              mem->h_bounce = !!param->i;
389              mem->h_bounce_exists = EINA_TRUE;
390           }
391         else if (!strcmp(param->name, "width bounce"))
392           {
393              mem->v_bounce = !!param->i;
394              mem->v_bounce_exists = EINA_TRUE;
395           }
396         else if (!strcmp(param->name, "horizontal page relative"))
397           {
398              mem->h_pagerel = param->d;
399              mem->h_pagerel_exists = EINA_TRUE;
400           }
401         else if (!strcmp(param->name, "vertical page relative"))
402           {
403              mem->v_pagerel = param->d;
404              mem->v_pagerel_exists = EINA_TRUE;
405           }
406         else if (!strcmp(param->name, "horizontal item size"))
407           {
408              mem->h_itemsize = param->i;
409              mem->h_itemsize_exists = EINA_TRUE;
410           }
411         else if (!strcmp(param->name, "vertical item size"))
412           {
413              mem->v_itemsize = param->i;
414              mem->v_itemsize_exists = EINA_TRUE;
415           }
416         else if (!strcmp(param->name, "horizontal"))
417           {
418              mem->horizontal = !!param->i;
419              mem->horizontal_exists = EINA_TRUE;
420           }
421         else if (!strcmp(param->name, "align x"))
422           {
423              mem->align_x = param->d;
424              mem->align_x_exists = EINA_TRUE;
425           }
426         else if (!strcmp(param->name, "align y"))
427           {
428              mem->align_y = param->d;
429              mem->align_y_exists = EINA_TRUE;
430           }
431      }
432
433    return mem;
434 }
435
436 static Evas_Object *
437 external_gengrid_content_get(void *data __UNUSED__, const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
438 {
439    ERR("No content.");
440    return NULL;
441 }
442
443 static void
444 external_gengrid_params_free(void *params)
445 {
446    Elm_Params_Gengrid *mem = params;
447    free(mem);
448 }
449
450 static Edje_External_Param_Info external_gengrid_params[] = {
451    DEFINE_EXTERNAL_COMMON_PARAMS,
452    EDJE_EXTERNAL_PARAM_INFO_BOOL("multi select"),
453    EDJE_EXTERNAL_PARAM_INFO_BOOL("no select"),
454    EDJE_EXTERNAL_PARAM_INFO_BOOL("always select"),
455    EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
456    EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
457    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("horizontal page relative"),
458    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("vertical page relative"),
459    EDJE_EXTERNAL_PARAM_INFO_INT("horizontal item size"),
460    EDJE_EXTERNAL_PARAM_INFO_INT("vertical item size"),
461    EDJE_EXTERNAL_PARAM_INFO_BOOL("horizontal"),
462    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("align x"),
463    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("align y"),
464    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
465 };
466
467 DEFINE_EXTERNAL_ICON_ADD(gengrid, "gengrid");
468 DEFINE_EXTERNAL_TYPE_SIMPLE(gengrid, "Generic Grid");