#
PKG_CHECK_MODULES(WRT_POPUP_DEPS
+ ecore-x
dpl-efl
dpl-event-efl
- dpl-popup-efl
REQUIRED
)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/renderer
${WRT_POPUP_DEPS_INCLUDE_DIRS}
${WRT_POPUP_COMMON_DIR}
)
wrt-popup.cpp
YesNoPopup.cpp
InfoPopup.cpp
+ renderer/evas_object.cpp
+ renderer/popup_controller.cpp
+ renderer/popup_manager.cpp
+ renderer/popup_renderer.cpp
)
ADD_EXECUTABLE(${TARGET_POPUP_WRT}
#include "InfoPopup.h"
#include <memory>
#include <string.h>
-#include <dpl/popup/popup_manager.h>
-#include <dpl/popup/popup.h>
+#include "popup_manager.h"
+#include "popup.h"
#include "PopupSerializer.h"
namespace Wrt {
namespace Popup {
-using namespace DPL::Popup;
-
void InfoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
{
LogDebug("Entered");
m_parent = parent;
- CtrlPopupPtr popup = PopupControllerSingleton::Instance().CreatePopup();
+ Renderer::CtrlPopupPtr popup =
+ Renderer::PopupControllerSingleton::Instance().CreatePopup();
popup->SetTitle(title);
- popup->Append(new PopupObject::Label(message));
+ popup->Append(new Renderer::PopupObject::Label(message));
- popup->Append(new PopupObject::Button(button, 0));
+ popup->Append(new Renderer::PopupObject::Button(button, 0));
ListenForAnswer(popup);
- ShowPopupEventShort event(popup,
- MakeAnswerCallback(
- this,
- &InfoPopup::responseCallback));
+ Renderer::ShowPopupEventShort event(popup,
+ MakeAnswerCallback(
+ this,
+ &InfoPopup::responseCallback));
- CONTROLLER_POST_EVENT(PopupController,
+ CONTROLLER_POST_EVENT(Renderer::PopupController,
event);
LogDebug("Exited");
return;
}
-void InfoPopup::responseCallback(const DPL::Popup::AnswerCallbackData &answer)
+void InfoPopup::responseCallback(const Renderer::AnswerCallbackData &answer)
{
DPL::BinaryQueue retValue;
PopupSerializer::appendArg(answer.buttonAnswer, retValue);
private:
- void responseCallback(const DPL::Popup::AnswerCallbackData &answer);
+ void responseCallback(const Renderer::AnswerCallbackData &answer);
WrtPopup* m_parent;
};
#include "YesNoPopup.h"
#include <memory>
#include <string.h>
-#include <dpl/popup/popup_manager.h>
+#include "popup_manager.h"
#include "PopupSerializer.h"
namespace {
namespace Wrt {
namespace Popup {
-using namespace DPL::Popup;
-
void YesNoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
{
LogDebug("Entered");
m_parent = parent;
- CtrlPopupPtr popup = PopupControllerSingleton::Instance().CreatePopup();
+ Renderer::CtrlPopupPtr popup =
+ Renderer::PopupControllerSingleton::Instance().CreatePopup();
popup->SetTitle(title);
- popup->Append(new PopupObject::Label(message));
+ popup->Append(new Renderer::PopupObject::Label(message));
- popup->Append(new PopupObject::Button(YES_LABEL, POPUP_YES_VALUE));
- popup->Append(new PopupObject::Button(NO_LABEL, POPUP_NO_VALUE));
+ popup->Append(new Renderer::PopupObject::Button(YES_LABEL, POPUP_YES_VALUE));
+ popup->Append(new Renderer::PopupObject::Button(NO_LABEL, POPUP_NO_VALUE));
ListenForAnswer(popup);
- ShowPopupEventShort event(popup,
- MakeAnswerCallback(
- this,
- &YesNoPopup::responseCallback));
+ Renderer::ShowPopupEventShort event(popup,
+ MakeAnswerCallback(
+ this,
+ &YesNoPopup::responseCallback));
- CONTROLLER_POST_EVENT(PopupController,
+ CONTROLLER_POST_EVENT(Renderer::PopupController,
event);
LogDebug("Exited");
return;
}
-void YesNoPopup::responseCallback(const DPL::Popup::AnswerCallbackData &answer)
+void YesNoPopup::responseCallback(const Renderer::AnswerCallbackData &answer)
{
bool result = (POPUP_YES_VALUE == answer.buttonAnswer);
DPL::BinaryQueue retValue;
private:
- void responseCallback(const DPL::Popup::AnswerCallbackData &answer);
+ void responseCallback(const Renderer::AnswerCallbackData &answer);
WrtPopup* m_parent;
};
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file evas_object.cpp
+ * @author Lukasz Wrzosek (l.wrzosel@samsung.com)
+ * @version 1.0
+ * @brief This file is the implementation for Evas_Object wrapper from Efl.
+ */
+
+#include "evas_object.h"
+#include <stddef.h>
+#include <dpl/foreach.h>
+
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+Evas_Object* EvasObject::IConnection::GetEvasObject()
+{
+ return m_object->GetObject();
+}
+
+void EvasObject::IConnection::Disconnect()
+{
+ m_object->DisconnectCallback(this);
+}
+
+EvasObject::IConnection::IConnection(EvasObject::EvasObjectShared* object) :
+ m_object(object)
+{
+}
+
+void EvasObject::IConnection::SmartCallbackWrapper(void* data,
+ Evas_Object* /*object*/,
+ void* event_info)
+{
+ Assert(data);
+ IConnection* Calle = static_cast<IConnection*>(data);
+ Calle->Call(event_info);
+}
+
+void EvasObject::IConnection::EvasCallbackWrapper(void* data,
+ Evas* /*evas*/,
+ Evas_Object* /*object*/,
+ void* event_info)
+{
+ Assert(data);
+ IConnection* Calle = static_cast<IConnection*>(data);
+ Calle->Call(event_info);
+}
+
+Evas_Object* EvasObject::EvasObjectShared::GetObject()
+{
+ return m_object;
+}
+
+EvasObject::EvasObjectShared::SmartConnectionBase::SmartConnectionBase(
+ const std::string& name,
+ EvasObject::EvasObjectShared* object) :
+ IConnection(object),
+ m_callbackName(name)
+{
+}
+
+void EvasObject::EvasObjectShared::SmartConnectionBase::ConnectPrv()
+{
+ evas_object_smart_callback_add(GetEvasObject(),
+ m_callbackName.c_str(),
+ &IConnection::SmartCallbackWrapper, this);
+}
+
+void EvasObject::EvasObjectShared::SmartConnectionBase::DisconnectPrv()
+{
+ evas_object_smart_callback_del(GetEvasObject(),
+ m_callbackName.c_str(),
+ &IConnection::SmartCallbackWrapper);
+}
+
+EvasObject::EvasObjectShared::EvasConnectionBase::EvasConnectionBase(
+ Evas_Callback_Type type,
+ EvasObject::EvasObjectShared* object) :
+ IConnection(object),
+ m_callbackType(type)
+{
+}
+
+void EvasObject::EvasObjectShared::EvasConnectionBase::ConnectPrv()
+{
+ evas_object_event_callback_add(
+ GetEvasObject(), m_callbackType, &IConnection::EvasCallbackWrapper,
+ this);
+}
+
+void EvasObject::EvasObjectShared::EvasConnectionBase::DisconnectPrv()
+{
+ evas_object_event_callback_del_full(
+ GetEvasObject(), m_callbackType, &IConnection::EvasCallbackWrapper,
+ this);
+}
+
+EvasObject::EvasObjectShared::EvasObjectShared() :
+ m_object(NULL)
+{
+}
+
+EvasObject::EvasObjectShared::EvasObjectShared(Evas_Object* object) :
+ m_object(object)
+{
+ Assert(m_object);
+ evas_object_event_callback_add(m_object,
+ EVAS_CALLBACK_DEL,
+ &StaticOnDelEvent,
+ this);
+}
+
+void EvasObject::EvasObjectShared::SetObject(Evas_Object* object)
+{
+ Assert(m_object == NULL);
+ Assert(object != NULL);
+ m_object = object;
+ evas_object_event_callback_add(m_object,
+ EVAS_CALLBACK_DEL,
+ &StaticOnDelEvent,
+ this);
+}
+
+EvasObject::EvasObjectShared::~EvasObjectShared()
+{
+ if (m_object) {
+ DisconnectAll();
+ evas_object_event_callback_del(m_object,
+ EVAS_CALLBACK_DEL,
+ &StaticOnDelEvent);
+ m_object = NULL;
+ }
+}
+
+bool EvasObject::EvasObjectShared::DisconnectCallback(IConnection* connection)
+{
+ IConnectionsSet::iterator it = m_connections.find(connection);
+ if (it != m_connections.end()) {
+ (*it)->DisconnectPrv();
+ delete connection;
+ m_connections.erase(it);
+ return true;
+ }
+ return false;
+}
+
+void EvasObject::EvasObjectShared::DisconnectAll()
+{
+ FOREACH(it, m_connections)
+ {
+ (*it)->DisconnectPrv();
+ delete *it;
+ }
+ m_connections.clear();
+}
+
+void EvasObject::EvasObjectShared::StaticOnDelEvent(void* data,
+ Evas* /*e*/,
+ Evas_Object* /*o*/,
+ void* /*ev*/)
+{
+ Assert(data);
+ EvasObjectShared* This = static_cast<EvasObjectShared*>(data);
+ if (This->m_object) {
+ evas_object_event_callback_del(This->m_object,
+ EVAS_CALLBACK_DEL,
+ &StaticOnDelEvent);
+ This->DisconnectAll();
+ This->m_object = NULL;
+ }
+}
+
+EvasObject::EvasObject() :
+ m_object(new EvasObjectShared())
+{
+}
+
+EvasObject::EvasObject(Evas_Object* object) :
+ m_object(new EvasObjectShared(object))
+{
+}
+
+EvasObject::EvasObject(const EvasObject& other) :
+ m_object(other.m_object)
+{
+}
+
+//this destructor must be here to let pimpl with shared_ptr work without warning
+EvasObject::~EvasObject()
+{
+}
+
+EvasObject& EvasObject::operator=(const EvasObject& other)
+{
+ Assert(m_object);
+ m_object = other.m_object;
+ return *this;
+}
+
+EvasObject* EvasObject::operator=(Evas_Object* object)
+{
+ Assert(m_object);
+ m_object->SetObject(object);
+ return this;
+}
+
+bool EvasObject::DisconnectCallback(IConnection* connection)
+{
+ Assert(m_object);
+ return m_object->DisconnectCallback(connection);
+}
+
+void EvasObject::DisconnectAll()
+{
+ Assert(m_object);
+ m_object->DisconnectAll();
+}
+
+EvasObject::operator Evas_Object *()
+{
+ Assert(m_object);
+ return m_object->GetObject();
+}
+
+}
+} // namespace DPL
+} // namespace Popup
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file evas_object.h
+ * @author Lukasz Wrzosek (l.wrzosel@samsung.com)
+ * @version 1.0
+ * @brief This file is the header for Evas_Object wrapper from Efl.
+ */
+
+#ifndef WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+#define WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+
+#include <Evas.h>
+#include <dpl/noncopyable.h>
+#include <dpl/framework_efl.h>
+#include <dpl/assert.h>
+#include <dpl/foreach.h>
+#include <dpl/apply.h>
+#include <set>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <memory>
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class EvasObject
+{
+ class EvasObjectShared;
+ typedef std::shared_ptr<EvasObjectShared> EvasObjectSharedPtr;
+
+ public:
+ class IConnection
+ {
+ public:
+ Evas_Object* GetEvasObject();
+ void Disconnect();
+
+ private:
+ IConnection(EvasObjectShared* object);
+ virtual ~IConnection()
+ {
+ }
+ virtual void Call(void* /*event_info*/) = 0;
+
+ static void SmartCallbackWrapper(void* data,
+ Evas_Object* /*object*/,
+ void* event_info);
+ static void EvasCallbackWrapper(void* data,
+ Evas* /*evas*/,
+ Evas_Object* /*object*/,
+ void* event_info);
+
+ virtual void ConnectPrv() = 0;
+ virtual void DisconnectPrv() = 0;
+
+ friend class EvasObjectShared;
+
+ EvasObjectShared* m_object;
+ };
+
+ private:
+ class EvasObjectShared : DPL::Noncopyable
+ {
+ public:
+ friend class IConnection;
+ Evas_Object* GetObject();
+
+ typedef std::set<IConnection*> IConnectionsSet;
+
+ class SmartConnectionBase : public IConnection
+ {
+ public:
+ SmartConnectionBase(const std::string& name,
+ EvasObjectShared* object);
+
+ virtual void ConnectPrv();
+ virtual void DisconnectPrv();
+ std::string m_callbackName;
+ };
+
+ template<typename ... Args>
+ class SmartConnection : public SmartConnectionBase
+ {
+ public:
+ typedef void (*CbType)(IConnection* connection,
+ void* event_info,
+ Args ... args);
+
+ SmartConnection(const std::string& name,
+ CbType callback,
+ EvasObjectShared* object,
+ Args ... args) :
+ SmartConnectionBase(name, object),
+ m_callback(callback),
+ m_args(args ...)
+ {
+ }
+
+ virtual ~SmartConnection()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ DPL::Apply<void,
+ DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
+ m_args,
+ this,
+ event_info);
+ }
+
+ private:
+ CbType m_callback;
+ std::tuple<Args ...> m_args;
+ };
+
+ template <class ThisType, class ArgType1>
+ class SmartMemberConnection1 : public SmartConnectionBase
+ {
+ public:
+ typedef void (ThisType::*CbType)(IConnection* connection,
+ void* event_info, ArgType1 *arg1);
+
+ SmartMemberConnection1(const std::string& name,
+ CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ EvasObjectShared* object) :
+ SmartConnectionBase(name, object),
+ m_callback(callback),
+ m_callee(callee),
+ m_arg1(arg1)
+ {
+ }
+
+ virtual ~SmartMemberConnection1()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ (m_callee->*m_callback)(this, event_info, m_arg1);
+ }
+
+ private:
+ CbType m_callback;
+ ThisType* m_callee;
+ ArgType1* m_arg1;
+ };
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ class SmartMemberConnection2 : public SmartConnectionBase
+ {
+ public:
+ typedef void (ThisType::*CbType)(IConnection* connection,
+ void* event_info, ArgType1 *arg1,
+ ArgType2* arg2);
+
+ SmartMemberConnection2(const std::string& name,
+ CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2,
+ EvasObjectShared* object) :
+ SmartConnectionBase(name, object),
+ m_callback(callback),
+ m_callee(callee),
+ m_arg1(arg1),
+ m_arg2(arg2)
+ {
+ }
+
+ virtual ~SmartMemberConnection2()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
+ }
+
+ private:
+ CbType m_callback;
+ ThisType* m_callee;
+ ArgType1* m_arg1;
+ ArgType2* m_arg2;
+ };
+
+ class EvasConnectionBase : public IConnection
+ {
+ public:
+ EvasConnectionBase(Evas_Callback_Type type,
+ EvasObjectShared* object);
+
+ virtual void ConnectPrv();
+ virtual void DisconnectPrv();
+
+ Evas_Callback_Type m_callbackType;
+ };
+
+ template <class ArgType1>
+ class EvasConnection1 : public EvasConnectionBase
+ {
+ public:
+ typedef void (*CbType)(IConnection* connection, void* event_info,
+ ArgType1 *arg1);
+
+ EvasConnection1(Evas_Callback_Type type,
+ CbType callback,
+ ArgType1* arg1,
+ EvasObjectShared* object) :
+ EvasConnectionBase(type, object),
+ m_callback(callback),
+ m_arg1(arg1)
+ {
+ }
+
+ virtual ~EvasConnection1()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ m_callback(this, event_info, m_arg1);
+ }
+
+ private:
+ CbType m_callback;
+ ArgType1* m_arg1;
+ };
+
+ template <class ArgType1, class ArgType2>
+ class EvasConnection2 : public EvasConnectionBase
+ {
+ public:
+ typedef void (*CbType)(IConnection* connection, void* event_info,
+ ArgType1 *arg1, ArgType2 *arg2);
+
+ EvasConnection2(Evas_Callback_Type type,
+ CbType callback,
+ ArgType1* arg1,
+ ArgType2* arg2,
+ EvasObjectShared* object) :
+ EvasConnectionBase(type, object),
+ m_callback(callback),
+ m_arg1(arg1),
+ m_arg2(arg2)
+ {
+ }
+
+ virtual ~EvasConnection2()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ m_callback(this, event_info, m_arg1, m_arg2);
+ }
+
+ private:
+ CbType m_callback;
+ ArgType1* m_arg1;
+ ArgType2* m_arg2;
+ };
+
+ template <class ThisType, class ArgType1>
+ class EvasMemberConnection1 : public EvasConnectionBase
+ {
+ public:
+ typedef void (ThisType::*CbType)(IConnection* connection,
+ void* event_info, ArgType1 *arg1);
+
+ EvasMemberConnection1(Evas_Callback_Type type,
+ CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ EvasObjectShared* object) :
+ EvasConnectionBase(type, object),
+ m_callback(callback),
+ m_callee(callee),
+ m_arg1(arg1)
+ {
+ }
+
+ virtual ~EvasMemberConnection1()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ (m_callee->*m_callback)(this, event_info, m_arg1);
+ }
+
+ private:
+ CbType m_callback;
+ ThisType* m_callee;
+ ArgType1* m_arg1;
+ };
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ class EvasMemberConnection2 : public EvasConnectionBase
+ {
+ public:
+ typedef void (ThisType::*CbType)(IConnection* connection,
+ void* event_info, ArgType1* arg1,
+ ArgType2* arg2);
+
+ EvasMemberConnection2(Evas_Callback_Type type,
+ CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2,
+ EvasObjectShared* object) :
+ EvasConnectionBase(type, object),
+ m_callback(callback),
+ m_callee(callee),
+ m_arg1(arg1),
+ m_arg2(arg2)
+ {
+ }
+
+ virtual ~EvasMemberConnection2()
+ {
+ }
+
+ virtual void Call(void* event_info)
+ {
+ (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
+ }
+
+ private:
+ CbType m_callback;
+ ThisType* m_callee;
+ ArgType1* m_arg1;
+ ArgType2* m_arg2;
+ };
+
+ EvasObjectShared();
+ explicit EvasObjectShared(Evas_Object* object);
+ void SetObject(Evas_Object* object);
+ ~EvasObjectShared();
+
+ template<typename ... Args>
+ IConnection* ConnectSmartCallback(const char* callbackName,
+ typename SmartConnection<Args ...>::CbType callback,
+ Args ... args)
+ {
+ Assert(m_object);
+ Assert(callbackName);
+ Assert(callback);
+ IConnection* connection = new SmartConnection<Args ...>(
+ callbackName,
+ callback,
+ this,
+ args ...);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ IConnection* ConnectMemberSmartCallback(
+ const char* callbackName,
+ typename SmartMemberConnection2<ThisType, ArgType1,
+ ArgType2>::CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callbackName);
+ Assert(callback);
+ IConnection* connection =
+ new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
+ callbackName,
+ callback,
+ callee,
+ arg1,
+ arg2,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ThisType, class ArgType1>
+ IConnection* ConnectMemberSmartCallback(
+ const char* callbackName,
+ typename SmartMemberConnection1<ThisType,
+ ArgType1>::CbType callback,
+ ThisType* callee,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callbackName);
+ Assert(callback);
+ IConnection* connection =
+ new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
+ callback,
+ callee,
+ arg1,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ArgType1, class ArgType2>
+ IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
+ typename EvasConnection2<ArgType1, ArgType2>::CbType callback,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ Assert(callbackType);
+ Assert(callback);
+ IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
+ callbackType,
+ callback,
+ arg1,
+ arg2,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ArgType1>
+ IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
+ typename EvasConnection1<ArgType1>::CbType callback,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ Assert(callbackType);
+ Assert(callback);
+ IConnection* connection = new EvasConnection1<ArgType1>(
+ callbackType,
+ callback,
+ arg1,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ IConnection* ConnectMemberEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasMemberConnection2<ThisType, ArgType1,
+ ArgType2>::CbType callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callbackType);
+ Assert(callback);
+ IConnection* connection =
+ new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
+ callbackType,
+ callback,
+ callee,
+ arg1,
+ arg2,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ template <class ThisType, class ArgType1>
+ IConnection* ConnectMemberEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasMemberConnection1<ThisType,
+ ArgType1>::CbType callback,
+ ThisType* callee,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callbackType);
+ Assert(callback);
+ IConnection* connection =
+ new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
+ callback,
+ callee,
+ arg1,
+ this);
+ m_connections.insert(connection);
+ connection->ConnectPrv();
+ return connection;
+ }
+
+ bool DisconnectCallback(IConnection* connection);
+ void DisconnectAll();
+
+ static void StaticOnDelEvent(void* data,
+ Evas* /*e*/,
+ Evas_Object* /*o*/,
+ void* /*ev*/);
+
+ IConnectionsSet m_connections;
+ Evas_Object* m_object;
+ };
+
+ public:
+ EvasObject();
+ explicit EvasObject(Evas_Object* object);
+ EvasObject(const EvasObject& other);
+ ~EvasObject();
+
+ EvasObject& operator=(const EvasObject& other);
+ EvasObject* operator=(Evas_Object* object);
+
+ operator Evas_Object *();
+
+ bool IsValid() const
+ {
+ Assert(m_object);
+ return m_object->GetObject() != NULL;
+ }
+
+ bool DisconnectCallback(IConnection* connection);
+ void DisconnectAll();
+
+ template <class ... Args>
+ IConnection* ConnectSmartCallback(
+ const char* callbackName,
+ typename EvasObjectShared::SmartConnection<Args ...>::CbType
+ callback,
+ Args ... args)
+ {
+ Assert(m_object);
+ return m_object->ConnectSmartCallback(callbackName, callback, args ...);
+ }
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ IConnection* ConnectMemberSmartCallback(
+ const char* callbackName,
+ typename EvasObjectShared::SmartMemberConnection2<ThisType,
+ ArgType1,
+ ArgType2>::CbType
+ callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callback);
+ return m_object->ConnectMemberSmartCallback(callbackName,
+ callback,
+ callee,
+ arg1,
+ arg2);
+ }
+
+ template <class ThisType, class ArgType1>
+ IConnection* ConnectMemberSmartCallback(
+ const char* callbackName,
+ typename EvasObjectShared::SmartMemberConnection1<ThisType,
+ ArgType1>::CbType
+ callback,
+ ThisType* callee,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callback);
+ return m_object->ConnectMemberSmartCallback(callbackName,
+ callback,
+ callee,
+ arg1);
+ }
+
+ template <class ArgType1, class ArgType2>
+ IConnection* ConnectEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
+ callback,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
+ }
+
+ template <class ArgType1>
+ IConnection* ConnectEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
+ callback,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ return m_object->ConnectEvasCallback(callbackType, callback, arg1);
+ }
+
+ template <class ThisType, class ArgType1>
+ IConnection* ConnectMemberEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasObjectShared::EvasMemberConnection1<ThisType,
+ ArgType1>::CbType
+ callback,
+ ThisType* callee,
+ ArgType1* arg1)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callback);
+ return m_object->ConnectMemberEvasCallback(callbackType,
+ callback,
+ callee,
+ arg1);
+ }
+
+ template <class ThisType, class ArgType1, class ArgType2>
+ IConnection* ConnectMemberEvasCallback(
+ Evas_Callback_Type callbackType,
+ typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
+ ArgType2>::CbType
+ callback,
+ ThisType* callee,
+ ArgType1* arg1,
+ ArgType2* arg2)
+ {
+ Assert(m_object);
+ Assert(callee);
+ Assert(callback);
+ return m_object->ConnectMemberEvasCallback(callbackType,
+ callback,
+ callee,
+ arg1,
+ arg2);
+ }
+
+ private:
+ EvasObjectSharedPtr m_object;
+};
+
+}
+}//namespace
+}//namespace
+
+
+#endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup.h
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief This is popup inteface declaration
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_H_
+#define WRT_SRC_POPUP_POPUP_H_
+
+#include <memory>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <string>
+#include <dpl/optional.h>
+#include "popup_object.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+struct AnswerCallbackData
+{
+ int buttonAnswer;
+ DPL::Optional<std::string> password;
+ bool chackState;
+};
+
+class PopupManager;
+class IPopup;
+typedef std::shared_ptr<IPopup> IPopupPtr;
+
+class IPopup : public std::enable_shared_from_this<IPopup>
+{
+ public:
+ virtual void SetTitle(const std::string &title) = 0;
+ /*The object is deleted automatically after rendered */
+ virtual void Append(PopupObject::IPopupObject *object) = 0;
+
+ protected:
+ typedef void (*PopupCallbackType)(const AnswerCallbackData& answer,
+ void *data);
+ virtual void Show(PopupCallbackType callback,
+ void* data) = 0;
+ virtual ~IPopup()
+ {
+ }
+
+ private:
+ friend class PopupManager;
+ friend class std::shared_ptr<IPopup>;
+};
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_H_
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/**
+ * @file popup_controller.cpp
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @bref Implementation file for popup controller
+ */
+
+#include "popup_controller.h"
+#include <stddef.h>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(Wrt::Popup::Renderer::PopupController)
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+void CtrlPopup::SetTitle(const std::string &title)
+{
+ Assert(m_popup);
+ m_popup->SetTitle(title);
+}
+
+void CtrlPopup::Append(PopupObject::IPopupObject *object)
+{
+ Assert(m_popup);
+ m_popup->Append(object);
+}
+
+CtrlPopup::CtrlPopup(IPopupPtr popup) :
+ m_popup(popup),
+ m_callback()
+{
+ Assert(m_popup);
+}
+
+CtrlPopup::~CtrlPopup()
+{
+}
+
+void CtrlPopup::EmitAnswer(const AnswerCallbackData & answer)
+{
+ AnswerCallbackData l_answer = answer;
+ PopupAnswerEvent event(shared_from_this(), m_callback, l_answer);
+ DPL::Event::EventSupport<PopupAnswerEvent>::EmitEvent(event);
+}
+
+PopupController::PopupController() : m_canvas(NULL)
+{
+}
+
+CtrlPopupPtr PopupController::CreatePopup() const
+{
+ return CtrlPopupPtr(
+ new CtrlPopup(PopupManagerSingleton::Instance().CreatePopup()));
+}
+
+void PopupController::OnEventReceived(const ShowPopupEventShort& event)
+{
+ CtrlPopupPtr popup = event.GetArg0();
+ popup->m_callback = event.GetArg1();
+
+ //pass canvas from controller to manager
+ //canvas is not passed earlier because value wasn't set properly
+ PopupManagerSingleton::Instance().setExternalCanvas(getExternalCanvas());
+
+ PopupManagerSingleton::Instance().RunAsyncWithArgType(
+ popup->m_popup,
+ &PopupController::StaticOnAnswerReceived,
+ new CtrlPopupPtr(popup));
+}
+
+void PopupController::StaticOnAnswerReceived(const AnswerCallbackData & answer,
+ CtrlPopupPtr* popup)
+{
+ Assert(popup != NULL);
+ (*popup)->EmitAnswer(answer);
+ delete popup; // Just SharedPtr is destroyed, not the popup itself
+}
+
+void PopupControllerUser::OnEventReceived(const PopupAnswerEvent& event)
+{
+ //Here we are in a proper context to call the callback
+ PopupAnswerCallback answerCall = event.GetArg1();
+ AnswerCallbackData answer = event.GetArg2();
+ answerCall.Call(answer);
+ event.GetArg0()->DPL::Event::EventSupport<PopupAnswerEvent>::RemoveListener(this);
+}
+
+void PopupControllerUser::ListenForAnswer(CtrlPopupPtr popup)
+{
+ popup->DPL::Event::EventSupport<PopupAnswerEvent>::AddListener(this);
+}
+
+}
+} //namespace Popup
+} //namespace Wrt
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/**
+ * @file popup_controller.h
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @bref Header file for popup controller
+ */
+
+/**
+ * To display a popup from a given class:
+ *
+ **class ABC
+ **{
+ * void AskUser()
+ * {
+ * }
+ *
+ * void DoSomeLogicWithAnswer()
+ * {
+ * }
+ **};
+ *
+ * ... update the class to something simmilar:
+ *
+ **class ABC : Popup::PopupControllerUser
+ **{
+ * void AskUser() {
+ * using namespace Popup;
+ * CtrlPopupPtr popup =
+ * PopupControllerSingletion::Instance().CreatePopup();
+ * popup->SetTitle("Title");
+ * popup->SetContent("Content");
+ * popup->AddButton("name1", 1);
+ * popup->AddButton("name2", 2);
+ * ListenForAnswer(popup);
+ * ShowPopupEvent event(popup,
+ * MakeAnswerCallback(this,
+ * &ABC::DoSomeLogicWithAnswer));
+ * CONTROLLER_POST_EVENT(PopupController, event);
+ * }
+ *
+ * void DoSomeLogicWithAnswer(Popup::LabelId answer) {
+ * if (answer == 1)
+ * ;//name1 pressed
+ * else if (answer == 2)
+ * ;//name2 pressed
+ * }
+ **};
+ **/
+
+#ifndef WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
+#define WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
+
+#include <memory>
+#include <dpl/singleton.h>
+#include <dpl/event/controller.h>
+#include <dpl/event/event_listener.h>
+#include <dpl/generic_event.h>
+#include <dpl/mutex.h>
+#include <dpl/exception.h>
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include "popup_manager.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+typedef int LabelId;
+
+struct PopupAnswerCallback
+{
+ typedef void (PopupAnswerCallback::*MemberPtr)();
+
+ void* callee;
+ MemberPtr member;
+ void (*callTranslator)(PopupAnswerCallback* callData,
+ const AnswerCallbackData& answer);
+
+ void Call(const AnswerCallbackData& answer)
+ {
+ callTranslator(this, answer);
+ }
+};
+
+class PopupController;
+class CtrlPopup;
+
+typedef std::shared_ptr<CtrlPopup> CtrlPopupPtr;
+
+DECLARE_GENERIC_EVENT_3(PopupAnswerEvent,
+ CtrlPopupPtr,
+ PopupAnswerCallback,
+ AnswerCallbackData)
+
+DECLARE_GENERIC_EVENT_2(ShowPopupEventShort,
+ CtrlPopupPtr,
+ PopupAnswerCallback)
+
+class CtrlPopup : public DPL::Event::EventSupport<PopupAnswerEvent>,
+ public std::enable_shared_from_this<CtrlPopup>
+{
+ public:
+ void SetTitle(const std::string &title);
+ void Append(PopupObject::IPopupObject *object);
+
+ ~CtrlPopup();
+ private:
+ friend class PopupController;
+ friend class std::shared_ptr<CtrlPopup>;
+
+ explicit CtrlPopup(IPopupPtr popup);
+ void EmitAnswer(const AnswerCallbackData& answer);
+
+ IPopupPtr m_popup;
+ PopupAnswerCallback m_callback;
+};
+
+class PopupController :
+ public DPL::Event::Controller<DPL::TypeListDecl<ShowPopupEventShort>::Type>
+{
+ public:
+ CtrlPopupPtr CreatePopup() const;
+
+ void setExternalCanvas(void* canvas)
+ {
+ m_canvas = canvas;
+ }
+ void* getExternalCanvas() const
+ {
+ return m_canvas;
+ }
+ void* m_canvas;
+
+ protected:
+ virtual void OnEventReceived(const ShowPopupEventShort& event);
+ PopupController();
+
+ private:
+ static void StaticOnAnswerReceived(const AnswerCallbackData& answer,
+ CtrlPopupPtr* popup);
+};
+
+class PopupControllerUser : DPL::Event::EventListener<PopupAnswerEvent>
+{
+ template <class Type>
+ struct PopupAnswerCallbackCreator
+ {
+ typedef void (Type::*MemberPtr)(const AnswerCallbackData& answer);
+ union Caster
+ {
+ MemberPtr specific;
+ PopupAnswerCallback::MemberPtr generic;
+ };
+
+ static PopupAnswerCallback Create(Type* callee,
+ MemberPtr callback)
+ {
+ PopupAnswerCallback callData;
+
+ callData.callee = callee;
+
+ Caster caster;
+ caster.specific = callback;
+ callData.member = caster.generic;
+
+ callData.callTranslator =
+ &PopupAnswerCallbackCreator::MemberCallbackTranslator;
+
+ return callData;
+ }
+
+ static void MemberCallbackTranslator(PopupAnswerCallback* callData,
+ const AnswerCallbackData& answer)
+ {
+ Type* typedThis = static_cast<Type*>(callData->callee);
+ Caster caster;
+ caster.generic = callData->member;
+ MemberPtr typedCallback = caster.specific;
+ (typedThis->*typedCallback)(answer);
+ }
+ };
+
+ protected:
+ virtual void OnEventReceived(const PopupAnswerEvent& event);
+ void ListenForAnswer(CtrlPopupPtr popup);
+
+ template <class Type>
+ PopupAnswerCallback MakeAnswerCallback(Type* This,
+ void (Type::*callback)
+ (const AnswerCallbackData &))
+ {
+ return PopupAnswerCallbackCreator<Type>::Create(This, callback);
+ }
+};
+
+typedef DPL::Singleton<PopupController> PopupControllerSingleton;
+
+}
+} //namespace Popup
+} //namespace Wrt
+
+#endif //WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup_manager.cpp
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief This is popup_manager implementation file
+ */
+
+#include "popup_manager.h"
+#include <stddef.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/singleton_impl.h>
+#include "popup.h"
+
+IMPLEMENT_SINGLETON(Wrt::Popup::Renderer::PopupManager)
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+void PopupManager::Initialize(PopupRendererPtr renderer)
+{
+ Assert(!m_initialized);
+ m_popupRenderer = renderer;
+ m_popupRenderer->Initialize();
+ m_initialized = true;
+}
+
+void PopupManager::Deinitialize()
+{
+ m_popupRenderer->Deinitialize();
+ Assert(m_initialized);
+ m_popupRenderer.reset();
+ m_initialized = false;
+}
+
+IPopupPtr PopupManager::CreatePopup()
+{
+ Assert(m_initialized);
+ return m_popupRenderer->CreatePopup();
+}
+
+}
+} // namespace Popup
+} // namespace Wrt
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup_manager.h
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief This is popup_manager declaration file
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_MANAGER_H_
+#define WRT_SRC_POPUP_POPUP_MANAGER_H_
+
+#include <memory>
+#include <dpl/assert.h>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+#include <dpl/optional.h>
+#include <dpl/log/log.h>
+#include "popup.h"
+#include "popup_renderer.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class PopupManager : DPL::Noncopyable
+{
+ template <class ArgType>
+ struct TemplatedPopupCallback
+ {
+ typedef void (*Type)(const AnswerCallbackData& answer, ArgType* data);
+ };
+
+ public:
+ PopupManager() : m_initialized(false) {}
+ ~PopupManager()
+ {
+ if (m_initialized) {
+ LogError("Destroyed without Deinitialize");
+ }
+ }
+ void Initialize (PopupRendererPtr creator);
+ void Deinitialize();
+ void SetPopupRenderer (PopupRendererPtr creator);
+ IPopupPtr CreatePopup();
+
+ template <class ArgType>
+ void RunAsyncWithArgType(IPopupPtr popup,
+ typename TemplatedPopupCallback<ArgType>::Type callback,
+ ArgType* argument)
+ {
+ Assert(callback);
+ WrapCbAndArg<ArgType>* wrapped =
+ new WrapCbAndArg<ArgType>(callback, argument);
+ popup->Show(&CallbackArgTypeTranslator<ArgType>, wrapped);
+ }
+
+ void Show(IPopupPtr popup,
+ IPopup::PopupCallbackType callback,
+ void* userdata)
+ {
+ popup->Show(callback, userdata);
+ }
+
+ void setExternalCanvas(void* externalCanvas)
+ {
+ Assert(m_initialized && "Manger should be initialized");
+ m_popupRenderer->setExternalCanvas(externalCanvas);
+ }
+
+ private:
+ template <class ArgType>
+ struct WrapCbAndArg
+ {
+ WrapCbAndArg(typename TemplatedPopupCallback<ArgType>::Type cb,
+ ArgType* arg) :
+ callback(cb),
+ argument(arg)
+ {
+ }
+
+ typename TemplatedPopupCallback<ArgType>::Type callback;
+ ArgType* argument;
+ };
+
+ template <class ArgType>
+ static void CallbackArgTypeTranslator(const AnswerCallbackData & answer,
+ void* data)
+ {
+ WrapCbAndArg<ArgType>* wrapped =
+ static_cast< WrapCbAndArg<ArgType>* >(data);
+ wrapped->callback(answer, wrapped->argument);
+ delete wrapped;
+ }
+
+ bool m_initialized;
+ PopupRendererPtr m_popupRenderer;
+};
+
+typedef DPL::Singleton<PopupManager> PopupManagerSingleton;
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_MANAGER_H_
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup_object.h
+ * @author Justyna Mejzner (j.mejzner@samsung.com)
+ * @version 1.0
+ * @brief This is declaration file of PopupObject
+ */
+
+#ifndef WRT_SRC_POPUP_POPUPOBJECT_H_
+#define WRT_SRC_POPUP_POPUPOBJECT_H_
+
+#include <dpl/foreach.h>
+
+#include <list>
+#include <string>
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+namespace PopupObject {
+class IPopupObject;
+class PopupObjectBase;
+class Button;
+class Label;
+class Check;
+
+typedef std::list<IPopupObject*> PopupObjects;
+
+enum PopupType
+{
+ BUTTON,
+ LABEL,
+ CHECK
+};
+
+class IPopupObject
+{
+ public:
+ virtual Button* asButton() = 0;
+ virtual Label* asLabel() = 0;
+ virtual Check* asCheck() = 0;
+ virtual PopupType getType() const = 0;
+ virtual ~IPopupObject()
+ {
+ }
+};
+
+class PopupObjectBase : public IPopupObject
+{
+ public:
+ virtual Button* asButton()
+ {
+ Assert("wrong type");
+ return NULL;
+ }
+ virtual Label* asLabel()
+ {
+ Assert("wrong type");
+ return NULL;
+ }
+ virtual Check* asCheck()
+ {
+ Assert("wrong type");
+ return NULL;
+ }
+
+ PopupType getType() const
+ {
+ return m_type;
+ }
+
+ protected:
+ PopupObjectBase(PopupType type) : m_type(type)
+ {
+ }
+
+ PopupType m_type;
+};
+
+class Button : public PopupObjectBase
+{
+ public:
+ Button(const std::string& label,
+ int labelId) :
+ PopupObjectBase(BUTTON),
+ m_label(label),
+ m_labelId(labelId)
+ {
+ }
+
+ Button* asButton()
+ {
+ return this;
+ }
+
+ const std::string& getLabel() const
+ {
+ return m_label;
+ }
+
+ int getLabelId() const
+ {
+ return m_labelId;
+ }
+
+ private:
+ std::string m_label;
+ int m_labelId;
+};
+
+class Label : public PopupObjectBase
+{
+ public:
+ Label(const std::string &label) :
+ PopupObjectBase(LABEL),
+ m_label(label)
+ {
+ }
+
+ Label* asLabel()
+ {
+ return this;
+ }
+
+ const std::string& getLabel() const
+ {
+ return m_label;
+ }
+
+ private:
+ std::string m_label;
+};
+
+class Check : public PopupObjectBase
+{
+ public:
+ Check(const std::string &label) :
+ PopupObjectBase(CHECK),
+ m_checkLabel(label)
+ {
+ }
+
+ Check* asCheck()
+ {
+ return this;
+ }
+
+ const std::string& getCheckLabel() const
+ {
+ return m_checkLabel;
+ }
+
+ private:
+ std::string m_checkLabel;
+};
+} /*PopupObject*/
+
+}
+}//namespace Popup
+}//namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUPOBJECT_H_
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup_renderer.cpp
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief This is efl specific implementation for PopupRenderer
+ */
+
+#include "popup_renderer.h"
+#include <stddef.h>
+#include <dpl/scoped_array.h>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/framework_efl.h>
+#include <dpl/lexical_cast.h>
+#include <queue>
+#include "popup_manager.h"
+#include "popup_manager.h"
+#include "evas_object.h"
+
+namespace Wrt {
+
+namespace {
+using namespace Popup;
+const char* EDJ_NAME = "/usr/share/edje/ace/generic_popup.edj";
+const char* POPUP_LAYOUT1 = "popup_layout1";
+const char* POPUP_LAYOUT2 = "popup_layout2";
+const char* POPUP_PART_TITLE = "title,text";
+const char* POPUP_PART_BUTTON1 = "button1";
+const char* POPUP_PART_BUTTON2 = "button2";
+const char* POPUP_PART_BUTTON3 = "button3";
+const char* BUTTON_CLICKED_CALLBACK_NAME = "clicked";
+const char* CHANGED_CALLBACK_NAME = "changed";
+const unsigned int MAX_NUMBER_OF_VERTICAL = 2;
+
+Evas_Object* create_layout_main(Evas_Object* parent, int totalV)
+{
+ Evas_Object *layout = elm_layout_add(parent);
+
+ if (totalV == 1) {
+ elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT1);
+ } else if (totalV == 2) {
+ elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT2);
+ } else {
+ Assert("popup needs define new group in the edc");
+ }
+
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ return layout;
+}
+} //namespace
+
+namespace Popup {
+namespace Renderer {
+
+class PopupRenderer::Impl
+{
+ public:
+ Impl() :
+ m_popupsToRender(),
+ m_current(),
+ m_initialized(false)
+ {
+ }
+
+ ~Impl()
+ {
+ if (m_initialized) {
+ LogError("Destroyed without Deinitialize");
+ }
+ }
+
+ void Initialize()
+ {
+ Assert(!m_initialized);
+ m_initialized = true;
+ }
+
+ void Deinitialize()
+ {
+ Assert(m_initialized);
+ m_current.reset();
+ while (!m_popupsToRender.empty()) {
+ m_popupsToRender.pop();
+ }
+ m_initialized = false;
+ }
+
+ void ButtonCallback(EvasObject::IConnection* /*connection*/,
+ void* /*event_info*/,
+ void* data)
+ {
+ LogInfo("ButtonCallback");
+ Assert(m_initialized);
+ AnswerCallbackData answerData;
+
+ answerData.buttonAnswer = reinterpret_cast<int>(data);
+ answerData.chackState = m_checkState;
+ answerData.password = m_password;
+ m_current->ForwardAnswer(answerData);
+ m_current.reset();
+
+ FOREACH(it, m_createdObjects)
+ {
+ if (it->IsValid()) {
+ evas_object_del(*it);
+ }
+ }
+ m_createdObjects.clear();
+ m_checkState = false;
+ DoRender();
+ }
+
+ void CheckCallback(EvasObject::IConnection* connection,
+ void* /*event_info*/,
+ void* /* unused */)
+ {
+ m_checkState =
+ elm_check_state_get(connection->GetEvasObject());
+ }
+
+ void Render (PopupPtr popup)
+ {
+ Assert(m_initialized);
+ m_popupsToRender.push(popup);
+ DoRender();
+ }
+
+ void DoRender(const PopupObject::Label& object,
+ EvasObject& parent,
+ EvasObject& layout,
+ int themeIndex)
+ {
+ EvasObject label(elm_label_add(parent));
+
+ elm_object_style_set(label, "popup_description/default");
+ elm_label_line_wrap_set(label, ELM_WRAP_WORD);
+ elm_object_text_set(label, object.getLabel().c_str());
+ evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
+ evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(label);
+
+ elm_object_part_content_set(
+ layout,
+ DPL::lexical_cast<std::string>(themeIndex).c_str(),
+ label);
+ m_createdObjects.push_back(label);
+ }
+
+ void DoRender(const PopupObject::Check& object,
+ EvasObject& parent,
+ EvasObject& layout,
+ int themeIndex)
+ {
+ EvasObject check(elm_check_add(parent));
+
+ evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
+ elm_object_text_set(check,
+ object.getCheckLabel().c_str());
+ elm_object_part_content_set(
+ layout,
+ DPL::lexical_cast<std::string>(themeIndex).c_str(),
+ check);
+
+ check.ConnectMemberSmartCallback(CHANGED_CALLBACK_NAME,
+ &Impl::CheckCallback,
+ this,
+ static_cast<void*>(NULL));
+ evas_object_show(check);
+ m_createdObjects.push_back(check);
+ }
+
+ void DoRender(const PopupObject::Button& object,
+ EvasObject &parent)
+ {
+ EvasObject btn(elm_button_add(parent));
+
+ elm_object_text_set(btn, object.getLabel().c_str());
+ elm_object_part_content_set(parent, POPUP_PART_BUTTON1, btn);
+ btn.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+ &Impl::ButtonCallback,
+ this,
+ reinterpret_cast<void*>(object.getLabelId()));
+ m_createdObjects.push_back(btn);
+ }
+
+ void DoRender(const PopupObject::Button& object1,
+ const PopupObject::Button& object2,
+ EvasObject &parent)
+ {
+ DoRender(object1, parent);
+
+ EvasObject btn2(elm_button_add(parent));
+
+ elm_object_text_set(btn2, object2.getLabel().c_str());
+ elm_object_part_content_set(parent, POPUP_PART_BUTTON2, btn2);
+ btn2.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+ &Impl::ButtonCallback,
+ this,
+ reinterpret_cast<void*>(object2.getLabelId()));
+ m_createdObjects.push_back(btn2);
+ }
+
+ void DoRender(const PopupObject::Button& object1,
+ const PopupObject::Button& object2,
+ const PopupObject::Button& object3,
+ EvasObject &parent)
+ {
+ DoRender(object1, object2, parent);
+
+ EvasObject btn3(elm_button_add(parent));
+
+ elm_object_text_set(btn3, object3.getLabel().c_str());
+ elm_object_part_content_set(parent, POPUP_PART_BUTTON3, btn3);
+ btn3.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+ &Impl::ButtonCallback,
+ this,
+ reinterpret_cast<void*>(object3.getLabelId()));
+ m_createdObjects.push_back(btn3);
+ }
+
+ EvasObject getBaseObject()
+ {
+ if (getExternalCanvas() == NULL) {
+ LogInfo("Create old style popup");
+ EvasObject win(elm_win_add(NULL, "Popup", ELM_WIN_DIALOG_BASIC));
+ elm_win_borderless_set(win, EINA_TRUE);
+ elm_win_alpha_set(win, EINA_TRUE);
+ elm_win_raise(win);
+ {
+ int w, h, x, y;
+ ecore_x_window_geometry_get(ecore_x_window_root_first_get(),
+ &x,
+ &y,
+ &w,
+ &h);
+ evas_object_resize(win, w, h);
+ evas_object_move(win, x, y);
+ }
+ m_createdObjects.push_back(win);
+ evas_object_show(win);
+ return win;
+ } else {
+ LogInfo("Create new style popup");
+ EvasObject win(getExternalCanvas());
+ evas_object_show(win);
+ return win;
+ }
+ }
+
+ void DoRender()
+ {
+ if (!m_current && !m_popupsToRender.empty()) {
+ m_current = m_popupsToRender.front();
+ m_popupsToRender.pop();
+
+ m_themeIndexV = 0;
+
+ // preprocessing
+ std::vector<int> countPopupObjects = {0 /* PopupObject::BUTTON */,
+ 0 /* PopupObject::LABEL */,
+ 0 /* PopupObject::CHECK */};
+ FOREACH(it, m_current->GetPopupObjects()) {
+ Assert((*it)->getType() < countPopupObjects.size() &&
+ "Wrong PopupObject assigned");
+ countPopupObjects[(*it)->getType()]++;
+ }
+ int needsIndexV = countPopupObjects[PopupObject::LABEL] +
+ countPopupObjects[PopupObject::CHECK];
+
+ EvasObject win = getBaseObject();
+ EvasObject main(elm_popup_add(win));
+
+ evas_object_size_hint_weight_set(main,
+ EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ elm_object_part_text_set(main,
+ POPUP_PART_TITLE,
+ m_current->GetTitle().c_str());
+
+ m_createdObjects.push_back(main);
+ std::vector<PopupObject::Button> buttonObjectList;
+ EvasObject layout(create_layout_main(main, needsIndexV));
+ m_createdObjects.push_back(layout);
+
+ FOREACH(it, m_current->GetPopupObjects()) {
+ switch ((*it)->getType()) {
+ case PopupObject::BUTTON:
+ buttonObjectList.push_back(*(*it)->asButton());
+ break;
+ case PopupObject::LABEL:
+ DoRender(*(*it)->asLabel(),
+ main,
+ layout,
+ m_themeIndexV++);
+ break;
+ case PopupObject::CHECK:
+ DoRender(*(*it)->asCheck(),
+ main,
+ layout,
+ m_themeIndexV++);
+ break;
+ default:
+ Assert("incorrect type");
+ }
+ Assert(m_themeIndexV <= MAX_NUMBER_OF_VERTICAL);
+ }
+ elm_object_content_set(main,
+ layout);
+
+ // show buution
+ switch(buttonObjectList.size()) {
+ case 0:
+ LogInfo("no button");
+ break;
+ case 1:
+ DoRender(buttonObjectList.at(0),
+ main);
+ break;
+ case 2:
+ DoRender(buttonObjectList.at(0),
+ buttonObjectList.at(1),
+ main);
+ break;
+ case 3:
+ DoRender(buttonObjectList.at(0),
+ buttonObjectList.at(1),
+ buttonObjectList.at(2),
+ main);
+ break;
+ default:
+ Assert("incorrect button number");
+ break;
+ }
+
+ evas_object_show(main);
+ }
+ }
+
+ void setExternalCanvas(void* externalCanvas)
+ {
+ m_externalCanvas = static_cast<Evas_Object*>(externalCanvas);
+ }
+
+ Evas_Object* getExternalCanvas() const
+ {
+ return m_externalCanvas;
+ }
+
+ std::queue<PopupPtr> m_popupsToRender;
+ std::list<EvasObject> m_createdObjects;
+ PopupPtr m_current;
+ bool m_initialized;
+ bool m_checkState;
+ DPL::Optional<std::string> m_password;
+ unsigned int m_themeIndexV;
+
+ private:
+ Evas_Object* m_externalCanvas;
+};
+
+PopupRenderer::PopupRenderer()
+{
+ m_impl = new PopupRenderer::Impl();
+}
+
+PopupRenderer::~PopupRenderer()
+{
+ delete m_impl;
+}
+
+void PopupRenderer::Initialize()
+{
+ Assert(m_impl);
+ m_impl->Initialize();
+}
+
+void PopupRenderer::Deinitialize()
+{
+ Assert(m_impl);
+ m_impl->Deinitialize();
+}
+
+IPopupPtr PopupRenderer::CreatePopup()
+{
+ return std::static_pointer_cast<IPopup>(IPopupPtr
+ (new Popup(shared_from_this())));
+}
+
+void PopupRenderer::Render(PopupPtr popup)
+{
+ m_impl->Render(popup);
+}
+
+void PopupRenderer::setExternalCanvas(void* externalCanvas)
+{
+ m_impl->setExternalCanvas(externalCanvas);
+}
+
+}
+} // namespace Popup
+} // namespace Wrt
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+/*
+ * @file popup_renderer.h
+ * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @brief This is declaration file of PopupRenderer
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_RENDERER_H_
+#define WRT_SRC_POPUP_POPUP_RENDERER_H_
+
+#include <map>
+#include <string>
+#include <memory>
+
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/foreach.h>
+#include "popup.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class PopupRenderer : public std::enable_shared_from_this<PopupRenderer>
+{
+ public:
+ PopupRenderer();
+ ~PopupRenderer();
+ void Initialize();
+ void Deinitialize();
+ IPopupPtr CreatePopup();
+ virtual void setExternalCanvas(void* externalCanvas);
+ protected:
+ class Popup;
+ typedef std::shared_ptr<Popup> PopupPtr;
+
+ class Popup : public IPopup
+ {
+ public:
+ typedef std::map<int, std::string> ButtonMap;
+ virtual void SetTitle(const std::string &title)
+ {
+ LogDebug(title);
+ Assert(m_title.empty());
+ m_title = title;
+ }
+
+ virtual void Append(PopupObject::IPopupObject *object)
+ {
+ m_popupObjectList.push_back(object);
+ }
+
+ virtual void Show(IPopup::PopupCallbackType callback,
+ void* data)
+ {
+ Assert(callback);
+ m_data = data;
+ m_callback = callback;
+ m_renderer->Render(std::static_pointer_cast<Popup>(shared_from_this()));
+ }
+
+ const std::string& GetTitle() const
+ {
+ return m_title;
+ }
+
+ PopupObject::PopupObjects& GetPopupObjects()
+ {
+ return m_popupObjectList;
+ }
+
+ virtual ~Popup()
+ {
+ FOREACH(it, m_popupObjectList) {
+ delete *it;
+ }
+ }
+
+ private:
+ friend class PopupRenderer;
+ friend class std::shared_ptr<Popup>;
+ friend class PopupObjectTheme;
+
+ Popup(std::shared_ptr<PopupRenderer> renderer) : m_renderer(renderer)
+ {
+ }
+
+ void ForwardAnswer(const AnswerCallbackData & answer) const
+ {
+ m_callback(answer, m_data);
+ }
+
+ std::string m_title;
+ void* m_data;
+ IPopup::PopupCallbackType m_callback;
+ PopupObject::PopupObjects m_popupObjectList;
+ std::shared_ptr<PopupRenderer> m_renderer;
+ };
+
+ private:
+ void Render (PopupPtr popup);
+
+ class Impl;
+ Impl* m_impl;
+};
+
+typedef std::shared_ptr<PopupRenderer> PopupRendererPtr;
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_RENDERER_H_
m_pipesOpened(false)
{
Touch();
- DPL::Popup::PopupControllerSingleton::Instance().Touch();
- DPL::Popup::PopupManagerSingleton::Instance().Initialize(
- DPL::Popup::PopupRendererPtr(new DPL::Popup::PopupRenderer));
+ Renderer::PopupControllerSingleton::Instance().Touch();
+ Renderer::PopupManagerSingleton::Instance().Initialize(
+ Renderer::PopupRendererPtr(new Renderer::PopupRenderer));
LogDebug("App Created");
}
WrtPopup::~WrtPopup()
{
- DPL::Popup::PopupManagerSingleton::Instance().Deinitialize();
+ Renderer::PopupManagerSingleton::Instance().Deinitialize();
LogDebug("App Finished");
}
#include <dpl/named_output_pipe.h>
#include <dpl/waitable_handle_watch_support.h>
#include <dpl/binary_queue.h>
-#include <dpl/popup/popup_controller.h>
+#include "popup_controller.h"
namespace Wrt {
namespace Popup {
DECLARE_GENERIC_EVENT_0(QuitEvent)
class WrtPopup;
-class IPopup : public DPL::Popup::PopupControllerUser
+class IPopup : public Renderer::PopupControllerUser
{
public:
virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent) = 0;