[dali_1.2.23] 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
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 }
78
79 DummyControl DummyControlImpl::New()
80 {
81   IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
82   DummyControl control( *impl );
83   impl->Initialize();
84   return control;
85 }
86
87 DummyControlImpl::DummyControlImpl()
88 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
89   mCustomSlot1Called(false)
90 {
91 }
92
93 DummyControlImpl::~DummyControlImpl()
94 {
95 }
96
97 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
98 {
99   Control::RegisterVisual( index, visual );
100
101   VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
102   if( iter == mRegisteredVisualIndices.end() )
103   {
104     mRegisteredVisualIndices.push_back(index);
105   }
106 }
107
108 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
109 {
110   Control::RegisterVisual( index, visual, enabled );
111
112   VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
113   if( iter == mRegisteredVisualIndices.end() )
114   {
115     mRegisteredVisualIndices.push_back(index);
116   }
117 }
118
119 void DummyControlImpl::UnregisterVisual( Property::Index index )
120 {
121   Control::UnregisterVisual( index );
122 }
123
124 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
125 {
126   return Control::GetVisual( index );
127 }
128
129 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
130 {
131   Control::EnableVisual( index, enabled );
132 }
133
134 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
135 {
136   return Control::IsVisualEnabled( index );
137 }
138
139
140 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
141 {
142   return Control::CreateTransition( transition );
143 }
144
145 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
146 {
147 }
148
149 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
150 {
151   Dali::Property::Value value;
152   return value;
153 }
154
155 Toolkit::DummyControl Impl::DummyControl::New()
156 {
157   IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
158   Toolkit::DummyControl control( *impl );
159   impl->Initialize();
160   return control;
161 }
162
163
164 Impl::DummyControl::DummyControl()
165 : DummyControlImpl(),
166   initializeCalled(false),
167   activatedCalled(false),
168   onAccTouchedCalled(false),
169   onAccValueChangeCalled(false),
170   themeChangeCalled(false),
171   fontChangeCalled(false),
172   pinchCalled(false),
173   panCalled(false),
174   tapCalled(false),
175   longPressCalled(false),
176   stageConnectionCalled(false),
177   stageDisconnectionCalled(false),
178   childAddCalled(false),
179   childRemoveCalled(false),
180   sizeSetCalled(false),
181   sizeAnimationCalled(false),
182   touchEventCalled(false),
183   hoverEventCalled(false),
184   wheelEventCalled(false),
185   keyEventCalled(false),
186   keyInputFocusGained(false),
187   keyInputFocusLost(false)
188 {
189 }
190
191 Impl::DummyControl::~DummyControl() { }
192
193
194 void Impl::DummyControl::OnInitialize() { initializeCalled = true; }
195 bool Impl::DummyControl::OnAccessibilityActivated() { activatedCalled = true; return true; }
196 bool Impl::DummyControl::OnAccessibilityTouch(const TouchEvent& touchEvent) { onAccTouchedCalled = true; return true; }
197 bool Impl::DummyControl::OnAccessibilityValueChange( bool isIncrease )
198 {
199   onAccValueChangeCalled = true; return true;
200 }
201
202 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
203 {
204   themeChangeCalled = change == StyleChange::THEME_CHANGE;
205   fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
206 }
207 void Impl::DummyControl::OnPinch(const PinchGesture& pinch) { pinchCalled = true; }
208 void Impl::DummyControl::OnPan(const PanGesture& pan) { panCalled = true; }
209 void Impl::DummyControl::OnTap(const TapGesture& tap) { tapCalled = true; }
210 void Impl::DummyControl::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
211 void Impl::DummyControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
212 void Impl::DummyControl::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
213 void Impl::DummyControl::OnChildAdd(Actor& child) { childAddCalled = true; }
214 void Impl::DummyControl::OnChildRemove(Actor& child) { childRemoveCalled = true; }
215 void Impl::DummyControl::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
216 void Impl::DummyControl::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
217 bool Impl::DummyControl::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
218 bool Impl::DummyControl::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
219 bool Impl::DummyControl::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
220 bool Impl::DummyControl::OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
221 void Impl::DummyControl::OnKeyInputFocusGained() { keyInputFocusGained = true; }
222 void Impl::DummyControl::OnKeyInputFocusLost() { keyInputFocusLost = true; }
223
224 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
225 {
226   Property::Value value( map );
227   mLayouts[visualIndex] = value;
228 }
229
230 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
231 {
232   Property::Map emptyMap;
233
234   for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
235   {
236     Visual::Base visual = GetVisual(*iter);
237     Property::Value value = mLayouts[*iter];
238     Property::Map* map = NULL;
239
240     if( value.GetType() != Property::NONE )
241     {
242       map = value.GetMap();
243     }
244     if( map == NULL )
245     {
246       map = &emptyMap;
247     }
248
249     visual.SetTransformAndSize( *map, size );
250   }
251 }
252
253 DummyControl DummyControl::New( bool override )
254 {
255   DummyControl control;
256
257   if (override)
258   {
259     control = Impl::DummyControl::New();
260   }
261   else
262   {
263     control = DummyControlImpl::New();
264   }
265
266   return control;
267 }
268
269 DummyControl::DummyControl( DummyControlImpl& implementation )
270 : Control( implementation )
271 {
272 }
273
274 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
275 : Control( internal )
276 {
277   VerifyCustomActorPointer<DummyControlImpl>(internal);
278 }
279
280 } // namespace Toolkit
281
282 } // namespace Dali