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