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