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>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
32 DummyControl::DummyControl()
36 DummyControl::DummyControl(const DummyControl& control)
41 DummyControl::~DummyControl()
45 DummyControl DummyControl::DownCast( BaseHandle handle )
47 return Control::DownCast<DummyControl, DummyControlImpl>(handle);
50 DummyControl& DummyControl::operator=(const DummyControl& control)
52 Control::operator=( control );
56 // Used to test signal connections
57 void DummyControlImpl::CustomSlot1( Actor actor )
59 mCustomSlot1Called = true;
66 return DummyControlImpl::New();
69 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::DummyControl, Toolkit::Control, Create );
70 DALI_TYPE_REGISTRATION_END()
72 Dali::PropertyRegistration dummyControlVisualProperty01(
73 typeRegistration, "testVisual", Dali::Toolkit::DummyControl::Property::TEST_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
75 Dali::PropertyRegistration dummyControlVisualProperty02(
76 typeRegistration, "testVisual2", Dali::Toolkit::DummyControl::Property::TEST_VISUAL2, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
78 Dali::PropertyRegistration dummyControlVisualProperty03(
79 typeRegistration, "foregroundVisual", Dali::Toolkit::DummyControl::Property::FOREGROUND_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
81 Dali::PropertyRegistration dummyControlVisualProperty04(
82 typeRegistration, "focusVisual", Dali::Toolkit::DummyControl::Property::FOCUS_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
84 Dali::PropertyRegistration dummyControlVisualProperty05(
85 typeRegistration, "labelVisual", Dali::Toolkit::DummyControl::Property::LABEL_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
89 DummyControl DummyControlImpl::New()
91 IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
92 DummyControl control( *impl );
97 DummyControlImpl::DummyControlImpl()
98 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
99 mCustomSlot1Called(false)
103 DummyControlImpl::~DummyControlImpl()
107 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
109 DevelControl::RegisterVisual( *this, index, visual );
111 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
112 if( iter == mRegisteredVisualIndices.end() )
114 mRegisteredVisualIndices.push_back(index);
118 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
120 DevelControl::RegisterVisual( *this, index, visual, enabled );
122 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
123 if( iter == mRegisteredVisualIndices.end() )
125 mRegisteredVisualIndices.push_back(index);
129 void DummyControlImpl::UnregisterVisual( Property::Index index )
131 DevelControl::UnregisterVisual( *this, index );
133 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
134 if( iter != mRegisteredVisualIndices.end() )
136 mRegisteredVisualIndices.erase(iter);
140 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
142 return DevelControl::GetVisual( *this, index );
145 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
147 DevelControl::EnableVisual( *this, index, enabled );
150 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
152 return DevelControl::IsVisualEnabled( *this, index );
155 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
157 return DevelControl::CreateTransition( *this, transition );
160 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
162 Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
163 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
167 case Toolkit::DummyControl::Property::TEST_VISUAL:
168 case Toolkit::DummyControl::Property::TEST_VISUAL2:
169 case Toolkit::DummyControl::Property::FOREGROUND_VISUAL:
170 case Toolkit::DummyControl::Property::FOCUS_VISUAL:
171 case Toolkit::DummyControl::Property::LABEL_VISUAL:
173 Property::Map* map = value.GetMap();
176 VisualFactory visualFactory = VisualFactory::Get();
177 Visual::Base visual = visualFactory.CreateVisual(*map);
178 dummyImpl.RegisterVisual(index, visual);
185 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
187 Dali::Property::Value value;
191 Toolkit::DummyControl Impl::DummyControl::New()
193 IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
194 Toolkit::DummyControl control( *impl );
200 Impl::DummyControl::DummyControl()
201 : DummyControlImpl(),
202 initializeCalled(false),
203 activatedCalled(false),
204 onAccTouchedCalled(false),
205 onAccValueChangeCalled(false),
206 themeChangeCalled(false),
207 fontChangeCalled(false),
211 longPressCalled(false),
212 stageConnectionCalled(false),
213 stageDisconnectionCalled(false),
214 childAddCalled(false),
215 childRemoveCalled(false),
216 sizeSetCalled(false),
217 sizeAnimationCalled(false),
218 touchEventCalled(false),
219 hoverEventCalled(false),
220 wheelEventCalled(false),
221 keyEventCalled(false),
222 keyInputFocusGained(false),
223 keyInputFocusLost(false)
227 Impl::DummyControl::~DummyControl() { }
230 void Impl::DummyControl::OnInitialize() { initializeCalled = true; }
231 bool Impl::DummyControl::OnAccessibilityActivated() { activatedCalled = true; return true; }
232 bool Impl::DummyControl::OnAccessibilityTouch(const TouchEvent& touchEvent) { onAccTouchedCalled = true; return true; }
233 bool Impl::DummyControl::OnAccessibilityValueChange( bool isIncrease )
235 onAccValueChangeCalled = true; return true;
238 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
240 themeChangeCalled = change == StyleChange::THEME_CHANGE;
241 fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
243 void Impl::DummyControl::OnPinch(const PinchGesture& pinch) { pinchCalled = true; }
244 void Impl::DummyControl::OnPan(const PanGesture& pan) { panCalled = true; }
245 void Impl::DummyControl::OnTap(const TapGesture& tap) { tapCalled = true; }
246 void Impl::DummyControl::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
247 void Impl::DummyControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
248 void Impl::DummyControl::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
249 void Impl::DummyControl::OnChildAdd(Actor& child) { childAddCalled = true; }
250 void Impl::DummyControl::OnChildRemove(Actor& child) { childRemoveCalled = true; }
251 void Impl::DummyControl::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
252 void Impl::DummyControl::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
253 bool Impl::DummyControl::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
254 bool Impl::DummyControl::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
255 bool Impl::DummyControl::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
256 bool Impl::DummyControl::OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
257 void Impl::DummyControl::OnKeyInputFocusGained() { keyInputFocusGained = true; }
258 void Impl::DummyControl::OnKeyInputFocusLost() { keyInputFocusLost = true; }
260 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
262 Property::Value value( map );
263 mLayouts[visualIndex] = value;
266 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
268 if ( mRelayoutCallback )
270 mRelayoutCallback( size ); // Execute callback if set
273 Property::Map emptyMap;
275 for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
277 Visual::Base visual = GetVisual(*iter);
278 Property::Value value = mLayouts[*iter];
279 Property::Map* map = NULL;
281 if( value.GetType() != Property::NONE )
283 map = value.GetMap();
290 visual.SetTransformAndSize( *map, size );
294 void Impl::DummyControl::SetRelayoutCallback( RelayoutCallbackFunc callback )
296 mRelayoutCallback = callback;
300 DummyControl DummyControl::New( bool override )
302 DummyControl control;
306 control = Impl::DummyControl::New();
310 control = DummyControlImpl::New();
316 DummyControl::DummyControl( DummyControlImpl& implementation )
317 : Control( implementation )
321 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
322 : Control( internal )
324 VerifyCustomActorPointer<DummyControlImpl>(internal);
327 } // namespace Toolkit