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