Merge "[Copy&Paste] remove "Paste" button when CBHM has no item"
[framework/uifw/elementary.git] / src / edje_externals / elm_thumb.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Thumb
6 {
7    Elm_Params base;
8    const char *animate;
9 } Elm_Params_Thumb;
10
11 static const char* choices[] = {"loop", "start", "stop", NULL};
12
13 static Elm_Thumb_Animation_Setting
14 _anim_setting_get(const char *anim_str)
15 {
16    unsigned int i;
17
18    assert(sizeof(choices)/sizeof(choices[0]) == ELM_THUMB_ANIMATION_LAST + 1);
19
20    for (i = 0; i < ELM_THUMB_ANIMATION_LAST; i++)
21      {
22         if (!strcmp(anim_str, choices[i]))
23           return i;
24      }
25    return ELM_THUMB_ANIMATION_LAST;
26 }
27
28 static void
29 external_thumb_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
30 {
31    const Elm_Params_Thumb *p;
32
33    if (to_params) p = to_params;
34    else if (from_params) p = from_params;
35    else return;
36
37    if (p->animate)
38      {
39         Elm_Thumb_Animation_Setting set = _anim_setting_get(p->animate);
40         if (set != ELM_THUMB_ANIMATION_LAST)
41            elm_thumb_animate_set(obj, set);
42      }
43 }
44
45 static Eina_Bool
46 external_thumb_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
47 {
48    if (!strcmp(param->name, "animate"))
49      {
50         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
51           {
52              Elm_Thumb_Animation_Setting set = _anim_setting_get(param->s);
53              if (set == ELM_THUMB_ANIMATION_LAST) return EINA_FALSE;
54              elm_thumb_animate_set(obj, set);
55              return EINA_TRUE;
56           }
57      }
58
59    ERR("unknown parameter '%s' of type '%s'",
60        param->name, edje_external_param_type_str(param->type));
61
62    return EINA_FALSE;
63 }
64
65 static Eina_Bool
66 external_thumb_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
67 {
68    if (!strcmp(param->name, "animate"))
69      {
70         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE)
71           {
72              Elm_Thumb_Animation_Setting anim_set = elm_thumb_animate_get(obj);
73
74              if (anim_set == ELM_THUMB_ANIMATION_LAST)
75                return EINA_FALSE;
76
77              param->s = choices[anim_set];
78              return EINA_TRUE;
79           }
80      }
81
82    ERR("unknown parameter '%s' of type '%s'",
83        param->name, edje_external_param_type_str(param->type));
84
85    return EINA_FALSE;
86 }
87
88 static void *
89 external_thumb_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
90 {
91    Elm_Params_Thumb *mem;
92    Edje_External_Param *param;
93    const Eina_List *l;
94
95    mem = calloc(1, sizeof(Elm_Params_Thumb));
96    if (!mem)
97      return NULL;
98
99    EINA_LIST_FOREACH(params, l, param)
100      {
101         if (!strcmp(param->name, "animate"))
102           mem->animate = eina_stringshare_add(param->s);
103      }
104
105    return mem;
106 }
107
108 static Evas_Object *external_thumb_content_get(void *data __UNUSED__,
109                 const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
110 {
111         ERR("No content.");
112         return NULL;
113 }
114
115 static void
116 external_thumb_params_free(void *params)
117 {
118    Elm_Params_Thumb *mem = params;
119
120    if (mem->animate)
121      eina_stringshare_del(mem->animate);
122    free(mem);
123 }
124
125 static Edje_External_Param_Info external_thumb_params[] =
126   {
127     DEFINE_EXTERNAL_COMMON_PARAMS,
128     EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("animate", "loop", choices),
129     EDJE_EXTERNAL_PARAM_INFO_SENTINEL
130   };
131
132 DEFINE_EXTERNAL_ICON_ADD(thumb, "thumb")
133
134 static Evas_Object *
135 external_thumb_add(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *edje, const Eina_List *params __UNUSED__, const char *part_name)
136 {
137    Evas_Object *parent, *obj;
138    external_elm_init();
139    parent = elm_widget_parent_widget_get(edje);
140    if (!parent) parent = edje;
141    elm_need_ethumb(); /* extra command needed */
142    obj = elm_thumb_add(parent);
143    external_signals_proxy(obj, edje, part_name);
144    return obj;
145 }
146 DEFINE_EXTERNAL_TYPE(thumb, "Thumbnail")