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