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.
23 #ifndef WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
24 #define WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
27 #include <dpl/noncopyable.h>
28 #include <dpl/framework_efl.h>
29 #include <dpl/assert.h>
30 #include <dpl/foreach.h>
31 #include <dpl/apply.h>
44 class EvasObjectShared;
45 typedef std::shared_ptr<EvasObjectShared> EvasObjectSharedPtr;
51 Evas_Object* GetEvasObject();
55 IConnection(EvasObjectShared* object);
56 virtual ~IConnection()
59 virtual void Call(void* /*event_info*/) = 0;
61 static void SmartCallbackWrapper(void* data,
62 Evas_Object* /*object*/,
64 static void EvasCallbackWrapper(void* data,
66 Evas_Object* /*object*/,
69 virtual void ConnectPrv() = 0;
70 virtual void DisconnectPrv() = 0;
72 friend class EvasObjectShared;
74 EvasObjectShared* m_object;
78 class EvasObjectShared : DPL::Noncopyable
81 friend class IConnection;
82 Evas_Object* GetObject();
84 typedef std::set<IConnection*> IConnectionsSet;
86 class SmartConnectionBase : public IConnection
89 SmartConnectionBase(const std::string& name,
90 EvasObjectShared* object);
92 virtual void ConnectPrv();
93 virtual void DisconnectPrv();
94 std::string m_callbackName;
97 template<typename ... Args>
98 class SmartConnection : public SmartConnectionBase
101 typedef void (*CbType)(IConnection* connection,
105 SmartConnection(const std::string& name,
107 EvasObjectShared* object,
109 SmartConnectionBase(name, object),
110 m_callback(callback),
115 virtual ~SmartConnection()
119 virtual void Call(void* event_info)
122 DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
130 std::tuple<Args ...> m_args;
133 template <class ThisType, class ArgType1>
134 class SmartMemberConnection1 : public SmartConnectionBase
137 typedef void (ThisType::*CbType)(IConnection* connection,
138 void* event_info, ArgType1 *arg1);
140 SmartMemberConnection1(const std::string& name,
144 EvasObjectShared* object) :
145 SmartConnectionBase(name, object),
146 m_callback(callback),
152 virtual ~SmartMemberConnection1()
156 virtual void Call(void* event_info)
158 (m_callee->*m_callback)(this, event_info, m_arg1);
167 template <class ThisType, class ArgType1, class ArgType2>
168 class SmartMemberConnection2 : public SmartConnectionBase
171 typedef void (ThisType::*CbType)(IConnection* connection,
172 void* event_info, ArgType1 *arg1,
175 SmartMemberConnection2(const std::string& name,
180 EvasObjectShared* object) :
181 SmartConnectionBase(name, object),
182 m_callback(callback),
189 virtual ~SmartMemberConnection2()
193 virtual void Call(void* event_info)
195 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
205 class EvasConnectionBase : public IConnection
208 EvasConnectionBase(Evas_Callback_Type type,
209 EvasObjectShared* object);
211 virtual void ConnectPrv();
212 virtual void DisconnectPrv();
214 Evas_Callback_Type m_callbackType;
217 template <class ArgType1>
218 class EvasConnection1 : public EvasConnectionBase
221 typedef void (*CbType)(IConnection* connection, void* event_info,
224 EvasConnection1(Evas_Callback_Type type,
227 EvasObjectShared* object) :
228 EvasConnectionBase(type, object),
229 m_callback(callback),
234 virtual ~EvasConnection1()
238 virtual void Call(void* event_info)
240 m_callback(this, event_info, m_arg1);
248 template <class ArgType1, class ArgType2>
249 class EvasConnection2 : public EvasConnectionBase
252 typedef void (*CbType)(IConnection* connection, void* event_info,
253 ArgType1 *arg1, ArgType2 *arg2);
255 EvasConnection2(Evas_Callback_Type type,
259 EvasObjectShared* object) :
260 EvasConnectionBase(type, object),
261 m_callback(callback),
267 virtual ~EvasConnection2()
271 virtual void Call(void* event_info)
273 m_callback(this, event_info, m_arg1, m_arg2);
282 template <class ThisType, class ArgType1>
283 class EvasMemberConnection1 : public EvasConnectionBase
286 typedef void (ThisType::*CbType)(IConnection* connection,
287 void* event_info, ArgType1 *arg1);
289 EvasMemberConnection1(Evas_Callback_Type type,
293 EvasObjectShared* object) :
294 EvasConnectionBase(type, object),
295 m_callback(callback),
301 virtual ~EvasMemberConnection1()
305 virtual void Call(void* event_info)
307 (m_callee->*m_callback)(this, event_info, m_arg1);
316 template <class ThisType, class ArgType1, class ArgType2>
317 class EvasMemberConnection2 : public EvasConnectionBase
320 typedef void (ThisType::*CbType)(IConnection* connection,
321 void* event_info, ArgType1* arg1,
324 EvasMemberConnection2(Evas_Callback_Type type,
329 EvasObjectShared* object) :
330 EvasConnectionBase(type, object),
331 m_callback(callback),
338 virtual ~EvasMemberConnection2()
342 virtual void Call(void* event_info)
344 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
355 explicit EvasObjectShared(Evas_Object* object);
356 void SetObject(Evas_Object* object);
359 template<typename ... Args>
360 IConnection* ConnectSmartCallback(const char* callbackName,
361 typename SmartConnection<Args ...>::CbType callback,
365 Assert(callbackName);
367 IConnection* connection = new SmartConnection<Args ...>(
372 m_connections.insert(connection);
373 connection->ConnectPrv();
377 template <class ThisType, class ArgType1, class ArgType2>
378 IConnection* ConnectMemberSmartCallback(
379 const char* callbackName,
380 typename SmartMemberConnection2<ThisType, ArgType1,
381 ArgType2>::CbType callback,
388 Assert(callbackName);
390 IConnection* connection =
391 new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
398 m_connections.insert(connection);
399 connection->ConnectPrv();
403 template <class ThisType, class ArgType1>
404 IConnection* ConnectMemberSmartCallback(
405 const char* callbackName,
406 typename SmartMemberConnection1<ThisType,
407 ArgType1>::CbType callback,
413 Assert(callbackName);
415 IConnection* connection =
416 new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
421 m_connections.insert(connection);
422 connection->ConnectPrv();
426 template <class ArgType1, class ArgType2>
427 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
428 typename EvasConnection2<ArgType1, ArgType2>::CbType callback,
433 Assert(callbackType);
435 IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
441 m_connections.insert(connection);
442 connection->ConnectPrv();
446 template <class ArgType1>
447 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
448 typename EvasConnection1<ArgType1>::CbType callback,
452 Assert(callbackType);
454 IConnection* connection = new EvasConnection1<ArgType1>(
459 m_connections.insert(connection);
460 connection->ConnectPrv();
464 template <class ThisType, class ArgType1, class ArgType2>
465 IConnection* ConnectMemberEvasCallback(
466 Evas_Callback_Type callbackType,
467 typename EvasMemberConnection2<ThisType, ArgType1,
468 ArgType2>::CbType callback,
475 Assert(callbackType);
477 IConnection* connection =
478 new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
485 m_connections.insert(connection);
486 connection->ConnectPrv();
490 template <class ThisType, class ArgType1>
491 IConnection* ConnectMemberEvasCallback(
492 Evas_Callback_Type callbackType,
493 typename EvasMemberConnection1<ThisType,
494 ArgType1>::CbType callback,
500 Assert(callbackType);
502 IConnection* connection =
503 new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
508 m_connections.insert(connection);
509 connection->ConnectPrv();
513 bool DisconnectCallback(IConnection* connection);
514 void DisconnectAll();
516 static void StaticOnDelEvent(void* data,
521 IConnectionsSet m_connections;
522 Evas_Object* m_object;
527 explicit EvasObject(Evas_Object* object);
528 EvasObject(const EvasObject& other);
531 EvasObject& operator=(const EvasObject& other);
532 EvasObject* operator=(Evas_Object* object);
534 operator Evas_Object *();
539 return m_object->GetObject() != NULL;
542 bool DisconnectCallback(IConnection* connection);
543 void DisconnectAll();
545 template <class ... Args>
546 IConnection* ConnectSmartCallback(
547 const char* callbackName,
548 typename EvasObjectShared::SmartConnection<Args ...>::CbType
553 return m_object->ConnectSmartCallback(callbackName, callback, args ...);
556 template <class ThisType, class ArgType1, class ArgType2>
557 IConnection* ConnectMemberSmartCallback(
558 const char* callbackName,
559 typename EvasObjectShared::SmartMemberConnection2<ThisType,
570 return m_object->ConnectMemberSmartCallback(callbackName,
577 template <class ThisType, class ArgType1>
578 IConnection* ConnectMemberSmartCallback(
579 const char* callbackName,
580 typename EvasObjectShared::SmartMemberConnection1<ThisType,
589 return m_object->ConnectMemberSmartCallback(callbackName,
595 template <class ArgType1, class ArgType2>
596 IConnection* ConnectEvasCallback(
597 Evas_Callback_Type callbackType,
598 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
604 return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
607 template <class ArgType1>
608 IConnection* ConnectEvasCallback(
609 Evas_Callback_Type callbackType,
610 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
615 return m_object->ConnectEvasCallback(callbackType, callback, arg1);
618 template <class ThisType, class ArgType1>
619 IConnection* ConnectMemberEvasCallback(
620 Evas_Callback_Type callbackType,
621 typename EvasObjectShared::EvasMemberConnection1<ThisType,
630 return m_object->ConnectMemberEvasCallback(callbackType,
636 template <class ThisType, class ArgType1, class ArgType2>
637 IConnection* ConnectMemberEvasCallback(
638 Evas_Callback_Type callbackType,
639 typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
649 return m_object->ConnectMemberEvasCallback(callbackType,
657 EvasObjectSharedPtr m_object;
665 #endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H