Merge branch 'intefl/svn_merge' of ssh://165.213.149.219:29418/slp/pkgs/e/elementary...
[framework/uifw/elementary.git] / src / edje_externals / elm_icon.c
1 #include <assert.h>
2 #include "private.h"
3
4 typedef struct _Elm_Params_Icon
5 {
6    const char *file;
7    Eina_Bool scale_up_exists;
8    Eina_Bool scale_up : 1;
9    Eina_Bool scale_down_exists;
10    Eina_Bool scale_down : 1;
11    Eina_Bool smooth_exists;
12    Eina_Bool smooth : 1;
13    Eina_Bool fill_outside_exists;
14    Eina_Bool fill_outside : 1;
15    Eina_Bool no_scale_exists;
16    Eina_Bool no_scale : 1;
17    Eina_Bool prescale_size_exists;
18    int prescale_size;
19    Elm_Params base;
20    const char *icon;
21 } Elm_Params_Icon;
22
23 static Elm_Params_Icon *param_icon;
24
25 static void
26 external_icon_state_set(void *data __UNUSED__, Evas_Object *obj,
27                         const void *from_params, const void *to_params,
28                         float pos __UNUSED__)
29 {
30    const Elm_Params_Icon *p;
31    Evas_Object *edje;
32    const char *file;
33
34    if (to_params) p = to_params;
35    else if (from_params) p = from_params;
36    else return;
37
38    if (p->file)
39      {
40         elm_icon_file_set(obj, p->file, NULL);
41 <<<<<<< HEAD
42         param_icon->file = p->file;
43 =======
44         param_icon->file = p->file;
45 >>>>>>> remotes/origin/upstream
46      }
47    if (p->smooth_exists)
48      {
49         elm_icon_smooth_set(obj, p->smooth);
50 <<<<<<< HEAD
51         param_icon->smooth = p->smooth;
52 =======
53         param_icon->smooth = p->smooth;
54 >>>>>>> remotes/origin/upstream
55      }
56    if (p->no_scale_exists)
57      {
58         elm_icon_no_scale_set(obj, p->no_scale);
59 <<<<<<< HEAD
60         param_icon->no_scale = p->no_scale;
61      }
62    if (p->scale_up_exists && p->scale_down_exists)
63      {
64         elm_icon_scale_set(obj, p->scale_up, p->scale_down);
65         param_icon->scale_up = p->scale_up;
66         param_icon->scale_down = p->scale_down;
67      }
68    else if (p->scale_up_exists || p->scale_down_exists)
69      {
70         if (p->scale_up_exists)
71           {
72              elm_icon_scale_set(obj, p->scale_up, param_icon->scale_down);
73              param_icon->scale_up = p->scale_up;
74           }
75         else
76           {
77              elm_icon_scale_set(obj, param_icon->scale_up, p->scale_down);
78              param_icon->scale_down = p->scale_down;
79           }
80 =======
81         param_icon->no_scale = p->no_scale;
82      }
83    if (p->scale_up_exists && p->scale_down_exists)
84      {
85         elm_icon_resizable_set(obj, p->scale_up, p->scale_down);
86         param_icon->scale_up = p->scale_up;
87         param_icon->scale_down = p->scale_down;
88      }
89    else if (p->scale_up_exists || p->scale_down_exists)
90      {
91         if (p->scale_up_exists)
92           {
93              elm_icon_resizable_set(obj, p->scale_up, param_icon->scale_down);
94              param_icon->scale_up = p->scale_up;
95           }
96         else
97           {
98              elm_icon_resizable_set(obj, param_icon->scale_up, p->scale_down);
99              param_icon->scale_down = p->scale_down;
100           }
101 >>>>>>> remotes/origin/upstream
102      }
103    if (p->fill_outside_exists)
104      {
105         elm_icon_fill_outside_set(obj, p->fill_outside);
106 <<<<<<< HEAD
107         param_icon->fill_outside = p->fill_outside;
108 =======
109         param_icon->fill_outside = p->fill_outside;
110 >>>>>>> remotes/origin/upstream
111      }
112    if (p->prescale_size_exists)
113      {
114         elm_icon_prescale_set(obj, p->prescale_size);
115 <<<<<<< HEAD
116         param_icon->prescale_size = p->prescale_size;
117 =======
118         param_icon->prescale_size = p->prescale_size;
119 >>>>>>> remotes/origin/upstream
120      }
121    if (p->icon)
122      {
123         edje = evas_object_smart_parent_get(obj);
124         edje_object_file_get(edje, &file, NULL);
125
126         if (!elm_icon_file_set(obj, file, p->icon))
127           elm_icon_standard_set(obj, p->icon);
128      }
129 }
130
131 static Eina_Bool
132 external_icon_param_set(void *data __UNUSED__, Evas_Object *obj,
133                         const Edje_External_Param *param)
134 {
135    Evas_Object *edje;
136    const char *file;
137
138    if (!strcmp(param->name, "file")
139                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
140      {
141         Eina_Bool ret = elm_icon_file_set(obj, param->s, NULL);
142         if (ret)
143           param_icon->file = param->s;
144         return ret;
145      }
146    else if (!strcmp(param->name, "smooth")
147 <<<<<<< HEAD
148                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
149      {
150         elm_icon_smooth_set(obj, param->i);
151         param_icon->smooth = param->i;
152         return EINA_TRUE;
153      }
154    else if (!strcmp(param->name, "no scale")
155                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
156      {
157         elm_icon_no_scale_set(obj, param->i);
158         param_icon->no_scale = param->i;
159         return EINA_TRUE;
160      }
161    else if (!strcmp(param->name, "scale up")
162                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
163      {
164         elm_icon_scale_set(obj, param->i, param_icon->scale_down);
165         param_icon->scale_up = param->i;
166         return EINA_TRUE;
167      }
168    else if (!strcmp(param->name, "scale down")
169                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
170      {
171         elm_icon_scale_set(obj, param_icon->scale_up, param->i);
172         param_icon->scale_down = param->i;
173         return EINA_TRUE;
174      }
175    else if (!strcmp(param->name, "fill outside")
176                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
177      {
178         elm_icon_fill_outside_set(obj, param->i);
179         param_icon->fill_outside = param->i;
180         return EINA_TRUE;
181      }
182    else if (!strcmp(param->name, "prescale")
183                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
184      {
185         elm_icon_prescale_set(obj, param->i);
186         param_icon->prescale_size = param->i;
187         return EINA_TRUE;
188 =======
189             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
190      {
191         elm_icon_smooth_set(obj, param->i);
192         param_icon->smooth = param->i;
193         return EINA_TRUE;
194      }
195    else if (!strcmp(param->name, "no scale")
196             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
197      {
198         elm_icon_no_scale_set(obj, param->i);
199         param_icon->no_scale = param->i;
200         return EINA_TRUE;
201      }
202    else if (!strcmp(param->name, "scale up")
203             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
204      {
205         elm_icon_resizable_set(obj, param->i, param_icon->scale_down);
206         param_icon->scale_up = param->i;
207         return EINA_TRUE;
208      }
209    else if (!strcmp(param->name, "scale down")
210             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
211      {
212         elm_icon_resizable_set(obj, param_icon->scale_up, param->i);
213         param_icon->scale_down = param->i;
214         return EINA_TRUE;
215      }
216    else if (!strcmp(param->name, "fill outside")
217             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
218      {
219         elm_icon_fill_outside_set(obj, param->i);
220         param_icon->fill_outside = param->i;
221         return EINA_TRUE;
222      }
223    else if (!strcmp(param->name, "prescale")
224             && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
225      {
226         elm_icon_prescale_set(obj, param->i);
227         param_icon->prescale_size = param->i;
228         return EINA_TRUE;
229 >>>>>>> remotes/origin/upstream
230      }
231    else if (!strcmp(param->name, "icon"))
232      {
233         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
234           {
235              edje = evas_object_smart_parent_get(obj);
236              edje_object_file_get(edje, &file, NULL);
237
238              if (!elm_icon_file_set(obj, file, param->s))
239                elm_icon_standard_set(obj, param->s);
240              return EINA_TRUE;
241           }
242      }
243
244    ERR("unknown parameter '%s' of type '%s'",
245        param->name, edje_external_param_type_str(param->type));
246
247    return EINA_FALSE;
248 }
249
250 static Eina_Bool
251 external_icon_param_get(void *data __UNUSED__,
252                         const Evas_Object *obj __UNUSED__,
253                         Edje_External_Param *param)
254 {
255    if (!strcmp(param->name, "file")
256                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
257      {
258         param->s = param_icon->file;
259 <<<<<<< HEAD
260         return EINA_TRUE;
261      }
262    else if (!strcmp(param->name, "smooth")
263                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
264      {
265         param->i = param_icon->smooth;
266         return EINA_TRUE;
267      }
268    else if (!strcmp(param->name, "no scale")
269                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
270      {
271         param->i = param_icon->no_scale;
272         return EINA_TRUE;
273      }
274    else if (!strcmp(param->name, "scale up")
275                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
276      {
277         param->i = param_icon->scale_up;
278         return EINA_TRUE;
279      }
280    else if (!strcmp(param->name, "scale down")
281                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
282      {
283         param->i = param_icon->scale_down;
284         return EINA_TRUE;
285      }
286    else if (!strcmp(param->name, "fill outside")
287                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
288      {
289         param->i = param_icon->fill_outside;
290         return EINA_TRUE;
291      }
292    else if (!strcmp(param->name, "prescale")
293                    && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
294      {
295         param->i = param_icon->prescale_size;
296         return EINA_TRUE;
297 =======
298         return EINA_TRUE;
299      }
300    else if (!strcmp(param->name, "smooth")
301             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
302      {
303         param->i = param_icon->smooth;
304         return EINA_TRUE;
305      }
306    else if (!strcmp(param->name, "no scale")
307             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
308      {
309         param->i = param_icon->no_scale;
310         return EINA_TRUE;
311      }
312    else if (!strcmp(param->name, "scale up")
313             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
314      {
315         param->i = param_icon->scale_up;
316         return EINA_TRUE;
317      }
318    else if (!strcmp(param->name, "scale down")
319             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
320      {
321         param->i = param_icon->scale_down;
322         return EINA_TRUE;
323      }
324    else if (!strcmp(param->name, "fill outside")
325             && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
326      {
327         param->i = param_icon->fill_outside;
328         return EINA_TRUE;
329      }
330    else if (!strcmp(param->name, "prescale")
331             && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
332      {
333         param->i = param_icon->prescale_size;
334         return EINA_TRUE;
335 >>>>>>> remotes/origin/upstream
336      }
337    else if (!strcmp(param->name, "icon"))
338      {
339         /* not easy to get icon name back from live object */
340         return EINA_FALSE;
341      }
342
343    ERR("unknown parameter '%s' of type '%s'",
344        param->name, edje_external_param_type_str(param->type));
345
346    return EINA_FALSE;
347 }
348
349 static void *
350 external_icon_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
351                            const Eina_List *params)
352 {
353    Elm_Params_Icon *mem;
354    Edje_External_Param *param;
355    const Eina_List *l;
356    param_icon = calloc(1, sizeof(Elm_Params_Icon));
357    mem = ELM_NEW(Elm_Params_Icon);
358    if (!mem)
359      return NULL;
360
361    EINA_LIST_FOREACH(params, l, param)
362      {
363         if (!strcmp(param->name, "file"))
364 <<<<<<< HEAD
365           mem->file = eina_stringshare_add(param->s);
366         else if (!strcmp(param->name, "smooth"))
367           {
368              mem->smooth = param->i;
369              mem->smooth_exists = EINA_TRUE;
370           }
371         else if (!strcmp(param->name, "no scale"))
372           {
373              mem->no_scale = param->i;
374              mem->no_scale_exists = EINA_TRUE;
375           }
376         else if (!strcmp(param->name, "scale up"))
377           {
378              mem->scale_up = param->i;
379              mem->scale_up_exists = EINA_TRUE;
380           }
381         else if (!strcmp(param->name, "scale down"))
382           {
383              mem->scale_down = param->i;
384              mem->scale_down_exists = EINA_TRUE;
385           }
386         else if (!strcmp(param->name, "fill outside"))
387           {
388              mem->fill_outside = param->i;
389              mem->fill_outside_exists = EINA_TRUE;
390           }
391         else if (!strcmp(param->name, "prescale"))
392           {
393              mem->prescale_size = param->i;
394              mem->prescale_size_exists = EINA_TRUE;
395 =======
396           mem->file = eina_stringshare_add(param->s);
397         else if (!strcmp(param->name, "smooth"))
398           {
399              mem->smooth = param->i;
400              mem->smooth_exists = EINA_TRUE;
401           }
402         else if (!strcmp(param->name, "no scale"))
403           {
404              mem->no_scale = param->i;
405              mem->no_scale_exists = EINA_TRUE;
406           }
407         else if (!strcmp(param->name, "scale up"))
408           {
409              mem->scale_up = param->i;
410              mem->scale_up_exists = EINA_TRUE;
411           }
412         else if (!strcmp(param->name, "scale down"))
413           {
414              mem->scale_down = param->i;
415              mem->scale_down_exists = EINA_TRUE;
416           }
417         else if (!strcmp(param->name, "fill outside"))
418           {
419              mem->fill_outside = param->i;
420              mem->fill_outside_exists = EINA_TRUE;
421           }
422         else if (!strcmp(param->name, "prescale"))
423           {
424              mem->prescale_size = param->i;
425              mem->prescale_size_exists = EINA_TRUE;
426 >>>>>>> remotes/origin/upstream
427           }
428         else if (!strcmp(param->name, "icon"))
429           {
430              mem->icon = eina_stringshare_add(param->s);
431           }
432      }
433
434    return mem;
435 }
436
437 static Evas_Object *
438 external_icon_content_get(void *data __UNUSED__,
439                           const Evas_Object *obj __UNUSED__,
440                           const char *content __UNUSED__)
441 {
442    ERR("no content");
443    return NULL;
444 }
445
446 static void
447 external_icon_params_free(void *params)
448 {
449    Elm_Params_Icon *mem = params;
450
451    if (mem->file)
452      eina_stringshare_del(mem->file);
453
454    if (param_icon->file)
455      eina_stringshare_del(param_icon->file);
456    free(param_icon);
457
458    if (mem->icon)
459      eina_stringshare_del(mem->icon);
460    free(mem);
461 }
462
463 static Edje_External_Param_Info external_icon_params[] = {
464    DEFINE_EXTERNAL_COMMON_PARAMS,
465    EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
466    EDJE_EXTERNAL_PARAM_INFO_STRING("file"),
467    EDJE_EXTERNAL_PARAM_INFO_BOOL("smooth"),
468    EDJE_EXTERNAL_PARAM_INFO_BOOL("no scale"),
469    EDJE_EXTERNAL_PARAM_INFO_BOOL("scale up"),
470    EDJE_EXTERNAL_PARAM_INFO_BOOL("scale down"),
471    EDJE_EXTERNAL_PARAM_INFO_BOOL("fill outside"),
472    EDJE_EXTERNAL_PARAM_INFO_INT("prescale"),
473    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
474 };
475
476 DEFINE_EXTERNAL_ICON_ADD(icon, "icon");
477 DEFINE_EXTERNAL_TYPE_SIMPLE(icon, "Icon");