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>
43 class EvasObjectShared;
44 typedef std::shared_ptr<EvasObjectShared> EvasObjectSharedPtr;
50 Evas_Object* GetEvasObject();
54 IConnection(EvasObjectShared* object);
55 virtual ~IConnection()
57 virtual void Call(void* /*event_info*/) = 0;
59 static void SmartCallbackWrapper(void* data,
60 Evas_Object* /*object*/,
62 static void EvasCallbackWrapper(void* data,
64 Evas_Object* /*object*/,
67 virtual void ConnectPrv() = 0;
68 virtual void DisconnectPrv() = 0;
70 friend class EvasObjectShared;
72 EvasObjectShared* m_object;
76 class EvasObjectShared : DPL::Noncopyable
79 friend class IConnection;
80 Evas_Object* GetObject();
82 typedef std::set<IConnection*> IConnectionsSet;
84 class SmartConnectionBase : public IConnection
87 SmartConnectionBase(const std::string& name,
88 EvasObjectShared* object);
90 virtual void ConnectPrv();
91 virtual void DisconnectPrv();
92 std::string m_callbackName;
95 template<typename ... Args>
96 class SmartConnection : public SmartConnectionBase
99 typedef void (*CbType)(IConnection* connection,
103 SmartConnection(const std::string& name,
105 EvasObjectShared* object,
107 SmartConnectionBase(name, object),
108 m_callback(callback),
112 virtual ~SmartConnection()
115 virtual void Call(void* event_info)
118 DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
126 std::tuple<Args ...> m_args;
129 template <class ThisType, class ArgType1>
130 class SmartMemberConnection1 : public SmartConnectionBase
133 typedef void (ThisType::*CbType)(IConnection* connection,
134 void* event_info, ArgType1 *arg1);
136 SmartMemberConnection1(const std::string& name,
140 EvasObjectShared* object) :
141 SmartConnectionBase(name, object),
142 m_callback(callback),
147 virtual ~SmartMemberConnection1()
150 virtual void Call(void* event_info)
152 (m_callee->*m_callback)(this, event_info, m_arg1);
161 template <class ThisType, class ArgType1, class ArgType2>
162 class SmartMemberConnection2 : public SmartConnectionBase
165 typedef void (ThisType::*CbType)(IConnection* connection,
166 void* event_info, ArgType1 *arg1,
169 SmartMemberConnection2(const std::string& name,
174 EvasObjectShared* object) :
175 SmartConnectionBase(name, object),
176 m_callback(callback),
182 virtual ~SmartMemberConnection2()
185 virtual void Call(void* event_info)
187 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
197 class EvasConnectionBase : public IConnection
200 EvasConnectionBase(Evas_Callback_Type type,
201 EvasObjectShared* object);
203 virtual void ConnectPrv();
204 virtual void DisconnectPrv();
206 Evas_Callback_Type m_callbackType;
209 template <class ArgType1>
210 class EvasConnection1 : public EvasConnectionBase
213 typedef void (*CbType)(IConnection* connection, void* event_info,
216 EvasConnection1(Evas_Callback_Type type,
219 EvasObjectShared* object) :
220 EvasConnectionBase(type, object),
221 m_callback(callback),
225 virtual ~EvasConnection1()
228 virtual void Call(void* event_info)
230 m_callback(this, event_info, m_arg1);
238 template <class ArgType1, class ArgType2>
239 class EvasConnection2 : public EvasConnectionBase
242 typedef void (*CbType)(IConnection* connection, void* event_info,
243 ArgType1 *arg1, ArgType2 *arg2);
245 EvasConnection2(Evas_Callback_Type type,
249 EvasObjectShared* object) :
250 EvasConnectionBase(type, object),
251 m_callback(callback),
256 virtual ~EvasConnection2()
259 virtual void Call(void* event_info)
261 m_callback(this, event_info, m_arg1, m_arg2);
270 template <class ThisType, class ArgType1>
271 class EvasMemberConnection1 : public EvasConnectionBase
274 typedef void (ThisType::*CbType)(IConnection* connection,
275 void* event_info, ArgType1 *arg1);
277 EvasMemberConnection1(Evas_Callback_Type type,
281 EvasObjectShared* object) :
282 EvasConnectionBase(type, object),
283 m_callback(callback),
288 virtual ~EvasMemberConnection1()
291 virtual void Call(void* event_info)
293 (m_callee->*m_callback)(this, event_info, m_arg1);
302 template <class ThisType, class ArgType1, class ArgType2>
303 class EvasMemberConnection2 : public EvasConnectionBase
306 typedef void (ThisType::*CbType)(IConnection* connection,
307 void* event_info, ArgType1* arg1,
310 EvasMemberConnection2(Evas_Callback_Type type,
315 EvasObjectShared* object) :
316 EvasConnectionBase(type, object),
317 m_callback(callback),
323 virtual ~EvasMemberConnection2()
326 virtual void Call(void* event_info)
328 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
339 explicit EvasObjectShared(Evas_Object* object);
340 void SetObject(Evas_Object* object);
343 template<typename ... Args>
344 IConnection* ConnectSmartCallback(
345 const char* callbackName,
346 typename SmartConnection<Args ...>::
351 Assert(callbackName);
353 IConnection* connection = new SmartConnection<Args ...>(
358 m_connections.insert(connection);
359 connection->ConnectPrv();
363 template <class ThisType, class ArgType1, class ArgType2>
364 IConnection* ConnectMemberSmartCallback(
365 const char* callbackName,
366 typename SmartMemberConnection2<ThisType, ArgType1,
367 ArgType2>::CbType callback,
374 Assert(callbackName);
376 IConnection* connection =
377 new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
384 m_connections.insert(connection);
385 connection->ConnectPrv();
389 template <class ThisType, class ArgType1>
390 IConnection* ConnectMemberSmartCallback(
391 const char* callbackName,
392 typename SmartMemberConnection1<ThisType,
393 ArgType1>::CbType callback,
399 Assert(callbackName);
401 IConnection* connection =
402 new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
407 m_connections.insert(connection);
408 connection->ConnectPrv();
412 template <class ArgType1, class ArgType2>
413 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
414 typename EvasConnection2<ArgType1,
421 Assert(callbackType);
423 IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
429 m_connections.insert(connection);
430 connection->ConnectPrv();
434 template <class ArgType1>
435 IConnection* ConnectEvasCallback(
436 Evas_Callback_Type callbackType,
437 typename EvasConnection1<ArgType1>::
442 Assert(callbackType);
444 IConnection* connection = new EvasConnection1<ArgType1>(
449 m_connections.insert(connection);
450 connection->ConnectPrv();
454 template <class ThisType, class ArgType1, class ArgType2>
455 IConnection* ConnectMemberEvasCallback(
456 Evas_Callback_Type callbackType,
457 typename EvasMemberConnection2<ThisType, ArgType1,
458 ArgType2>::CbType callback,
465 Assert(callbackType);
467 IConnection* connection =
468 new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
475 m_connections.insert(connection);
476 connection->ConnectPrv();
480 template <class ThisType, class ArgType1>
481 IConnection* ConnectMemberEvasCallback(
482 Evas_Callback_Type callbackType,
483 typename EvasMemberConnection1<ThisType,
484 ArgType1>::CbType callback,
490 Assert(callbackType);
492 IConnection* connection =
493 new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
498 m_connections.insert(connection);
499 connection->ConnectPrv();
503 bool DisconnectCallback(IConnection* connection);
504 void DisconnectAll();
506 static void StaticOnDelEvent(void* data,
511 IConnectionsSet m_connections;
512 Evas_Object* m_object;
517 explicit EvasObject(Evas_Object* object);
518 EvasObject(const EvasObject& other);
521 EvasObject& operator=(const EvasObject& other);
522 EvasObject* operator=(Evas_Object* object);
524 operator Evas_Object *();
529 return m_object->GetObject() != NULL;
532 bool DisconnectCallback(IConnection* connection);
533 void DisconnectAll();
535 template <class ... Args>
536 IConnection* ConnectSmartCallback(
537 const char* callbackName,
538 typename EvasObjectShared::SmartConnection<Args ...>::CbType
543 return m_object->ConnectSmartCallback(callbackName, callback, args ...);
546 template <class ThisType, class ArgType1, class ArgType2>
547 IConnection* ConnectMemberSmartCallback(
548 const char* callbackName,
549 typename EvasObjectShared::SmartMemberConnection2<ThisType,
560 return m_object->ConnectMemberSmartCallback(callbackName,
567 template <class ThisType, class ArgType1>
568 IConnection* ConnectMemberSmartCallback(
569 const char* callbackName,
570 typename EvasObjectShared::SmartMemberConnection1<ThisType,
579 return m_object->ConnectMemberSmartCallback(callbackName,
585 template <class ArgType1, class ArgType2>
586 IConnection* ConnectEvasCallback(
587 Evas_Callback_Type callbackType,
588 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
594 return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
597 template <class ArgType1>
598 IConnection* ConnectEvasCallback(
599 Evas_Callback_Type callbackType,
600 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
605 return m_object->ConnectEvasCallback(callbackType, callback, arg1);
608 template <class ThisType, class ArgType1>
609 IConnection* ConnectMemberEvasCallback(
610 Evas_Callback_Type callbackType,
611 typename EvasObjectShared::EvasMemberConnection1<ThisType,
620 return m_object->ConnectMemberEvasCallback(callbackType,
626 template <class ThisType, class ArgType1, class ArgType2>
627 IConnection* ConnectMemberEvasCallback(
628 Evas_Callback_Type callbackType,
629 typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
639 return m_object->ConnectMemberEvasCallback(callbackType,
647 EvasObjectSharedPtr m_object;
653 #endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H