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