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/controls/control-devel.h>
30 DummyControl::DummyControl()
34 DummyControl::DummyControl(const DummyControl& control)
39 DummyControl::~DummyControl()
43 DummyControl DummyControl::DownCast( BaseHandle handle )
45 return Control::DownCast<DummyControl, DummyControlImpl>(handle);
48 DummyControl& DummyControl::operator=(const DummyControl& control)
50 Control::operator=( control );
54 // Used to test signal connections
55 void DummyControlImpl::CustomSlot1( Actor actor )
57 mCustomSlot1Called = true;
64 return DummyControlImpl::New();
67 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::DummyControl, Toolkit::Control, Create );
68 DALI_TYPE_REGISTRATION_END()
70 Dali::PropertyRegistration dummyControlVisualProperty01(
71 typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
73 Dali::PropertyRegistration dummyControlVisualProperty02(
74 typeRegistration, "testVisual2", Dali::Toolkit::DummyControl::Property::TEST_VISUAL2, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
76 Dali::PropertyRegistration dummyControlVisualProperty03(
77 typeRegistration, "foregroundVisual", Dali::Toolkit::DummyControl::Property::FOREGROUND_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
79 Dali::PropertyRegistration dummyControlVisualProperty04(
80 typeRegistration, "focusVisual", Dali::Toolkit::DummyControl::Property::FOCUS_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
82 Dali::PropertyRegistration dummyControlVisualProperty05(
83 typeRegistration, "labelVisual", Dali::Toolkit::DummyControl::Property::LABEL_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
87 DummyControl DummyControlImpl::New()
89 IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
90 DummyControl control( *impl );
95 DummyControlImpl::DummyControlImpl()
96 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
97 mCustomSlot1Called(false)
101 DummyControlImpl::~DummyControlImpl()
105 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
107 DevelControl::RegisterVisual( *this, index, visual );
109 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
110 if( iter == mRegisteredVisualIndices.end() )
112 mRegisteredVisualIndices.push_back(index);
116 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
118 DevelControl::RegisterVisual( *this, index, visual, enabled );
120 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
121 if( iter == mRegisteredVisualIndices.end() )
123 mRegisteredVisualIndices.push_back(index);
127 void DummyControlImpl::UnregisterVisual( Property::Index index )
129 DevelControl::UnregisterVisual( *this, index );
131 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
132 if( iter != mRegisteredVisualIndices.end() )
134 mRegisteredVisualIndices.erase(iter);
138 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
140 return DevelControl::GetVisual( *this, index );
143 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
145 DevelControl::EnableVisual( *this, index, enabled );
148 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
150 return DevelControl::IsVisualEnabled( *this, index );
153 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
155 return DevelControl::CreateTransition( *this, transition );
158 void DummyControlImpl::DoAction( Dali::Property::Index index, Dali::Property::Index action, const Dali::Property::Value attributes )
160 DummyControl control( *this );
161 DevelControl::DoAction( control, index, action, attributes);
164 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
166 Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
167 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
171 case Toolkit::DummyControl::Property::TEST_VISUAL:
172 case Toolkit::DummyControl::Property::TEST_VISUAL2:
173 case Toolkit::DummyControl::Property::FOREGROUND_VISUAL:
174 case Toolkit::DummyControl::Property::FOCUS_VISUAL:
175 case Toolkit::DummyControl::Property::LABEL_VISUAL:
177 Property::Map* map = value.GetMap();
180 VisualFactory visualFactory = VisualFactory::Get();
181 Visual::Base visual = visualFactory.CreateVisual(*map);
182 dummyImpl.RegisterVisual(index, visual);
189 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
191 Dali::Property::Value value;
196 Toolkit::DummyControl Impl::DummyControl::New()
198 IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
199 Toolkit::DummyControl control( *impl );
204 int Impl::DummyControl::constructorCount;
205 int Impl::DummyControl::destructorCount;
207 Impl::DummyControl::DummyControl()
208 : DummyControlImpl(),
209 initializeCalled(false),
210 activatedCalled(false),
211 onAccTouchedCalled(false),
212 onAccValueChangeCalled(false),
213 themeChangeCalled(false),
214 fontChangeCalled(false),
218 longPressCalled(false),
219 stageConnectionCalled(false),
220 stageDisconnectionCalled(false),
221 childAddCalled(false),
222 childRemoveCalled(false),
223 sizeSetCalled(false),
224 sizeAnimationCalled(false),
225 touchEventCalled(false),
226 hoverEventCalled(false),
227 wheelEventCalled(false),
228 keyEventCalled(false),
229 keyInputFocusGained(false),
230 keyInputFocusLost(false)
235 Impl::DummyControl::~DummyControl()
240 void Impl::DummyControl::OnInitialize() { initializeCalled = true; }
241 bool Impl::DummyControl::OnAccessibilityActivated() { activatedCalled = true; return true; }
242 bool Impl::DummyControl::OnAccessibilityTouch(const TouchEvent& touchEvent) { onAccTouchedCalled = true; return true; }
243 bool Impl::DummyControl::OnAccessibilityValueChange( bool isIncrease )
245 onAccValueChangeCalled = true; return true;
248 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
250 themeChangeCalled = change == StyleChange::THEME_CHANGE;
251 fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
253 void Impl::DummyControl::OnPinch(const PinchGesture& pinch) { pinchCalled = true; }
254 void Impl::DummyControl::OnPan(const PanGesture& pan) { panCalled = true; }
255 void Impl::DummyControl::OnTap(const TapGesture& tap) { tapCalled = true; }
256 void Impl::DummyControl::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
257 void Impl::DummyControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
258 void Impl::DummyControl::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
259 void Impl::DummyControl::OnChildAdd(Actor& child) { childAddCalled = true; }
260 void Impl::DummyControl::OnChildRemove(Actor& child) { childRemoveCalled = true; }
261 void Impl::DummyControl::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
262 void Impl::DummyControl::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
263 bool Impl::DummyControl::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
264 bool Impl::DummyControl::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
265 bool Impl::DummyControl::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
266 bool Impl::DummyControl::OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
267 void Impl::DummyControl::OnKeyInputFocusGained() { keyInputFocusGained = true; }
268 void Impl::DummyControl::OnKeyInputFocusLost() { keyInputFocusLost = true; }
270 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
272 Property::Value value( map );
273 mLayouts[visualIndex] = value;
276 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
278 if ( mRelayoutCallback )
280 mRelayoutCallback( size ); // Execute callback if set
283 Property::Map emptyMap;
285 for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
287 Visual::Base visual = GetVisual(*iter);
288 Property::Value value = mLayouts[*iter];
289 Property::Map* map = NULL;
291 if( value.GetType() != Property::NONE )
293 map = value.GetMap();
300 visual.SetTransformAndSize( *map, size );
304 void Impl::DummyControl::SetRelayoutCallback( RelayoutCallbackFunc callback )
306 mRelayoutCallback = callback;
309 Vector3 Impl::DummyControl::GetNaturalSize()
313 for( auto elem : mRegisteredVisualIndices )
316 Visual::Base visual = GetVisual(elem);
317 visual.GetNaturalSize( naturalSize );
318 currentSize.width = std::max( naturalSize.width, currentSize.width );
319 currentSize.height = std::max( naturalSize.height, currentSize.height );
322 return Vector3( currentSize );
327 DummyControl DummyControl::New( bool override )
329 DummyControl control;
333 control = Impl::DummyControl::New();
337 control = DummyControlImpl::New();
343 DummyControl::DummyControl( DummyControlImpl& implementation )
344 : Control( implementation )
348 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
349 : Control( internal )
351 VerifyCustomActorPointer<DummyControlImpl>(internal);
354 } // namespace Toolkit