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 dummyControlVisualProperty01(
72 typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
74 Dali::PropertyRegistration dummyControlVisualProperty02(
75 typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL2, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
79 DummyControl DummyControlImpl::New()
81 IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
82 DummyControl control( *impl );
87 DummyControlImpl::DummyControlImpl()
88 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
89 mCustomSlot1Called(false)
93 DummyControlImpl::~DummyControlImpl()
97 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
99 Control::RegisterVisual( index, visual );
101 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
102 if( iter == mRegisteredVisualIndices.end() )
104 mRegisteredVisualIndices.push_back(index);
108 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
110 Control::RegisterVisual( index, visual, enabled );
112 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
113 if( iter == mRegisteredVisualIndices.end() )
115 mRegisteredVisualIndices.push_back(index);
119 void DummyControlImpl::UnregisterVisual( Property::Index index )
121 Control::UnregisterVisual( index );
124 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
126 return Control::GetVisual( index );
129 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
131 Control::EnableVisual( index, enabled );
134 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
136 return Control::IsVisualEnabled( index );
140 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
142 return Control::CreateTransition( transition );
145 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
149 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
151 Dali::Property::Value value;
155 Toolkit::DummyControl Impl::DummyControl::New()
157 IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
158 Toolkit::DummyControl control( *impl );
164 Impl::DummyControl::DummyControl()
165 : DummyControlImpl(),
166 initializeCalled(false),
167 activatedCalled(false),
168 onAccTouchedCalled(false),
169 onAccValueChangeCalled(false),
170 themeChangeCalled(false),
171 fontChangeCalled(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)
191 Impl::DummyControl::~DummyControl() { }
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 )
199 onAccValueChangeCalled = true; return true;
202 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
204 themeChangeCalled = change == StyleChange::THEME_CHANGE;
205 fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
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; }
224 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
226 Property::Value value( map );
227 mLayouts[visualIndex] = value;
230 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
232 Property::Map emptyMap;
234 for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
236 Visual::Base visual = GetVisual(*iter);
237 Property::Value value = mLayouts[*iter];
238 Property::Map* map = NULL;
240 if( value.GetType() != Property::NONE )
242 map = value.GetMap();
249 visual.SetTransformAndSize( *map, size );
253 DummyControl DummyControl::New( bool override )
255 DummyControl control;
259 control = Impl::DummyControl::New();
263 control = DummyControlImpl::New();
269 DummyControl::DummyControl( DummyControlImpl& implementation )
270 : Control( implementation )
274 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
275 : Control( internal )
277 VerifyCustomActorPointer<DummyControlImpl>(internal);
280 } // namespace Toolkit