Initialize Tizen 2.3
[framework/uifw/elementary.git] / wearable / src / edje_externals / elm_notify.c
1 #include "private.h"
2 #include <assert.h>
3
4
5 typedef struct _Elm_Params_Notify Elm_Params_Notify;
6
7 struct _Elm_Params_Notify {
8         Elm_Params base;
9         Evas_Object *content; /* part name whose obj is to be set as content */
10         Eina_Bool allow_events_exists;
11         Eina_Bool allow_events;
12         Eina_Bool timeout_exists;
13         double timeout;
14
15         const char *orient;
16 };
17
18
19 static const char *orients[] = {
20                 "top",
21                 "center",
22                 "bottom",
23                 "left",
24                 "right",
25                 "top_left",
26                 "top_right",
27                 "bottom_left",
28                 "bottom_right",
29                 NULL
30 };
31
32 /* keeping old externals orient api for notify, but taking away the
33  * introduced deprecation warning by copying the deprecated code
34  * here */
35 static Elm_Notify_Orient
36 _elm_notify_orient_get(const Evas_Object *obj)
37 {
38    Elm_Notify_Orient orient;
39    double horizontal, vertical;
40
41    elm_notify_align_get(obj, &horizontal, &vertical);
42
43    if ((horizontal == 0.5) && (vertical == 0.0))
44      orient = ELM_NOTIFY_ORIENT_TOP;
45    else if ((horizontal == 0.5) && (vertical == 0.5))
46      orient = ELM_NOTIFY_ORIENT_CENTER;
47    else if ((horizontal == 0.5) && (vertical == 1.0))
48      orient = ELM_NOTIFY_ORIENT_BOTTOM;
49    else if ((horizontal == 0.0) && (vertical == 0.5))
50      orient = ELM_NOTIFY_ORIENT_LEFT;
51    else if ((horizontal == 1.0) && (vertical == 0.5))
52      orient = ELM_NOTIFY_ORIENT_RIGHT;
53    else if ((horizontal == 0.0) && (vertical == 0.0))
54      orient = ELM_NOTIFY_ORIENT_TOP_LEFT;
55    else if ((horizontal == 1.0) && (vertical == 0.0))
56      orient = ELM_NOTIFY_ORIENT_TOP_RIGHT;
57    else if ((horizontal == 0.0) && (vertical == 1.0))
58      orient = ELM_NOTIFY_ORIENT_BOTTOM_LEFT;
59    else if ((horizontal == 1.0) && (vertical == 1.0))
60      orient = ELM_NOTIFY_ORIENT_BOTTOM_RIGHT;
61    else
62      orient = ELM_NOTIFY_ORIENT_TOP;
63    return orient;
64 }
65
66 static void
67 _elm_notify_orient_set(Evas_Object *obj,
68                        Elm_Notify_Orient orient)
69 {
70    double horizontal = 0, vertical = 0;
71
72    switch (orient)
73      {
74       case ELM_NOTIFY_ORIENT_TOP:
75          horizontal = 0.5; vertical = 0.0;
76         break;
77
78       case ELM_NOTIFY_ORIENT_CENTER:
79          horizontal = 0.5; vertical = 0.5;
80         break;
81
82       case ELM_NOTIFY_ORIENT_BOTTOM:
83          horizontal = 0.5; vertical = 1.0;
84         break;
85
86       case ELM_NOTIFY_ORIENT_LEFT:
87          horizontal = 0.0; vertical = 0.5;
88         break;
89
90       case ELM_NOTIFY_ORIENT_RIGHT:
91          horizontal = 1.0; vertical = 0.5;
92         break;
93
94       case ELM_NOTIFY_ORIENT_TOP_LEFT:
95          horizontal = 0.0; vertical = 0.0;
96         break;
97
98       case ELM_NOTIFY_ORIENT_TOP_RIGHT:
99          horizontal = 1.0; vertical = 0.0;
100         break;
101
102       case ELM_NOTIFY_ORIENT_BOTTOM_LEFT:
103          horizontal = 0.0; vertical = 1.0;
104         break;
105
106       case ELM_NOTIFY_ORIENT_BOTTOM_RIGHT:
107          horizontal = 1.0; vertical = 1.0;
108         break;
109
110       case ELM_NOTIFY_ORIENT_LAST:
111         break;
112      }
113
114    elm_notify_align_set(obj, horizontal, vertical);
115 }
116
117 static Elm_Notify_Orient _orient_get(const char *orient)
118 {
119    unsigned int i;
120
121    assert(sizeof(orients)/sizeof(orients[0]) ==
122           ELM_NOTIFY_ORIENT_LAST + 1);
123
124    for (i = 0; i < ELM_NOTIFY_ORIENT_LAST; i++)
125      if (!strcmp(orient, orients[i])) return i;
126
127    return ELM_NOTIFY_ORIENT_LAST;
128 }
129
130 static void external_notify_state_set(void *data __UNUSED__,
131                 Evas_Object *obj, const void *from_params,
132                 const void *to_params, float pos __UNUSED__)
133 {
134         const Elm_Params_Notify *p;
135
136         if (to_params) p = to_params;
137         else if (from_params) p = from_params;
138         else return;
139
140         if (p->content) {
141                 elm_object_content_set(obj, p->content);
142         }
143         if (p->allow_events_exists)
144                 elm_notify_allow_events_set(obj, p->allow_events);
145         if (p->timeout_exists)
146                 elm_notify_timeout_set(obj, p->timeout);
147         if (p->orient)
148         {
149                 Elm_Notify_Orient set = _orient_get(p->orient);
150                 if (set == ELM_NOTIFY_ORIENT_LAST) return;
151                 _elm_notify_orient_set(obj, set);
152         }
153 }
154
155 static Eina_Bool external_notify_param_set(void *data __UNUSED__,
156                 Evas_Object *obj, const Edje_External_Param *param)
157 {
158         if ((!strcmp(param->name, "content"))
159                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING))
160         {
161                 Evas_Object *content = external_common_param_edje_object_get(obj, param);
162                 if ((strcmp(param->s, "")) && (!content))
163                         return EINA_FALSE;
164                 elm_object_content_set(obj, content);
165                 return EINA_TRUE;
166         }
167         else if ((!strcmp(param->name, "allow_events"))
168                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL))
169         {
170                 elm_notify_allow_events_set(obj, param->i);
171                 return EINA_TRUE;
172         }
173         else if ((!strcmp(param->name, "timeout"))
174                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE))
175         {
176                 elm_notify_timeout_set(obj, param->d);
177                 return EINA_TRUE;
178         }
179         else if ((!strcmp(param->name, "orient"))
180                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE))
181         {
182                 Elm_Notify_Orient set = _orient_get(param->s);
183                 if (set == ELM_NOTIFY_ORIENT_LAST) return EINA_FALSE;
184                 _elm_notify_orient_set(obj, set);
185                 return EINA_TRUE;
186         }
187
188         ERR("unknown parameter '%s' of type '%s'",
189                         param->name, edje_external_param_type_str(param->type));
190
191         return EINA_FALSE;
192 }
193
194 static Eina_Bool external_notify_param_get(void *data __UNUSED__,
195                 const Evas_Object *obj, Edje_External_Param *param)
196 {
197         if (!strcmp(param->name, "content"))
198         {
199                 /* not easy to get content name back from live object */
200                 return EINA_FALSE;
201         }
202         else if ((!strcmp(param->name, "allow_events"))
203                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL))
204         {
205                 param->i = elm_notify_allow_events_get(obj);
206                 return EINA_TRUE;
207         }
208         else if ((!strcmp(param->name, "timeout"))
209                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE))
210         {
211                 param->d = elm_notify_timeout_get(obj);
212                 return EINA_TRUE;
213         }
214         else if ((!strcmp(param->name, "orient"))
215                         && (param->type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE))
216         {
217                 Elm_Notify_Orient set = _elm_notify_orient_get(obj);
218                 if (set == ELM_NOTIFY_ORIENT_LAST) return EINA_FALSE;
219                 param->s = orients[set];
220                 return EINA_TRUE;
221         }
222
223         ERR("unknown parameter '%s' of type '%s'",
224                         param->name, edje_external_param_type_str(param->type));
225
226         return EINA_FALSE;
227 }
228
229 static void * external_notify_params_parse(void *data __UNUSED__, Evas_Object *obj,
230                 const Eina_List *params) {
231         Elm_Params_Notify *mem;
232         Edje_External_Param *param;
233         const Eina_List *l;
234
235         mem = calloc(1, sizeof(Elm_Params_Notify));
236         if (!mem)
237                 return NULL;
238
239         EINA_LIST_FOREACH(params, l, param)
240         {
241                 if (!strcmp(param->name, "content"))
242                         mem->content = external_common_param_edje_object_get(obj, param);
243                 else if (!strcmp(param->name, "timeout"))
244                 {
245                         mem->timeout = param->d;
246                         mem->timeout_exists = EINA_TRUE;
247                 }
248                 else if (!strcmp(param->name, "allow_events"))
249                 {
250                         mem->allow_events = param->i;
251                         mem->allow_events_exists = EINA_TRUE;
252                 }
253                 else if (!strcmp(param->name, "orient"))
254                           mem->orient = eina_stringshare_add(param->s);
255         }
256
257         return mem;
258 }
259
260 static Evas_Object *external_notify_content_get(void *data __UNUSED__,
261                 const Evas_Object *obj, const char *content)
262 {
263         if (!strcmp(content, "content"))
264                 return elm_object_content_get(obj);
265
266         ERR("unknown content '%s'", content);
267         return NULL;
268 }
269
270 static void external_notify_params_free(void *params) {
271         free(params);
272 }
273
274 static Edje_External_Param_Info external_notify_params[] = {
275                 DEFINE_EXTERNAL_COMMON_PARAMS,
276                 EDJE_EXTERNAL_PARAM_INFO_STRING("content"),
277                 EDJE_EXTERNAL_PARAM_INFO_BOOL("allow_events"),
278                 EDJE_EXTERNAL_PARAM_INFO_DOUBLE("timeout"),
279                 EDJE_EXTERNAL_PARAM_INFO_SENTINEL
280 };
281
282 DEFINE_EXTERNAL_ICON_ADD(notify, "notify");
283 DEFINE_EXTERNAL_TYPE_SIMPLE(notify, "Notify")
284 ;