apply FSL license
[pkgs/u/ui-gadget.git] / ug-efl-engine / ug-efl-engine.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
18
19
20
21 #include <glib.h>
22 #include <Elementary.h>
23 #include <ui-gadget-engine.h>
24
25 #include "ug.h"
26 #include "ug-efl-engine.h"
27 #include "ug-dbg.h"
28
29 #ifndef UG_ENGINE_API
30 #define UG_ENGINE_API __attribute__ ((visibility("default")))
31 #endif
32
33 static void _on_hideonly_cb(void *data, Evas_Object *obj)
34 {
35         struct ui_gadget *ug = (struct ui_gadget *)data;
36         if (!ug)
37                 return;
38
39         if (ug->layout_state == UG_LAYOUT_SHOW) {
40                 ug->layout_state = UG_LAYOUT_HIDEEFFECT;
41                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
42                                         "elm,state,hideonly", "");
43         }
44 }
45
46 static void _signal_hideonly_finished(void *data, Evas_Object *obj,
47                                       const char *emission, const char *source)
48 {
49         struct ui_gadget *ug = (struct ui_gadget *)data;
50         if (!ug)
51                 return;
52
53         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
54
55         evas_object_hide(ug->layout);
56         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
57
58         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
59                 return;
60
61         evas_object_hide(ug->effect_layout);
62
63         if (ug->layout_state == UG_LAYOUT_DESTROY)
64                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
65                                         "elm,state,hidealready", "");
66         else
67                 ug->layout_state = UG_LAYOUT_HIDE;
68 }
69
70 static void _signal_hide_finished(void *data, Evas_Object *obj,
71                                   const char *emission, const char *source)
72 {
73         struct ui_gadget *ug = (struct ui_gadget *)data;
74         if (!ug)
75                 return;
76
77         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
78
79         evas_object_hide(ug->layout);
80         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
81         evas_object_hide(ug->effect_layout);
82         evas_object_del(ug->effect_layout);
83         ug->effect_layout = NULL;
84 }
85
86 static void _del_effect_layout(struct ui_gadget *ug)
87 {
88         if (!ug || !ug->effect_layout)
89                 return;
90
91         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
92
93         evas_object_hide(ug->layout);
94         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
95         evas_object_hide(ug->effect_layout);
96         evas_object_del(ug->effect_layout);
97         ug->effect_layout = NULL;
98 }
99
100 static void _signal_hidealready_finished(void *data, Evas_Object *obj,
101                                 const char *emission, const char *source)
102 {
103         _del_effect_layout((struct ui_gadget*)data);
104 }
105
106 static void _do_destroy(struct ui_gadget *ug, struct ui_gadget *fv_top)
107 {
108         GSList *child;
109         GSList *trail;
110         static int depth = 0;
111
112         if (ug->children) {
113                 child = ug->children;
114                 while (child) {
115                         trail = g_slist_next(child);
116                         depth++;
117                         _do_destroy(child->data, fv_top);
118                         depth--;
119                         child = trail;
120                 }
121         }
122
123         _DBG("[UG Effect Plug-in] : start destroy. ug(%p), fv_top(%p),"
124                                         " depth(%d), layout_state(%d)\n",
125                                          ug, fv_top, depth, ug->layout_state);
126         /* only show transition effect of top view UG */
127         if (ug != fv_top) {
128                 if (depth) {
129                         _del_effect_layout(ug);
130                         return;
131                 }
132         }
133
134         if (ug->layout_state == UG_LAYOUT_SHOW) {
135                 evas_object_intercept_hide_callback_del(ug->layout,
136                                                         _on_hideonly_cb);
137                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
138                                         "elm,state,hide", "");
139         } else if (ug->layout_state == UG_LAYOUT_HIDE
140                    || ug->layout_state == UG_LAYOUT_NOEFFECT) {
141                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
142                                         "elm,state,hidealready", "");
143         } else if (ug->layout_state == UG_LAYOUT_HIDEEFFECT
144                    || ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
145                 ug->layout_state = UG_LAYOUT_DESTROY;
146         } else {
147                 _ERR("[UG Effect Plug-in] : layout state error!!");
148         }
149 }
150
151 static void on_destroy(struct ui_gadget *ug, struct ui_gadget *fv_top)
152 {
153         if (!ug)
154                 return;
155         _do_destroy(ug, fv_top);
156 }
157
158 static void _signal_show_finished(void *data, Evas_Object *obj,
159                                   const char *emission, const char *source)
160 {
161         struct ui_gadget *ug = (struct ui_gadget *)data;
162         if (!ug)
163                 return;
164
165         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
166                 return;
167
168         if (ug->layout_state == UG_LAYOUT_DESTROY)
169                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
170                                         "elm,state,hide", "");
171         else
172                 ug->layout_state = UG_LAYOUT_SHOW;
173 }
174
175 static void on_show_cb(void *data, Evas *e, Evas_Object *obj,
176                        void *event_info)
177 {
178         struct ui_gadget *ug = (struct ui_gadget *)data;
179         if (!ug)
180                 return;
181
182         if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
183                 evas_object_hide(ug->effect_layout);
184                 evas_object_show(ug->layout);
185                 return;
186         }
187
188         if (ug->layout_state == UG_LAYOUT_HIDE
189             || ug->layout_state == UG_LAYOUT_INIT) {
190                 ug->layout_state = UG_LAYOUT_SHOWEFFECT;
191                 evas_object_show(ug->effect_layout);
192                 elm_object_part_content_set(ug->effect_layout, "elm.swallow.content",
193                                        ug->layout);
194                 evas_object_intercept_hide_callback_add(ug->layout,
195                                                         _on_hideonly_cb, ug);
196                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
197                                         "elm,state,show", "");
198         }
199 }
200
201 static void *on_create(void *win, struct ui_gadget *ug,
202                        void (*hide_end_cb) (struct ui_gadget * ug))
203 {
204         static const char *ug_effect_edj_name = "/usr/share/edje/ug_effect.edj";
205
206         Evas_Object *ly = elm_layout_add((Evas_Object *) win);
207
208         if (!ly)
209                 return NULL;
210
211         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
212                                          EVAS_HINT_EXPAND);
213         elm_win_resize_object_add((Evas_Object *) win, ly);
214         elm_layout_file_set(ly, ug_effect_edj_name, "ug_effect");
215         evas_object_show(ly);
216
217         evas_object_hide(ug->layout);
218         edje_object_signal_callback_add(elm_layout_edje_get(ly),
219                                         "elm,action,hide,finished", "",
220                                         _signal_hide_finished, ug);
221         edje_object_signal_callback_add(elm_layout_edje_get(ly),
222                                         "elm,action,hide,finished", "",
223                                         (Edje_Signal_Cb) hide_end_cb, ug);
224         edje_object_signal_callback_add(elm_layout_edje_get(ly),
225                                         "elm,action,hidealready,finished", "",
226                                         _signal_hidealready_finished, ug);
227         edje_object_signal_callback_add(elm_layout_edje_get(ly),
228                                         "elm,action,hidealready,finished", "",
229                                         (Edje_Signal_Cb) hide_end_cb, ug);
230         edje_object_signal_callback_add(elm_layout_edje_get(ly),
231                                         "elm,action,hideonly,finished", "",
232                                         _signal_hideonly_finished, ug);
233         edje_object_signal_callback_add(elm_layout_edje_get(ly),
234                                         "elm,action,show,finished", "",
235                                         _signal_show_finished, ug);
236
237         evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW,
238                                        on_show_cb, ug);
239
240         ug->layout_state = UG_LAYOUT_INIT;
241
242         return ly;
243 }
244
245 UG_ENGINE_API int UG_ENGINE_INIT(struct ug_engine_ops *ops)
246 {
247         if (!ops)
248                 return -1;
249
250         ops->create = on_create;
251         ops->destroy = on_destroy;
252
253         return 0;
254 }
255
256 UG_ENGINE_API void UG_ENGINE_EXIT(struct ug_engine_ops *ops)
257 {
258 }