summaryrefslogtreecommitdiff
path: root/ug-efl-engine/ug-efl-engine.c
blob: f4bf697cb33729a29703542cd5af7db0f7a1bd88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 *  UI Gadget
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jayoun Lee <airjany@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <glib.h>
#include <Elementary.h>
#include <ui-gadget-engine.h>

#include "ug.h"
#include "ug-efl-engine.h"
#include "ug-dbg.h"

#ifndef UG_ENGINE_API
#define UG_ENGINE_API __attribute__ ((visibility("default")))
#endif

static Evas_Object *navi = NULL;
static Evas_Object *conform = NULL;
struct cb_data {
	ui_gadget_h ug;
	void (*transition_cb)(ui_gadget_h ug);
};
static void __hide_finished(void *data, Evas_Object *obj, void *event_info);
static void on_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);

static void _on_hideonly_cb(void *data, Evas_Object *obj)
{
	ui_gadget_h ug = (ui_gadget_h)data;

	if (!ug)
		return;

	_DBG("\t obj=%p ug=%p state=%d", obj, ug, ug->layout_state);

	evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);

	struct cb_data *cb_d;
	cb_d = (struct cb_data *)calloc(1, sizeof(struct cb_data));
	cb_d->ug = ug;
	cb_d->transition_cb = NULL;

	evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW, on_show_cb, cb_d);

	if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
		;
	}

	if (ug->layout_state == UG_LAYOUT_SHOW) {
		ug->layout_state = UG_LAYOUT_HIDEEFFECT;
	}

	if (GET_OPT_OVERLAP_VAL(ug->opt) == UG_OPT_OVERLAP_ENABLE) {
		_DBG("\t this is Overlap UG. Send nooverlap sig on hide_cb");
		elm_object_signal_emit(conform, "elm,state,indicator,nooverlap", "");
	}

	if (elm_naviframe_top_item_get(navi) == ug->effect_layout) {
		elm_naviframe_item_pop(navi);
	} else {
		elm_object_item_del(ug->effect_layout);
		ug->effect_layout = NULL;
	}
}

static void _del_effect_layout(ui_gadget_h ug)
{
	GSList *child, *trail;

	if (!ug)
		return;

	_DBG("\t ug=%p state=%d", ug, ug->layout_state);

	evas_object_intercept_hide_callback_del(ug->layout, _on_hideonly_cb);

	if (ug->children) {
		child = ug->children;
		while (child) {
			trail = g_slist_next(child);
			_del_effect_layout(child->data);
			child = trail;
		}
	}

	/* effect_layout of frameview is null */
	/* remove navi item */
	if (ug->effect_layout) {
		_DBG("\t remove navi item: ug=%p", ug);
		if (ug->layout_state == UG_LAYOUT_HIDEEFFECT) {
			_DBG("\t del cb, ug=%p", ug);
			evas_object_smart_callback_del(navi, "transition,finished",
							__hide_finished);
		}
		elm_object_item_del(ug->effect_layout);
		ug->effect_layout = NULL;
	}

	if (navi) {
		Elm_Object_Item *t = elm_naviframe_top_item_get(navi);
		Elm_Object_Item *b = elm_naviframe_bottom_item_get(navi);
		if (t == b) {
			_DBG("\t remove navi");
			evas_object_del(navi);
			navi = NULL;
		}
	}
	evas_object_hide(ug->layout);
}

static void __hide_finished(void *data, Evas_Object *obj, void *event_info)
{
	struct cb_data *cb_d = (struct cb_data *)data;

	if (!cb_d)
		return;

	evas_object_smart_callback_del(obj, "transition,finished",
					__hide_finished);

	ui_gadget_h ug = cb_d->ug;
	_DBG("\t obj=%p ug=%p state=%d", obj, ug, ug->layout_state);

	ug->effect_layout = NULL;
	_del_effect_layout(ug);
	cb_d->transition_cb(ug);
	free(cb_d);
}

static int __find_child(ui_gadget_h p, ui_gadget_h ug)
{
	GSList *child = NULL;

	if (!p || !ug)
		return 0;
	child = p->children;

	while (child) {
		if (child->data == ug)
			return 1;
		if (__find_child(child->data, ug))
			return 1;
		child = g_slist_next(child);
	}

	return 0;
}

static void on_destroy(ui_gadget_h ug, ui_gadget_h t_ug,
		       void (*hide_end_cb) (ui_gadget_h ug))
{
	if (!ug)
		return;
	_DBG("\t ug=%p tug=%p state=%d", ug, t_ug, ug->layout_state);

	evas_object_intercept_hide_callback_del(ug->layout,
						_on_hideonly_cb);

	if (ug != t_ug) {
		_DBG("requested ug(%p) is not top ug(%p)", ug, t_ug);
		_del_effect_layout(ug);
		hide_end_cb(ug);
		return;
	}

	if (ug->layout_state == UG_LAYOUT_SHOW) {
		struct cb_data *cb_d;
		cb_d = (struct cb_data *)calloc(1, sizeof(struct cb_data));
		cb_d->ug = ug;
		cb_d->transition_cb = hide_end_cb;

		_DBG("\t cb add ug=%p", ug);

		/* overlap update does not needed because manager will do that at on_destroy scenario */

		evas_object_smart_callback_add(navi, "transition,finished",
					__hide_finished, cb_d);
		elm_naviframe_item_pop(navi);
		ug->layout_state = UG_LAYOUT_HIDEEFFECT;
	} else if (ug->layout_state == UG_LAYOUT_HIDE
		   || ug->layout_state == UG_LAYOUT_NOEFFECT) {
		_del_effect_layout(ug);
		hide_end_cb(ug);
	} else if (ug->layout_state == UG_LAYOUT_HIDEEFFECT
		   || ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
		ug->layout_state = UG_LAYOUT_DESTROY;
	} else {
		_ERR("[UG Effect Plug-in] : layout state error!!");
	}
}

static void __show_finished(void *data, Evas_Object *obj, void *event_info)
{
	struct cb_data *cb_d = (struct cb_data *)data;
	if (!cb_d)
		return;

	ui_gadget_h ug = cb_d->ug;
	if (!ug)
		return;

	_DBG("\tobj=%p ug=%p state=%d", obj, ug, ug->layout_state);

	evas_object_smart_callback_del(obj, "transition,finished",
					__show_finished);

	if (ug->layout_state == UG_LAYOUT_NOEFFECT)
		return;

	if (ug->layout_state == UG_LAYOUT_DESTROY)
		;
	else
		ug->layout_state = UG_LAYOUT_SHOW;

	if(cb_d->transition_cb)
		cb_d->transition_cb(ug);
	free(cb_d);
}

static void on_show_cb(void *data, Evas *e, Evas_Object *obj,
		       void *event_info)
{
	struct cb_data *cb_d = (struct cb_data *)data;
	if (!cb_d)
		return;
	ui_gadget_h ug = cb_d->ug;
	if (!ug)
		return;
	_DBG("\tobj=%p ug=%p layout=%p state=%d", obj, ug, ug->layout, ug->layout_state);

	evas_object_event_callback_del(ug->layout, EVAS_CALLBACK_SHOW, on_show_cb);

	evas_object_intercept_hide_callback_add(ug->layout,
						_on_hideonly_cb, ug);

	elm_object_part_content_set(conform, "elm.swallow.ug", navi);

	if (ug->layout_state == UG_LAYOUT_HIDE
	    || ug->layout_state == UG_LAYOUT_INIT) {
		_DBG("\t UG_LAYOUT_Init(%d) obj=%p", ug->layout_state, obj);
		ug->layout_state = UG_LAYOUT_SHOWEFFECT;

		if (GET_OPT_OVERLAP_VAL(ug->opt)) {
			_DBG("\t this is Overlap UG. Send overlap sig on_show_cb");
			elm_object_signal_emit(conform, "elm,state,indicator,overlap", "");
		}

		evas_object_smart_callback_add(navi, "transition,finished",
						__show_finished, cb_d);
		ug->effect_layout = elm_naviframe_item_push(navi, NULL, NULL, NULL,
						    ug->layout, NULL);
	} else if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
		_DBG("\t UG_LAYOUT_NOEFFECT obj=%p", obj);

		if (GET_OPT_OVERLAP_VAL(ug->opt)) {
			_DBG("\t this is Overlap UG. Send overlap sig on_show_cb");
			elm_object_signal_emit(conform, "elm,state,indicator,overlap", "");
		}

		Elm_Object_Item *navi_top = elm_naviframe_top_item_get(navi);
		ug->effect_layout = elm_naviframe_item_insert_after(navi,
				navi_top, NULL, NULL, NULL, ug->layout, NULL);

		//ug start cb
		if(cb_d->transition_cb)
			cb_d->transition_cb(ug);
		free(cb_d);
	} else {
		_ERR("\tlayout state error!! state=%d\n", ug->layout_state);
		free(cb_d);
	}
}

static void *on_create(void *win, ui_gadget_h ug,
					void (*show_end_cb) (void* data))
{
	Evas_Object *navi_bg;
	Evas_Object *con = NULL;

	if (!ug)
		return NULL;
	_DBG("\t ug=%p state=%d", ug, ug->layout_state);

	con = evas_object_data_get(win, "\377 elm,conformant");
	if (con) {
		conform = con;
		_DBG("\t There is conformant");
	}
	else
		_DBG("\t There is NO conformant");

	if (!navi) {
		navi = elm_naviframe_add(conform);
		elm_object_style_set(navi, "uglib");
		elm_naviframe_content_preserve_on_pop_set(navi, EINA_TRUE);
		_DBG("\t new navi first navi=%p", navi);
		elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);

		navi_bg = evas_object_rectangle_add(evas_object_evas_get(navi));
		evas_object_size_hint_fill_set(navi_bg, EVAS_HINT_FILL,
						EVAS_HINT_FILL);
		evas_object_color_set(navi_bg, 0, 0, 0, 0);
		elm_naviframe_item_push(navi, NULL, NULL, NULL, navi_bg, NULL);
	}

	struct cb_data *cb_d;
	cb_d = (struct cb_data *)calloc(1, sizeof(struct cb_data));
	cb_d->ug = ug;
	cb_d->transition_cb = show_end_cb;

	evas_object_hide(ug->layout);
	evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW, on_show_cb, cb_d);

	ug->layout_state = UG_LAYOUT_INIT;

	return conform;
}

UG_ENGINE_API int UG_ENGINE_INIT(struct ug_engine_ops *ops)
{
	if (!ops)
		return -1;

	ops->create = on_create;
	ops->destroy = on_destroy;

	return 0;
}

UG_ENGINE_API void UG_ENGINE_EXIT(struct ug_engine_ops *ops)
{
}