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