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()
54 virtual void Call(void* /*event_info*/) = 0;
56 static void SmartCallbackWrapper(void* data,
57 Evas_Object* /*object*/,
59 static void EvasCallbackWrapper(void* data,
61 Evas_Object* /*object*/,
64 virtual void ConnectPrv() = 0;
65 virtual void DisconnectPrv() = 0;
67 friend class EvasObjectShared;
69 EvasObjectShared* m_object;
73 class EvasObjectShared : DPL::Noncopyable
76 friend class IConnection;
77 Evas_Object* GetObject();
79 typedef std::set<IConnection*> IConnectionsSet;
81 class SmartConnectionBase : public IConnection
84 SmartConnectionBase(const std::string& name,
85 EvasObjectShared* object);
87 virtual void ConnectPrv();
88 virtual void DisconnectPrv();
89 std::string m_callbackName;
92 template<typename ... Args>
93 class SmartConnection : public SmartConnectionBase
96 typedef void (*CbType)(IConnection* connection,
100 SmartConnection(const std::string& name,
102 EvasObjectShared* object,
104 SmartConnectionBase(name, object),
105 m_callback(callback),
110 virtual ~SmartConnection()
114 virtual void Call(void* event_info)
117 DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
125 std::tuple<Args ...> m_args;
128 template <class ThisType, class ArgType1>
129 class SmartMemberConnection1 : public SmartConnectionBase
132 typedef void (ThisType::*CbType)(IConnection* connection,
133 void* event_info, ArgType1 *arg1);
135 SmartMemberConnection1(const std::string& name,
139 EvasObjectShared* object) :
140 SmartConnectionBase(name, object),
141 m_callback(callback),
147 virtual ~SmartMemberConnection1()
151 virtual void Call(void* event_info)
153 (m_callee->*m_callback)(this, event_info, m_arg1);
162 template <class ThisType, class ArgType1, class ArgType2>
163 class SmartMemberConnection2 : public SmartConnectionBase
166 typedef void (ThisType::*CbType)(IConnection* connection,
167 void* event_info, ArgType1 *arg1,
170 SmartMemberConnection2(const std::string& name,
175 EvasObjectShared* object) :
176 SmartConnectionBase(name, object),
177 m_callback(callback),
184 virtual ~SmartMemberConnection2()
188 virtual void Call(void* event_info)
190 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
200 class EvasConnectionBase : public IConnection
203 EvasConnectionBase(Evas_Callback_Type type,
204 EvasObjectShared* object);
206 virtual void ConnectPrv();
207 virtual void DisconnectPrv();
209 Evas_Callback_Type m_callbackType;
212 template <class ArgType1>
213 class EvasConnection1 : public EvasConnectionBase
216 typedef void (*CbType)(IConnection* connection, void* event_info,
219 EvasConnection1(Evas_Callback_Type type,
222 EvasObjectShared* object) :
223 EvasConnectionBase(type, object),
224 m_callback(callback),
229 virtual ~EvasConnection1()
233 virtual void Call(void* event_info)
235 m_callback(this, event_info, m_arg1);
243 template <class ArgType1, class ArgType2>
244 class EvasConnection2 : public EvasConnectionBase
247 typedef void (*CbType)(IConnection* connection, void* event_info,
248 ArgType1 *arg1, ArgType2 *arg2);
250 EvasConnection2(Evas_Callback_Type type,
254 EvasObjectShared* object) :
255 EvasConnectionBase(type, object),
256 m_callback(callback),
262 virtual ~EvasConnection2()
266 virtual void Call(void* event_info)
268 m_callback(this, event_info, m_arg1, m_arg2);
277 template <class ThisType, class ArgType1>
278 class EvasMemberConnection1 : public EvasConnectionBase
281 typedef void (ThisType::*CbType)(IConnection* connection,
282 void* event_info, ArgType1 *arg1);
284 EvasMemberConnection1(Evas_Callback_Type type,
288 EvasObjectShared* object) :
289 EvasConnectionBase(type, object),
290 m_callback(callback),
296 virtual ~EvasMemberConnection1()
300 virtual void Call(void* event_info)
302 (m_callee->*m_callback)(this, event_info, m_arg1);
311 template <class ThisType, class ArgType1, class ArgType2>
312 class EvasMemberConnection2 : public EvasConnectionBase
315 typedef void (ThisType::*CbType)(IConnection* connection,
316 void* event_info, ArgType1* arg1,
319 EvasMemberConnection2(Evas_Callback_Type type,
324 EvasObjectShared* object) :
325 EvasConnectionBase(type, object),
326 m_callback(callback),
333 virtual ~EvasMemberConnection2()
337 virtual void Call(void* event_info)
339 (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
350 explicit EvasObjectShared(Evas_Object* object);
351 void SetObject(Evas_Object* object);
354 template<typename ... Args>
355 IConnection* ConnectSmartCallback(const char* callbackName,
356 typename SmartConnection<Args ...>::CbType callback,
360 Assert(callbackName);
362 IConnection* connection = new SmartConnection<Args ...>(
367 m_connections.insert(connection);
368 connection->ConnectPrv();
372 template <class ThisType, class ArgType1, class ArgType2>
373 IConnection* ConnectMemberSmartCallback(
374 const char* callbackName,
375 typename SmartMemberConnection2<ThisType, ArgType1,
376 ArgType2>::CbType callback,
383 Assert(callbackName);
385 IConnection* connection =
386 new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
393 m_connections.insert(connection);
394 connection->ConnectPrv();
398 template <class ThisType, class ArgType1>
399 IConnection* ConnectMemberSmartCallback(
400 const char* callbackName,
401 typename SmartMemberConnection1<ThisType,
402 ArgType1>::CbType callback,
408 Assert(callbackName);
410 IConnection* connection =
411 new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
416 m_connections.insert(connection);
417 connection->ConnectPrv();
421 template <class ArgType1, class ArgType2>
422 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
423 typename EvasConnection2<ArgType1, ArgType2>::CbType callback,
428 Assert(callbackType);
430 IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
436 m_connections.insert(connection);
437 connection->ConnectPrv();
441 template <class ArgType1>
442 IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
443 typename EvasConnection1<ArgType1>::CbType callback,
447 Assert(callbackType);
449 IConnection* connection = new EvasConnection1<ArgType1>(
454 m_connections.insert(connection);
455 connection->ConnectPrv();
459 template <class ThisType, class ArgType1, class ArgType2>
460 IConnection* ConnectMemberEvasCallback(
461 Evas_Callback_Type callbackType,
462 typename EvasMemberConnection2<ThisType, ArgType1,
463 ArgType2>::CbType callback,
470 Assert(callbackType);
472 IConnection* connection =
473 new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
480 m_connections.insert(connection);
481 connection->ConnectPrv();
485 template <class ThisType, class ArgType1>
486 IConnection* ConnectMemberEvasCallback(
487 Evas_Callback_Type callbackType,
488 typename EvasMemberConnection1<ThisType,
489 ArgType1>::CbType callback,
495 Assert(callbackType);
497 IConnection* connection =
498 new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
503 m_connections.insert(connection);
504 connection->ConnectPrv();
508 bool DisconnectCallback(IConnection* connection);
509 void DisconnectAll();
511 static void StaticOnDelEvent(void* data,
516 IConnectionsSet m_connections;
517 Evas_Object* m_object;
522 explicit EvasObject(Evas_Object* object);
523 EvasObject(const EvasObject& other);
526 EvasObject& operator=(const EvasObject& other);
527 EvasObject* operator=(Evas_Object* object);
529 operator Evas_Object *();
534 return m_object->GetObject() != NULL;
537 bool DisconnectCallback(IConnection* connection);
538 void DisconnectAll();
540 template <class ... Args>
541 IConnection* ConnectSmartCallback(
542 const char* callbackName,
543 typename EvasObjectShared::SmartConnection<Args ...>::CbType
548 return m_object->ConnectSmartCallback(callbackName, callback, args ...);
551 template <class ThisType, class ArgType1, class ArgType2>
552 IConnection* ConnectMemberSmartCallback(
553 const char* callbackName,
554 typename EvasObjectShared::SmartMemberConnection2<ThisType,
565 return m_object->ConnectMemberSmartCallback(callbackName,
572 template <class ThisType, class ArgType1>
573 IConnection* ConnectMemberSmartCallback(
574 const char* callbackName,
575 typename EvasObjectShared::SmartMemberConnection1<ThisType,
584 return m_object->ConnectMemberSmartCallback(callbackName,
590 template <class ArgType1, class ArgType2>
591 IConnection* ConnectEvasCallback(
592 Evas_Callback_Type callbackType,
593 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
599 return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
602 template <class ArgType1>
603 IConnection* ConnectEvasCallback(
604 Evas_Callback_Type callbackType,
605 typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
610 return m_object->ConnectEvasCallback(callbackType, callback, arg1);
613 template <class ThisType, class ArgType1>
614 IConnection* ConnectMemberEvasCallback(
615 Evas_Callback_Type callbackType,
616 typename EvasObjectShared::EvasMemberConnection1<ThisType,
625 return m_object->ConnectMemberEvasCallback(callbackType,
631 template <class ThisType, class ArgType1, class ArgType2>
632 IConnection* ConnectMemberEvasCallback(
633 Evas_Callback_Type callbackType,
634 typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
644 return m_object->ConnectMemberEvasCallback(callbackType,
652 EvasObjectSharedPtr m_object;
655 #endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H