2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Lukasz Wrzosek (l.wrzosel@samsung.com)
20 * @brief This file is the header for Evas_Object wrapper from Efl.
22 #ifndef WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
23 #define WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
31 #include <dpl/framework_efl.h>
32 #include <dpl/assert.h>
33 #include <dpl/foreach.h>
34 #include <dpl/apply.h>
35 #include <dpl/noncopyable.h>
39 class EvasObjectShared;
40 typedef std::shared_ptr<EvasObjectShared> EvasObjectSharedPtr;
46 Evas_Object* GetEvasObject();
50 IConnection(EvasObjectShared* object);
51 virtual ~IConnection()
53 virtual void Call(void* /*event_info*/) = 0;
55 static void SmartCallbackWrapper(void* data,
56 Evas_Object* /*object*/,
58 static void EvasCallbackWrapper(void* data,
60 Evas_Object* /*object*/,
63 virtual void ConnectPrv() = 0;
64 virtual void DisconnectPrv() = 0;
66 friend class EvasObjectShared;
68 EvasObjectShared* m_object;
72 class EvasObjectShared : DPL::Noncopyable
75 friend class IConnection;
76 Evas_Object* GetObject();
78 typedef std::set<IConnection*> IConnectionsSet;
80 class SmartConnectionBase : public IConnection
83 SmartConnectionBase(const std::string& name,
84 EvasObjectShared* object);
86 virtual void ConnectPrv();
87 virtual void DisconnectPrv();
88 std::string m_callbackName;
91 template<typename ... Args>
92 class SmartConnection : public SmartConnectionBase
95 typedef void (*CbType)(IConnection* connection,
99 SmartConnection(const std::string& name,
101 EvasObjectShared* object,
103 SmartConnectionBase(name, object),
104 m_callback(callback),
108 virtual ~SmartConnection()
111 virtual void Call(void* event_info)
114 DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
122 std::tuple<Args ...> m_args;
125 template <class ThisType, class ArgType1>
126 class SmartMemberConnection1 : public SmartConnectionBase
129 typedef void (ThisType::*CbType)(IConnection* connection,
130 void* event_info, ArgType1 *arg1);
132 SmartMemberConnection1(const std::string& name,
136 EvasObjectShared* object) :
137 SmartConnectionBase(name, object),
138 m_callback(callback),
143 virtual ~SmartMemberConnection1()
146 virtual void Call(void* event_info)
148 (m_callee->*m_callback)(this, event_info, m_arg1);
157 template <class ThisType, class ArgType1, class ArgType2>
158 class SmartMemberConnection2 : public SmartConnectionBase
161 typedef void (ThisType::*CbType)(IConnection* connection,
162 void* event_info, ArgType1 *arg1,
165 SmartMemberConnection2(const std::string& name,
170 EvasObjectShared* object) :
171 SmartConnectionBase(name, object),
172 m_callback(callback),
178 virtual ~SmartMemberConnection2()
181 virtual void Call(void* event_info)
183 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
193 class EvasConnectionBase : public IConnection
196 EvasConnectionBase(Evas_Callback_Type type,
197 EvasObjectShared* object);
199 virtual void ConnectPrv();
200 virtual void DisconnectPrv();
202 Evas_Callback_Type m_callbackType;
205 template <class ArgType1>
206 class EvasConnection1 : public EvasConnectionBase
209 typedef void (*CbType)(IConnection* connection, void* event_info,
212 EvasConnection1(Evas_Callback_Type type,
215 EvasObjectShared* object) :
216 EvasConnectionBase(type, object),
217 m_callback(callback),
221 virtual ~EvasConnection1()
224 virtual void Call(void* event_info)
226 m_callback(this, event_info, m_arg1);
234 template <class ArgType1, class ArgType2>
235 class EvasConnection2 : public EvasConnectionBase
238 typedef void (*CbType)(IConnection* connection, void* event_info,
239 ArgType1 *arg1, ArgType2 *arg2);
241 EvasConnection2(Evas_Callback_Type type,
245 EvasObjectShared* object) :
246 EvasConnectionBase(type, object),
247 m_callback(callback),
252 virtual ~EvasConnection2()
255 virtual void Call(void* event_info)
257 m_callback(this, event_info, m_arg1, m_arg2);
266 template <class ThisType, class ArgType1>
267 class EvasMemberConnection1 : public EvasConnectionBase
270 typedef void (ThisType::*CbType)(IConnection* connection,
271 void* event_info, ArgType1 *arg1);
273 EvasMemberConnection1(Evas_Callback_Type type,
277 EvasObjectShared* object) :
278 EvasConnectionBase(type, object),
279 m_callback(callback),
284 virtual ~EvasMemberConnection1()
287 virtual void Call(void* event_info)
289 (m_callee->*m_callback)(this, event_info, m_arg1);
298 template <class ThisType, class ArgType1, class ArgType2>
299 class EvasMemberConnection2 : public EvasConnectionBase
302 typedef void (ThisType::*CbType)(IConnection* connection,
303 void* event_info, ArgType1* arg1,
306 EvasMemberConnection2(Evas_Callback_Type type,
311 EvasObjectShared* object) :
312 EvasConnectionBase(type, object),
313 m_callback(callback),
319 virtual ~EvasMemberConnection2()
322 virtual void Call(void* event_info)
324 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
335 explicit EvasObjectShared(Evas_Object* object);
336 void SetObject(Evas_Object* object);
339 template<typename ... Args>
340 IConnection* ConnectSmartCallback(
341 const char* callbackName,
342 typename SmartConnection<Args ...>::
347 Assert(callbackName);
349 IConnection* connection = new SmartConnection<Args ...>(
354 m_connections.insert(connection);
355 connection->ConnectPrv();
359 template <class ThisType, class ArgType1, class ArgType2>
360 IConnection* ConnectMemberSmartCallback(
361 const char* callbackName,
362 typename SmartMemberConnection2<ThisType, ArgType1,
363 ArgType2>::CbType callback,
370 Assert(callbackName);
372 IConnection* connection =
373 new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
380 m_connections.insert(connection);
381 connection->ConnectPrv();
385 template <class ThisType, class ArgType1>
386 IConnection* ConnectMemberSmartCallback(
387 const char* callbackName,
388 typename SmartMemberConnection1<ThisType,
389 ArgType1>::CbType callback,
395 Assert(callbackName);
397 IConnection* connection =
398 new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
403 m_connections.insert(connection);
404 connection->ConnectPrv();
408 template <class ArgType1, class ArgType2>
409 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
410 typename EvasConnection2<ArgType1,
417 Assert(callbackType);
419 IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
425 m_connections.insert(connection);
426 connection->ConnectPrv();
430 template <class ArgType1>
431 IConnection* ConnectEvasCallback(
432 Evas_Callback_Type callbackType,
433 typename EvasConnection1<ArgType1>::
438 Assert(callbackType);
440 IConnection* connection = new EvasConnection1<ArgType1>(
445 m_connections.insert(connection);
446 connection->ConnectPrv();
450 template <class ThisType, class ArgType1, class ArgType2>
451 IConnection* ConnectMemberEvasCallback(
452 Evas_Callback_Type callbackType,
453 typename EvasMemberConnection2<ThisType, ArgType1,
454 ArgType2>::CbType callback,
461 Assert(callbackType);
463 IConnection* connection =
464 new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
471 m_connections.insert(connection);
472 connection->ConnectPrv();
476 template <class ThisType, class ArgType1>
477 IConnection* ConnectMemberEvasCallback(
478 Evas_Callback_Type callbackType,
479 typename EvasMemberConnection1<ThisType,
480 ArgType1>::CbType callback,
486 Assert(callbackType);
488 IConnection* connection =
489 new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
494 m_connections.insert(connection);
495 connection->ConnectPrv();
499 bool DisconnectCallback(IConnection* connection);
500 void DisconnectAll();
502 static void StaticOnDelEvent(void* data,
507 IConnectionsSet m_connections;
508 Evas_Object* m_object;
513 explicit EvasObject(Evas_Object* object);
514 EvasObject(const EvasObject& other);
517 EvasObject& operator=(const EvasObject& other);
518 EvasObject* operator=(Evas_Object* object);
520 operator Evas_Object *();
525 return m_object->GetObject() != NULL;
528 bool DisconnectCallback(IConnection* connection);
529 void DisconnectAll();
531 template <class ... Args>
532 IConnection* ConnectSmartCallback(
533 const char* callbackName,
534 typename EvasObjectShared::SmartConnection<Args ...>::CbType
539 return m_object->ConnectSmartCallback(callbackName, callback, args ...);
542 template <class ThisType, class ArgType1, class ArgType2>
543 IConnection* ConnectMemberSmartCallback(
544 const char* callbackName,
545 typename EvasObjectShared::SmartMemberConnection2<ThisType,
556 return m_object->ConnectMemberSmartCallback(callbackName,
563 template <class ThisType, class ArgType1>
564 IConnection* ConnectMemberSmartCallback(
565 const char* callbackName,
566 typename EvasObjectShared::SmartMemberConnection1<ThisType,
575 return m_object->ConnectMemberSmartCallback(callbackName,
581 template <class ArgType1, class ArgType2>
582 IConnection* ConnectEvasCallback(
583 Evas_Callback_Type callbackType,
584 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
590 return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
593 template <class ArgType1>
594 IConnection* ConnectEvasCallback(
595 Evas_Callback_Type callbackType,
596 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
601 return m_object->ConnectEvasCallback(callbackType, callback, arg1);
604 template <class ThisType, class ArgType1>
605 IConnection* ConnectMemberEvasCallback(
606 Evas_Callback_Type callbackType,
607 typename EvasObjectShared::EvasMemberConnection1<ThisType,
616 return m_object->ConnectMemberEvasCallback(callbackType,
622 template <class ThisType, class ArgType1, class ArgType2>
623 IConnection* ConnectMemberEvasCallback(
624 Evas_Callback_Type callbackType,
625 typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
635 return m_object->ConnectMemberEvasCallback(callbackType,
643 EvasObjectSharedPtr m_object;
646 #endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H