(StyleManager) Add style monitor signal into StyleManager
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #define __DALI_ADAPTOR_H__
18 #define __DALI_ACCESSIBILITY_MANAGER_H__
19 #define __DALI_TIMER_H__
20 #define __DALI_CLIPBOARD_H__
21 #define IMFMANAGER_H
22
23 #include "toolkit-adaptor.h"
24 #include <map>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/signals/dali-signal-v2.h>
27
28 namespace Dali
29 {
30
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
32
33 class TestRenderSurface : public RenderSurface
34 {
35 public:
36   TestRenderSurface(){}
37   virtual ~TestRenderSurface(){}
38   virtual SurfaceType GetType() { return RenderSurface::WINDOW; }
39   virtual Dali::Any GetSurface() { return Dali::Any(); }
40   virtual Dali::Any GetDisplay() { return Dali::Any(); }
41   virtual PositionSize GetPositionSize() const { return PositionSize(0, 0, 640, 480);}
42   virtual void SetRenderMode(RenderMode mode){}
43   virtual RenderMode GetRenderMode() const { return RenderSurface::RENDER_60FPS; }
44 };
45
46 typedef Dali::Rect<int> PositionSize;
47
48 /**
49  * Stub for the Adaptor
50  */
51 class Adaptor
52 {
53 public:
54
55   typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
56
57   typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
58   typedef std::map<std::string, Dali::BaseHandle>  SingletonContainer;
59   typedef SingletonContainer::const_iterator       SingletonConstIter;
60
61 public:
62
63   Adaptor(ToolkitAdaptor& toolkitAdaptor);
64   ~Adaptor();
65
66 public:
67
68   void Start();
69   void Pause();
70   void Resume();
71   void Stop();
72   bool AddIdle(boost::function<void(void)> callBack);
73   void FeedEvent(TouchPoint& point, int timeStamp);
74   bool MoveResize(const PositionSize& positionSize);
75   void SurfaceResized(const PositionSize& positionSize);
76   void ReplaceSurface(RenderSurface& surface);
77   void RenderSync();
78   RenderSurface& GetSurface();
79
80   void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
81   Dali::BaseHandle GetSingleton(const std::type_info& info) const;
82
83 public: // static methods
84   static Adaptor& Get();
85   static bool IsAvailable();
86
87 public:  // Signals
88
89   AdaptorSignalV2& SignalResize();
90
91   void EmitSignalResize()
92   {
93     mResizeSignal.Emit( *this );
94   }
95
96 private:
97
98   // Undefined
99   Adaptor(const Adaptor&);
100   Adaptor& operator=(Adaptor&);
101
102   AdaptorSignalV2 mResizeSignal;
103   TestRenderSurface mRenderSurface;
104   ToolkitAdaptor& mToolkitAdaptor;
105
106   SingletonContainer mSingletonContainer;
107 };
108
109 namespace
110 {
111 Adaptor* gAdaptor = NULL;
112
113 }
114
115 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
116 : mToolkitAdaptor(toolkitAdaptor)
117 {
118 }
119
120 Adaptor::~Adaptor()
121 {
122
123 }
124
125 void Adaptor::Start()
126 {
127   mToolkitAdaptor.mFunctionsCalled.Start = true;
128 }
129
130 void Adaptor::Pause()
131 {
132   mToolkitAdaptor.mFunctionsCalled.Pause = true;
133 }
134
135 void Adaptor::Resume()
136 {
137   mToolkitAdaptor.mFunctionsCalled.Resume = true;
138 }
139
140 void Adaptor::Stop()
141 {
142   mToolkitAdaptor.mFunctionsCalled.Stop = true;
143 }
144
145 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
146 {
147   mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
148   mToolkitAdaptor.mLastIdleAdded = callBack;
149   return true;
150 }
151
152 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
153 {
154   mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
155   mToolkitAdaptor.mLastTouchPointFed = point;
156   mToolkitAdaptor.mLastTimeStampFed = timeStamp;
157 }
158
159 bool Adaptor::MoveResize(const PositionSize& positionSize)
160 {
161   mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
162   mToolkitAdaptor.mLastSizeSet = positionSize;
163   return true;
164 }
165
166 void Adaptor::SurfaceResized(const PositionSize& positionSize)
167 {
168   mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
169   mToolkitAdaptor.mLastSizeSet = positionSize;
170 }
171
172 void Adaptor::ReplaceSurface(RenderSurface& surface)
173 {
174   mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
175 }
176
177 void Adaptor::RenderSync()
178 {
179   mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
180 }
181
182 RenderSurface& Adaptor::GetSurface()
183 {
184   mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
185   return mRenderSurface;
186 }
187
188 Adaptor& Adaptor::Get()
189 {
190   DALI_ASSERT_ALWAYS(gAdaptor);
191   gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
192   return *gAdaptor;
193 }
194
195 bool Adaptor::IsAvailable()
196 {
197   bool available(false);
198
199   if (gAdaptor)
200   {
201     gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
202     available = true;
203   }
204
205   return available;
206 }
207
208 void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
209 {
210   mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
211
212   if(singleton)
213   {
214     mSingletonContainer.insert(SingletonPair(info.name(), singleton));
215   }
216 }
217
218 Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
219 {
220   mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
221
222   Dali::BaseHandle object = Dali::BaseHandle();
223
224   SingletonConstIter iter = mSingletonContainer.find(info.name());
225   if(iter != mSingletonContainer.end())
226   {
227     object = (*iter).second;
228   }
229
230   return object;
231 }
232
233 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
234 {
235   mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
236   return mResizeSignal;
237 }
238
239 ////////////////////////////////////////////////////////////////////////////////////////////////////
240
241 ToolkitAdaptor::ToolkitAdaptor()
242 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
243   mLastTimeStampFed(0),
244   mStyleMonitor(StyleMonitor::Get()),
245   mAccessibilityManager(AccessibilityManager::Get()),
246   mImfManager(ImfManager::Get()),
247   mAdaptorStub(new Adaptor(*this))
248 {
249   gAdaptor = mAdaptorStub;
250 }
251
252 ToolkitAdaptor::~ToolkitAdaptor()
253 {
254   delete mAdaptorStub;
255   gAdaptor = NULL;
256 }
257
258 void ToolkitAdaptor::EmitSignalResize()
259 {
260   mAdaptorStub->EmitSignalResize();
261 }
262
263 } // namespace Dali