(TextInput) Don't show grab handle when edit modes starts until actually needed
[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 };
44
45 typedef Dali::Rect<int> PositionSize;
46
47 /**
48  * Stub for the Adaptor
49  */
50 class Adaptor
51 {
52 public:
53
54   typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
55
56 public:
57
58   Adaptor(ToolkitAdaptor& toolkitAdaptor);
59   ~Adaptor();
60
61 public:
62
63   void Start();
64   void Pause();
65   void Resume();
66   void Stop();
67   bool AddIdle(boost::function<void(void)> callBack);
68   void FeedEvent(TouchPoint& point, int timeStamp);
69   bool MoveResize(const PositionSize& positionSize);
70   void SurfaceResized(const PositionSize& positionSize);
71   void ReplaceSurface(RenderSurface& surface);
72   void RenderSync();
73   RenderSurface& GetSurface();
74
75 public: // static methods
76   static Adaptor& Get();
77   static bool IsAvailable();
78
79 public:  // Signals
80
81   AdaptorSignalV2& SignalResize();
82
83   void EmitSignalResize()
84   {
85     mResizeSignal.Emit( *this );
86   }
87
88 private:
89
90   // Undefined
91   Adaptor(const Adaptor&);
92   Adaptor& operator=(Adaptor&);
93
94   AdaptorSignalV2 mResizeSignal;
95   TestRenderSurface mRenderSurface;
96   ToolkitAdaptor& mToolkitAdaptor;
97 };
98
99 namespace
100 {
101 Adaptor* gAdaptor = NULL;
102
103 }
104
105 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
106 : mToolkitAdaptor(toolkitAdaptor)
107 {
108 }
109
110 Adaptor::~Adaptor()
111 {
112
113 }
114
115 void Adaptor::Start()
116 {
117   mToolkitAdaptor.mFunctionsCalled.Start = true;
118 }
119
120 void Adaptor::Pause()
121 {
122   mToolkitAdaptor.mFunctionsCalled.Pause = true;
123 }
124
125 void Adaptor::Resume()
126 {
127   mToolkitAdaptor.mFunctionsCalled.Resume = true;
128 }
129
130 void Adaptor::Stop()
131 {
132   mToolkitAdaptor.mFunctionsCalled.Stop = true;
133 }
134
135 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
136 {
137   mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
138   mToolkitAdaptor.mLastIdleAdded = callBack;
139   return true;
140 }
141
142 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
143 {
144   mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
145   mToolkitAdaptor.mLastTouchPointFed = point;
146   mToolkitAdaptor.mLastTimeStampFed = timeStamp;
147 }
148
149 bool Adaptor::MoveResize(const PositionSize& positionSize)
150 {
151   mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
152   mToolkitAdaptor.mLastSizeSet = positionSize;
153   return true;
154 }
155
156 void Adaptor::SurfaceResized(const PositionSize& positionSize)
157 {
158   mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
159   mToolkitAdaptor.mLastSizeSet = positionSize;
160 }
161
162 void Adaptor::ReplaceSurface(RenderSurface& surface)
163 {
164   mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
165 }
166
167 void Adaptor::RenderSync()
168 {
169   mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
170 }
171
172 RenderSurface& Adaptor::GetSurface()
173 {
174   mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
175   return mRenderSurface;
176 }
177
178 Adaptor& Adaptor::Get()
179 {
180   DALI_ASSERT_ALWAYS(gAdaptor);
181   gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
182   return *gAdaptor;
183 }
184
185 bool Adaptor::IsAvailable()
186 {
187   bool available(false);
188
189   if (gAdaptor)
190   {
191     gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
192     available = true;
193   }
194
195   return available;
196 }
197
198 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
199 {
200   mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
201   return mResizeSignal;
202 }
203
204 ////////////////////////////////////////////////////////////////////////////////////////////////////
205
206 ToolkitAdaptor::ToolkitAdaptor()
207 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
208   mLastTimeStampFed(0),
209   mStyleMonitor(StyleMonitor::Get()),
210   mAccessibilityManager(AccessibilityManager::Get()),
211   mImfManager(ImfManager::Get()),
212   mAdaptorStub(new Adaptor(*this))
213 {
214   gAdaptor = mAdaptorStub;
215 }
216
217 ToolkitAdaptor::~ToolkitAdaptor()
218 {
219   delete mAdaptorStub;
220   gAdaptor = NULL;
221 }
222
223 void ToolkitAdaptor::EmitSignalResize()
224 {
225   mAdaptorStub->EmitSignalResize();
226 }
227
228 } // namespace Dali