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