Remove appdata structure
[apps/native/sample/sample-core-components.git] / rule / project / src / view.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 static struct view_info {
18         Evas_Object *win;
19         Evas_Object *conform;
20 } s_info = {
21         .win = NULL,
22         .conform = NULL,
23 };
24
25
26 /*
27  * @brief: Create Essential Object window, conformant and layout
28  */
29 void view_create(void)
30 {
31         /* Create window */
32         s_info.win = view_create_win(PACKAGE);
33         if (s_info.win == NULL) {
34                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a window.");
35                 return;
36         }
37
38         /* Create conformant */
39         s_info.conform = view_create_conformant_without_indicator(s_info.win);
40         if (s_info.conform == NULL) {
41                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a conformant");
42                 return;
43         }
44
45         /* Show window after main view is set up */
46         evas_object_show(s_info.win);
47 }
48
49 /*
50  * @brief: Make a basic window named package
51  * @param[pkg_name]: Name of the window
52  */
53 Evas_Object *view_create_win(const char *pkg_name)
54 {
55         Evas_Object *win = NULL;
56
57         /* Window */
58         /* Create and initialize elm_win.
59            elm_win is mandatory to manipulate window. */
60
61         win = elm_win_util_standard_add(pkg_name, pkg_name);
62         elm_win_conformant_set(win, EINA_TRUE);
63         elm_win_autodel_set(win, EINA_TRUE);
64
65         /* Rotation setting */
66         if (elm_win_wm_rotation_supported_get(win)) {
67                 int rots[4] = { 0, 90, 180, 270 };
68                 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
69         }
70
71         evas_object_smart_callback_add(win, "delete,request", _win_delete_request_cb, NULL);
72
73         return win;
74 }
75
76 /*
77  * @brief: Make a conformant without indicator for wearable app
78  * @param[win]: The object to which you want to set this conformant
79  * Conformant is mandatory for base GUI to have proper size
80  */
81 Evas_Object *view_create_conformant_without_indicator(Evas_Object *win)
82 {
83         /* Conformant
84          * Create and initialize elm_conformant.
85          * elm_conformant is mandatory for base GUI to have proper size
86          * when indicator or virtual keypad is visible.
87          */
88         Evas_Object *conform = NULL;
89
90         if (win == NULL) {
91                 dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL.");
92                 return NULL;
93         }
94
95         conform = elm_conformant_add(win);
96         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
97         elm_win_resize_object_add(win, conform);
98
99         evas_object_show(conform);
100
101         return conform;
102 }
103
104 /*
105  * @brief: Make a layout to target parent object with edje file
106  * @param[parent]: The object to which you want to add this layout
107  * @param[file_name]: File path of EDJ
108  * @param[group_name]: Name of group in EDJ you want to set to
109  * @param[Evas_Object_Event_Cb]: File path of EDJ
110  * @param[user_data]: The user data to be passed to the callback functions
111  */
112 Evas_Object *view_create_layout(Evas_Object *parent, const char *edj_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
113 {
114         Evas_Object *layout = NULL;
115
116         if (parent == NULL) {
117                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
118                 return NULL;
119         }
120
121         /* Create layout by EDC(edje file) */
122         layout = elm_layout_add(parent);
123         elm_layout_file_set(layout, edj_path, group_name);
124
125         /* Layout size setting */
126         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
127
128         if (cb_function)
129                 eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, cb_function, user_data);
130
131         evas_object_show(layout);
132
133         return layout;
134 }
135
136 /*
137  * @brief: Make and set a layout to conformant
138  * @param[parent]: Target conformant object
139  * @param[file_name]: File path of EDJ used
140  * @param[group_name]: Group name in EDJ you want to set to layout
141  * @param[cb_function]: Callback for back event handling
142  * @param[user_data]: The user data to be passed to the callback functions
143  */
144 Evas_Object *view_create_layout_for_conformant(Evas_Object *parent, const char *file_name, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
145 {
146         Evas_Object *layout = NULL;
147
148         if (parent == NULL) {
149                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
150                 return NULL;
151         }
152
153         /* Create layout for conformant */
154         if (!file_name) {
155                 layout = view_create_layout_by_theme(parent, "layout", "application", "default");
156         } else {
157                 layout = view_create_layout(parent, file_name, group_name, cb_function, user_data);
158         }
159
160         if (layout == NULL) {
161                 dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL.");
162                 return NULL;
163         }
164
165         elm_object_content_set(parent, layout);
166
167         return layout;
168 }
169
170 /*
171  * @brief: Make a layout with theme.
172  * @param[parent]: Object to which you want to add this layout
173  * @param[class]: The class of the group
174  * @param[group_name]: Group name in EDJ you want to set to layout
175  * @param[style]: The style to use
176  */
177 Evas_Object *view_create_layout_by_theme(Evas_Object *parent, const char *classname, const char *group, const char *style)
178 {
179         /*
180          * Layout
181          * Create and initialize elm_layout.
182          * view_create_layout_by_theme() is used to create layout by using premade edje file.
183          */
184         Evas_Object *layout = NULL;
185
186         if (parent == NULL) {
187                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
188                 return NULL;
189         }
190
191         layout = elm_layout_add(parent);
192         elm_layout_theme_set(layout, classname, group, style);
193         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
194
195         evas_object_show(layout);
196
197         return layout;
198 }
199
200 /*
201  * @brief: Make and set a layout to the part
202  * @param[parent]: Object to which you want to set this layout
203  * @param[file_name]: File path of EDJ used
204  * @param[group_name]: Group name in EDJ you want to set to layout
205  * @param[part]: Part name to which you want to set this layout
206  */
207 Evas_Object *view_create_layout_for_part(Evas_Object *parent, char *part, char *file_name, char *group_name)
208 {
209         Evas_Object *layout = NULL;
210
211         if (parent == NULL) {
212                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
213                 return NULL;
214         }
215
216         layout = elm_layout_add(parent);
217         elm_layout_file_set(layout, file_name, group_name);
218         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219
220         evas_object_show(layout);
221
222         elm_object_part_content_set(parent, part, layout);
223
224         return layout;
225 }
226
227 /*
228  * @brief: Destroy window and free important data to finish this application
229  * @param[user_data]: Structure has informations for managing this application
230  */
231 void view_destroy(void *user_data)
232 {
233         if (s_info.win == NULL) {
234                 return;
235         }
236
237         evas_object_del(s_info.win);
238 }
239
240 /*
241  * @brief: Destroy given layout
242  * @param[layout]: The layout you want to destroy
243  */
244 void view_destroy_layout(Evas_Object *layout)
245 {
246         evas_object_del(layout);
247 }
248
249 /*
250  * @brief: Set image to given part
251  * @param[parent]: object has part to which you want to set this image
252  * @param[part]: part name to which you want to set this image
253  * @param[image_path]: path of image file
254  */
255 void view_set_image(Evas_Object *parent, const char *part, const char *image_path)
256 {
257         Evas_Object *image = NULL;
258
259         if (parent == NULL) {
260                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
261                 return;
262         }
263
264         image = elm_object_part_content_get(parent, part);
265         if (image == NULL) {
266                 image = elm_image_add(parent);
267                 if (!image) {
268                         dlog_print(DLOG_ERROR, LOG_TAG, "failed to create an image object.");
269                         return;
270                 }
271         }
272
273         if (EINA_FALSE == elm_image_file_set(image, image_path, NULL)) {
274                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to set image.");
275                 return;
276         }
277
278         if (part) {
279                 elm_object_part_content_set(parent, part, image);
280         } else {
281                 elm_object_content_set(parent, image);
282         }
283
284         evas_object_show(image);
285
286         return;
287 }
288
289 /*
290  * @brief: Set text to the part
291  * @param[parent]: Object has part to which you want to set text
292  * @param[part]: Part name to which you want to set text
293  * @param[text]: text you want to set to the part
294  */
295 void view_set_text(Evas_Object *parent, const char *part, const char *text)
296 {
297         if (parent == NULL) {
298                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
299                 return;
300         }
301
302         /* Set text of target part object */
303         elm_object_part_text_set(parent, part, text);
304 }
305
306 /*
307  * @brief: Set color of the part
308  * @param[parent]: Object has part to which you want to set color
309  * @param[part]: Name of part to which you want to set color
310  * @param[r]: R of RGBA you want to set to the part
311  * @param[g]: G of RGBA you want to set to the part
312  * @param[b]: B of RGBA you want to set to the part
313  * @param[a]: A of RGBA you want to set to the part
314  */
315 void view_set_color(Evas_Object *parent, const char *part, int r, int g, int b, int a)
316 {
317         Evas_Object *obj = NULL;
318
319         if (parent == NULL) {
320                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
321                 return;
322         }
323
324         obj = elm_object_part_content_get(parent, part);
325         if (obj == NULL) {
326                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
327                 return;
328         }
329
330         /* Set color of target part object */
331         evas_object_color_set(obj, r, g, b, a);
332 }
333
334 /*
335  * @brief: Set the color of circle line and font in a given circle object
336  * @param[parent]: Object has part to which you want to set color
337  * @param[part]: Name of part to which you want to set color
338  * @param[r] The red component of the given color
339  * @param[g] The green component of the given color
340  * @param[b] The blue component of the given color
341  * @param[a] The alpha component of the given color
342  */
343 void view_set_color_of_circle_object(Evas_Object *parent, const char *part, int r, int g, int b, int a)
344 {
345         Evas_Object *obj = NULL;
346
347         if (parent == NULL) {
348                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
349                 return;
350         }
351
352         obj = elm_object_part_content_get(parent, part);
353         if (obj == NULL) {
354                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
355                 return;
356         }
357
358         /* Set color of target part object */
359         eext_circle_object_color_set(obj, r, g, b, a);
360 }
361
362 /*
363  * @brief: Make a naviframe and set to parent
364  * @param[parent]: Object to which you want to set naviframe
365  * @Add callback function will be operated when back key is pressed
366  */
367 Evas_Object *view_create_naviframe(Evas_Object *parent)
368 {
369         /* Naviframe
370          * Create and initialize elm_naviframe.
371          * Naviframe stands for navigation frame.
372          * elm_naviframe is a views manager for applications.
373          */
374         Evas_Object *nf = NULL;
375
376         if (parent == NULL) {
377                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
378                 return NULL;
379         }
380
381         nf = elm_naviframe_add(parent);
382
383         elm_object_part_content_set(parent, "elm.swallow.content", nf);
384         eext_object_event_callback_add(nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
385         eext_object_event_callback_add(nf, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
386
387         evas_object_show(nf);
388
389         return nf;
390 }
391
392 /*
393  * @brief: Push item to naviframe
394  * @param[nf]: naviframe
395  * @param[item]: object will be added to naviframe
396  * @param[_pop_cb]: function will be operated when this item is popped from naviframe
397  * @param[cb_data]: data needed to operate '_pop_cb' function
398  * Naviframe make changing of view is easy and effectively
399  */
400 Elm_Object_Item* view_push_item_to_naviframe(Evas_Object *nf, Evas_Object *item, Elm_Naviframe_Item_Pop_Cb _pop_cb, void *cb_data)
401 {
402         Elm_Object_Item* nf_it = NULL;
403
404         if (nf == NULL) {
405                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is NULL.");
406                 return NULL;
407         }
408
409         if (item == NULL) {
410                 dlog_print(DLOG_ERROR, LOG_TAG, "item is NULL.");
411                 return NULL;
412         }
413
414         nf_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, item, "empty");
415
416         if (_pop_cb != NULL)
417                 elm_naviframe_item_pop_cb_set(nf_it, _pop_cb, cb_data);
418
419         return nf_it;
420 }
421
422 void view_set_more_button(Evas_Object *parent, const char *part)
423 {
424         Evas_Object *more_btn = NULL;
425
426         if (pirent == NULL) {
427                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
428                 return;
429         }
430
431         more_btn = eext_more_option_add(parent);
432         if (more_btn == NULL) {
433                 dlog_print(DLOG_ERROR, LOG_TAG, "more option is NULL.");
434                 return;
435         }
436
437         /* Add smart callback */
438         evas_object_smart_callback_add(more_btn, "more,option,opened", _more_option_opened, NULL);
439         evas_object_smart_callback_add(more_btn, "more,option,closed", _more_option_closed, NULL);
440         evas_object_smart_callback_add(more_btn, "item,selected", _item_selected, NULL);
441
442         elm_object_part_content_set(parent, part, more_btn);
443 }
444
445 /*
446  * @brief: Make and set button.
447  * @param[parent]: object to which you want to set the button
448  * @param[style]: style of the button
449  * @param[text]: text will be written on the button
450  * @param[image_path]: path of image file will be used as button icon
451  * @param[part]: part name in EDJ to which you want to set the button
452  * @param[down_cb]: function will be operated when the button is pressed
453  * @param[up_cb]: function will be operated when the button is released
454  * @param[clicked_cb]: function will be operated when the button is clicked
455  * @param[data]: data needed in this function
456  */
457 void view_set_button(Evas_Object *parent, const char *part, const char *style, const char *image_path, const char *text,
458                 Evas_Object_Event_Cb down_cb, Evas_Object_Event_Cb up_cb, Evas_Smart_Cb clicked_cb, void *data)
459 {
460         Evas_Object *btn = NULL;
461
462         if (parent == NULL) {
463                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
464                 return;
465         }
466
467         btn = elm_button_add(parent);
468         if (!btn) {
469                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create button.");
470                 return;
471         }
472
473         if (style)
474                 elm_object_style_set(btn, style);
475
476         evas_object_size_hint_weight_set(btn ,EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
477         elm_object_part_content_set(parent, part, btn);
478
479         if (text)
480                 elm_object_text_set(btn, text);
481
482         if (image_path)
483                 view_set_image(btn, NULL, image_path);
484
485         if (down_cb)
486                 evas_object_event_callback_add(btn , EVAS_CALLBACK_MOUSE_DOWN, down_cb, data);
487         if (up_cb)
488                 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_UP, up_cb, data);
489         if (clicked_cb)
490                 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
491
492         evas_object_show(btn);
493 }
494
495 /*
496  * @brief: Add a more button item
497  * @param[parent]: object that contains more button
498  * @param[main_txt]: text will be written in the middle of the selector
499  * @param[sub_txt] Text will be written under the main_txt
500  * @param[img_path]: path of image file will be used as more button item icon
501  * @param[clicked_cb]: function will be operated when the more button item is clicked
502  * @param[user_data]: data needed in this function
503  */
504 void view_add_more_button_item(Evas_Object *parent, const char *part, const char *main_txt, const char *sub_txt, const char *img_path, Evas_Smart_Cb clicked_cb, void *user_data)
505 {
506         Evas_Object *img = NULL;
507         Evas_Object *more_btn = NULL;
508         char full_path[PATH_MAX] = { 0, };
509
510         if (parent == NULL) {
511                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
512                 return;
513         }
514
515         more_btn = elm_object_part_content_get(parent, part);
516         if (more_btn == NULL) {
517                 return;
518         }
519
520         /* Create the new item */
521         Eext_Object_Item *item  = eext_more_option_item_append(more_btn);
522
523         /* Set the text in item text part */
524         eext_more_option_item_part_text_set(item, "selector,main_text", main_txt);
525         eext_more_option_item_part_text_set(item, "selector,sub_text", sub_txt);
526
527         img = elm_image_add(more_btn);
528         _get_resource(img_path, full_path, sizeof(full_path));
529         elm_image_file_set(img, full_path, NULL);
530
531         /* Set the content in item content part */
532         eext_more_option_item_part_content_set(item, "item,icon", img);
533
534         evas_object_smart_callback_add(more_btn, "item,clicked", clicked_cb, user_data);
535 }
536
537 /*
538  * @brief: Make a Entry Object to target window
539  * @param[parent]: Object to which you want to set Entry
540  * @param[part]: Part of the layout which you want to locate Entry
541  * @param[data]: The user data to be passed to the callback function
542  * @Add callback function will be operated when mouse clicked event is triggered
543  */
544 Evas_Object *view_set_entry(Evas_Object *parent, const char *part, void (*_clicked_cb)(void *data, Evas_Object *obj, void *event_info), void *data)
545 {
546         Evas_Object *entry = NULL;
547
548         if (parent == NULL) {
549                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
550                 return NULL;
551         }
552
553         /* Add Entry object to parent */
554         entry = elm_entry_add(parent);
555         if (entry == NULL) {
556                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to add a entry");
557                 return NULL;
558         }
559
560         /* Set Entry size option */
561         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
562
563         /* Set Entry option for display and functionalities */
564         elm_entry_single_line_set(entry, EINA_TRUE);
565         elm_entry_scrollable_set(entry, EINA_TRUE);
566         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
567         elm_entry_editable_set(entry, EINA_FALSE);
568         elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
569         elm_entry_cursor_handler_disabled_set(entry, EINA_TRUE);
570         elm_entry_select_allow_set(entry, EINA_FALSE);
571
572         /* Set Entry text style using predefined style description */
573     elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_NORMAL);
574
575     elm_object_part_content_set(parent, part, entry);
576
577         /* Set callback for event about Entry */
578     if (_clicked_cb) {
579                 evas_object_smart_callback_add(entry, "clicked", _clicked_cb, data);
580         }
581
582         return entry;
583 }
584
585 /*
586  * @brief: make genlist for circular shape
587  * @param[parent]: object to which you want to set genlist
588  */
589 Evas_Object *view_create_circle_genlist(Evas_Object *parent)
590 {
591         Evas_Object *genlist = NULL;
592         Evas_Object *circle_genlist = NULL;
593
594         if (parent == NULL) {
595                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
596                 return NULL;
597         }
598
599         if (s_info.circle_surface == NULL) {
600                 dlog_print(DLOG_ERROR, LOG_TAG, "circle surface is NULL.");
601                 return NULL;
602         }
603
604         genlist = elm_genlist_add(parent);
605         /*
606          * This make selected list item is shown compressed.
607          */
608         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
609         evas_object_smart_callback_add(genlist, "selected", _gl_selected_cb, NULL);
610
611         /*
612          * This make genlist style circular.
613          */
614         circle_genlist = eext_circle_object_genlist_add(genlist, s_info.circle_surface);
615         eext_circle_object_genlist_scroller_policy_set(circle_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
616         eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
617
618         evas_object_show(genlist);
619
620         return genlist;
621 }
622
623 /*
624  * @brief: Add item to genlist.
625  * @param[genlist]: genlist
626  * @param[style]: style of item determine how to show this item, such as "1text", "1text1icon" and so on
627  * @param[data]: item data that use item's callback function
628  * @param[_clicked_cb]: function will be operated when the item is clicked
629  * @param[cb_data]: data needed in '_clicked_cb' function
630  * This make item's class and add item to genlist.
631  */
632 Elm_Object_Item *view_append_item_to_genlist(Evas_Object *genlist, const char *style,
633                 const void *data, Evas_Smart_Cb _clicked_cb, const void *cb_data)
634 {
635         Elm_Genlist_Item_Class *item_class;
636         Elm_Object_Item *item;
637
638         if (genlist == NULL) {
639                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
640                 return NULL;
641         }
642
643         if (style == NULL) {
644                 dlog_print(DLOG_ERROR, LOG_TAG, "item style is NULL.");
645                 return NULL;
646         }
647
648         item_class = _set_genlist_item_class(style);
649
650         item = elm_genlist_item_append(genlist, item_class, data, NULL, ELM_GENLIST_ITEM_NONE, _clicked_cb, cb_data);
651
652         elm_genlist_item_class_free(item_class);
653
654         return item;
655 }
656
657 /*
658  * @brief: Find item from genlist.
659  * @param[genlist]: genlist
660  * @param[val]: value determine which of the items has to remove
661  */
662 Elm_Object_Item *view_find_item_from_genlist(Evas_Object *genlist, const char *val)
663 {
664         int item_count;
665         int i;
666         Elm_Object_Item *item = NULL;
667         struct genlist_data *gendata = NULL;
668
669         if (!genlist) {
670                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
671                 return NULL;
672         }
673
674         item_count = elm_genlist_items_count(genlist);
675
676         /*
677          * The fist item and the last item are "padding".
678          */
679         for(i = 1; i < item_count-1; i++) {
680                 item = elm_genlist_nth_item_get(genlist, i);
681                 gendata = elm_object_item_data_get(item);
682
683                 if (gendata->alarm_id == atoi(val)) {
684                         return item;
685                 }
686         }
687
688         return NULL;
689 }
690
691 /*
692  * @brief: Remove item.
693  * @param[item]: item from genlist
694  */
695 void view_delete_item(Elm_Object_Item *item)
696 {
697         elm_object_item_del(item);
698 }
699
700 /*
701  * @brief: Make popup with theme.
702  * @param[popup_style]: style of the popup's layout
703  * @param[data]: data needed in this function
704  */
705 void view_create_text_popup(Evas_Object *parent, double timeout, const char *text)
706 {
707         Evas_Object *popup = NULL;
708         Evas_Object *popup_layout = NULL;
709
710         if (parent == NULL) {
711                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
712                 return;
713         }
714
715         popup = elm_popup_add(parent);
716         elm_object_style_set(popup, "circle");
717         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
718
719         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_hide_cb, NULL);
720         /*
721          * Delete popup object in _popup_hide_finished_cb(), when the "dismissed" signal will be called.
722          */
723         evas_object_smart_callback_add(popup, "dismissed", _popup_hide_finished_cb, NULL);
724
725         popup_layout = elm_layout_add(popup);
726         elm_layout_theme_set(popup_layout, "layout", "popup", "content/circle");
727
728         elm_object_content_set(popup, popup_layout);
729
730         elm_popup_timeout_set(popup, timeout);
731
732         if (text)
733                 view_set_text(popup_layout, "elm.text", text);
734
735         evas_object_show(popup);
736 }
737
738 void view_set_content_to_part(Evas_Object *layout, const char *part, Evas_Object *content)
739 {
740         elm_object_part_content_set(layout, part, content);
741 }
742
743 void view_send_signal_to_edje(Evas_Object *layout, const char *signal, const char *source)
744 {
745         elm_object_signal_emit(layout, signal, source);
746 }
747
748 void view_set_customized_event_callback(Evas_Object *item, char *signal, char *source, void (*signal_cb)(void *data, Evas_Object *obj, const char *emission, const char *source), void *user_data)
749 {
750         elm_object_signal_callback_add(item, signal, source, signal_cb, user_data);
751 }
752
753 /*
754  * @brief: Register rotary event callback function.
755  * @param[obj]: object that will receive rotary event
756  * @param[rotary_cb]: function will be operated when rotary event happens
757  * @param[user_data]: data needed in this function
758  */
759 void view_set_rotary_event_callback(Evas_Object *obj, Eext_Rotary_Event_Cb rotary_cb, void *user_data)
760 {
761         if (obj == NULL) {
762                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
763                 return;
764         }
765
766         eext_rotary_object_event_activated_set(obj, EINA_TRUE);
767         eext_rotary_object_event_callback_add(obj, rotary_cb, user_data);
768 }
769
770 /*
771  * @brief: Make a label and set label options.
772  * @param[parent]: The object to which you want to add this label
773  */
774 Evas_Object *view_create_label(Evas_Object *parent)
775 {
776         Evas_Object *label = elm_label_add(parent);
777
778         if (parent == NULL) {
779                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
780                 return NULL;
781         }
782
783         elm_object_style_set(label, "slide_short");
784         elm_label_wrap_width_set(label, 230);
785         elm_label_ellipsis_set(label, EINA_TRUE);
786         elm_label_slide_duration_set(label, 2);
787         elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_NONE);
788         elm_label_slide_go(label);
789         evas_object_show(label);
790
791         return label;
792 }
793
794 /*
795  * @brief: Set a text to label object
796  * @param[parent]: Object has part to which you want to set text
797  * @param[part]: Part name to which you want to set text
798  * @param[text]: text you want to set to the part
799  */
800 void view_set_label_text(Evas_Object *parent, const char *part, const char *text)
801 {
802         Evas_Object *label = NULL;
803         char *markup_text = NULL;
804         char buf[256] = { 0, };
805
806         if (parent == NULL) {
807                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
808                 return;
809         }
810
811         markup_text = elm_entry_utf8_to_markup(text);
812         snprintf(buf, sizeof(buf), "%s%s%s", LABEL_STYLE_START, markup_text, LABEL_STYLE_END);
813         free(markup_text);
814
815         label = elm_object_part_content_get(parent, part);
816         if (label == NULL) {
817                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
818                 return;
819         }
820
821         elm_object_text_set(label, buf);
822 }
823
824 /*
825  * @brief: Set a label to given part
826  * @param[parent]: object has part to which you want to set this label
827  * @param[part]: part name to which you want to set this label
828  */
829 void view_set_label(Evas_Object *parent, const char *part)
830 {
831         Evas_Object *label = NULL;
832
833         if (parent == NULL) {
834                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
835                 return;
836         }
837
838         label = view_create_label(parent);
839         if (label == NULL) {
840                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
841                 return;
842         }
843
844         elm_object_part_content_set(parent, part, label);
845 }
846
847 /*
848  * @brief: Create a progressbar
849  * @param[parent]: object has part to which you want to set this progressbar
850  * @param[radius]: radius The radius value of a given circle object
851  * @param[line_width]: line_width The line width value of the circle object
852  */
853 Evas_Object *view_create_progressbar(Evas_Object *parent, int radius, int line_width)
854 {
855         Evas_Object *progressbar = NULL;
856
857         if (parent == NULL) {
858                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
859                 return NULL;
860         }
861
862         progressbar = eext_circle_object_progressbar_add(parent, NULL);
863
864         eext_circle_object_value_min_max_set(progressbar, 0.0, 100.0);
865         eext_circle_object_radius_set(progressbar, radius);
866         eext_circle_object_line_width_set(progressbar, line_width);
867         evas_object_show(progressbar);
868
869         return progressbar;
870 }
871
872 /*
873  * @brief: Set a progressbar to given part
874  * @param[parent]: object has part to which you want to set
875  * @param[part]: part name to which you want to set
876  * @param[radius]: radius The radius value of a given circle object
877  * @param[line_width]: line_width The line width value of the circle object
878  */
879 void view_set_progressbar(Evas_Object *parent, const char *part, int radius, int line_width)
880 {
881         Evas_Object *progressbar = NULL;
882
883         if (parent == NULL) {
884                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
885                 return;
886         }
887
888         progressbar = view_create_progressbar(parent, radius, line_width);
889         if (progressbar == NULL) {
890                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
891                 return;
892         }
893
894         elm_object_part_content_set(parent, part, progressbar);
895 }
896
897 /*
898  * @brief: Set value to a progressbar
899  * @param[parent]: object has part to which you want to set
900  * @param[part]: part name to which you want to set
901  * @param[val]: value to which you want to set
902  */
903 void view_set_progressbar_val(Evas_Object *parent, const char *part, int val)
904 {
905         Evas_Object *progressbar = NULL;
906
907         if (parent == NULL) {
908                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
909                 return;
910         }
911
912         if (part == NULL) {
913                 dlog_print(DLOG_ERROR, LOG_TAG, "part is NULL.");
914                 return;
915         }
916
917         progressbar = elm_object_part_content_get(parent, part);
918         if (progressbar == NULL) {
919                 dlog_print(DLOG_ERROR, LOG_TAG, "progressbar is NULL.");
920                 return;
921         }
922
923         eext_circle_object_value_set(progressbar, val);
924 }
925
926 /*
927  * @brief: Make a checkbox
928  * @param[parent]: The object to which you want to add this checkbox
929  */
930 Evas_Object *view_create_checkbox(Evas_Object *parent)
931 {
932         Evas_Object *check;
933
934         if (parent == NULL) {
935                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
936                 return NULL;
937         }
938
939         check = elm_check_add(parent);
940         elm_check_state_set(check, EINA_FALSE);
941         evas_object_smart_callback_add(check, "changed", _icon_clicked_cb, NULL);
942         evas_object_show(check);
943
944         return check;
945 }
946
947 /*
948  * @brief: Make no voice memo view
949  * @param[parent]: naviframe
950  * @param[title]: titile of this view
951  * @param[detail]: detail text of this view
952  * @param[image_file]: image file name will be used in this view
953  * This function make a view consists of one title, one center image and one detail text at the bottom
954  */
955 Evas_Object *view_create_layout_no_content(Evas_Object *parent, char *title, char *detail, char *image_file)
956 {
957         Evas_Object *layout = NULL;
958         Evas_Object *img;
959         Elm_Object_Item *it;
960
961         if (parent == NULL) {
962                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
963                 return NULL;
964         }
965
966         layout = elm_layout_add(parent);
967         /* this make you can use layout consists of one title, one image and one detail text */
968         elm_layout_theme_set(layout, "layout", "nocontents", "default");
969         evas_object_size_hint_weight_set (layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
970         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
971
972         if (image_file) {
973                 img = elm_image_add(parent);
974                 elm_image_file_set(img, image_file, NULL);
975                 elm_object_part_content_set(layout, "elm.swallow.icon", img);
976                 evas_object_show(img);
977         }
978
979         if (detail) {
980                 char detail_text[256] = {0, };
981
982                 /* Customize font style bellow */
983                 snprintf(detail_text, sizeof(detail_text), "<font=TIZEN:style=Medium align=center color=#FFFFFF><font_size=28>%s</font_size></font>", detail);
984                 elm_object_part_text_set(layout, "elm.text", detail_text);
985         }
986         if (title) {
987                 char title_text[256] = {0, };
988
989                 snprintf(title_text, sizeof(title_text), "<font=TIZEN:style=Medium align=center color=#12B4FF><font_size=28>%s</font_size></font>", title);
990                 elm_object_part_text_set(layout, "elm.text.title", title_text);
991         }
992
993         /* if this signal is not sent, title text will be disappear */
994         elm_object_signal_emit(layout, "elm,state,title,enable", "elm");
995         /* push this no voice memo view to naviframe to show */
996         it = elm_naviframe_item_push(parent, "Title Enabled", NULL, NULL, layout, NULL);
997         /* if this is EINA_TRUE, you can see Title of naviframe on the top of the screen */
998         elm_naviframe_item_title_enabled_set(it, EINA_FALSE, EINA_FALSE);
999
1000         return layout;
1001 }
1002
1003 /*
1004  * @brief: Set datetime to the part
1005  * @param[parent]: object to which you want to set datetime
1006  * @param[style]: style of the datetime
1007  */
1008 Evas_Object *view_create_datetime(Evas_Object *parent, const char *style)
1009 {
1010         Evas_Object *circle_datetime = NULL;
1011
1012         if (parent == NULL) {
1013                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
1014                 return NULL;
1015         }
1016
1017         if (s_info.circle_surface == NULL) {
1018                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get circle_surface.");
1019                 return NULL;
1020         }
1021
1022         s_info.datetime = elm_datetime_add(parent);
1023         circle_datetime = eext_circle_object_datetime_add(s_info.datetime, s_info.circle_surface);
1024
1025         eext_rotary_object_event_activated_set(s_info.datetime, EINA_TRUE);
1026         elm_datetime_format_set(s_info.datetime, FORMAT);
1027
1028         elm_object_style_set(s_info.datetime, style);
1029
1030         elm_object_part_content_set(parent, "elm.swallow.content", s_info.datetime);
1031
1032         return s_info.datetime;
1033 }