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