Add default Smack manifest for ui-gadget.spec
[pkgs/u/ui-gadget.git] / ug-efl-engine / ug-efl-engine.c
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This file is part of the UI Gadget
5  * Written by Jayoun Lee <airjany@samsung.com>, Jinwoo Nam <jwoo.nam@samsung.com>
6  *
7  * PROPRIETARY/CONFIDENTIAL
8  *
9  * This software is the confidential and proprietary information of
10  * SAMSUNG ELECTRONICS (Confidential Information).
11  * You shall not disclose such Confidential Information and shall
12  * use it only in accordance with the terms of the license agreement
13  * you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
14  * representations or warranties about the suitability
15  * of the software, either express or implied, including but not
16  * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
17  * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
18  * a result of using, modifying or distributing this software or its derivatives.
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 static void _on_hideonly_cb(void *data, Evas_Object *obj)
37 {
38         struct ui_gadget *ug = (struct ui_gadget *)data;
39         if (!ug)
40                 return;
41
42         if (ug->layout_state == UG_LAYOUT_SHOW) {
43                 ug->layout_state = UG_LAYOUT_HIDEEFFECT;
44                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
45                                         "elm,state,hideonly", "");
46         }
47 }
48
49 static void _signal_hideonly_finished(void *data, Evas_Object *obj,
50                                       const char *emission, const char *source)
51 {
52         struct ui_gadget *ug = (struct ui_gadget *)data;
53         if (!ug)
54                 return;
55
56         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
57
58         evas_object_hide(ug->layout);
59         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
60
61         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
62                 return;
63
64         evas_object_hide(ug->effect_layout);
65
66         if (ug->layout_state == UG_LAYOUT_DESTROY)
67                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
68                                         "elm,state,hidealready", "");
69         else
70                 ug->layout_state = UG_LAYOUT_HIDE;
71 }
72
73 static void _signal_hide_finished(void *data, Evas_Object *obj,
74                                   const char *emission, const char *source)
75 {
76         struct ui_gadget *ug = (struct ui_gadget *)data;
77         if (!ug)
78                 return;
79
80         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
81
82         evas_object_hide(ug->layout);
83         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
84         evas_object_hide(ug->effect_layout);
85         evas_object_del(ug->effect_layout);
86         ug->effect_layout = NULL;
87 }
88
89 static void _del_effect_layout(struct ui_gadget *ug)
90 {
91         if (!ug || !ug->effect_layout)
92                 return;
93
94         evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);
95
96         evas_object_hide(ug->layout);
97         elm_object_part_content_unset(ug->effect_layout, "elm.swallow.content");
98         evas_object_hide(ug->effect_layout);
99         evas_object_del(ug->effect_layout);
100         ug->effect_layout = NULL;
101 }
102
103 static void _signal_hidealready_finished(void *data, Evas_Object *obj,
104                                 const char *emission, const char *source)
105 {
106         _del_effect_layout((struct ui_gadget*)data);
107 }
108
109 static void _do_destroy(struct ui_gadget *ug, struct ui_gadget *fv_top)
110 {
111         GSList *child;
112         GSList *trail;
113         static int depth = 0;
114
115         if (ug->children) {
116                 child = ug->children;
117                 while (child) {
118                         trail = g_slist_next(child);
119                         depth++;
120                         _do_destroy(child->data, fv_top);
121                         depth--;
122                         child = trail;
123                 }
124         }
125
126         _DBG("[UG Effect Plug-in] : start destroy. ug(%p), fv_top(%p),"
127                                         " depth(%d), layout_state(%d)\n",
128                                          ug, fv_top, depth, ug->layout_state);
129         /* only show transition effect of top view UG */
130         if (ug != fv_top) {
131                 if (depth) {
132                         _del_effect_layout(ug);
133                         return;
134                 }
135         }
136
137         if (ug->layout_state == UG_LAYOUT_SHOW) {
138                 evas_object_intercept_hide_callback_del(ug->layout,
139                                                         _on_hideonly_cb);
140                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
141                                         "elm,state,hide", "");
142         } else if (ug->layout_state == UG_LAYOUT_HIDE
143                    || ug->layout_state == UG_LAYOUT_NOEFFECT) {
144                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
145                                         "elm,state,hidealready", "");
146         } else if (ug->layout_state == UG_LAYOUT_HIDEEFFECT
147                    || ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
148                 ug->layout_state = UG_LAYOUT_DESTROY;
149         } else {
150                 _ERR("[UG Effect Plug-in] : layout state error!!");
151         }
152 }
153
154 static void on_destroy(struct ui_gadget *ug, struct ui_gadget *fv_top)
155 {
156         if (!ug)
157                 return;
158         _do_destroy(ug, fv_top);
159 }
160
161 static void _signal_show_finished(void *data, Evas_Object *obj,
162                                   const char *emission, const char *source)
163 {
164         struct ui_gadget *ug = (struct ui_gadget *)data;
165         if (!ug)
166                 return;
167
168         if (ug->layout_state == UG_LAYOUT_NOEFFECT)
169                 return;
170
171         if (ug->layout_state == UG_LAYOUT_DESTROY)
172                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
173                                         "elm,state,hide", "");
174         else
175                 ug->layout_state = UG_LAYOUT_SHOW;
176 }
177
178 static void on_show_cb(void *data, Evas *e, Evas_Object *obj,
179                        void *event_info)
180 {
181         struct ui_gadget *ug = (struct ui_gadget *)data;
182         if (!ug)
183                 return;
184
185         if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
186                 evas_object_hide(ug->effect_layout);
187                 evas_object_show(ug->layout);
188                 return;
189         }
190
191         if (ug->layout_state == UG_LAYOUT_HIDE
192             || ug->layout_state == UG_LAYOUT_INIT) {
193                 ug->layout_state = UG_LAYOUT_SHOWEFFECT;
194                 evas_object_show(ug->effect_layout);
195                 elm_object_part_content_set(ug->effect_layout, "elm.swallow.content",
196                                        ug->layout);
197                 evas_object_intercept_hide_callback_add(ug->layout,
198                                                         _on_hideonly_cb, ug);
199                 edje_object_signal_emit(elm_layout_edje_get(ug->effect_layout),
200                                         "elm,state,show", "");
201         }
202 }
203
204 static void *on_create(void *win, struct ui_gadget *ug,
205                        void (*hide_end_cb) (struct ui_gadget * ug))
206 {
207         static const char *ug_effect_edj_name = "/usr/share/edje/ug_effect.edj";
208
209         Evas_Object *ly = elm_layout_add((Evas_Object *) win);
210
211         if (!ly)
212                 return NULL;
213
214         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
215                                          EVAS_HINT_EXPAND);
216         elm_win_resize_object_add((Evas_Object *) win, ly);
217         elm_layout_file_set(ly, ug_effect_edj_name, "ug_effect");
218         evas_object_show(ly);
219
220         evas_object_hide(ug->layout);
221         edje_object_signal_callback_add(elm_layout_edje_get(ly),
222                                         "elm,action,hide,finished", "",
223                                         _signal_hide_finished, ug);
224         edje_object_signal_callback_add(elm_layout_edje_get(ly),
225                                         "elm,action,hide,finished", "",
226                                         (Edje_Signal_Cb) hide_end_cb, ug);
227         edje_object_signal_callback_add(elm_layout_edje_get(ly),
228                                         "elm,action,hidealready,finished", "",
229                                         _signal_hidealready_finished, ug);
230         edje_object_signal_callback_add(elm_layout_edje_get(ly),
231                                         "elm,action,hidealready,finished", "",
232                                         (Edje_Signal_Cb) hide_end_cb, ug);
233         edje_object_signal_callback_add(elm_layout_edje_get(ly),
234                                         "elm,action,hideonly,finished", "",
235                                         _signal_hideonly_finished, ug);
236         edje_object_signal_callback_add(elm_layout_edje_get(ly),
237                                         "elm,action,show,finished", "",
238                                         _signal_show_finished, ug);
239
240         evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW,
241                                        on_show_cb, ug);
242
243         ug->layout_state = UG_LAYOUT_INIT;
244
245         return ly;
246 }
247
248 UG_ENGINE_API int UG_ENGINE_INIT(struct ug_engine_ops *ops)
249 {
250         if (!ops)
251                 return -1;
252
253         ops->create = on_create;
254         ops->destroy = on_destroy;
255
256         return 0;
257 }
258
259 UG_ENGINE_API void UG_ENGINE_EXIT(struct ug_engine_ops *ops)
260 {
261 }