Added scrollMode property to ScrollView to simplify Rulers
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / control-wrapper-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/devel-api/controls/control-wrapper-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/public-api/object/type-registry-helper.h>
25 #include <dali/devel-api/object/handle-devel.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30 #include <dali-toolkit/public-api/styling/style-manager.h>
31 #include <dali-toolkit/internal/styling/style-manager-impl.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 namespace
43 {
44
45 BaseHandle Create()
46 {
47   // empty handle as we cannot create control wrapper
48   return BaseHandle();
49 }
50
51 // Setup type-registry.
52 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ControlWrapper, Toolkit::Control, Create )
53 DALI_TYPE_REGISTRATION_END()
54
55 }
56
57 /*
58  * Implementation.
59  */
60
61 Dali::Toolkit::ControlWrapper ControlWrapper::New( const std::string& typeName, ControlWrapper* controlWrapper )
62 {
63   ControlWrapperPtr wrapper( controlWrapper );
64
65   // Pass ownership to CustomActor via derived handle.
66   Dali::Toolkit::ControlWrapper handle( *wrapper );
67
68   // Second-phase initialisation of the implementation.
69   // This can only be done after the CustomActor connection has been made.
70   wrapper->Initialize();
71
72   // Different types of C# custom view registered themselves using type registry,
73   // but their type names are registered per type not per instance, so they still
74   // have the same wrong type name in native side when type registry queries the
75   // unique type name of each instance using typeid() because of the binding.
76   // Therefore, we have to link each instance with its correct type info if already
77   // pre-registered.
78
79   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeName );
80   if(typeInfo)
81   {
82     Dali::DevelHandle::SetTypeInfo( handle, typeInfo );
83   }
84
85   return handle;
86 }
87
88 ControlWrapper::ControlWrapper( CustomControlBehaviour behaviourFlags )
89 : Control( static_cast< ControlBehaviour >( behaviourFlags ) )
90 {
91 }
92
93 ControlWrapper::~ControlWrapper()
94 {
95 }
96
97 void ControlWrapper::RelayoutRequest()
98 {
99   CustomActorImpl::RelayoutRequest();
100 }
101
102 float ControlWrapper::GetHeightForWidthBase( float width )
103 {
104   return CustomActorImpl::GetHeightForWidthBase( width );
105 }
106
107 float ControlWrapper::GetWidthForHeightBase( float height )
108 {
109   return CustomActorImpl::GetWidthForHeightBase( height );
110 }
111
112 float ControlWrapper::CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
113 {
114   return CustomActorImpl::CalculateChildSizeBase( child, dimension );
115 }
116
117 bool ControlWrapper::RelayoutDependentOnChildrenBase( Dimension::Type dimension )
118 {
119   return CustomActorImpl::RelayoutDependentOnChildrenBase( dimension );
120 }
121
122 void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual )
123 {
124   Control::RegisterVisual( index, visual );
125 }
126
127 void ControlWrapper::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled )
128 {
129   Control::RegisterVisual( index, visual, enabled );
130 }
131
132 void ControlWrapper::UnregisterVisual( Property::Index index )
133 {
134   Control::UnregisterVisual( index );
135 }
136
137 Toolkit::Visual::Base ControlWrapper::GetVisual( Property::Index index ) const
138 {
139   return Control::GetVisual( index );
140 }
141
142 void ControlWrapper::EnableVisual( Property::Index index, bool enable )
143 {
144   Control::EnableVisual( index, enable );
145 }
146
147 bool ControlWrapper::IsVisualEnabled( Property::Index index ) const
148 {
149   return Control::IsVisualEnabled( index );
150 }
151
152 Dali::Animation ControlWrapper::CreateTransition( const Toolkit::TransitionData& handle )
153 {
154   return Control::CreateTransition( handle );
155 }
156
157 void ControlWrapper::ApplyThemeStyle()
158 {
159   Toolkit::StyleManager styleManager = StyleManager::Get();
160
161   // if style manager is available
162   if( styleManager )
163   {
164     StyleManager& styleManagerImpl = GetImpl( styleManager );
165
166     // Apply the current style
167     styleManagerImpl.ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
168   }
169 }
170
171 } // namespace Internal
172
173 } // namespace Toolkit
174
175 } // namespace Dali