2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "dummy-control.h"
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>
31 DummyControl::DummyControl()
35 DummyControl::DummyControl(const DummyControl& control)
40 DummyControl::~DummyControl()
44 DummyControl DummyControl::DownCast( BaseHandle handle )
46 return Control::DownCast<DummyControl, DummyControlImpl>(handle);
49 DummyControl& DummyControl::operator=(const DummyControl& control)
51 Control::operator=( control );
55 // Used to test signal connections
56 void DummyControlImpl::CustomSlot1( Actor actor )
58 mCustomSlot1Called = true;
65 return DummyControlImpl::New();
68 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::DummyControl, Toolkit::Control, Create );
69 DALI_TYPE_REGISTRATION_END()
71 Dali::PropertyRegistration dummyControlVisualProperty(
72 typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
76 DummyControl DummyControlImpl::New()
78 IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
79 DummyControl control( *impl );
84 DummyControlImpl::DummyControlImpl()
85 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
86 mCustomSlot1Called(false)
90 DummyControlImpl::~DummyControlImpl()
94 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
96 Control::RegisterVisual( index, visual );
98 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
99 if( iter == mRegisteredVisualIndices.end() )
101 mRegisteredVisualIndices.push_back(index);
105 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
107 Control::RegisterVisual( index, visual, enabled );
109 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
110 if( iter == mRegisteredVisualIndices.end() )
112 mRegisteredVisualIndices.push_back(index);
116 void DummyControlImpl::UnregisterVisual( Property::Index index )
118 Control::UnregisterVisual( index );
121 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
123 return Control::GetVisual( index );
126 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
128 Control::EnableVisual( index, enabled );
131 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
133 return Control::IsVisualEnabled( index );
137 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
139 return Control::CreateTransition( transition );
142 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
146 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
148 Dali::Property::Value value;
154 DummyControl DummyControlImplOverride::New()
156 IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride;
157 DummyControl control( *impl );
163 DummyControlImplOverride::DummyControlImplOverride()
164 : DummyControlImpl(),
165 initializeCalled(false),
166 activatedCalled(false),
167 onAccTouchedCalled(false),
168 onAccValueChangeCalled(false),
169 themeChangeCalled(false),
170 fontChangeCalled(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)
190 DummyControlImplOverride::~DummyControlImplOverride() { }
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 )
198 onAccValueChangeCalled = true; return true;
201 void DummyControlImplOverride::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
203 themeChangeCalled = change == StyleChange::THEME_CHANGE;
204 fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
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; }
223 void DummyControlImplOverride::OnRelayout( const Vector2& size, RelayoutContainer& container )
225 Property::Map 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 );
233 for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
235 Visual::Base visual = GetVisual(*iter);
236 visual.SetTransformAndSize( transformMap, size );
241 DummyControl DummyControl::New( bool override )
243 DummyControl control;
247 control = DummyControlImplOverride::New();
251 control = DummyControlImpl::New();
257 DummyControl::DummyControl( DummyControlImpl& implementation )
258 : Control( implementation )
262 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
263 : Control( internal )
265 VerifyCustomActorPointer<DummyControlImpl>(internal);
268 } // namespace Toolkit