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.
17 * @file popup_controller.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @bref Implementation file for popup controller
23 #include "popup_controller.h"
25 #include <dpl/assert.h>
26 #include <dpl/log/log.h>
27 #include <dpl/singleton_impl.h>
29 IMPLEMENT_SINGLETON(Wrt::Popup::Renderer::PopupController)
35 void CtrlPopup::SetTitle(const std::string &title)
38 m_popup->SetTitle(title);
41 void CtrlPopup::Append(PopupObject::IPopupObject *object)
44 m_popup->Append(object);
47 CtrlPopup::CtrlPopup(IPopupPtr popup) :
54 CtrlPopup::~CtrlPopup()
58 void CtrlPopup::EmitAnswer(const AnswerCallbackData & answer)
60 AnswerCallbackData l_answer = answer;
61 PopupAnswerEvent event(shared_from_this(), m_callback, l_answer);
62 DPL::Event::EventSupport<PopupAnswerEvent>::EmitEvent(event);
65 PopupController::PopupController() : m_canvas(NULL)
69 CtrlPopupPtr PopupController::CreatePopup() const
72 new CtrlPopup(PopupManagerSingleton::Instance().CreatePopup()));
75 void PopupController::OnEventReceived(const ShowPopupEventShort& event)
77 CtrlPopupPtr popup = event.GetArg0();
78 popup->m_callback = event.GetArg1();
80 //pass canvas from controller to manager
81 //canvas is not passed earlier because value wasn't set properly
82 PopupManagerSingleton::Instance().setExternalCanvas(getExternalCanvas());
84 PopupManagerSingleton::Instance().RunAsyncWithArgType(
86 &PopupController::StaticOnAnswerReceived,
87 new CtrlPopupPtr(popup));
90 void PopupController::StaticOnAnswerReceived(const AnswerCallbackData & answer,
93 Assert(popup != NULL);
94 (*popup)->EmitAnswer(answer);
95 delete popup; // Just SharedPtr is destroyed, not the popup itself
98 void PopupControllerUser::OnEventReceived(const PopupAnswerEvent& event)
100 //Here we are in a proper context to call the callback
101 PopupAnswerCallback answerCall = event.GetArg1();
102 AnswerCallbackData answer = event.GetArg2();
103 answerCall.Call(answer);
104 event.GetArg0()->DPL::Event::EventSupport<PopupAnswerEvent>::RemoveListener(this);
107 void PopupControllerUser::ListenForAnswer(CtrlPopupPtr popup)
109 popup->DPL::Event::EventSupport<PopupAnswerEvent>::AddListener(this);