tizen 2.3 release
[framework/uifw/elementary.git] / src / edje_externals / elm_bubble.c
1 #include "private.h"
2
3 typedef struct _Elm_Params_Bubble
4 {
5    Elm_Params base;
6    const char *label;
7    Evas_Object *icon;
8    const char *info;
9    Evas_Object *content; /* part name whose obj is to be set as content */
10 } Elm_Params_Bubble;
11
12 static void
13 external_bubble_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
14 {
15    const Elm_Params_Bubble *p;
16
17    if (to_params) p = to_params;
18    else if (from_params) p = from_params;
19    else return;
20
21    if (p->label) elm_object_text_set(obj, p->label);
22    if (p->icon)
23      elm_object_part_content_set(obj, "icon", p->icon);
24    if (p->info) elm_object_part_text_set(obj, "info", p->info);
25    if (p->content) elm_object_content_set(obj, p->content);
26 }
27
28 static Eina_Bool
29 external_bubble_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
30 {
31    if (!strcmp(param->name, "label"))
32      {
33         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
34           {
35              elm_object_text_set(obj, param->s);
36              return EINA_TRUE;
37           }
38      }
39    else if (!strcmp(param->name, "icon"))
40      {
41         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
42           {
43              Evas_Object *icon = external_common_param_icon_get(obj, param);
44              if ((strcmp(param->s, "")) && (!icon)) return EINA_FALSE;
45              elm_object_part_content_set(obj, "icon", icon);
46         return EINA_TRUE;
47           }
48      }
49    else if (!strcmp(param->name, "info"))
50      {
51         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
52           {
53              elm_object_part_text_set(obj, "info", param->s);
54              return EINA_TRUE;
55           }
56      }
57    else if (!strcmp(param->name, "content"))
58      {
59         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
60           {
61              Evas_Object *content = \
62                     external_common_param_edje_object_get(obj, param);
63              if ((strcmp(param->s, "")) && (!content)) return EINA_FALSE;
64              elm_object_content_set(obj, content);
65              return EINA_TRUE;
66           }
67      }
68
69    ERR("unknown parameter '%s' of type '%s'",
70        param->name, edje_external_param_type_str(param->type));
71
72    return EINA_FALSE;
73 }
74
75 static Eina_Bool
76 external_bubble_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
77 {
78    if (!strcmp(param->name, "label"))
79      {
80         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
81           {
82              param->s = elm_object_text_get(obj);
83              return EINA_TRUE;
84           }
85      }
86    else if (!strcmp(param->name, "icon"))
87      {
88         /* not easy to get icon name back from live object */
89         return EINA_FALSE;
90      }
91    else if (!strcmp(param->name, "info"))
92      {
93         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
94           {
95              param->s = elm_object_part_text_get(obj, "info");
96              return EINA_TRUE;
97           }
98      }
99    else if (!strcmp(param->name, "content"))
100      {
101         /* not easy to get content name back from live object */
102         return EINA_FALSE;
103      }
104
105    ERR("unknown parameter '%s' of type '%s'",
106        param->name, edje_external_param_type_str(param->type));
107
108    return EINA_FALSE;
109 }
110
111 static void *
112 external_bubble_params_parse(void *data __UNUSED__, Evas_Object *obj, const Eina_List *params)
113 {
114    Elm_Params_Bubble *mem;
115    Edje_External_Param *param;
116    const Eina_List *l;
117
118    mem = calloc(1, sizeof(Elm_Params_Bubble));
119    if (!mem)
120      return NULL;
121
122    external_common_icon_param_parse(&mem->icon, obj, params);
123
124    EINA_LIST_FOREACH(params, l, param)
125      {
126         if (!strcmp(param->name, "info"))
127           mem->info = eina_stringshare_add(param->s);
128         else if (!strcmp(param->name, "content"))
129           mem->content = external_common_param_edje_object_get(obj, param);
130         else if (!strcmp(param->name, "label"))
131           mem->label = eina_stringshare_add(param->s);
132      }
133
134    return mem;
135 }
136
137 static Evas_Object *external_bubble_content_get(void *data __UNUSED__,
138                 const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
139 {
140    if (!strcmp(content, "content"))
141      return elm_object_content_get(obj);
142    ERR("unknown content '%s'", content);
143    return NULL;
144 }
145
146 static void
147 external_bubble_params_free(void *params)
148 {
149    Elm_Params_Bubble *mem = params;
150
151    if (mem->info)
152      eina_stringshare_del(mem->info);
153    if (mem->label)
154       eina_stringshare_del(mem->label);
155    free(params);
156 }
157
158 static Edje_External_Param_Info external_bubble_params[] = {
159    DEFINE_EXTERNAL_COMMON_PARAMS,
160    EDJE_EXTERNAL_PARAM_INFO_STRING("label"),
161    EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
162    EDJE_EXTERNAL_PARAM_INFO_STRING("info"),
163    EDJE_EXTERNAL_PARAM_INFO_STRING("content"),
164    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
165 };
166
167 DEFINE_EXTERNAL_ICON_ADD(bubble, "bubble");
168 DEFINE_EXTERNAL_TYPE_SIMPLE(bubble, "Bubble");