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 );
77 Dali::PropertyRegistration dummyControlVisualProperty03(
78 typeRegistration, "foregroundVisual", Dali::Toolkit::DummyControl::Property::FOREGROUND_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
80 Dali::PropertyRegistration dummyControlVisualProperty04(
81 typeRegistration, "focusVisual", Dali::Toolkit::DummyControl::Property::FOCUS_VISUAL, Dali::Property::MAP, &Dali::Toolkit::DummyControlImpl::SetProperty, &Dali::Toolkit::DummyControlImpl::GetProperty );
85 DummyControl DummyControlImpl::New()
87 IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
88 DummyControl control( *impl );
93 DummyControlImpl::DummyControlImpl()
94 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_HOVER_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
95 mCustomSlot1Called(false)
99 DummyControlImpl::~DummyControlImpl()
103 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual )
105 Control::RegisterVisual( index, visual );
107 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
108 if( iter == mRegisteredVisualIndices.end() )
110 mRegisteredVisualIndices.push_back(index);
114 void DummyControlImpl::RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled )
116 Control::RegisterVisual( index, visual, enabled );
118 VisualIndices::iterator iter = std::find( mRegisteredVisualIndices.begin(), mRegisteredVisualIndices.end(), index );
119 if( iter == mRegisteredVisualIndices.end() )
121 mRegisteredVisualIndices.push_back(index);
125 void DummyControlImpl::UnregisterVisual( Property::Index index )
127 Control::UnregisterVisual( index );
130 Toolkit::Visual::Base DummyControlImpl::GetVisual( Property::Index index )
132 return Control::GetVisual( index );
135 void DummyControlImpl::EnableVisual( Property::Index index, bool enabled )
137 Control::EnableVisual( index, enabled );
140 bool DummyControlImpl::IsVisualEnabled( Property::Index index )
142 return Control::IsVisualEnabled( index );
146 Animation DummyControlImpl::CreateTransition( const Toolkit::TransitionData& transition )
148 return Control::CreateTransition( transition );
151 void DummyControlImpl::SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value )
153 Toolkit::DummyControl control = Toolkit::DummyControl::DownCast( Dali::BaseHandle( object ) );
154 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
158 case Toolkit::DummyControl::Property::TEST_VISUAL:
159 case Toolkit::DummyControl::Property::TEST_VISUAL2:
160 case Toolkit::DummyControl::Property::FOREGROUND_VISUAL:
161 case Toolkit::DummyControl::Property::FOCUS_VISUAL:
163 Property::Map* map = value.GetMap();
166 VisualFactory visualFactory = VisualFactory::Get();
167 Visual::Base visual = visualFactory.CreateVisual(*map);
168 dummyImpl.RegisterVisual(index, visual);
175 Property::Value DummyControlImpl::GetProperty( BaseObject* object, Dali::Property::Index propertyIndex )
177 Dali::Property::Value value;
181 Toolkit::DummyControl Impl::DummyControl::New()
183 IntrusivePtr< Toolkit::Impl::DummyControl > impl = new Toolkit::Impl::DummyControl;
184 Toolkit::DummyControl control( *impl );
190 Impl::DummyControl::DummyControl()
191 : DummyControlImpl(),
192 initializeCalled(false),
193 activatedCalled(false),
194 onAccTouchedCalled(false),
195 onAccValueChangeCalled(false),
196 themeChangeCalled(false),
197 fontChangeCalled(false),
201 longPressCalled(false),
202 stageConnectionCalled(false),
203 stageDisconnectionCalled(false),
204 childAddCalled(false),
205 childRemoveCalled(false),
206 sizeSetCalled(false),
207 sizeAnimationCalled(false),
208 touchEventCalled(false),
209 hoverEventCalled(false),
210 wheelEventCalled(false),
211 keyEventCalled(false),
212 keyInputFocusGained(false),
213 keyInputFocusLost(false)
217 Impl::DummyControl::~DummyControl() { }
220 void Impl::DummyControl::OnInitialize() { initializeCalled = true; }
221 bool Impl::DummyControl::OnAccessibilityActivated() { activatedCalled = true; return true; }
222 bool Impl::DummyControl::OnAccessibilityTouch(const TouchEvent& touchEvent) { onAccTouchedCalled = true; return true; }
223 bool Impl::DummyControl::OnAccessibilityValueChange( bool isIncrease )
225 onAccValueChangeCalled = true; return true;
228 void Impl::DummyControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
230 themeChangeCalled = change == StyleChange::THEME_CHANGE;
231 fontChangeCalled = change == StyleChange::DEFAULT_FONT_SIZE_CHANGE;
233 void Impl::DummyControl::OnPinch(const PinchGesture& pinch) { pinchCalled = true; }
234 void Impl::DummyControl::OnPan(const PanGesture& pan) { panCalled = true; }
235 void Impl::DummyControl::OnTap(const TapGesture& tap) { tapCalled = true; }
236 void Impl::DummyControl::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
237 void Impl::DummyControl::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
238 void Impl::DummyControl::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
239 void Impl::DummyControl::OnChildAdd(Actor& child) { childAddCalled = true; }
240 void Impl::DummyControl::OnChildRemove(Actor& child) { childRemoveCalled = true; }
241 void Impl::DummyControl::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
242 void Impl::DummyControl::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
243 bool Impl::DummyControl::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
244 bool Impl::DummyControl::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
245 bool Impl::DummyControl::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
246 bool Impl::DummyControl::OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
247 void Impl::DummyControl::OnKeyInputFocusGained() { keyInputFocusGained = true; }
248 void Impl::DummyControl::OnKeyInputFocusLost() { keyInputFocusLost = true; }
250 void Impl::DummyControl::SetLayout( Property::Index visualIndex, Property::Map& map )
252 Property::Value value( map );
253 mLayouts[visualIndex] = value;
256 void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
258 Property::Map emptyMap;
260 for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
262 Visual::Base visual = GetVisual(*iter);
263 Property::Value value = mLayouts[*iter];
264 Property::Map* map = NULL;
266 if( value.GetType() != Property::NONE )
268 map = value.GetMap();
275 visual.SetTransformAndSize( *map, size );
279 DummyControl DummyControl::New( bool override )
281 DummyControl control;
285 control = Impl::DummyControl::New();
289 control = DummyControlImpl::New();
295 DummyControl::DummyControl( DummyControlImpl& implementation )
296 : Control( implementation )
300 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
301 : Control( internal )
303 VerifyCustomActorPointer<DummyControlImpl>(internal);
306 } // namespace Toolkit