check rotation lock and set rotation info when ug launch
[framework/appfw/ui-gadget-1.git] / ug-efl-engine / ug-efl-engine.c
1 /*
2  *  UI Gadget
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23
24 #include <glib.h>
25 #include <Elementary.h>
26 #include <ui-gadget-engine.h>
27
28 #include "ug.h"
29 #include "ug-efl-engine.h"
30 #include "ug-dbg.h"
31
32 #ifndef UG_ENGINE_API
33 #define UG_ENGINE_API __attribute__ ((visibility("default")))
34 #endif
35
36 struct cb_data {
37         ui_gadget_h ug;
38         void(*hide_end_cb)(ui_gadget_h ug);
39 };
40
41
42 static void _on_hideonly_cb(void *data, Evas_Object *obj)
43 {
44         ui_gadget_h ug = (ui_gadget_h)data;
45         if (!ug)
46                 return;
47
48         if (ug->layout_state == UG_LAYOUT_SHOW) {
49                 ug->layout_state = UG_LAYOUT_HIDEEFFECT;
50                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
51                                         "elm,state,hideonly", "");
52         }
53 }
54
55 static void _signal_hideonly_finished(void *data, Evas_Object *obj,
56                                       const char *emission, const char *source)
57 {
58         ui_gadget_h ug = (ui_gadget_h)data;
59         if (!ug)
60                 return;
61
62         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
63
64         evas_object_hide(ug->layout);
65         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
66
67         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
68                 return;
69
70         evas_object_hide(ug->effect_layout);
71
72         if (ug->layout_state == UG_LAYOUT_DESTROY)
73                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
74                                         "elm,state,hidealready", "");
75         else
76                 ug->layout_state = UG_LAYOUT_HIDE;
77 }
78
79 static void _del_effect_layout(ui_gadget_h ug)
80 {
81         if (!ug || !ug->effect_layout)
82                 return;
83
84         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
85
86         evas_object_hide(ug->layout);
87         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
88         evas_object_hide(ug->effect_layout);
89         evas_object_del(ug->effect_layout);
90         ug->effect_layout = NULL;
91 }
92
93 static void _signal_hide_finished(void *data, Evas_Object *obj,
94                                   const char *emission, const char *source)
95 {
96         struct cb_data *cb_d = (struct cb_data*)data;
97
98         if (!cb_d)
99                 return;
100
101         ui_gadget_h ug = cb_d->ug;
102
103         _del_effect_layout(ug);
104         cb_d->hide_end_cb(ug);
105         free(cb_d);
106 }
107
108 static void _signal_hidealready_finished(void *data, Evas_Object *obj,
109                                 const char *emission, const char *source)
110 {
111         struct cb_data *cb_d = (struct cb_data*)data;
112
113         if (!cb_d)
114                 return;
115
116         ui_gadget_h ug = cb_d->ug;
117
118         _del_effect_layout(ug);
119         cb_d->hide_end_cb(ug);
120         free(cb_d);
121 }
122
123 static void _do_destroy(ui_gadget_h ug, ui_gadget_h fv_top)
124 {
125         GSList *child;
126         GSList *trail;
127         static int depth = 0;
128
129         if (ug->children) {
130                 child = ug->children;
131                 while (child) {
132                         trail = g_slist_next(child);
133                         depth++;
134                         _do_destroy(child->data, fv_top);
135                         depth--;
136                         child = trail;
137                 }
138         }
139
140         _DBG("[UG Effect Plug-in] : start destroy. ug(%p), fv_top(%p),"
141                                         " depth(%d), layout_state(%d)\n",
142                                          ug, fv_top, depth, ug->layout_state);
143
144         /* fv_top is null while destroying frameview ug */
145         if (fv_top == NULL) {
146                 _del_effect_layout(ug);
147                 return;
148         }
149         /* only show transition effect of top view UG */
150         if (ug != fv_top) {
151                 if (depth) {
152                         _del_effect_layout(ug);
153                         return;
154                 }
155         }
156
157         if (ug->layout_state == UG_LAYOUT_SHOW) {
158                 evas_object_intercept_hide_callback_del(ug->layout,
159                                                         _on_hideonly_cb);
160                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
161                                         "elm,state,hide", "");
162         } else if (ug->layout_state == UG_LAYOUT_HIDE
163                    || ug->layout_state == UG_LAYOUT_NOEFFECT) {
164                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
165                                         "elm,state,hidealready", "");
166         } else if (ug->layout_state == UG_LAYOUT_HIDEEFFECT
167                    || ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
168                 ug->layout_state = UG_LAYOUT_DESTROY;
169         } else {
170                 _ERR("[UG Effect Plug-in] : layout state error!!");
171         }
172 }
173
174 static void on_destroy(ui_gadget_h ug, ui_gadget_h fv_top)
175 {
176         if (!ug)
177                 return;
178         _do_destroy(ug, fv_top);
179 }
180
181 static void _signal_show_finished(void *data, Evas_Object *obj,
182                                   const char *emission, const char *source)
183 {
184         ui_gadget_h ug = (ui_gadget_h )data;
185         if (!ug)
186                 return;
187
188         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
189                 return;
190
191         if (ug->layout_state == UG_LAYOUT_DESTROY)
192                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
193                                         "elm,state,hide", "");
194         else
195                 ug->layout_state = UG_LAYOUT_SHOW;
196 }
197
198 static void on_show_cb(void *data, Evas *e, Evas_Object *obj,
199                        void *event_info)
200 {
201         ui_gadget_h ug = (ui_gadget_h )data;
202         if (!ug)
203                 return;
204
205         if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
206                 evas_object_hide(ug->effect_layout);
207                 evas_object_show(ug->layout);
208                 return;
209         }
210
211         if (ug->layout_state == UG_LAYOUT_HIDE
212             || ug->layout_state == UG_LAYOUT_INIT) {
213                 ug->layout_state = UG_LAYOUT_SHOWEFFECT;
214                 evas_object_show(ug->effect_layout);
215                 elm_object_part_content_set(ug->effect_layout, "elm.swallow.content",
216                                        ug->layout);
217                 evas_object_intercept_hide_callback_add(ug->layout,
218                                                         _on_hideonly_cb, ug);
219                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
220                                         "elm,state,show", "");
221         }
222 }
223
224 static void *on_create(void *win, ui_gadget_h ug,
225                        void (*hide_end_cb) (ui_gadget_h ug))
226 {
227         static const char *ug_effect_edj_name = "/usr/share/edje/ug_effect.edj";
228         struct cb_data *cb_d;
229
230         Evas_Object *ly = elm_layout_add((Evas_Object *) win);
231
232         if (!ly)
233                 return NULL;
234
235         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
236                                          EVAS_HINT_EXPAND);
237         elm_win_resize_object_add((Evas_Object *) win, ly);
238         elm_layout_file_set(ly, ug_effect_edj_name, "ug_effect");
239         evas_object_show(ly);
240
241         evas_object_hide(ug->layout);
242
243         cb_d = calloc(1, sizeof(struct cb_data));
244         cb_d->ug = ug;
245         cb_d->hide_end_cb = hide_end_cb;
246
247         edje_object_signal_callback_add(elm_layout_edje_get(ly),
248                                         "elm,action,hide,finished", "",
249                                         _signal_hide_finished, cb_d);
250         edje_object_signal_callback_add(elm_layout_edje_get(ly),
251                                         "elm,action,hidealready,finished", "",
252                                         _signal_hidealready_finished, cb_d);
253         edje_object_signal_callback_add(elm_layout_edje_get(ly),
254                                         "elm,action,hideonly,finished", "",
255                                         _signal_hideonly_finished, ug);
256         edje_object_signal_callback_add(elm_layout_edje_get(ly),
257                                         "elm,action,show,finished", "",
258                                         _signal_show_finished, ug);
259
260         evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW,
261                                        on_show_cb, ug);
262
263         ug->layout_state = UG_LAYOUT_INIT;
264
265         return ly;
266 }
267
268 UG_ENGINE_API int UG_ENGINE_INIT(struct ug_engine_ops *ops)
269 {
270         if (!ops)
271                 return -1;
272
273         ops->create = on_create;
274         ops->destroy = on_destroy;
275
276         return 0;
277 }
278
279 UG_ENGINE_API void UG_ENGINE_EXIT(struct ug_engine_ops *ops)
280 {
281 }