380e07ca94e6cebcbf9de77c939d26b148ae115e
[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    Evas_Object *icon;
7    const char *info;
8    Evas_Object *content; /* part name whose obj is to be set as content */
9 } Elm_Params_Bubble;
10
11 static void
12 external_bubble_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
13 {
14    const Elm_Params_Bubble *p;
15
16    if (to_params) p = to_params;
17    else if (from_params) p = from_params;
18    else return;
19
20    if (p->base.label) elm_bubble_label_set(obj, p->base.label);
21    if (p->icon) elm_bubble_icon_set(obj, p->icon);
22    if (p->info) elm_bubble_info_set(obj, p->info);
23    if (p->content) elm_bubble_content_set(obj, p->content);
24 }
25
26 static Eina_Bool
27 external_bubble_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
28 {
29    if (!strcmp(param->name, "label"))
30      {
31         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
32           {
33              elm_bubble_label_set(obj, param->s);
34              return EINA_TRUE;
35           }
36      }
37    else if (!strcmp(param->name, "icon"))
38      {
39         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
40           {
41              Evas_Object *icon = external_common_param_icon_get(obj, param);
42              if (icon)
43                {
44                   elm_bubble_icon_set(obj, icon);
45                   return EINA_TRUE;
46                }
47           }
48      }
49    else if (!strcmp(param->name, "info"))
50      {
51         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
52           {
53              elm_bubble_info_set(obj, 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 (content)
64                {
65                   elm_bubble_content_set(obj, content);
66                   return EINA_TRUE;
67                }
68           }
69      }
70
71    ERR("unknown parameter '%s' of type '%s'",
72        param->name, edje_external_param_type_str(param->type));
73
74    return EINA_FALSE;
75 }
76
77 static Eina_Bool
78 external_bubble_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
79 {
80    if (!strcmp(param->name, "label"))
81      {
82         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
83           {
84              param->s = elm_bubble_label_get(obj);
85              return EINA_TRUE;
86           }
87      }
88    else if (!strcmp(param->name, "icon"))
89      {
90         /* not easy to get icon name back from live object */
91         return EINA_FALSE;
92      }
93    else if (!strcmp(param->name, "info"))
94      {
95         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
96           {
97              param->s = elm_bubble_info_get(obj);
98              return EINA_TRUE;
99           }
100      }
101    else if (!strcmp(param->name, "content"))
102      {
103         /* not easy to get content name back from live object */
104         return EINA_FALSE;
105      }
106
107    ERR("unknown parameter '%s' of type '%s'",
108        param->name, edje_external_param_type_str(param->type));
109
110    return EINA_FALSE;
111 }
112
113 static void *
114 external_bubble_params_parse(void *data, Evas_Object *obj, const Eina_List *params)
115 {
116    Elm_Params_Bubble *mem;
117    Edje_External_Param *param;
118    const Eina_List *l;
119
120    mem = external_common_params_parse(Elm_Params_Bubble, data, obj, params);
121    if (!mem)
122      return NULL;
123
124    external_common_icon_param_parse(&mem->icon, obj, params);
125
126    EINA_LIST_FOREACH(params, l, param)
127      {
128         if (!strcmp(param->name, "info"))
129           mem->info = eina_stringshare_add(param->s);
130         else if (!strcmp(param->name, "content"))
131           mem->content = external_common_param_edje_object_get(obj, param);
132      }
133
134    return mem;
135 }
136
137  static void
138 external_bubble_params_free(void *params)
139 {
140    Elm_Params_Bubble *mem = params;
141
142    if (mem->icon)
143      evas_object_del(mem->icon);
144    if (mem->content)
145      evas_object_del(mem->content);
146    if (mem->info)
147      eina_stringshare_del(mem->info);
148    external_common_params_free(params);
149 }
150
151 static Edje_External_Param_Info external_bubble_params[] = {
152    DEFINE_EXTERNAL_COMMON_PARAMS,
153    EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
154    EDJE_EXTERNAL_PARAM_INFO_STRING("info"),
155    EDJE_EXTERNAL_PARAM_INFO_STRING("content"),
156    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
157 };
158
159 DEFINE_EXTERNAL_ICON_ADD(bubble, "bubble");
160 DEFINE_EXTERNAL_TYPE_SIMPLE(bubble, "Bubble");