2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUi_Control.cpp
20 * @brief This is the implementation file for the _Control class.
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_Control.h"
36 #include "FUi_ControlManager.h"
37 #include "FUi_FocusManagerImpl.h"
38 #include "FUi_CoordinateSystemUtils.h"
39 #include "FUi_Window.h"
40 #include "FUi_EcoreEvasMgr.h"
41 #include "FUi_EcoreEvas.h"
42 #include "FUi_LayoutLayoutContainer.h"
43 #include "FUi_LayoutAbsoluteLayout.h"
44 #include "FUi_LayoutILayoutItemHandler.h"
45 #include "FUi_TouchManager.h"
46 #include "FUi_DataBindingContext.h"
47 #include "FUi_TouchLongPressGestureDetector.h"
48 #include "FUi_TouchTapGestureDetector.h"
49 #include "FUi_AccessibilityContainer.h"
50 #include "FUi_ResourceManager.h"
51 #include "FUiAnim_ControlVisualElement.h"
52 #include "FUiAnim_Debug.h"
53 #include "FUiAnim_VisualElement.h"
54 #include "FUiAnim_VisualElementImpl.h"
55 #include "FUiCtrl_Form.h"
56 #include "FUiCtrl_Frame.h"
57 #include "FUi_ContainerImpl.h"
58 #include "FUi_DragAndDropItem.h"
61 using namespace Tizen::Base;
62 using namespace Tizen::Base::Collection;
63 using namespace Tizen::Base::Runtime;
64 using namespace Tizen::Graphics;
65 using namespace Tizen::Ui;
66 using namespace Tizen::Ui::Animations;
67 using namespace Tizen::Ui::Controls;
72 GetZOrderGroupOfVisualElement(_ControlLayer layer)
76 case _CONTROL_LAYER_OVERLAY:
77 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL - 1;
78 case _CONTROL_LAYER_CLIENT_BOTTOM:
79 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL;
80 case _CONTROL_LAYER_NONE:
82 case _CONTROL_LAYER_CLIENT_MIDDLE:
83 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
84 case _CONTROL_LAYER_CLIENT_TOP:
85 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 2;
86 case _CONTROL_LAYER_SYSTEM:
87 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 3;
90 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
95 AdjustSizeToRange(float& width, float& height, const FloatDimension& minDim, const FloatDimension& maxDim)
98 if (width < minDim.width)
100 width = minDim.width;
103 if (height < minDim.height)
105 height = minDim.height;
109 if (width > maxDim.width)
111 width = maxDim.width;
114 if (height > maxDim.height)
116 height = maxDim.height;
124 AdjustSizeToRange(FloatDimension& dim, const FloatDimension& minDim, const FloatDimension& maxDim)
126 return AdjustSizeToRange(dim.width, dim.height, minDim, maxDim);
131 _ControlVisualElement*
132 CreateVisualElementN(void)
136 _ControlVisualElement* pVisualElement = new (std::nothrow) _ControlVisualElement;
137 SysTryReturn(NID_UI, pVisualElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
140 pVisualElement->ConstructControlVisualElement() == E_SUCCESS, ,
141 E_SYSTEM, "[E_SYSTEM] System error occurred.");
143 pVisualElement->SetImplicitAnimationEnabled(false);
144 pVisualElement->SetShowState(true);
145 pVisualElement->SetBackBufferEnabled(true);
146 pVisualElement->SetRedrawOnResizeEnabled(true);
147 pVisualElement->SetSurfaceOpaque(false);
149 return pVisualElement;
152 //delete pVisualElement;
153 pVisualElement->Destroy();
157 _Control::GestureMap*
158 CreateGestureMapN(void)
162 _Control::GestureMap* pGestureMap = new (std::nothrow) _Control::GestureMap;
163 SysTryReturn(NID_UI, pGestureMap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
166 pGestureMap->Construct() == E_SUCCESS, ,
167 E_SYSTEM, "[E_SYSTEM] System error occurred.");
177 _Control::ControlList*
178 CreateControlListN(void)
182 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
183 SysTryReturn(NID_UI, pControlList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
189 _Control::WindowList*
190 CreateWindowListN(void)
194 _Control::WindowList* pWindowList = new (std::nothrow) _Control::WindowList;
195 SysTryReturn(NID_UI, pWindowList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
202 _Layout::LayoutContainer*
203 CreateLayoutContainerN(_Layout::ILayoutItemHandler* pLayoutItemHandler)
206 result r = E_SUCCESS;
208 _Layout::LayoutContainer* pLayoutContainer = null;
209 _Layout::AbsoluteLayout* pAbsLayout = null;
211 pLayoutContainer = new (std::nothrow) _Layout::LayoutContainer();
212 SysTryReturn(NID_UI, pLayoutContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage");
213 if (IsFailed(GetLastResult()))
218 pAbsLayout = new (std::nothrow) _Layout::AbsoluteLayout();
219 SysTryCatch(NID_UI, pAbsLayout, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
220 if (IsFailed(GetLastResult()))
225 pLayoutContainer->SetItemHandler(pLayoutItemHandler);
227 r = pLayoutContainer->SetDefaultLayout(*pAbsLayout);
228 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
230 return pLayoutContainer;
234 delete pLayoutContainer;
239 } // Anonymous namespace
241 namespace Tizen { namespace Ui
244 IMPLEMENT_PROPERTY(_Control);
246 class _Control::ControlVisualElementContentProvider
247 : public VisualElementContentProvider
254 ControlVisualElementContentProvider(_Control& control)
259 virtual ~ControlVisualElementContentProvider(void)
263 virtual bool PrepareDraw(VisualElement& target)
265 _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(&target);
271 Color bgColor = __control.GetBackgroundColor();
273 pCVE->SetBackgroundColor(
275 (float) bgColor.GetRed() / 255.0f,
276 (float) bgColor.GetGreen() / 255.0f,
277 (float) bgColor.GetBlue() / 255.0f,
278 (float) bgColor.GetAlpha() / 255.0f
282 __control.GetControlDelegate().OnDraw();
284 target.SetFlushNeeded();
289 virtual HitTestResult HitTest(VisualElement& target, const FloatPoint& point)
291 return __control.GetControlDelegate().HitTest(point);
295 ControlVisualElementContentProvider(const ControlVisualElementContentProvider& rhs);
296 ControlVisualElementContentProvider& operator =(const ControlVisualElementContentProvider& rhs);
299 class _Control::ControlVisualElementEventListener
300 : public IVisualElementEventListener
303 ControlVisualElementEventListener(_Control& control)
308 virtual ~ControlVisualElementEventListener(void)
313 virtual void OnChildAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
317 virtual void OnChildDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
321 virtual void OnAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
325 virtual void OnDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
329 virtual result OnTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
334 virtual void OnTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
338 virtual result OnChildrenTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
340 for (int i = 0; i < __control.GetChildCount(); ++i)
342 _Control* pChild = __control.GetChild(i);
348 if (pChild->GetArea() == _CONTROL_AREA_SYSTEM)
350 _VisualElement* pVisualElement = pChild->GetVisualElement();
353 FloatMatrix4 inverseMatrix(newTransform);
354 inverseMatrix.Invert();
356 result r = pVisualElement->SetTransformMatrix(inverseMatrix);
368 virtual void OnChildrenTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
372 virtual result OnBoundsChanging(Tizen::Ui::Animations::VisualElement& source, FloatRectangle& newBounds)
377 virtual void OnBoundsChanged(Tizen::Ui::Animations::VisualElement& source, const FloatRectangle& previousBounds)
381 virtual void OnShowStateChanged(Tizen::Ui::Animations::VisualElement& source, bool previousShowState)
386 ControlVisualElementEventListener(const ControlVisualElementEventListener& rhs);
387 ControlVisualElementEventListener& operator =(const ControlVisualElementEventListener& rhs);
391 }; // ControlVisualElementEventListener
393 // Layout Item Handler
394 class _Control::LayoutItemHandler
395 : public _Layout::ILayoutItemHandler
398 LayoutItemHandler(_Control* pControl)
399 : __pControl(pControl)
401 SysAssert(__pControl);
404 void SetItemVisibleState(bool visible)
406 __pControl->SetVisibleState(visible);
409 result SetItemBounds(const FloatRectangle& rect)
411 SysAssert(__pControl->IsInSizeRange(FloatDimension(rect.width, rect.height)));
412 return __pControl->SetBoundsFinal(rect, false, true);
415 FloatRectangle GetItemBounds(void) const
417 return __pControl->GetBoundsF();
420 FloatRectangle GetItemClientBoundsFromSize(const FloatDimension& size) const
422 FloatRectangle clientBounds(0.0f, 0.0f, 0.0f, 0.0f);
423 __pControl->UpdateClientBounds(size, clientBounds);
427 FloatDimension GetItemContentSize(bool horizontalMode, bool verticalMode) const
429 return __pControl->GetControlDelegate().GetContentSizeF(horizontalMode, verticalMode);
432 FloatDimension GetItemMinimumSize(void) const
434 return __pControl->GetMinimumSizeF();
437 FloatDimension GetItemMaximumSize(void) const
439 return __pControl->GetMaximumSizeF();
442 result OnItemMeasure(float& width, float& height)
444 Dimension evaluatedSize(_CoordinateSystemUtils::ConvertToInteger(width), _CoordinateSystemUtils::ConvertToInteger(height));
445 FloatDimension evaluatedSizeF(width, height);
447 bool changed = __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSizeF);
450 width = evaluatedSizeF.width;
451 height = evaluatedSizeF.height;
455 __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSize);
457 if (evaluatedSize.width != (_CoordinateSystemUtils::ConvertToInteger(width)))
459 width = evaluatedSize.width;
461 if (evaluatedSize.height != (_CoordinateSystemUtils::ConvertToInteger(height)))
463 height = evaluatedSize.height;
471 LayoutItemHandler(const LayoutItemHandler& rhs);
472 LayoutItemHandler& operator =(const LayoutItemHandler& rhs);
475 _Control* __pControl;
476 }; // LayoutItemHandler
481 _Control::CreateControlN(void)
483 _Control* pControl = new (std::nothrow) _Control;
484 SysTryReturn(NID_UI, pControl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
485 if (IsFailed(GetLastResult()))
490 pControl->AcquireHandle();
492 SysAssert(GetLastResult() == E_SUCCESS);
501 _Control::ResetEventListeners(void)
503 __pFocusEventListener = this;
504 __pNotificationEventListener = this;
508 _Control::SetControlDelegate(_IControlDelegate& delegate)
510 __pControlDelegate = &delegate;
514 _Control::ResetControlDelegate(void)
516 __pControlDelegate = this;
520 _Control::GetControlDelegate(void) const
524 return const_cast<_Control&>(*this);
527 SysAssert(__pControlDelegate);
528 return *__pControlDelegate;
532 _Control::SetPropagatedTouchEventListener(_IPropagatedTouchEventListener* pListener)
534 __pPropagatedTouchEventListener = pListener;
537 _IPropagatedTouchEventListener*
538 _Control::GetPropagatedTouchEventListener(void) const
542 return const_cast<_Control*>(this);
545 SysAssert(__pPropagatedTouchEventListener);
546 return __pPropagatedTouchEventListener;
550 _Control::SetPropagatedKeyEventListener(_IPropagatedKeyEventListener* pListener)
552 __pPropagatedKeyEventListener = pListener;
555 _IPropagatedKeyEventListener*
556 _Control::GetPropagatedKeyEventListener(void) const
560 return const_cast<_Control*>(this);
563 SysAssert(__pPropagatedKeyEventListener);
564 return __pPropagatedKeyEventListener;
568 _Control::OnPreviewKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
574 _Control::OnPreviewKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
580 _Control::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
582 //SysLog(NID_UI, ">>> [core] OnKeyPressed(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
587 _Control::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
589 //SysLog(NID_UI, ">>> [core] OnKeyReleased(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
594 _Control::TranslateKeyEventInfo(const _Control& source, _KeyInfo& keyInfo)
599 _UiTouchEventDelivery
600 _Control::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
602 return _UI_TOUCH_EVENT_DELIVERY_YES;
605 _UiTouchEventDelivery
606 _Control::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
608 return _UI_TOUCH_EVENT_DELIVERY_YES;
611 _UiTouchEventDelivery
612 _Control::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
614 return _UI_TOUCH_EVENT_DELIVERY_YES;
617 _UiTouchEventDelivery
618 _Control::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
620 return _UI_TOUCH_EVENT_DELIVERY_YES;
623 _UiTouchEventDelivery
624 _Control::OnPreviewTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
626 return _UI_TOUCH_EVENT_DELIVERY_YES;
630 _Control::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
636 _Control::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
642 _Control::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
648 _Control::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
654 _Control::OnTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
660 _Control::OnFocusGained(const _Control& source)
662 bool isFocusMode = _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
663 bool isFocusalbeControl = _FocusManagerImpl::GetInstance()->IsFocusable(this);
664 if (isFocusMode && isFocusalbeControl)
672 _Control::OnFocusLost(const _Control& source)
674 if (__pFocusVisualElement)
676 __pFocusVisualElement->SetShowState(false);
682 _Control::OnPreviewNotifiedN(const _Control& source, IList* pArgs)
688 _Control::OnNotifiedN(const _Control& source, IList* pArgs)
694 _Control::IsMovable(void) const
701 _Control::IsResizable(void) const
708 _Control::GetContentSize(void) const
711 return Dimension(0, 0);
715 _Control::GetContentSizeF(bool horizontalMode, bool verticalMode) const
718 return FloatDimension(0.0f, 0.0f);
722 _Control::HitTest(const FloatPoint& point)
724 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
726 if (pVisualElementImpl)
728 if (pVisualElementImpl->HitTestI(point) == _VisualElementImpl::HITTEST_MATCH)
730 return HIT_TEST_MATCH;
734 return HIT_TEST_NOWHERE;
738 _Control::GetVerticalScrollPosition(void) const
744 _Control::GetHorizontalScrollPosition(void) const
750 _Control::GetOrientation(void) const
753 return __orientation;
757 _Control::OnDraw(void)
762 _Control::OnCanvasRequestedN(const FloatRectangle& bounds)
769 _Control::OnCapturedBitmapRequestedN(void)
776 _Control::OnAttaching(const _Control* pParent)
782 _Control::OnAttached(void)
788 _Control::OnAttachingToMainTree(const _Control* pParent)
794 _Control::OnPreAttachedToMainTree(void)
800 _Control::OnAttachedToMainTree(void)
806 _Control::OnDetachingFromMainTree(void)
812 _Control::OnAttachingFailed(const _Control& parent)
817 _Control::OnDetaching(void)
823 _Control::OnBoundsChanging(const Rectangle& bounds)
829 _Control::OnBoundsChanging(const FloatRectangle& bounds)
835 _Control::OnBoundsChanged(void)
841 _Control::OnEvaluateSize(Dimension& evaluatedSize)
847 _Control::OnEvaluateSize(FloatDimension& evaluatedSize)
853 _Control::OnParentBoundsChanged(const _Control& parent)
858 _Control::OnChildAttached(const _Control& child)
863 _Control::OnChildDetaching(const _Control& child)
868 _Control::OnChildDetached(const _Control& child)
873 _Control::OnChildBoundsChanged(const _Control& child)
878 _Control::OnChildVisibleStateChanged(const _Control& child)
883 _Control::OnChangeLayout(_ControlOrientation orientation)
888 _Control::OnChangeLayout(_ControlRotation rotation)
893 _Control::OnZOrderChanging(_ControlZOrderUpdate zOrderUpdate)
898 _Control::OnVisibleStateChanging(void)
903 _Control::OnVisibleStateChanged(void)
908 _Control::OnAncestorVisibleStateChanged(const _Control& control)
910 _TouchManager* pTouchManager = _TouchManager::GetInstance();
911 if (pTouchManager && IsVisible() == false && IsAttachedToMainTree() == true)
913 if(pTouchManager->GetTouchControlSource() == this)
915 SysLog(NID_UI, "VisibleState changed false, Call SetTouchCanceled");
916 pTouchManager->SetTouchCanceled(null);
922 _Control::OnAncestorEnableStateChanged(const _Control& control)
927 _Control::OnAncestorInputEnableStateChanged(const _Control& control)
932 _Control::OnTouchPressHandled(const _Control& control)
937 _Control::OnTouchReleaseHandled(const _Control& control)
942 _Control::OnTouchMoveHandled(const _Control& control)
947 _Control::OnFontChanged(Tizen::Graphics::Font* pFont)
949 SetUpdateLayoutState(true);
953 _Control::OnFontInfoRequested(unsigned long& style, int& size)
958 _Control::OnFontInfoRequested(unsigned long& style, float& size)
963 _Control::OnBackgroundColorChanged(Color& backgroundColor)
968 _Control::OnFocusableStateChanged(bool focusalbeState)
973 _Control::OnFocusModeStateChanged(void)
978 _Control::OnTouchCancelHandled(const _Control& control)
983 _Control::Accept(Visitor& visitor)
987 VisitType visitType = visitor.Visit(*this);
995 for (int i = 0; i < GetChildCount(); ++i) // [Postpone] Keep handle list before iternation.
997 _Control* pChild = GetChild(i);
1000 pChild->Accept(visitor);
1007 _Control* pParent = GetParent();
1010 pParent->Accept(visitor);
1021 _Control::Accept(Visitor& visitor) const
1023 const_cast <_Control*>(this)->Accept(visitor);
1027 _Control::InvalidateHierarchyRootWindow(_Control& control)
1029 control.__needRecalcRootWindow = true;
1030 control.__pRootWindow = null;
1032 for (int i = 0; i < control.GetChildCount(); ++i)
1034 _Control* pChild = control.GetChild(i);
1037 pChild->InvalidateHierarchyRootWindow(*pChild);
1043 _Control::InvalidateHierarchyAbsoluteBounds(_Control& control)
1045 control.__needRecalcAbsBounds = true;
1046 control.__needRecalcAbsBoundsF = true;
1048 for (int i = 0; i < control.GetChildCount(); ++i)
1050 _Control* pChild = control.GetChild(i);
1053 pChild->InvalidateHierarchyAbsoluteBounds(*pChild);
1059 _Control::Draw(bool recursive)
1063 Invalidate(recursive);
1064 GetVisualElement()->Draw();
1068 _Control::Show(void)
1070 GetVisualElement()->Flush();
1073 SysAssert(GetLastResult() == E_SUCCESS);
1077 _Control::ChangeLayout(_ControlOrientation orientation, bool callRotation)
1084 _Visitor(_ControlOrientation orientation)
1085 : __orientation(orientation){}
1087 virtual VisitType Visit(_Control& control)
1089 if (control.__orientation != __orientation)
1091 control.__orientation = __orientation;
1092 control.GetControlDelegate().OnChangeLayout(__orientation);
1096 return VISIT_DOWNWARD;
1100 _ControlOrientation __orientation;
1103 _Visitor visitor(orientation);
1106 SysAssert(GetLastResult() == E_SUCCESS);
1108 if (callRotation == true)
1110 _ControlManager* pMgr = _ControlManager::GetInstance();
1113 _ControlRotation rotation = pMgr->GetOrientationStatus();
1114 ChangeLayout(rotation);
1120 _Control::ChangeLayout(_ControlRotation rotation)
1127 _Visitor(_ControlRotation rotation)
1128 : __rotation(rotation){}
1130 virtual VisitType Visit(_Control& control)
1132 if (control.__rotation != __rotation)
1134 control.__rotation = __rotation;
1135 control.GetControlDelegate().OnChangeLayout(__rotation);
1139 return VISIT_DOWNWARD;
1143 _ControlRotation __rotation;
1146 _Visitor visitor(rotation);
1149 SysAssert(GetLastResult() == E_SUCCESS);
1153 _Control::IsLayoutChangable(void) const
1159 _Control::IsOrientationRoot(void) const
1165 _Control::Invalidate(void)
1168 GetVisualElement()->InvalidateRectangle(null);
1172 _Control::Invalidate(bool recursive)
1177 _Layout::Layout* pLayout = GetLayout();
1180 pLayout->UpdateLayout();
1183 if (recursive == false)
1194 _Control::Invalidate(_Control& control)
1196 if (control.GetVisibleState() == false)
1201 control.Invalidate();
1204 int owneeCount = control.GetOwneeCount();
1205 for (int i = 0; i < owneeCount; ++i)
1207 _Window* pOwnee = control.GetOwnee(i);
1210 pOwnee->Invalidate(true);
1214 for (int i = 0; i < control.GetChildCount(); ++i)
1216 _Control* pChild = control.GetChild(i);
1219 pChild->Invalidate(*pChild);
1225 _Control::Invalidate(const Rectangle& rect)
1228 FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1229 GetVisualElement()->InvalidateRectangle(&rectf);
1231 __invalidatedBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
1235 _Control::Invalidate(const FloatRectangle& rect)
1238 FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1239 GetVisualElement()->InvalidateRectangle(&rectf);
1241 __invalidatedBounds = rect;
1245 _Control::Contains(const Point& point) const
1249 Rectangle bounds = GetBounds();
1250 bounds.x = bounds.y = 0;
1251 return bounds.Contains(point);
1255 _Control::Contains(const FloatPoint& point) const
1259 FloatRectangle bounds = GetBoundsF();
1260 bounds.x = bounds.y = 0;
1261 return bounds.Contains(point);
1266 _Control::PartialUpdateLayout(void)
1270 _Layout::Layout* pLayout = GetLayout();
1273 pLayout->PartialUpdateLayout();
1278 _Control::UpdateLayout(void)
1282 _Layout::Layout* pLayout = GetLayout();
1285 pLayout->UpdateLayout();
1290 _Control::SetChildAlwaysOnTop(_Control& child)
1294 SysTryReturn(NID_UI,
1295 child.GetParent() == this, E_INVALID_ARG,
1296 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1298 SysTryReturn(NID_UI,
1299 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1300 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1302 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_TOP)
1307 child.SetLayer(_CONTROL_LAYER_CLIENT_TOP);
1313 _Control::SetChildAlwaysAtBottom(_Control& child)
1317 SysTryReturn(NID_UI,
1318 child.GetParent() == this, E_INVALID_ARG,
1319 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1321 SysTryReturn(NID_UI,
1322 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1323 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1325 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_BOTTOM)
1330 child.SetLayer(_CONTROL_LAYER_CLIENT_BOTTOM);
1336 _Control::ResetChildLayer(_Control& child)
1340 SysTryReturn(NID_UI,
1341 child.GetParent() == this, E_INVALID_ARG,
1342 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1344 SysTryReturn(NID_UI,
1345 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1346 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1348 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_MIDDLE)
1353 child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1360 _Control::AttachSystemChild(_Control& child)
1363 result r = E_SUCCESS;
1365 r = StartAttaching(child, _CONTROL_AREA_SYSTEM);
1371 ControlList& children = GetChildList();
1372 r = children.Add(&child);
1373 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1375 r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1376 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1378 r = EndAttaching(child);
1381 result listResult = children.Remove(&child);
1382 if (IsFailed(listResult))
1384 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
1389 SysAssert(GetLastResult() == E_SUCCESS);
1395 _Control::DetachSystemChild(_Control& child)
1397 return DetachChild(child);
1401 _Control::HasParent(void) const
1403 return __pParent != null;
1407 _Control::GetArea(void) const
1414 _Control::GetLayer(void) const
1421 _Control::SetLayer(_ControlLayer layer)
1424 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*GetVisualElement());
1426 result r = pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(layer));
1429 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1432 const _Control::ControlList&
1433 _Control::GetChildList() const
1435 return const_cast <_Control*>(this)->GetChildList();
1438 _Control::ControlList&
1439 _Control::GetChildList()
1441 return *__pChildren;
1445 _Control::IsCalledCallAttachingToMainTree(void)
1447 return __isCalledCallOnAttachingToMainTree;
1451 _Control::SetCalledCallAttachingToMainTree(bool isAttaching)
1453 __isCalledCallOnAttachingToMainTree = isAttaching;
1457 _Control::IsCalledCallPreAttachedToMainTree(void)
1459 return __isCalledCallOnPreAttachedToMainTree;
1463 _Control::IsCalledCallAttachedToMainTree(void)
1465 return __isCalledCallOnAttachedToMainTree;
1469 _Control::SetCalledCallPreAttachedToMainTree(bool isAttached)
1471 __isCalledCallOnPreAttachedToMainTree = isAttached;
1475 _Control::SetCalledCallAttachedToMainTree(bool isAttached)
1477 __isCalledCallOnAttachedToMainTree = isAttached;
1481 _Control::CallOnAttachingToMainTree(_Control& control)
1483 result r = E_SUCCESS;
1485 ControlList& children = control.GetChildList();
1486 _Control* pChild = null;
1488 int childrenCount = children.GetCount();
1490 for (int index = 0; index < childrenCount; index++)
1492 r = children.GetAt(index, pChild);
1495 SysAssert(r == E_OUT_OF_RANGE);
1496 SysTryReturn(NID_UI,
1497 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1498 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1500 if (!pChild->IsCalledCallAttachingToMainTree())
1502 r = CallOnAttachingToMainTree(*pChild);
1503 pChild->SetCalledCallAttachingToMainTree(true);
1504 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1508 if (!control.IsCalledCallAttachingToMainTree())
1510 r = control.GetControlDelegate().OnAttachingToMainTree(this);
1511 control.SetCalledCallAttachingToMainTree(true);
1512 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1519 _Control::CallOnPreAttachedToMainTree(_Control& control)
1521 result r = E_SUCCESS;
1523 ControlList& children = control.GetChildList();
1524 _Control* pChild = null;
1526 int childrenCount = children.GetCount();
1528 for (int index = 0; index < childrenCount; index++)
1530 r = children.GetAt(index, pChild);
1533 SysAssert(r == E_OUT_OF_RANGE);
1534 SysTryReturn(NID_UI,
1535 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1536 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1539 if (!pChild->IsCalledCallPreAttachedToMainTree())
1541 r = CallOnPreAttachedToMainTree(*pChild);
1542 pChild->SetCalledCallPreAttachedToMainTree(true);
1546 if (!control.IsCalledCallPreAttachedToMainTree())
1548 r = control.GetControlDelegate().OnPreAttachedToMainTree();
1549 control.SetCalledCallPreAttachedToMainTree(true);
1556 _Control::CallOnAttachedToMainTree(_Control& control)
1558 result r = E_SUCCESS;
1560 ControlList& children = control.GetChildList();
1561 _Control* pChild = null;
1563 int childrenCount = children.GetCount();
1565 for (int index = 0; index < childrenCount; index++)
1567 r = children.GetAt(index, pChild);
1570 SysAssert(r == E_OUT_OF_RANGE);
1571 SysTryReturn(NID_UI,
1572 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1573 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1576 if (!pChild->IsCalledCallAttachedToMainTree())
1578 r = CallOnAttachedToMainTree(*pChild);
1579 pChild->SetCalledCallAttachedToMainTree(true);
1583 if (!control.IsCalledCallAttachedToMainTree())
1585 r = control.GetControlDelegate().OnAttachedToMainTree();
1586 control.SetCalledCallAttachedToMainTree(true);
1593 _Control::CallOnDetachingFromMainTree(_Control& control)
1595 result r = E_SUCCESS;
1597 ControlList& children = control.GetChildList();
1598 _Control* pChild = null;
1600 _Window* pTop = control.GetRootWindow();
1603 _Control* pControl = pTop->GetFocusControl(this);
1604 if ((&control) == pControl)
1606 pTop->SetFocusControl(&control, false);
1608 _Control* pFocusTraversalControl = pTop->GetFocusTraversalControl(this);
1609 if ((&control) == pFocusTraversalControl)
1611 pTop->SetFocusTraversalControl(&control, false);
1615 if (!__isPostOrderTraversal)
1617 r = control.GetControlDelegate().OnDetachingFromMainTree();
1618 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1621 int childrenCount = children.GetCount();
1623 for (int index = 0; index < childrenCount; index++)
1625 r = children.GetAt(index, pChild);
1628 SysAssert(r == E_OUT_OF_RANGE);
1629 SysTryReturn(NID_UI,
1630 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1631 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1633 r = CallOnDetachingFromMainTree(*pChild);
1634 pChild->SetCalledCallAttachingToMainTree(false);
1635 pChild->SetCalledCallPreAttachedToMainTree(false);
1636 pChild->SetCalledCallAttachedToMainTree(false);
1637 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1640 if (__isPostOrderTraversal)
1642 r = control.GetControlDelegate().OnDetachingFromMainTree();
1643 control.SetCalledCallAttachingToMainTree(false);
1644 control.SetCalledCallPreAttachedToMainTree(false);
1645 control.SetCalledCallAttachedToMainTree(false);
1646 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1653 _Control::CallOnAncestorVisibleStateChanged(void)
1658 _Visitor(_Control& parent)
1659 : __parent(parent){}
1661 virtual VisitType Visit(_Control& control)
1663 control.GetControlDelegate().OnAncestorVisibleStateChanged(__parent);
1664 return VISIT_DOWNWARD;
1670 _Visitor visitor(*this);
1675 _Control::CallOnAncestorEnableStateChanged(void)
1680 _Visitor(_Control& parent)
1681 : __parent(parent){}
1683 virtual VisitType Visit(_Control& control)
1685 control.GetControlDelegate().OnAncestorEnableStateChanged(__parent);
1686 return VISIT_DOWNWARD;
1692 _Visitor visitor(*this);
1697 _Control::CallOnAncestorInputEnableStateChanged(void)
1702 _Visitor(_Control& parent)
1703 : __parent(parent){}
1705 virtual VisitType Visit(_Control& control)
1707 control.GetControlDelegate().OnAncestorInputEnableStateChanged(__parent);
1708 return VISIT_DOWNWARD;
1714 _Visitor visitor(*this);
1720 // [ToDo] Rollback is difficult.
1722 _Control::StartAttaching(_Control& child, _ControlArea area)
1724 result r = E_SUCCESS;
1726 _Control* pOldParent = child.GetParent();
1728 SysTryReturn(NID_UI,
1729 (pOldParent != this), E_INVALID_ARG,
1730 E_INVALID_ARG, "[E_INVALID_ARG] The child control is already attached to this container.");
1732 SysTryReturn(NID_UI,
1733 pOldParent == null, E_INVALID_ARG,
1734 E_INVALID_ARG, "[E_INVALID_ARG] Unable to add the child which already has another parent.");
1736 r = child.GetControlDelegate().OnAttaching(this);
1737 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1739 if (IsAttachedToMainTree())
1741 r = CallOnAttachingToMainTree(child);
1742 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1745 // [ToDo] Add control to layout
1746 // What should we do about non-layoutable controls?
1747 if (area == _CONTROL_AREA_CLIENT)
1749 _ControlManager* pMgr = _ControlManager::GetInstance();
1750 r = GetLastResult();
1751 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
1753 r = __pLayoutContainer->AddItem(child.GetLayoutContainer());
1756 child.GetControlDelegate().OnAttachingFailed(*this);
1757 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] Failed to apply layout.");
1762 if (IsAttachedToMainTree())
1764 if (!(IsOrientationRoot() && child.IsOrientationRoot()))
1766 child.ChangeLayout(_ControlManager::GetInstance()->GetOrientation());
1770 child.__area = area;
1772 if (area == _CONTROL_AREA_CLIENT)
1774 if (child.GetLayer() != _CONTROL_LAYER_CLIENT_TOP && child.GetLayer() != _CONTROL_LAYER_CLIENT_BOTTOM)
1776 child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1781 child.SetLayer(_CONTROL_LAYER_SYSTEM);
1784 SysAssert(GetLastResult() == E_SUCCESS);
1789 _Control::EndAttaching(_Control& child)
1791 child.SetParent(this);
1792 InvalidateHierarchyRootWindow(child);
1793 InvalidateHierarchyAbsoluteBounds(child);
1795 FloatRectangle floatBounds(child.GetBoundsF().x, child.GetBoundsF().y, child.GetBoundsF().width, child.GetBoundsF().height);
1797 result r = E_SUCCESS;
1798 if (child.IsLayoutChangable() == false)
1800 r = child.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, floatBounds.width, floatBounds.height));
1804 r = child.UpdateBoundsOfVisualElement(floatBounds);
1806 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1808 r = child.GetControlDelegate().OnAttached();
1809 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1811 if (IsAttachedToMainTree())
1813 r = CallOnPreAttachedToMainTree(child);
1814 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1816 r = CallOnAttachedToMainTree(child);
1817 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1822 GetControlDelegate().OnChildAttached(child);
1832 _Control::AttachChild(_Control& child)
1835 result r = E_SUCCESS;
1837 SysTryReturn(NID_UI,
1838 IsChildAttachable(child), E_INVALID_ARG,
1839 E_INVALID_ARG, "[E_INVALID_ARG] %ls cannot be a child of %ls.",
1840 child.GetName().GetPointer(), GetName().GetPointer());
1842 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1848 ControlList& children = GetChildList();
1849 r = children.Add(&child);
1850 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1852 r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1854 r = EndAttaching(child);
1857 result listResult = children.Remove(&child);
1858 if (IsFailed(listResult))
1860 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
1865 SysAssert(GetLastResult() == E_SUCCESS);
1871 _Control::UpdateFocusList(void)
1873 _Window* pTop = GetRootWindow();
1876 pTop->ResetFocusList();
1881 _Control::RemoveFocusRing(void)
1883 if (__pFocusVisualElement)
1885 __pFocusVisualElement->SetShowState(false);
1890 _Control::HasFocusRing(void)
1892 if (__pFocusVisualElement)
1901 _Control::SetFocusNavigateEnabled(bool enable)
1903 __isNavigatable = enable;
1907 _Control::IsFocusNavigateEnabled(void) const
1909 return __isNavigatable;
1913 _Control::IsFocusModeStateEnabled(void) const
1915 return _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
1922 _Control::InsertChildToBottom(_Control& child)
1925 result r = E_SUCCESS;
1927 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1933 ControlList& children = GetChildList();
1934 r = children.InsertAt(&child, 0);
1935 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1937 GetVisualElement()->InsertChild(*child.GetVisualElement(), null, false);
1938 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1940 r = EndAttaching(child);
1943 result listResult = children.Remove(&child);
1944 if (IsFailed(listResult))
1946 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
1951 SysAssert(GetLastResult() == E_SUCCESS);
1959 _Control::InsertChildAfter(const _Control& targetChild, _Control& child)
1962 result r = E_SUCCESS;
1964 SysTryReturn(NID_UI,
1965 targetChild.GetParent() == this, E_INVALID_ARG,
1966 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
1968 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1974 int targetIndex = GetChildIndex(targetChild);
1975 SysAssert(targetIndex != -1);
1977 ControlList& children = GetChildList();
1978 r = children.InsertAt(&child, targetIndex + 1);
1979 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1981 GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), true);
1982 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1984 r = EndAttaching(child);
1987 result listResult = children.Remove(&child);
1988 if (IsFailed(listResult))
1990 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
1995 SysAssert(GetLastResult() == E_SUCCESS);
2003 _Control::InsertChildBefore(const _Control& targetChild, _Control& child)
2006 result r = E_SUCCESS;
2008 SysTryReturn(NID_UI,
2009 targetChild.GetParent() == this, E_INVALID_ARG,
2010 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
2012 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
2018 int targetIndex = GetChildIndex(targetChild);
2019 SysAssert(targetIndex != -1);
2021 ControlList& children = GetChildList();
2022 r = children.InsertAt(&child, targetIndex);
2023 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2025 GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), false);
2026 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2028 r = EndAttaching(child);
2031 result listResult = children.Remove(&child);
2032 if (IsFailed(listResult))
2034 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
2039 SysAssert(GetLastResult() == E_SUCCESS);
2045 _Control::DetachChild(_Control& child)
2048 result r = E_SUCCESS;
2050 if (child.GetParent() != this)
2052 SetLastResult(E_INVALID_ARG);
2053 return E_INVALID_ARG;
2056 if (IsAttachedToMainTree())
2058 r = CallOnDetachingFromMainTree(child);
2059 SysTryReturn(NID_UI,
2060 r == E_SUCCESS, E_SYSTEM,
2061 E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2063 SysTryReturn(NID_UI,
2064 child.GetControlDelegate().OnDetaching() == E_SUCCESS, E_SYSTEM,
2065 E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2068 GetControlDelegate().OnChildDetaching(child);
2071 r = GetVisualElement()->DetachChild(*child.GetVisualElement());
2072 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2074 ControlList& children = GetChildList();
2075 r = children.Remove(&child);
2076 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2078 // Remove control to layout
2079 if (child.__area == _CONTROL_AREA_CLIENT)
2081 _ControlManager* pMgr = _ControlManager::GetInstance();
2082 r = GetLastResult();
2083 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
2085 r = __pLayoutContainer->RemoveItem(child.GetLayoutContainer());
2086 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2089 child.SetParent(null);
2090 child.__area = _CONTROL_AREA_NONE;
2091 child.__layer = _CONTROL_LAYER_NONE;
2093 GetControlDelegate().OnChildDetached(child);
2096 SysAssert(GetLastResult() == E_SUCCESS);
2098 InvalidateHierarchyRootWindow(child);
2105 _Control::DetachAllChildren(bool detachSystemChild, bool recursive)
2108 result r = E_SUCCESS;
2110 int childCount = GetChildCount();
2115 while (childCount--)
2117 _Control* pChild = GetChild(itemIndex);
2123 if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2129 int childCount = pChild->GetChildCount();
2130 if (childCount == 0)
2132 r = DetachChild(*pChild);
2135 SysLog(NID_UI, "child is not detached from this container.");
2140 r = DetachChild(*pChild);
2143 SysLog(NID_UI, "child is not detached from this container.");
2145 pChild->DetachAllChildren(detachSystemChild, true);
2151 int notDetachedChildCount = 0;
2152 while (childCount--)
2154 _Control* pChild = GetChild(itemIndex);
2160 if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2165 r = DetachChild(*pChild);
2169 ++notDetachedChildCount;
2173 if (notDetachedChildCount > 0)
2175 SysLog(NID_UI, "%d children are not detached from this container.", notDetachedChildCount);
2184 _Control::MoveChildToTop(const _Control& child)
2187 result r = E_SUCCESS;
2189 SysTryReturn(NID_UI,
2190 child.GetParent() == this, E_INVALID_ARG,
2191 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2193 // If already on top,
2194 ControlList& children = GetChildList();
2195 if (GetChildIndex(child) == children.GetCount() - 1)
2197 SysAssert(GetLastResult() == E_SUCCESS);
2201 _Control* pChild = const_cast <_Control*>(&child);
2203 r = children.Remove(pChild);
2204 SysAssert(r == E_SUCCESS);
2206 r = children.Add(pChild);
2207 SysAssert(r == E_SUCCESS);
2209 r = child.GetVisualElement()->SetZOrder(null, true);
2210 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2212 SysAssert(GetLastResult() == E_SUCCESS);
2218 _Control::MoveChildToBottom(const _Control& child)
2221 result r = E_SUCCESS;
2223 SysTryReturn(NID_UI,
2224 child.GetParent() == this, E_INVALID_ARG,
2225 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2227 ControlList& children = GetChildList();
2229 if (GetChildIndex(child) == 0)
2231 SysAssert(GetLastResult() == E_SUCCESS);
2235 _Control* pChild = const_cast <_Control*>(&child);
2237 r = children.Remove(pChild);
2238 SysAssert(r == E_SUCCESS);
2240 r = children.InsertAt(pChild, 0);
2241 SysAssert(r == E_SUCCESS);
2243 r = child.GetVisualElement()->SetZOrder(null, false);
2244 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2246 SysAssert(GetLastResult() == E_SUCCESS);
2252 _Control::MoveChildAfter(const _Control& targetChild, const _Control& child)
2255 result r = E_SUCCESS;
2257 SysTryReturn(NID_UI,
2258 targetChild.GetParent() == this, E_INVALID_ARG,
2259 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2261 SysTryReturn(NID_UI,
2262 child.GetParent() == this, E_INVALID_ARG,
2263 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2265 SysTryReturn(NID_UI,
2266 &targetChild != &child, E_INVALID_ARG,
2267 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move after self.");
2269 ControlList& children = GetChildList();
2271 int targetIndex = GetChildIndex(targetChild);
2272 SysAssert(targetIndex != -1);
2274 if (targetIndex + 1 == GetChildIndex(child))
2276 SysAssert(GetLastResult() == E_SUCCESS);
2280 _Control* pChild = const_cast <_Control*>(&child);
2282 r = children.Remove(pChild);
2283 SysAssert(r == E_SUCCESS);
2285 r = children.InsertAt(pChild, targetIndex + 1);
2286 SysAssert(r == E_SUCCESS);
2288 r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), true);
2289 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2291 SysAssert(GetLastResult() == E_SUCCESS);
2297 _Control::MoveChildBefore(const _Control& targetChild, const _Control& child)
2300 result r = E_SUCCESS;
2302 SysTryReturn(NID_UI,
2303 targetChild.GetParent() == this, E_INVALID_ARG,
2304 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2306 SysTryReturn(NID_UI,
2307 child.GetParent() == this, E_INVALID_ARG,
2308 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2310 SysTryReturn(NID_UI,
2311 &targetChild != &child, E_INVALID_ARG,
2312 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move before self.");
2314 ControlList& children = GetChildList();
2316 int targetIndex = GetChildIndex(targetChild);
2317 SysAssert(targetIndex != -1);
2319 if (targetIndex - 1 == GetChildIndex(child))
2321 SysAssert(GetLastResult() == E_SUCCESS);
2325 _Control* pChild = const_cast <_Control*>(&child);
2327 r = children.Remove(pChild);
2328 SysAssert(r == E_SUCCESS);
2330 r = children.InsertAt(pChild, targetIndex);
2331 SysAssert(r == E_SUCCESS);
2333 r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), false);
2334 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2336 SysAssert(GetLastResult() == E_SUCCESS);
2343 _Control::GetChildIndex(const _Control& child) const
2346 result r = E_SUCCESS;
2348 SysTryReturn(NID_UI,
2349 child.GetParent() == this, -1,
2350 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2352 const ControlList& children = GetChildList();
2355 r = children.IndexOf(const_cast<_Control*>(&child), index);
2358 SysAssert(r == E_OBJ_NOT_FOUND);
2359 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
2363 SysAssert(GetLastResult() == E_SUCCESS);
2369 _Control::GetChild(int index) const
2372 result r = E_SUCCESS;
2374 const ControlList& children = GetChildList();
2376 _Control* pChild = null;
2377 r = children.GetAt(index, pChild);
2380 SysAssert(r == E_OUT_OF_RANGE);
2381 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
2385 SysAssert(GetLastResult() == E_SUCCESS);
2390 _Control::GetChildCount(void) const
2393 return GetChildList().GetCount();
2397 _Control::GetHandle(void) const
2399 return __controlHandle;
2403 _Control::GetUserData(void) const
2409 _Control::SetUserData(void* pUserData)
2411 __pUserData = pUserData;
2415 _Control::GetPropertyName(void) const
2418 return Tizen::Ui::Variant(__name);
2422 _Control::GetName(void) const
2424 Variant name = GetProperty("Name");
2426 return name.ToString();
2430 _Control::SetPropertyName(const Variant& name)
2433 __name = name.ToString();
2439 _Control::SetName(const String& name)
2441 SetProperty("Name", Variant(name));
2445 _Control::GetParent(void) const
2451 _Control::GetCanvasN(void) const
2453 return GetCanvasN(FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
2457 _Control::GetCanvasN(const Rectangle& bounds) const
2460 Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
2461 if (pCanvas == null)
2463 GetVisualElement()->SetFlushNeeded();
2464 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2465 if (IsFailed(GetLastResult()))
2467 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2470 if (pCanvas && !__isCalledGetCanvasN)
2472 pCanvas->SetBackgroundColor(GetBackgroundColor());
2474 const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2481 _Control::GetCanvasN(const FloatRectangle& bounds) const
2484 Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds));
2485 if (pCanvas == null)
2487 GetVisualElement()->SetFlushNeeded();
2488 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2489 if (IsFailed(GetLastResult()))
2491 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2494 if (pCanvas && !__isCalledGetCanvasN)
2496 pCanvas->SetBackgroundColor(GetBackgroundColor());
2498 const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2505 _Control::IsCalledGetCanvasN(void) const
2507 return __isCalledGetCanvasN;
2511 _Control::GetClientCanvasN(void) const
2513 return GetCanvasN(GetClientBounds());
2517 _Control::IsAncestorOf(const _Control& control) const
2521 const _Control* pParent = control.GetParent();
2531 const _Control& __ancestor;
2536 _Visitor(const _Control& ancestor)
2537 : __ancestor(ancestor)
2540 virtual VisitType Visit(_Control& control)
2542 if (&__ancestor == &control)
2549 return VISIT_UPWARD;
2554 _Visitor visitor(*this);
2555 pParent->Accept(visitor);
2557 SysAssert(GetLastResult() == E_SUCCESS);
2562 _Control::GetRootWindow(void) const
2566 if (!__needRecalcRootWindow && __pRootWindow != this)
2568 return __pRootWindow;
2579 virtual VisitType Visit(_Control& control)
2581 pRoot = dynamic_cast <_Window*>(&control);
2587 return VISIT_UPWARD;
2594 SysAssert(GetLastResult() == E_SUCCESS);
2596 const_cast<_Control*>(this)->__pRootWindow = visitor.pRoot;
2597 const_cast<_Control*>(this)->__needRecalcRootWindow = false;
2599 return visitor.pRoot;
2603 _Control::IsAttachedToMainTree(void) const
2607 _ControlManager* pMgr = _ControlManager::GetInstance();
2613 _Window* pRootWindow = GetRootWindow();
2614 if (pRootWindow == null)
2619 return pRootWindow->IsAttached();
2623 _Control::IsFocusable(void) const
2630 _Control::SetFocusable(bool focusable)
2633 bool oldState = __focusable;
2634 __focusable = focusable;
2635 if (oldState != __focusable)
2637 GetControlDelegate().OnFocusableStateChanged(focusable);
2642 _Control::IsNativeObjectFocusable(void) const
2645 return __nativeObjectFocusable;
2649 _Control::SetNativeObjectFocusable(bool focusable)
2652 __nativeObjectFocusable = focusable;
2656 _Control::IsFocused(void) const
2660 _Window* pTop = GetRootWindow();
2666 if (this == pTop->GetFocusControl(const_cast<_Control*>(this)))
2675 _Control::SetFocusWindowActivationChecked(bool isChecked)
2677 __isFocusWindowActivationChecked = isChecked;
2681 _Control::IsFocusWindowActivationChecked(void)
2683 return __isFocusWindowActivationChecked;
2687 _Control::SetFocused(bool on)
2691 SysTryReturn(NID_UI,
2692 IsAttachedToMainTree(), E_INVALID_OPERATION,
2693 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2695 SysTryReturn(NID_UI,
2696 IsFocusable(), E_INVALID_OPERATION,
2697 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This Control isn't focusable control.");
2699 _Window* pTop = GetRootWindow();
2703 pTop->SetFocusControl(this, true);
2707 pTop->SetFocusControl(this, false);
2714 _Control::SetFont(const String& fontName)
2716 result r = E_SUCCESS;
2718 if (__fontName.Equals(fontName))
2723 __isControlFontChanged = true;
2724 __fontName = fontName;
2725 __fontFileName.Clear();
2727 Font* pFont = GetFallbackFont();
2731 r = GetLastResult();
2732 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2738 _Control::GetFallbackFont(void)
2740 unsigned long style = 0;
2742 float floatTextSize = 0.0f;
2743 result r = E_SUCCESS;
2744 _IControlDelegate& delegate = GetControlDelegate();
2745 delegate.OnFontInfoRequested(style, textSize);
2746 delegate.OnFontInfoRequested(style, floatTextSize);
2747 _ControlManager* pControlManager = _ControlManager::GetInstance();
2748 _FontImpl* pFontImpl = _FontImpl::GetInstance(*__pFont);
2749 if (!(__isControlFontChanged || pControlManager->IsDefaultFontChanged() || pControlManager->IsSystemFontChanged())
2751 && ((__pFont->GetSize() == textSize || __pFont->GetSizeF() == floatTextSize))
2752 && (pFontImpl->GetStyle() == static_cast<int>(style)))
2756 unique_ptr<Font>pTempFont(new(std::nothrow)Font());
2757 SysTryReturn(NID_UI , pTempFont , null , E_OUT_OF_MEMORY, "[%s] Fails to create a __pFont.", GetErrorMessage(r));
2759 if (!__fontName.IsEmpty())
2761 __isControlFontChanged = false;
2762 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2763 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2765 if (floatTextSize > 0.0f)
2767 r = pFontImpl->Construct(__fontName, style, floatTextSize, false);
2771 r = pFontImpl->Construct(__fontName, style, textSize, false);
2774 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2775 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2777 else if (!__fontFileName.IsEmpty())
2779 __isControlFontChanged = false;
2780 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2781 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2783 if (floatTextSize > 0.0f)
2785 r = pFontImpl->Construct(__fontFileName, style, floatTextSize);
2789 r = pFontImpl->Construct(__fontFileName, style, textSize);
2791 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2792 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2795 else if (!pControlManager->GetDefaultFont().IsEmpty())
2797 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2798 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2800 if (floatTextSize > 0.0f)
2802 r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, floatTextSize, false);
2806 r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, textSize, false);
2808 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2809 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2811 else if (!pControlManager->GetDefaultFontFile().IsEmpty())
2813 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2814 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2816 if (floatTextSize > 0.0f)
2818 r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, floatTextSize);
2822 r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, textSize);
2824 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2825 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2829 if (floatTextSize > 0.0f)
2831 r = pTempFont->Construct(style, floatTextSize);
2835 r = pTempFont->Construct(style, textSize);
2837 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2838 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2846 __pFont = pTempFont.release();
2847 delegate.OnFontChanged(__pFont);
2852 _Control::GetFont(void) const
2858 _Control::IsEnabled(void) const
2870 virtual VisitType Visit(_Control& control)
2872 if (!control.GetEnableState())
2878 return VISIT_UPWARD;
2884 return visitor.enabled;
2888 _Control::GetEnableState(void) const
2891 return __enabledState;
2895 _Control::SetEnableState(bool enabledState)
2898 const bool changed = (__enabledState != enabledState);
2901 __enabledState = enabledState;
2902 CallOnAncestorEnableStateChanged();
2904 __pAccessibilityContainer->SetEnableState(enabledState);
2908 _Control::IsInputEventEnabled(void) const
2918 : inputEnabled(true){}
2920 virtual VisitType Visit(_Control& control)
2922 if (!control.GetInputEnableState())
2924 inputEnabled = false;
2928 return VISIT_UPWARD;
2934 return visitor.inputEnabled;
2938 _Control::GetInputEnableState(void) const
2942 if (__inputLockRefCount != 0)
2953 _Control::LockInputEvent(void)
2955 __inputLockRefCount++;
2956 CallOnAncestorInputEnableStateChanged();
2960 _Control::UnlockInputEvent(void)
2962 __inputLockRefCount--;
2963 if (__inputLockRefCount < 0)
2965 __inputLockRefCount = 0;
2970 _Control::IsVisible(void) const
2974 if (IsAttachedToMainTree() == false)
2976 SetLastResult(E_SYSTEM);
2988 virtual VisitType Visit(_Control& control)
2990 if (!control.GetVisibleState())
2996 return VISIT_UPWARD;
3003 SysAssert(GetLastResult() == E_SUCCESS);
3004 return visitor.visible;
3008 _Control::GetVisibleState(void) const
3011 return __visibleState;
3015 _Control::SetVisibleState(bool visibleState)
3019 const bool changed = (__visibleState != visibleState) || !__initVisibleState;
3023 GetControlDelegate().OnVisibleStateChanging();
3026 __visibleState = visibleState;
3027 GetVisualElement()->SetShowState(visibleState);
3029 if (visibleState == false)
3031 int owneeCount = GetOwneeCount();
3032 for (int i = 0; i < owneeCount; ++i)
3034 _Window* pWindow = GetOwnee(i);
3037 pWindow->SetVisibleState(visibleState);
3044 GetControlDelegate().OnVisibleStateChanged();
3045 CallOnAncestorVisibleStateChanged();
3046 _Control* pParent = GetParent();
3049 pParent->GetControlDelegate().OnChildVisibleStateChanged(*this);
3055 __initVisibleState = true;
3059 _Control::IsLayoutable(void) const
3066 _Control::IsClipToParent(void) const
3069 // SysAssert(GetVisualElement()->IsClipToParent() == __clipToParent);
3070 return __clipToParent;
3074 _Control::SetClipToParent(bool clipToParent)
3077 result r = E_SUCCESS;
3079 __clipToParent = clipToParent;
3080 r = GetVisualElement()->SetClipToParent(clipToParent);
3081 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
3087 _Control::SetClipChildrenEnabled(bool clipChildren)
3090 //result r = E_SUCCESS;
3092 GetVisualElement()->SetClipChildrenEnabled(clipChildren);
3093 //SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
3099 _Control::GetBounds(void) const
3102 return _CoordinateSystemUtils::ConvertToInteger(__bounds);
3106 _Control::GetBoundsF(void) const
3113 _Control::GetPosition(void) const
3116 return Point(_CoordinateSystemUtils::ConvertToInteger(__bounds.x), _CoordinateSystemUtils::ConvertToInteger(__bounds.y));
3120 _Control::GetPositionF(void) const
3123 return FloatPoint(__bounds.x, __bounds.y);
3127 _Control::GetSize(void) const
3130 return Dimension(_CoordinateSystemUtils::ConvertToInteger(__bounds.width), _CoordinateSystemUtils::ConvertToInteger(__bounds.height));
3134 _Control::GetSizeF(void) const
3137 return FloatDimension(__bounds.width, __bounds.height);
3142 _Control::UpdateBoundsOfVisualElement(const FloatRectangle& controlBounds)
3144 FloatRectangle rect(controlBounds.x, controlBounds.y, controlBounds.width, controlBounds.height);
3146 _Control* pParent = GetParent();
3147 if (__area == _CONTROL_AREA_CLIENT && pParent)
3149 const FloatRectangle clientBounds = pParent->GetClientBoundsF();
3150 rect.x += clientBounds.x;
3151 rect.y += clientBounds.y;
3154 GetVisualElement()->SetBounds(rect);
3160 _Control::AdjustAbsoluteBounds(void)
3165 _Visitor(_Control* pControl)
3166 : __pControl(pControl){}
3168 virtual VisitType Visit(_Control& control)
3170 result r = E_SUCCESS;
3172 if (__pControl == &control)
3174 return VISIT_DOWNWARD;
3176 FloatRectangle fbounds = control.GetBoundsF();
3177 if (control.IsLayoutChangable() == false)
3179 r = control.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3183 r = control.UpdateBoundsOfVisualElement(fbounds);
3186 ControlList& children = control.GetChildList();
3188 int childrenCount = children.GetCount();
3189 if (childrenCount <= 0)
3195 return VISIT_DOWNWARD;
3199 _Control* __pControl;
3202 _Visitor visitor(this);
3209 _Control::IsInSizeRange(const Dimension& size) const
3211 return (__minSize.width <= size.width) && (size.width <= __maxSize.width) &&
3212 (__minSize.height <= size.height) && (size.height <= __maxSize.height);
3216 _Control::IsInSizeRange(const FloatDimension& size) const
3218 return (__minSize.width <= size.width) && (size.width <= __maxSize.width) &&
3219 (__minSize.height <= size.height) && (size.height <= __maxSize.height);
3222 // Custom Exception: ex) Location::Map
3224 _Control::SetBoundsFinal(const FloatRectangle& newBounds, bool changeLayoutBaseRect, bool callBoundsChangeCallbacks)
3226 result r = E_SUCCESS;
3228 FloatRectangle bounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
3230 _IControlDelegate& delegate = GetControlDelegate();
3232 const bool moved = (__bounds.x != bounds.x) || (__bounds.y != bounds.y);
3233 const bool resized = (__bounds.width != bounds.width) || (__bounds.height != bounds.height);
3235 if ((moved || resized) && callBoundsChangeCallbacks)
3237 r = delegate.OnBoundsChanging(_CoordinateSystemUtils::ConvertToInteger(bounds));
3240 SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3241 return r; // Relay the result;
3243 r = delegate.OnBoundsChanging(bounds);
3246 SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3247 return r; // Relay the result;
3251 if (moved || resized)
3253 const FloatRectangle fbounds(bounds.x, bounds.y, bounds.width, bounds.height);
3254 if (IsLayoutChangable() == false)
3256 r = UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3260 r = UpdateBoundsOfVisualElement(fbounds);
3264 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
3268 if (changeLayoutBaseRect)
3270 __pLayoutContainer->OnChangeBaseRect();
3273 if ((moved || resized) && callBoundsChangeCallbacks)
3275 if (IsMovable() && IsResizable())
3277 SetClientBounds(FloatRectangle(0.0f, 0.0f, GetSizeF().width, GetSizeF().height));
3279 if (__pFocusVisualElement)
3281 __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, __bounds.width, __bounds.height));
3283 delegate.OnBoundsChanged();
3285 _Control* pParent = GetParent();
3288 pParent->GetControlDelegate().OnChildBoundsChanged(*this);
3291 ControlList& children = GetChildList();
3292 _Control* pChild = null;
3293 int childrenCount = children.GetCount();
3295 for (int index = 0; index < childrenCount; index++)
3297 r = children.GetAt(index, pChild);
3300 pChild->GetControlDelegate().OnParentBoundsChanged(*this);
3305 if (moved || resized)
3307 InvalidateHierarchyAbsoluteBounds(*this);
3314 // Custom Exception: ex) Location::Map
3316 _Control::AdjustSizeToRange(void)
3319 result r = E_SUCCESS;
3321 SysAssert(IsResizable());
3323 FloatDimension size = GetSizeF();
3324 bool changed = ::AdjustSizeToRange(size, __minSize, __maxSize);
3330 FloatRectangle newBounds(__bounds.x, __bounds.y, size.width, size.height);
3331 r = SetBoundsFinal(newBounds, true, true);
3340 // Custom Exception: ex) Location::Map
3343 _Control::SetBoundsInternal(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3345 SysTryReturn(NID_UI,
3346 IsInSizeRange(Dimension(bounds.width, bounds.height)), E_INVALID_ARG,
3348 "[E_INVALID_ARG] The specified size(%f, %f) is out of range from min size(%d, %d) to max size(%d, %d).",
3349 bounds.width, bounds.height, __minSize.width, __minSize.height, __maxSize.width, __maxSize.height);
3351 SetUpdateLayoutState(true);
3353 return SetBoundsFinal(bounds, true, callBoundsChangeCallbacks);
3356 // Custom Exception: ex) Location::Map
3358 // E_UNSUPPORTED_OPERATION
3360 _Control::SetBounds(const Rectangle& bounds, bool callBoundsChangeCallbacks)
3364 if (callBoundsChangeCallbacks)
3366 SysTryReturn(NID_UI,
3367 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3368 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3370 FloatRectangle floatBounds(bounds.x, bounds.y, bounds.width, bounds.height);
3372 return SetBoundsInternal(floatBounds, callBoundsChangeCallbacks);
3375 // Custom Exception: ex) Location::Map
3377 // E_UNSUPPORTED_OPERATION
3379 _Control::SetBounds(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3383 if (callBoundsChangeCallbacks)
3385 SysTryReturn(NID_UI,
3386 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3387 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3390 return SetBoundsInternal(bounds, callBoundsChangeCallbacks);
3393 // A custom Exception can occur. ex) Location::Map
3395 // E_UNSUPPORTED_OPERATION
3397 _Control::SetPosition(const Point& position)
3401 SysTryReturn(NID_UI,
3402 IsMovable(), E_UNSUPPORTED_OPERATION,
3403 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3405 return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3409 _Control::SetPosition(const FloatPoint& position)
3413 SysTryReturn(NID_UI,
3414 IsMovable(), E_UNSUPPORTED_OPERATION,
3415 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3417 return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3420 // Custom Exception: ex) Location::Map
3422 // E_UNSUPPORTED_OPERATION
3424 _Control::SetSize(const Dimension& size)
3428 SysTryReturn(NID_UI,
3429 IsResizable(), E_UNSUPPORTED_OPERATION,
3430 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3432 return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3436 _Control::SetSize(const FloatDimension& size)
3440 SysTryReturn(NID_UI,
3441 IsResizable(), E_UNSUPPORTED_OPERATION,
3442 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3444 return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3448 _Control::GetMinimumSize(void) const
3452 return _CoordinateSystemUtils::ConvertToInteger(__minSize);
3456 _Control::GetMinimumSizeF(void) const
3464 _Control::GetMaximumSize(void) const
3468 return _CoordinateSystemUtils::ConvertToInteger(__maxSize);
3472 _Control::GetMaximumSizeF(void) const
3479 // Custom Exception: ex) Location::Map
3480 // E_UNSUPPORTED_OPERATION
3483 _Control::SetMinimumSize(const Dimension& newMinSize)
3487 SysTryReturn(NID_UI,
3488 IsResizable(), E_UNSUPPORTED_OPERATION,
3489 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3491 SysTryReturn(NID_UI,
3492 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3493 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3495 SysTryReturn(NID_UI,
3496 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3497 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3499 if (__maxSize.width < newMinSize.width)
3501 __maxSize.width = newMinSize.width;
3503 if (__maxSize.height < newMinSize.height)
3505 __maxSize.height = newMinSize.height;
3508 __minSize = _CoordinateSystemUtils::ConvertToFloat(newMinSize);
3509 return AdjustSizeToRange();
3513 _Control::SetMinimumSize(const FloatDimension& newMinSize)
3517 SysTryReturn(NID_UI,
3518 IsResizable(), E_UNSUPPORTED_OPERATION,
3519 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3521 SysTryReturn(NID_UI,
3522 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3523 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3525 SysTryReturn(NID_UI,
3526 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3527 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3529 if (__maxSize.width < newMinSize.width)
3531 __maxSize.width = newMinSize.width;
3533 if (__maxSize.height < newMinSize.height)
3535 __maxSize.height = newMinSize.height;
3538 __minSize = newMinSize;
3539 return AdjustSizeToRange();
3542 // Custom Exception: ex) Location::Map
3543 // E_UNSUPPORTED_OPERATION
3546 _Control::SetMaximumSize(const Dimension& newMaxSize)
3550 SysTryReturn(NID_UI,
3551 IsResizable(), E_UNSUPPORTED_OPERATION,
3552 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3554 SysTryReturn(NID_UI,
3555 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3556 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3558 SysTryReturn(NID_UI,
3559 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3560 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3562 if (newMaxSize.width < __minSize.width)
3564 __minSize.width = newMaxSize.width;
3566 if (newMaxSize.height < __minSize.height)
3568 __minSize.height = newMaxSize.height;
3571 __maxSize = _CoordinateSystemUtils::ConvertToFloat(newMaxSize);
3572 return AdjustSizeToRange();
3576 _Control::SetMaximumSize(const FloatDimension& newMaxSize)
3580 SysTryReturn(NID_UI,
3581 IsResizable(), E_UNSUPPORTED_OPERATION,
3582 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3584 SysTryReturn(NID_UI,
3585 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3586 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3588 SysTryReturn(NID_UI,
3589 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3590 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3592 if (newMaxSize.width < __minSize.width)
3594 __minSize.width = newMaxSize.width;
3596 if (newMaxSize.height < __minSize.height)
3598 __minSize.height = newMaxSize.height;
3601 __maxSize = newMaxSize;
3602 return AdjustSizeToRange();
3607 _Control::ConvertToControlPosition(const Point& screenPosition) const
3609 Point controlPosition;
3610 Rectangle absoluteBounds = GetAbsoluteBounds();
3612 controlPosition.x = screenPosition.x - absoluteBounds.x;
3613 controlPosition.y = screenPosition.y - absoluteBounds.y;
3615 return controlPosition;
3619 _Control::ConvertToControlPosition(const FloatPoint& screenPosition) const
3621 FloatPoint controlPosition;
3622 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3624 controlPosition.x = screenPosition.x - absoluteBounds.x;
3625 controlPosition.y = screenPosition.y - absoluteBounds.y;
3627 return controlPosition;
3631 _Control::ConvertToScreenPosition(const Point& controlPosition) const
3633 Point screenPosition;
3634 Rectangle absoluteBounds = GetAbsoluteBounds();
3636 screenPosition.x = controlPosition.x + absoluteBounds.x;
3637 screenPosition.y = controlPosition.y + absoluteBounds.y;
3639 return screenPosition;
3643 _Control::ConvertToScreenPosition(const FloatPoint& controlPosition) const
3645 FloatPoint screenPosition;
3646 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3648 screenPosition.x = controlPosition.x + absoluteBounds.x;
3649 screenPosition.y = controlPosition.y + absoluteBounds.y;
3651 return screenPosition;
3655 _Control::GetClientBounds(void) const
3657 if (!__isSetClientBounds)
3659 return Rectangle(0, 0, __bounds.width, __bounds.height);
3662 return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3666 _Control::GetClientBoundsF(void) const
3668 if (!__isSetClientBounds)
3670 return FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height);
3673 return __clientBounds;
3678 _Control::GetClientBounds(const Tizen::Graphics::Dimension& size) const
3680 if (!__isSetClientBounds)
3682 return Rectangle(0, 0, size.width, size.height);
3685 return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3690 _Control::GetClientBoundsF(const Tizen::Graphics::FloatDimension& size) const
3692 if (!__isSetClientBounds)
3694 return FloatRectangle(0.0f, 0.0f, size.width, size.height);
3697 return __clientBounds;
3701 _Control::GetAbsoluteBounds(bool recalcAlways) const
3703 if (!recalcAlways && !__needRecalcAbsBounds)
3705 return __absoluteBounds;
3709 Rectangle absoluteBounds;
3710 Rectangle clientBounds;
3712 const _Control* pSelf = this;
3713 const _Control* pParent = GetParent();
3717 if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3719 clientBounds = pParent->GetClientBounds();
3720 accumPoint += Point(clientBounds.x, clientBounds.y);
3721 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3722 accumPoint.y -= pParent->GetVerticalScrollPosition();
3725 accumPoint += pSelf->GetPosition();
3727 pParent = pParent->GetParent();
3730 _Window* pWindow = GetRootWindow();
3734 Point winPoint = pWindow->GetPosition();
3736 accumPoint.x += winPoint.x;
3737 accumPoint.y += winPoint.y;
3740 absoluteBounds.x = accumPoint.x;
3741 absoluteBounds.y = accumPoint.y;
3742 absoluteBounds.width = __bounds.width;
3743 absoluteBounds.height = __bounds.height;
3745 const_cast<_Control*>(this)->__absoluteBounds = absoluteBounds;
3746 const_cast<_Control*>(this)->__needRecalcAbsBounds = false;
3748 return absoluteBounds;
3752 _Control::GetAbsoluteBoundsF(bool recalcAlways) const
3754 if (!recalcAlways && !__needRecalcAbsBoundsF)
3756 return __absoluteBoundsF;
3759 FloatPoint accumPoint;
3760 FloatRectangle absoluteBounds;
3761 FloatRectangle clientBounds;
3763 const _Control* pSelf = this;
3764 const _Control* pParent = GetParent();
3768 if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3770 clientBounds = pParent->GetClientBoundsF();
3771 accumPoint += FloatPoint(clientBounds.x, clientBounds.y);
3772 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3773 accumPoint.y -= pParent->GetVerticalScrollPosition();
3776 accumPoint += pSelf->GetPositionF();
3778 pParent = pParent->GetParent();
3781 _Window* pWindow = GetRootWindow();
3785 FloatPoint winPoint = pWindow->GetPositionF();
3787 accumPoint.x += winPoint.x;
3788 accumPoint.y += winPoint.y;
3791 absoluteBounds.x = accumPoint.x;
3792 absoluteBounds.y = accumPoint.y;
3793 absoluteBounds.width = __bounds.width;
3794 absoluteBounds.height = __bounds.height;
3796 const_cast<_Control*>(this)->__absoluteBoundsF = absoluteBounds;
3797 const_cast<_Control*>(this)->__needRecalcAbsBoundsF = false;
3799 return absoluteBounds;
3803 _Control::SetClientBounds(const Rectangle& bounds)
3807 const bool moved = (__clientBounds.x != _CoordinateSystemUtils::ConvertToFloat(bounds).x) || (__clientBounds.y != _CoordinateSystemUtils::ConvertToFloat(bounds).y);
3808 const bool resized = (__clientBounds.width != _CoordinateSystemUtils::ConvertToFloat(bounds).width) || (__clientBounds.height != _CoordinateSystemUtils::ConvertToFloat(bounds).height);
3810 SysTryReturn(NID_UI,
3811 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3812 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3813 __clientBounds = _CoordinateSystemUtils::ConvertToFloat(bounds);
3814 __isSetClientBounds = true;
3816 if (moved || resized)
3818 result r = AdjustAbsoluteBounds();
3819 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3821 SetUpdateLayoutState(true);
3827 _Control::SetClientBounds(const FloatRectangle& bounds)
3831 const bool moved = (__clientBounds.x != bounds.x) || (__clientBounds.y != bounds.y);
3832 const bool resized = (__clientBounds.width != bounds.width) || (__clientBounds.height != bounds.height);
3834 SysTryReturn(NID_UI,
3835 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3836 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3837 __clientBounds = bounds;
3838 __isSetClientBounds = true;
3840 if (moved || resized)
3842 result r = AdjustAbsoluteBounds();
3843 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3845 SetUpdateLayoutState(true);
3852 _Control::IsCalledSetClientBounds(void)
3854 return __isSetClientBounds;
3858 _Control::UpdateClientBounds(const FloatDimension& size, FloatRectangle& clientBounds)
3860 clientBounds.width = size.width;
3861 clientBounds.height = size.height;
3865 _Control::GetBackgroundColor(void) const
3868 return __backgroundColor;
3872 _Control::SetBackgroundColor(const Color& color)
3875 __backgroundColor = color;
3877 _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(GetVisualElement());
3880 pCVE->SetBackgroundColor(
3882 (float)color.GetRed() / 255.0f,
3883 (float)color.GetGreen() / 255.0f,
3884 (float)color.GetBlue() / 255.0f,
3885 (float)color.GetAlpha() / 255.0f
3890 GetControlDelegate().OnBackgroundColorChanged(const_cast<Color&>(color));
3894 _Control::~_Control(void)
3896 __destroying = true;
3898 DoBacktrace(__pDeleteBacktrace.get());
3900 DetachAllChildren();
3902 _ControlManager::GetInstance()->TakeFocusFromControl(*this);
3912 // Dangerous: it clears last result and log in catch block.
3913 // ClearLastResult();
3917 _Control::DisposeControl(void)
3919 __pControlDelegate = null;
3921 delete __pLayoutItemHandler;
3922 __pLayoutItemHandler = null;
3924 delete __pLayoutContainer;
3925 __pLayoutContainer = null;
3933 if (__pVisualElement)
3935 __pVisualElement->Destroy();
3937 __pVisualElement = null;
3939 delete __pVisualElementContentProvider;
3940 __pVisualElementContentProvider = null;
3942 delete __pVisualElementEventListener;
3943 __pVisualElementEventListener = null;
3945 delete __pCoreGestureDetectors;
3946 __pCoreGestureDetectors = null;
3948 delete __pDataBindingContext;
3949 __pDataBindingContext = null;
3951 ClearStartedGestureDetectorList();
3952 delete __pDetectStartedGestureMap;
3953 __pDetectStartedGestureMap = null;
3955 delete __pDelayedTouchInfoList;
3956 __pDelayedTouchInfoList = null;
3958 delete __pAccessibilityContainer;
3959 __pAccessibilityContainer = null;
3961 if (__pFocusVisualElement)
3963 __pFocusVisualElement.release();
3969 _Control::_Control(void)
3970 : __needRecalcRootWindow(true)
3971 , __needRecalcAbsBounds(true)
3972 , __needRecalcAbsBoundsF(true)
3973 , __pRootWindow(null)
3978 , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
3979 , __contentAreaBounds(0.0f, 0.0f, 0.0f, 0.0f)
3980 , __clientBounds(0.0f, 0.0f, 0.0f, 0.0f)
3981 , __absoluteBounds(0, 0, 0, 0)
3982 , __absoluteBoundsF(0.0f, 0.0f, 0.0f, 0.0f)
3983 , __invalidatedBounds(0.0f, 0.0f, 0.0f, 0.0f)
3984 , __minSize(FloatDimension(0.0f, 0.0f))
3985 , __maxSize(FloatDimension(MAX_LENGTH, MAX_LENGTH))
3986 , __backgroundColor(Color::GetColor(COLOR_ID_BLACK))
3990 , __nativeObjectFocusable(true)
3991 , __enabledState(true)
3992 , __visibleState(true)
3993 , __initVisibleState(false)
3994 , __clipToParent(true)
3995 , __multiTouchEnabled(false)
3996 , __dragEnabled(false)
3997 , __dropEnabled(false)
3998 , __drawWhenVisible(true)
3999 , __isPostOrderTraversal(false)
4000 , __isCalledCallOnAttachingToMainTree(false)
4001 , __isCalledCallOnPreAttachedToMainTree(false)
4002 , __isCalledCallOnAttachedToMainTree(false)
4003 , __isSetClientBounds(false)
4004 , __isCalledGetCanvasN(false)
4005 , __isFocusMode(false)
4006 , __isNavigatable(true)
4007 , __isFocusWindowActivationChecked(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)
4032 , __isSentDelayedEvent(false)
4033 , __isSendingDelayedEvent(false)
4034 , __isChangingEventTarget(false)
4035 , __pDataBindingContext(null)
4036 , __pControlDelegate(null)
4038 , __destroying(false)
4039 , __isEventEnableState(true)
4040 , __isEffectSoundEnabled(true)
4041 , __isControlFontChanged(false)
4044 , __fontFileName(L"")
4045 , __pPreviousFocus(null)
4046 , __pNextFocus(null)
4047 , __pDragWindow(null)
4048 , __isDragAndDropSource(false)
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.");
4055 result r = pNewBacktrace->Construct();
4056 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
4058 __pNewBacktrace = move(pNewBacktrace);
4060 DoBacktrace(__pNewBacktrace.get());
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.");
4065 r = pDeleteBacktrace->Construct();
4066 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
4068 __pDeleteBacktrace = move(pDeleteBacktrace);
4070 SetControlDelegate(*this);
4071 __pAccessibilityContainer = new (std::nothrow) _AccessibilityContainer(*this);
4072 __pAccessibilityContainer->Activate(true);
4074 __pLayoutItemHandler = new (std::nothrow) LayoutItemHandler(this);
4075 if (!__pLayoutItemHandler)
4080 __pLayoutContainer = CreateLayoutContainerN(__pLayoutItemHandler);
4081 if (!__pLayoutContainer)
4086 __pChildren = ::CreateControlListN();
4092 __pOwnees = ::CreateWindowListN();
4098 __pVisualElement = ::CreateVisualElementN();
4099 if (!__pVisualElement)
4104 __pVisualElement->SetUserData(this);
4105 __pVisualElement->SetClipChildrenEnabled(true);
4106 __pVisualElement->SetRedrawOnResizeEnabled(true);
4108 __pVisualElementContentProvider = new (std::nothrow) ControlVisualElementContentProvider(*this);
4109 SysTryCatch(NID_UI, __pVisualElementContentProvider, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4111 GetVisualElement()->SetContentProvider(__pVisualElementContentProvider);
4113 __pVisualElementEventListener = new (std::nothrow) ControlVisualElementEventListener(*this);
4114 SysTryCatch(NID_UI, __pVisualElementEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4116 GetVisualElement()->SetVisualElementEventListener(__pVisualElementEventListener);
4118 __pDetectStartedGestureMap = ::CreateGestureMapN();
4119 if (!__pDetectStartedGestureMap)
4124 __pCoreGestureDetectors = new (std::nothrow) LinkedListT<_TouchGestureDetector*>;
4125 if (!__pCoreGestureDetectors)
4130 __pDelayedTouchInfoList = new (std::nothrow) LinkedListT<_TouchInfo*>;
4131 if (!__pDelayedTouchInfoList)
4136 SetEventPreviewer<_UI_EVENT_TOUCH>(this);
4137 SetEventPreviewer<_UI_EVENT_KEY>(this);
4138 SetEventPreviewer<_UI_EVENT_NOTIFICAITON>(this);
4140 SetEventListener<_UI_EVENT_NOTIFICAITON>(this);
4141 SetEventListener<_UI_EVENT_FOCUS>(this);
4143 SetPropagatedTouchEventListener(this);
4144 SetPropagatedKeyEventListener(this);
4145 GET_COLOR_CONFIG(BASIC::background, __backgroundColor);
4147 if (IsFailed(GetLastResult()))
4149 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
4152 __screenDpi = _ControlManager::GetInstance()->GetScreenDpi();
4162 _Control::AcquireHandle(void)
4164 __controlHandle = _ControlManager::GetInstance()->Register(this); // [ToDo] exception?
4168 _Control::ReleaseHandle(void)
4170 _ControlManager::GetInstance()->Release(__controlHandle); // [ToDo] exception?
4174 _Control::SetDrawWhenVisible(bool draw)
4176 __drawWhenVisible = draw;
4180 _Control::IsDrawWhenVisible(void)
4182 return __drawWhenVisible;
4186 _Control::SetTerminatingOrder(bool postOrderTraversal)
4188 __isPostOrderTraversal = postOrderTraversal;
4192 _Control::IsPostOrderTraversal(void)
4194 return __isPostOrderTraversal;
4198 _Control::SetParent(_Control* pParent)
4201 __pParent = pParent;
4205 // Only called by _Window::SetOwner(pOwner)
4207 _Control::AttachOwnee(_Window& window)
4210 result r = E_SUCCESS;
4212 _Control* pOldOwner = window.GetOwner();
4215 pOldOwner->DetachOwnee(window);
4218 r = __pOwnees->Add(&window);
4221 SysLogException(NID_UI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4222 return E_OUT_OF_MEMORY;
4229 _Control::GetOwneeCount(void) const
4232 return __pOwnees->GetCount();
4237 _Control::GetOwnee(int index) const
4240 result r = E_SUCCESS;
4242 _Window* pOwnee = null;
4243 r = __pOwnees->GetAt(index, pOwnee);
4246 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4253 // Called by _Window::SetOwner(null)
4255 _Control::DetachOwnee(_Window& ownee)
4258 result r = E_SUCCESS;
4260 _Control* pOwner = ownee.GetOwner();
4266 r = __pOwnees->Remove(&ownee);
4269 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4274 _Control::DetachAllOwnees(void)
4278 int owneeCount = GetOwneeCount();
4279 while (owneeCount--)
4281 _Window* pOwnee = GetOwnee(0);
4287 pOwnee->SetOwner(null);
4291 _Layout::LayoutContainer&
4292 _Control::GetLayoutContainer() const
4294 return *__pLayoutContainer;
4298 _Control::SetMultiTouchEnabled(bool enabled)
4301 __multiTouchEnabled = enabled;
4305 _Control::IsMultiTouchEnabled(void) const
4308 return __multiTouchEnabled;
4312 _Control::SetMovable(bool movable)
4315 __movable = movable;
4319 _Control::SetResizable(bool resizable)
4325 __minSize = __maxSize = GetSizeF();
4328 if (!__resizable && resizable)
4330 __minSize = FloatDimension(0.0f, 0.0f);
4331 __maxSize = FloatDimension(MAX_LENGTH, MAX_LENGTH);
4334 __resizable = resizable;
4338 _Control::GetLayout(void) const
4341 _Layout::Layout* pLayout = __pLayoutContainer->GetLayout();
4343 SysAssert(GetLastResult() == E_SUCCESS);
4348 _Control::SetCurrentLayout(_Layout::Layout& layout)
4351 return __pLayoutContainer->SetCurrentLayout(layout);
4355 _Control::AddLayout(_Layout::Layout& layout)
4358 return __pLayoutContainer->AddLayout(layout);
4362 _Control::SetUpdateLayoutState(bool state)
4364 _Layout::Layout* pLayout = GetLayout();
4367 pLayout->SetUpdateState(state);
4372 _Control::SetEffectSoundEnabled(bool enable)
4374 __isEffectSoundEnabled = enable;
4378 _Control::IsEffectSoundEnabled(void) const
4380 return __isEffectSoundEnabled;
4383 _DataBindingContext*
4384 _Control::GetDataBindingContext(void)
4386 return __pDataBindingContext;
4388 _AccessibilityContainer*
4389 _Control::GetAccessibilityContainer(void)
4391 return __pAccessibilityContainer;
4394 _Control::SetDataBindingContext(_DataBindingContext* pDataBindingContext)
4396 __pDataBindingContext = pDataBindingContext;
4400 _Control::DoBacktrace(Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList)
4402 SysTryReturnVoidResult(NID_SHELL, pBacktraceList, E_INVALID_ARG, "[E_INVALID_ARG].");
4404 const static int ADDR_SIZE = 100;
4406 void* pBuffer[ADDR_SIZE];
4408 retSize = backtrace(pBuffer, ADDR_SIZE);
4409 SysSecureLog(NID_SHELL, " %d addresses", retSize);
4411 for (int i = 0; i < retSize; i++)
4415 pBacktraceList->Add(pBuffer[i]);
4421 _Control::GetDescription(void) const
4427 _Control::SetTouchCapture(bool allowOutOfBounds, bool allowOwnerBounds)
4429 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4430 SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4432 pTouchManager->SetCapturedControl(this, allowOutOfBounds, allowOwnerBounds);
4436 _Control::ReleaseTouchCapture(void)
4438 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4439 SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4441 pTouchManager->SetCapturedControl(null, false, false);
4445 _Control::GetTopmostChildAt(const Point& point) const
4447 _Control* pTouchedControl = null;
4448 FloatPoint ptf((float) point.x, (float) point.y);
4449 _ControlManager* pControlManager = _ControlManager::GetInstance();
4450 SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
4452 _Window* pRootWindow = GetRootWindow();
4453 SysTryReturn(NID_UI, pRootWindow, null, E_SYSTEM, "[E_SYSTEM] GetRootWindow() is null, this control is detached from the main trree");
4455 _ControlVisualElement* pRootControlElement = dynamic_cast <_ControlVisualElement*>(pRootWindow->GetVisualElement());
4456 SysTryReturn(NID_UI, pRootControlElement, null, E_SYSTEM, "[E_SYSTEM] pRootControlElement is null.");
4458 _ControlVisualElement* pHitTestElm = pRootControlElement->GetControlChildAtPoint(ptf);
4459 if (pHitTestElm == null)
4461 SysSecureLog(NID_UI, "pHitTestElm is null, point(%f, %f)", ptf.x, ptf.y);
4465 pTouchedControl = static_cast <_Control*>(pHitTestElm->GetUserData());
4467 return pTouchedControl;
4471 _Control::SetContentAreaBounds(const Rectangle& rect)
4475 __contentAreaBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
4479 _Control::SetContentAreaBounds(const FloatRectangle& rect)
4483 __contentAreaBounds = rect;
4487 _Control::GetContentAreaBounds(void) const
4489 return _CoordinateSystemUtils::ConvertToInteger(__contentAreaBounds);
4493 _Control::GetContentAreaBoundsF(void) const
4495 return __contentAreaBounds;
4499 _Control::GetCapturedBitmapN(bool includeChildren) const
4501 result r = E_SUCCESS;
4503 Canvas* pCanvas = null;
4504 Bitmap* pBitmap = null;
4506 pBitmap = GetControlDelegate().OnCapturedBitmapRequestedN();
4507 if (pBitmap == null)
4509 FloatRectangle rect;
4511 Rectangle boundsInCanvas = GetBounds();
4512 boundsInCanvas.x = boundsInCanvas.y = 0;
4514 pCanvas = new (std::nothrow) Canvas;
4515 SysTryReturn(NID_UI, pCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4517 r = pCanvas->Construct(boundsInCanvas);
4518 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4520 GetVisualElement()->Draw();
4523 rect.SetBounds(boundsInCanvas.x, boundsInCanvas.y, boundsInCanvas.width, boundsInCanvas.height);
4525 r = GetVisualElement()->Capture(*pCanvas, rect, includeChildren);
4526 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4528 pBitmap = new (std::nothrow) Bitmap;
4529 SysTryCatch(NID_UI, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4531 r = pBitmap->Construct(*pCanvas, boundsInCanvas);
4534 SysTryCatch(NID_UI, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4537 SysLog(NID_UI, "Bitmap (width:%d, height:%d)", pBitmap->GetWidth(), pBitmap->GetHeight());
4541 _BitmapImpl::ConvertToNonpremultiplied(*pBitmap, true);
4553 Tizen::Graphics::Rectangle
4554 _Control::GetInvalidatedBounds(void) const
4556 return _CoordinateSystemUtils::ConvertToInteger(__invalidatedBounds);
4559 Tizen::Graphics::FloatRectangle
4560 _Control::GetInvalidatedBoundsF(void) const
4562 return __invalidatedBounds;
4566 _Control::AddGestureDetector(const _TouchGestureDetector& gestureDetector)
4570 bool exist = __pCoreGestureDetectors->Contains(const_cast<_TouchGestureDetector*>(&gestureDetector));
4571 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "__pCoreGestureDetectors has gesture already");
4573 result r = __pCoreGestureDetectors->Add(const_cast<_TouchGestureDetector*>(&gestureDetector));
4574 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4576 r = const_cast<_TouchGestureDetector&>(gestureDetector).SetControl(*this);
4577 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "Control handle is not valid.");
4579 const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorAdded();
4585 _Control::RemoveGestureDetector(const _TouchGestureDetector& gestureDetector)
4589 result r = __pCoreGestureDetectors->Remove(&(const_cast<_TouchGestureDetector&>(gestureDetector)));
4595 const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorRemoved();
4600 IListT <_TouchGestureDetector*>*
4601 _Control::GetGestureDetectorList(void) const
4603 return __pCoreGestureDetectors;
4606 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>*
4607 _Control::GetStartedGestureDetectorEnumeratorN(void) const
4609 return __pDetectStartedGestureMap->GetMapEnumeratorN();
4612 IListT <_TouchGestureDetector*>*
4613 _Control::GetStartedGestureDetectorListN(void) const
4615 return __pDetectStartedGestureMap->GetKeysN();
4619 _Control::AddStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4623 result r = E_SUCCESS;
4626 __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4630 r = __pDetectStartedGestureMap->Add(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4637 _Control::SetStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4641 result r = E_SUCCESS;
4644 __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4648 r = __pDetectStartedGestureMap->SetValue(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4655 _Control::ClearStartedGestureDetectorList(void)
4659 result r = E_SUCCESS;
4661 IListT<_TouchGestureDetector*>* pList = __pDetectStartedGestureMap->GetKeysN();
4664 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pList->GetEnumeratorN();
4667 while(pEnumerator->MoveNext() == E_SUCCESS)
4669 _TouchGestureDetector* pGestureDetector = null;
4670 pEnumerator->GetCurrent(pGestureDetector);
4672 if (pGestureDetector == null)
4677 __pDetectStartedGestureMap->Remove(pGestureDetector);
4684 IEnumeratorT<_TouchInfo*>* pEnumerator = __pDelayedTouchInfoList->GetEnumeratorN();
4687 while(pEnumerator->MoveNext() == E_SUCCESS)
4689 _TouchInfo* pTouchInfo = null;
4690 pEnumerator->GetCurrent(pTouchInfo);
4691 if (pTouchInfo == null)
4699 __pDelayedTouchInfoList->RemoveAll();
4703 __isSentDelayedEvent = false;
4704 __isSendingDelayedEvent = false;
4710 _Control::IsDelayedTouchEventEnabled(void) const
4712 bool existDelayTouchEventGesture = false;
4714 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4717 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4719 _TouchGestureDetector* pGestureDetector = null;
4720 pMapEnumerator->GetKey(pGestureDetector);
4722 if (pGestureDetector == null)
4727 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4728 pMapEnumerator->GetValue(state);
4730 if (pGestureDetector->IsDelayTouchEventEnabled())
4732 existDelayTouchEventGesture = true;
4735 delete pMapEnumerator;
4738 bool delayTouchEvent = false;
4739 if (existDelayTouchEventGesture)
4741 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4744 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4746 _TouchGestureDetector* pGestureDetector = null;
4747 pMapEnumerator->GetKey(pGestureDetector);
4749 if (pGestureDetector == null)
4754 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4755 pMapEnumerator->GetValue(state);
4757 if (state == _TOUCH_GESTURE_DETECTOR_STATE_STARTED)
4759 delayTouchEvent = true;
4763 delete pMapEnumerator;
4766 return delayTouchEvent;
4775 _Control::IsPossibleToSendDelayedTouchEvent(void) const
4777 bool existDelayTouchEventGesture = false;
4779 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4782 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4784 _TouchGestureDetector* pGestureDetector = null;
4785 pMapEnumerator->GetKey(pGestureDetector);
4787 if (pGestureDetector == null)
4792 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4793 pMapEnumerator->GetValue(state);
4795 if (pGestureDetector->IsDelayTouchEventEnabled())
4797 existDelayTouchEventGesture = true;
4800 delete pMapEnumerator;
4803 bool allFailed = true;
4804 if (existDelayTouchEventGesture)
4806 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4809 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4811 _TouchGestureDetector* pGestureDetector = null;
4812 pMapEnumerator->GetKey(pGestureDetector);
4814 if (pGestureDetector == null)
4819 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4820 pMapEnumerator->GetValue(state);
4822 if (state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS)
4828 delete pMapEnumerator;
4840 _Control::IsCancelOnGestureSuccess(void) const
4842 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4843 SysAssert(pTouchManager != null);
4845 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4848 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4850 _TouchGestureDetector* pGestureDetector = null;
4851 pMapEnumerator->GetKey(pGestureDetector);
4853 if (pGestureDetector == null)
4858 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4859 pMapEnumerator->GetValue(state);
4861 if (pGestureDetector->IsCancelTouchEventOnSuccessEnabled() && state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS && !pTouchManager->IsTouchCanceledOnGestureSuccess())
4863 delete pMapEnumerator;
4867 delete pMapEnumerator;
4874 _Control::IsSentDelayedEvent(void) const
4876 return __isSentDelayedEvent;
4880 _Control::SetSentDelayedEvent(bool sent)
4882 __isSentDelayedEvent = sent;
4886 _Control::SetSendingDelayedEvent(bool sending)
4888 __isSendingDelayedEvent = sending;
4892 _Control::IsSendingDelayedEvent(void) const
4894 return __isSendingDelayedEvent;
4898 _Control::AddTouchInfo(const _TouchInfo& touchInfo)
4900 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4901 SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] _TouchManager does not exist.");
4903 _TouchInfo* pTouchInfo = new (std::nothrow) _TouchInfo;
4904 SysTryReturnVoidResult(NID_UI, pTouchInfo, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4906 FloatPoint screenPoint = pTouchManager->GetScreenPoint(touchInfo.GetPointId());
4907 pTouchInfo->SetTouchInfo(touchInfo.GetPointId(), touchInfo.GetTouchStatus(), screenPoint, false, 0);
4908 __pDelayedTouchInfoList->Add(pTouchInfo);
4911 IListT<_TouchInfo*>*
4912 _Control::GetTouchInfoList(void)
4914 return __pDelayedTouchInfoList;
4918 _Control::SetVisualElement(_ControlVisualElement* pVisualElement)
4920 __pVisualElement = pVisualElement;
4924 _Control::GetVisualElement(void) const
4926 return __pVisualElement;
4930 _Control::PrintDescription(bool printChildren, int level)
4932 int count = PrintDescription(printChildren, 0, level);
4934 SysSecureLog(NID_UI, "%d controls were printed.", count);
4938 _Control::PrintDescription(bool printChildren, int depth, int level)
4940 const int PRINT_CONTROL_VE = 1;
4941 const int PRINT_CONTROL_EVAS = 2;
4942 const int PRINT_CONTROL_VE_EVAS = 3;
4947 format.Format(LOG_LEN_MAX, L"%d", depth);
4949 for (int i = 0; i < depth; i++)
4951 indent.Append(L" ");
4954 indent.Append(format);
4956 String delimiter(L"-------------------------------------------------------------------------------------------");
4957 SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
4960 String publicDescription = GetControlDelegate().GetDescription();
4961 if (!publicDescription.IsEmpty())
4963 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), publicDescription.GetPointer());
4966 _ControlManager* pControlManager = _ControlManager::GetInstance();
4967 SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
4969 bool focused = false;
4970 _Control* pFocusedControl = pControlManager->GetFocusControl();
4971 if (pFocusedControl && (pFocusedControl == this))
4977 SysSecureLog(NID_UI, "%ls 0x%x(%d %ls) enable(%d) enableState(%d) visible(%d) visibleState(%d) clip(%d) movable(%d) resizable(%d)",
4978 indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer(), IsEnabled(), GetEnableState(), IsVisible(), GetVisibleState(),
4979 IsClipToParent(), IsMovable(), IsResizable());
4981 SysSecureLog(NID_UI, "%ls inputEnableState(%d) focusable(%d) focused(%d) prevFocus(0x%x) nextFocus(0x%x) font(0x%x) fontName(%ls) fontFileName(%ls)",
4982 indent.GetPointer(), GetInputEnableState(), IsFocusable(), focused, __pPreviousFocus, __pNextFocus, __pFont, __fontName.GetPointer(), __fontFileName.GetPointer());
4984 Rectangle bounds = GetBounds();
4985 Dimension min = GetMinimumSize();
4986 Dimension max = GetMaximumSize();
4987 Rectangle clientBounds = GetClientBounds();
4988 Rectangle absoluteBounds = GetAbsoluteBounds();
4990 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)",
4991 indent.GetPointer(), bounds.x, bounds.y, bounds.width, bounds.height,
4992 min.width, min.height, max.width, max.height,
4993 GetVerticalScrollPosition(), GetHorizontalScrollPosition(),
4994 clientBounds.x, clientBounds.y, clientBounds.width, clientBounds.height,
4995 absoluteBounds.x, absoluteBounds.y, absoluteBounds.width, absoluteBounds.height);
4997 SysSecureLog(NID_UI, "%ls bgColor(0x%x) layoutable(%d) orientation(%d) drag(%d) drop(%d) area(%d) layer(%d)",
4998 indent.GetPointer(), __backgroundColor.GetRGB32(), IsLayoutable(), GetOrientation(), IsDragEnabled(), IsDropEnabled(), GetArea(), GetLayer());
5000 Canvas* pCanvas = GetCanvasN();
5003 Rectangle canvasBounds = pCanvas->GetBounds();
5004 Color canvasBackgroundColor = pCanvas->GetBackgroundColor();
5005 Color canvasForegroundColor = pCanvas->GetForegroundColor();
5007 SysSecureLog(NID_UI, "%ls canvas.bounds(%d %d %d %d) canvas.bgColor(0x%x) canvas.fgColor(0x%x)",
5008 indent.GetPointer(), canvasBounds.x, canvasBounds.y, canvasBounds.width, canvasBounds.height, canvasBackgroundColor.GetRGB32(), canvasForegroundColor.GetRGB32());
5013 SysSecureLog(NID_UI, "%ls DataBindingContext(0x%x) ControlDelegate(0x%x) UserData(0x%x) destroying(%d)",
5014 indent.GetPointer(), __pDataBindingContext, __pControlDelegate, __pUserData, __destroying);
5019 for (int i = 0; i < GetOwneeCount(); ++i)
5022 _Window* pOwnee = GetOwnee(i);
5025 ownee.Format(LOG_LEN_MAX, L"0x%x ", pOwnee);
5026 ownees.Append(ownee);
5030 if (!ownees.IsEmpty())
5032 SysSecureLog(NID_UI, "%ls Ownees(%ls)", indent.GetPointer(), ownees.GetPointer());
5035 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
5037 SysSecureLog(NID_UI, "%ls _VisualElement(0x%x) _VisualElementImpl(0x%x) VisualElementContentProvider(0x%x) VisualElementEventListener(0x%x)",
5038 indent.GetPointer(), __pVisualElement, pVisualElementImpl, __pVisualElementContentProvider, __pVisualElementEventListener);
5041 SysSecureLog(NID_UI, "%ls LayoutItemHandler(0x%x) PortraitLayout(0x%x) LandscapeLayout(0x%x) LayoutContainer(0x%x)",
5042 indent.GetPointer(), __pLayoutItemHandler, __pPortraitLayout, __pLandscapeLayout, __pLayoutContainer);
5045 String description = GetDescription();
5046 if (!description.IsEmpty())
5048 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), description.GetPointer());
5051 // Print Gesture List
5052 IListT<_TouchGestureDetector*>* pGestureList = GetGestureDetectorList();
5053 SysTryReturn(NID_UI, pGestureList, 0, E_SYSTEM, "[E_SYSTEM] System error occurred.");
5055 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pGestureList->GetEnumeratorN();
5056 SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
5058 while (pEnumerator->MoveNext() == E_SUCCESS)
5060 _TouchGestureDetector* pGestureDetector = null;
5061 pEnumerator->GetCurrent(pGestureDetector);
5062 if (pGestureDetector)
5064 SysSecureLog(NID_UI, "%ls AddedGesture : %ls", indent.GetPointer(), pGestureDetector->GetDescription().GetPointer());
5070 // Print Started Gesture List
5071 unique_ptr<IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState> > pStartedGestureEnumerator(GetStartedGestureDetectorEnumeratorN());
5072 SysTryReturn(NID_UI, pStartedGestureEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
5074 while (pStartedGestureEnumerator->MoveNext() == E_SUCCESS)
5076 _TouchGestureDetector* pStartedGestureDetector = null;
5077 pStartedGestureEnumerator->GetKey(pStartedGestureDetector);
5078 if (pStartedGestureDetector)
5080 SysSecureLog(NID_UI, "%ls StartedGesture : %ls", indent.GetPointer(), pStartedGestureDetector->GetDescription().GetPointer());
5085 unique_ptr<IEnumeratorT<void*> > pNewEnumerator(__pNewBacktrace->GetEnumeratorN());
5086 SysTryReturn(NID_SHELL, pNewEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5088 String newBacktrace;
5090 while (pNewEnumerator->MoveNext() == E_SUCCESS)
5093 pNewEnumerator->GetCurrent(pAddr);
5096 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5097 newBacktrace.Append(addr);
5100 if (!newBacktrace.IsEmpty())
5102 SysSecureLog(NID_UI, "%ls new [%ls]", indent.GetPointer(), newBacktrace.GetPointer());
5106 unique_ptr<IEnumeratorT<void*> > pDeleteEnumerator(__pDeleteBacktrace->GetEnumeratorN());
5107 SysTryReturn(NID_SHELL, pDeleteEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5109 String deleteBacktrace;
5111 while (pDeleteEnumerator->MoveNext() == E_SUCCESS)
5114 pDeleteEnumerator->GetCurrent(pAddr);
5117 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5118 deleteBacktrace.Append(addr);
5121 if (!deleteBacktrace.IsEmpty())
5123 SysSecureLog(NID_UI, "%ls delete [%ls]", indent.GetPointer(), deleteBacktrace.GetPointer());
5126 // Print VE and Evas
5129 case PRINT_CONTROL_VE:
5130 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5133 case PRINT_CONTROL_EVAS:
5134 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5137 case PRINT_CONTROL_VE_EVAS:
5138 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5139 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5146 static int totalCount = 0;
5157 int count = GetChildCount();
5158 totalCount += count;
5160 for (int i = count - 1; i >= 0; --i)
5162 _Control* pChild = GetChild(i);
5165 pChild->PrintDescription(printChildren, depth, level);
5174 _Control::PrintBacktrace(bool printChildren, bool newBacktrace)
5176 int count = PrintBacktrace(printChildren, 0, newBacktrace);
5178 SysSecureLog(NID_UI, "%d controls were printed.", count);
5182 _Control::PrintBacktrace(bool printChildren, int depth, bool newBacktrace)
5187 format.Format(LOG_LEN_MAX, L"%d", depth);
5189 for (int i = 0; i < depth; i++)
5191 indent.Append(L" ");
5194 indent.Append(format);
5196 String delimiter(L"-------------------------------------------------------------------------------------------");
5197 SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
5199 SysSecureLog(NID_UI, "%ls 0x%x(%d %ls)", indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer());
5201 Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList = null;
5205 pBacktraceList = __pNewBacktrace.get();
5209 pBacktraceList = __pDeleteBacktrace.get();
5212 SysTryReturn(NID_UI, pBacktraceList, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5214 int backtraceCount = pBacktraceList->GetCount();
5215 SysTryReturn(NID_UI, backtraceCount > 0, 0, E_INVALID_ARG, "[E_INVALID_ARG].");
5217 void** pBacktrace = new (std::nothrow) void*[backtraceCount];
5218 SysTryReturn(NID_UI, pBacktrace, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5220 unique_ptr<IEnumeratorT<void*> > pEnumerator(pBacktraceList->GetEnumeratorN());
5221 SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5224 while (pEnumerator->MoveNext() == E_SUCCESS)
5227 pEnumerator->GetCurrent(pAddr);
5229 pBacktrace[i++] = pAddr;
5232 char** pSymbols = backtrace_symbols(pBacktrace, backtraceCount);
5233 SysTryReturn(NID_UI, pSymbols, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5235 for (int j = 0; j < backtraceCount; j++)
5237 SysSecureLog(NID_UI, "%ls [%s]", indent.GetPointer(), pSymbols[j]);
5241 delete [] pBacktrace;
5243 static int totalCount = 0;
5254 int count = GetChildCount();
5255 totalCount += count;
5257 for (int i = count - 1; i >= 0; --i)
5259 _Control* pChild = GetChild(i);
5262 pChild->PrintBacktrace(printChildren, depth, newBacktrace);
5271 _Control::DragAndDropBegin(const _DragAndDropItem& dragAndDropItem)
5273 _Window* pRootWindow = GetRootWindow();
5279 __isDragAndDropSource = true;
5281 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5287 pEcoreEvas->SetDragAndDropState(true);
5288 pEcoreEvas->DragAndDropBegin(*pRootWindow, dragAndDropItem.GetData());
5290 __pDragWindow = GetControlDelegate().OnDragAndDropBeginning();
5294 _Control::DragAndDropDrop(void)
5296 _Window* pRootWindow = GetRootWindow();
5302 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5303 pEcoreEvas->DragAndDropDrop(*pRootWindow);
5305 GetControlDelegate().OnDragAndDropDropping();
5308 Point dropPosition = pEcoreEvas->GetDropPosition();
5309 Rectangle bounds = GetRootWindow()->GetBounds();
5310 if (bounds.Contains(dropPosition))
5312 _Control* pDropControl = _ControlManager::GetInstance()->GetTopmostTouchedControl(dropPosition, true);
5315 // Send dnd events to Source.
5317 if (pDropControl->IsDragAndDropSource() == false)
5320 int pid = pEcoreEvas->GetProcessId(pRootWindow->GetNativeHandle());
5321 String dropData = pEcoreEvas->GetDropData();
5322 SysLog(NID_UI, "[DND][S:%d] Call OnDragAndDropDropped(%ls) => %ls.", pid, dropData.GetPointer(), pDropControl->GetName().GetPointer());
5323 _DragAndDropItem* pDragAndDropItem = _DragAndDropItem::CreateInstanceN(_DRAG_AND_DROP_TYPE_TEXT, dropData);
5324 pDropControl->GetControlDelegate().OnDragAndDropDropped(*pDragAndDropItem);
5325 delete pDragAndDropItem;
5330 __isDragAndDropSource = false;
5334 _Control::GetDragWindow(void) const
5336 return __pDragWindow;
5340 _Control::IsDragAndDropSource(void) const
5342 return __isDragAndDropSource;
5346 _Control::OnDragAndDropBeginning(void)
5352 _Control::OnDragAndDropDropping(void)
5357 _Control::OnDragAndDropEntered(void)
5362 _Control::OnDragAndDropMoved(const FloatPoint& position)
5367 _Control::OnDragAndDropLeft(void)
5372 _Control::OnDragAndDropDropped(const _DragAndDropItem& dragAndDropItem)
5376 _ITouchEventPreviewer*
5377 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>) const
5379 return __pTouchEventPreviewer;
5382 _IKeyEventPreviewer*
5383 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_KEY>) const
5385 return __pKeyEventPreviewer;
5388 _INotificationEventPreviewer*
5389 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5391 return __pNotificationEventPreviewer;
5395 _Control::GetEventListener(_IntToType<_UI_EVENT_KEY>) const
5397 return __pKeyEventListener;
5400 _IFocusEventListener*
5401 _Control::GetEventListener(_IntToType<_UI_EVENT_FOCUS>) const
5403 return __pFocusEventListener;
5406 _INotificationEventListener*
5407 _Control::GetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5409 return __pNotificationEventListener;
5413 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>, _ITouchEventPreviewer* pPreviewer)
5415 __pTouchEventPreviewer = pPreviewer;
5419 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_KEY>, _IKeyEventPreviewer* pPreviewer)
5421 __pKeyEventPreviewer = pPreviewer;
5425 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventPreviewer* pPreviewer)
5427 __pNotificationEventPreviewer = pPreviewer;
5431 _Control::SetEventListener(_IntToType<_UI_EVENT_FOCUS>, _IFocusEventListener* pListener)
5433 __pFocusEventListener = pListener;
5437 _Control::SetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventListener* pListener)
5439 __pNotificationEventListener = pListener;
5443 _Control::IsDragEnabled(void) const
5445 return __dragEnabled;
5449 _Control::IsDropEnabled(void) const
5451 return __dropEnabled;
5455 _Control::SetDragEnabled(bool enabled)
5457 __dragEnabled = enabled;
5461 _Control::SetDropEnabled(bool enabled)
5463 __dropEnabled = enabled;
5467 _Control::SetTouchPressThreshold(float distance)
5469 __touchMoveAllowance = static_cast<int>(distance * __screenDpi);
5470 __pressThresHold = distance;
5474 _Control::GetTouchPressThreshold(void) const
5476 return __pressThresHold;
5480 _Control::GetTouchPressThresholdPixel(void) const
5482 return __touchMoveAllowance;
5486 _Control::SetChangingEventTarget(bool isChangingEventTarget)
5488 __isChangingEventTarget = isChangingEventTarget;
5492 _Control::GetChangingEventTarget(void) const
5494 return __isChangingEventTarget;
5498 _Control::SetEventEnableState(bool enableState)
5500 __isEventEnableState = enableState;
5504 _Control::IsEventEnabled(void) const
5506 return __isEventEnableState;
5510 _Control::SetPreviousFocus(_Control* pPreviousFocus)
5512 __pPreviousFocus = pPreviousFocus;
5516 _Control::SetNextFocus(_Control* pNextFocus)
5518 __pNextFocus = pNextFocus;
5521 _Control::GetPreviousFocus(void) const
5523 return __pPreviousFocus;
5526 _Control::GetNextFocus(void) const
5528 return __pNextFocus;
5532 _Control::OnDrawFocus(void)
5534 if (__pFocusVisualElement.get() == null)
5536 unique_ptr<VisualElement, _VisualElementDeleter> pFocusVisualElement (new (std::nothrow) VisualElement, _VisualElementDeleter());
5537 SysTryReturn(NID_UI, pFocusVisualElement, , E_SYSTEM, "[E_SYSTEM] System error");
5539 result r = pFocusVisualElement->Construct();
5540 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
5542 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*pFocusVisualElement);
5543 SysTryReturn(NID_UI, pImpl, , E_SYSTEM, "[E_SYSTEM] pImpl System error");
5544 pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(_CONTROL_LAYER_SYSTEM));
5546 __pFocusVisualElement.reset(pFocusVisualElement.release());
5547 __pFocusVisualElement->SetImplicitAnimationEnabled(false);
5549 _VisualElement* pControVisualElement = this->GetVisualElement();
5550 pControVisualElement->AttachChild(*__pFocusVisualElement);
5553 if (__pFocusVisualElement)
5555 Rectangle rectangle = GetBounds();
5556 __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, rectangle.width, rectangle.height));
5557 unique_ptr<Canvas>pCanvas(__pFocusVisualElement->GetCanvasN());
5560 pCanvas->SetBackgroundColor(0x55555555);
5563 Color contentHighlightedColor;
5564 GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
5565 Bitmap* pBitmap = null;
5566 Bitmap* pTempBitmap = null;
5567 result r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
5568 pBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
5572 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
5576 r = pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5583 r = pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5590 __pFocusVisualElement->SetShowState(true);
5594 _Control::OnChildControlFocusMoved(const _Control& control)
5599 _Control::OnDescendantControlFocusMoved(const _Control& control)
5604 _Control::IsChildControlFocusManage(void) const
5610 _Control::SetFontFromFile(const String& fileName)
5612 result r = E_SUCCESS;
5614 if (__fontFileName.Equals(fileName))
5619 __isControlFontChanged = true;
5620 __fontFileName = fileName;
5623 Font* pFont = GetFallbackFont();
5627 r = GetLastResult();
5628 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5634 _Control::GetFontFile(void) const
5636 return __fontFileName;
5639 _Control::DrawFocus(void)
5641 _IControlDelegate& delegate = GetControlDelegate();
5642 delegate.OnDrawFocus();
5646 _Control::MakeFocusList(const _Control* pControl, IListT<_Control*>* pFocusControlList) const
5648 int childCount = pControl->GetChildCount();
5649 for(int i = 0; i < childCount; i++)
5651 _Control* pChildControl = pControl->GetChild(i);
5652 Rectangle rect = pChildControl->GetAbsoluteBounds();
5653 unique_ptr<IEnumeratorT<_Control*> > pEnum (pFocusControlList->GetEnumeratorN());
5655 while (pEnum->MoveNext() == E_SUCCESS)
5657 _Control* pEnumeratorControl = null;
5658 pEnum->GetCurrent(pEnumeratorControl);
5659 if (pEnumeratorControl != null)
5661 Rectangle enumeratorRect = pEnumeratorControl->GetAbsoluteBounds();
5662 if(enumeratorRect.y > rect.y)
5666 else if (enumeratorRect.y == rect.y)
5668 if(enumeratorRect.x > rect.x)
5677 pFocusControlList->InsertAt(pChildControl, index);
5682 _Control::MakeChildContainerFocusList(const _Control* pControl, int startIndex , IListT<_Control*>* pFocusControlList) const
5684 unique_ptr<IListT<_Control*> > pTempList (new (std::nothrow) ArrayListT<_Control*>);
5685 SysTryReturnVoidResult(NID_UI_CTRL, pTempList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
5686 MakeFocusList(pControl, pTempList.get());
5688 unique_ptr<IEnumeratorT<_Control*> > pTempEnum(pTempList->GetEnumeratorN());
5689 int index = ++startIndex;
5690 while (pTempEnum->MoveNext() == E_SUCCESS)
5692 _Control* pEnumeratorControl = null;
5693 pTempEnum->GetCurrent(pEnumeratorControl);
5694 pFocusControlList->InsertAt(pEnumeratorControl, index);
5699 Tizen::Base::Collection::IListT<_Control*>*
5700 _Control::GetFocusListN(void) const
5702 unique_ptr<IListT<_Control*> > pControlFocusList (new (std::nothrow) ArrayListT<_Control*>);
5703 SysTryReturn(NID_UI_CTRL, pControlFocusList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5704 MakeFocusList(this, pControlFocusList.get());
5706 unique_ptr<IEnumeratorT<_Control*> > pEnum(pControlFocusList->GetEnumeratorN());
5707 SysTryReturn(NID_UI_CTRL, pEnum, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5709 int nextContainerIndex = -1;
5710 while (pEnum->MoveNext() == E_SUCCESS)
5712 _Control* pEnumeratorControl = null;
5713 pEnum->GetCurrent(pEnumeratorControl);
5715 if (nextContainerIndex < i)
5717 if (pEnumeratorControl->IsChildControlFocusManage() == false)
5719 MakeChildContainerFocusList(pEnumeratorControl, i, pControlFocusList.get());
5720 nextContainerIndex = i;
5721 pEnum.reset(pControlFocusList->GetEnumeratorN());
5727 return pControlFocusList.release();
5731 _Control::IsChildAttachable(_Control& child) const
5733 if (dynamic_cast <_Window*>(&child) != null)