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