tizen 2.4 release
[framework/web/wrt-plugins-common.git] / src / wrt-popup / wrt / popup-bin / renderer / popup_renderer.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        popup_renderer.h
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @version     1.0
20  * @brief       This is declaration file of PopupRenderer
21  */
22
23 #ifndef WRT_SRC_POPUP_POPUP_RENDERER_H_
24 #define WRT_SRC_POPUP_POPUP_RENDERER_H_
25
26 #include <map>
27 #include <string>
28 #include <memory>
29
30 #include <dpl/noncopyable.h>
31 #include <dpl/log/log.h>
32 #include <dpl/assert.h>
33 #include <dpl/foreach.h>
34 #include "popup.h"
35
36 namespace Wrt {
37 namespace Popup {
38 namespace Renderer {
39 class PopupRenderer : public std::enable_shared_from_this<PopupRenderer>
40 {
41   public:
42     PopupRenderer();
43     ~PopupRenderer();
44     void Initialize();
45     void Deinitialize();
46     IPopupPtr CreatePopup();
47     virtual void setExternalCanvas(void* externalCanvas);
48
49     PopupRenderer (const PopupRenderer &) = delete;
50     PopupRenderer & operator= (const PopupRenderer &) = delete;
51
52   protected:
53     class Popup;
54     typedef std::shared_ptr<Popup> PopupPtr;
55
56     class Popup : public IPopup
57     {
58       public:
59         typedef std::map<int, std::string> ButtonMap;
60         virtual void SetTitle(const std::string &title)
61         {
62             LogDebug(title);
63             Assert(m_title.empty());
64             m_title = title;
65         }
66
67         virtual void Append(PopupObject::IPopupObject *object)
68         {
69             m_popupObjectList.push_back(object);
70         }
71
72         virtual void Show(IPopup::PopupCallbackType callback,
73                           void* data)
74         {
75             Assert(callback);
76             m_data = data;
77             m_callback = callback;
78             m_renderer->Render(std::static_pointer_cast<Popup>(shared_from_this()));
79         }
80
81         const std::string& GetTitle() const
82         {
83             return m_title;
84         }
85
86         PopupObject::PopupObjects& GetPopupObjects()
87         {
88             return m_popupObjectList;
89         }
90
91         virtual ~Popup()
92         {
93             FOREACH(it, m_popupObjectList) {
94                 delete *it;
95             }
96         }
97
98       private:
99         friend class PopupRenderer;
100         friend class std::shared_ptr<Popup>;
101         friend class PopupObjectTheme;
102
103         Popup(std::shared_ptr<PopupRenderer> renderer) :
104                 m_data(NULL), m_callback(NULL), m_renderer(renderer)
105         {}
106
107         void ForwardAnswer(const AnswerCallbackData & answer) const
108         {
109             m_callback(answer, m_data);
110         }
111
112         std::string m_title;
113         void* m_data;
114         IPopup::PopupCallbackType m_callback;
115         PopupObject::PopupObjects m_popupObjectList;
116         std::shared_ptr<PopupRenderer> m_renderer;
117     };
118
119   private:
120     void Render (PopupPtr popup);
121
122     class Impl;
123     Impl* m_impl;
124 };
125
126 typedef std::shared_ptr<PopupRenderer> PopupRendererPtr;
127 }
128 } // namespace Popup
129 } // namespace Wrt
130
131 #endif //WRT_SRC_POPUP_POPUP_RENDERER_H_