ddd77740945b57be80a6a9368f64bf9ca95fc027
[apps/core/preloaded/calendar.git] / common / external-ug.c
1 /*
2
3 Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
4
5 This file is part of org.tizen.efl-calendar
6 Written by Taeho Kang <taeho84.kang@samsung.com>
7
8 PROPRIETARY/CONFIDENTIAL
9
10 This software is the confidential and proprietary information of
11 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
12 disclose such Confidential Information and shall use it only in
13 accordance with the terms of the license agreement you entered
14 into with SAMSUNG ELECTRONICS.
15
16 SAMSUNG make no representations or warranties about the suitability
17 of the software, either express or implied, including but not limited
18 to the implied warranties of merchantability, fitness for a particular
19 purpose, or non-infringement. SAMSUNG shall not be liable for any
20 damages suffered by licensee as a result of using, modifying or
21 distributing this software or its derivatives.
22
23 */
24
25
26
27 #include "cld.h"
28 #include "external-ug.h"
29
30 static void __cal_ug_destroy_callback(struct ui_gadget *ug, void *priv)
31 {
32         c_retm_if(!ug, "ug is null");
33
34         ug_destroy(ug);
35 }
36
37 static void __cal_ug_layout_callback(struct ui_gadget *ug, enum ug_mode mode, void *priv)
38 {
39         c_retm_if(!ug, "ug is null");
40         c_retm_if(mode != UG_MODE_FULLVIEW, "mode is invaild");
41
42         Evas_Object *base = ug_get_layout(ug);
43         if (!base) {
44                 ERR("ug_get_layout() returned null");
45                 ug_destroy(ug);
46                 return;
47         }
48
49         switch (mode) {
50         case UG_MODE_FULLVIEW:
51                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
52                 elm_win_resize_object_add(ug_get_window(), base);
53                 evas_object_show(base);
54                 break;
55         default:
56                 break;
57         }
58 }
59
60 static void __cal_ug_result_callback(struct ui_gadget *ug, bundle *res, void *priv)
61 {
62         c_retm_if(!ug, "ug is null");
63 }
64
65 void cal_launch_ug(bundle *bd, char *ug_name, struct ug_cbs *cbs)
66 {
67         CAL_FN_START;
68
69         c_retm_if(!bd, "bd is null");
70         c_retm_if(!ug_name, "ug_name is null");
71
72         struct ui_gadget *ug;
73         struct ug_cbs uc;
74
75         if (NULL == cbs) {
76                 uc.destroy_cb = __cal_ug_destroy_callback;
77                 uc.layout_cb = __cal_ug_layout_callback;
78                 uc.result_cb = __cal_ug_result_callback;
79                 uc.priv = NULL;
80         } else {
81                 if (NULL == cbs->destroy_cb)
82                         uc.destroy_cb = __cal_ug_destroy_callback;
83                 else
84                         uc.destroy_cb = cbs->destroy_cb;
85
86                 if (NULL == cbs->layout_cb)
87                         uc.layout_cb = __cal_ug_layout_callback;
88                 else
89                         uc.layout_cb = cbs->layout_cb;
90
91                 if (NULL == cbs->result_cb)
92                         uc.result_cb = __cal_ug_result_callback;
93                 else
94                         uc.result_cb = cbs->result_cb;
95
96                 if (NULL == cbs->priv)
97                         uc.priv = NULL;
98                 else
99                         uc.priv = cbs->priv;
100         }
101
102         ug = ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &uc);
103         if (!ug)
104                 ERR("ug create error");
105 }
106
107 void cal_launch_ug_with_var(char *ug_name, struct ug_cbs *cbs,...)
108 {
109         CAL_FN_START;
110
111         c_retm_if(!ug_name, "ug_name is null");
112
113         char *key = NULL;
114         char *val = NULL;
115         bundle *bd = bundle_create();
116         c_retm_if(!bd, "bd is null");
117
118         va_list ap;
119         va_start(ap, cbs);
120         while (CAL_TRUE) {
121                 key = va_arg(ap, char *);
122                 val = va_arg(ap, char *);
123
124                 if (!key || !val) {
125                         break;
126                 }
127
128
129                 bundle_add(bd, key, val);
130         }
131
132         va_end(ap);
133
134         cal_launch_ug(bd, ug_name, cbs);
135
136         bundle_free(bd);
137 }
138
139