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