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