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