summaryrefslogtreecommitdiff
path: root/ug-efl-engine/ug-efl-engine.c
blob: 1faefb8ff748bc58d6075d1a9abc390267ba3047 (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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
 *  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;
static void on_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void (*show_end_cb)(void* data) = NULL;
static void (*hide_end_cb)(void* data) = NULL;

static void _layout_del_cb(void *data, Evas_Object *obj, void *event_info)
{
	ui_gadget_h ug = (ui_gadget_h)data;
	if (!ug)
		return;

	_WRN("ug(%p) layout is deleted by abnormal path", ug);

	evas_object_event_callback_del(ug->layout, EVAS_CALLBACK_DEL, _layout_del_cb);

	ug->layout_state = UG_LAYOUT_DESTROY;
	ug->layout = NULL;
}

static Eina_Bool __destroy_end_cb(void *data)
{
	GSList *child;
	ui_gadget_h ug = (ui_gadget_h)data;

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

	if (ug->children) {
		child = ug->children;
		//_DBG("\t ug(%p) has children(%p)", ug, child);
		while (child) {
			if(!child->data) {
				_ERR("child->data is null");
				return ECORE_CALLBACK_CANCEL;
			}

			//_DBG("\t child(%p) layout_state(%d)", child, ((ui_gadget_h)child->data)->layout_state);

			if( ((ui_gadget_h)child->data)->layout_state == UG_LAYOUT_HIDEEFFECT) {
				//_DBG("\t wait hideeffect child(%p)", ug);
				return ECORE_CALLBACK_RENEW;
			}
			child = g_slist_next(child);
		}
	}

	hide_end_cb(ug);
	return ECORE_CALLBACK_CANCEL;
}

static void __del_effect_end(ui_gadget_h ug)
{
	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 unset navi");
			elm_object_part_content_unset(conform, "elm.swallow.ug");
			evas_object_hide(navi);
		}
	}
	if (ug->layout) {
		evas_object_hide(ug->layout);
		evas_object_event_callback_del(ug->layout, EVAS_CALLBACK_DEL, _layout_del_cb);
	}

	ecore_idler_add((Ecore_Task_Cb)__destroy_end_cb, (void *)ug);

	ug->layout_state = UG_LAYOUT_DESTROY;
}

static void __del_finished(void *data, Evas_Object *obj, void *event_info)
{
	ui_gadget_h ug = (ui_gadget_h)data;
	if (!ug)
		return;

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

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

	if(ug->layout_state == UG_LAYOUT_HIDEEFFECT)
		__del_effect_end(ug);
	else
		_ERR("wrong ug(%p) state(%d)", ug, ug->layout_state);
}

static void __del_effect_top_layout(ui_gadget_h ug)
{
	_DBG("\t cb transition add ug=%p", ug);
	evas_object_smart_callback_add(navi, "transition,finished",
				__del_finished, ug);
	elm_naviframe_item_pop(navi);
	ug->effect_layout = NULL;
	ug->layout_state = UG_LAYOUT_HIDEEFFECT;
}

static void __del_effect_layout(ui_gadget_h ug, ui_gadget_h t_ug)
{
	GSList *child;

	if (!ug)
		return;

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

	if (ug->children) {
		child = ug->children;
		_DBG("\t ug(%p) has children(%p)", ug, child);
		while (child) {
			__del_effect_layout(child->data, t_ug);
			child = g_slist_next(child);
		}
	}

	if((ug == t_ug)&&(ug->layout_state != UG_LAYOUT_NOEFFECT)){
		if (ug->layout_state != UG_LAYOUT_HIDEEFFECT) {
			__del_effect_top_layout(ug);
		} else {
			_ERR("\t top ug(%p) state is hideeffect.");
			return;
		}
	} else {
		_DBG("\t remove navi item: ug=%p state=%d", ug, ug->layout_state);
		elm_object_item_del(ug->effect_layout);
		ug->effect_layout = NULL;
	}

	__del_effect_end(ug);
}

static void __hide_effect_end(ui_gadget_h ug)
{
	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 unset navi");
			elm_object_part_content_unset(conform, "elm.swallow.ug");
			evas_object_hide(navi);
		}
	}

	if (ug->layout) {
		evas_object_hide(ug->layout);
	}

	ug->layout_state = UG_LAYOUT_HIDE;
}

static void __hide_finished(void *data, Evas_Object *obj, void *event_info)
{
	ui_gadget_h ug = (ui_gadget_h)data;
	if (!ug)
		return;

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

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

	if(ug->layout_state == UG_LAYOUT_HIDEEFFECT)
		__hide_effect_end(ug);
	else
		_ERR("wrong ug(%p) state(%d)", ug, ug->layout_state);
}

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 layout_state=%d state=%d", obj, ug, ug->layout_state, ug->state);

	evas_object_intercept_hide_callback_del(ug->layout, __on_hideonly_cb);
	evas_object_event_callback_add(ug->layout, EVAS_CALLBACK_SHOW, on_show_cb, ug);

	if (ug->layout_state == UG_LAYOUT_SHOW) {
		ug->layout_state = UG_LAYOUT_HIDE;
	} else if (ug->layout_state == UG_LAYOUT_NOEFFECT) {
		;
	} else {
		_ERR("wrong ug(%p) state(%d)", ug, ug->layout_state);
		return;
	}

	if (elm_naviframe_top_item_get(navi) == ug->effect_layout) {
		_DBG("\t cb transition add ug=%p", ug);
		evas_object_smart_callback_add(navi, "transition,finished",
				__hide_finished, ug);
		elm_naviframe_item_pop(navi);
		ug->layout_state = UG_LAYOUT_HIDEEFFECT;
	} else {
		elm_object_item_del(ug->effect_layout);
		__hide_effect_end(ug);
	}

	ug->effect_layout = NULL;
}

static void on_destroy(ui_gadget_h ug, ui_gadget_h t_ug,
		       void (*hide_cb)(void* data))
{
	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(hide_cb == NULL) {
		/* ug_destroy_all case */
		evas_object_event_callback_del(ug->layout, EVAS_CALLBACK_DEL, _layout_del_cb);
		return;
	}

	if(!hide_end_cb)
		hide_end_cb = hide_cb;

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

	if(ug->layout_state == UG_LAYOUT_SHOW) {
		__del_effect_top_layout(ug);
	} else if (ug->layout_state == UG_LAYOUT_HIDE
		|| ug->layout_state == UG_LAYOUT_NOEFFECT
		|| ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
		__del_effect_layout(ug, t_ug);
	} else if (ug->layout_state == UG_LAYOUT_HIDEEFFECT) {
		;
	} else {
		_WRN("[UG Effect Plug-in] : layout state error!!");
		__del_effect_end(ug);
	}
}

static void __update_indicator_overlap(int opt)
{
	if (GET_OPT_OVERLAP_VAL(opt)) {
		_DBG("\t this is Overlap UG. Send overlap sig on_show_cb");
		elm_object_signal_emit(conform, "elm,state,indicator,overlap", "");
	}  else {
		_DBG("\t this is no overlap UG. Send no overlap sig on_show_cb");
		elm_object_signal_emit(conform, "elm,state,indicator,nooverlap", "");
	}
}

static void __show_finished(void *data, Evas_Object *obj, void *event_info)
{
	ui_gadget_h ug = (ui_gadget_h)data;
	if (!ug)
		return;

	_DBG("\tobj=%p ug=%p", obj, ug);

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

	if (ug->layout_state == UG_LAYOUT_DESTROY) {
		_DBG("ug(%p) already destroyed", ug);
	} else if (ug->layout_state == UG_LAYOUT_SHOWEFFECT) {
		ug->layout_state = UG_LAYOUT_SHOW;
		if((show_end_cb)&&(ug->state == UG_STATE_CREATED))
			show_end_cb(ug);
	} else {
		_ERR("wrong state(%d)", ug->layout_state);
	}

	return;
}

static void on_show_cb(void *data, Evas *e, Evas_Object *obj,
		       void *event_info)
{
	ui_gadget_h ug = (ui_gadget_h)data;
	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);

	//if 'elm.swallow.ug' string is changed, msg team have to apply this changes.
	elm_object_part_content_set(conform, "elm.swallow.ug", navi);

	if (ug->layout_state == UG_LAYOUT_HIDEEFFECT
		|| 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;

		__update_indicator_overlap(ug->opt);

		evas_object_smart_callback_add(navi, "transition,finished",
						__show_finished, ug);
		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);

		__update_indicator_overlap(ug->opt);

		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(show_end_cb)
			show_end_cb(ug);
	} else {
		_ERR("\tlayout state error!! state=%d\n", ug->layout_state);
	}

	_DBG("\ton_show_cb end ug=%p", ug);
}

static void *on_create(void *win, ui_gadget_h ug,
					void (*show_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_focus_allow_set(navi, EINA_FALSE);
		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);
	}

	if(!show_end_cb)
		show_end_cb = show_cb;

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

	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)
{
}