summaryrefslogtreecommitdiff
path: root/app-assist-efl/src/WNaviframe.cpp
blob: f911acc5fadf16a19394c9c664e27d06a6f7182d (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
/*
 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * 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 <memory.h>
#include "WNaviframe.h"
#include "WDebugInternal.h"
#include "WWindow.h"
#include "WDefineInternal.h"

#include <efl_extension.h>

#include "WView.h"

#define __CLASS_NAME	"WNaviframe"

class __WNaviframeImpl
{
public:
	__WNaviframeImpl();
	~__WNaviframeImpl();
public:
	//
	char* __name;
	Evas_Object* __evasObj;
	//
	std::function<Evas_Object*(Evas_Object*, void*)> __createHandler;
	std::function<void(bool*)> __lastItemPopHandler;

	static void __objDelCb( void* data, Evas* evas, Evas_Object* obj, void* event_info);
	static void __transitionFinishedCb(void* data, Evas_Object* obj, void* event_info);
};

__WNaviframeImpl::__WNaviframeImpl():
		__name(NULL),
		__evasObj(NULL),
		__createHandler(NULL),
		__lastItemPopHandler(NULL)
{
}
__WNaviframeImpl::~__WNaviframeImpl()
{
	if( __name)
		free(__name);
}


void __WNaviframeImpl::__objDelCb( void* data, Evas* evas, Evas_Object* obj, void* event_info)
{
	WHIT();

	auto frame = (WNaviframe*)data;
	frame->onDestroy();
	//
	delete frame;
}


void __WNaviframeImpl::__transitionFinishedCb(void* data, Evas_Object* obj, void* event_info)
{
//	WNaviframe* nf = (WNaviframe*)data;
//	nf->getTopView()->onExpose();
}


WNaviframe::WNaviframe() : __pv( new __WNaviframeImpl() )
{
	WHIT();
}

WNaviframe::~WNaviframe()
{
	WHIT();
	delete __pv;
}

const char* WNaviframe::getClassName()
{
	return __CLASS_NAME;
}

bool WNaviframe::create( Evas_Object* parent, void* param )
{
//	mWindow = win;
	if( __pv->__evasObj )
	{
		WDEBUG("Already created!");
		return true;
	}
	__pv->__evasObj = NULL;
	if( __pv->__createHandler )
		__pv->__evasObj = __pv->__createHandler(parent, param);
	else
		__pv->__evasObj = onCreate(parent, param);
	//
	if(__pv->__evasObj ==  NULL)
	{
		WERROR("No frame object created!");
		return false;
	}
	evas_object_data_set( __pv->__evasObj, WKEY_FRAME_INSTANCE, this );
	evas_object_event_callback_add( __pv->__evasObj, EVAS_CALLBACK_DEL, __WNaviframeImpl::__objDelCb, this);
	//
	// Do not place this before "evas_object_event_callback_add",
	// The reason is that if additional del callback is added at child class, it should be called first to keep state the class object is still alive.
	onCreated();

	return true;
}

void WNaviframe::destroy()
{
	WHIT();
	if(__pv->__evasObj)
	{
		destroyAllViews();
		evas_object_del(__pv->__evasObj);
		// Do not leave any code here.
		// After executing upper statement "evas_object_del", this object will be deleted at evas object deletion callback!
	}
	else
	{
		onDestroy();
		delete this;
	}
}

Evas_Object* WNaviframe::getEvasObj()
{
	return __pv->__evasObj;
}

void WNaviframe::setName(const char* name)
{
	if( __pv->__name)
	{
		free(__pv->__name);
		__pv->__name = NULL;
	}
	if( name )
	{
		__pv->__name = (char*)malloc( strlen(name)+1);
		strcpy( __pv->__name, name);
	}
}

const char* WNaviframe::getName()
{
	return __pv->__name;
}

WWindow* WNaviframe::getWindow()
{
	if( __pv->__evasObj == NULL)
		return NULL;

	WWindow* window = (WWindow*)evas_object_data_get( __pv->__evasObj, WKEY_WINDOW_INSTANCE );

	return window;
}

bool WNaviframe::push( WView* view, const char* viewName, void* viewCreationParam )
{
	if( viewName )
		view->setName( viewName );
	return onPush( view, viewCreationParam );
	//

}

void WNaviframe::destroyAllViews()
{
	WHIT();

	Eina_List* list = elm_naviframe_items_get( getEvasObj());
	Eina_List* temp = NULL;
	void* it = NULL;
	EINA_LIST_FOREACH( list, temp, it)
	{
		elm_object_item_del( (Elm_Object_Item*)it);
	}

}

void WNaviframe::setOnCreate( const std::function<Evas_Object*(Evas_Object*, void*)>& handlerFunc)
{
	__pv->__createHandler = handlerFunc;
}


void WNaviframe::setOnLastItemPop( const std::function<void(bool*)>& handlerFunc)
{
	__pv->__lastItemPopHandler = handlerFunc;
}



Evas_Object* WNaviframe::onCreate(Evas_Object* parent, void* param)
{
	Evas_Object* obj = elm_naviframe_add( parent);
	elm_object_part_content_set(parent, "elm.swallow.content", obj);
	eext_object_event_callback_add(obj, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
	eext_object_event_callback_add(obj, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
	evas_object_smart_callback_add(obj, "transition,finished", __WNaviframeImpl::__transitionFinishedCb, this);

	evas_object_show(obj);

	return obj;
}

void WNaviframe::onDestroy()
{

}

void WNaviframe::onLastItemPop( bool* popOut )
{
	WHIT();
	*popOut = false;
	WWindow *window = getWindow();
	if (window) {
		elm_win_lower(window->getEvasObj());
	}
}

bool WNaviframe::onPush( WView* view, void* viewParam )
{
	WASSERT( getEvasObj() != NULL );
	//
	view->create( getEvasObj(), viewParam );


	WView_setContainerProperties( view, getWindow(), this );
	//
	Elm_Object_Item* item = view->onPushToNaviframe( getEvasObj() );
	if( item == NULL )
		item = elm_naviframe_item_push( getEvasObj(), view->getTitle(), NULL, NULL, view->getEvasObj(), NULL);
	//
	WView_setContainerNaviItemProperty( view, item );
	//
	if( view->__callPushedHandlerFunc( item ) == false)
		view->onPushed( item );

	elm_naviframe_item_pop_cb_set( item, __popCb, view);

	return true;
}

bool WNaviframe::onItemPop( WView* view, Elm_Object_Item* item )
{
	WNaviframe* nf = view->getNaviframe();

	if( item == elm_naviframe_bottom_item_get( nf->getEvasObj() ))
	{
		bool ret = view->onPop();
		if( ret == false )
			return EINA_FALSE;

		bool popOut = true;

		if( nf->__pv->__lastItemPopHandler)
			nf->__pv->__lastItemPopHandler(&popOut);
		else
			nf->onLastItemPop(&popOut);
		return popOut;
	}
	else
	{
		return view->onPop();
	}
}

Eina_Bool WNaviframe::__popCb( void* data, Elm_Object_Item* item)
{
	auto view = (WView*)data;
	WNaviframe* nf = view->getNaviframe();
	//
	WASSERT( view->getNaviItem() == item );
	//
	if( nf->onItemPop( view, item ) )
		return EINA_TRUE;
	else
		return EINA_FALSE;
}