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