modify Klockwork bug
[platform/framework/native/uifw.git] / src / ui / FUi_Control.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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                FUi_Control.cpp
20  * @brief               This is the implementation file for the _Control class.
21  */
22
23 #include <new>
24 #include <execinfo.h>
25 #include <unique_ptr.h>
26 #include <FBaseColLinkedListT.h>
27 #include <FBaseColArrayListT.h>
28 #include <FBaseColHashMapT.h>
29 #include <FBaseSysLog.h>
30 #include <FGrpFloatRectangle.h>
31 #include <FUiAnimVisualElementContentProvider.h>
32 #include <FBase_Log.h>
33 #include <FGrp_BitmapImpl.h>
34 #include <FSys_SystemInfoImpl.h>
35 #include "FUi_Math.h"
36 #include "FUi_Control.h"
37 #include "FUi_ControlManager.h"
38 #include "FUi_FocusManagerImpl.h"
39 #include "FUi_CoordinateSystemUtils.h"
40 #include "FUi_Window.h"
41 #include "FUi_EcoreEvasMgr.h"
42 #include "FUi_EcoreEvas.h"
43 #include "FUi_LayoutLayoutContainer.h"
44 #include "FUi_LayoutAbsoluteLayout.h"
45 #include "FUi_LayoutILayoutItemHandler.h"
46 #include "FUi_TouchManager.h"
47 #include "FUi_DataBindingContext.h"
48 #include "FUi_TouchLongPressGestureDetector.h"
49 #include "FUi_TouchTapGestureDetector.h"
50 #include "FUi_AccessibilityContainer.h"
51 #include "FUi_ResourceManager.h"
52 #include "FUiAnim_ControlVisualElement.h"
53 #include "FUiAnim_Debug.h"
54 #include "FUiAnim_VisualElement.h"
55 #include "FUiAnim_VisualElementImpl.h"
56 #include "FUiCtrl_Form.h"
57 #include "FUiCtrl_Frame.h"
58 #include "FUi_ContainerImpl.h"
59 #include "FUi_DragAndDropItem.h"
60 #include "FUi_UiEventManager.h"
61 #include "FUiAnim_MatrixUtil.h"
62
63 using namespace std;
64 using namespace Tizen::Base;
65 using namespace Tizen::Base::Collection;
66 using namespace Tizen::Base::Runtime;
67 using namespace Tizen::Graphics;
68 using namespace Tizen::Ui;
69 using namespace Tizen::Ui::Animations;
70 using namespace Tizen::Ui::Controls;
71
72 namespace {
73
74 int
75 GetZOrderGroupOfVisualElement(_ControlLayer layer)
76 {
77         switch (layer)
78         {
79         case _CONTROL_LAYER_OVERLAY:
80                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL - 1;
81         case _CONTROL_LAYER_CLIENT_BOTTOM:
82                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL;
83         case _CONTROL_LAYER_NONE:
84                 // fall through
85         case _CONTROL_LAYER_CLIENT_MIDDLE:
86                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
87         case _CONTROL_LAYER_CLIENT_TOP:
88                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 2;
89         case _CONTROL_LAYER_SYSTEM:
90                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 3;
91         default:
92                 SysAssert(false);
93                 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
94         }
95 }
96
97 inline bool
98 AdjustSizeToRange(float& width, float& height, const FloatDimension& minDim, const FloatDimension& maxDim)
99 {
100         bool changed = false;
101         if (width < minDim.width)
102         {
103                 width = minDim.width;
104                 changed = true;
105         }
106         if (height < minDim.height)
107         {
108                 height = minDim.height;
109                 changed = true;
110         }
111
112         if (width > maxDim.width)
113         {
114                 width = maxDim.width;
115                 changed = true;
116         }
117         if (height > maxDim.height)
118         {
119                 height = maxDim.height;
120                 changed = true;
121         }
122
123         return changed;
124 }
125
126 inline bool
127 AdjustSizeToRange(FloatDimension& dim, const FloatDimension& minDim, const FloatDimension& maxDim)
128 {
129         return AdjustSizeToRange(dim.width, dim.height, minDim, maxDim);
130 }
131
132 // E_OUT_OF_MEMORY
133 // E_SYSTEM
134 _ControlVisualElement*
135 CreateVisualElementN(void)
136 {
137         ClearLastResult();
138
139         _ControlVisualElement* pVisualElement = new (std::nothrow) _ControlVisualElement;
140         SysTryReturn(NID_UI, pVisualElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
141
142         SysTryCatch(NID_UI,
143                 pVisualElement->ConstructControlVisualElement() == E_SUCCESS, ,
144                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
145
146         pVisualElement->SetImplicitAnimationEnabled(false);
147         pVisualElement->SetShowState(true);
148         pVisualElement->SetBackBufferEnabled(true);
149         pVisualElement->SetRedrawOnResizeEnabled(true);
150         pVisualElement->SetSurfaceOpaque(false);
151
152         return pVisualElement;
153
154 CATCH:
155         //delete pVisualElement;
156         pVisualElement->Destroy();
157         return null;
158 }
159
160 _Control::GestureMap*
161 CreateGestureMapN(void)
162 {
163         ClearLastResult();
164
165         _Control::GestureMap* pGestureMap = new (std::nothrow) _Control::GestureMap;
166         SysTryReturn(NID_UI, pGestureMap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
167
168         SysTryCatch(NID_UI,
169                 pGestureMap->Construct() == E_SUCCESS, ,
170                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
171
172         return pGestureMap;
173
174 CATCH:
175         delete pGestureMap;
176         return null;
177 }
178
179 // E_OUT_OF_MEMORY
180 _Control::ControlList*
181 CreateControlListN(void)
182 {
183         ClearLastResult();
184
185         _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
186         SysTryReturn(NID_UI, pControlList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
187
188         return pControlList;
189 }
190
191 // E_OUT_OF_MEMORY
192 _Control::WindowList*
193 CreateWindowListN(void)
194 {
195         ClearLastResult();
196
197         _Control::WindowList* pWindowList = new (std::nothrow) _Control::WindowList;
198         SysTryReturn(NID_UI, pWindowList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
199
200         return pWindowList;
201 }
202
203 // E_OUT_OF_MEMORY
204 // E_SYSTEM
205 _Layout::LayoutContainer*
206 CreateLayoutContainerN(_Layout::ILayoutItemHandler* pLayoutItemHandler)
207 {
208         ClearLastResult();
209         result r = E_SUCCESS;
210
211         _Layout::LayoutContainer* pLayoutContainer = null;
212         _Layout::AbsoluteLayout* pAbsLayout = null;
213
214         pLayoutContainer = new (std::nothrow) _Layout::LayoutContainer();
215         SysTryReturn(NID_UI, pLayoutContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage");
216         if (IsFailed(GetLastResult()))
217         {
218                 goto CATCH;
219         }
220
221         pAbsLayout = new (std::nothrow) _Layout::AbsoluteLayout();
222         SysTryCatch(NID_UI, pAbsLayout, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
223         if (IsFailed(GetLastResult()))
224         {
225                 goto CATCH;
226         }
227
228         pLayoutContainer->SetItemHandler(pLayoutItemHandler);
229
230         r = pLayoutContainer->SetDefaultLayout(*pAbsLayout);
231         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
232
233         return pLayoutContainer;
234
235 CATCH:
236         delete pAbsLayout;
237         delete pLayoutContainer;
238
239         return null;
240 }
241
242 } // Anonymous namespace
243
244 namespace Tizen { namespace Ui
245 {
246
247 IMPLEMENT_PROPERTY(_Control);
248
249 class _Control::ControlVisualElementContentProvider
250         : public VisualElementContentProvider
251 {
252
253 private:
254         _Control& __control;
255
256 public:
257         ControlVisualElementContentProvider(_Control& control)
258                 : __control(control)
259         {
260         }
261
262         virtual ~ControlVisualElementContentProvider(void)
263         {
264         }
265
266         virtual bool PrepareDraw(VisualElement& target)
267         {
268                 _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(&target);
269                 if (!pCVE)
270                 {
271                         return false;
272                 }
273
274                 Color bgColor = __control.GetBackgroundColor();
275
276                 pCVE->SetBackgroundColor(
277                         _Colorf(
278                                 (float) bgColor.GetRed() / 255.0f,
279                                 (float) bgColor.GetGreen() / 255.0f,
280                                 (float) bgColor.GetBlue() / 255.0f,
281                                 (float) bgColor.GetAlpha() / 255.0f
282                                 )
283                         );
284
285                 __control.GetControlDelegate().OnDraw();
286
287                 target.SetFlushNeeded();
288
289                 return false;
290         }
291
292         virtual HitTestResult HitTest(VisualElement& target, const FloatPoint& point)
293         {
294                 return __control.GetControlDelegate().HitTest(point);
295         }
296
297 private:
298         ControlVisualElementContentProvider(const ControlVisualElementContentProvider& rhs);
299         ControlVisualElementContentProvider& operator =(const ControlVisualElementContentProvider& rhs);
300 };
301
302 class _Control::ControlVisualElementEventListener
303         : public IVisualElementEventListener
304 {
305 public:
306         ControlVisualElementEventListener(_Control& control)
307                 : __control(control)
308         {
309         }
310
311         virtual ~ControlVisualElementEventListener(void)
312         {
313         }
314
315 public:
316         virtual void OnChildAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
317         {
318         }
319
320         virtual void OnChildDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
321         {
322         }
323
324         virtual void OnAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
325         {
326         }
327
328         virtual void OnDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
329         {
330         }
331
332         virtual result OnTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
333         {
334                 return E_SUCCESS;
335         }
336
337         virtual void OnTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
338         {
339         }
340
341         virtual result OnChildrenTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
342         {
343                 for (int i = 0; i < __control.GetChildCount(); ++i)
344                 {
345                         _Control* pChild = __control.GetChild(i);
346                         if (!pChild)
347                         {
348                                 continue;
349                         }
350
351                         if (pChild->GetArea() == _CONTROL_AREA_SYSTEM)
352                         {
353                                 _VisualElement* pVisualElement = pChild->GetVisualElement();
354                                 if (pVisualElement)
355                                 {
356                                         FloatMatrix4 inverseMatrix(newTransform);
357                                         _MatrixUtilInvert(inverseMatrix);
358
359                                         result r = pVisualElement->SetTransformMatrix(inverseMatrix);
360                                         if (r != E_SUCCESS)
361                                         {
362                                                 continue;
363                                         }
364                                 }
365                         }
366                 }
367
368                 return E_SUCCESS;
369         }
370
371         virtual void OnChildrenTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
372                 {
373         }
374
375         virtual result OnBoundsChanging(Tizen::Ui::Animations::VisualElement& source, FloatRectangle& newBounds)
376         {
377                 return E_SUCCESS;
378         }
379
380         virtual void OnBoundsChanged(Tizen::Ui::Animations::VisualElement& source, const FloatRectangle& previousBounds)
381         {
382         }
383
384         virtual void OnShowStateChanged(Tizen::Ui::Animations::VisualElement& source, bool previousShowState)
385         {
386         }
387
388 private:
389         ControlVisualElementEventListener(const ControlVisualElementEventListener& rhs);
390         ControlVisualElementEventListener& operator =(const ControlVisualElementEventListener& rhs);
391
392 private:
393         _Control& __control;
394 }; // ControlVisualElementEventListener
395
396 // Layout Item Handler
397 class _Control::LayoutItemHandler
398         : public _Layout::ILayoutItemHandler
399 {
400 public:
401         LayoutItemHandler(_Control* pControl)
402                 : __pControl(pControl)
403         {
404                 SysAssert(__pControl);
405         }
406
407         void SetItemVisibleState(bool visible)
408         {
409                 __pControl->SetVisibleState(visible);
410         }
411
412         result SetItemBounds(const FloatRectangle& rect)
413         {
414                 SysAssert(__pControl->IsInSizeRange(FloatDimension(rect.width, rect.height)));
415                 return __pControl->SetBoundsFinal(rect, false, true);
416         }
417
418         FloatRectangle GetItemBounds(void) const
419         {
420                 return __pControl->GetBoundsF();
421         }
422
423         FloatRectangle GetItemClientBoundsFromSize(const FloatDimension& size) const
424         {
425                 FloatRectangle clientBounds(0.0f, 0.0f, 0.0f, 0.0f);
426                 __pControl->UpdateClientBounds(size, clientBounds);
427                 return clientBounds;
428         }
429
430         FloatDimension GetItemContentSize(bool horizontalMode, bool verticalMode) const
431         {
432                 FloatRectangle rect = __pControl->GetContentAreaBoundsF();
433                 if (rect == FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
434                 {
435                         return __pControl->GetControlDelegate().GetContentSizeF(horizontalMode, verticalMode);
436                 }
437                 else
438                 {
439                         return FloatDimension(rect.width, rect.height);
440                 }
441         }
442
443         FloatDimension GetItemMinimumSize(void) const
444         {
445                 return __pControl->GetMinimumSizeF();
446         }
447
448         FloatDimension GetItemMaximumSize(void) const
449         {
450                 return __pControl->GetMaximumSizeF();
451         }
452
453         result OnItemMeasure(float& width, float& height)
454         {
455                 Dimension evaluatedSize(_CoordinateSystemUtils::ConvertToInteger(width), _CoordinateSystemUtils::ConvertToInteger(height));
456                 FloatDimension evaluatedSizeF(width, height);
457
458                 bool changed = __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSizeF);
459                 if (changed)
460                 {
461                         width = evaluatedSizeF.width;
462                         height = evaluatedSizeF.height;
463                 }
464                 else
465                 {
466                         __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSize);
467
468                         if (evaluatedSize.width != (_CoordinateSystemUtils::ConvertToInteger(width)))
469                         {
470                                 width = evaluatedSize.width;
471                         }
472                         if (evaluatedSize.height != (_CoordinateSystemUtils::ConvertToInteger(height)))
473                         {
474                                 height = evaluatedSize.height;
475                         }
476                 }
477
478                 return E_SUCCESS;
479         }
480
481 private:
482         LayoutItemHandler(const LayoutItemHandler& rhs);
483         LayoutItemHandler& operator =(const LayoutItemHandler& rhs);
484
485 private:
486         _Control* __pControl;
487 }; // LayoutItemHandler
488
489 // E_OUT_OF_MEMORY
490 // E_SYSTEM
491 _Control*
492 _Control::CreateControlN(void)
493 {
494         _Control* pControl = new (std::nothrow) _Control;
495         SysTryReturn(NID_UI, pControl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
496         if (IsFailed(GetLastResult()))
497         {
498                 goto CATCH;
499         }
500
501         pControl->AcquireHandle();
502
503         SysAssert(GetLastResult() == E_SUCCESS);
504         return pControl;
505
506 CATCH:
507         delete pControl;
508         return null;
509 }
510
511 void
512 _Control::ResetEventListeners(void)
513 {
514         __pFocusEventListener = this;
515         __pNotificationEventListener = this;
516 }
517
518 void
519 _Control::SetControlDelegate(_IControlDelegate& delegate)
520 {
521         __pControlDelegate = &delegate;
522 }
523
524 void
525 _Control::ResetControlDelegate(void)
526 {
527         __pControlDelegate = this;
528 }
529
530 _IControlDelegate&
531 _Control::GetControlDelegate(void) const
532 {
533         if (__destroying)
534         {
535                 return const_cast<_Control&>(*this);
536         }
537
538         SysAssert(__pControlDelegate);
539         return *__pControlDelegate;
540 }
541
542 void
543 _Control::SetPropagatedTouchEventListener(_IPropagatedTouchEventListener* pListener)
544 {
545         __pPropagatedTouchEventListener = pListener;
546 }
547
548 _IPropagatedTouchEventListener*
549 _Control::GetPropagatedTouchEventListener(void) const
550 {
551         if (__destroying)
552         {
553                 return const_cast<_Control*>(this);
554         }
555
556         SysAssert(__pPropagatedTouchEventListener);
557         return __pPropagatedTouchEventListener;
558 }
559
560 void
561 _Control::SetPropagatedKeyEventListener(_IPropagatedKeyEventListener* pListener)
562 {
563         __pPropagatedKeyEventListener = pListener;
564 }
565
566 _IPropagatedKeyEventListener*
567 _Control::GetPropagatedKeyEventListener(void) const
568 {
569         if (__destroying)
570         {
571                 return const_cast<_Control*>(this);
572         }
573
574         SysAssert(__pPropagatedKeyEventListener);
575         return __pPropagatedKeyEventListener;
576 }
577
578 bool
579 _Control::OnPreviewKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
580 {
581         return false;
582 }
583
584 bool
585 _Control::OnPreviewKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
586 {
587         return false;
588 }
589
590 bool
591 _Control::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
592 {
593         //SysLog(NID_UI, ">>> [core] OnKeyPressed(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
594         return false;
595 }
596
597 bool
598 _Control::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
599 {
600         //SysLog(NID_UI, ">>> [core] OnKeyReleased(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
601         return false;
602 }
603
604 bool
605 _Control::TranslateKeyEventInfo(const _Control& source, _KeyInfo& keyInfo)
606 {
607         return false;
608 }
609
610 _UiTouchEventDelivery
611 _Control::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
612 {
613         return _UI_TOUCH_EVENT_DELIVERY_YES;
614 }
615
616 _UiTouchEventDelivery
617 _Control::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
618 {
619         return _UI_TOUCH_EVENT_DELIVERY_YES;
620 }
621
622 _UiTouchEventDelivery
623 _Control::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
624 {
625         return _UI_TOUCH_EVENT_DELIVERY_YES;
626 }
627
628 _UiTouchEventDelivery
629 _Control::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
630 {
631         return _UI_TOUCH_EVENT_DELIVERY_YES;
632 }
633
634 _UiTouchEventDelivery
635 _Control::OnPreviewTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
636 {
637         return _UI_TOUCH_EVENT_DELIVERY_YES;
638 }
639
640 bool
641 _Control::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
642 {
643         return false;
644 }
645
646 bool
647 _Control::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
648 {
649         return false;
650 }
651
652 bool
653 _Control::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
654 {
655         return false;
656 }
657
658 bool
659 _Control::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
660 {
661         return false;
662 }
663
664 bool
665 _Control::OnTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
666 {
667         return false;
668 }
669
670 bool
671 _Control::OnFocusGained(const _Control& source)
672 {
673         bool isFocusMode = _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
674         bool isFocusalbeControl = _FocusManagerImpl::GetInstance()->IsFocusable(this);
675         if (isFocusMode && isFocusalbeControl)
676         {
677                 DrawFocus();
678         }
679         return false;
680 }
681
682 bool
683 _Control::OnFocusLost(const _Control& source)
684 {
685     if (__pFocusVisualElement)
686     {
687                 __pFocusVisualElement->SetShowState(false);
688     }
689         return false;
690 }
691 bool
692 _Control::OnTraversalControlFocusGained(void)
693 {
694         return false;   
695 }
696 bool
697 _Control::OnTraversalControlFocusLost(void)
698 {
699         return false;
700 }
701 bool
702 _Control::OnPreviewNotifiedN(const _Control& source, IList* pArgs)
703 {
704         return false;
705 }
706
707 bool
708 _Control::OnNotifiedN(const _Control& source, IList* pArgs)
709 {
710         return false;
711 }
712
713 bool
714 _Control::IsMovable(void) const
715 {
716         ClearLastResult();
717         return __movable;
718 }
719
720 bool
721 _Control::IsResizable(void) const
722 {
723         ClearLastResult();
724         return __resizable;
725 }
726
727 Dimension
728 _Control::GetContentSize(void) const
729 {
730         ClearLastResult();
731         return Dimension(0, 0);
732 }
733
734 FloatDimension
735 _Control::GetContentSizeF(bool horizontalMode, bool verticalMode) const
736 {
737         ClearLastResult();
738         return FloatDimension(0.0f, 0.0f);
739 }
740
741 HitTestResult
742 _Control::HitTest(const FloatPoint& point)
743 {
744         _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
745
746         if (pVisualElementImpl)
747         {
748                 if (pVisualElementImpl->HitTestI(point) == _VisualElementImpl::HITTEST_MATCH)
749                 {
750                         return HIT_TEST_MATCH;
751                 }
752         }
753
754         return HIT_TEST_NOWHERE;
755 }
756
757 float
758 _Control::GetVerticalScrollPosition(void) const
759 {
760         return 0.0f;
761 }
762
763 float
764 _Control::GetHorizontalScrollPosition(void) const
765 {
766         return 0.0f;
767 }
768
769 _ControlOrientation
770 _Control::GetOrientation(void) const
771 {
772         ClearLastResult();
773         return __orientation;
774 }
775
776 void
777 _Control::OnDraw(void)
778 {
779 }
780
781 Canvas*
782 _Control::OnCanvasRequestedN(const FloatRectangle& bounds)
783 {
784
785         return null;
786 }
787
788 Bitmap*
789 _Control::OnCapturedBitmapRequestedN(void)
790 {
791
792         return null;
793 }
794
795 result
796 _Control::OnAttaching(const _Control* pParent)
797 {
798         return E_SUCCESS;
799 }
800
801 result
802 _Control::OnAttached(void)
803 {
804         return E_SUCCESS;
805 }
806
807 result
808 _Control::OnAttachingToMainTree(const _Control* pParent)
809 {
810         return E_SUCCESS;
811 }
812
813 result
814 _Control::OnPreAttachedToMainTree(void)
815 {
816         return E_SUCCESS;
817 }
818
819 result
820 _Control::OnAttachedToMainTree(void)
821 {
822         return E_SUCCESS;
823 }
824
825 result
826 _Control::OnDetachingFromMainTree(void)
827 {
828         return E_SUCCESS;
829 }
830
831 void
832 _Control::OnAttachingFailed(const _Control& parent)
833 {
834 }
835
836 result
837 _Control::OnDetaching(void)
838 {
839         return E_SUCCESS;
840 }
841
842 result
843 _Control::OnBoundsChanging(const Rectangle& bounds)
844 {
845         return E_SUCCESS;
846 }
847
848 result
849 _Control::OnBoundsChanging(const FloatRectangle& bounds)
850 {
851         return E_SUCCESS;
852 }
853
854 void
855 _Control::OnBoundsChanged(void)
856 {
857
858 }
859
860 void
861 _Control::OnEvaluateSize(Dimension& evaluatedSize)
862 {
863
864 }
865
866 bool
867 _Control::OnEvaluateSize(FloatDimension& evaluatedSize)
868 {
869         return false;
870 }
871
872 void
873 _Control::OnParentBoundsChanged(const _Control& parent)
874 {
875 }
876
877 void
878 _Control::OnChildAttached(const _Control& child)
879 {
880 }
881
882 void
883 _Control::OnChildDetaching(const _Control& child)
884 {
885 }
886
887 void
888 _Control::OnChildDetached(const _Control& child)
889 {
890 }
891
892 void
893 _Control::OnChildBoundsChanged(const _Control& child)
894 {
895 }
896
897 void
898 _Control::OnChildVisibleStateChanged(const _Control& child)
899 {
900 }
901
902 void
903 _Control::OnChangeLayout(_ControlOrientation orientation)
904 {
905 }
906
907 void
908 _Control::OnChangeLayout(_ControlRotation rotation)
909 {
910 }
911
912 void
913 _Control::OnZOrderChanging(_ControlZOrderUpdate zOrderUpdate)
914 {
915 }
916
917 void
918 _Control::OnVisibleStateChanging(void)
919 {
920 }
921
922 void
923 _Control::OnVisibleStateChanged(void)
924 {
925 }
926
927 void
928 _Control::OnAncestorVisibleStateChanged(const _Control& control)
929 {
930         _TouchManager* pTouchManager = _TouchManager::GetInstance();
931         if (pTouchManager && IsVisible() == false && IsAttachedToMainTree() == true)
932         {
933                 if(pTouchManager->GetTouchControlSource() == this)
934                 {
935                         SysLog(NID_UI, "VisibleState changed false, Call SetTouchCanceled");
936                         pTouchManager->SetTouchCanceled(null);
937
938                         _UiEventManager* pUiEventManager = _UiEventManager::GetInstance();
939                         if (pUiEventManager)
940                         {
941                                 pUiEventManager->ClearEventQueue();
942                         }
943                 }
944         }
945 }
946
947 void
948 _Control::OnAncestorEnableStateChanged(const _Control& control)
949 {
950 }
951
952 void
953 _Control::OnAncestorInputEnableStateChanged(const _Control& control)
954 {
955 }
956
957 void
958 _Control::OnTouchPressHandled(const _Control& control)
959 {
960 }
961
962 void
963 _Control::OnTouchReleaseHandled(const _Control& control)
964 {
965 }
966
967 void
968 _Control::OnTouchMoveHandled(const _Control& control)
969 {
970 }
971
972 void
973 _Control::OnFontChanged(Tizen::Graphics::Font* pFont)
974 {
975         SetUpdateLayoutState(true);
976 }
977
978 void
979 _Control::OnFontInfoRequested(unsigned long& style, int& size)
980 {
981 }
982
983 void
984 _Control::OnFontInfoRequested(unsigned long& style, float& size)
985 {
986 }
987
988 void
989 _Control::OnBackgroundColorChanged(Color& backgroundColor)
990 {
991 }
992
993 void
994 _Control::OnFocusableStateChanged(bool focusalbeState)
995 {
996 }
997
998 void
999 _Control::OnFocusModeStateChanged(void)
1000 {
1001 }
1002
1003 void
1004 _Control::OnTouchCancelHandled(const _Control& control)
1005 {
1006 }
1007
1008 void
1009 _Control::Accept(Visitor& visitor)
1010 {
1011         ClearLastResult();
1012
1013         VisitType visitType = visitor.Visit(*this);
1014
1015         switch (visitType)
1016         {
1017         case VISIT_STOP:
1018                 break;
1019
1020         case VISIT_DOWNWARD:
1021                 for (int i = 0; i < GetChildCount(); ++i) // [Postpone] Keep handle list before iternation.
1022                 {
1023                         _Control* pChild = GetChild(i);
1024                         if (pChild)
1025                         {
1026                                 pChild->Accept(visitor);
1027                         }
1028                 }
1029                 break;
1030
1031         case VISIT_UPWARD:
1032                 {
1033                         _Control* pParent = GetParent();
1034                         if (pParent)
1035                         {
1036                                 pParent->Accept(visitor);
1037                         }
1038                 }
1039                 break;
1040
1041         default:
1042                 break;
1043         }
1044 }
1045
1046 void
1047 _Control::Accept(Visitor& visitor) const
1048 {
1049         const_cast <_Control*>(this)->Accept(visitor);
1050 }
1051
1052 void
1053 _Control::InvalidateHierarchyRootWindow(_Control& control)
1054 {
1055         control.__needRecalcRootWindow = true;
1056         control.__pRootWindow = null;
1057
1058         for (int i = 0; i < control.GetChildCount(); ++i)
1059         {
1060                 _Control* pChild = control.GetChild(i);
1061                 if (pChild)
1062                 {
1063                         pChild->InvalidateHierarchyRootWindow(*pChild);
1064                 }
1065         }
1066 }
1067
1068 void
1069 _Control::InvalidateHierarchyAbsoluteBounds(_Control& control)
1070 {
1071         control.__needRecalcAbsBounds = true;
1072         control.__needRecalcAbsBoundsF = true;
1073
1074         for (int i = 0; i < control.GetChildCount(); ++i)
1075         {
1076                 _Control* pChild = control.GetChild(i);
1077                 if (pChild)
1078                 {
1079                         pChild->InvalidateHierarchyAbsoluteBounds(*pChild);
1080                 }
1081         }
1082 }
1083
1084 void
1085 _Control::Draw(bool recursive)
1086 {
1087         ClearLastResult();
1088
1089         Invalidate(recursive);
1090         GetVisualElement()->Draw();
1091 }
1092
1093 void
1094 _Control::Show(void)
1095 {
1096         GetVisualElement()->Flush();
1097         ClearLastResult();
1098
1099         SysAssert(GetLastResult() == E_SUCCESS);
1100 }
1101
1102 void
1103 _Control::ChangeLayout(_Control& control, _ControlOrientation orientation)
1104 {
1105         if (control.__orientation != orientation)
1106         {
1107                 control.__orientation = orientation;
1108                 control.GetControlDelegate().OnChangeLayout(orientation);
1109         }
1110
1111         for (int i = 0; i < control.GetChildCount(); ++i)
1112         {
1113                 _Control* pChild = control.GetChild(i);
1114                 if (pChild)
1115                 {
1116                         ChangeLayout(*pChild, orientation);
1117                 }
1118         }
1119 }
1120
1121 void
1122 _Control::ChangeLayout(_ControlOrientation orientation, bool callRotation)
1123 {
1124         ClearLastResult();
1125         ChangeLayout(*this, orientation);
1126
1127         if (callRotation == true)
1128         {
1129                 _ControlManager* pMgr = _ControlManager::GetInstance();
1130                 if (pMgr)
1131                 {
1132                         _ControlRotation rotation = pMgr->GetOrientationStatus();
1133                         ChangeLayout(rotation);
1134                 }
1135         }
1136 }
1137
1138 void
1139 _Control::ChangeLayout(_Control& control, _ControlRotation rotation)
1140 {
1141         if (control.__rotation != rotation)
1142         {
1143                 control.__rotation = rotation;
1144                 control.GetControlDelegate().OnChangeLayout(rotation);
1145                 ClearLastResult();
1146         }
1147
1148         for (int i = 0; i < control.GetChildCount(); ++i)
1149         {
1150                 _Control* pChild = control.GetChild(i);
1151                 if (pChild)
1152                 {
1153                         ChangeLayout(*pChild, rotation);
1154                 }
1155         }
1156 }
1157
1158 void
1159 _Control::ChangeLayout(_ControlRotation rotation)
1160 {
1161         ClearLastResult();
1162         ChangeLayout(*this, rotation);
1163 }
1164
1165 bool
1166 _Control::IsLayoutChangable(void) const
1167 {
1168         return true;
1169 }
1170
1171 bool
1172 _Control::IsOrientationRoot(void) const
1173 {
1174         return false;
1175 }
1176
1177 void
1178 _Control::Invalidate(void)
1179 {
1180         ClearLastResult();
1181         GetVisualElement()->InvalidateRectangle(null);
1182 }
1183
1184 void
1185 _Control::Invalidate(bool recursive)
1186 {
1187         ClearLastResult();
1188
1189         // Update layout
1190         _Layout::Layout* pLayout = GetLayout();
1191         if (pLayout)
1192         {
1193                 pLayout->UpdateLayout();
1194         }
1195
1196         if (recursive == false)
1197         {
1198                 Invalidate();
1199         }
1200         else
1201         {
1202                 Invalidate(*this);
1203         }
1204 }
1205
1206 void
1207 _Control::Invalidate(_Control& control)
1208 {
1209         if (control.GetVisibleState() == false)
1210         {
1211                 return;
1212         }
1213
1214         control.Invalidate();
1215
1216         // Ownee
1217         int owneeCount = control.GetOwneeCount();
1218         for (int i = 0; i < owneeCount; ++i)
1219         {
1220                 _Window* pOwnee = control.GetOwnee(i);
1221                 if (pOwnee)
1222                 {
1223                         pOwnee->Invalidate(true);
1224                 }
1225         }
1226
1227         for (int i = 0; i < control.GetChildCount(); ++i)
1228         {
1229                 _Control* pChild = control.GetChild(i);
1230                 if (pChild)
1231                 {
1232                         pChild->Invalidate(*pChild);
1233                 }
1234         }
1235 }
1236
1237 void
1238 _Control::Invalidate(const Rectangle& rect)
1239 {
1240         ClearLastResult();
1241         FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1242         GetVisualElement()->InvalidateRectangle(&rectf);
1243
1244         __invalidatedBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
1245 }
1246
1247 void
1248 _Control::Invalidate(const FloatRectangle& rect)
1249 {
1250         ClearLastResult();
1251         FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1252         GetVisualElement()->InvalidateRectangle(&rectf);
1253
1254         __invalidatedBounds = rect;
1255 }
1256
1257 bool
1258 _Control::Contains(const Point& point) const
1259 {
1260         ClearLastResult();
1261
1262         Rectangle bounds = GetBounds();
1263         bounds.x = bounds.y = 0;
1264         return bounds.Contains(point);
1265 }
1266
1267 bool
1268 _Control::Contains(const FloatPoint& point) const
1269 {
1270         ClearLastResult();
1271
1272         FloatRectangle bounds = GetBoundsF();
1273         bounds.x = bounds.y = 0;
1274         return bounds.Contains(point);
1275 }
1276
1277
1278 void
1279 _Control::PartialUpdateLayout(void)
1280 {
1281         ClearLastResult();
1282
1283         _Layout::Layout* pLayout = GetLayout();
1284         if (pLayout)
1285         {
1286                 pLayout->PartialUpdateLayout();
1287         }
1288 }
1289
1290 void
1291 _Control::UpdateLayout(void)
1292 {
1293         ClearLastResult();
1294
1295         _Layout::Layout* pLayout = GetLayout();
1296         if (pLayout)
1297         {
1298                 pLayout->UpdateLayout();
1299         }
1300 }
1301
1302 result
1303 _Control::SetChildAlwaysOnTop(_Control& child)
1304 {
1305         ClearLastResult();
1306
1307         SysTryReturn(NID_UI,
1308                                 child.GetParent() == this, E_INVALID_ARG,
1309                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1310
1311         SysTryReturn(NID_UI,
1312                                 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1313                                 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1314
1315         if (child.GetLayer() == _CONTROL_LAYER_CLIENT_TOP)
1316         {
1317                 return E_SUCCESS;
1318         }
1319
1320         child.SetLayer(_CONTROL_LAYER_CLIENT_TOP);
1321
1322         return E_SUCCESS;
1323 }
1324
1325 result
1326 _Control::SetChildAlwaysAtBottom(_Control& child)
1327 {
1328         ClearLastResult();
1329
1330         SysTryReturn(NID_UI,
1331                                 child.GetParent() == this, E_INVALID_ARG,
1332                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1333
1334         SysTryReturn(NID_UI,
1335                                 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1336                                 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1337
1338         if (child.GetLayer() == _CONTROL_LAYER_CLIENT_BOTTOM)
1339         {
1340                 return E_SUCCESS;
1341         }
1342
1343         child.SetLayer(_CONTROL_LAYER_CLIENT_BOTTOM);
1344
1345         return E_SUCCESS;
1346 }
1347
1348 result
1349 _Control::ResetChildLayer(_Control& child)
1350 {
1351         ClearLastResult();
1352
1353         SysTryReturn(NID_UI,
1354                                 child.GetParent() == this, E_INVALID_ARG,
1355                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1356
1357         SysTryReturn(NID_UI,
1358                                 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1359                                 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1360
1361         if (child.GetLayer() == _CONTROL_LAYER_CLIENT_MIDDLE)
1362         {
1363                 return E_SUCCESS;
1364         }
1365
1366         child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1367
1368         return E_SUCCESS;
1369 }
1370
1371
1372 result
1373 _Control::AttachSystemChild(_Control& child)
1374 {
1375         ClearLastResult();
1376         result r = E_SUCCESS;
1377
1378         r = StartAttaching(child, _CONTROL_AREA_SYSTEM);
1379         if (IsFailed(r))
1380         {
1381                 return r;
1382         }
1383
1384         ControlList& children = GetChildList();
1385         r = children.Add(&child);
1386         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1387
1388         r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1389         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1390
1391         r = EndAttaching(child);
1392         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1393
1394         SysAssert(GetLastResult() == E_SUCCESS);
1395
1396         return E_SUCCESS;
1397 }
1398
1399 result
1400 _Control::DetachSystemChild(_Control& child)
1401 {
1402         return DetachChild(child);
1403 }
1404
1405 bool
1406 _Control::HasParent(void) const
1407 {
1408         return __pParent != null;
1409 }
1410
1411 _ControlArea
1412 _Control::GetArea(void) const
1413 {
1414         ClearLastResult();
1415         return __area;
1416 }
1417
1418 _ControlLayer
1419 _Control::GetLayer(void) const
1420 {
1421         ClearLastResult();
1422         return __layer;
1423 }
1424
1425 void
1426 _Control::SetLayer(_ControlLayer layer)
1427 {
1428         ClearLastResult();
1429         _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*GetVisualElement());
1430
1431         result r = pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(layer));
1432         __layer = layer;
1433
1434         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1435 }
1436
1437 const _Control::ControlList&
1438 _Control::GetChildList() const
1439 {
1440         return const_cast <_Control*>(this)->GetChildList();
1441 }
1442
1443 _Control::ControlList&
1444 _Control::GetChildList()
1445 {
1446         return *__pChildren;
1447 }
1448
1449 bool
1450 _Control::IsCalledCallAttachingToMainTree(void) const
1451 {
1452         return __isCalledCallOnAttachingToMainTree;
1453 }
1454
1455 void
1456 _Control::SetCalledCallAttachingToMainTree(bool isAttaching)
1457 {
1458         __isCalledCallOnAttachingToMainTree = isAttaching;
1459 }
1460
1461 bool
1462 _Control::IsCalledCallPreAttachedToMainTree(void) const
1463 {
1464         return __isCalledCallOnPreAttachedToMainTree;
1465 }
1466
1467 bool
1468 _Control::IsCalledCallAttachedToMainTree(void) const
1469 {
1470         return __isCalledCallOnAttachedToMainTree;
1471 }
1472
1473 void
1474 _Control::SetCalledCallPreAttachedToMainTree(bool isAttached)
1475 {
1476         __isCalledCallOnPreAttachedToMainTree = isAttached;
1477 }
1478
1479 void
1480 _Control::SetCalledCallAttachedToMainTree(bool isAttached)
1481 {
1482         __isCalledCallOnAttachedToMainTree = isAttached;
1483 }
1484
1485 result
1486 _Control::CallOnAttachingToMainTree(_Control& control)
1487 {
1488         result r = E_SUCCESS;
1489
1490         ControlList& children = control.GetChildList();
1491         _Control* pChild = null;
1492
1493         int childrenCount = children.GetCount();
1494
1495         for (int index = 0; index < childrenCount; index++)
1496         {
1497                 r = children.GetAt(index, pChild);
1498                 if (IsFailed(r))
1499                 {
1500                         SysAssert(r == E_OUT_OF_RANGE);
1501                         SysTryReturn(NID_UI,
1502                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1503                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1504                 }
1505                 if (!pChild->IsCalledCallAttachingToMainTree())
1506                 {
1507                         r = CallOnAttachingToMainTree(*pChild);
1508                         pChild->SetCalledCallAttachingToMainTree(true);
1509                         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1510                 }
1511         }
1512
1513         if (!control.IsCalledCallAttachingToMainTree())
1514         {
1515                 r = control.GetControlDelegate().OnAttachingToMainTree(this);
1516                 control.SetCalledCallAttachingToMainTree(true);
1517                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1518         }
1519
1520         return r;
1521 }
1522
1523 result
1524 _Control::CallOnPreAttachedToMainTree(_Control& control)
1525 {
1526         result r = E_SUCCESS;
1527
1528         ControlList& children = control.GetChildList();
1529         _Control* pChild = null;
1530
1531         int childrenCount = children.GetCount();
1532
1533         for (int index = 0; index < childrenCount; index++)
1534         {
1535                 r = children.GetAt(index, pChild);
1536                 if (IsFailed(r))
1537                 {
1538                         SysAssert(r == E_OUT_OF_RANGE);
1539                         SysTryReturn(NID_UI,
1540                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1541                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1542                 }
1543
1544                 if (!pChild->IsCalledCallPreAttachedToMainTree())
1545                 {
1546                         r = CallOnPreAttachedToMainTree(*pChild);
1547                         pChild->SetCalledCallPreAttachedToMainTree(true);
1548                 }
1549         }
1550
1551         if (!control.IsCalledCallPreAttachedToMainTree())
1552         {
1553                 r = control.GetControlDelegate().OnPreAttachedToMainTree();
1554                 control.SetCalledCallPreAttachedToMainTree(true);
1555         }
1556
1557         return r;
1558 }
1559
1560 result
1561 _Control::CallOnAttachedToMainTree(_Control& control)
1562 {
1563         result r = E_SUCCESS;
1564
1565         ControlList& children = control.GetChildList();
1566         _Control* pChild = null;
1567
1568         int childrenCount = children.GetCount();
1569
1570         for (int index = 0; index < childrenCount; index++)
1571         {
1572                 r = children.GetAt(index, pChild);
1573                 if (IsFailed(r))
1574                 {
1575                         SysAssert(r == E_OUT_OF_RANGE);
1576                         SysTryReturn(NID_UI,
1577                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1578                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1579                 }
1580
1581                 if (!pChild->IsCalledCallAttachedToMainTree())
1582                 {
1583                         r = CallOnAttachedToMainTree(*pChild);
1584                         pChild->SetCalledCallAttachedToMainTree(true);
1585                 }
1586         }
1587
1588         if (!control.IsCalledCallAttachedToMainTree())
1589         {
1590                 r = control.GetControlDelegate().OnAttachedToMainTree();
1591                 control.SetCalledCallAttachedToMainTree(true);
1592         }
1593
1594         return r;
1595 }
1596
1597 result
1598 _Control::CallOnDetachingFromMainTree(_Control& control)
1599 {
1600         result r = E_SUCCESS;
1601
1602         ControlList& children = control.GetChildList();
1603         _Control* pChild = null;
1604
1605         _Window* pTop = control.GetRootWindow();
1606         if (pTop)
1607         {
1608                 _Control* pControl = pTop->GetFocusControl(this);
1609                 if ((&control) == pControl)
1610                 {
1611                         pTop->SetFocusControl(&control, false);
1612                 }
1613                 _Control* pFocusTraversalControl = pTop->GetFocusTraversalControl(this);
1614                 if ((&control) == pFocusTraversalControl)
1615                 {
1616                         pTop->SetFocusTraversalControl(&control, false);
1617                 }
1618         }
1619
1620         if (!__isPostOrderTraversal)
1621         {
1622                 r = control.GetControlDelegate().OnDetachingFromMainTree();
1623                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1624         }
1625
1626         int childrenCount = children.GetCount();
1627
1628         for (int index = 0; index < childrenCount; index++)
1629         {
1630                 r = children.GetAt(index, pChild);
1631                 if (IsFailed(r))
1632                 {
1633                         SysAssert(r == E_OUT_OF_RANGE);
1634                         SysTryReturn(NID_UI,
1635                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1636                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1637                 }
1638                 r = CallOnDetachingFromMainTree(*pChild);
1639                 pChild->SetCalledCallAttachingToMainTree(false);
1640                 pChild->SetCalledCallPreAttachedToMainTree(false);
1641                 pChild->SetCalledCallAttachedToMainTree(false);
1642                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1643         }
1644
1645         if (__isPostOrderTraversal)
1646         {
1647                 r = control.GetControlDelegate().OnDetachingFromMainTree();
1648                 control.SetCalledCallAttachingToMainTree(false);
1649                 control.SetCalledCallPreAttachedToMainTree(false);
1650                 control.SetCalledCallAttachedToMainTree(false);
1651                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1652         }
1653
1654         return r;
1655 }
1656
1657 void
1658 _Control::CallOnAncestorVisibleStateChanged(_Control& control)
1659 {
1660         control.GetControlDelegate().OnAncestorVisibleStateChanged(*this);
1661
1662         for (int i = 0; i < control.GetChildCount(); ++i)
1663         {
1664                 _Control* pChild = control.GetChild(i);
1665                 if (pChild)
1666                 {
1667                         CallOnAncestorVisibleStateChanged(*pChild);
1668                 }
1669         }
1670 }
1671
1672 void
1673 _Control::CallOnAncestorEnableStateChanged(_Control& control)
1674 {
1675         control.GetControlDelegate().OnAncestorEnableStateChanged(*this);
1676
1677         for (int i = 0; i < control.GetChildCount(); ++i)
1678         {
1679                 _Control* pChild = control.GetChild(i);
1680                 if (pChild)
1681                 {
1682                         CallOnAncestorEnableStateChanged(*pChild);
1683                 }
1684         }
1685 }
1686
1687 void
1688 _Control::CallOnAncestorInputEnableStateChanged(_Control& control)
1689 {
1690         control.GetControlDelegate().OnAncestorInputEnableStateChanged(*this);
1691
1692         for (int i = 0; i < control.GetChildCount(); ++i)
1693         {
1694                 _Control* pChild = control.GetChild(i);
1695                 if (pChild)
1696                 {
1697                         CallOnAncestorInputEnableStateChanged(*pChild);
1698                 }
1699         }
1700 }
1701
1702 // E_INVALID_ARG
1703 // E_SYSTEM
1704 // [ToDo] Rollback is difficult.
1705 result
1706 _Control::StartAttaching(_Control& child, _ControlArea area)
1707 {
1708         result r = E_SUCCESS;
1709
1710         _Control* pOldParent = child.GetParent();
1711
1712         SysTryReturn(NID_UI,
1713                                 (pOldParent != this), E_INVALID_ARG,
1714                                 E_INVALID_ARG, "[E_INVALID_ARG] The child control is already attached to this container.");
1715
1716         SysTryReturn(NID_UI,
1717                                 pOldParent == null, E_INVALID_ARG,
1718                                 E_INVALID_ARG, "[E_INVALID_ARG] Unable to add the child which already has another parent.");
1719
1720         r = child.GetControlDelegate().OnAttaching(this);
1721         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1722
1723         if (IsAttachedToMainTree())
1724         {
1725                 r = CallOnAttachingToMainTree(child);
1726                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1727         }
1728
1729         // [ToDo] Add control to layout
1730         // What should we do about non-layoutable controls?
1731         if (area == _CONTROL_AREA_CLIENT)
1732         {
1733                 _ControlManager* pMgr = _ControlManager::GetInstance();
1734                 r = GetLastResult();
1735                 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
1736
1737                 r = __pLayoutContainer->AddItem(child.GetLayoutContainer());
1738                 if (IsFailed(r))
1739                 {
1740                         child.GetControlDelegate().OnAttachingFailed(*this);
1741                         SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] Failed to apply layout.");
1742                         return E_SYSTEM;
1743                 }
1744         }
1745
1746         if (IsAttachedToMainTree())
1747         {
1748                 if (!(IsOrientationRoot() && child.IsOrientationRoot()))
1749                 {
1750                         child.ChangeLayout(_ControlManager::GetInstance()->GetOrientation());
1751                 }
1752         }
1753
1754         child.__area = area;
1755
1756         if (area == _CONTROL_AREA_CLIENT)
1757         {
1758                 if (child.GetLayer() != _CONTROL_LAYER_CLIENT_TOP && child.GetLayer() != _CONTROL_LAYER_CLIENT_BOTTOM)
1759                 {
1760                         child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1761                 }
1762         }
1763         else
1764         {
1765                 child.SetLayer(_CONTROL_LAYER_SYSTEM);
1766         }
1767
1768         SysAssert(GetLastResult() == E_SUCCESS);
1769         return E_SUCCESS;
1770 }
1771
1772 result
1773 _Control::EndAttaching(_Control& child)
1774 {
1775         child.SetParent(this);
1776         InvalidateHierarchyRootWindow(child);
1777         InvalidateHierarchyAbsoluteBounds(child);
1778
1779         FloatRectangle floatBounds(child.GetBoundsF().x, child.GetBoundsF().y, child.GetBoundsF().width, child.GetBoundsF().height);
1780
1781         result r = E_SUCCESS;
1782         if (child.IsLayoutChangable() == false)
1783         {
1784                 r = child.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, floatBounds.width, floatBounds.height));
1785         }
1786         else
1787         {
1788                 r = child.UpdateBoundsOfVisualElement(floatBounds);
1789         }
1790         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1791
1792         r = child.GetControlDelegate().OnAttached();
1793         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1794
1795         if (IsAttachedToMainTree())
1796         {
1797                 r = CallOnPreAttachedToMainTree(child);
1798                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1799
1800                 r = CallOnAttachedToMainTree(child);
1801                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1802         }
1803
1804         ClearLastResult();
1805
1806         GetControlDelegate().OnChildAttached(child);
1807         ClearLastResult();
1808
1809         return E_SUCCESS;
1810 }
1811
1812 // E_INVALID_ARG
1813 // E_OUT_OF_MEMORY
1814 // E_SYSTEM
1815 result
1816 _Control::AttachChild(_Control& child)
1817 {
1818         ClearLastResult();
1819         result r = E_SUCCESS;
1820
1821         SysTryReturn(NID_UI,
1822                                 IsChildAttachable(child), E_INVALID_ARG,
1823                                 E_INVALID_ARG, "[E_INVALID_ARG] %ls cannot be a child of %ls.",
1824                                 child.GetName().GetPointer(), GetName().GetPointer());
1825
1826         r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1827         if (IsFailed(r))
1828         {
1829                 return r;
1830         }
1831
1832         ControlList& children = GetChildList();
1833         r = children.Add(&child);
1834         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1835
1836         r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1837
1838         r = EndAttaching(child);
1839         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1840
1841         SysAssert(GetLastResult() == E_SUCCESS);
1842         UpdateFocusList();
1843         return E_SUCCESS;
1844 }
1845
1846 void
1847 _Control::UpdateFocusList(void)
1848 {
1849         _Window* pTop = GetRootWindow();
1850         if (pTop)
1851         {
1852                 pTop->ResetFocusList();
1853         }
1854 }
1855
1856 void
1857 _Control::RemoveFocusRing(bool needToDelete)
1858 {
1859         if (__pFocusVisualElement)
1860         {
1861                 if (needToDelete)
1862                 {
1863                         __pFocusVisualElement.reset();
1864                 }
1865                 else
1866                 {
1867                         __pFocusVisualElement->SetShowState(false);
1868                 }
1869         }
1870 }
1871
1872 bool
1873 _Control::HasFocusRing(void)
1874 {
1875         if (__pFocusVisualElement)
1876         {
1877                 return true;
1878         }
1879
1880         return false;
1881 }
1882
1883 void
1884 _Control::SetFocusNavigateEnabled(bool enable)
1885 {
1886         __isNavigatable = enable;
1887 }
1888
1889 bool
1890 _Control::IsFocusNavigateEnabled(void) const
1891 {
1892         return __isNavigatable;
1893 }
1894
1895 bool
1896 _Control::IsFocusModeStateEnabled(void) const
1897 {
1898         return _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
1899 }
1900
1901 // E_INVALID_ARG
1902 // E_OUT_OF_MEMORY
1903 // E_SYSTEM
1904 result
1905 _Control::InsertChildToBottom(_Control& child)
1906 {
1907         ClearLastResult();
1908         result r = E_SUCCESS;
1909
1910         r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1911         if (IsFailed(r))
1912         {
1913                 return r;
1914         }
1915
1916         ControlList& children = GetChildList();
1917         r = children.InsertAt(&child, 0);
1918         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1919
1920         GetVisualElement()->InsertChild(*child.GetVisualElement(), null, false);
1921         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1922
1923         r = EndAttaching(child);
1924         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1925
1926         SysAssert(GetLastResult() == E_SUCCESS);
1927         UpdateFocusList();
1928         return E_SUCCESS;
1929 }
1930
1931 // E_INVALID_ARG
1932 // E_OUT_OF_MEMORY
1933 // E_SYSTEM
1934 result
1935 _Control::InsertChildAfter(const _Control& targetChild, _Control& child)
1936 {
1937         ClearLastResult();
1938         result r = E_SUCCESS;
1939
1940         SysTryReturn(NID_UI,
1941                                 targetChild.GetParent() == this, E_INVALID_ARG,
1942                                 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
1943
1944         r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1945         if (IsFailed(r))
1946         {
1947                 return r;
1948         }
1949
1950         int targetIndex = GetChildIndex(targetChild);
1951         SysAssert(targetIndex != -1);
1952
1953         ControlList& children = GetChildList();
1954         r = children.InsertAt(&child, targetIndex + 1);
1955         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1956
1957         GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), true);
1958         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1959
1960         r = EndAttaching(child);
1961         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1962
1963         SysAssert(GetLastResult() == E_SUCCESS);
1964         UpdateFocusList();
1965         return E_SUCCESS;
1966 }
1967
1968 // E_INVALID_ARG
1969 // E_OUT_OF_MEMORY
1970 // E_SYSTEM
1971 result
1972 _Control::InsertChildBefore(const _Control& targetChild, _Control& child)
1973 {
1974         ClearLastResult();
1975         result r = E_SUCCESS;
1976
1977         SysTryReturn(NID_UI,
1978                                 targetChild.GetParent() == this, E_INVALID_ARG,
1979                                 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
1980
1981         r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1982         if (IsFailed(r))
1983         {
1984                 return r;
1985         }
1986
1987         int targetIndex = GetChildIndex(targetChild);
1988         SysAssert(targetIndex != -1);
1989
1990         ControlList& children = GetChildList();
1991         r = children.InsertAt(&child, targetIndex);
1992         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1993
1994         GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), false);
1995         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1996
1997         r = EndAttaching(child);
1998         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1999
2000         SysAssert(GetLastResult() == E_SUCCESS);
2001         UpdateFocusList();
2002         return E_SUCCESS;
2003 }
2004
2005 // E_SYSTEM
2006 result
2007 _Control::DetachChild(_Control& child)
2008 {
2009         ClearLastResult();
2010         result r = E_SUCCESS;
2011
2012         if (child.GetParent() != this)
2013         {
2014                 SetLastResult(E_INVALID_ARG);
2015                 return E_INVALID_ARG;
2016         }
2017
2018         if (IsAttachedToMainTree())
2019         {
2020                 r = CallOnDetachingFromMainTree(child);
2021                 SysTryReturn(NID_UI,
2022                                         r == E_SUCCESS, E_SYSTEM,
2023                                         E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2024
2025                 SysTryReturn(NID_UI,
2026                                         child.GetControlDelegate().OnDetaching() == E_SUCCESS, E_SYSTEM,
2027                                         E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2028         }
2029
2030         GetControlDelegate().OnChildDetaching(child);
2031         ClearLastResult();
2032
2033         r = GetVisualElement()->DetachChild(*child.GetVisualElement());
2034         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2035
2036         ControlList& children = GetChildList();
2037         r = children.Remove(&child);
2038         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2039
2040         // Remove control to layout
2041         if (child.__area == _CONTROL_AREA_CLIENT)
2042         {
2043                 _ControlManager* pMgr = _ControlManager::GetInstance();
2044                 r = GetLastResult();
2045                 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
2046
2047                 r = __pLayoutContainer->RemoveItem(child.GetLayoutContainer());
2048                 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2049         }
2050
2051         child.SetParent(null);
2052         child.__area = _CONTROL_AREA_NONE;
2053         child.__layer = _CONTROL_LAYER_NONE;
2054
2055         GetControlDelegate().OnChildDetached(child);
2056         ClearLastResult();
2057
2058         SysAssert(GetLastResult() == E_SUCCESS);
2059         UpdateFocusList();
2060         InvalidateHierarchyRootWindow(child);
2061
2062         return E_SUCCESS;
2063 }
2064
2065 // Always success
2066 void
2067 _Control::DetachAllChildren(bool detachSystemChild, bool recursive)
2068 {
2069         ClearLastResult();
2070         result r = E_SUCCESS;
2071
2072         int childCount = GetChildCount();
2073         int itemIndex = 0;
2074
2075         if (recursive)
2076         {
2077                 while (childCount--)
2078                 {
2079                         _Control* pChild = GetChild(itemIndex);
2080                         if (pChild == null)
2081                         {
2082                                 continue;
2083                         }
2084
2085                         if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2086                         {
2087                                 itemIndex++;
2088                                 continue;
2089                         }
2090
2091                         int childCount = pChild->GetChildCount();
2092                         if (childCount == 0)
2093                         {
2094                                 r = DetachChild(*pChild);
2095                                 if (IsFailed(r))
2096                                 {
2097                                         SysLog(NID_UI, "child is not detached from this container.");
2098                                 }
2099                         }
2100                         else
2101                         {
2102                                 r = DetachChild(*pChild);
2103                                 if (IsFailed(r))
2104                                 {
2105                                         SysLog(NID_UI, "child is not detached from this container.");
2106                                 }
2107                                 pChild->DetachAllChildren(detachSystemChild, true);
2108                         }
2109                 }
2110         }
2111         else
2112         {
2113                 int notDetachedChildCount = 0;
2114                 while (childCount--)
2115                 {
2116                         _Control* pChild = GetChild(itemIndex);
2117                         if (pChild == null)
2118                         {
2119                                 continue;
2120                         }
2121
2122                         if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2123                         {
2124                                 itemIndex++;
2125                                 continue;
2126                         }
2127                         r = DetachChild(*pChild);
2128
2129                         if (IsFailed(r))
2130                         {
2131                                 ++notDetachedChildCount;
2132                         }
2133                 }
2134
2135                 if (notDetachedChildCount > 0)
2136                 {
2137                         SysLog(NID_UI, "%d children are not detached from this container.", notDetachedChildCount);
2138                 }
2139         }
2140
2141         ClearLastResult();
2142 }
2143
2144 // E_INVALID_ARG
2145 result
2146 _Control::MoveChildToTop(const _Control& child)
2147 {
2148         ClearLastResult();
2149         result r = E_SUCCESS;
2150
2151         SysTryReturn(NID_UI,
2152                                 child.GetParent() == this, E_INVALID_ARG,
2153                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2154
2155         // If already on top,
2156         ControlList& children = GetChildList();
2157         if (GetChildIndex(child) == children.GetCount() - 1)
2158         {
2159                 SysAssert(GetLastResult() == E_SUCCESS);
2160                 return E_SUCCESS;
2161         }
2162
2163         _Control* pChild = const_cast <_Control*>(&child);
2164
2165         r = children.Remove(pChild);
2166         SysAssert(r == E_SUCCESS);
2167
2168         r = children.Add(pChild);
2169         SysAssert(r == E_SUCCESS);
2170
2171         r = child.GetVisualElement()->SetZOrder(null, true);
2172         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2173
2174         SysAssert(GetLastResult() == E_SUCCESS);
2175         return E_SUCCESS;
2176 }
2177
2178 // E_INVALID_ARG
2179 result
2180 _Control::MoveChildToBottom(const _Control& child)
2181 {
2182         ClearLastResult();
2183         result r = E_SUCCESS;
2184
2185         SysTryReturn(NID_UI,
2186                                 child.GetParent() == this, E_INVALID_ARG,
2187                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2188
2189         ControlList& children = GetChildList();
2190
2191         if (GetChildIndex(child) == 0)
2192         {
2193                 SysAssert(GetLastResult() == E_SUCCESS);
2194                 return E_SUCCESS;
2195         }
2196
2197         _Control* pChild = const_cast <_Control*>(&child);
2198
2199         r = children.Remove(pChild);
2200         SysAssert(r == E_SUCCESS);
2201
2202         r = children.InsertAt(pChild, 0);
2203         SysAssert(r == E_SUCCESS);
2204
2205         r = child.GetVisualElement()->SetZOrder(null, false);
2206         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2207
2208         SysAssert(GetLastResult() == E_SUCCESS);
2209         return E_SUCCESS;
2210 }
2211
2212 // E_INVALID_ARG
2213 result
2214 _Control::MoveChildAfter(const _Control& targetChild, const _Control& child)
2215 {
2216         ClearLastResult();
2217         result r = E_SUCCESS;
2218
2219         SysTryReturn(NID_UI,
2220                                 targetChild.GetParent() == this, E_INVALID_ARG,
2221                                 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2222
2223         SysTryReturn(NID_UI,
2224                                 child.GetParent() == this, E_INVALID_ARG,
2225                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2226
2227         SysTryReturn(NID_UI,
2228                                 &targetChild != &child, E_INVALID_ARG,
2229                                 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move after self.");
2230
2231         ControlList& children = GetChildList();
2232
2233         int targetIndex = GetChildIndex(targetChild);
2234         SysAssert(targetIndex != -1);
2235
2236         if (targetIndex + 1 == GetChildIndex(child))
2237         {
2238                 SysAssert(GetLastResult() == E_SUCCESS);
2239                 return E_SUCCESS;
2240         }
2241
2242         _Control* pChild = const_cast <_Control*>(&child);
2243
2244         r = children.Remove(pChild);
2245         SysAssert(r == E_SUCCESS);
2246
2247         r = children.InsertAt(pChild, targetIndex + 1);
2248         SysAssert(r == E_SUCCESS);
2249
2250         r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), true);
2251         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2252
2253         SysAssert(GetLastResult() == E_SUCCESS);
2254         return E_SUCCESS;
2255 }
2256
2257 // E_INVALID_ARG
2258 result
2259 _Control::MoveChildBefore(const _Control& targetChild, const _Control& child)
2260 {
2261         ClearLastResult();
2262         result r = E_SUCCESS;
2263
2264         SysTryReturn(NID_UI,
2265                                 targetChild.GetParent() == this, E_INVALID_ARG,
2266                                 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2267
2268         SysTryReturn(NID_UI,
2269                                 child.GetParent() == this, E_INVALID_ARG,
2270                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2271
2272         SysTryReturn(NID_UI,
2273                                 &targetChild != &child, E_INVALID_ARG,
2274                                 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move before self.");
2275
2276         ControlList& children = GetChildList();
2277
2278         int targetIndex = GetChildIndex(targetChild);
2279         SysAssert(targetIndex != -1);
2280
2281         if (targetIndex - 1 == GetChildIndex(child))
2282         {
2283                 SysAssert(GetLastResult() == E_SUCCESS);
2284                 return E_SUCCESS;
2285         }
2286
2287         _Control* pChild = const_cast <_Control*>(&child);
2288
2289         r = children.Remove(pChild);
2290         SysAssert(r == E_SUCCESS);
2291
2292         r = children.InsertAt(pChild, targetIndex);
2293         SysAssert(r == E_SUCCESS);
2294
2295         r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), false);
2296         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2297
2298         SysAssert(GetLastResult() == E_SUCCESS);
2299         return E_SUCCESS;
2300 }
2301
2302 // E_INVALID_ARG
2303 // E_OBJ_NOT_FOUND
2304 int
2305 _Control::GetChildIndex(const _Control& child) const
2306 {
2307         ClearLastResult();
2308         result r = E_SUCCESS;
2309
2310         SysTryReturn(NID_UI,
2311                                 child.GetParent() == this, -1,
2312                                 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2313
2314         const ControlList& children = GetChildList();
2315
2316         int index = -1;
2317         r = children.IndexOf(const_cast<_Control*>(&child), index);
2318         if (IsFailed(r))
2319         {
2320                 SysAssert(r == E_OBJ_NOT_FOUND);
2321                 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
2322                 return -1;
2323         }
2324
2325         SysAssert(GetLastResult() == E_SUCCESS);
2326         return index;
2327 }
2328
2329 // E_OUT_OF_RANGE
2330 _Control*
2331 _Control::GetChild(int index) const
2332 {
2333         ClearLastResult();
2334         result r = E_SUCCESS;
2335
2336         const ControlList& children = GetChildList();
2337
2338         _Control* pChild = null;
2339         r = children.GetAt(index, pChild);
2340         if (IsFailed(r))
2341         {
2342                 SysAssert(r == E_OUT_OF_RANGE);
2343                 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
2344                 return null;
2345         }
2346
2347         SysAssert(GetLastResult() == E_SUCCESS);
2348         return pChild;
2349 }
2350
2351 int
2352 _Control::GetChildCount(void) const
2353 {
2354         ClearLastResult();
2355         return GetChildList().GetCount();
2356 }
2357
2358 _ControlHandle
2359 _Control::GetHandle(void) const
2360 {
2361         return __controlHandle;
2362 }
2363
2364 void*
2365 _Control::GetUserData(void) const
2366 {
2367         return __pUserData;
2368 }
2369
2370 void
2371 _Control::SetUserData(void* pUserData)
2372 {
2373         __pUserData = pUserData;
2374 }
2375
2376 Variant
2377 _Control::GetPropertyName(void) const
2378 {
2379         ClearLastResult();
2380         return Tizen::Ui::Variant(__name);
2381 }
2382
2383 String
2384 _Control::GetName(void) const
2385 {
2386         Variant name = GetProperty("Name");
2387
2388         return name.ToString();
2389 }
2390
2391 result
2392 _Control::SetPropertyName(const Variant& name)
2393 {
2394         ClearLastResult();
2395         __name = name.ToString();
2396
2397         return E_SUCCESS;
2398 }
2399
2400 void
2401 _Control::SetName(const String& name)
2402 {
2403         SetProperty("Name", Variant(name));
2404 }
2405
2406 _Control*
2407 _Control::GetParent(void) const
2408 {
2409         return __pParent;
2410 }
2411
2412 Canvas*
2413 _Control::GetCanvasN(void) const
2414 {
2415         return GetCanvasN(FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
2416 }
2417
2418 Canvas*
2419 _Control::GetCanvasN(const Rectangle& bounds) const
2420 {
2421         ClearLastResult();
2422         Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
2423         if (pCanvas == null)
2424         {
2425                 GetVisualElement()->SetFlushNeeded();
2426                 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2427                 if (IsFailed(GetLastResult()))
2428                 {
2429                         SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2430                 }
2431
2432                 if (pCanvas && !__isCalledGetCanvasN)
2433                 {
2434                         pCanvas->SetBackgroundColor(GetBackgroundColor());
2435                         pCanvas->Clear();
2436                         const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2437                 }
2438         }
2439         return pCanvas;
2440 }
2441
2442 Canvas*
2443 _Control::GetCanvasN(const FloatRectangle& bounds) const
2444 {
2445         ClearLastResult();
2446         Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds));
2447         if (pCanvas == null)
2448         {
2449                 GetVisualElement()->SetFlushNeeded();
2450                 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2451                 if (IsFailed(GetLastResult()))
2452                 {
2453                         SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2454                 }
2455
2456                 if (pCanvas && !__isCalledGetCanvasN)
2457                 {
2458                         pCanvas->SetBackgroundColor(GetBackgroundColor());
2459                         pCanvas->Clear();
2460                         const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2461                 }
2462         }
2463         return pCanvas;
2464 }
2465
2466 bool
2467 _Control::IsCalledGetCanvasN(void) const
2468 {
2469         return __isCalledGetCanvasN;
2470 }
2471
2472 Canvas*
2473 _Control::GetClientCanvasN(void) const
2474 {
2475         return GetCanvasN(GetClientBounds());
2476 }
2477
2478 bool
2479 _Control::IsAncestorOf(const _Control& control) const
2480 {
2481         ClearLastResult();
2482         return IsAncestorOf(control, *this);
2483 }
2484
2485 bool
2486 _Control::IsAncestorOf(const _Control& control, const _Control& ancestor) const
2487 {
2488         const _Control* pParent = control.GetParent();
2489         if (pParent)
2490         {
2491                 if (pParent == &ancestor)
2492                 {
2493                         return true;
2494                 }
2495                 return IsAncestorOf(*pParent, ancestor);
2496         }
2497
2498         return false;
2499 }
2500
2501 _Window*
2502 _Control::GetRootWindow(void) const
2503 {
2504         ClearLastResult();
2505
2506         if (!__needRecalcRootWindow && __pRootWindow != this)
2507         {
2508                 return __pRootWindow;
2509         }
2510
2511         _Window* pRoot = null;
2512         _Control* pControl = const_cast<_Control*>(this);
2513
2514         while (pControl)
2515         {
2516                 pRoot = dynamic_cast <_Window*>(pControl);
2517                 if (pRoot)
2518                 {
2519                         break;
2520                 }
2521                 pControl = pControl->GetParent();
2522         }
2523
2524         const_cast<_Control*>(this)->__pRootWindow = pRoot;
2525         const_cast<_Control*>(this)->__needRecalcRootWindow = false;
2526
2527         return pRoot;
2528 }
2529
2530 bool
2531 _Control::IsAttachedToMainTree(void) const
2532 {
2533         ClearLastResult();
2534
2535         _ControlManager* pMgr = _ControlManager::GetInstance();
2536         if (pMgr == null)
2537         {
2538                 return false;
2539         }
2540
2541         _Window* pRootWindow = GetRootWindow();
2542         if (pRootWindow == null)
2543         {
2544                 return false;
2545         }
2546
2547         return pRootWindow->IsAttached();
2548 }
2549
2550 bool
2551 _Control::IsFocusable(void) const
2552 {
2553         ClearLastResult();
2554         return __focusable;
2555 }
2556
2557 void
2558 _Control::SetFocusable(bool focusable)
2559 {
2560         ClearLastResult();
2561         bool oldState = __focusable;
2562         __focusable = focusable;
2563         if (oldState != __focusable)
2564         {
2565                 GetControlDelegate().OnFocusableStateChanged(focusable);
2566         }
2567 }
2568
2569 bool
2570 _Control::IsNativeObjectFocusable(void) const
2571 {
2572         ClearLastResult();
2573         return __nativeObjectFocusable;
2574 }
2575
2576 void
2577 _Control::SetNativeObjectFocusable(bool focusable)
2578 {
2579         ClearLastResult();
2580         __nativeObjectFocusable = focusable;
2581 }
2582
2583 bool
2584 _Control::IsFocused(void) const
2585 {
2586         ClearLastResult();
2587
2588         _Window* pTop = GetRootWindow();
2589         if (pTop == null)
2590         {
2591                 return false;
2592         }
2593
2594         if (this == pTop->GetFocusControl(const_cast<_Control*>(this)))
2595         {
2596                 return true;
2597         }
2598
2599         return false;
2600 }
2601
2602 void
2603 _Control::SetFocusWindowActivationChecked(bool isChecked)
2604 {
2605         __isFocusWindowActivationChecked = isChecked;
2606 }
2607
2608 bool
2609 _Control::IsFocusWindowActivationChecked(void) const
2610 {
2611         return __isFocusWindowActivationChecked;
2612 }
2613
2614 result
2615 _Control::SetFocused(bool on)
2616 {
2617         ClearLastResult();
2618
2619         SysTryReturn(NID_UI,
2620                                 IsAttachedToMainTree(), E_INVALID_OPERATION,
2621                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2622
2623         SysTryReturn(NID_UI,
2624                                 IsFocusable(), E_INVALID_OPERATION,
2625                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This Control isn't focusable control.");
2626
2627         _Window* pTop = GetRootWindow();
2628         SysAssert(pTop);
2629         if (on)
2630         {
2631                 pTop->SetFocusControl(this, true);
2632         }
2633         else
2634         {
2635                 pTop->SetFocusControl(this, false);
2636         }
2637
2638         bool isFocusControlListControl = _FocusManagerImpl::GetInstance()->IsFocusControlListControl(this);
2639         if (isFocusControlListControl)
2640         {
2641                 pTop->SetFocusTraversalControl(this, true);
2642         }
2643         return E_SUCCESS;
2644 }
2645
2646 result
2647 _Control::SetFont(const String& fontName)
2648 {
2649         result r = E_SUCCESS;
2650
2651         if (__fontName.Equals(fontName))
2652         {
2653                 return E_SUCCESS;
2654         }
2655
2656         __isControlFontChanged = true;
2657         __fontName = fontName;
2658         __fontFileName.Clear();
2659
2660         Font* pFont = GetFallbackFont();
2661
2662         if (pFont == null)
2663         {
2664                 r = GetLastResult();
2665                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2666         }
2667         return E_SUCCESS;
2668 }
2669
2670 Font*
2671 _Control::GetFallbackFont(void)
2672 {
2673         unsigned long style = 0;
2674         int textSize = 0;
2675         float floatTextSize = 0.0f;
2676         result r = E_SUCCESS;
2677         _IControlDelegate& delegate = GetControlDelegate();
2678         delegate.OnFontInfoRequested(style, textSize);
2679         delegate.OnFontInfoRequested(style, floatTextSize);
2680         _ControlManager* pControlManager = _ControlManager::GetInstance();
2681         _FontImpl* pFontImpl  = _FontImpl::GetInstance(*__pFont);
2682         if (!(__isControlFontChanged || pControlManager->IsDefaultFontChanged() || pControlManager->IsSystemFontChanged())
2683                 && __pFont != null
2684                 && ((__pFont->GetSize() == textSize || __pFont->GetSizeF() == floatTextSize))
2685                 && (pFontImpl->GetStyle() == static_cast<int>(style)))
2686         {
2687                 return __pFont;
2688         }
2689         unique_ptr<Font>pTempFont(new(std::nothrow)Font());
2690         SysTryReturn(NID_UI , pTempFont , null , E_OUT_OF_MEMORY, "[%s] Fails to create a __pFont.", GetErrorMessage(r));
2691
2692         if (!__fontName.IsEmpty())
2693         {
2694                 __isControlFontChanged = false;
2695                 _FontImpl* pFontImpl  = _FontImpl::GetInstance(*pTempFont);
2696                 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2697
2698                 if (floatTextSize > 0.0f)
2699                 {
2700                         r = pFontImpl->Construct(__fontName, style, floatTextSize, false);
2701                 }
2702                 else
2703                 {
2704                         r = pFontImpl->Construct(__fontName, style, textSize, false);
2705                 }
2706
2707                 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2708                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2709         }
2710         else if (!__fontFileName.IsEmpty())
2711         {
2712                 __isControlFontChanged = false;
2713                 _FontImpl* pFontImpl  = _FontImpl::GetInstance(*pTempFont);
2714                 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2715
2716                 if (floatTextSize > 0.0f)
2717                 {
2718                         r = pFontImpl->Construct(__fontFileName, style, floatTextSize);
2719                 }
2720                 else
2721                 {
2722                         r = pFontImpl->Construct(__fontFileName, style, textSize);
2723                 }
2724                 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2725                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2726
2727         }
2728         else if (!pControlManager->GetDefaultFont().IsEmpty())
2729         {
2730                 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2731                 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2732
2733                 if (floatTextSize > 0.0f)
2734                 {
2735                         r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, floatTextSize, false);
2736                 }
2737                 else
2738                 {
2739                         r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, textSize, false);
2740                 }
2741                 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2742                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2743         }
2744         else if (!pControlManager->GetDefaultFontFile().IsEmpty())
2745         {
2746                 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2747                 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2748
2749                 if (floatTextSize > 0.0f)
2750                 {
2751                         r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, floatTextSize);
2752                 }
2753                 else
2754                 {
2755                         r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, textSize);
2756                 }
2757                 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2758                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2759         }
2760         else
2761         {
2762                 if (floatTextSize > 0.0f)
2763                 {
2764                         r = pTempFont->Construct(style, floatTextSize);
2765                 }
2766                 else
2767                 {
2768                         r = pTempFont->Construct(style, textSize);
2769                 }
2770                 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2771                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2772         }
2773
2774         if (__pFont)
2775         {
2776                 delete __pFont;
2777                 __pFont = null;
2778         }
2779         __pFont = pTempFont.release();
2780         delegate.OnFontChanged(__pFont);
2781         return  __pFont;
2782 }
2783
2784 String
2785 _Control::GetFont(void) const
2786 {
2787         return __fontName;
2788 }
2789
2790 bool
2791 _Control::IsEnabled(void) const
2792 {
2793         ClearLastResult();
2794
2795         bool enabled = true;
2796         const _Control* pControl = this;
2797
2798         while (pControl)
2799         {
2800                 if (!pControl->GetEnableState())
2801                 {
2802                         enabled = false;
2803                         break;
2804                 }
2805                 pControl = pControl->GetParent();
2806         }
2807
2808         return enabled;
2809 }
2810
2811 bool
2812 _Control::GetEnableState(void) const
2813 {
2814         ClearLastResult();
2815         return __enabledState;
2816 }
2817
2818 void
2819 _Control::SetEnableState(bool enabledState)
2820 {
2821         ClearLastResult();
2822         const bool changed = (__enabledState != enabledState);
2823         if (changed)
2824         {
2825                 __enabledState = enabledState;
2826                 CallOnAncestorEnableStateChanged(*this);
2827         }
2828         __pAccessibilityContainer->SetEnableState(enabledState);
2829 }
2830
2831 bool
2832 _Control::IsInputEventEnabled(void) const
2833 {
2834         ClearLastResult();
2835
2836         bool inputEnabled = true;
2837         const _Control* pControl = this;
2838
2839         while (pControl)
2840         {
2841                 if (!pControl->GetInputEnableState())
2842                 {
2843                         inputEnabled = false;
2844                         break;
2845                 }
2846                 pControl = pControl->GetParent();
2847         }
2848
2849         return inputEnabled;
2850 }
2851
2852 bool
2853 _Control::GetInputEnableState(void) const
2854 {
2855         ClearLastResult();
2856
2857         if (__inputLockRefCount != 0)
2858         {
2859                 return false;
2860         }
2861         else
2862         {
2863                 return true;
2864         }
2865 }
2866
2867 void
2868 _Control::LockInputEvent(void)
2869 {
2870         __inputLockRefCount++;
2871         CallOnAncestorInputEnableStateChanged(*this);
2872 }
2873
2874 void
2875 _Control::UnlockInputEvent(void)
2876 {
2877         __inputLockRefCount--;
2878         if (__inputLockRefCount < 0)
2879         {
2880                 __inputLockRefCount = 0;
2881         }
2882 }
2883
2884 bool
2885 _Control::IsVisible(void) const
2886 {
2887         ClearLastResult();
2888
2889         if (IsAttachedToMainTree() == false)
2890         {
2891                 SetLastResult(E_SYSTEM);
2892                 return false;
2893         }
2894
2895         bool visible = true;
2896         const _Control* pControl = this;
2897
2898         while (pControl)
2899         {
2900                 if (!pControl->GetVisibleState())
2901                 {
2902                         visible = false;
2903                         break;
2904                 }
2905                 pControl = pControl->GetParent();
2906         }
2907
2908         return visible;
2909 }
2910
2911 bool
2912 _Control::GetVisibleState(void) const
2913 {
2914         ClearLastResult();
2915         return __visibleState;
2916 }
2917
2918 void
2919 _Control::SetVisibleState(bool visibleState)
2920 {
2921         ClearLastResult();
2922
2923         const bool changed = (__visibleState != visibleState) || !__initVisibleState;
2924
2925         if (changed)
2926         {
2927                 GetControlDelegate().OnVisibleStateChanging();
2928         }
2929
2930         __visibleState = visibleState;
2931         GetVisualElement()->SetShowState(visibleState);
2932
2933         if (visibleState == false)
2934         {
2935                 int owneeCount = GetOwneeCount();
2936                 for (int i = 0; i < owneeCount; ++i)
2937                 {
2938                         _Window* pWindow = GetOwnee(i);
2939                         if (pWindow)
2940                         {
2941                                 pWindow->SetVisibleState(visibleState);
2942                         }
2943                 }
2944         }
2945
2946         if (changed)
2947         {
2948                 GetControlDelegate().OnVisibleStateChanged();
2949                 CallOnAncestorVisibleStateChanged(*this);
2950                 _Control* pParent = GetParent();
2951                 if (pParent)
2952                 {
2953                         pParent->GetControlDelegate().OnChildVisibleStateChanged(*this);
2954                 }
2955
2956                 ClearLastResult();
2957         }
2958
2959         __initVisibleState = true;
2960 }
2961
2962 bool
2963 _Control::IsLayoutable(void) const
2964 {
2965         ClearLastResult();
2966         return IsMovable();
2967 }
2968
2969 bool
2970 _Control::IsClipToParent(void) const
2971 {
2972         ClearLastResult();
2973 //      SysAssert(GetVisualElement()->IsClipToParent() == __clipToParent);
2974         return __clipToParent;
2975 }
2976
2977 result
2978 _Control::SetClipToParent(bool clipToParent)
2979 {
2980         ClearLastResult();
2981         result r = E_SUCCESS;
2982
2983         __clipToParent = clipToParent;
2984         r =  GetVisualElement()->SetClipToParent(clipToParent);
2985         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2986
2987         return E_SUCCESS;
2988 }
2989
2990 result
2991 _Control::SetClipChildrenEnabled(bool clipChildren)
2992 {
2993         ClearLastResult();
2994         //result r = E_SUCCESS;
2995
2996         GetVisualElement()->SetClipChildrenEnabled(clipChildren);
2997         //SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2998
2999         return E_SUCCESS;
3000 }
3001
3002 Rectangle
3003 _Control::GetBounds(void) const
3004 {
3005         ClearLastResult();
3006         return _CoordinateSystemUtils::ConvertToInteger(__bounds);
3007 }
3008
3009 FloatRectangle
3010 _Control::GetBoundsF(void) const
3011 {
3012         ClearLastResult();
3013         return __bounds;
3014 }
3015
3016 Point
3017 _Control::GetPosition(void) const
3018 {
3019         ClearLastResult();
3020         return Point(_CoordinateSystemUtils::ConvertToInteger(__bounds.x), _CoordinateSystemUtils::ConvertToInteger(__bounds.y));
3021 }
3022
3023 FloatPoint
3024 _Control::GetPositionF(void) const
3025 {
3026         ClearLastResult();
3027         return FloatPoint(__bounds.x, __bounds.y);
3028 }
3029
3030 Dimension
3031 _Control::GetSize(void) const
3032 {
3033         ClearLastResult();
3034         return Dimension(_CoordinateSystemUtils::ConvertToInteger(__bounds.width), _CoordinateSystemUtils::ConvertToInteger(__bounds.height));
3035 }
3036
3037 FloatDimension
3038 _Control::GetSizeF(void) const
3039 {
3040         ClearLastResult();
3041         return FloatDimension(__bounds.width, __bounds.height);
3042 }
3043
3044 // E_SYSTEM
3045 result
3046 _Control::UpdateBoundsOfVisualElement(const FloatRectangle& controlBounds)
3047 {
3048         FloatRectangle rect(controlBounds.x, controlBounds.y, controlBounds.width, controlBounds.height);
3049
3050         _Control* pParent = GetParent();
3051         if (__area == _CONTROL_AREA_CLIENT && pParent)
3052         {
3053                 const FloatRectangle clientBounds = pParent->GetClientBoundsF();
3054                 rect.x += clientBounds.x;
3055                 rect.y += clientBounds.y;
3056         }
3057
3058         GetVisualElement()->SetBounds(rect);
3059
3060         return E_SUCCESS;
3061 }
3062
3063 result
3064 _Control::AdjustAbsoluteBounds(_Control& control, bool update)
3065 {
3066         result r = E_SUCCESS;
3067
3068         if (update && (&control != this))
3069         {
3070                 FloatRectangle fbounds = control.GetBoundsF();
3071
3072                 if (control.IsLayoutChangable() == false)
3073                 {
3074                         r = control.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3075                 }
3076                 else
3077                 {
3078                         r = control.UpdateBoundsOfVisualElement(fbounds);
3079                 }
3080         }
3081
3082         for (int i = 0; i < control.GetChildCount(); ++i)
3083         {
3084                 _Control* pChild = control.GetChild(i);
3085                 if (pChild)
3086                 {
3087
3088                         if (pChild == this)
3089                         {
3090                                 r = AdjustAbsoluteBounds(*pChild, false);
3091                         }
3092                         else
3093                         {
3094                                 r = AdjustAbsoluteBounds(*pChild);
3095                         }
3096                         if (IsFailed(r))
3097                         {
3098                                 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
3099                         }
3100                 }
3101         }
3102
3103         return r;
3104 }
3105
3106 bool
3107 _Control::IsInSizeRange(const Dimension& size) const
3108 {
3109         return (__minSize.width <= size.width) && (size.width <= __maxSize.width) &&
3110                    (__minSize.height <= size.height) && (size.height <= __maxSize.height);
3111 }
3112
3113 bool
3114 _Control::IsInSizeRange(const FloatDimension& size) const
3115 {
3116         return (_FloatCompareLE(__minSize.width, size.width)) && (_FloatCompareLE(size.width, __maxSize.width)) &&
3117                    (_FloatCompareLE(__minSize.height, size.height)) && (_FloatCompareLE(size.height, __maxSize.height));
3118 }
3119
3120 // Custom Exception: ex) Location::Map
3121 result
3122 _Control::SetBoundsFinal(const FloatRectangle& newBounds, bool changeLayoutBaseRect, bool callBoundsChangeCallbacks)
3123 {
3124         result r = E_SUCCESS;
3125
3126         FloatRectangle bounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
3127
3128         _IControlDelegate& delegate = GetControlDelegate();
3129
3130         const bool moved   = (__bounds.x != bounds.x) || (__bounds.y != bounds.y);
3131         const bool resized = (__bounds.width != bounds.width) || (__bounds.height != bounds.height);
3132
3133         if ((moved || resized) && callBoundsChangeCallbacks)
3134         {
3135                 r = delegate.OnBoundsChanging(_CoordinateSystemUtils::ConvertToInteger(bounds));
3136                 if (IsFailed(r))
3137                 {
3138                         SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3139                         return r; // Relay the result;
3140                 }
3141                 r = delegate.OnBoundsChanging(bounds);
3142                 if (IsFailed(r))
3143                 {
3144                         SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3145                         return r; // Relay the result;
3146                 }
3147         }
3148
3149         if (moved || resized)
3150         {
3151                 const FloatRectangle fbounds(bounds.x, bounds.y, bounds.width, bounds.height);
3152                 if (IsLayoutChangable() == false)
3153                 {
3154                         r = UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3155                 }
3156                 else
3157                 {
3158                         bool isAdjustPosition = false;
3159                         
3160                         _Window* pWindow = dynamic_cast<_Window*>(this);
3161                         _Window* pRootWindow = null;
3162                         if (pWindow)
3163                         {
3164                                 _WindowType winType = pWindow->GetWindowType();
3165                                 if (winType == _WINDOW_TYPE_VE)
3166                                 {
3167                                         _Control* pOwner = pWindow->GetOwner();
3168                                         if (pOwner)
3169                                         {
3170                                                 pRootWindow = pOwner->GetRootWindow();
3171                                                 if (pRootWindow)
3172                                                 {
3173                                                         if (pRootWindow->IsLayoutChangable() == false)
3174                                                         {
3175                                                                 isAdjustPosition = true;
3176                                                         }
3177                                                 }
3178                                         }
3179                                 }
3180                         }
3181
3182                         if (isAdjustPosition == true)
3183                         {
3184                                 FloatPoint ownerPosition = pRootWindow->GetPositionF();
3185                                 r = UpdateBoundsOfVisualElement(FloatRectangle(fbounds.x - ownerPosition.x, fbounds.y - ownerPosition.y, fbounds.width, fbounds.height));
3186                         }
3187                         else
3188                         {
3189                                 r = UpdateBoundsOfVisualElement(fbounds);
3190                         }
3191                 }
3192         }
3193
3194         SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
3195
3196         __bounds = bounds;
3197
3198         if (changeLayoutBaseRect)
3199         {
3200                 __pLayoutContainer->OnChangeBaseRect();
3201         }
3202
3203         if ((moved || resized) && callBoundsChangeCallbacks)
3204         {
3205                 if (IsMovable() && IsResizable())
3206                 {
3207                         SetClientBounds(FloatRectangle(0.0f, 0.0f, GetSizeF().width, GetSizeF().height));
3208                 }
3209                 if (__pFocusVisualElement)
3210                 {
3211                         __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, __bounds.width, __bounds.height));
3212                 }
3213                 delegate.OnBoundsChanged();
3214
3215                 _Control* pParent = GetParent();
3216                 if (pParent)
3217                 {
3218                         pParent->GetControlDelegate().OnChildBoundsChanged(*this);
3219                 }
3220
3221                 ControlList& children = GetChildList();
3222                 _Control* pChild = null;
3223                 int childrenCount = children.GetCount();
3224
3225                 for (int index = 0; index < childrenCount; index++)
3226                 {
3227                         r = children.GetAt(index, pChild);
3228                         if (!IsFailed(r))
3229                         {
3230                                 pChild->GetControlDelegate().OnParentBoundsChanged(*this);
3231                         }
3232                 }
3233         }
3234
3235         if (moved || resized)
3236         {
3237                 InvalidateHierarchyAbsoluteBounds(*this);
3238         }
3239
3240         ClearLastResult();
3241         return E_SUCCESS;
3242 }
3243
3244 // Custom Exception: ex) Location::Map
3245 result
3246 _Control::AdjustSizeToRange(void)
3247 {
3248         ClearLastResult();
3249         result r = E_SUCCESS;
3250
3251         SysAssert(IsResizable());
3252
3253         FloatDimension size = GetSizeF();
3254         bool changed = ::AdjustSizeToRange(size, __minSize, __maxSize);
3255         if (!changed)
3256         {
3257                 return E_SUCCESS;
3258         }
3259
3260         FloatRectangle newBounds(__bounds.x, __bounds.y, size.width, size.height);
3261         r = SetBoundsFinal(newBounds, true, true);
3262         if (IsFailed(r))
3263         {
3264                 return r;
3265         }
3266
3267         return E_SUCCESS;
3268 }
3269
3270 // Custom Exception: ex) Location::Map
3271 // E_INVALID_ARG
3272 result
3273 _Control::SetBoundsInternal(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3274 {
3275         SysTryReturn(NID_UI,
3276                                 IsInSizeRange(FloatDimension(bounds.width, bounds.height)), E_INVALID_ARG,
3277                                 E_INVALID_ARG,
3278                                 "[E_INVALID_ARG] The specified size(%f, %f) is out of range from min size(%f, %f) to max size(%f, %f).",
3279                                 bounds.width, bounds.height, __minSize.width, __minSize.height, __maxSize.width, __maxSize.height);
3280
3281         SetUpdateLayoutState(true);
3282
3283         return SetBoundsFinal(bounds, true, callBoundsChangeCallbacks);
3284 }
3285
3286 // Custom Exception: ex) Location::Map
3287 // E_INVALID_ARG
3288 // E_UNSUPPORTED_OPERATION
3289 result
3290 _Control::SetBounds(const Rectangle& bounds, bool callBoundsChangeCallbacks)
3291 {
3292         ClearLastResult();
3293
3294         __isChangedPositionByUser = true;
3295
3296         if (callBoundsChangeCallbacks)
3297         {
3298                 SysTryReturn(NID_UI,
3299                                         IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3300                                         E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3301         }
3302         FloatRectangle floatBounds(bounds.x, bounds.y, bounds.width, bounds.height);
3303
3304         return SetBoundsInternal(floatBounds, callBoundsChangeCallbacks);
3305 }
3306
3307 // Custom Exception: ex) Location::Map
3308 // E_INVALID_ARG
3309 // E_UNSUPPORTED_OPERATION
3310 result
3311 _Control::SetBounds(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3312 {
3313         ClearLastResult();
3314
3315         __isChangedPositionByUser = true;
3316
3317         if (callBoundsChangeCallbacks)
3318         {
3319                 SysTryReturn(NID_UI,
3320                                         IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3321                                         E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3322         }
3323
3324         return SetBoundsInternal(bounds, callBoundsChangeCallbacks);
3325 }
3326
3327 // A custom Exception can occur. ex) Location::Map
3328 // E_INVALID_ARG
3329 // E_UNSUPPORTED_OPERATION
3330 result
3331 _Control::SetPosition(const Point& position)
3332 {
3333         ClearLastResult();
3334
3335         __isChangedPositionByUser = true;
3336
3337         SysTryReturn(NID_UI,
3338                                 IsMovable(), E_UNSUPPORTED_OPERATION,
3339                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3340
3341         return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3342 }
3343
3344 result
3345 _Control::SetPosition(const FloatPoint& position)
3346 {
3347         ClearLastResult();
3348
3349         __isChangedPositionByUser = true;
3350
3351         SysTryReturn(NID_UI,
3352                                 IsMovable(), E_UNSUPPORTED_OPERATION,
3353                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3354
3355         return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3356 }
3357
3358 // Custom Exception: ex) Location::Map
3359 // E_INVALID_ARG
3360 // E_UNSUPPORTED_OPERATION
3361 result
3362 _Control::SetSize(const Dimension& size)
3363 {
3364         ClearLastResult();
3365
3366         SysTryReturn(NID_UI,
3367                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3368                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3369
3370         return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3371 }
3372
3373 result
3374 _Control::SetSize(const FloatDimension& size)
3375 {
3376         ClearLastResult();
3377
3378         SysTryReturn(NID_UI,
3379                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3380                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3381
3382         return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3383 }
3384
3385 bool
3386 _Control::IsChangedPositionByUser(void) const
3387 {
3388         return __isChangedPositionByUser;
3389 }
3390
3391 void
3392 _Control::SetChangedPositionByUser(bool change)
3393 {
3394         __isChangedPositionByUser = change;
3395 }
3396
3397 Dimension
3398 _Control::GetMinimumSize(void) const
3399 {
3400         ClearLastResult();
3401
3402         return _CoordinateSystemUtils::ConvertToInteger(__minSize);
3403 }
3404
3405 FloatDimension
3406 _Control::GetMinimumSizeF(void) const
3407 {
3408         ClearLastResult();
3409
3410         return __minSize;
3411 }
3412
3413 Dimension
3414 _Control::GetMaximumSize(void) const
3415 {
3416         ClearLastResult();
3417
3418         return _CoordinateSystemUtils::ConvertToInteger(__maxSize);
3419 }
3420
3421 FloatDimension
3422 _Control::GetMaximumSizeF(void) const
3423 {
3424         ClearLastResult();
3425
3426         return __maxSize;
3427 }
3428
3429 // Custom Exception: ex) Location::Map
3430 // E_UNSUPPORTED_OPERATION
3431 // E_INVALID_ARG
3432 result
3433 _Control::SetMinimumSize(const Dimension& newMinSize)
3434 {
3435         ClearLastResult();
3436
3437         SysTryReturn(NID_UI,
3438                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3439                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3440
3441         SysTryReturn(NID_UI,
3442                                 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3443                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3444
3445         SysTryReturn(NID_UI,
3446                                 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3447                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3448
3449         if (__maxSize.width < newMinSize.width)
3450         {
3451                 __maxSize.width = newMinSize.width;
3452         }
3453         if (__maxSize.height < newMinSize.height)
3454         {
3455                 __maxSize.height = newMinSize.height;
3456         }
3457
3458         __minSize = _CoordinateSystemUtils::ConvertToFloat(newMinSize);
3459         return AdjustSizeToRange();
3460 }
3461
3462 result
3463 _Control::SetMinimumSize(const FloatDimension& newMinSize)
3464 {
3465         ClearLastResult();
3466
3467         SysTryReturn(NID_UI,
3468                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3469                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3470
3471         SysTryReturn(NID_UI,
3472                                 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3473                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3474
3475         SysTryReturn(NID_UI,
3476                                 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3477                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3478
3479         if (__maxSize.width < newMinSize.width)
3480         {
3481                 __maxSize.width = newMinSize.width;
3482         }
3483         if (__maxSize.height < newMinSize.height)
3484         {
3485                 __maxSize.height = newMinSize.height;
3486         }
3487
3488         __minSize = newMinSize;
3489         return AdjustSizeToRange();
3490 }
3491
3492 // Custom Exception: ex) Location::Map
3493 // E_UNSUPPORTED_OPERATION
3494 // E_INVALID_ARG
3495 result
3496 _Control::SetMaximumSize(const Dimension& newMaxSize)
3497 {
3498         ClearLastResult();
3499
3500         SysTryReturn(NID_UI,
3501                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3502                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3503
3504         SysTryReturn(NID_UI,
3505                                 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3506                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3507
3508         SysTryReturn(NID_UI,
3509                                 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3510                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3511
3512         if (newMaxSize.width < __minSize.width)
3513         {
3514                 __minSize.width = newMaxSize.width;
3515         }
3516         if (newMaxSize.height < __minSize.height)
3517         {
3518                 __minSize.height = newMaxSize.height;
3519         }
3520
3521         __maxSize = _CoordinateSystemUtils::ConvertToFloat(newMaxSize);
3522         return AdjustSizeToRange();
3523 }
3524
3525 result
3526 _Control::SetMaximumSize(const FloatDimension& newMaxSize)
3527 {
3528         ClearLastResult();
3529
3530         SysTryReturn(NID_UI,
3531                                 IsResizable(), E_UNSUPPORTED_OPERATION,
3532                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3533
3534         SysTryReturn(NID_UI,
3535                                 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3536                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3537
3538         SysTryReturn(NID_UI,
3539                                 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3540                                 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3541
3542         if (newMaxSize.width < __minSize.width)
3543         {
3544                 __minSize.width = newMaxSize.width;
3545         }
3546         if (newMaxSize.height < __minSize.height)
3547         {
3548                 __minSize.height = newMaxSize.height;
3549         }
3550
3551         __maxSize = newMaxSize;
3552         return AdjustSizeToRange();
3553 }
3554
3555
3556 Point
3557 _Control::ConvertToControlPosition(const Point& screenPosition) const
3558 {
3559         Point controlPosition;
3560         Rectangle absoluteBounds = GetAbsoluteBounds();
3561
3562         controlPosition.x = screenPosition.x - absoluteBounds.x;
3563         controlPosition.y = screenPosition.y - absoluteBounds.y;
3564
3565         return controlPosition;
3566 }
3567
3568 FloatPoint
3569 _Control::ConvertToControlPosition(const FloatPoint& screenPosition) const
3570 {
3571         FloatPoint controlPosition;
3572         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3573
3574         controlPosition.x = screenPosition.x - absoluteBounds.x;
3575         controlPosition.y = screenPosition.y - absoluteBounds.y;
3576
3577         return controlPosition;
3578 }
3579
3580 Point
3581 _Control::ConvertToScreenPosition(const Point& controlPosition) const
3582 {
3583         Point screenPosition;
3584         Rectangle absoluteBounds = GetAbsoluteBounds();
3585
3586         screenPosition.x = controlPosition.x + absoluteBounds.x;
3587         screenPosition.y = controlPosition.y + absoluteBounds.y;
3588
3589         return screenPosition;
3590 }
3591
3592 FloatPoint
3593 _Control::ConvertToScreenPosition(const FloatPoint& controlPosition) const
3594 {
3595         FloatPoint screenPosition;
3596         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3597
3598         screenPosition.x = controlPosition.x + absoluteBounds.x;
3599         screenPosition.y = controlPosition.y + absoluteBounds.y;
3600
3601         return screenPosition;
3602 }
3603
3604 Rectangle
3605 _Control::GetClientBounds(void) const
3606 {
3607         if (!__isSetClientBounds)
3608         {
3609                 return Rectangle(0, 0, __bounds.width, __bounds.height);
3610         }
3611
3612         return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3613 }
3614
3615 FloatRectangle
3616 _Control::GetClientBoundsF(void) const
3617 {
3618         if (!__isSetClientBounds)
3619         {
3620                 return FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height);
3621         }
3622
3623         return __clientBounds;
3624 }
3625
3626
3627 Rectangle
3628 _Control::GetClientBounds(const Tizen::Graphics::Dimension& size) const
3629 {
3630         if (!__isSetClientBounds)
3631         {
3632                 return Rectangle(0, 0, size.width, size.height);
3633         }
3634
3635         return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3636 }
3637
3638
3639 FloatRectangle
3640 _Control::GetClientBoundsF(const Tizen::Graphics::FloatDimension& size) const
3641 {
3642         if (!__isSetClientBounds)
3643         {
3644                 return FloatRectangle(0.0f, 0.0f, size.width, size.height);
3645         }
3646
3647         return __clientBounds;
3648 }
3649
3650 Rectangle
3651 _Control::GetAbsoluteBounds(bool recalcAlways) const
3652 {
3653         if (!recalcAlways && !__needRecalcAbsBounds)
3654         {
3655                 return __absoluteBounds;
3656         }
3657
3658         Point accumPoint;
3659         Rectangle absoluteBounds;
3660         Rectangle clientBounds;
3661
3662         const _Control* pSelf = this;
3663         const _Control* pParent = GetParent();
3664         bool needRecalc = true;
3665
3666         while (pParent)
3667         {
3668                 if (pParent->__needRecalcAbsBounds)
3669                 {
3670                         if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT))
3671                         {
3672                                 clientBounds = pParent->GetClientBounds();
3673                                 accumPoint += Point(clientBounds.x, clientBounds.y);
3674                                 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3675                                 accumPoint.y -= pParent->GetVerticalScrollPosition();
3676                         }
3677
3678                         accumPoint += pSelf->GetPosition();
3679                         pSelf = pParent;
3680                         pParent = pParent->GetParent();
3681                 }
3682                 else
3683                 {
3684                         Rectangle parentAbsoluteBounds = pParent->GetAbsoluteBounds(false);
3685                         accumPoint += Point(parentAbsoluteBounds.x, parentAbsoluteBounds.y);
3686
3687                         if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT))
3688                         {
3689                                 clientBounds = pParent->GetClientBounds();
3690                                 accumPoint += Point(clientBounds.x, clientBounds.y);
3691                                 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3692                                 accumPoint.y -= pParent->GetVerticalScrollPosition();
3693                         }
3694
3695                         accumPoint += pSelf->GetPosition();
3696                         needRecalc = false;
3697                         break;
3698                 }
3699         }
3700
3701         if (needRecalc)
3702         {
3703                 _Window* pWindow = GetRootWindow();
3704                 if (pWindow)
3705                 {
3706                         Point winPoint = pWindow->GetPosition();
3707                         accumPoint.x += winPoint.x;
3708                         accumPoint.y += winPoint.y;
3709                 }
3710         }
3711
3712         absoluteBounds.x = accumPoint.x;
3713         absoluteBounds.y = accumPoint.y;
3714         absoluteBounds.width = __bounds.width;
3715         absoluteBounds.height = __bounds.height;
3716
3717         const_cast<_Control*>(this)->__absoluteBounds = absoluteBounds;
3718         const_cast<_Control*>(this)->__needRecalcAbsBounds = false;
3719
3720         return absoluteBounds;
3721 }
3722
3723 FloatRectangle
3724 _Control::GetAbsoluteBoundsF(bool recalcAlways) const
3725 {
3726         if (!recalcAlways && !__needRecalcAbsBoundsF)
3727         {
3728                 return __absoluteBoundsF;
3729         }
3730
3731         FloatPoint accumPoint;
3732         FloatRectangle absoluteBounds;
3733         FloatRectangle clientBounds;
3734
3735         const _Control* pSelf = this;
3736         const _Control* pParent = GetParent();
3737         bool needRecalc = true;
3738
3739         while (pParent)
3740         {
3741                 if (pParent->__needRecalcAbsBounds)
3742                 {
3743                         if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3744                         {
3745                                 clientBounds = pParent->GetClientBoundsF();
3746                                 accumPoint += FloatPoint(clientBounds.x, clientBounds.y);
3747                                 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3748                                 accumPoint.y -= pParent->GetVerticalScrollPosition();
3749                         }
3750
3751                         accumPoint += pSelf->GetPositionF();
3752                         pSelf = pParent;
3753                         pParent = pParent->GetParent();
3754                 }
3755                 else
3756                 {
3757                         FloatRectangle parentAbsoluteBounds = pParent->GetAbsoluteBoundsF(false);
3758                         accumPoint += FloatPoint(parentAbsoluteBounds.x, parentAbsoluteBounds.y);
3759
3760                         if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3761                         {
3762                                 clientBounds = pParent->GetClientBoundsF();
3763                                 accumPoint += FloatPoint(clientBounds.x, clientBounds.y);
3764                                 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3765                                 accumPoint.y -= pParent->GetVerticalScrollPosition();
3766                         }
3767
3768                         accumPoint += pSelf->GetPositionF();
3769                         needRecalc = false;
3770                         break;
3771                 }
3772         }
3773
3774         if (needRecalc)
3775         {
3776                 _Window* pWindow = GetRootWindow();
3777                 if (pWindow)
3778                 {
3779                         FloatPoint winPoint = pWindow->GetPositionF();
3780                         accumPoint.x += winPoint.x;
3781                         accumPoint.y += winPoint.y;
3782                 }
3783         }
3784
3785         absoluteBounds.x = accumPoint.x;
3786         absoluteBounds.y = accumPoint.y;
3787         absoluteBounds.width = __bounds.width;
3788         absoluteBounds.height = __bounds.height;
3789
3790         const_cast<_Control*>(this)->__absoluteBoundsF = absoluteBounds;
3791         const_cast<_Control*>(this)->__needRecalcAbsBoundsF = false;
3792
3793         return absoluteBounds;
3794 }
3795
3796 result
3797 _Control::SetClientBounds(const Rectangle& bounds)
3798 {
3799         ClearLastResult();
3800
3801         const bool moved   = (__clientBounds.x != _CoordinateSystemUtils::ConvertToFloat(bounds).x) || (__clientBounds.y != _CoordinateSystemUtils::ConvertToFloat(bounds).y);
3802         const bool resized = (__clientBounds.width != _CoordinateSystemUtils::ConvertToFloat(bounds).width) || (__clientBounds.height != _CoordinateSystemUtils::ConvertToFloat(bounds).height);
3803
3804         SysTryReturn(NID_UI,
3805                                 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3806                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3807         __clientBounds = _CoordinateSystemUtils::ConvertToFloat(bounds);
3808         __isSetClientBounds = true;
3809
3810         if (moved || resized)
3811         {
3812                 result r = AdjustAbsoluteBounds(*this);
3813                 SysTryReturn(NID_UI, r == E_SUCCESS, r,         r, "[%s] Propagating.", GetErrorMessage(r));
3814
3815                 SetUpdateLayoutState(true);
3816                 InvalidateHierarchyAbsoluteBounds(*this);
3817         }
3818         return E_SUCCESS;
3819 }
3820
3821 result
3822 _Control::SetClientBounds(const FloatRectangle& bounds)
3823 {
3824         ClearLastResult();
3825
3826         const bool moved   = (__clientBounds.x != bounds.x) || (__clientBounds.y != bounds.y);
3827         const bool resized = (__clientBounds.width != bounds.width) || (__clientBounds.height != bounds.height);
3828
3829         SysTryReturn(NID_UI,
3830                                 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3831                                 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3832         __clientBounds = bounds;
3833         __isSetClientBounds = true;
3834
3835         if (moved || resized)
3836         {
3837                 result r = AdjustAbsoluteBounds(*this);
3838                 SysTryReturn(NID_UI, r == E_SUCCESS, r,         r, "[%s] Propagating.", GetErrorMessage(r));
3839
3840                 SetUpdateLayoutState(true);
3841                 InvalidateHierarchyAbsoluteBounds(*this);
3842         }
3843
3844         return E_SUCCESS;
3845 }
3846
3847 bool
3848 _Control::IsCalledSetClientBounds(void) const
3849 {
3850         return __isSetClientBounds;
3851 }
3852
3853 void
3854 _Control::UpdateClientBounds(const FloatDimension& size, FloatRectangle& clientBounds)
3855 {
3856         clientBounds.width = size.width;
3857         clientBounds.height = size.height;
3858 }
3859
3860 Color
3861 _Control::GetBackgroundColor(void) const
3862 {
3863         ClearLastResult();
3864         return __backgroundColor;
3865 }
3866
3867 void
3868 _Control::SetBackgroundColor(const Color& color)
3869 {
3870         ClearLastResult();
3871         __backgroundColor = color;
3872
3873         _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(GetVisualElement());
3874         if (pCVE)
3875         {
3876                 pCVE->SetBackgroundColor(
3877                         _Colorf(
3878                                 (float)color.GetRed() / 255.0f,
3879                                 (float)color.GetGreen() / 255.0f,
3880                                 (float)color.GetBlue() / 255.0f,
3881                                 (float)color.GetAlpha() / 255.0f
3882                         )
3883                 );
3884         }
3885
3886         GetControlDelegate().OnBackgroundColorChanged(const_cast<Color&>(color));
3887         ClearLastResult();
3888 }
3889
3890 _Control::~_Control(void)
3891 {
3892         if (!__destroying)
3893         {
3894                 __destroying = true;
3895         }
3896
3897         DoBacktrace(__pDeleteBacktrace.get());
3898
3899         DetachAllChildren();
3900         DetachAllOwnees();
3901         _ControlManager::GetInstance()->TakeFocusFromControl(*this);
3902         DisposeControl();
3903         ReleaseHandle();
3904
3905         if (__pFont)
3906         {
3907                 delete __pFont;
3908                 __pFont = null;
3909         }
3910
3911 //      Dangerous: it clears last result and log in catch block.
3912 //      ClearLastResult();
3913 }
3914
3915 void
3916 _Control::DisposeControl(void)
3917 {
3918         __pControlDelegate = null;
3919
3920         delete __pLayoutItemHandler;
3921         __pLayoutItemHandler = null;
3922
3923         delete __pLayoutContainer;
3924         __pLayoutContainer = null;
3925
3926         delete __pChildren;
3927         __pChildren = null;
3928
3929         delete __pOwnees;
3930         __pOwnees = null;
3931
3932         if (__pVisualElement)
3933         {
3934                 __pVisualElement->Destroy();
3935         }
3936         __pVisualElement = null;
3937
3938         delete __pVisualElementContentProvider;
3939         __pVisualElementContentProvider = null;
3940
3941         delete __pVisualElementEventListener;
3942         __pVisualElementEventListener = null;
3943
3944         delete __pCoreGestureDetectors;
3945         __pCoreGestureDetectors = null;
3946
3947         delete __pDataBindingContext;
3948         __pDataBindingContext = null;
3949
3950         ClearStartedGestureDetectorList();
3951         delete __pDetectStartedGestureMap;
3952         __pDetectStartedGestureMap = null;
3953
3954         delete __pDelayedTouchInfoList;
3955         __pDelayedTouchInfoList = null;
3956
3957         delete __pAccessibilityContainer;
3958         __pAccessibilityContainer = null;
3959
3960         if (__pFocusVisualElement)
3961         {
3962                 __pFocusVisualElement.release();
3963         }
3964 }
3965
3966 // E_OUT_OF_MEMORY
3967 // E_SYSTEM
3968 _Control::_Control(void)
3969         : __needRecalcRootWindow(true)
3970         , __needRecalcAbsBounds(true)
3971         , __needRecalcAbsBoundsF(true)
3972         , __pRootWindow(null)
3973         , __name(L"")
3974         , __pParent(null)
3975         , __pChildren(null)
3976         , __pOwnees(null)
3977         , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
3978         , __contentAreaBounds(0.0f, 0.0f, 0.0f, 0.0f)
3979         , __clientBounds(0.0f, 0.0f, 0.0f, 0.0f)
3980         , __absoluteBounds(0, 0, 0, 0)
3981         , __absoluteBoundsF(0.0f, 0.0f, 0.0f, 0.0f)
3982         , __invalidatedBounds(0.0f, 0.0f, 0.0f, 0.0f)
3983         , __minSize(FloatDimension(0.0f, 0.0f))
3984         , __maxSize(FloatDimension(MAX_LENGTH, MAX_LENGTH))
3985         , __backgroundColor(Color::GetColor(COLOR_ID_BLACK))
3986         , __movable(true)
3987         , __resizable(true)
3988         , __focusable(true)
3989         , __nativeObjectFocusable(true)
3990         , __enabledState(true)
3991         , __visibleState(true)
3992         , __initVisibleState(false)
3993         , __clipToParent(true)
3994         , __multiTouchEnabled(false)
3995         , __dragEnabled(false)
3996         , __dropEnabled(false)
3997         , __drawWhenVisible(true)
3998         , __isPostOrderTraversal(false)
3999         , __isCalledCallOnAttachingToMainTree(false)
4000         , __isCalledCallOnPreAttachedToMainTree(false)
4001         , __isCalledCallOnAttachedToMainTree(false)
4002         , __isSetClientBounds(false)
4003         , __isCalledGetCanvasN(false)
4004         , __isFocusMode(false)
4005         , __isNavigatable(true)
4006         , __isFocusWindowActivationChecked(false)
4007         , __isChangedPositionByUser(false)
4008         , __pVisualElementContentProvider(null)
4009         , __pVisualElement(null)
4010         , __pVisualElementEventListener(null)
4011         , __pLayoutItemHandler(null)
4012         , __pPortraitLayout(null)
4013         , __pLandscapeLayout(null)
4014         , __pLayoutContainer(null)
4015         , __area(_CONTROL_AREA_NONE)
4016         , __layer(_CONTROL_LAYER_NONE)
4017         , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
4018         , __rotation(_CONTROL_ROTATION_0)
4019         , __pTouchEventPreviewer(null)
4020         , __pKeyEventPreviewer(null)
4021         , __pNotificationEventPreviewer(null)
4022         , __pKeyEventListener(null)
4023         , __pFocusEventListener(null)
4024         , __pNotificationEventListener(null)
4025         , __pCoreGestureDetectors(null)
4026         , __pDetectStartedGestureMap(null)
4027         , __pDelayedTouchInfoList(null)
4028         , __touchMoveAllowance(3)
4029         , __pressThresHold(0.0f)
4030         , __inputLockRefCount(0)
4031         , __screenDpi(0)
4032         , __isSentDelayedEvent(false)
4033         , __isSendingDelayedEvent(false)
4034         , __isChangingEventTarget(false)
4035         , __pDataBindingContext(null)
4036         , __pControlDelegate(null)
4037         , __pUserData(null)
4038         , __destroying(false)
4039         , __isEventEnableState(true)
4040         , __isEffectSoundEnabled(true)
4041         , __isControlFontChanged(false)
4042         , __pFont(null)
4043         , __fontName(L"")
4044         , __fontFileName(L"")
4045         , __pPreviousFocus(null)
4046         , __pNextFocus(null)
4047         , __pDragWindow(null)
4048         , __isDragAndDropSource(false)
4049 {
4050         ClearLastResult();
4051
4052         std::unique_ptr<Tizen::Base::Collection::ArrayListT<void*> > pNewBacktrace(new (std::nothrow) ArrayListT<void*>);
4053         SysTryReturnVoidResult(NID_SHELL, pNewBacktrace, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4054
4055         result r = pNewBacktrace->Construct();
4056         SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
4057
4058         __pNewBacktrace = move(pNewBacktrace);
4059
4060 //      DoBacktrace(__pNewBacktrace.get());
4061
4062         std::unique_ptr<Tizen::Base::Collection::ArrayListT<void*> > pDeleteBacktrace(new (std::nothrow) ArrayListT<void*>);
4063         SysTryReturnVoidResult(NID_SHELL, pDeleteBacktrace, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4064
4065         r = pDeleteBacktrace->Construct();
4066         SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
4067
4068         __pDeleteBacktrace = move(pDeleteBacktrace);
4069
4070         SetControlDelegate(*this);
4071         __pAccessibilityContainer = new (std::nothrow) _AccessibilityContainer(*this);
4072         __pAccessibilityContainer->Activate(true);
4073
4074         __pLayoutItemHandler = new (std::nothrow) LayoutItemHandler(this);
4075         if (!__pLayoutItemHandler)
4076         {
4077                 goto CATCH;
4078         }
4079
4080         __pLayoutContainer = CreateLayoutContainerN(__pLayoutItemHandler);
4081         if (!__pLayoutContainer)
4082         {
4083                 goto CATCH;
4084         }
4085
4086         __pChildren = ::CreateControlListN();
4087         if (!__pChildren)
4088         {
4089                 goto CATCH;
4090         }
4091
4092         __pOwnees = ::CreateWindowListN();
4093         if (!__pOwnees)
4094         {
4095                 goto CATCH;
4096         }
4097
4098         __pVisualElement = ::CreateVisualElementN();
4099         if (!__pVisualElement)
4100         {
4101                 goto CATCH;
4102         }
4103
4104         __pVisualElement->SetUserData(this);
4105         __pVisualElement->SetClipChildrenEnabled(true);
4106         __pVisualElement->SetRedrawOnResizeEnabled(true);
4107
4108         __pVisualElementContentProvider = new (std::nothrow) ControlVisualElementContentProvider(*this);
4109         SysTryCatch(NID_UI, __pVisualElementContentProvider, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4110
4111         GetVisualElement()->SetContentProvider(__pVisualElementContentProvider);
4112
4113         __pVisualElementEventListener = new (std::nothrow) ControlVisualElementEventListener(*this);
4114         SysTryCatch(NID_UI, __pVisualElementEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4115
4116         GetVisualElement()->SetVisualElementEventListener(__pVisualElementEventListener);
4117
4118         __pDetectStartedGestureMap = ::CreateGestureMapN();
4119         if (!__pDetectStartedGestureMap)
4120         {
4121                 goto CATCH;
4122         }
4123
4124         __pCoreGestureDetectors = new (std::nothrow) LinkedListT<_TouchGestureDetector*>;
4125         if (!__pCoreGestureDetectors)
4126         {
4127                 goto CATCH;
4128         }
4129
4130         __pDelayedTouchInfoList = new (std::nothrow) LinkedListT<_TouchInfo*>;
4131         if (!__pDelayedTouchInfoList)
4132         {
4133                 goto CATCH;
4134         }
4135
4136         SetEventPreviewer<_UI_EVENT_TOUCH>(this);
4137         SetEventPreviewer<_UI_EVENT_KEY>(this);
4138         SetEventPreviewer<_UI_EVENT_NOTIFICAITON>(this);
4139
4140         SetEventListener<_UI_EVENT_NOTIFICAITON>(this);
4141         SetEventListener<_UI_EVENT_FOCUS>(this);
4142
4143         SetPropagatedTouchEventListener(this);
4144         SetPropagatedKeyEventListener(this);
4145         GET_COLOR_CONFIG(BASIC::background, __backgroundColor);
4146
4147         if (IsFailed(GetLastResult()))
4148         {
4149                 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
4150         }
4151
4152         __screenDpi = _ControlManager::GetInstance()->GetScreenDpi();
4153
4154         return;
4155
4156 CATCH:
4157         DisposeControl();
4158         return;
4159 }
4160
4161 void
4162 _Control::AcquireHandle(void)
4163 {
4164         __controlHandle = _ControlManager::GetInstance()->Register(this); // [ToDo] exception?
4165 }
4166
4167 void
4168 _Control::ReleaseHandle(void)
4169 {
4170         _ControlManager::GetInstance()->Release(__controlHandle); // [ToDo] exception?
4171 }
4172
4173 void
4174 _Control::SetDrawWhenVisible(bool draw)
4175 {
4176         __drawWhenVisible = draw;
4177 }
4178
4179 bool
4180 _Control::IsDrawWhenVisible(void) const
4181 {
4182         return __drawWhenVisible;
4183 }
4184
4185 void
4186 _Control::SetTerminatingOrder(bool postOrderTraversal)
4187 {
4188         __isPostOrderTraversal = postOrderTraversal;
4189 }
4190
4191 bool
4192 _Control::IsPostOrderTraversal(void) const
4193 {
4194         return __isPostOrderTraversal;
4195 }
4196
4197 void
4198 _Control::SetParent(_Control* pParent)
4199 {
4200         ClearLastResult();
4201         __pParent = pParent;
4202 }
4203
4204 // E_OUT_OF_MEMORY
4205 // Only called by _Window::SetOwner(pOwner)
4206 result
4207 _Control::AttachOwnee(_Window& window)
4208 {
4209         ClearLastResult();
4210         result r = E_SUCCESS;
4211
4212         _Control* pOldOwner = window.GetOwner();
4213         if (pOldOwner)
4214         {
4215                 pOldOwner->DetachOwnee(window);
4216         }
4217
4218         r = __pOwnees->Add(&window);
4219         if (IsFailed(r))
4220         {
4221                 SysLogException(NID_UI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4222                 return E_OUT_OF_MEMORY;
4223         }
4224
4225         return E_SUCCESS;
4226 }
4227
4228 int
4229 _Control::GetOwneeCount(void) const
4230 {
4231         ClearLastResult();
4232         return __pOwnees->GetCount();
4233 }
4234
4235 // E_OUT_OF_RANGE
4236 _Window*
4237 _Control::GetOwnee(int index) const
4238 {
4239         ClearLastResult();
4240         result r = E_SUCCESS;
4241
4242         _Window* pOwnee = null;
4243         r = __pOwnees->GetAt(index, pOwnee);
4244         if (IsFailed(r))
4245         {
4246                 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4247                 return null;
4248         }
4249
4250         return pOwnee;
4251 }
4252
4253 // Called by _Window::SetOwner(null)
4254 void
4255 _Control::DetachOwnee(_Window& ownee)
4256 {
4257         ClearLastResult();
4258         result r = E_SUCCESS;
4259
4260         _Control* pOwner = ownee.GetOwner();
4261         if (pOwner != this)
4262         {
4263                 return;
4264         }
4265
4266         r = __pOwnees->Remove(&ownee);
4267         if (IsFailed(r))
4268         {
4269                 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4270         }
4271 }
4272
4273 void
4274 _Control::DetachAllOwnees(void)
4275 {
4276         ClearLastResult();
4277
4278         int owneeCount = GetOwneeCount();
4279         while (owneeCount--)
4280         {
4281                 _Window* pOwnee = GetOwnee(0);
4282                 if (pOwnee == null)
4283                 {
4284                         continue;
4285                 }
4286
4287                 pOwnee->SetOwner(null);
4288         }
4289 }
4290
4291 _Layout::LayoutContainer&
4292 _Control::GetLayoutContainer() const
4293 {
4294         return *__pLayoutContainer;
4295 }
4296
4297 void
4298 _Control::SetMultiTouchEnabled(bool enabled)
4299 {
4300         ClearLastResult();
4301         __multiTouchEnabled = enabled;
4302 }
4303
4304 bool
4305 _Control::IsMultiTouchEnabled(void) const
4306 {
4307         ClearLastResult();
4308         return __multiTouchEnabled;
4309 }
4310
4311 void
4312 _Control::SetMovable(bool movable)
4313 {
4314         ClearLastResult();
4315         __movable = movable;
4316 }
4317
4318 void
4319 _Control::SetResizable(bool resizable)
4320 {
4321         ClearLastResult();
4322
4323         if (!resizable)
4324         {
4325                 __minSize = __maxSize = GetSizeF();
4326         }
4327
4328         if (!__resizable && resizable)
4329         {
4330                 __minSize = FloatDimension(0.0f, 0.0f);
4331                 __maxSize = FloatDimension(MAX_LENGTH, MAX_LENGTH);
4332         }
4333
4334         __resizable = resizable;
4335 }
4336
4337 _Layout::Layout*
4338 _Control::GetLayout(void) const
4339 {
4340         ClearLastResult();
4341         _Layout::Layout* pLayout = __pLayoutContainer->GetLayout();
4342
4343         SysAssert(GetLastResult() == E_SUCCESS);
4344         return pLayout;
4345 }
4346
4347 result
4348 _Control::SetCurrentLayout(_Layout::Layout& layout)
4349 {
4350         ClearLastResult();
4351         return __pLayoutContainer->SetCurrentLayout(layout);
4352 }
4353
4354 result
4355 _Control::AddLayout(_Layout::Layout& layout)
4356 {
4357         ClearLastResult();
4358         return __pLayoutContainer->AddLayout(layout);
4359 }
4360
4361 void
4362 _Control::SetUpdateLayoutState(bool state)
4363 {
4364         _Layout::Layout* pLayout = GetLayout();
4365         if (pLayout)
4366         {
4367                 pLayout->SetUpdateState(state);
4368         }
4369 }
4370
4371 void
4372 _Control::SetEffectSoundEnabled(bool enable)
4373 {
4374         __isEffectSoundEnabled = enable;
4375 }
4376
4377 bool
4378 _Control::IsEffectSoundEnabled(void) const
4379 {
4380         return __isEffectSoundEnabled;
4381 }
4382
4383 _DataBindingContext*
4384 _Control::GetDataBindingContext(void)
4385 {
4386         return __pDataBindingContext;
4387 }
4388 _AccessibilityContainer*
4389 _Control::GetAccessibilityContainer(void)
4390 {
4391         return __pAccessibilityContainer;
4392 }
4393 void
4394 _Control::SetDataBindingContext(_DataBindingContext* pDataBindingContext)
4395 {
4396         __pDataBindingContext = pDataBindingContext;
4397 }
4398
4399 void
4400 _Control::DoBacktrace(Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList)
4401 {
4402         SysTryReturnVoidResult(NID_SHELL, pBacktraceList, E_INVALID_ARG, "[E_INVALID_ARG].");
4403
4404         const static int ADDR_SIZE = 100;
4405         int retSize = 0;
4406         void* pBuffer[ADDR_SIZE];
4407
4408         retSize = backtrace(pBuffer, ADDR_SIZE);
4409         for (int i = 0; i < retSize; i++)
4410         {
4411                 if (pBuffer[i])
4412                 {
4413                         pBacktraceList->Add(pBuffer[i]);
4414                 }
4415         }
4416 }
4417
4418 void
4419 _Control::SetDestroying(bool destroying)
4420 {
4421         __destroying = destroying;
4422 }
4423
4424 bool
4425 _Control::IsDestroying(void) const
4426 {
4427         return __destroying;
4428 }
4429
4430 Tizen::Base::String
4431 _Control::GetDescription(void) const
4432 {
4433         return String(L"");
4434 }
4435
4436 void
4437 _Control::SetTouchCapture(bool allowOutOfBounds, bool allowOwnerBounds)
4438 {
4439         _TouchManager* pTouchManager = _TouchManager::GetInstance();
4440         SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4441
4442         pTouchManager->SetCapturedControl(this, allowOutOfBounds, allowOwnerBounds);
4443 }
4444
4445 void
4446 _Control::ReleaseTouchCapture(void)
4447 {
4448         _TouchManager* pTouchManager = _TouchManager::GetInstance();
4449         SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4450
4451         pTouchManager->SetCapturedControl(null, false, false);
4452 }
4453
4454 _Control*
4455 _Control::GetTopmostChildAt(const Point& point) const
4456 {
4457         _Control* pTouchedControl = null;
4458         FloatPoint ptf((float) point.x, (float) point.y);
4459         _ControlManager* pControlManager = _ControlManager::GetInstance();
4460         SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
4461
4462         _Window* pRootWindow = GetRootWindow();
4463         SysTryReturn(NID_UI, pRootWindow, null, E_SYSTEM, "[E_SYSTEM] GetRootWindow() is null, this control is detached from the main trree");
4464
4465         _ControlVisualElement* pRootControlElement = dynamic_cast <_ControlVisualElement*>(pRootWindow->GetVisualElement());
4466         SysTryReturn(NID_UI, pRootControlElement, null, E_SYSTEM, "[E_SYSTEM] pRootControlElement is null.");
4467
4468         _ControlVisualElement* pHitTestElm = pRootControlElement->GetControlChildAtPoint(ptf);
4469         if (pHitTestElm == null)
4470         {
4471                 SysSecureLog(NID_UI, "pHitTestElm is null, point(%f, %f)", ptf.x, ptf.y);
4472                 return null;
4473         }
4474
4475         pTouchedControl = static_cast <_Control*>(pHitTestElm->GetUserData());
4476
4477         return pTouchedControl;
4478 }
4479
4480 void
4481 _Control::SetContentAreaBounds(const Rectangle& rect)
4482 {
4483         ClearLastResult();
4484
4485         __contentAreaBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
4486 }
4487
4488 void
4489 _Control::SetContentAreaBounds(const FloatRectangle& rect)
4490 {
4491         ClearLastResult();
4492
4493         __contentAreaBounds = rect;
4494 }
4495
4496 Rectangle
4497 _Control::GetContentAreaBounds(void) const
4498 {
4499         return _CoordinateSystemUtils::ConvertToInteger(__contentAreaBounds);
4500 }
4501
4502 FloatRectangle
4503 _Control::GetContentAreaBoundsF(void) const
4504 {
4505         if (__contentAreaBounds != FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
4506         {
4507                 return __contentAreaBounds;
4508         }
4509         else
4510         {
4511                 _Layout::Layout* pLayout = GetLayout();
4512                 if (pLayout)
4513                 {
4514                         _Layout::LayoutMatchMode widthMatchMode = _Layout::NONE_MODE;
4515                         _Layout::LayoutMatchMode heightMatchMode = _Layout::NONE_MODE;
4516
4517                         _Layout::LayoutItem& layoutItem = GetLayoutContainer();
4518
4519                         pLayout->GetItemWidthMatchMode(layoutItem, widthMatchMode);
4520                         pLayout->GetItemHeightMatchMode(layoutItem, heightMatchMode);
4521
4522                         bool widthWrapContent = widthMatchMode == _Layout::WRAP_CONTENT;
4523                         bool heightWrapContent = heightMatchMode == _Layout::WRAP_CONTENT;
4524
4525                         if (widthWrapContent || heightWrapContent)
4526                         {
4527                                 FloatDimension contentSize = GetContentSizeF(widthWrapContent, heightWrapContent);
4528                                 return FloatRectangle(__bounds.x, __bounds.y, contentSize.width, contentSize.height);
4529                         }
4530                         else
4531                         {
4532                                 return __contentAreaBounds;
4533                         }
4534                 }
4535         }
4536 }
4537
4538 Bitmap*
4539 _Control::GetCapturedBitmapN(bool includeChildren) const
4540 {
4541         result r = E_SUCCESS;
4542
4543         Canvas* pCanvas = null;
4544         Bitmap* pBitmap = null;
4545
4546         pBitmap = GetControlDelegate().OnCapturedBitmapRequestedN();
4547         if (pBitmap == null)
4548         {
4549                 FloatRectangle rect;
4550
4551                 Rectangle boundsInCanvas = GetBounds();
4552                 boundsInCanvas.x = boundsInCanvas.y = 0;
4553
4554                 pCanvas = new (std::nothrow) Canvas;
4555                 SysTryReturn(NID_UI, pCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4556
4557                 r = pCanvas->Construct(boundsInCanvas);
4558                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4559
4560                 GetVisualElement()->Draw();
4561                 ClearLastResult();
4562
4563                 rect.SetBounds(boundsInCanvas.x, boundsInCanvas.y, boundsInCanvas.width, boundsInCanvas.height);
4564
4565                 r = GetVisualElement()->Capture(*pCanvas, rect, includeChildren);
4566                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4567
4568                 pBitmap = new (std::nothrow) Bitmap;
4569                 SysTryCatch(NID_UI, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4570
4571                 r = pBitmap->Construct(*pCanvas, boundsInCanvas);
4572                 if (IsFailed(r))
4573                 {
4574                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4575                 }
4576
4577                 SysLog(NID_UI, "Bitmap (width:%d, height:%d)", pBitmap->GetWidth(), pBitmap->GetHeight());
4578
4579                 delete pCanvas;
4580         }
4581         _BitmapImpl::ConvertToNonpremultiplied(*pBitmap, true);
4582
4583         return pBitmap;
4584
4585 CATCH:
4586         delete pCanvas;
4587         delete pBitmap;
4588         SetLastResult(r);
4589
4590         return null;
4591 }
4592
4593 Tizen::Graphics::Rectangle
4594 _Control::GetInvalidatedBounds(void) const
4595 {
4596         return _CoordinateSystemUtils::ConvertToInteger(__invalidatedBounds);
4597 }
4598
4599 Tizen::Graphics::FloatRectangle
4600 _Control::GetInvalidatedBoundsF(void) const
4601 {
4602         return __invalidatedBounds;
4603 }
4604
4605 result
4606 _Control::AddGestureDetector(const _TouchGestureDetector& gestureDetector)
4607 {
4608         ClearLastResult();
4609
4610         bool exist = __pCoreGestureDetectors->Contains(const_cast<_TouchGestureDetector*>(&gestureDetector));
4611         SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "__pCoreGestureDetectors has gesture already");
4612
4613         result r = __pCoreGestureDetectors->Add(const_cast<_TouchGestureDetector*>(&gestureDetector));
4614         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4615
4616         r = const_cast<_TouchGestureDetector&>(gestureDetector).SetControl(*this);
4617         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "Control handle is not valid.");
4618
4619         const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorAdded();
4620
4621         return r;
4622 }
4623
4624 result
4625 _Control::RemoveGestureDetector(const _TouchGestureDetector& gestureDetector)
4626 {
4627         ClearLastResult();
4628
4629         result r = __pCoreGestureDetectors->Remove(&(const_cast<_TouchGestureDetector&>(gestureDetector)));
4630         if (r != E_SUCCESS)
4631         {
4632                 return r;
4633         }
4634
4635         const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorRemoved();
4636
4637         return E_SUCCESS;
4638 }
4639
4640 IListT <_TouchGestureDetector*>*
4641 _Control::GetGestureDetectorList(void) const
4642 {
4643         return __pCoreGestureDetectors;
4644 }
4645
4646 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>*
4647 _Control::GetStartedGestureDetectorEnumeratorN(void) const
4648 {
4649         return __pDetectStartedGestureMap->GetMapEnumeratorN();
4650 }
4651
4652 IListT <_TouchGestureDetector*>*
4653 _Control::GetStartedGestureDetectorListN(void) const
4654 {
4655         return __pDetectStartedGestureMap->GetKeysN();
4656 }
4657
4658 result
4659 _Control::AddStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4660 {
4661         ClearLastResult();
4662
4663         result r = E_SUCCESS;
4664
4665         bool exist = false;
4666         __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4667
4668         if (exist == false)
4669         {
4670                 r = __pDetectStartedGestureMap->Add(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4671         }
4672
4673         return r;
4674 }
4675
4676 result
4677 _Control::SetStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4678 {
4679         ClearLastResult();
4680
4681         result r = E_SUCCESS;
4682
4683         bool exist = false;
4684         __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4685
4686         if (exist == true)
4687         {
4688                 r = __pDetectStartedGestureMap->SetValue(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4689         }
4690
4691         return r;
4692 }
4693
4694 result
4695 _Control::ClearStartedGestureDetectorList(void)
4696 {
4697         ClearLastResult();
4698
4699         result r = E_SUCCESS;
4700
4701         IListT<_TouchGestureDetector*>* pList = __pDetectStartedGestureMap->GetKeysN();
4702         if (pList)
4703         {
4704                 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pList->GetEnumeratorN();
4705                 if (pEnumerator)
4706                 {
4707                         while(pEnumerator->MoveNext() == E_SUCCESS)
4708                         {
4709                                 _TouchGestureDetector* pGestureDetector = null;
4710                                 pEnumerator->GetCurrent(pGestureDetector);
4711
4712                                 if (pGestureDetector == null)
4713                                 {
4714                                         continue;
4715                                 }
4716
4717                                 __pDetectStartedGestureMap->Remove(pGestureDetector);
4718                         }
4719                         delete pEnumerator;
4720                 }
4721                 delete pList;
4722         }
4723
4724         IEnumeratorT<_TouchInfo*>* pEnumerator = __pDelayedTouchInfoList->GetEnumeratorN();
4725         if(pEnumerator)
4726         {
4727                 while(pEnumerator->MoveNext() == E_SUCCESS)
4728                 {
4729                         _TouchInfo* pTouchInfo = null;
4730                         pEnumerator->GetCurrent(pTouchInfo);
4731                         if (pTouchInfo == null)
4732                         {
4733                                 continue;
4734                         }
4735
4736                         delete pTouchInfo;
4737                 }
4738
4739                 __pDelayedTouchInfoList->RemoveAll();
4740                 delete pEnumerator;
4741         }
4742
4743         __isSentDelayedEvent = false;
4744         __isSendingDelayedEvent = false;
4745
4746         return r;
4747 }
4748
4749 bool
4750 _Control::IsDelayedTouchEventEnabled(void) const
4751 {
4752         bool existDelayTouchEventGesture = false;
4753
4754         IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4755         if (pMapEnumerator)
4756         {
4757                 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4758                 {
4759                         _TouchGestureDetector* pGestureDetector = null;
4760                         pMapEnumerator->GetKey(pGestureDetector);
4761
4762                         if (pGestureDetector == null)
4763                         {
4764                                 continue;
4765                         }
4766
4767                         _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4768                         pMapEnumerator->GetValue(state);
4769
4770                         if (pGestureDetector->IsDelayTouchEventEnabled())
4771                         {
4772                                 existDelayTouchEventGesture = true;
4773                         }
4774                 }
4775                 delete pMapEnumerator;
4776         }
4777
4778         bool delayTouchEvent = false;
4779         if (existDelayTouchEventGesture)
4780         {
4781                 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4782                 if (pMapEnumerator)
4783                 {
4784                         while(pMapEnumerator->MoveNext() == E_SUCCESS)
4785                         {
4786                                 _TouchGestureDetector* pGestureDetector = null;
4787                                 pMapEnumerator->GetKey(pGestureDetector);
4788
4789                                 if (pGestureDetector == null)
4790                                 {
4791                                         continue;
4792                                 }
4793
4794                                 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4795                                 pMapEnumerator->GetValue(state);
4796
4797                                 if (state == _TOUCH_GESTURE_DETECTOR_STATE_STARTED)
4798                                 {
4799                                         delayTouchEvent = true;
4800                                         break;
4801                                 }
4802                         }
4803                         delete pMapEnumerator;
4804                 }
4805
4806                 return delayTouchEvent;
4807         }
4808         else
4809         {
4810                 return false;
4811         }
4812 }
4813
4814 bool
4815 _Control::IsPossibleToSendDelayedTouchEvent(void) const
4816 {
4817         bool existDelayTouchEventGesture = false;
4818
4819         IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4820         if (pMapEnumerator)
4821         {
4822                 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4823                 {
4824                         _TouchGestureDetector* pGestureDetector = null;
4825                         pMapEnumerator->GetKey(pGestureDetector);
4826
4827                         if (pGestureDetector == null)
4828                         {
4829                                 continue;
4830                         }
4831
4832                         _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4833                         pMapEnumerator->GetValue(state);
4834
4835                         if (pGestureDetector->IsDelayTouchEventEnabled())
4836                         {
4837                                 existDelayTouchEventGesture = true;
4838                         }
4839                 }
4840                 delete pMapEnumerator;
4841         }
4842
4843         bool allFailed = true;
4844         if (existDelayTouchEventGesture)
4845         {
4846                 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4847                 if (pMapEnumerator)
4848                 {
4849                         while(pMapEnumerator->MoveNext() == E_SUCCESS)
4850                         {
4851                                 _TouchGestureDetector* pGestureDetector = null;
4852                                 pMapEnumerator->GetKey(pGestureDetector);
4853
4854                                 if (pGestureDetector == null)
4855                                 {
4856                                         continue;
4857                                 }
4858
4859                                 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4860                                 pMapEnumerator->GetValue(state);
4861
4862                                 if (state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS)
4863                                 {
4864                                         allFailed = false;
4865                                         break;
4866                                 }
4867                         }
4868                         delete pMapEnumerator;
4869                 }
4870
4871                 return allFailed;
4872         }
4873         else
4874         {
4875                 return false;
4876         }
4877 }
4878
4879 bool
4880 _Control::IsCancelOnGestureSuccess(void) const
4881 {
4882         _TouchManager* pTouchManager = _TouchManager::GetInstance();
4883         SysAssert(pTouchManager != null);
4884
4885         IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4886         if (pMapEnumerator)
4887         {
4888                 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4889                 {
4890                         _TouchGestureDetector* pGestureDetector = null;
4891                         pMapEnumerator->GetKey(pGestureDetector);
4892
4893                         if (pGestureDetector == null)
4894                         {
4895                                 continue;
4896                         }
4897
4898                         _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4899                         pMapEnumerator->GetValue(state);
4900
4901                         if (pGestureDetector->IsCancelTouchEventOnSuccessEnabled() && state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS && !pTouchManager->IsTouchCanceledOnGestureSuccess())
4902                         {
4903                                 delete pMapEnumerator;
4904                                 return true;
4905                         }
4906                 }
4907                 delete pMapEnumerator;
4908         }
4909
4910         return false;
4911 }
4912
4913 bool
4914 _Control::IsSentDelayedEvent(void) const
4915 {
4916         return __isSentDelayedEvent;
4917 }
4918
4919 void
4920 _Control::SetSentDelayedEvent(bool sent)
4921 {
4922         __isSentDelayedEvent = sent;
4923 }
4924
4925 void
4926 _Control::SetSendingDelayedEvent(bool sending)
4927 {
4928         __isSendingDelayedEvent = sending;
4929 }
4930
4931 bool
4932 _Control::IsSendingDelayedEvent(void) const
4933 {
4934         return __isSendingDelayedEvent;
4935 }
4936
4937 void
4938 _Control::AddTouchInfo(const _TouchInfo& touchInfo)
4939 {
4940         _TouchManager* pTouchManager = _TouchManager::GetInstance();
4941         SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] _TouchManager does not exist.");
4942
4943         _TouchInfo* pTouchInfo = new (std::nothrow) _TouchInfo;
4944         SysTryReturnVoidResult(NID_UI, pTouchInfo, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4945
4946         FloatPoint screenPoint = pTouchManager->GetScreenPoint(touchInfo.GetPointId());
4947         pTouchInfo->SetTouchInfo(touchInfo.GetPointId(), touchInfo.GetTouchStatus(), screenPoint, false, 0);
4948         __pDelayedTouchInfoList->Add(pTouchInfo);
4949 }
4950
4951 IListT<_TouchInfo*>*
4952 _Control::GetTouchInfoList(void)
4953 {
4954         return __pDelayedTouchInfoList;
4955 }
4956
4957 void
4958 _Control::SetVisualElement(_ControlVisualElement* pVisualElement)
4959 {
4960         __pVisualElement = pVisualElement;
4961 }
4962
4963 _VisualElement*
4964 _Control::GetVisualElement(void) const
4965 {
4966         return __pVisualElement;
4967 }
4968
4969 void
4970 _Control::PrintDescription(bool printChildren, int level)
4971 {
4972         int count = PrintDescription(printChildren, 0, level);
4973
4974         SysSecureLog(NID_UI, "%d controls were printed.", count);
4975 }
4976
4977 int
4978 _Control::PrintDescription(bool printChildren, int depth, int level)
4979 {
4980         const int PRINT_CONTROL_VE = 1;
4981         const int PRINT_CONTROL_EVAS = 2;
4982         const int PRINT_CONTROL_VE_EVAS = 3;
4983
4984         String indent(L"");
4985         String format(L"");
4986
4987         format.Format(LOG_LEN_MAX, L"%d", depth);
4988
4989         for (int i = 0; i < depth; i++)
4990         {
4991                 indent.Append(L"   ");
4992         }
4993
4994         indent.Append(format);
4995
4996         String delimiter(L"-------------------------------------------------------------------------------------------");
4997         SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
4998
4999         // Public
5000         String publicDescription = GetControlDelegate().GetDescription();
5001         if (!publicDescription.IsEmpty())
5002         {
5003                 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), publicDescription.GetPointer());
5004         }
5005
5006         _ControlManager* pControlManager = _ControlManager::GetInstance();
5007         SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
5008
5009         bool focused = false;
5010         _Control* pFocusedControl = pControlManager->GetFocusControl();
5011         if (pFocusedControl && (pFocusedControl == this))
5012         {
5013                 focused = true;
5014         }
5015
5016         // Core
5017         SysSecureLog(NID_UI, "%ls 0x%x(%d %ls) enable(%d) enableState(%d) visible(%d) visibleState(%d) clip(%d) movable(%d) resizable(%d)",
5018                 indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer(), IsEnabled(), GetEnableState(), IsVisible(), GetVisibleState(),
5019                 IsClipToParent(), IsMovable(), IsResizable());
5020
5021         SysSecureLog(NID_UI, "%ls  inputEnableState(%d) focusable(%d) focused(%d) prevFocus(0x%x) nextFocus(0x%x) font(0x%x) fontName(%ls) fontFileName(%ls)",
5022                 indent.GetPointer(), GetInputEnableState(), IsFocusable(), focused, __pPreviousFocus, __pNextFocus, __pFont, __fontName.GetPointer(), __fontFileName.GetPointer());
5023
5024         Rectangle bounds = GetBounds();
5025         Dimension min = GetMinimumSize();
5026         Dimension max = GetMaximumSize();
5027         Rectangle clientBounds = GetClientBounds();
5028         Rectangle absoluteBounds = GetAbsoluteBounds();
5029
5030         SysSecureLog(NID_UI, "%ls bounds(%d %d %d %d) min(%d %d) max(%d %d) scrollPos(%.2f %.2f) cbounds(%d %d %d %d) abounds(%d %d %d %d)",
5031                 indent.GetPointer(), bounds.x, bounds.y, bounds.width, bounds.height,
5032                 min.width, min.height, max.width, max.height,
5033                 GetVerticalScrollPosition(), GetHorizontalScrollPosition(),
5034                 clientBounds.x, clientBounds.y, clientBounds.width, clientBounds.height,
5035                 absoluteBounds.x, absoluteBounds.y, absoluteBounds.width, absoluteBounds.height);
5036
5037         SysSecureLog(NID_UI, "%ls bgColor(0x%x) layoutable(%d) orientation(%d) drag(%d) drop(%d) area(%d) layer(%d)",
5038                 indent.GetPointer(), __backgroundColor.GetRGB32(), IsLayoutable(), GetOrientation(), IsDragEnabled(), IsDropEnabled(), GetArea(), GetLayer());
5039
5040         Canvas* pCanvas = GetCanvasN();
5041         if (pCanvas)
5042         {
5043                 Rectangle canvasBounds = pCanvas->GetBounds();
5044                 Color canvasBackgroundColor = pCanvas->GetBackgroundColor();
5045                 Color canvasForegroundColor = pCanvas->GetForegroundColor();
5046
5047                 SysSecureLog(NID_UI, "%ls canvas.bounds(%d %d %d %d) canvas.bgColor(0x%x) canvas.fgColor(0x%x)",
5048                         indent.GetPointer(), canvasBounds.x, canvasBounds.y, canvasBounds.width, canvasBounds.height, canvasBackgroundColor.GetRGB32(), canvasForegroundColor.GetRGB32());
5049
5050                 delete pCanvas;
5051         }
5052
5053         SysSecureLog(NID_UI, "%ls DataBindingContext(0x%x) ControlDelegate(0x%x) UserData(0x%x) destroying(%d)",
5054                 indent.GetPointer(), __pDataBindingContext, __pControlDelegate, __pUserData, __destroying);
5055
5056         // Ownees
5057         String ownees(L"");
5058
5059         for (int i = 0; i < GetOwneeCount(); ++i)
5060         {
5061                 String ownee(L"");
5062                 _Window* pOwnee = GetOwnee(i);
5063                 if (pOwnee)
5064                 {
5065                         ownee.Format(LOG_LEN_MAX, L"0x%x ", pOwnee);
5066                         ownees.Append(ownee);
5067                 }
5068         }
5069
5070         if (!ownees.IsEmpty())
5071         {
5072                 SysSecureLog(NID_UI, "%ls Ownees(%ls)", indent.GetPointer(), ownees.GetPointer());
5073         }
5074
5075         _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
5076
5077         SysSecureLog(NID_UI, "%ls _VisualElement(0x%x) _VisualElementImpl(0x%x) VisualElementContentProvider(0x%x) VisualElementEventListener(0x%x)",
5078                 indent.GetPointer(), __pVisualElement, pVisualElementImpl, __pVisualElementContentProvider, __pVisualElementEventListener);
5079
5080         // Layout
5081         SysSecureLog(NID_UI, "%ls LayoutItemHandler(0x%x) PortraitLayout(0x%x) LandscapeLayout(0x%x) LayoutContainer(0x%x)",
5082                 indent.GetPointer(), __pLayoutItemHandler, __pPortraitLayout, __pLandscapeLayout, __pLayoutContainer);
5083
5084         // Derived class
5085         String description = GetDescription();
5086         if (!description.IsEmpty())
5087         {
5088                 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), description.GetPointer());
5089         }
5090
5091         // Print Gesture List
5092         IListT<_TouchGestureDetector*>* pGestureList = GetGestureDetectorList();
5093         SysTryReturn(NID_UI, pGestureList, 0, E_SYSTEM, "[E_SYSTEM] System error occurred.");
5094
5095         IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pGestureList->GetEnumeratorN();
5096         SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
5097
5098         while (pEnumerator->MoveNext() == E_SUCCESS)
5099         {
5100                 _TouchGestureDetector* pGestureDetector = null;
5101                 pEnumerator->GetCurrent(pGestureDetector);
5102                 if (pGestureDetector)
5103                 {
5104                         SysSecureLog(NID_UI, "%ls AddedGesture : %ls", indent.GetPointer(), pGestureDetector->GetDescription().GetPointer());
5105                 }
5106         }
5107
5108         delete pEnumerator;
5109
5110         // Print Started Gesture List
5111         unique_ptr<IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState> > pStartedGestureEnumerator(GetStartedGestureDetectorEnumeratorN());
5112         SysTryReturn(NID_UI, pStartedGestureEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
5113
5114         while (pStartedGestureEnumerator->MoveNext() == E_SUCCESS)
5115         {
5116                 _TouchGestureDetector* pStartedGestureDetector = null;
5117                 pStartedGestureEnumerator->GetKey(pStartedGestureDetector);
5118                 if (pStartedGestureDetector)
5119                 {
5120                         SysSecureLog(NID_UI, "%ls StartedGesture : %ls", indent.GetPointer(), pStartedGestureDetector->GetDescription().GetPointer());
5121                 }
5122         }
5123
5124         // new backtrace
5125         unique_ptr<IEnumeratorT<void*> > pNewEnumerator(__pNewBacktrace->GetEnumeratorN());
5126         SysTryReturn(NID_SHELL, pNewEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5127
5128         String newBacktrace;
5129
5130         while (pNewEnumerator->MoveNext() == E_SUCCESS)
5131         {
5132                 void* pAddr = null;
5133                 pNewEnumerator->GetCurrent(pAddr);
5134
5135                 String addr(L"");
5136                 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5137                 newBacktrace.Append(addr);
5138         }
5139
5140         if (!newBacktrace.IsEmpty())
5141         {
5142                 SysSecureLog(NID_UI, "%ls new [%ls]", indent.GetPointer(), newBacktrace.GetPointer());
5143         }
5144
5145         // delete backtrace
5146         unique_ptr<IEnumeratorT<void*> > pDeleteEnumerator(__pDeleteBacktrace->GetEnumeratorN());
5147         SysTryReturn(NID_SHELL, pDeleteEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5148
5149         String deleteBacktrace;
5150
5151         while (pDeleteEnumerator->MoveNext() == E_SUCCESS)
5152         {
5153                 void* pAddr = null;
5154                 pDeleteEnumerator->GetCurrent(pAddr);
5155
5156                 String addr(L"");
5157                 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5158                 deleteBacktrace.Append(addr);
5159         }
5160
5161         if (!deleteBacktrace.IsEmpty())
5162         {
5163                 SysSecureLog(NID_UI, "%ls delete [%ls]", indent.GetPointer(), deleteBacktrace.GetPointer());
5164         }
5165
5166         // Print VE and Evas
5167         switch (level)
5168         {
5169         case PRINT_CONTROL_VE:
5170                 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5171                 break;
5172
5173         case PRINT_CONTROL_EVAS:
5174                 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5175                 break;
5176
5177         case PRINT_CONTROL_VE_EVAS:
5178                 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5179                 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5180                 break;
5181
5182         default:
5183                 break;
5184         }
5185
5186         static int totalCount = 0;
5187
5188         if (depth == 0)
5189         {
5190                 totalCount = 0;
5191         }
5192
5193         if (printChildren)
5194         {
5195                 depth ++;
5196
5197                 int count = GetChildCount();
5198                 totalCount += count;
5199
5200                 for (int i = count - 1; i >= 0; --i)
5201                 {
5202                         _Control* pChild = GetChild(i);
5203                         if (pChild)
5204                         {
5205                                 pChild->PrintDescription(printChildren, depth, level);
5206                         }
5207                 }
5208         }
5209
5210         return totalCount;
5211 }
5212
5213 void
5214 _Control::PrintBacktrace(bool printChildren, bool newBacktrace)
5215 {
5216         int count = PrintBacktrace(printChildren, 0, newBacktrace);
5217
5218         SysSecureLog(NID_UI, "%d controls were printed.", count);
5219 }
5220
5221 int
5222 _Control::PrintBacktrace(bool printChildren, int depth, bool newBacktrace)
5223 {
5224         String indent(L"");
5225         String format(L"");
5226
5227         format.Format(LOG_LEN_MAX, L"%d", depth);
5228
5229         for (int i = 0; i < depth; i++)
5230         {
5231                 indent.Append(L"   ");
5232         }
5233
5234         indent.Append(format);
5235
5236         String delimiter(L"-------------------------------------------------------------------------------------------");
5237         SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
5238
5239         SysSecureLog(NID_UI, "%ls 0x%x(%d %ls)", indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer());
5240
5241         Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList = null;
5242
5243         if (newBacktrace)
5244         {
5245                 pBacktraceList = __pNewBacktrace.get();
5246         }
5247         else
5248         {
5249                 pBacktraceList = __pDeleteBacktrace.get();
5250         }
5251
5252         SysTryReturn(NID_UI, pBacktraceList, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5253
5254         int backtraceCount = pBacktraceList->GetCount();
5255         SysTryReturn(NID_UI, backtraceCount > 0, 0, E_INVALID_ARG, "[E_INVALID_ARG].");
5256
5257         void** pBacktrace = new (std::nothrow) void*[backtraceCount];
5258         SysTryReturn(NID_UI, pBacktrace, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5259
5260         unique_ptr<IEnumeratorT<void*> > pEnumerator(pBacktraceList->GetEnumeratorN());
5261         SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5262
5263         int i = 0;
5264         while (pEnumerator->MoveNext() == E_SUCCESS)
5265         {
5266                 void* pAddr = null;
5267                 pEnumerator->GetCurrent(pAddr);
5268
5269                 pBacktrace[i++] = pAddr;
5270         }
5271
5272         char** pSymbols = backtrace_symbols(pBacktrace, backtraceCount);
5273         SysTryReturn(NID_UI, pSymbols, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5274
5275         for (int j = 0; j < backtraceCount; j++)
5276         {
5277                 SysSecureLog(NID_UI, "%ls [%s]", indent.GetPointer(), pSymbols[j]);
5278         }
5279
5280         free(pSymbols);
5281         delete [] pBacktrace;
5282
5283         static int totalCount = 0;
5284
5285         if (depth == 0)
5286         {
5287                 totalCount = 0;
5288         }
5289
5290         if (printChildren)
5291         {
5292                 depth ++;
5293
5294                 int count = GetChildCount();
5295                 totalCount += count;
5296
5297                 for (int i = count - 1; i >= 0; --i)
5298                 {
5299                         _Control* pChild = GetChild(i);
5300                         if (pChild)
5301                         {
5302                                 pChild->PrintBacktrace(printChildren, depth, newBacktrace);
5303                         }
5304                 }
5305         }
5306
5307         return totalCount;
5308 }
5309
5310 void
5311 _Control::DragAndDropBegin(const _DragAndDropItem& dragAndDropItem)
5312 {
5313         _Window* pRootWindow = GetRootWindow();
5314         if (!pRootWindow)
5315         {
5316                 return;
5317         }
5318
5319         __isDragAndDropSource = true;
5320
5321         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5322         if (!pEcoreEvas)
5323         {
5324                 return;
5325         }
5326
5327         pEcoreEvas->SetDragAndDropState(true);
5328         pEcoreEvas->DragAndDropBegin(*pRootWindow, dragAndDropItem.GetData());
5329         
5330         __pDragWindow = GetControlDelegate().OnDragAndDropBeginning();
5331 }
5332
5333 void
5334 _Control::DragAndDropDrop(void)
5335 {
5336         _Window* pRootWindow = GetRootWindow();
5337         if (!pRootWindow)
5338         {
5339                 return;
5340         }
5341         
5342         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5343         pEcoreEvas->DragAndDropDrop(*pRootWindow);
5344
5345         GetControlDelegate().OnDragAndDropDropping();
5346
5347         // Check self drop.
5348         Point dropPosition = pEcoreEvas->GetDropPosition();
5349         Rectangle bounds = GetRootWindow()->GetBounds();
5350         if (bounds.Contains(dropPosition))
5351         {
5352                 _Control* pDropControl = _ControlManager::GetInstance()->GetTopmostTouchedControl(dropPosition, true);
5353                 if (pDropControl)
5354                 {
5355 // Send dnd events to Source.
5356 #if 0
5357                         if (pDropControl->IsDragAndDropSource() == false)
5358 #endif
5359                         {
5360                                 int pid = pEcoreEvas->GetProcessId(pRootWindow->GetNativeHandle());
5361                                 String dropData = pEcoreEvas->GetDropData();
5362                                 SysLog(NID_UI, "[DND][S:%d][0x%x] DROPPED(%ls)", pid, pDropControl, dropData.GetPointer());
5363                                 _DragAndDropItem* pDragAndDropItem = _DragAndDropItem::CreateInstanceN(_DRAG_AND_DROP_TYPE_TEXT, dropData);
5364                                 pDropControl->GetControlDelegate().OnDragAndDropDropped(*pDragAndDropItem);
5365                                 delete pDragAndDropItem;
5366                         }
5367                 }
5368         }
5369
5370         __isDragAndDropSource = false;
5371 }
5372
5373 _Window*
5374 _Control::GetDragWindow(void) const
5375 {
5376         return __pDragWindow;
5377 }
5378
5379 bool
5380 _Control::IsDragAndDropSource(void) const
5381 {
5382         return __isDragAndDropSource;
5383 }
5384
5385 _Window*
5386 _Control::OnDragAndDropBeginning(void)
5387 {
5388         return null;
5389 }
5390
5391 void
5392 _Control::OnDragAndDropDropping(void)
5393 {
5394 }
5395
5396 void
5397 _Control::OnDragAndDropEntered(void)
5398 {
5399 }
5400
5401 void
5402 _Control::OnDragAndDropMoved(const FloatPoint& position)
5403 {
5404 }
5405
5406 void
5407 _Control::OnDragAndDropLeft(void)
5408 {
5409 }
5410
5411 void
5412 _Control::OnDragAndDropDropped(const _DragAndDropItem& dragAndDropItem)
5413 {
5414 }
5415
5416 _ITouchEventPreviewer*
5417 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>) const
5418 {
5419         return __pTouchEventPreviewer;
5420 }
5421
5422 _IKeyEventPreviewer*
5423 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_KEY>) const
5424 {
5425         return __pKeyEventPreviewer;
5426 }
5427
5428 _INotificationEventPreviewer*
5429 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5430 {
5431         return __pNotificationEventPreviewer;
5432 }
5433
5434 _IKeyEventListener*
5435 _Control::GetEventListener(_IntToType<_UI_EVENT_KEY>) const
5436 {
5437         return __pKeyEventListener;
5438 }
5439
5440 _IFocusEventListener*
5441 _Control::GetEventListener(_IntToType<_UI_EVENT_FOCUS>) const
5442 {
5443         return __pFocusEventListener;
5444 }
5445
5446 _INotificationEventListener*
5447 _Control::GetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5448 {
5449         return __pNotificationEventListener;
5450 }
5451
5452 void
5453 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>, _ITouchEventPreviewer* pPreviewer)
5454 {
5455         __pTouchEventPreviewer = pPreviewer;
5456 }
5457
5458 void
5459 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_KEY>, _IKeyEventPreviewer* pPreviewer)
5460 {
5461         __pKeyEventPreviewer = pPreviewer;
5462 }
5463
5464 void
5465 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventPreviewer* pPreviewer)
5466 {
5467         __pNotificationEventPreviewer = pPreviewer;
5468 }
5469
5470 void
5471 _Control::SetEventListener(_IntToType<_UI_EVENT_FOCUS>, _IFocusEventListener* pListener)
5472 {
5473         __pFocusEventListener = pListener;
5474 }
5475
5476 void
5477 _Control::SetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventListener* pListener)
5478 {
5479         __pNotificationEventListener = pListener;
5480 }
5481
5482 bool
5483 _Control::IsDragEnabled(void) const
5484 {
5485         return __dragEnabled;
5486 }
5487
5488 bool
5489 _Control::IsDropEnabled(void) const
5490 {
5491         return __dropEnabled;
5492 }
5493
5494 void
5495 _Control::SetDragEnabled(bool enabled)
5496 {
5497         __dragEnabled = enabled;
5498 }
5499
5500 void
5501 _Control::SetDropEnabled(bool enabled)
5502 {
5503         __dropEnabled = enabled;
5504 }
5505
5506 void
5507 _Control::SetTouchPressThreshold(float distance)
5508 {
5509         __touchMoveAllowance = static_cast<int>(distance * __screenDpi);
5510         __pressThresHold = distance;
5511 }
5512
5513 float
5514 _Control::GetTouchPressThreshold(void) const
5515 {
5516         return __pressThresHold;
5517 }
5518
5519 int
5520 _Control::GetTouchPressThresholdPixel(void) const
5521 {
5522         return __touchMoveAllowance;
5523 }
5524
5525 void
5526 _Control::SetChangingEventTarget(bool isChangingEventTarget)
5527 {
5528         __isChangingEventTarget = isChangingEventTarget;
5529 }
5530
5531 bool
5532 _Control::GetChangingEventTarget(void) const
5533 {
5534         return __isChangingEventTarget;
5535 }
5536
5537 void
5538 _Control::SetEventEnableState(bool enableState)
5539 {
5540         __isEventEnableState = enableState;
5541 }
5542
5543 bool
5544 _Control::IsEventEnabled(void) const
5545 {
5546         return __isEventEnableState;
5547 }
5548
5549 void
5550 _Control::SetPreviousFocus(_Control* pPreviousFocus)
5551 {
5552         __pPreviousFocus = pPreviousFocus;
5553
5554 }
5555 void
5556 _Control::SetNextFocus(_Control* pNextFocus)
5557 {
5558         __pNextFocus = pNextFocus;
5559 }
5560 _Control*
5561 _Control::GetPreviousFocus(void) const
5562 {
5563         return  __pPreviousFocus;
5564 }
5565 _Control*
5566 _Control::GetNextFocus(void) const
5567 {
5568         return __pNextFocus;
5569 }
5570
5571 void
5572 _Control::OnDrawFocus(void)
5573 {
5574         if (__pFocusVisualElement.get() == null)
5575         {
5576                 unique_ptr<VisualElement, _VisualElementDeleter> pFocusVisualElement (new (std::nothrow) VisualElement, _VisualElementDeleter());
5577                 SysTryReturn(NID_UI, pFocusVisualElement, , E_SYSTEM, "[E_SYSTEM] System error");
5578
5579                 result r = pFocusVisualElement->Construct();
5580                 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
5581
5582                 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*pFocusVisualElement);
5583                 SysTryReturn(NID_UI, pImpl, , E_SYSTEM, "[E_SYSTEM] pImpl System error");
5584                 pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(_CONTROL_LAYER_SYSTEM));
5585
5586                 __pFocusVisualElement.reset(pFocusVisualElement.release());
5587                 __pFocusVisualElement->SetImplicitAnimationEnabled(false);
5588
5589                 _VisualElement* pControVisualElement = this->GetVisualElement();
5590                 pControVisualElement->AttachChild(*__pFocusVisualElement);
5591
5592
5593                 if (__pFocusVisualElement)
5594                 {
5595                         Rectangle rectangle = GetBounds();
5596                         __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, rectangle.width, rectangle.height));
5597                         unique_ptr<Canvas>pCanvas(__pFocusVisualElement->GetCanvasN());
5598                         if (pCanvas)
5599                         {
5600                                 pCanvas->SetBackgroundColor(0x55555555);
5601                                 pCanvas->Clear();
5602                         }
5603                         Color contentHighlightedColor;
5604                         GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
5605                         Bitmap* pBitmap = null;
5606                         Bitmap* pTempBitmap = null;
5607                         result r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
5608                         pBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
5609
5610                         if (pBitmap)
5611                         {
5612                                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
5613                                 {
5614                                         if (pCanvas)
5615                                         {
5616                                                 r = pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5617                                         }
5618                                 }
5619                                 else
5620                                 {
5621                                         if (pCanvas)
5622                                         {
5623                                                 r = pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5624                                         }
5625                                 }
5626                         }
5627
5628                 }
5629         }
5630         __pFocusVisualElement->SetShowState(true);
5631 }
5632
5633 void
5634 _Control::OnChildControlFocusMoved(const _Control& control)
5635 {
5636 }
5637
5638 void
5639 _Control::OnDescendantControlFocusMoved(const _Control& control)
5640 {
5641 }
5642
5643 bool
5644 _Control::IsChildControlFocusManage(void) const
5645 {
5646         return false;
5647 }
5648
5649 result
5650 _Control::SetFontFromFile(const String& fileName)
5651 {
5652         result r = E_SUCCESS;
5653
5654         if (__fontFileName.Equals(fileName))
5655         {
5656                 return E_SUCCESS;
5657         }
5658
5659         __isControlFontChanged = true;
5660         __fontFileName = fileName;
5661         __fontName.Clear();
5662
5663         Font* pFont = GetFallbackFont();
5664
5665         if (pFont == null)
5666         {
5667                 r = GetLastResult();
5668                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5669         }
5670         return E_SUCCESS;
5671 }
5672
5673 Tizen::Base::String
5674 _Control::GetFontFile(void) const
5675 {
5676         return __fontFileName;
5677 }
5678 void
5679 _Control::DrawFocus(void)
5680 {
5681         _IControlDelegate& delegate = GetControlDelegate();
5682         delegate.OnDrawFocus();
5683 }
5684
5685 void
5686 _Control::MakeFocusList(const _Control* pControl, IListT<_Control*>*  pFocusControlList) const
5687 {
5688         int childCount = pControl->GetChildCount();
5689         for(int i = 0; i < childCount; i++)
5690         {
5691                 _Control* pChildControl = pControl->GetChild(i);
5692                 Rectangle rect = pChildControl->GetAbsoluteBounds();
5693                 unique_ptr<IEnumeratorT<_Control*> > pEnum (pFocusControlList->GetEnumeratorN());
5694                 int index = 0;
5695                 while (pEnum->MoveNext() == E_SUCCESS)
5696                 {
5697                         _Control* pEnumeratorControl = null;
5698                         pEnum->GetCurrent(pEnumeratorControl);
5699                         if (pEnumeratorControl != null)
5700                         {
5701                                 Rectangle enumeratorRect = pEnumeratorControl->GetAbsoluteBounds();
5702                                 if(enumeratorRect.y > rect.y)
5703                                 {
5704                                         break;
5705                                 }
5706                                 else if (enumeratorRect.y == rect.y)
5707                                 {
5708                                         if(enumeratorRect.x > rect.x)
5709                                         {
5710                                                 break;
5711                                         }
5712                                 }
5713
5714                                 index ++;
5715                         }
5716                 }
5717                 pFocusControlList->InsertAt(pChildControl, index);
5718         }
5719 }
5720
5721 void
5722 _Control::MakeChildContainerFocusList(const _Control* pControl, int startIndex , IListT<_Control*>*  pFocusControlList) const
5723 {
5724         unique_ptr<IListT<_Control*> > pTempList (new (std::nothrow) ArrayListT<_Control*>);
5725         SysTryReturnVoidResult(NID_UI_CTRL, pTempList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
5726         MakeFocusList(pControl, pTempList.get());
5727
5728         unique_ptr<IEnumeratorT<_Control*> > pTempEnum(pTempList->GetEnumeratorN());
5729         int index = ++startIndex;
5730         while (pTempEnum->MoveNext() == E_SUCCESS)
5731         {
5732                 _Control* pEnumeratorControl = null;
5733                 pTempEnum->GetCurrent(pEnumeratorControl);
5734                 pFocusControlList->InsertAt(pEnumeratorControl, index);
5735                 index ++;
5736         }
5737 }
5738
5739 Tizen::Base::Collection::IListT<_Control*>*
5740 _Control::GetFocusListN(void) const
5741 {
5742         unique_ptr<IListT<_Control*> > pControlFocusList (new (std::nothrow) ArrayListT<_Control*>);
5743         SysTryReturn(NID_UI_CTRL, pControlFocusList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5744         MakeFocusList(this, pControlFocusList.get());
5745
5746         unique_ptr<IEnumeratorT<_Control*> > pEnum(pControlFocusList->GetEnumeratorN());
5747         SysTryReturn(NID_UI_CTRL, pEnum, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5748         int i =0;
5749         int nextContainerIndex = -1;
5750         while (pEnum->MoveNext() == E_SUCCESS)
5751         {
5752                 _Control* pEnumeratorControl = null;
5753                 pEnum->GetCurrent(pEnumeratorControl);
5754
5755                 if (nextContainerIndex < i)
5756                 {
5757                         if (pEnumeratorControl->IsChildControlFocusManage() == false)
5758                         {
5759                                 MakeChildContainerFocusList(pEnumeratorControl, i, pControlFocusList.get());
5760                                 nextContainerIndex = i;
5761                                 pEnum.reset(pControlFocusList->GetEnumeratorN());
5762                                 i = -1;
5763                         }
5764                 }
5765                 i++;
5766         }
5767         return pControlFocusList.release();
5768 }
5769
5770 bool
5771 _Control::IsChildAttachable(_Control& child) const
5772 {
5773         if (dynamic_cast <_Window*>(&child) != null)
5774         {
5775                 return false;
5776         }
5777
5778         return true;
5779 }
5780
5781 }} // Tizen::Ui