[popup]: standardization
[framework/uifw/elementary.git] / src / lib / elm_popup.c
1 #include <Elementary.h>\r
2 #include "elm_priv.h"\r
3 #include <stdlib.h>\r
4 \r
5 /**\r
6  * @defgroup Popup Popup\r
7  * @ingroup Elementary\r
8  *\r
9  * This is a popup widget. it can be used to display information/ get information from user.\r
10  */\r
11 \r
12 typedef struct _Widget_Data Widget_Data;\r
13 \r
14 struct _Widget_Data \r
15 {\r
16         Evas_Object     *notify;\r
17         Evas_Object     *layout;\r
18         Evas_Object *parent;\r
19         Evas_Object *parent_app;\r
20         Evas_Object     *title_area;\r
21         Evas_Object    *title_icon;\r
22         Evas_Object     *content_area;\r
23         Evas_Object     *desc_label;\r
24         Evas_Object     *action_area;   \r
25         Eina_List                       *button_list;\r
26         int rot_angle;\r
27         Ecore_Job    *del_job;\r
28         Eina_Bool      delete_me : 1;\r
29 };\r
30 \r
31 typedef struct _action_area_Data Action_Area_Data;\r
32 struct _action_area_Data \r
33 {\r
34         Evas_Object     *obj;   \r
35         int response_id;\r
36 };\r
37 \r
38 static void _del_hook(Evas_Object *obj);\r
39 static void _theme_hook(Evas_Object *obj);\r
40 static void _sizing_eval(Evas_Object *obj);\r
41 static void _elm_popup_buttons_add_valist(Evas_Object *obj,const char *first_button_text,va_list args);\r
42 static Evas_Object* _elm_popup_add_button(Evas_Object *obj,const char *text,int response_id);\r
43 static void _action_area_clicked( void *data, Evas_Object *obj, void *event_info );\r
44 static void _block_clicked_cb( void *data, Evas_Object *obj, void *event_info );\r
45 static void _show(void *data, Evas *e, Evas_Object *obj, void *event_info);\r
46 static void _hide(void *data, Evas *e, Evas_Object *obj, void *event_info);\r
47 static void _resize_parent(void *data, Evas *e, Evas_Object *obj, void *event_info);\r
48 \r
49 static void\r
50 _del_parent(void *data, Evas *e, Evas_Object *obj, void *evet_info)\r
51 {\r
52         Evas_Object *pop = data;\r
53         Widget_Data *wd = elm_widget_data_get(pop);\r
54         if (!wd) return;\r
55         if (wd->parent == obj)\r
56                 {\r
57                         evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _del_parent, pop);\r
58                         wd->parent = NULL;\r
59                 }\r
60 }\r
61 \r
62 static void\r
63 _del_job(void *data)\r
64 {\r
65         Evas_Object *obj = data;\r
66         evas_object_del(obj);\r
67 }\r
68 \r
69 static void\r
70 _del_hook(Evas_Object *obj)\r
71 {\r
72         Widget_Data *wd = elm_widget_data_get(obj);\r
73         if (!wd) return;        \r
74         if (!wd->del_job)\r
75         {\r
76            if (wd->parent)\r
77                         {\r
78                                 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _del_parent, obj);\r
79                                 wd->del_job = ecore_job_add(_del_job, wd->parent);\r
80                    wd->parent = NULL;\r
81                 }\r
82         }\r
83         free(wd);       \r
84 }\r
85 \r
86 static void\r
87 _del_pre_hook(Evas_Object *obj)\r
88 {\r
89         Widget_Data *wd = elm_widget_data_get(obj);\r
90         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_SHOW, _show, NULL);\r
91         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_HIDE, _hide, NULL);\r
92         if(wd->parent_app)\r
93         evas_object_event_callback_del_full(wd->parent_app, EVAS_CALLBACK_RESIZE, _resize_parent, obj);\r
94         eina_list_free(wd->button_list);\r
95 }\r
96 \r
97 static void\r
98 _theme_hook(Evas_Object *obj)\r
99 {\r
100         Widget_Data *wd = elm_widget_data_get(obj);\r
101         char buf[4096];\r
102         Eina_List *list=NULL;\r
103         Evas_Object *btn_obj;\r
104         if (!wd) return;\r
105         \r
106         elm_layout_theme_set(wd->layout, "popup", "base", elm_widget_style_get(obj));\r
107         elm_notify_orient_set(wd->notify, ELM_NOTIFY_ORIENT_CENTER);\r
108         edje_object_message_signal_process( elm_layout_edje_get(wd->layout));\r
109         if(wd->title_area)\r
110                 {\r
111                         snprintf(buf, sizeof(buf), "popup_title/%s", elm_widget_style_get(obj));\r
112                         elm_object_style_set(wd->title_area,buf);\r
113                 }\r
114         if(wd->action_area)\r
115                 {\r
116                          EINA_LIST_FOREACH(wd->button_list, list, btn_obj)\r
117                                 {\r
118                                         snprintf(buf, sizeof(buf), "popup_button/%s", elm_widget_style_get(obj));\r
119                                         elm_object_style_set(btn_obj, buf);\r
120                                 }\r
121                 }\r
122         if(wd->content_area)\r
123                 {\r
124                         elm_layout_theme_set(wd->content_area,"popup","content",elm_widget_style_get(obj));\r
125                         if(wd->desc_label)\r
126                                 {\r
127                                         snprintf(buf, sizeof(buf), "popup_description/%s", elm_widget_style_get(obj));\r
128                                         elm_object_style_set(wd->desc_label,buf);\r
129                                 }\r
130                 }               \r
131         _sizing_eval(obj);\r
132 }\r
133 \r
134 static void\r
135 _sizing_eval(Evas_Object *obj)\r
136 {\r
137         Widget_Data *wd = elm_widget_data_get(obj);\r
138         Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;\r
139 \r
140         edje_object_size_min_calc(elm_layout_edje_get(wd->layout), &minw, &minh);\r
141         evas_object_size_hint_min_set(obj, minw, minh);\r
142         evas_object_size_hint_max_set(obj, maxw, maxh);\r
143 }\r
144 \r
145 static void\r
146 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)\r
147 {\r
148    _sizing_eval(data);\r
149 }\r
150 \r
151 static void _block_clicked_cb( void *data, Evas_Object *obj, void *event_info )\r
152 {       \r
153         evas_object_hide((Evas_Object*)data);   \r
154         evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_NONE);              \r
155 }\r
156 \r
157 static void\r
158 _show(void *data, Evas *e, Evas_Object *obj, void *event_info)\r
159 {       \r
160         Widget_Data *wd = elm_widget_data_get(obj);   \r
161          if(wd->parent)\r
162           evas_object_show(wd->parent);         \r
163     elm_layout_theme_set(wd->layout, "popup", "base",\r
164                          elm_widget_style_get(obj));\r
165         _sizing_eval(obj);\r
166         evas_object_show(obj);          \r
167 \r
168 }\r
169 static void\r
170 _hide(void *data, Evas *e, Evas_Object *obj, void *event_info)\r
171 {\r
172         \r
173    Widget_Data *wd = elm_widget_data_get(obj);\r
174     if(wd->parent)\r
175           evas_object_hide(wd->parent);  \r
176         evas_object_hide(obj); \r
177 \r
178 }\r
179 \r
180 static void\r
181 _resize_parent(void *data, Evas *e, Evas_Object *obj, void *event_info)\r
182 {\r
183         Widget_Data *wd = elm_widget_data_get(data);\r
184         int rot_angle;\r
185         if(!wd)\r
186                 return;\r
187         if(wd->parent)\r
188         {\r
189                 rot_angle = elm_win_rotation_get(obj);\r
190                 if(wd->rot_angle!=rot_angle)\r
191                 {\r
192                         elm_win_rotation_with_resize_set(wd->parent,  rot_angle);\r
193                         wd->rot_angle = rot_angle;\r
194                 }\r
195         }\r
196 }\r
197 \r
198 static void _action_area_clicked( void *data, Evas_Object *obj, void *event_info )\r
199 {\r
200         Action_Area_Data *adata = (Action_Area_Data *)data;\r
201         if (!adata) return;     \r
202         evas_object_smart_callback_call(adata->obj, "response", (void *)adata->response_id);    \r
203         evas_object_hide(adata->obj);\r
204 }\r
205 \r
206 static Evas_Object* _elm_popup_add_button(Evas_Object *obj,const char *text,int response_id)\r
207 {\r
208         char buf[4096];\r
209         Widget_Data *wd = elm_widget_data_get(obj);\r
210         if (!wd) return NULL;\r
211         Evas_Object *btn;\r
212         Action_Area_Data *adata = malloc(sizeof(Action_Area_Data));     \r
213         btn = elm_button_add(obj);\r
214         snprintf(buf, sizeof(buf), "popup_button/%s", elm_widget_style_get(obj));\r
215         elm_object_style_set(btn, buf);\r
216         elm_button_label_set(btn,text);\r
217         wd->button_list = eina_list_append(wd->button_list, btn);\r
218         adata->response_id = response_id;\r
219         adata->obj = obj;\r
220         evas_object_smart_callback_add(btn, "clicked", _action_area_clicked, adata);    \r
221         return btn;\r
222 }\r
223 \r
224 static void _elm_popup_buttons_add_valist(Evas_Object *obj,const char *first_button_text,va_list args)\r
225 {\r
226         const char *text;       \r
227         char buf[4096];\r
228         int response=0;\r
229         int index=0;\r
230         if(first_button_text==NULL)\r
231                 return;\r
232         Widget_Data *wd = elm_widget_data_get(obj);\r
233         if (!wd) return;\r
234         text = first_button_text;       \r
235         response = va_arg (args, int);\r
236         Evas_Object *btn;\r
237          while (text != NULL)\r
238                 {\r
239                         btn = _elm_popup_add_button(obj,text,response);\r
240                         ++index;                        \r
241                         snprintf(buf,sizeof(buf),"actionbtn%d",index);                          \r
242                         elm_layout_content_set(wd->action_area,buf,btn);\r
243                         evas_object_event_callback_add(wd->action_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,\r
244                                        _changed_size_hints, obj);\r
245                         \r
246                         text = va_arg (args, char*);\r
247                         if (text == NULL)\r
248                                 break;\r
249                         response = va_arg (args, int);\r
250                 }                \r
251 }\r
252 \r
253 static void _elm_popup_timeout( void *data, Evas_Object *obj, void *event_info )\r
254 {       \r
255         evas_object_hide((Evas_Object*)data);   \r
256         evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_TIMEOUT);           \r
257 }\r
258 \r
259 \r
260 /**\r
261  * Add a new Popup object.\r
262  *\r
263  * @param parent The parent object\r
264  * @return The new object or NULL if it cannot be created\r
265  *\r
266  * @ingroup Popup\r
267  */\r
268 EAPI Evas_Object *\r
269 elm_popup_add(Evas_Object *parent_app)\r
270 {\r
271         Evas_Object *obj;\r
272         Evas *e;\r
273         Widget_Data *wd;\r
274         Evas_Object *parent;\r
275         Evas_Coord x,y,w,h;\r
276         int rotation=-1;\r
277         int count;\r
278         unsigned char *prop_data = NULL;\r
279         int ret;\r
280 \r
281         //FIXME: Keep this window always on top\r
282         parent = elm_win_add(parent_app,"popup",ELM_WIN_DIALOG_BASIC);\r
283         elm_win_alpha_set(parent, EINA_TRUE);   \r
284         elm_win_raise(parent);  \r
285 \r
286         if(parent_app)\r
287                 {\r
288                         evas_object_geometry_get(parent_app, &x, &y, &w, &h);\r
289                         rotation = elm_win_rotation_get(parent_app);\r
290                         evas_object_resize(parent, w, h);\r
291                         evas_object_move(parent, x, y);\r
292                         if(rotation!=-1)\r
293                         {\r
294                                 elm_win_rotation_set(parent, rotation);\r
295                         }                               \r
296                 }\r
297         else\r
298                 {\r
299                         ecore_x_window_geometry_get(ecore_x_window_root_get(ecore_x_window_focus_get()),&x, &y, &w, &h);        \r
300                         ret  = ecore_x_window_prop_property_get (ecore_x_window_root_get(ecore_x_window_focus_get()), ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);\r
301                         if( ret && prop_data )\r
302                         memcpy (&rotation, prop_data, sizeof (int));\r
303 \r
304                         if (prop_data) free (prop_data);\r
305                         evas_object_resize(parent, w, h);\r
306                         evas_object_move(parent, x, y);\r
307                         if(rotation!=-1)\r
308                                 {\r
309                                         elm_win_rotation_with_resize_set(parent, rotation);\r
310                                 }                               \r
311                 }\r
312         wd = ELM_NEW(Widget_Data);\r
313         e = evas_object_evas_get(parent);\r
314         obj = elm_widget_add(e);\r
315         elm_widget_type_set(obj, "popup");\r
316         elm_widget_sub_object_add(parent, obj);\r
317         elm_widget_data_set(obj, wd);\r
318         elm_widget_del_pre_hook_set(obj, _del_pre_hook);\r
319         elm_widget_del_hook_set(obj, _del_hook);\r
320         elm_widget_theme_hook_set(obj, _theme_hook);\r
321         wd->parent = parent;\r
322         wd->rot_angle = rotation;\r
323 \r
324         evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL, _del_parent, obj);\r
325         if(parent_app)\r
326         evas_object_event_callback_add(parent_app, EVAS_CALLBACK_RESIZE, _resize_parent, obj);\r
327         wd->parent_app = parent_app;\r
328 \r
329         wd->notify= elm_notify_add(parent);             \r
330         elm_widget_resize_object_set(obj, wd->notify);\r
331         elm_notify_orient_set(wd->notify, ELM_NOTIFY_ORIENT_CENTER);\r
332         elm_notify_repeat_events_set(wd->notify, EINA_FALSE);\r
333         evas_object_size_hint_weight_set(wd->notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
334         evas_object_size_hint_align_set(wd->notify, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
335 \r
336         wd->layout = elm_layout_add(parent);\r
337         evas_object_size_hint_weight_set(wd->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
338         evas_object_size_hint_align_set(wd->layout , EVAS_HINT_FILL, EVAS_HINT_FILL);\r
339         \r
340         elm_layout_theme_set(wd->layout, "popup", "base", "default");\r
341         elm_notify_content_set(wd->notify, wd->layout);\r
342 \r
343         evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, NULL);\r
344         evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide, NULL);\r
345                 \r
346         _sizing_eval(obj);\r
347 \r
348         return obj;\r
349 }\r
350 \r
351 /**\r
352  * Add a new Popup object.\r
353  *\r
354  * @param parent The parent object\r
355  * @param title text to be displayed in title area.\r
356  * @param desc_text text to be displayed in description area.\r
357  * @param no_of_buttons Number of buttons to be packed in action area.\r
358  * @param first_button_text button text\r
359  * @param Varargs response ID for first button, then additional buttons followed by response id's ending with NULL\r
360  * @return The new object or NULL if it cannot be created\r
361  *\r
362  * @ingroup Popup\r
363  */\r
364 Evas_Object *\r
365 elm_popup_add_with_buttons(Evas_Object *parent, char *title, char *desc_text,int no_of_buttons, char *first_button_text, ... )\r
366 {\r
367         Evas_Object *popup;\r
368         popup = elm_popup_add(parent);\r
369         Widget_Data *wd = elm_widget_data_get(popup);\r
370         char buf[4096];\r
371         if(desc_text)\r
372                 {\r
373                         elm_popup_desc_set(popup, desc_text);\r
374                 }\r
375         if(title)\r
376                 {\r
377                         elm_popup_title_label_set(popup, title);\r
378                 }\r
379         if(first_button_text)\r
380                 {\r
381                         va_list args;   \r
382                         va_start (args, first_button_text);     \r
383                         wd->action_area= elm_layout_add(popup);                                                 \r
384                         elm_layout_content_set(wd->layout, "elm.swallow.buttonArea", wd->action_area);          \r
385                         snprintf(buf,sizeof(buf),"buttons%d",no_of_buttons);    \r
386                         elm_layout_theme_set(wd->action_area,"popup",buf,elm_widget_style_get(popup));\r
387 \r
388                         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,visible", "elm");\r
389                         if(wd->title_area)\r
390                                 {\r
391                                         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,title,visible", "elm");\r
392                                 }\r
393                         _elm_popup_buttons_add_valist (popup,\r
394                                 first_button_text,\r
395                                 args);\r
396                          va_end (args);                 \r
397                 }\r
398         _sizing_eval(popup);\r
399         return popup;\r
400         \r
401 }\r
402 \r
403 /**\r
404  * This Set's the description text in content area of Popup widget.\r
405  *\r
406  * @param text description text.\r
407  *\r
408  * @ingroup Popup\r
409  */\r
410 EAPI void \r
411 elm_popup_desc_set(Evas_Object *obj, const char *text)\r
412 {\r
413         Widget_Data *wd = elm_widget_data_get(obj);\r
414         int w;          \r
415         char buf[4096];\r
416         if (!wd) return;\r
417 \r
418         if(wd->content_area)\r
419                 {\r
420                         evas_object_del(wd->content_area);\r
421                         wd->content_area=NULL;\r
422                 }       \r
423         wd->content_area = elm_layout_add(obj);\r
424         elm_layout_theme_set(wd->content_area,"popup","content",elm_widget_style_get(obj));\r
425         wd->desc_label = elm_label_add(obj);\r
426         snprintf(buf, sizeof(buf), "popup_description/%s", elm_widget_style_get(obj));\r
427         elm_object_style_set(wd->desc_label,buf);\r
428         elm_label_line_wrap_set(wd->desc_label, EINA_TRUE);\r
429         elm_label_label_set(wd->desc_label, text);\r
430         evas_object_size_hint_weight_set(wd->desc_label, EVAS_HINT_EXPAND, 0.0);\r
431         evas_object_size_hint_align_set(wd->desc_label, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
432         evas_object_show(wd->desc_label);               \r
433         elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->desc_label);                \r
434         elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);                    \r
435         evas_object_event_callback_add(wd->content_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,\r
436                        _changed_size_hints, obj);\r
437         _sizing_eval(obj);\r
438 }\r
439 \r
440 /**\r
441  * This Get's the description text packed in content area of popup object.\r
442  *\r
443  * @param obj The Popup object\r
444  * @return  description text.\r
445  *\r
446  * @ingroup Popup\r
447  */\r
448 EAPI const char* \r
449 elm_popup_desc_get(Evas_Object *obj)\r
450 {\r
451         Widget_Data *wd = elm_widget_data_get(obj);\r
452         if (!wd) return NULL;\r
453 \r
454         return elm_label_label_get(wd->desc_label);\r
455 }\r
456 \r
457 /**\r
458  * This Set's the title text in title area of popup object.\r
459  *\r
460  * @param obj The popup object\r
461  * @param text The title text\r
462  *\r
463  * @ingroup Popup\r
464  */\r
465 EAPI void \r
466 elm_popup_title_label_set(Evas_Object *obj, const char *text)\r
467 {\r
468         Widget_Data *wd = elm_widget_data_get(obj);\r
469         char buf[4096];\r
470         if (!wd) return;\r
471 \r
472         if(wd->title_area)\r
473                 {\r
474                         evas_object_del(wd->title_area);\r
475                         wd->title_area=NULL;\r
476                 }\r
477                 \r
478         wd->title_area= elm_label_add(obj);     \r
479         snprintf(buf, sizeof(buf), "popup_title/%s", elm_widget_style_get(obj));\r
480         elm_object_style_set(wd->title_area,buf);\r
481         elm_label_label_set(wd->title_area, text);\r
482         evas_object_size_hint_weight_set(wd->title_area, EVAS_HINT_EXPAND, 0.0);\r
483         evas_object_size_hint_align_set(wd->title_area, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
484         elm_layout_content_set(wd->layout, "elm.swallow.title", wd->title_area);                \r
485         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,title,visible", "elm");\r
486         if(wd->action_area)\r
487                 {\r
488                         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,title,visible", "elm");\r
489                 }\r
490         if(wd->title_icon)\r
491                 {\r
492                         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,title,icon,visible", "elm");\r
493                 }               \r
494         _sizing_eval(obj);\r
495 }\r
496 \r
497 /**\r
498  * This Get's the title text packed in title area of popup object.\r
499  *\r
500  * @param obj The Popup object\r
501  * @return title text\r
502  *\r
503  * @ingroup Popup\r
504  */\r
505 EAPI const char* \r
506 elm_popup_title_label_get(Evas_Object *obj)\r
507 {\r
508         Widget_Data *wd = elm_widget_data_get(obj);\r
509         if (!wd) return NULL;\r
510 \r
511         return elm_label_label_get(wd->title_area);\r
512 }\r
513 \r
514 /**\r
515  * This Set's the icon in the title area of Popup object.\r
516  *\r
517  * @param obj The popup object\r
518  * @param icon The title icon\r
519  *\r
520  * @ingroup Popup\r
521  */\r
522 EAPI void \r
523 elm_popup_title_icon_set(Evas_Object *obj, Evas_Object *icon)\r
524 {\r
525         Widget_Data *wd = elm_widget_data_get(obj);\r
526         if (!wd) return;\r
527 \r
528         if(wd->title_icon)\r
529                 {\r
530                         evas_object_del(wd->title_icon);\r
531                         wd->title_icon=NULL;\r
532                 }\r
533                 \r
534         wd->title_icon= icon;   \r
535         elm_layout_content_set(wd->layout, "elm.swallow.title.icon", wd->title_icon);           \r
536         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,title,icon,visible", "elm");        \r
537         _sizing_eval(obj);\r
538 }\r
539 \r
540 /**\r
541  * This Get's the icon packed in title area of Popup object.\r
542  *\r
543  * @param obj The Popup object\r
544  * @return title icon\r
545  *\r
546  * @ingroup Popup\r
547  */\r
548 EAPI Evas_Object* \r
549 elm_popup_title_icon_get(Evas_Object *obj)\r
550 {\r
551         Widget_Data *wd = elm_widget_data_get(obj);\r
552         if (!wd) return NULL;\r
553 \r
554         return wd->title_icon;\r
555 }\r
556 \r
557 /**\r
558  * This Set's the content widget in content area of Popup object.\r
559  *\r
560  * @param obj The popup object\r
561  * @param content The content widget\r
562  *\r
563  * @ingroup Popup\r
564  */\r
565 EAPI void \r
566 elm_popup_content_set(Evas_Object *obj, Evas_Object *content)\r
567 {\r
568         Widget_Data *wd = elm_widget_data_get(obj);     \r
569         if (!wd) return;\r
570 \r
571         if(wd->content_area)\r
572                 {\r
573                         evas_object_del(wd->content_area);\r
574                         wd->content_area=NULL;\r
575                 }                       \r
576         wd->content_area = elm_layout_add(obj);\r
577         elm_layout_theme_set(wd->content_area,"popup","content",elm_widget_style_get(obj));\r
578         elm_layout_content_set(wd->content_area, "elm.swallow.content", content);               \r
579         elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);            \r
580         evas_object_event_callback_add(wd->content_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,\r
581                                        _changed_size_hints, obj);\r
582         _sizing_eval(obj);\r
583 }\r
584 \r
585 /**\r
586  * This Get's the content widget packed in content area of Popup object.\r
587  *\r
588  * @param obj The Popup object\r
589  * @return content packed in popup widget\r
590  *\r
591  * @ingroup Popup\r
592  */\r
593 EAPI Evas_Object*\r
594 elm_popup_content_get(Evas_Object *obj)\r
595 {\r
596         Widget_Data *wd = elm_widget_data_get(obj);\r
597         if (!wd) return NULL;\r
598 \r
599         return wd->content_area;\r
600 }\r
601 \r
602 /**\r
603  * Adds the buttons in to the action area of popup object.\r
604  *\r
605  * @param obj The popup object\r
606  * @param no_of_buttons Number of buttons that has to be packed in action area.\r
607  * @param first_button_text     Label of first button\r
608  * @param Varargs        Response ID(Elm_Popup_Response/ any integer value) for first button, then additional buttons along with their response id ending with NULL.\r
609  * @ingroup Popup\r
610  */\r
611 EAPI void \r
612 elm_popup_buttons_add(Evas_Object *obj,int no_of_buttons, char *first_button_text,  ...)\r
613 \r
614 {\r
615         Widget_Data *wd = elm_widget_data_get(obj);     \r
616         char buf[4096];\r
617         if (!wd) return;        \r
618         va_list args;   \r
619 \r
620         va_start (args, first_button_text);     \r
621 \r
622         if(wd->action_area)\r
623                 {\r
624                         evas_object_del(wd->action_area);\r
625                         wd->action_area=NULL;\r
626                 }\r
627         wd->action_area= elm_layout_add(obj);                   \r
628         elm_layout_content_set(wd->layout, "elm.swallow.buttonArea", wd->action_area);          \r
629         evas_object_size_hint_weight_set(wd->action_area, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);\r
630         evas_object_size_hint_align_set(wd->action_area, EVAS_HINT_FILL, EVAS_HINT_FILL);\r
631         snprintf(buf,sizeof(buf),"buttons%d",no_of_buttons);    \r
632         elm_layout_theme_set(wd->action_area,"popup",buf,elm_widget_style_get(obj));            \r
633         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,visible", "elm");\r
634 \r
635         if(wd->title_area)\r
636                 {\r
637                         edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,title,visible", "elm");\r
638                 }\r
639 \r
640         _elm_popup_buttons_add_valist (obj,\r
641                                 first_button_text,\r
642                                 args);\r
643         \r
644          va_end (args);\r
645         _sizing_eval(obj);\r
646 }\r
647 \r
648 /**\r
649  * This Set's the time before the popup window is hidden, \r
650  * and ELM_POPUP_RESPONSE_TIMEOUT is sent along with response signal.\r
651  *\r
652  * @param obj The popup object\r
653  * @param timeout The timeout value in seconds.\r
654  *\r
655  * @ingroup Popup\r
656  */\r
657 EAPI void \r
658 elm_popup_timeout_set(Evas_Object *obj, int timeout)\r
659 {       \r
660         Widget_Data *wd = elm_widget_data_get(obj);\r
661         if (!wd)        return; \r
662         elm_notify_timeout_set(wd->notify, timeout);\r
663         evas_object_smart_callback_add(wd->notify, "notify,timeout", _elm_popup_timeout, obj);\r
664 }\r
665 \r
666 /**\r
667  * This Set's the mode of popup, by default ELM_POPUP_TYPE_NONE is set i.e, popup  \r
668  * will not close when clicked outside. if ELM_POPUP_TYPE_ALERT is set, popup will close\r
669  * when clicked outside, and ELM_POPUP_RESPONSE_NONE is sent along with response signal.\r
670  *\r
671  * @param obj The popup object\r
672  * @param mode  Elm_Popup_Mode\r
673  *\r
674  * @ingroup Popup\r
675  */\r
676 EAPI void elm_popup_set_mode(Evas_Object *obj, Elm_Popup_Mode mode)\r
677 {\r
678         Widget_Data *wd = elm_widget_data_get(obj);\r
679         if (!wd)        return; \r
680         evas_object_smart_callback_add(wd->notify, "block,clicked", _block_clicked_cb, obj);\r
681 }\r
682 \r
683 /**\r
684  * This Hides the popup by emitting response signal.\r
685  *\r
686  * @param obj The popup object\r
687  * @param response_id  response ID of the signal to be emitted along with response signal\r
688  *\r
689  * @ingroup Popup\r
690  */ \r
691 EAPI void elm_popup_response(Evas_Object *obj, int  response_id)\r
692 {\r
693         Widget_Data *wd = elm_widget_data_get(obj);\r
694         if (!wd)        return; \r
695         evas_object_hide(obj);  \r
696         evas_object_smart_callback_call((Evas_Object *)obj, "response", (void *)response_id);   \r
697 }\r
698 \r
699 /**\r
700  * This API controls the direction from which popup will appear and location of popup.\r
701  * @param obj The popup object\r
702  * @param orient  the orientation of the popup\r
703  *\r
704  * @ingroup Popup\r
705  */\r
706  EAPI void elm_popup_orient_set(Evas_Object *obj, Elm_Popup_Orient orient)\r
707 {\r
708         Widget_Data *wd = elm_widget_data_get(obj);\r
709         if (!wd)        return; \r
710         Elm_Notify_Orient notify_orient=-1;\r
711         switch (orient)\r
712      {\r
713                         case ELM_POPUP_ORIENT_TOP:\r
714                         notify_orient = ELM_NOTIFY_ORIENT_TOP;\r
715                         break;\r
716                         case ELM_POPUP_ORIENT_CENTER:\r
717                         notify_orient = ELM_NOTIFY_ORIENT_CENTER;\r
718                         break;\r
719                         case ELM_POPUP_ORIENT_BOTTOM:\r
720                         notify_orient = ELM_NOTIFY_ORIENT_BOTTOM;\r
721                         break;\r
722                         case ELM_POPUP_ORIENT_LEFT:\r
723                         notify_orient = ELM_NOTIFY_ORIENT_LEFT;\r
724                         break;\r
725                         case ELM_POPUP_ORIENT_RIGHT:\r
726                         notify_orient = ELM_NOTIFY_ORIENT_RIGHT;\r
727                         break;\r
728                         case ELM_POPUP_ORIENT_TOP_LEFT:\r
729                         notify_orient = ELM_NOTIFY_ORIENT_TOP_LEFT;\r
730                         break;\r
731                         case ELM_POPUP_ORIENT_TOP_RIGHT:\r
732                         notify_orient = ELM_NOTIFY_ORIENT_TOP_RIGHT;\r
733                         break;\r
734                         case ELM_POPUP_ORIENT_BOTTOM_LEFT:\r
735                         notify_orient = ELM_NOTIFY_ORIENT_BOTTOM_LEFT;\r
736                         break;\r
737                         case ELM_POPUP_ORIENT_BOTTOM_RIGHT:\r
738                         notify_orient = ELM_NOTIFY_ORIENT_BOTTOM_RIGHT;\r
739                 break;\r
740      }\r
741         elm_notify_orient_set(wd->notify, notify_orient);\r
742 }\r
743 \r
744 /**\r
745  * Applications which do not pass any window to popup need to take care of rotation, only when popup is already shown.\r
746  * @param obj The popup object\r
747  * @param rot_angle  the angle to which popup has to be rotated.\r
748  *\r
749  * @ingroup Popup\r
750  */\r
751  EAPI void elm_popup_rotation_set(Evas_Object *obj, int rot_angle)\r
752 {\r
753         Widget_Data *wd = elm_widget_data_get(obj);\r
754         if (!wd)        return; \r
755         if(wd->parent)\r
756         {\r
757                 if(wd->rot_angle!=rot_angle)\r
758                 {\r
759                         elm_win_rotation_with_resize_set(wd->parent,  rot_angle);\r
760                         wd->rot_angle = rot_angle;\r
761                 }\r
762         }\r
763 }\r
764 \r
765 \r