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_manager.h
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @brief This is popup_manager declaration file
23 #ifndef WRT_SRC_POPUP_POPUP_MANAGER_H_
24 #define WRT_SRC_POPUP_POPUP_MANAGER_H_
26 #include <dpl/assert.h>
27 #include <dpl/shared_ptr.h>
28 #include <dpl/noncopyable.h>
29 #include <dpl/singleton.h>
30 #include <dpl/optional.h>
31 #include <dpl/popup/popup.h>
32 #include <dpl/popup/popup_renderer.h>
33 #include <dpl/log/log.h>
38 class PopupManager : DPL::Noncopyable
40 template <class ArgType>
41 struct TemplatedPopupCallback
43 typedef void (*Type)(const AnswerCallbackData& answer, ArgType* data);
47 PopupManager() : m_initialized(false) {}
51 LogError("Destroyed without Deinitialize");
54 void Initialize (PopupRendererPtr creator);
56 void SetPopupRenderer (PopupRendererPtr creator);
57 IPopupPtr CreatePopup();
59 template <class ArgType>
60 void RunAsyncWithArgType(IPopupPtr popup,
61 typename TemplatedPopupCallback<ArgType>::Type callback,
65 WrapCbAndArg<ArgType>* wrapped =
66 new WrapCbAndArg<ArgType>(callback, argument);
67 popup->Show(&CallbackArgTypeTranslator<ArgType>, wrapped);
70 void Show(IPopupPtr popup,
71 IPopup::PopupCallbackType callback,
74 popup->Show(callback, userdata);
77 void setExternalCanvas(void* externalCanvas)
79 Assert(m_initialized && "Manger should be initialized");
80 m_popupRenderer->setExternalCanvas(externalCanvas);
84 template <class ArgType>
87 WrapCbAndArg(typename TemplatedPopupCallback<ArgType>::Type cb,
94 typename TemplatedPopupCallback<ArgType>::Type callback;
98 template <class ArgType>
99 static void CallbackArgTypeTranslator(const AnswerCallbackData & answer,
102 WrapCbAndArg<ArgType>* wrapped =
103 static_cast< WrapCbAndArg<ArgType>* >(data);
104 wrapped->callback(answer, wrapped->argument);
109 PopupRendererPtr m_popupRenderer;
112 typedef DPL::Singleton<Popup::PopupManager> PopupManagerSingleton;
117 #endif //WRT_SRC_POPUP_POPUP_MANAGER_H_