Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_ControlVisualElement.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_ControlVisualElement.cpp
20  * @brief       This file contains implementation of _ControlVisualElement class
21  *
22  * This file contains implementation _ControlVisualElement class.
23  */
24
25 #include <FBaseSysLog.h>
26
27 #include "FUiAnim_EflNode.h"
28 #include "FUiAnim_ControlVisualElement.h"
29 #include "FUiAnim_VisualElementImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33
34
35 namespace Tizen { namespace Ui { namespace Animations
36 {
37
38
39 //IMPLEMENT_PROPERTY(_ControlVisualElement);
40
41 _ControlVisualElement::_ControlVisualElement(void)
42         : __autoResize(false)
43 {
44
45 }
46
47 _ControlVisualElement::~_ControlVisualElement(void)
48 {
49 }
50
51 VisualElement*
52 _ControlVisualElement::CloneN(void) const
53 {
54         return new (std::nothrow) _ControlVisualElement(*this);
55 }
56
57 _ControlVisualElement::_ControlVisualElement(const _ControlVisualElement& rhs)
58         : _VisualElement(rhs)
59         , __autoResize(rhs.__autoResize)
60 {
61 }
62
63 result
64 _ControlVisualElement::ConstructControlVisualElement(void)
65 {
66         result r = VisualElement::Construct();
67         SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, r, "Propagating.");
68
69         _pVisualElementImpl->SetZOrderGroup(Z_ORDER_GROUP_CONTROL);
70
71         SetImplicitAnimationEnabled(false);
72
73         return r;
74 }
75
76 _ControlVisualElement*
77 _ControlVisualElement::__GetControlChildAtPoint(Tizen::Graphics::FloatPoint& point, int parentHitTest)
78 {
79         _ControlVisualElement* pHitTarget = null;
80         Tizen::Graphics::FloatPoint hitPoint = point;
81         int hitTest = _pVisualElementImpl->InvokeHitTest(point);
82         if ((hitTest & _VisualElementImpl::HITTEST_MATCH) != 0)
83         {
84                 // passed hittest
85                 pHitTarget = this;
86 #if 0
87                 // this passed hittest, but not parent --> clipped out by parent
88                 if (GetParent() && IsClipToParent())
89                 {
90                         if ((parentHitTest & HITTEST_MATCH) == 0)
91                                 pHitTarget = null;
92                 }
93 #endif
94         }
95
96         if ((hitTest & _VisualElementImpl::HITTEST_NOMORECHILDREN) == 0)
97         {
98                 int count = _pVisualElementImpl->__children.GetCount();
99                 for (int i = count - 1; i >= 0; i--)    // from top to bottom
100                 {
101                         // Skip non-ControlVisualElement
102                         _VisualElementImpl* pTemp = _pVisualElementImpl->__children.GetChildAt(i);
103                         _ControlVisualElement* pChild = null;
104                         if (!pTemp)
105                         {
106                                 continue;
107                         }
108
109                         pChild = dynamic_cast< _ControlVisualElement* >(pTemp->GetPublic());
110                         if (!pChild)
111                         {
112                                 continue;
113                         }
114
115                         Tizen::Graphics::FloatPoint childHitPoint = point;
116
117                         pChild->ConvertCoordinates(childHitPoint, this);
118
119                         _ControlVisualElement* pChildHitTarget = pChild->__GetControlChildAtPoint(childHitPoint, hitTest);
120                         if (pChildHitTarget)
121                         {
122                                 pHitTarget = pChildHitTarget;
123                                 hitPoint = childHitPoint;
124                                 break;
125                         }
126                 }
127         }
128
129
130         if (pHitTarget)
131         {
132                 point = hitPoint;
133                 return pHitTarget;
134         }
135
136         return null;
137 }
138
139 // WARNING:
140 //      Because Hit-Testing from self, clipping flags of self will be ignored.
141 _ControlVisualElement*
142 _ControlVisualElement::GetControlChildAtPoint(Tizen::Graphics::FloatPoint& point)
143 {
144         _ControlVisualElement* pHitTarget = __GetControlChildAtPoint(point, _VisualElementImpl::HITTEST_MATCH);
145
146         if (!pHitTarget)
147         {
148                 SetLastResult(E_OBJ_NOT_FOUND);  // TBD: error code
149         }
150         else
151         {
152                 ClearLastResult();
153         }
154         return pHitTarget;
155 }
156
157 bool
158 _ControlVisualElement::IsAutoResizeChildrenEnabled(void) const
159 {
160         return __autoResize;
161 }
162
163 result
164 _ControlVisualElement::SetAutoResizeChildrenEnabled(bool autoResize)
165 {
166         ClearLastResult();
167
168         __autoResize = autoResize;
169 //      _ControlVisualElement* pVisualElement = dynamic_cast< _ControlVisualElement* >(__pPresentation->__pPublicInstance);
170 //      pVisualElement->__autoResize = autoResize;
171
172         return E_SUCCESS;
173 }
174
175 Variant
176 _ControlVisualElement::OnGetPropertyRequested(const Tizen::Base::String& property) const
177 {
178         if (property == *pVePropBounds)
179         {
180                 return _PropGetControlBounds();
181         }
182         else if (property == *pVePropImplicitAnimationEnabled)
183         {
184                 return _PropGetControlImplicitAnimationEnabled();
185         }
186         else if (property == *pVePropPropertyPropagationEnabled)
187         {
188                 return _PropGetControlPropertyPropagationEnabled();
189         }
190
191         return VisualElement::OnGetPropertyRequested(property);
192 }
193
194 result
195 _ControlVisualElement::OnSetPropertyRequested(const Tizen::Base::String& property, const Variant& value)
196 {
197         if (property == *pVePropBounds)
198         {
199                 return _PropSetControlBounds(value);
200         }
201         else if (property == *pVePropImplicitAnimationEnabled)
202         {
203                 return _PropSetControlImplicitAnimationEnabled(value);
204         }
205         else if (property == *pVePropPropertyPropagationEnabled)
206         {
207                 return _PropSetControlPropertyPropagationEnabled(value);
208         }
209
210         return VisualElement::OnSetPropertyRequested(property, value);
211 }
212
213 Variant
214 _ControlVisualElement::_PropGetControlBounds(void) const
215 {
216         return _VisualElementImpl::GetInstance(*this)->GetBoundsProperty();
217 }
218
219 result
220 _ControlVisualElement::_PropSetControlBounds(const Variant& v)
221 {
222         result r = _VisualElementImpl::GetInstance(*this)->SetBoundsProperty(v);
223         SysTryReturnResult(NID_UI_ANIM, !IsFailed(r), r,"Can't set bounds for control VisualElement.");
224
225         if (__autoResize)
226         {
227                 Tizen::Base::Collection::IList* pList = GetChildrenN();
228                 if (!pList)
229                 {
230                         return E_SYSTEM;
231                 }
232
233                 Tizen::Graphics::FloatRectangle clientBounds = v.ToFloatRectangle();
234                 clientBounds.x = 0.0f;
235                 clientBounds.y = 0.0f;
236
237                 for (int i = 0; i < pList->GetCount(); i++)
238                 {
239                         _ControlVisualElement* pChild = dynamic_cast< _ControlVisualElement* >(pList->GetAt(i));
240                         if (pChild)
241                         {
242                                 pChild->SetBounds(clientBounds);
243                         }
244                 }
245
246                 if (pList->GetCount() > 2)
247                 {
248                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Invalid control state(root/system/client)");
249                 }
250
251                 delete pList;
252         }
253
254         return E_SUCCESS;
255 }
256
257 Variant
258 _ControlVisualElement::_PropGetControlImplicitAnimationEnabled(void) const
259 {
260         return _VisualElementImpl::GetInstance(*this)->GetImplicitAnimationProperty();
261 }
262
263 result
264 _ControlVisualElement::_PropSetControlImplicitAnimationEnabled(const Variant& v)
265 {
266         result r = _VisualElementImpl::GetInstance(*this)->SetImplicitAnimationProperty(v);
267         SysTryReturnResult(NID_UI_ANIM, !IsFailed(r), r, "Can't enable or diable implicit animation for control VisualElement.");
268
269         if (__autoResize)
270         {
271                 Tizen::Base::Collection::IList* pList = GetChildrenN();
272                 if (!pList)
273                 {
274                         return E_SYSTEM;
275                 }
276
277                 bool enable = v.ToBool();
278
279                 for (int i = 0; i < pList->GetCount(); i++)
280                 {
281                         _ControlVisualElement* pChild = dynamic_cast< _ControlVisualElement* >(pList->GetAt(i));
282                         if (pChild)
283                         {
284                                 pChild->SetImplicitAnimationEnabled(enable);
285                         }
286                 }
287
288                 if (pList->GetCount() > 2)
289                 {
290                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Invalid control state(root/system/client)");
291                 }
292
293                 delete pList;
294         }
295
296         return E_SUCCESS;
297 }
298
299 Variant
300 _ControlVisualElement::_PropGetControlPropertyPropagationEnabled(void) const
301 {
302         return _VisualElementImpl::GetInstance(*this)->GetPropertyPropagationProperty();
303 }
304
305 result
306 _ControlVisualElement::_PropSetControlPropertyPropagationEnabled(const Variant& v)
307 {
308         result r = _VisualElementImpl::GetInstance(*this)->SetPropertyPropagationProperty(v);
309         SysTryReturnResult(NID_UI_ANIM, !IsFailed(r), r, "Can't enable or diable property propagation for control VisualElement.");
310
311         if (__autoResize)
312         {
313                 Tizen::Base::Collection::IList* pList = GetChildrenN();
314                 if (!pList)
315                 {
316                         return E_SYSTEM;
317                 }
318
319                 bool enable = v.ToBool();
320
321                 for (int i = 0; i < pList->GetCount(); i++)
322                 {
323                         _ControlVisualElement* pChild = dynamic_cast< _ControlVisualElement* >(pList->GetAt(i));
324                         if (pChild)
325                         {
326                                 _VisualElementImpl::GetInstance(*pChild)->SetPropertyPropagationEnabled(enable);
327                         }
328                 }
329
330                 if (pList->GetCount() > 2)
331                 {
332                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Invalid control state(root/system/client)");
333                 }
334
335                 delete pList;
336         }
337
338         return E_SUCCESS;
339 }
340
341
342 }}}             // Tizen::Ui::Animations
343