Merge "Prepare for Tizen 4.0 Build" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / dummy-control.cpp
1 /*
2  * Copyright (c) 2017 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 #include "dummy-control.h"
19
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
23 #include <dali-toolkit/devel-api/align-enums.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 DummyControl::DummyControl()
32 {
33 }
34
35 DummyControl::DummyControl(const DummyControl& control)
36 : Control( control )
37 {
38 }
39
40 DummyControl::~DummyControl()
41 {
42 }
43
44 DummyControl DummyControl::DownCast( BaseHandle handle )
45 {
46   return Control::DownCast<DummyControl, DummyControlImpl>(handle);
47 }
48
49 DummyControl& DummyControl::operator=(const DummyControl& control)
50 {
51   Control::operator=( control );
52   return *this;
53 }
54
55 // Used to test signal connections
56 void DummyControlImpl::CustomSlot1( Actor actor )
57 {
58   mCustomSlot1Called = true;
59 }
60
61 namespace {
62
63 BaseHandle Create()
64 {
65   return DummyControlImpl::New();
66 }
67
68 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::DummyControl, Toolkit::Control, Create );
69 DALI_TYPE_REGISTRATION_END()
70
71 Dali::PropertyRegistration dummyControlVisualProperty01(
72   typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
73
74 Dali::PropertyRegistration dummyControlVisualProperty02(
75   typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL2, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
76
77 Dali::PropertyRegistration dummyControlVisualProperty03(
78   typeRegistration, "foregroundVisual", Dali::Toolkit::DummyControl::Property::FOREGROUND_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
79
80 Dali::PropertyRegistration dummyControlVisualProperty04(
81   typeRegistration, "focusVisual", Dali::Toolkit::DummyControl::Property::FOCUS_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
82
83 }
84
85 DummyControl DummyControlImpl::New()
86 {
87   IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
88   DummyControl control( *impl );
89   impl->Initialize();
90   return control;
91 }
92
93 DummyControlImpl::DummyControlImpl()
94 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
95   mCustomSlot1Called(false)
96 {
97 }
98
99 DummyControlImpl::~DummyControlImpl()
100 {
101 }
102
103 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
104 {
105   Control::RegisterVisual( index, visual );
106
107   VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
108   if( iter == mRegisteredVisualIndices.end() )
109   {
110     mRegisteredVisualIndices.push_back(index);
111   }
112 }
113
114 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
115 {
116   Control::RegisterVisual( index, visual, enabled );
117
118   VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
119   if( iter == mRegisteredVisualIndices.end() )
120   {
121     mRegisteredVisualIndices.push_back(index);
122   }
123 }
124
125 void DummyControlImpl::UnregisterVisual( Property::Index index )
126 {
127   Control::UnregisterVisual( index );
128 }
129
130 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
131 {
132   return Control::GetVisual( index );
133 }
134
135 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
136 {
137   Control::EnableVisual( index, enabled );
138 }
139
140 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
141 {
142   return Control::IsVisualEnabled( index );
143 }
144
145
146 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
147 {
148   return Control::CreateTransition( transition );
149 }
150
151 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
152 {
153   Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
154   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
155
156   switch(index)
157   {
158     case Toolkit::DummyControl::Property::TEST_VISUAL:
159     case Toolkit::DummyControl::Property::TEST_VISUAL2:
160     case Toolkit::DummyControl::Property::FOREGROUND_VISUAL:
161     case Toolkit::DummyControl::Property::FOCUS_VISUAL:
162     {
163       Property::Map* map = value.GetMap();
164       if( map != NULL )
165       {
166         VisualFactory visualFactory = VisualFactory::Get();
167         Visual::Base visual = visualFactory.CreateVisual(*map);
168         dummyImpl.RegisterVisual(index, visual);
169       }
170       break;
171     }
172   }
173 }
174
175 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
176 {
177   Dali::Property::Value value;
178   return value;
179 }
180
181 Toolkit::DummyControl Impl::DummyControl::New()
182 {
183   IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
184   Toolkit::DummyControl control( *impl );
185   impl->Initialize();
186   return control;
187 }
188
189
190 Impl::DummyControl::DummyControl()
191 : DummyControlImpl(),
192   initializeCalled(false),
193   activatedCalled(false),
194   onAccTouchedCalled(false),
195   onAccValueChangeCalled(false),
196   themeChangeCalled(false),
197   fontChangeCalled(false),
198   pinchCalled(false),
199   panCalled(false),
200   tapCalled(false),
201   longPressCalled(false),
202   stageConnectionCalled(false),
203   stageDisconnectionCalled(false),
204   childAddCalled(false),
205   childRemoveCalled(false),
206   sizeSetCalled(false),
207   sizeAnimationCalled(false),
208   touchEventCalled(false),
209   hoverEventCalled(false),
210   wheelEventCalled(false),
211   keyEventCalled(false),
212   keyInputFocusGained(false),
213   keyInputFocusLost(false)
214 {
215 }
216
217 Impl::DummyControl::~DummyControl() { }
218
219
220 void Impl::DummyControl::OnInitialize() { initializeCalled = true; }
221 bool Impl::DummyControl::OnAccessibilityActivated() { activatedCalled = true; return true; }
222 bool Impl::DummyControl::OnAccessibilityTouch(const TouchEvent& touchEvent) { onAccTouchedCalled = true; return true; }
223 bool Impl::DummyControl::OnAccessibilityValueChange( bool isIncrease )
224 {
225   onAccValueChangeCalled = true; return true;
226 }
227
228 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
229 {
230   themeChangeCalled = change == StyleChange::THEME_CHANGE;
231   fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
232 }
233 void Impl::DummyControl::OnPinch(const PinchGesture& pinch) { pinchCalled = true; }
234 void Impl::DummyControl::OnPan(const PanGesture& pan) { panCalled = true; }
235 void Impl::DummyControl::OnTap(const TapGesture& tap) { tapCalled = true; }
236 void Impl::DummyControl::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
237 void Impl::DummyControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
238 void Impl::DummyControl::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
239 void Impl::DummyControl::OnChildAdd(Actor& child) { childAddCalled = true; }
240 void Impl::DummyControl::OnChildRemove(Actor& child) { childRemoveCalled = true; }
241 void Impl::DummyControl::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
242 void Impl::DummyControl::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
243 bool Impl::DummyControl::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
244 bool Impl::DummyControl::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
245 bool Impl::DummyControl::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
246 bool Impl::DummyControl::OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
247 void Impl::DummyControl::OnKeyInputFocusGained() { keyInputFocusGained = true; }
248 void Impl::DummyControl::OnKeyInputFocusLost() { keyInputFocusLost = true; }
249
250 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
251 {
252   Property::Value value( map );
253   mLayouts[visualIndex] = value;
254 }
255
256 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
257 {
258   Property::Map emptyMap;
259
260   for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
261   {
262     Visual::Base visual = GetVisual(*iter);
263     Property::Value value = mLayouts[*iter];
264     Property::Map* map = NULL;
265
266     if( value.GetType() != Property::NONE )
267     {
268       map = value.GetMap();
269     }
270     if( map == NULL )
271     {
272       map = &emptyMap;
273     }
274
275     visual.SetTransformAndSize( *map, size );
276   }
277 }
278
279 DummyControl DummyControl::New( bool override )
280 {
281   DummyControl control;
282
283   if (override)
284   {
285     control = Impl::DummyControl::New();
286   }
287   else
288   {
289     control = DummyControlImpl::New();
290   }
291
292   return control;
293 }
294
295 DummyControl::DummyControl( DummyControlImpl& implementation )
296 : Control( implementation )
297 {
298 }
299
300 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
301 : Control( internal )
302 {
303   VerifyCustomActorPointer<DummyControlImpl>(internal);
304 }
305
306 } // namespace Toolkit
307
308 } // namespace Dali