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