License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / control.cpp
1 /*
2  * Copyright (c) 2014 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 #include <dali-toolkit/public-api/controls/control.h>
19 #include <dali-toolkit/public-api/controls/control-impl.h>
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 const char* const Control::ACTION_CONTROL_ACTIVATED = "control-activated";
28 const char* const Control::SIGNAL_KEY_EVENT = "key-event";
29
30 Control Control::New()
31 {
32   // Use TypeRegistry to create instance of control so that the type-info matches Control rather than ControlImpl
33   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(Control) );
34   DALI_ASSERT_ALWAYS( typeInfo && "TypeRegistry returning Invalid TypeInfo" );
35
36   BaseHandle handle = typeInfo.CreateInstance();
37   DALI_ASSERT_ALWAYS( handle && "Unable to Create Control" );
38
39   Control control = DownCast( handle );
40   DALI_ASSERT_ALWAYS( handle && "TypeRegistry did not create a Control" );
41
42   return control;
43 }
44
45 Control::Control()
46 {
47 }
48
49 Control::Control(const Control& uiControl)
50 : CustomActor( uiControl ? static_cast<const ControlImpl&>( uiControl.GetImplementation() ).GetOwner() : NULL)
51 {
52 }
53
54 Control::~Control()
55 {
56 }
57
58 Control& Control::operator=( const Control& handle )
59 {
60   if( &handle != this )
61   {
62     CustomActor::operator=( handle );
63   }
64   return *this;
65 }
66
67 Control Control::DownCast( BaseHandle handle )
68 {
69   return DownCast<Control, ControlImpl>(handle);
70 }
71
72 ControlImpl& Control::GetImplementation()
73 {
74   return static_cast<ControlImpl&>(CustomActor::GetImplementation());
75 }
76
77 const ControlImpl& Control::GetImplementation() const
78 {
79   return static_cast<const ControlImpl&>(CustomActor::GetImplementation());
80 }
81
82 void Control::SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy )
83 {
84   GetImplementation().SetSizePolicy( widthPolicy, heightPolicy );
85 }
86
87 void Control::GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const
88 {
89   GetImplementation().GetSizePolicy( widthPolicy, heightPolicy );
90 }
91
92 void Control::SetMinimumSize( const Vector3& size )
93 {
94   GetImplementation().SetMinimumSize( size );
95 }
96
97 const Vector3& Control::GetMinimumSize() const
98 {
99   return GetImplementation().GetMinimumSize();
100 }
101
102 void Control::SetMaximumSize( const Vector3& size )
103 {
104   GetImplementation().SetMaximumSize( size );
105 }
106
107 const Vector3& Control::GetMaximumSize() const
108 {
109   return GetImplementation().GetMaximumSize();
110 }
111
112 Vector3 Control::GetNaturalSize()
113 {
114   return GetImplementation().GetNaturalSize();
115 }
116
117 float Control::GetHeightForWidth( float width )
118 {
119   return GetImplementation().GetHeightForWidth( width );
120 }
121
122 float Control::GetWidthForHeight( float height )
123 {
124   return GetImplementation().GetWidthForHeight( height );
125 }
126
127 void Control::SetKeyInputFocus()
128 {
129   GetImplementation().SetKeyInputFocus();
130 }
131
132 bool Control::HasKeyInputFocus()
133 {
134   return GetImplementation().HasKeyInputFocus();
135 }
136
137 void Control::ClearKeyInputFocus()
138 {
139   GetImplementation().ClearKeyInputFocus();
140 }
141
142 PinchGestureDetector Control::GetPinchGestureDetector() const
143 {
144   return GetImplementation().GetPinchGestureDetector();
145 }
146
147 PanGestureDetector Control::GetPanGestureDetector() const
148 {
149   return GetImplementation().GetPanGestureDetector();
150 }
151
152 TapGestureDetector Control::GetTapGestureDetector() const
153 {
154   return GetImplementation().GetTapGestureDetector();
155 }
156
157 LongPressGestureDetector Control::GetLongPressGestureDetector() const
158 {
159   return GetImplementation().GetLongPressGestureDetector();
160 }
161
162 void Control::SetBackgroundColor( const Vector4& color )
163 {
164   GetImplementation().SetBackgroundColor( color );
165 }
166
167 Vector4 Control::GetBackgroundColor() const
168 {
169   return GetImplementation().GetBackgroundColor();
170 }
171
172 void Control::SetBackground( Image image )
173 {
174   GetImplementation().SetBackground( image );
175 }
176
177 void Control::ClearBackground()
178 {
179   GetImplementation().ClearBackground();
180 }
181
182 Actor Control::GetBackgroundActor() const
183 {
184   return GetImplementation().GetBackgroundActor();
185 }
186
187 Control::KeyEventSignalV2& Control::KeyEventSignal()
188 {
189   return GetImplementation().KeyEventSignal();
190 }
191
192 /**
193  * @copydoc ConnectionTrackerInterface::SignalConnected
194  */
195 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
196 {
197   GetImplementation().SignalConnected(slotObserver, callback );
198 }
199
200 /**
201  * @copydoc ConnectionTrackerInterface::SignalDisconnected
202  */
203 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
204 {
205   GetImplementation().SignalDisconnected(slotObserver, callback );
206 }
207
208 /**
209  * @copydoc ConnectionTrackerInterface::GetConnectionCount
210  */
211 std::size_t Control::GetConnectionCount() const
212 {
213   return GetImplementation().GetConnectionCount( );
214 }
215
216
217 Control::Control(ControlImpl& implementation)
218 : CustomActor(implementation)
219 {
220 }
221
222 Control::Control(Dali::Internal::CustomActor* internal)
223 : CustomActor(internal)
224 {
225   VerifyCustomActorPointer<ControlImpl>(internal);
226 }
227
228 } // namespace Toolkit
229
230 } // namespace Dali