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>
36 #include "FUi_Control.h"
37 #include "FUi_ControlManager.h"
38 #include "FUi_FocusManagerImpl.h"
39 #include "FUi_CoordinateSystemUtils.h"
40 #include "FUi_Window.h"
41 #include "FUi_EcoreEvasMgr.h"
42 #include "FUi_EcoreEvas.h"
43 #include "FUi_LayoutLayoutContainer.h"
44 #include "FUi_LayoutAbsoluteLayout.h"
45 #include "FUi_LayoutILayoutItemHandler.h"
46 #include "FUi_TouchManager.h"
47 #include "FUi_DataBindingContext.h"
48 #include "FUi_TouchLongPressGestureDetector.h"
49 #include "FUi_TouchTapGestureDetector.h"
50 #include "FUi_AccessibilityContainer.h"
51 #include "FUi_ResourceManager.h"
52 #include "FUiAnim_ControlVisualElement.h"
53 #include "FUiAnim_Debug.h"
54 #include "FUiAnim_VisualElement.h"
55 #include "FUiAnim_VisualElementImpl.h"
56 #include "FUiCtrl_Form.h"
57 #include "FUiCtrl_Frame.h"
58 #include "FUi_ContainerImpl.h"
59 #include "FUi_DragAndDropItem.h"
60 #include "FUi_UiEventManager.h"
63 using namespace Tizen::Base;
64 using namespace Tizen::Base::Collection;
65 using namespace Tizen::Base::Runtime;
66 using namespace Tizen::Graphics;
67 using namespace Tizen::Ui;
68 using namespace Tizen::Ui::Animations;
69 using namespace Tizen::Ui::Controls;
74 GetZOrderGroupOfVisualElement(_ControlLayer layer)
78 case _CONTROL_LAYER_OVERLAY:
79 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL - 1;
80 case _CONTROL_LAYER_CLIENT_BOTTOM:
81 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL;
82 case _CONTROL_LAYER_NONE:
84 case _CONTROL_LAYER_CLIENT_MIDDLE:
85 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
86 case _CONTROL_LAYER_CLIENT_TOP:
87 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 2;
88 case _CONTROL_LAYER_SYSTEM:
89 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 3;
92 return _ControlVisualElement::Z_ORDER_GROUP_CONTROL + 1;
97 AdjustSizeToRange(float& width, float& height, const FloatDimension& minDim, const FloatDimension& maxDim)
100 if (width < minDim.width)
102 width = minDim.width;
105 if (height < minDim.height)
107 height = minDim.height;
111 if (width > maxDim.width)
113 width = maxDim.width;
116 if (height > maxDim.height)
118 height = maxDim.height;
126 AdjustSizeToRange(FloatDimension& dim, const FloatDimension& minDim, const FloatDimension& maxDim)
128 return AdjustSizeToRange(dim.width, dim.height, minDim, maxDim);
133 _ControlVisualElement*
134 CreateVisualElementN(void)
138 _ControlVisualElement* pVisualElement = new (std::nothrow) _ControlVisualElement;
139 SysTryReturn(NID_UI, pVisualElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
142 pVisualElement->ConstructControlVisualElement() == E_SUCCESS, ,
143 E_SYSTEM, "[E_SYSTEM] System error occurred.");
145 pVisualElement->SetImplicitAnimationEnabled(false);
146 pVisualElement->SetShowState(true);
147 pVisualElement->SetBackBufferEnabled(true);
148 pVisualElement->SetRedrawOnResizeEnabled(true);
149 pVisualElement->SetSurfaceOpaque(false);
151 return pVisualElement;
154 //delete pVisualElement;
155 pVisualElement->Destroy();
159 _Control::GestureMap*
160 CreateGestureMapN(void)
164 _Control::GestureMap* pGestureMap = new (std::nothrow) _Control::GestureMap;
165 SysTryReturn(NID_UI, pGestureMap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
168 pGestureMap->Construct() == E_SUCCESS, ,
169 E_SYSTEM, "[E_SYSTEM] System error occurred.");
179 _Control::ControlList*
180 CreateControlListN(void)
184 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
185 SysTryReturn(NID_UI, pControlList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
191 _Control::WindowList*
192 CreateWindowListN(void)
196 _Control::WindowList* pWindowList = new (std::nothrow) _Control::WindowList;
197 SysTryReturn(NID_UI, pWindowList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
204 _Layout::LayoutContainer*
205 CreateLayoutContainerN(_Layout::ILayoutItemHandler* pLayoutItemHandler)
208 result r = E_SUCCESS;
210 _Layout::LayoutContainer* pLayoutContainer = null;
211 _Layout::AbsoluteLayout* pAbsLayout = null;
213 pLayoutContainer = new (std::nothrow) _Layout::LayoutContainer();
214 SysTryReturn(NID_UI, pLayoutContainer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage");
215 if (IsFailed(GetLastResult()))
220 pAbsLayout = new (std::nothrow) _Layout::AbsoluteLayout();
221 SysTryCatch(NID_UI, pAbsLayout, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
222 if (IsFailed(GetLastResult()))
227 pLayoutContainer->SetItemHandler(pLayoutItemHandler);
229 r = pLayoutContainer->SetDefaultLayout(*pAbsLayout);
230 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
232 return pLayoutContainer;
236 delete pLayoutContainer;
241 } // Anonymous namespace
243 namespace Tizen { namespace Ui
246 IMPLEMENT_PROPERTY(_Control);
248 class _Control::ControlVisualElementContentProvider
249 : public VisualElementContentProvider
256 ControlVisualElementContentProvider(_Control& control)
261 virtual ~ControlVisualElementContentProvider(void)
265 virtual bool PrepareDraw(VisualElement& target)
267 _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(&target);
273 Color bgColor = __control.GetBackgroundColor();
275 pCVE->SetBackgroundColor(
277 (float) bgColor.GetRed() / 255.0f,
278 (float) bgColor.GetGreen() / 255.0f,
279 (float) bgColor.GetBlue() / 255.0f,
280 (float) bgColor.GetAlpha() / 255.0f
284 __control.GetControlDelegate().OnDraw();
286 target.SetFlushNeeded();
291 virtual HitTestResult HitTest(VisualElement& target, const FloatPoint& point)
293 return __control.GetControlDelegate().HitTest(point);
297 ControlVisualElementContentProvider(const ControlVisualElementContentProvider& rhs);
298 ControlVisualElementContentProvider& operator =(const ControlVisualElementContentProvider& rhs);
301 class _Control::ControlVisualElementEventListener
302 : public IVisualElementEventListener
305 ControlVisualElementEventListener(_Control& control)
310 virtual ~ControlVisualElementEventListener(void)
315 virtual void OnChildAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
319 virtual void OnChildDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& child)
323 virtual void OnAttached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
327 virtual void OnDetached(Tizen::Ui::Animations::VisualElement& source, Tizen::Ui::Animations::VisualElement& parent)
331 virtual result OnTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
336 virtual void OnTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
340 virtual result OnChildrenTransformChanging(Tizen::Ui::Animations::VisualElement& source, FloatMatrix4& newTransform)
342 for (int i = 0; i < __control.GetChildCount(); ++i)
344 _Control* pChild = __control.GetChild(i);
350 if (pChild->GetArea() == _CONTROL_AREA_SYSTEM)
352 _VisualElement* pVisualElement = pChild->GetVisualElement();
355 FloatMatrix4 inverseMatrix(newTransform);
356 inverseMatrix.Invert();
358 result r = pVisualElement->SetTransformMatrix(inverseMatrix);
370 virtual void OnChildrenTransformChanged(Tizen::Ui::Animations::VisualElement& source, const FloatMatrix4& previousTransform)
374 virtual result OnBoundsChanging(Tizen::Ui::Animations::VisualElement& source, FloatRectangle& newBounds)
379 virtual void OnBoundsChanged(Tizen::Ui::Animations::VisualElement& source, const FloatRectangle& previousBounds)
383 virtual void OnShowStateChanged(Tizen::Ui::Animations::VisualElement& source, bool previousShowState)
388 ControlVisualElementEventListener(const ControlVisualElementEventListener& rhs);
389 ControlVisualElementEventListener& operator =(const ControlVisualElementEventListener& rhs);
393 }; // ControlVisualElementEventListener
395 // Layout Item Handler
396 class _Control::LayoutItemHandler
397 : public _Layout::ILayoutItemHandler
400 LayoutItemHandler(_Control* pControl)
401 : __pControl(pControl)
403 SysAssert(__pControl);
406 void SetItemVisibleState(bool visible)
408 __pControl->SetVisibleState(visible);
411 result SetItemBounds(const FloatRectangle& rect)
413 SysAssert(__pControl->IsInSizeRange(FloatDimension(rect.width, rect.height)));
414 return __pControl->SetBoundsFinal(rect, false, true);
417 FloatRectangle GetItemBounds(void) const
419 return __pControl->GetBoundsF();
422 FloatRectangle GetItemClientBoundsFromSize(const FloatDimension& size) const
424 FloatRectangle clientBounds(0.0f, 0.0f, 0.0f, 0.0f);
425 __pControl->UpdateClientBounds(size, clientBounds);
429 FloatDimension GetItemContentSize(bool horizontalMode, bool verticalMode) const
431 FloatRectangle rect = __pControl->GetContentAreaBoundsF();
432 if (rect == FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
434 return __pControl->GetControlDelegate().GetContentSizeF(horizontalMode, verticalMode);
438 return FloatDimension(rect.width, rect.height);
442 FloatDimension GetItemMinimumSize(void) const
444 return __pControl->GetMinimumSizeF();
447 FloatDimension GetItemMaximumSize(void) const
449 return __pControl->GetMaximumSizeF();
452 result OnItemMeasure(float& width, float& height)
454 Dimension evaluatedSize(_CoordinateSystemUtils::ConvertToInteger(width), _CoordinateSystemUtils::ConvertToInteger(height));
455 FloatDimension evaluatedSizeF(width, height);
457 bool changed = __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSizeF);
460 width = evaluatedSizeF.width;
461 height = evaluatedSizeF.height;
465 __pControl->GetControlDelegate().OnEvaluateSize(evaluatedSize);
467 if (evaluatedSize.width != (_CoordinateSystemUtils::ConvertToInteger(width)))
469 width = evaluatedSize.width;
471 if (evaluatedSize.height != (_CoordinateSystemUtils::ConvertToInteger(height)))
473 height = evaluatedSize.height;
481 LayoutItemHandler(const LayoutItemHandler& rhs);
482 LayoutItemHandler& operator =(const LayoutItemHandler& rhs);
485 _Control* __pControl;
486 }; // LayoutItemHandler
491 _Control::CreateControlN(void)
493 _Control* pControl = new (std::nothrow) _Control;
494 SysTryReturn(NID_UI, pControl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
495 if (IsFailed(GetLastResult()))
500 pControl->AcquireHandle();
502 SysAssert(GetLastResult() == E_SUCCESS);
511 _Control::ResetEventListeners(void)
513 __pFocusEventListener = this;
514 __pNotificationEventListener = this;
518 _Control::SetControlDelegate(_IControlDelegate& delegate)
520 __pControlDelegate = &delegate;
524 _Control::ResetControlDelegate(void)
526 __pControlDelegate = this;
530 _Control::GetControlDelegate(void) const
534 return const_cast<_Control&>(*this);
537 SysAssert(__pControlDelegate);
538 return *__pControlDelegate;
542 _Control::SetPropagatedTouchEventListener(_IPropagatedTouchEventListener* pListener)
544 __pPropagatedTouchEventListener = pListener;
547 _IPropagatedTouchEventListener*
548 _Control::GetPropagatedTouchEventListener(void) const
552 return const_cast<_Control*>(this);
555 SysAssert(__pPropagatedTouchEventListener);
556 return __pPropagatedTouchEventListener;
560 _Control::SetPropagatedKeyEventListener(_IPropagatedKeyEventListener* pListener)
562 __pPropagatedKeyEventListener = pListener;
565 _IPropagatedKeyEventListener*
566 _Control::GetPropagatedKeyEventListener(void) const
570 return const_cast<_Control*>(this);
573 SysAssert(__pPropagatedKeyEventListener);
574 return __pPropagatedKeyEventListener;
578 _Control::OnPreviewKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
584 _Control::OnPreviewKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
590 _Control::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
592 //SysLog(NID_UI, ">>> [core] OnKeyPressed(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
597 _Control::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
599 //SysLog(NID_UI, ">>> [core] OnKeyReleased(%d, %d)", keyInfo.GetKeyCode(), keyInfo.GetKeyModifier());
604 _Control::TranslateKeyEventInfo(const _Control& source, _KeyInfo& keyInfo)
609 _UiTouchEventDelivery
610 _Control::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
612 return _UI_TOUCH_EVENT_DELIVERY_YES;
615 _UiTouchEventDelivery
616 _Control::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
618 return _UI_TOUCH_EVENT_DELIVERY_YES;
621 _UiTouchEventDelivery
622 _Control::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
624 return _UI_TOUCH_EVENT_DELIVERY_YES;
627 _UiTouchEventDelivery
628 _Control::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
630 return _UI_TOUCH_EVENT_DELIVERY_YES;
633 _UiTouchEventDelivery
634 _Control::OnPreviewTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
636 return _UI_TOUCH_EVENT_DELIVERY_YES;
640 _Control::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
646 _Control::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
652 _Control::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
658 _Control::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
664 _Control::OnTouchWheeled(const _Control& source, const _TouchInfo& touchinfo)
670 _Control::OnFocusGained(const _Control& source)
672 bool isFocusMode = _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
673 bool isFocusalbeControl = _FocusManagerImpl::GetInstance()->IsFocusable(this);
674 if (isFocusMode && isFocusalbeControl)
682 _Control::OnFocusLost(const _Control& source)
684 if (__pFocusVisualElement)
686 __pFocusVisualElement->SetShowState(false);
692 _Control::OnPreviewNotifiedN(const _Control& source, IList* pArgs)
698 _Control::OnNotifiedN(const _Control& source, IList* pArgs)
704 _Control::IsMovable(void) const
711 _Control::IsResizable(void) const
718 _Control::GetContentSize(void) const
721 return Dimension(0, 0);
725 _Control::GetContentSizeF(bool horizontalMode, bool verticalMode) const
728 return FloatDimension(0.0f, 0.0f);
732 _Control::HitTest(const FloatPoint& point)
734 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
736 if (pVisualElementImpl)
738 if (pVisualElementImpl->HitTestI(point) == _VisualElementImpl::HITTEST_MATCH)
740 return HIT_TEST_MATCH;
744 return HIT_TEST_NOWHERE;
748 _Control::GetVerticalScrollPosition(void) const
754 _Control::GetHorizontalScrollPosition(void) const
760 _Control::GetOrientation(void) const
763 return __orientation;
767 _Control::OnDraw(void)
772 _Control::OnCanvasRequestedN(const FloatRectangle& bounds)
779 _Control::OnCapturedBitmapRequestedN(void)
786 _Control::OnAttaching(const _Control* pParent)
792 _Control::OnAttached(void)
798 _Control::OnAttachingToMainTree(const _Control* pParent)
804 _Control::OnPreAttachedToMainTree(void)
810 _Control::OnAttachedToMainTree(void)
816 _Control::OnDetachingFromMainTree(void)
822 _Control::OnAttachingFailed(const _Control& parent)
827 _Control::OnDetaching(void)
833 _Control::OnBoundsChanging(const Rectangle& bounds)
839 _Control::OnBoundsChanging(const FloatRectangle& bounds)
845 _Control::OnBoundsChanged(void)
851 _Control::OnEvaluateSize(Dimension& evaluatedSize)
857 _Control::OnEvaluateSize(FloatDimension& evaluatedSize)
863 _Control::OnParentBoundsChanged(const _Control& parent)
868 _Control::OnChildAttached(const _Control& child)
873 _Control::OnChildDetaching(const _Control& child)
878 _Control::OnChildDetached(const _Control& child)
883 _Control::OnChildBoundsChanged(const _Control& child)
888 _Control::OnChildVisibleStateChanged(const _Control& child)
893 _Control::OnChangeLayout(_ControlOrientation orientation)
898 _Control::OnChangeLayout(_ControlRotation rotation)
903 _Control::OnZOrderChanging(_ControlZOrderUpdate zOrderUpdate)
908 _Control::OnVisibleStateChanging(void)
913 _Control::OnVisibleStateChanged(void)
918 _Control::OnAncestorVisibleStateChanged(const _Control& control)
920 _TouchManager* pTouchManager = _TouchManager::GetInstance();
921 if (pTouchManager && IsVisible() == false && IsAttachedToMainTree() == true)
923 if(pTouchManager->GetTouchControlSource() == this)
925 SysLog(NID_UI, "VisibleState changed false, Call SetTouchCanceled");
926 pTouchManager->SetTouchCanceled(null);
928 _UiEventManager* pUiEventManager = _UiEventManager::GetInstance();
931 pUiEventManager->ClearEventQueue();
938 _Control::OnAncestorEnableStateChanged(const _Control& control)
943 _Control::OnAncestorInputEnableStateChanged(const _Control& control)
948 _Control::OnTouchPressHandled(const _Control& control)
953 _Control::OnTouchReleaseHandled(const _Control& control)
958 _Control::OnTouchMoveHandled(const _Control& control)
963 _Control::OnFontChanged(Tizen::Graphics::Font* pFont)
965 SetUpdateLayoutState(true);
969 _Control::OnFontInfoRequested(unsigned long& style, int& size)
974 _Control::OnFontInfoRequested(unsigned long& style, float& size)
979 _Control::OnBackgroundColorChanged(Color& backgroundColor)
984 _Control::OnFocusableStateChanged(bool focusalbeState)
989 _Control::OnFocusModeStateChanged(void)
994 _Control::OnTouchCancelHandled(const _Control& control)
999 _Control::Accept(Visitor& visitor)
1003 VisitType visitType = visitor.Visit(*this);
1010 case VISIT_DOWNWARD:
1011 for (int i = 0; i < GetChildCount(); ++i) // [Postpone] Keep handle list before iternation.
1013 _Control* pChild = GetChild(i);
1016 pChild->Accept(visitor);
1023 _Control* pParent = GetParent();
1026 pParent->Accept(visitor);
1037 _Control::Accept(Visitor& visitor) const
1039 const_cast <_Control*>(this)->Accept(visitor);
1043 _Control::InvalidateHierarchyRootWindow(_Control& control)
1045 control.__needRecalcRootWindow = true;
1046 control.__pRootWindow = null;
1048 for (int i = 0; i < control.GetChildCount(); ++i)
1050 _Control* pChild = control.GetChild(i);
1053 pChild->InvalidateHierarchyRootWindow(*pChild);
1059 _Control::InvalidateHierarchyAbsoluteBounds(_Control& control)
1061 control.__needRecalcAbsBounds = true;
1062 control.__needRecalcAbsBoundsF = true;
1064 for (int i = 0; i < control.GetChildCount(); ++i)
1066 _Control* pChild = control.GetChild(i);
1069 pChild->InvalidateHierarchyAbsoluteBounds(*pChild);
1075 _Control::Draw(bool recursive)
1079 Invalidate(recursive);
1080 GetVisualElement()->Draw();
1084 _Control::Show(void)
1086 GetVisualElement()->Flush();
1089 SysAssert(GetLastResult() == E_SUCCESS);
1093 _Control::ChangeLayout(_Control& control, _ControlOrientation orientation)
1095 if (control.__orientation != orientation)
1097 control.__orientation = orientation;
1098 control.GetControlDelegate().OnChangeLayout(orientation);
1101 for (int i = 0; i < control.GetChildCount(); ++i)
1103 _Control* pChild = control.GetChild(i);
1106 ChangeLayout(*pChild, orientation);
1112 _Control::ChangeLayout(_ControlOrientation orientation, bool callRotation)
1115 ChangeLayout(*this, orientation);
1117 if (callRotation == true)
1119 _ControlManager* pMgr = _ControlManager::GetInstance();
1122 _ControlRotation rotation = pMgr->GetOrientationStatus();
1123 ChangeLayout(rotation);
1129 _Control::ChangeLayout(_Control& control, _ControlRotation rotation)
1131 if (control.__rotation != rotation)
1133 control.__rotation = rotation;
1134 control.GetControlDelegate().OnChangeLayout(rotation);
1138 for (int i = 0; i < control.GetChildCount(); ++i)
1140 _Control* pChild = control.GetChild(i);
1143 ChangeLayout(*pChild, rotation);
1149 _Control::ChangeLayout(_ControlRotation rotation)
1152 ChangeLayout(*this, rotation);
1156 _Control::IsLayoutChangable(void) const
1162 _Control::IsOrientationRoot(void) const
1168 _Control::Invalidate(void)
1171 GetVisualElement()->InvalidateRectangle(null);
1175 _Control::Invalidate(bool recursive)
1180 _Layout::Layout* pLayout = GetLayout();
1183 pLayout->UpdateLayout();
1186 if (recursive == false)
1197 _Control::Invalidate(_Control& control)
1199 if (control.GetVisibleState() == false)
1204 control.Invalidate();
1207 int owneeCount = control.GetOwneeCount();
1208 for (int i = 0; i < owneeCount; ++i)
1210 _Window* pOwnee = control.GetOwnee(i);
1213 pOwnee->Invalidate(true);
1217 for (int i = 0; i < control.GetChildCount(); ++i)
1219 _Control* pChild = control.GetChild(i);
1222 pChild->Invalidate(*pChild);
1228 _Control::Invalidate(const Rectangle& rect)
1231 FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1232 GetVisualElement()->InvalidateRectangle(&rectf);
1234 __invalidatedBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
1238 _Control::Invalidate(const FloatRectangle& rect)
1241 FloatRectangle rectf(rect.x, rect.y, rect.width, rect.height);
1242 GetVisualElement()->InvalidateRectangle(&rectf);
1244 __invalidatedBounds = rect;
1248 _Control::Contains(const Point& point) const
1252 Rectangle bounds = GetBounds();
1253 bounds.x = bounds.y = 0;
1254 return bounds.Contains(point);
1258 _Control::Contains(const FloatPoint& point) const
1262 FloatRectangle bounds = GetBoundsF();
1263 bounds.x = bounds.y = 0;
1264 return bounds.Contains(point);
1269 _Control::PartialUpdateLayout(void)
1273 _Layout::Layout* pLayout = GetLayout();
1276 pLayout->PartialUpdateLayout();
1281 _Control::UpdateLayout(void)
1285 _Layout::Layout* pLayout = GetLayout();
1288 pLayout->UpdateLayout();
1293 _Control::SetChildAlwaysOnTop(_Control& child)
1297 SysTryReturn(NID_UI,
1298 child.GetParent() == this, E_INVALID_ARG,
1299 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1301 SysTryReturn(NID_UI,
1302 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1303 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1305 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_TOP)
1310 child.SetLayer(_CONTROL_LAYER_CLIENT_TOP);
1316 _Control::SetChildAlwaysAtBottom(_Control& child)
1320 SysTryReturn(NID_UI,
1321 child.GetParent() == this, E_INVALID_ARG,
1322 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1324 SysTryReturn(NID_UI,
1325 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1326 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1328 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_BOTTOM)
1333 child.SetLayer(_CONTROL_LAYER_CLIENT_BOTTOM);
1339 _Control::ResetChildLayer(_Control& child)
1343 SysTryReturn(NID_UI,
1344 child.GetParent() == this, E_INVALID_ARG,
1345 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
1347 SysTryReturn(NID_UI,
1348 child.GetArea() == _CONTROL_AREA_CLIENT, E_SYSTEM,
1349 E_SYSTEM, "[E_SYSTEM] The child is not in the client area.");
1351 if (child.GetLayer() == _CONTROL_LAYER_CLIENT_MIDDLE)
1356 child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1363 _Control::AttachSystemChild(_Control& child)
1366 result r = E_SUCCESS;
1368 r = StartAttaching(child, _CONTROL_AREA_SYSTEM);
1374 ControlList& children = GetChildList();
1375 r = children.Add(&child);
1376 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1378 r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1379 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1381 r = EndAttaching(child);
1382 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1384 SysAssert(GetLastResult() == E_SUCCESS);
1390 _Control::DetachSystemChild(_Control& child)
1392 return DetachChild(child);
1396 _Control::HasParent(void) const
1398 return __pParent != null;
1402 _Control::GetArea(void) const
1409 _Control::GetLayer(void) const
1416 _Control::SetLayer(_ControlLayer layer)
1419 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*GetVisualElement());
1421 result r = pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(layer));
1424 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1427 const _Control::ControlList&
1428 _Control::GetChildList() const
1430 return const_cast <_Control*>(this)->GetChildList();
1433 _Control::ControlList&
1434 _Control::GetChildList()
1436 return *__pChildren;
1440 _Control::IsCalledCallAttachingToMainTree(void)
1442 return __isCalledCallOnAttachingToMainTree;
1446 _Control::SetCalledCallAttachingToMainTree(bool isAttaching)
1448 __isCalledCallOnAttachingToMainTree = isAttaching;
1452 _Control::IsCalledCallPreAttachedToMainTree(void)
1454 return __isCalledCallOnPreAttachedToMainTree;
1458 _Control::IsCalledCallAttachedToMainTree(void)
1460 return __isCalledCallOnAttachedToMainTree;
1464 _Control::SetCalledCallPreAttachedToMainTree(bool isAttached)
1466 __isCalledCallOnPreAttachedToMainTree = isAttached;
1470 _Control::SetCalledCallAttachedToMainTree(bool isAttached)
1472 __isCalledCallOnAttachedToMainTree = isAttached;
1476 _Control::CallOnAttachingToMainTree(_Control& control)
1478 result r = E_SUCCESS;
1480 ControlList& children = control.GetChildList();
1481 _Control* pChild = null;
1483 int childrenCount = children.GetCount();
1485 for (int index = 0; index < childrenCount; index++)
1487 r = children.GetAt(index, pChild);
1490 SysAssert(r == E_OUT_OF_RANGE);
1491 SysTryReturn(NID_UI,
1492 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1493 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1495 if (!pChild->IsCalledCallAttachingToMainTree())
1497 r = CallOnAttachingToMainTree(*pChild);
1498 pChild->SetCalledCallAttachingToMainTree(true);
1499 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1503 if (!control.IsCalledCallAttachingToMainTree())
1505 r = control.GetControlDelegate().OnAttachingToMainTree(this);
1506 control.SetCalledCallAttachingToMainTree(true);
1507 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1514 _Control::CallOnPreAttachedToMainTree(_Control& control)
1516 result r = E_SUCCESS;
1518 ControlList& children = control.GetChildList();
1519 _Control* pChild = null;
1521 int childrenCount = children.GetCount();
1523 for (int index = 0; index < childrenCount; index++)
1525 r = children.GetAt(index, pChild);
1528 SysAssert(r == E_OUT_OF_RANGE);
1529 SysTryReturn(NID_UI,
1530 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1531 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1534 if (!pChild->IsCalledCallPreAttachedToMainTree())
1536 r = CallOnPreAttachedToMainTree(*pChild);
1537 pChild->SetCalledCallPreAttachedToMainTree(true);
1541 if (!control.IsCalledCallPreAttachedToMainTree())
1543 r = control.GetControlDelegate().OnPreAttachedToMainTree();
1544 control.SetCalledCallPreAttachedToMainTree(true);
1551 _Control::CallOnAttachedToMainTree(_Control& control)
1553 result r = E_SUCCESS;
1555 ControlList& children = control.GetChildList();
1556 _Control* pChild = null;
1558 int childrenCount = children.GetCount();
1560 for (int index = 0; index < childrenCount; index++)
1562 r = children.GetAt(index, pChild);
1565 SysAssert(r == E_OUT_OF_RANGE);
1566 SysTryReturn(NID_UI,
1567 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1568 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1571 if (!pChild->IsCalledCallAttachedToMainTree())
1573 r = CallOnAttachedToMainTree(*pChild);
1574 pChild->SetCalledCallAttachedToMainTree(true);
1578 if (!control.IsCalledCallAttachedToMainTree())
1580 r = control.GetControlDelegate().OnAttachedToMainTree();
1581 control.SetCalledCallAttachedToMainTree(true);
1588 _Control::CallOnDetachingFromMainTree(_Control& control)
1590 result r = E_SUCCESS;
1592 ControlList& children = control.GetChildList();
1593 _Control* pChild = null;
1595 _Window* pTop = control.GetRootWindow();
1598 _Control* pControl = pTop->GetFocusControl(this);
1599 if ((&control) == pControl)
1601 pTop->SetFocusControl(&control, false);
1603 _Control* pFocusTraversalControl = pTop->GetFocusTraversalControl(this);
1604 if ((&control) == pFocusTraversalControl)
1606 pTop->SetFocusTraversalControl(&control, false);
1610 if (!__isPostOrderTraversal)
1612 r = control.GetControlDelegate().OnDetachingFromMainTree();
1613 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1616 int childrenCount = children.GetCount();
1618 for (int index = 0; index < childrenCount; index++)
1620 r = children.GetAt(index, pChild);
1623 SysAssert(r == E_OUT_OF_RANGE);
1624 SysTryReturn(NID_UI,
1625 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
1626 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
1628 r = CallOnDetachingFromMainTree(*pChild);
1629 pChild->SetCalledCallAttachingToMainTree(false);
1630 pChild->SetCalledCallPreAttachedToMainTree(false);
1631 pChild->SetCalledCallAttachedToMainTree(false);
1632 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1635 if (__isPostOrderTraversal)
1637 r = control.GetControlDelegate().OnDetachingFromMainTree();
1638 control.SetCalledCallAttachingToMainTree(false);
1639 control.SetCalledCallPreAttachedToMainTree(false);
1640 control.SetCalledCallAttachedToMainTree(false);
1641 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1648 _Control::CallOnAncestorVisibleStateChanged(_Control& control)
1650 control.GetControlDelegate().OnAncestorVisibleStateChanged(*this);
1652 for (int i = 0; i < control.GetChildCount(); ++i)
1654 _Control* pChild = control.GetChild(i);
1657 CallOnAncestorVisibleStateChanged(*pChild);
1663 _Control::CallOnAncestorEnableStateChanged(_Control& control)
1665 control.GetControlDelegate().OnAncestorEnableStateChanged(*this);
1667 for (int i = 0; i < control.GetChildCount(); ++i)
1669 _Control* pChild = control.GetChild(i);
1672 CallOnAncestorEnableStateChanged(*pChild);
1678 _Control::CallOnAncestorInputEnableStateChanged(_Control& control)
1680 control.GetControlDelegate().OnAncestorInputEnableStateChanged(*this);
1682 for (int i = 0; i < control.GetChildCount(); ++i)
1684 _Control* pChild = control.GetChild(i);
1687 CallOnAncestorInputEnableStateChanged(*pChild);
1694 // [ToDo] Rollback is difficult.
1696 _Control::StartAttaching(_Control& child, _ControlArea area)
1698 result r = E_SUCCESS;
1700 _Control* pOldParent = child.GetParent();
1702 SysTryReturn(NID_UI,
1703 (pOldParent != this), E_INVALID_ARG,
1704 E_INVALID_ARG, "[E_INVALID_ARG] The child control is already attached to this container.");
1706 SysTryReturn(NID_UI,
1707 pOldParent == null, E_INVALID_ARG,
1708 E_INVALID_ARG, "[E_INVALID_ARG] Unable to add the child which already has another parent.");
1710 r = child.GetControlDelegate().OnAttaching(this);
1711 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1713 if (IsAttachedToMainTree())
1715 r = CallOnAttachingToMainTree(child);
1716 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1719 // [ToDo] Add control to layout
1720 // What should we do about non-layoutable controls?
1721 if (area == _CONTROL_AREA_CLIENT)
1723 _ControlManager* pMgr = _ControlManager::GetInstance();
1724 r = GetLastResult();
1725 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
1727 r = __pLayoutContainer->AddItem(child.GetLayoutContainer());
1730 child.GetControlDelegate().OnAttachingFailed(*this);
1731 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] Failed to apply layout.");
1736 if (IsAttachedToMainTree())
1738 if (!(IsOrientationRoot() && child.IsOrientationRoot()))
1740 child.ChangeLayout(_ControlManager::GetInstance()->GetOrientation());
1744 child.__area = area;
1746 if (area == _CONTROL_AREA_CLIENT)
1748 if (child.GetLayer() != _CONTROL_LAYER_CLIENT_TOP && child.GetLayer() != _CONTROL_LAYER_CLIENT_BOTTOM)
1750 child.SetLayer(_CONTROL_LAYER_CLIENT_MIDDLE);
1755 child.SetLayer(_CONTROL_LAYER_SYSTEM);
1758 SysAssert(GetLastResult() == E_SUCCESS);
1763 _Control::EndAttaching(_Control& child)
1765 child.SetParent(this);
1766 InvalidateHierarchyRootWindow(child);
1767 InvalidateHierarchyAbsoluteBounds(child);
1769 FloatRectangle floatBounds(child.GetBoundsF().x, child.GetBoundsF().y, child.GetBoundsF().width, child.GetBoundsF().height);
1771 result r = E_SUCCESS;
1772 if (child.IsLayoutChangable() == false)
1774 r = child.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, floatBounds.width, floatBounds.height));
1778 r = child.UpdateBoundsOfVisualElement(floatBounds);
1780 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1782 r = child.GetControlDelegate().OnAttached();
1783 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1785 if (IsAttachedToMainTree())
1787 r = CallOnPreAttachedToMainTree(child);
1788 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1790 r = CallOnAttachedToMainTree(child);
1791 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1796 GetControlDelegate().OnChildAttached(child);
1806 _Control::AttachChild(_Control& child)
1809 result r = E_SUCCESS;
1811 SysTryReturn(NID_UI,
1812 IsChildAttachable(child), E_INVALID_ARG,
1813 E_INVALID_ARG, "[E_INVALID_ARG] %ls cannot be a child of %ls.",
1814 child.GetName().GetPointer(), GetName().GetPointer());
1816 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1822 ControlList& children = GetChildList();
1823 r = children.Add(&child);
1824 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1826 r = GetVisualElement()->AttachChild(*child.GetVisualElement());
1828 r = EndAttaching(child);
1829 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1831 SysAssert(GetLastResult() == E_SUCCESS);
1837 _Control::UpdateFocusList(void)
1839 _Window* pTop = GetRootWindow();
1842 pTop->ResetFocusList();
1847 _Control::RemoveFocusRing(void)
1849 if (__pFocusVisualElement)
1851 __pFocusVisualElement->SetShowState(false);
1856 _Control::HasFocusRing(void)
1858 if (__pFocusVisualElement)
1867 _Control::SetFocusNavigateEnabled(bool enable)
1869 __isNavigatable = enable;
1873 _Control::IsFocusNavigateEnabled(void) const
1875 return __isNavigatable;
1879 _Control::IsFocusModeStateEnabled(void) const
1881 return _FocusManagerImpl::GetInstance()->IsFocusModeStateEnabled();
1888 _Control::InsertChildToBottom(_Control& child)
1891 result r = E_SUCCESS;
1893 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1899 ControlList& children = GetChildList();
1900 r = children.InsertAt(&child, 0);
1901 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1903 GetVisualElement()->InsertChild(*child.GetVisualElement(), null, false);
1904 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1906 r = EndAttaching(child);
1907 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1909 SysAssert(GetLastResult() == E_SUCCESS);
1917 _Control::InsertChildAfter(const _Control& targetChild, _Control& child)
1920 result r = E_SUCCESS;
1922 SysTryReturn(NID_UI,
1923 targetChild.GetParent() == this, E_INVALID_ARG,
1924 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
1926 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1932 int targetIndex = GetChildIndex(targetChild);
1933 SysAssert(targetIndex != -1);
1935 ControlList& children = GetChildList();
1936 r = children.InsertAt(&child, targetIndex + 1);
1937 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1939 GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), true);
1940 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1942 r = EndAttaching(child);
1943 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1945 SysAssert(GetLastResult() == E_SUCCESS);
1953 _Control::InsertChildBefore(const _Control& targetChild, _Control& child)
1956 result r = E_SUCCESS;
1958 SysTryReturn(NID_UI,
1959 targetChild.GetParent() == this, E_INVALID_ARG,
1960 E_INVALID_ARG, "[E_INVALID_ARG] The target is not my child.");
1962 r = StartAttaching(child, _CONTROL_AREA_CLIENT);
1968 int targetIndex = GetChildIndex(targetChild);
1969 SysAssert(targetIndex != -1);
1971 ControlList& children = GetChildList();
1972 r = children.InsertAt(&child, targetIndex);
1973 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1975 GetVisualElement()->InsertChild(*child.GetVisualElement(), targetChild.GetVisualElement(), false);
1976 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
1978 r = EndAttaching(child);
1979 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] propagated.", GetErrorMessage(r));
1981 SysAssert(GetLastResult() == E_SUCCESS);
1987 _Control::DetachChild(_Control& child)
1990 result r = E_SUCCESS;
1992 if (child.GetParent() != this)
1994 SetLastResult(E_INVALID_ARG);
1995 return E_INVALID_ARG;
1998 if (IsAttachedToMainTree())
2000 r = CallOnDetachingFromMainTree(child);
2001 SysTryReturn(NID_UI,
2002 r == E_SUCCESS, E_SYSTEM,
2003 E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2005 SysTryReturn(NID_UI,
2006 child.GetControlDelegate().OnDetaching() == E_SUCCESS, E_SYSTEM,
2007 E_SYSTEM, "[E_SYSTEM] The child cannot detached from parent.");
2010 GetControlDelegate().OnChildDetaching(child);
2013 r = GetVisualElement()->DetachChild(*child.GetVisualElement());
2014 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2016 ControlList& children = GetChildList();
2017 r = children.Remove(&child);
2018 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2020 // Remove control to layout
2021 if (child.__area == _CONTROL_AREA_CLIENT)
2023 _ControlManager* pMgr = _ControlManager::GetInstance();
2024 r = GetLastResult();
2025 SysTryReturn(NID_UI, pMgr, r, r, "[%s] Propagating.", GetErrorMessage(r));
2027 r = __pLayoutContainer->RemoveItem(child.GetLayoutContainer());
2028 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2031 child.SetParent(null);
2032 child.__area = _CONTROL_AREA_NONE;
2033 child.__layer = _CONTROL_LAYER_NONE;
2035 GetControlDelegate().OnChildDetached(child);
2038 SysAssert(GetLastResult() == E_SUCCESS);
2040 InvalidateHierarchyRootWindow(child);
2047 _Control::DetachAllChildren(bool detachSystemChild, bool recursive)
2050 result r = E_SUCCESS;
2052 int childCount = GetChildCount();
2057 while (childCount--)
2059 _Control* pChild = GetChild(itemIndex);
2065 if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2071 int childCount = pChild->GetChildCount();
2072 if (childCount == 0)
2074 r = DetachChild(*pChild);
2077 SysLog(NID_UI, "child is not detached from this container.");
2082 r = DetachChild(*pChild);
2085 SysLog(NID_UI, "child is not detached from this container.");
2087 pChild->DetachAllChildren(detachSystemChild, true);
2093 int notDetachedChildCount = 0;
2094 while (childCount--)
2096 _Control* pChild = GetChild(itemIndex);
2102 if (!detachSystemChild && (pChild->GetArea() == _CONTROL_AREA_SYSTEM))
2107 r = DetachChild(*pChild);
2111 ++notDetachedChildCount;
2115 if (notDetachedChildCount > 0)
2117 SysLog(NID_UI, "%d children are not detached from this container.", notDetachedChildCount);
2126 _Control::MoveChildToTop(const _Control& child)
2129 result r = E_SUCCESS;
2131 SysTryReturn(NID_UI,
2132 child.GetParent() == this, E_INVALID_ARG,
2133 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2135 // If already on top,
2136 ControlList& children = GetChildList();
2137 if (GetChildIndex(child) == children.GetCount() - 1)
2139 SysAssert(GetLastResult() == E_SUCCESS);
2143 _Control* pChild = const_cast <_Control*>(&child);
2145 r = children.Remove(pChild);
2146 SysAssert(r == E_SUCCESS);
2148 r = children.Add(pChild);
2149 SysAssert(r == E_SUCCESS);
2151 r = child.GetVisualElement()->SetZOrder(null, true);
2152 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2154 SysAssert(GetLastResult() == E_SUCCESS);
2160 _Control::MoveChildToBottom(const _Control& child)
2163 result r = E_SUCCESS;
2165 SysTryReturn(NID_UI,
2166 child.GetParent() == this, E_INVALID_ARG,
2167 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2169 ControlList& children = GetChildList();
2171 if (GetChildIndex(child) == 0)
2173 SysAssert(GetLastResult() == E_SUCCESS);
2177 _Control* pChild = const_cast <_Control*>(&child);
2179 r = children.Remove(pChild);
2180 SysAssert(r == E_SUCCESS);
2182 r = children.InsertAt(pChild, 0);
2183 SysAssert(r == E_SUCCESS);
2185 r = child.GetVisualElement()->SetZOrder(null, false);
2186 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2188 SysAssert(GetLastResult() == E_SUCCESS);
2194 _Control::MoveChildAfter(const _Control& targetChild, const _Control& child)
2197 result r = E_SUCCESS;
2199 SysTryReturn(NID_UI,
2200 targetChild.GetParent() == this, E_INVALID_ARG,
2201 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2203 SysTryReturn(NID_UI,
2204 child.GetParent() == this, E_INVALID_ARG,
2205 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2207 SysTryReturn(NID_UI,
2208 &targetChild != &child, E_INVALID_ARG,
2209 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move after self.");
2211 ControlList& children = GetChildList();
2213 int targetIndex = GetChildIndex(targetChild);
2214 SysAssert(targetIndex != -1);
2216 if (targetIndex + 1 == GetChildIndex(child))
2218 SysAssert(GetLastResult() == E_SUCCESS);
2222 _Control* pChild = const_cast <_Control*>(&child);
2224 r = children.Remove(pChild);
2225 SysAssert(r == E_SUCCESS);
2227 r = children.InsertAt(pChild, targetIndex + 1);
2228 SysAssert(r == E_SUCCESS);
2230 r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), true);
2231 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2233 SysAssert(GetLastResult() == E_SUCCESS);
2239 _Control::MoveChildBefore(const _Control& targetChild, const _Control& child)
2242 result r = E_SUCCESS;
2244 SysTryReturn(NID_UI,
2245 targetChild.GetParent() == this, E_INVALID_ARG,
2246 E_INVALID_ARG, "[E_INVALID_ARG] Target is not my child.");
2248 SysTryReturn(NID_UI,
2249 child.GetParent() == this, E_INVALID_ARG,
2250 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2252 SysTryReturn(NID_UI,
2253 &targetChild != &child, E_INVALID_ARG,
2254 E_INVALID_ARG, "[E_INVALID_ARG] Cannot move before self.");
2256 ControlList& children = GetChildList();
2258 int targetIndex = GetChildIndex(targetChild);
2259 SysAssert(targetIndex != -1);
2261 if (targetIndex - 1 == GetChildIndex(child))
2263 SysAssert(GetLastResult() == E_SUCCESS);
2267 _Control* pChild = const_cast <_Control*>(&child);
2269 r = children.Remove(pChild);
2270 SysAssert(r == E_SUCCESS);
2272 r = children.InsertAt(pChild, targetIndex);
2273 SysAssert(r == E_SUCCESS);
2275 r = child.GetVisualElement()->SetZOrder(targetChild.GetVisualElement(), false);
2276 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
2278 SysAssert(GetLastResult() == E_SUCCESS);
2285 _Control::GetChildIndex(const _Control& child) const
2288 result r = E_SUCCESS;
2290 SysTryReturn(NID_UI,
2291 child.GetParent() == this, -1,
2292 E_INVALID_ARG, "[E_INVALID_ARG] Not my child.");
2294 const ControlList& children = GetChildList();
2297 r = children.IndexOf(const_cast<_Control*>(&child), index);
2300 SysAssert(r == E_OBJ_NOT_FOUND);
2301 SysLogException(NID_UI, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Unable to find the specified child.");
2305 SysAssert(GetLastResult() == E_SUCCESS);
2311 _Control::GetChild(int index) const
2314 result r = E_SUCCESS;
2316 const ControlList& children = GetChildList();
2318 _Control* pChild = null;
2319 r = children.GetAt(index, pChild);
2322 SysAssert(r == E_OUT_OF_RANGE);
2323 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
2327 SysAssert(GetLastResult() == E_SUCCESS);
2332 _Control::GetChildCount(void) const
2335 return GetChildList().GetCount();
2339 _Control::GetHandle(void) const
2341 return __controlHandle;
2345 _Control::GetUserData(void) const
2351 _Control::SetUserData(void* pUserData)
2353 __pUserData = pUserData;
2357 _Control::GetPropertyName(void) const
2360 return Tizen::Ui::Variant(__name);
2364 _Control::GetName(void) const
2366 Variant name = GetProperty("Name");
2368 return name.ToString();
2372 _Control::SetPropertyName(const Variant& name)
2375 __name = name.ToString();
2381 _Control::SetName(const String& name)
2383 SetProperty("Name", Variant(name));
2387 _Control::GetParent(void) const
2393 _Control::GetCanvasN(void) const
2395 return GetCanvasN(FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
2399 _Control::GetCanvasN(const Rectangle& bounds) const
2402 Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
2403 if (pCanvas == null)
2405 GetVisualElement()->SetFlushNeeded();
2406 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2407 if (IsFailed(GetLastResult()))
2409 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2412 if (pCanvas && !__isCalledGetCanvasN)
2414 pCanvas->SetBackgroundColor(GetBackgroundColor());
2416 const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2423 _Control::GetCanvasN(const FloatRectangle& bounds) const
2426 Canvas *pCanvas = GetControlDelegate().OnCanvasRequestedN(FloatRectangle(bounds));
2427 if (pCanvas == null)
2429 GetVisualElement()->SetFlushNeeded();
2430 pCanvas = GetVisualElement()->GetCanvasN(bounds);
2431 if (IsFailed(GetLastResult()))
2433 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2436 if (pCanvas && !__isCalledGetCanvasN)
2438 pCanvas->SetBackgroundColor(GetBackgroundColor());
2440 const_cast <_Control*>(this)->__isCalledGetCanvasN = true;
2447 _Control::IsCalledGetCanvasN(void) const
2449 return __isCalledGetCanvasN;
2453 _Control::GetClientCanvasN(void) const
2455 return GetCanvasN(GetClientBounds());
2459 _Control::IsAncestorOf(const _Control& control) const
2462 return IsAncestorOf(control, *this);
2466 _Control::IsAncestorOf(const _Control& control, const _Control& ancestor) const
2468 const _Control* pParent = control.GetParent();
2471 if (pParent == &ancestor)
2475 return IsAncestorOf(*pParent, ancestor);
2482 _Control::GetRootWindow(void) const
2486 if (!__needRecalcRootWindow && __pRootWindow != this)
2488 return __pRootWindow;
2491 _Window* pRoot = null;
2492 _Control* pControl = const_cast<_Control*>(this);
2496 pRoot = dynamic_cast <_Window*>(pControl);
2501 pControl = pControl->GetParent();
2504 const_cast<_Control*>(this)->__pRootWindow = pRoot;
2505 const_cast<_Control*>(this)->__needRecalcRootWindow = false;
2511 _Control::IsAttachedToMainTree(void) const
2515 _ControlManager* pMgr = _ControlManager::GetInstance();
2521 _Window* pRootWindow = GetRootWindow();
2522 if (pRootWindow == null)
2527 return pRootWindow->IsAttached();
2531 _Control::IsFocusable(void) const
2538 _Control::SetFocusable(bool focusable)
2541 bool oldState = __focusable;
2542 __focusable = focusable;
2543 if (oldState != __focusable)
2545 GetControlDelegate().OnFocusableStateChanged(focusable);
2550 _Control::IsNativeObjectFocusable(void) const
2553 return __nativeObjectFocusable;
2557 _Control::SetNativeObjectFocusable(bool focusable)
2560 __nativeObjectFocusable = focusable;
2564 _Control::IsFocused(void) const
2568 _Window* pTop = GetRootWindow();
2574 if (this == pTop->GetFocusControl(const_cast<_Control*>(this)))
2583 _Control::SetFocusWindowActivationChecked(bool isChecked)
2585 __isFocusWindowActivationChecked = isChecked;
2589 _Control::IsFocusWindowActivationChecked(void)
2591 return __isFocusWindowActivationChecked;
2595 _Control::SetFocused(bool on)
2599 SysTryReturn(NID_UI,
2600 IsAttachedToMainTree(), E_INVALID_OPERATION,
2601 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2603 SysTryReturn(NID_UI,
2604 IsFocusable(), E_INVALID_OPERATION,
2605 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This Control isn't focusable control.");
2607 _Window* pTop = GetRootWindow();
2611 pTop->SetFocusControl(this, true);
2615 pTop->SetFocusControl(this, false);
2622 _Control::SetFont(const String& fontName)
2624 result r = E_SUCCESS;
2626 if (__fontName.Equals(fontName))
2631 __isControlFontChanged = true;
2632 __fontName = fontName;
2633 __fontFileName.Clear();
2635 Font* pFont = GetFallbackFont();
2639 r = GetLastResult();
2640 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2646 _Control::GetFallbackFont(void)
2648 unsigned long style = 0;
2650 float floatTextSize = 0.0f;
2651 result r = E_SUCCESS;
2652 _IControlDelegate& delegate = GetControlDelegate();
2653 delegate.OnFontInfoRequested(style, textSize);
2654 delegate.OnFontInfoRequested(style, floatTextSize);
2655 _ControlManager* pControlManager = _ControlManager::GetInstance();
2656 _FontImpl* pFontImpl = _FontImpl::GetInstance(*__pFont);
2657 if (!(__isControlFontChanged || pControlManager->IsDefaultFontChanged() || pControlManager->IsSystemFontChanged())
2659 && ((__pFont->GetSize() == textSize || __pFont->GetSizeF() == floatTextSize))
2660 && (pFontImpl->GetStyle() == static_cast<int>(style)))
2664 unique_ptr<Font>pTempFont(new(std::nothrow)Font());
2665 SysTryReturn(NID_UI , pTempFont , null , E_OUT_OF_MEMORY, "[%s] Fails to create a __pFont.", GetErrorMessage(r));
2667 if (!__fontName.IsEmpty())
2669 __isControlFontChanged = false;
2670 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2671 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2673 if (floatTextSize > 0.0f)
2675 r = pFontImpl->Construct(__fontName, style, floatTextSize, false);
2679 r = pFontImpl->Construct(__fontName, style, textSize, false);
2682 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2683 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2685 else if (!__fontFileName.IsEmpty())
2687 __isControlFontChanged = false;
2688 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2689 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2691 if (floatTextSize > 0.0f)
2693 r = pFontImpl->Construct(__fontFileName, style, floatTextSize);
2697 r = pFontImpl->Construct(__fontFileName, style, textSize);
2699 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2700 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2703 else if (!pControlManager->GetDefaultFont().IsEmpty())
2705 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2706 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2708 if (floatTextSize > 0.0f)
2710 r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, floatTextSize, false);
2714 r = pFontImpl->Construct(pControlManager->GetDefaultFont(), style, textSize, false);
2716 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2717 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2719 else if (!pControlManager->GetDefaultFontFile().IsEmpty())
2721 _FontImpl* pFontImpl = _FontImpl::GetInstance(*pTempFont);
2722 SysAssertf(pFontImpl != null, "Getting _FontImpl instance failed.");
2724 if (floatTextSize > 0.0f)
2726 r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, floatTextSize);
2730 r = pFontImpl->Construct(pControlManager->GetDefaultFontFile(), style, textSize);
2732 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2733 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2737 if (floatTextSize > 0.0f)
2739 r = pTempFont->Construct(style, floatTextSize);
2743 r = pTempFont->Construct(style, textSize);
2745 SysTryReturn(NID_UI, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "%s.", GetErrorMessage(r));
2746 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "%s.", GetErrorMessage(r));
2754 __pFont = pTempFont.release();
2755 delegate.OnFontChanged(__pFont);
2760 _Control::GetFont(void) const
2766 _Control::IsEnabled(void) const
2770 bool enabled = true;
2771 const _Control* pControl = this;
2775 if (!pControl->GetEnableState())
2780 pControl = pControl->GetParent();
2787 _Control::GetEnableState(void) const
2790 return __enabledState;
2794 _Control::SetEnableState(bool enabledState)
2797 const bool changed = (__enabledState != enabledState);
2800 __enabledState = enabledState;
2801 CallOnAncestorEnableStateChanged(*this);
2803 __pAccessibilityContainer->SetEnableState(enabledState);
2807 _Control::IsInputEventEnabled(void) const
2811 bool inputEnabled = true;
2812 const _Control* pControl = this;
2816 if (!pControl->GetInputEnableState())
2818 inputEnabled = false;
2821 pControl = pControl->GetParent();
2824 return inputEnabled;
2828 _Control::GetInputEnableState(void) const
2832 if (__inputLockRefCount != 0)
2843 _Control::LockInputEvent(void)
2845 __inputLockRefCount++;
2846 CallOnAncestorInputEnableStateChanged(*this);
2850 _Control::UnlockInputEvent(void)
2852 __inputLockRefCount--;
2853 if (__inputLockRefCount < 0)
2855 __inputLockRefCount = 0;
2860 _Control::IsVisible(void) const
2864 if (IsAttachedToMainTree() == false)
2866 SetLastResult(E_SYSTEM);
2870 bool visible = true;
2871 const _Control* pControl = this;
2875 if (!pControl->GetVisibleState())
2880 pControl = pControl->GetParent();
2887 _Control::GetVisibleState(void) const
2890 return __visibleState;
2894 _Control::SetVisibleState(bool visibleState)
2898 const bool changed = (__visibleState != visibleState) || !__initVisibleState;
2902 GetControlDelegate().OnVisibleStateChanging();
2905 __visibleState = visibleState;
2906 GetVisualElement()->SetShowState(visibleState);
2908 if (visibleState == false)
2910 int owneeCount = GetOwneeCount();
2911 for (int i = 0; i < owneeCount; ++i)
2913 _Window* pWindow = GetOwnee(i);
2916 pWindow->SetVisibleState(visibleState);
2923 GetControlDelegate().OnVisibleStateChanged();
2924 CallOnAncestorVisibleStateChanged(*this);
2925 _Control* pParent = GetParent();
2928 pParent->GetControlDelegate().OnChildVisibleStateChanged(*this);
2934 __initVisibleState = true;
2938 _Control::IsLayoutable(void) const
2945 _Control::IsClipToParent(void) const
2948 // SysAssert(GetVisualElement()->IsClipToParent() == __clipToParent);
2949 return __clipToParent;
2953 _Control::SetClipToParent(bool clipToParent)
2956 result r = E_SUCCESS;
2958 __clipToParent = clipToParent;
2959 r = GetVisualElement()->SetClipToParent(clipToParent);
2960 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2966 _Control::SetClipChildrenEnabled(bool clipChildren)
2969 //result r = E_SUCCESS;
2971 GetVisualElement()->SetClipChildrenEnabled(clipChildren);
2972 //SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2978 _Control::GetBounds(void) const
2981 return _CoordinateSystemUtils::ConvertToInteger(__bounds);
2985 _Control::GetBoundsF(void) const
2992 _Control::GetPosition(void) const
2995 return Point(_CoordinateSystemUtils::ConvertToInteger(__bounds.x), _CoordinateSystemUtils::ConvertToInteger(__bounds.y));
2999 _Control::GetPositionF(void) const
3002 return FloatPoint(__bounds.x, __bounds.y);
3006 _Control::GetSize(void) const
3009 return Dimension(_CoordinateSystemUtils::ConvertToInteger(__bounds.width), _CoordinateSystemUtils::ConvertToInteger(__bounds.height));
3013 _Control::GetSizeF(void) const
3016 return FloatDimension(__bounds.width, __bounds.height);
3021 _Control::UpdateBoundsOfVisualElement(const FloatRectangle& controlBounds)
3023 FloatRectangle rect(controlBounds.x, controlBounds.y, controlBounds.width, controlBounds.height);
3025 _Control* pParent = GetParent();
3026 if (__area == _CONTROL_AREA_CLIENT && pParent)
3028 const FloatRectangle clientBounds = pParent->GetClientBoundsF();
3029 rect.x += clientBounds.x;
3030 rect.y += clientBounds.y;
3033 GetVisualElement()->SetBounds(rect);
3039 _Control::AdjustAbsoluteBounds(_Control& control, bool update)
3041 result r = E_SUCCESS;
3045 FloatRectangle fbounds = control.GetBoundsF();
3047 if (control.IsLayoutChangable() == false)
3049 r = control.UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3053 r = control.UpdateBoundsOfVisualElement(fbounds);
3057 for (int i = 0; i < control.GetChildCount(); ++i)
3059 _Control* pChild = control.GetChild(i);
3065 r = AdjustAbsoluteBounds(*pChild, false);
3069 r = AdjustAbsoluteBounds(*pChild);
3073 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
3082 _Control::IsInSizeRange(const Dimension& size) const
3084 return (__minSize.width <= size.width) && (size.width <= __maxSize.width) &&
3085 (__minSize.height <= size.height) && (size.height <= __maxSize.height);
3089 _Control::IsInSizeRange(const FloatDimension& size) const
3091 return (_FloatCompareLE(__minSize.width, size.width)) && (_FloatCompareLE(size.width, __maxSize.width)) &&
3092 (_FloatCompareLE(__minSize.height, size.height)) && (_FloatCompareLE(size.height, __maxSize.height));
3095 // Custom Exception: ex) Location::Map
3097 _Control::SetBoundsFinal(const FloatRectangle& newBounds, bool changeLayoutBaseRect, bool callBoundsChangeCallbacks)
3099 result r = E_SUCCESS;
3101 FloatRectangle bounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
3103 _IControlDelegate& delegate = GetControlDelegate();
3105 const bool moved = (__bounds.x != bounds.x) || (__bounds.y != bounds.y);
3106 const bool resized = (__bounds.width != bounds.width) || (__bounds.height != bounds.height);
3108 if ((moved || resized) && callBoundsChangeCallbacks)
3110 r = delegate.OnBoundsChanging(_CoordinateSystemUtils::ConvertToInteger(bounds));
3113 SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3114 return r; // Relay the result;
3116 r = delegate.OnBoundsChanging(bounds);
3119 SysLogException(NID_UI, r, "[%s] Callback returns exception.", GetErrorMessage(r));
3120 return r; // Relay the result;
3124 if (moved || resized)
3126 const FloatRectangle fbounds(bounds.x, bounds.y, bounds.width, bounds.height);
3127 if (IsLayoutChangable() == false)
3129 r = UpdateBoundsOfVisualElement(FloatRectangle(0.0f, 0.0f, fbounds.width, fbounds.height));
3133 r = UpdateBoundsOfVisualElement(fbounds);
3137 SysAssert(r == E_SUCCESS); // [ToDo] Exception check and rollback.
3141 if (changeLayoutBaseRect)
3143 __pLayoutContainer->OnChangeBaseRect();
3146 if ((moved || resized) && callBoundsChangeCallbacks)
3148 if (IsMovable() && IsResizable())
3150 SetClientBounds(FloatRectangle(0.0f, 0.0f, GetSizeF().width, GetSizeF().height));
3152 if (__pFocusVisualElement)
3154 __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, __bounds.width, __bounds.height));
3156 delegate.OnBoundsChanged();
3158 _Control* pParent = GetParent();
3161 pParent->GetControlDelegate().OnChildBoundsChanged(*this);
3164 ControlList& children = GetChildList();
3165 _Control* pChild = null;
3166 int childrenCount = children.GetCount();
3168 for (int index = 0; index < childrenCount; index++)
3170 r = children.GetAt(index, pChild);
3173 pChild->GetControlDelegate().OnParentBoundsChanged(*this);
3178 if (moved || resized)
3180 InvalidateHierarchyAbsoluteBounds(*this);
3187 // Custom Exception: ex) Location::Map
3189 _Control::AdjustSizeToRange(void)
3192 result r = E_SUCCESS;
3194 SysAssert(IsResizable());
3196 FloatDimension size = GetSizeF();
3197 bool changed = ::AdjustSizeToRange(size, __minSize, __maxSize);
3203 FloatRectangle newBounds(__bounds.x, __bounds.y, size.width, size.height);
3204 r = SetBoundsFinal(newBounds, true, true);
3213 // Custom Exception: ex) Location::Map
3216 _Control::SetBoundsInternal(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3218 SysTryReturn(NID_UI,
3219 IsInSizeRange(FloatDimension(bounds.width, bounds.height)), E_INVALID_ARG,
3221 "[E_INVALID_ARG] The specified size(%f, %f) is out of range from min size(%f, %f) to max size(%f, %f).",
3222 bounds.width, bounds.height, __minSize.width, __minSize.height, __maxSize.width, __maxSize.height);
3224 SetUpdateLayoutState(true);
3226 return SetBoundsFinal(bounds, true, callBoundsChangeCallbacks);
3229 // Custom Exception: ex) Location::Map
3231 // E_UNSUPPORTED_OPERATION
3233 _Control::SetBounds(const Rectangle& bounds, bool callBoundsChangeCallbacks)
3237 __isChangedPositionByUser = true;
3239 if (callBoundsChangeCallbacks)
3241 SysTryReturn(NID_UI,
3242 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3243 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3245 FloatRectangle floatBounds(bounds.x, bounds.y, bounds.width, bounds.height);
3247 return SetBoundsInternal(floatBounds, callBoundsChangeCallbacks);
3250 // Custom Exception: ex) Location::Map
3252 // E_UNSUPPORTED_OPERATION
3254 _Control::SetBounds(const FloatRectangle& bounds, bool callBoundsChangeCallbacks)
3258 __isChangedPositionByUser = true;
3260 if (callBoundsChangeCallbacks)
3262 SysTryReturn(NID_UI,
3263 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3264 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3267 return SetBoundsInternal(bounds, callBoundsChangeCallbacks);
3270 // A custom Exception can occur. ex) Location::Map
3272 // E_UNSUPPORTED_OPERATION
3274 _Control::SetPosition(const Point& position)
3278 __isChangedPositionByUser = true;
3280 SysTryReturn(NID_UI,
3281 IsMovable(), E_UNSUPPORTED_OPERATION,
3282 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3284 return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3288 _Control::SetPosition(const FloatPoint& position)
3292 __isChangedPositionByUser = true;
3294 SysTryReturn(NID_UI,
3295 IsMovable(), E_UNSUPPORTED_OPERATION,
3296 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable.");
3298 return SetBoundsInternal(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height), true);
3301 // Custom Exception: ex) Location::Map
3303 // E_UNSUPPORTED_OPERATION
3305 _Control::SetSize(const Dimension& size)
3309 SysTryReturn(NID_UI,
3310 IsResizable(), E_UNSUPPORTED_OPERATION,
3311 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3313 return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3317 _Control::SetSize(const FloatDimension& size)
3321 SysTryReturn(NID_UI,
3322 IsResizable(), E_UNSUPPORTED_OPERATION,
3323 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3325 return SetBoundsInternal(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height), true);
3329 _Control::IsChangedPositionByUser(void) const
3331 return __isChangedPositionByUser;
3335 _Control::SetChangedPositionByUser(bool change)
3337 __isChangedPositionByUser = change;
3341 _Control::GetMinimumSize(void) const
3345 return _CoordinateSystemUtils::ConvertToInteger(__minSize);
3349 _Control::GetMinimumSizeF(void) const
3357 _Control::GetMaximumSize(void) const
3361 return _CoordinateSystemUtils::ConvertToInteger(__maxSize);
3365 _Control::GetMaximumSizeF(void) const
3372 // Custom Exception: ex) Location::Map
3373 // E_UNSUPPORTED_OPERATION
3376 _Control::SetMinimumSize(const Dimension& newMinSize)
3380 SysTryReturn(NID_UI,
3381 IsResizable(), E_UNSUPPORTED_OPERATION,
3382 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3384 SysTryReturn(NID_UI,
3385 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3386 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3388 SysTryReturn(NID_UI,
3389 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3390 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3392 if (__maxSize.width < newMinSize.width)
3394 __maxSize.width = newMinSize.width;
3396 if (__maxSize.height < newMinSize.height)
3398 __maxSize.height = newMinSize.height;
3401 __minSize = _CoordinateSystemUtils::ConvertToFloat(newMinSize);
3402 return AdjustSizeToRange();
3406 _Control::SetMinimumSize(const FloatDimension& newMinSize)
3410 SysTryReturn(NID_UI,
3411 IsResizable(), E_UNSUPPORTED_OPERATION,
3412 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3414 SysTryReturn(NID_UI,
3415 (newMinSize.width >= 0 && newMinSize.height >= 0), E_INVALID_ARG,
3416 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3418 SysTryReturn(NID_UI,
3419 (newMinSize.width <= MAX_LENGTH && newMinSize.height <= MAX_LENGTH), E_INVALID_ARG,
3420 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3422 if (__maxSize.width < newMinSize.width)
3424 __maxSize.width = newMinSize.width;
3426 if (__maxSize.height < newMinSize.height)
3428 __maxSize.height = newMinSize.height;
3431 __minSize = newMinSize;
3432 return AdjustSizeToRange();
3435 // Custom Exception: ex) Location::Map
3436 // E_UNSUPPORTED_OPERATION
3439 _Control::SetMaximumSize(const Dimension& newMaxSize)
3443 SysTryReturn(NID_UI,
3444 IsResizable(), E_UNSUPPORTED_OPERATION,
3445 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3447 SysTryReturn(NID_UI,
3448 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3449 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3451 SysTryReturn(NID_UI,
3452 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3453 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3455 if (newMaxSize.width < __minSize.width)
3457 __minSize.width = newMaxSize.width;
3459 if (newMaxSize.height < __minSize.height)
3461 __minSize.height = newMaxSize.height;
3464 __maxSize = _CoordinateSystemUtils::ConvertToFloat(newMaxSize);
3465 return AdjustSizeToRange();
3469 _Control::SetMaximumSize(const FloatDimension& newMaxSize)
3473 SysTryReturn(NID_UI,
3474 IsResizable(), E_UNSUPPORTED_OPERATION,
3475 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not resizable.");
3477 SysTryReturn(NID_UI,
3478 (newMaxSize.width >= 0 && newMaxSize.height >= 0), E_INVALID_ARG,
3479 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is smaller than 0.");
3481 SysTryReturn(NID_UI,
3482 (newMaxSize.width <= MAX_LENGTH && newMaxSize.height <= MAX_LENGTH), E_INVALID_ARG,
3483 E_INVALID_ARG, "[E_INVALID_ARG] The width or height is greater than %d.", MAX_LENGTH);
3485 if (newMaxSize.width < __minSize.width)
3487 __minSize.width = newMaxSize.width;
3489 if (newMaxSize.height < __minSize.height)
3491 __minSize.height = newMaxSize.height;
3494 __maxSize = newMaxSize;
3495 return AdjustSizeToRange();
3500 _Control::ConvertToControlPosition(const Point& screenPosition) const
3502 Point controlPosition;
3503 Rectangle absoluteBounds = GetAbsoluteBounds();
3505 controlPosition.x = screenPosition.x - absoluteBounds.x;
3506 controlPosition.y = screenPosition.y - absoluteBounds.y;
3508 return controlPosition;
3512 _Control::ConvertToControlPosition(const FloatPoint& screenPosition) const
3514 FloatPoint controlPosition;
3515 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3517 controlPosition.x = screenPosition.x - absoluteBounds.x;
3518 controlPosition.y = screenPosition.y - absoluteBounds.y;
3520 return controlPosition;
3524 _Control::ConvertToScreenPosition(const Point& controlPosition) const
3526 Point screenPosition;
3527 Rectangle absoluteBounds = GetAbsoluteBounds();
3529 screenPosition.x = controlPosition.x + absoluteBounds.x;
3530 screenPosition.y = controlPosition.y + absoluteBounds.y;
3532 return screenPosition;
3536 _Control::ConvertToScreenPosition(const FloatPoint& controlPosition) const
3538 FloatPoint screenPosition;
3539 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
3541 screenPosition.x = controlPosition.x + absoluteBounds.x;
3542 screenPosition.y = controlPosition.y + absoluteBounds.y;
3544 return screenPosition;
3548 _Control::GetClientBounds(void) const
3550 if (!__isSetClientBounds)
3552 return Rectangle(0, 0, __bounds.width, __bounds.height);
3555 return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3559 _Control::GetClientBoundsF(void) const
3561 if (!__isSetClientBounds)
3563 return FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height);
3566 return __clientBounds;
3571 _Control::GetClientBounds(const Tizen::Graphics::Dimension& size) const
3573 if (!__isSetClientBounds)
3575 return Rectangle(0, 0, size.width, size.height);
3578 return _CoordinateSystemUtils::ConvertToInteger(__clientBounds);
3583 _Control::GetClientBoundsF(const Tizen::Graphics::FloatDimension& size) const
3585 if (!__isSetClientBounds)
3587 return FloatRectangle(0.0f, 0.0f, size.width, size.height);
3590 return __clientBounds;
3594 _Control::GetAbsoluteBounds(bool recalcAlways) const
3596 if (!recalcAlways && !__needRecalcAbsBounds)
3598 return __absoluteBounds;
3602 Rectangle absoluteBounds;
3603 Rectangle clientBounds;
3605 const _Control* pSelf = this;
3606 const _Control* pParent = GetParent();
3610 if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3612 clientBounds = pParent->GetClientBounds();
3613 accumPoint += Point(clientBounds.x, clientBounds.y);
3614 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3615 accumPoint.y -= pParent->GetVerticalScrollPosition();
3618 accumPoint += pSelf->GetPosition();
3620 pParent = pParent->GetParent();
3623 _Window* pWindow = GetRootWindow();
3627 Point winPoint = pWindow->GetPosition();
3629 accumPoint.x += winPoint.x;
3630 accumPoint.y += winPoint.y;
3633 absoluteBounds.x = accumPoint.x;
3634 absoluteBounds.y = accumPoint.y;
3635 absoluteBounds.width = __bounds.width;
3636 absoluteBounds.height = __bounds.height;
3638 const_cast<_Control*>(this)->__absoluteBounds = absoluteBounds;
3639 const_cast<_Control*>(this)->__needRecalcAbsBounds = false;
3641 return absoluteBounds;
3645 _Control::GetAbsoluteBoundsF(bool recalcAlways) const
3647 if (!recalcAlways && !__needRecalcAbsBoundsF)
3649 return __absoluteBoundsF;
3652 FloatPoint accumPoint;
3653 FloatRectangle absoluteBounds;
3654 FloatRectangle clientBounds;
3656 const _Control* pSelf = this;
3657 const _Control* pParent = GetParent();
3661 if ((pSelf->GetArea() == _CONTROL_AREA_CLIENT) && pParent)
3663 clientBounds = pParent->GetClientBoundsF();
3664 accumPoint += FloatPoint(clientBounds.x, clientBounds.y);
3665 accumPoint.x -= pParent->GetHorizontalScrollPosition();
3666 accumPoint.y -= pParent->GetVerticalScrollPosition();
3669 accumPoint += pSelf->GetPositionF();
3671 pParent = pParent->GetParent();
3674 _Window* pWindow = GetRootWindow();
3678 FloatPoint winPoint = pWindow->GetPositionF();
3680 accumPoint.x += winPoint.x;
3681 accumPoint.y += winPoint.y;
3684 absoluteBounds.x = accumPoint.x;
3685 absoluteBounds.y = accumPoint.y;
3686 absoluteBounds.width = __bounds.width;
3687 absoluteBounds.height = __bounds.height;
3689 const_cast<_Control*>(this)->__absoluteBoundsF = absoluteBounds;
3690 const_cast<_Control*>(this)->__needRecalcAbsBoundsF = false;
3692 return absoluteBounds;
3696 _Control::SetClientBounds(const Rectangle& bounds)
3700 const bool moved = (__clientBounds.x != _CoordinateSystemUtils::ConvertToFloat(bounds).x) || (__clientBounds.y != _CoordinateSystemUtils::ConvertToFloat(bounds).y);
3701 const bool resized = (__clientBounds.width != _CoordinateSystemUtils::ConvertToFloat(bounds).width) || (__clientBounds.height != _CoordinateSystemUtils::ConvertToFloat(bounds).height);
3703 SysTryReturn(NID_UI,
3704 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3705 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3706 __clientBounds = _CoordinateSystemUtils::ConvertToFloat(bounds);
3707 __isSetClientBounds = true;
3709 if (moved || resized)
3711 result r = AdjustAbsoluteBounds(*this);
3712 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3714 SetUpdateLayoutState(true);
3720 _Control::SetClientBounds(const FloatRectangle& bounds)
3724 const bool moved = (__clientBounds.x != bounds.x) || (__clientBounds.y != bounds.y);
3725 const bool resized = (__clientBounds.width != bounds.width) || (__clientBounds.height != bounds.height);
3727 SysTryReturn(NID_UI,
3728 IsMovable() && IsResizable(), E_UNSUPPORTED_OPERATION,
3729 E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Not movable nor resizable.");
3730 __clientBounds = bounds;
3731 __isSetClientBounds = true;
3733 if (moved || resized)
3735 result r = AdjustAbsoluteBounds(*this);
3736 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3738 SetUpdateLayoutState(true);
3745 _Control::IsCalledSetClientBounds(void)
3747 return __isSetClientBounds;
3751 _Control::UpdateClientBounds(const FloatDimension& size, FloatRectangle& clientBounds)
3753 clientBounds.width = size.width;
3754 clientBounds.height = size.height;
3758 _Control::GetBackgroundColor(void) const
3761 return __backgroundColor;
3765 _Control::SetBackgroundColor(const Color& color)
3768 __backgroundColor = color;
3770 _ControlVisualElement* pCVE = dynamic_cast <_ControlVisualElement*>(GetVisualElement());
3773 pCVE->SetBackgroundColor(
3775 (float)color.GetRed() / 255.0f,
3776 (float)color.GetGreen() / 255.0f,
3777 (float)color.GetBlue() / 255.0f,
3778 (float)color.GetAlpha() / 255.0f
3783 GetControlDelegate().OnBackgroundColorChanged(const_cast<Color&>(color));
3787 _Control::~_Control(void)
3789 __destroying = true;
3791 DoBacktrace(__pDeleteBacktrace.get());
3793 DetachAllChildren();
3795 _ControlManager::GetInstance()->TakeFocusFromControl(*this);
3805 // Dangerous: it clears last result and log in catch block.
3806 // ClearLastResult();
3810 _Control::DisposeControl(void)
3812 __pControlDelegate = null;
3814 delete __pLayoutItemHandler;
3815 __pLayoutItemHandler = null;
3817 delete __pLayoutContainer;
3818 __pLayoutContainer = null;
3826 if (__pVisualElement)
3828 __pVisualElement->Destroy();
3830 __pVisualElement = null;
3832 delete __pVisualElementContentProvider;
3833 __pVisualElementContentProvider = null;
3835 delete __pVisualElementEventListener;
3836 __pVisualElementEventListener = null;
3838 delete __pCoreGestureDetectors;
3839 __pCoreGestureDetectors = null;
3841 delete __pDataBindingContext;
3842 __pDataBindingContext = null;
3844 ClearStartedGestureDetectorList();
3845 delete __pDetectStartedGestureMap;
3846 __pDetectStartedGestureMap = null;
3848 delete __pDelayedTouchInfoList;
3849 __pDelayedTouchInfoList = null;
3851 delete __pAccessibilityContainer;
3852 __pAccessibilityContainer = null;
3854 if (__pFocusVisualElement)
3856 __pFocusVisualElement.release();
3862 _Control::_Control(void)
3863 : __needRecalcRootWindow(true)
3864 , __needRecalcAbsBounds(true)
3865 , __needRecalcAbsBoundsF(true)
3866 , __pRootWindow(null)
3871 , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
3872 , __contentAreaBounds(0.0f, 0.0f, 0.0f, 0.0f)
3873 , __clientBounds(0.0f, 0.0f, 0.0f, 0.0f)
3874 , __absoluteBounds(0, 0, 0, 0)
3875 , __absoluteBoundsF(0.0f, 0.0f, 0.0f, 0.0f)
3876 , __invalidatedBounds(0.0f, 0.0f, 0.0f, 0.0f)
3877 , __minSize(FloatDimension(0.0f, 0.0f))
3878 , __maxSize(FloatDimension(MAX_LENGTH, MAX_LENGTH))
3879 , __backgroundColor(Color::GetColor(COLOR_ID_BLACK))
3883 , __nativeObjectFocusable(true)
3884 , __enabledState(true)
3885 , __visibleState(true)
3886 , __initVisibleState(false)
3887 , __clipToParent(true)
3888 , __multiTouchEnabled(false)
3889 , __dragEnabled(false)
3890 , __dropEnabled(false)
3891 , __drawWhenVisible(true)
3892 , __isPostOrderTraversal(false)
3893 , __isCalledCallOnAttachingToMainTree(false)
3894 , __isCalledCallOnPreAttachedToMainTree(false)
3895 , __isCalledCallOnAttachedToMainTree(false)
3896 , __isSetClientBounds(false)
3897 , __isCalledGetCanvasN(false)
3898 , __isFocusMode(false)
3899 , __isNavigatable(true)
3900 , __isFocusWindowActivationChecked(false)
3901 , __isChangedPositionByUser(false)
3902 , __pVisualElementContentProvider(null)
3903 , __pVisualElement(null)
3904 , __pVisualElementEventListener(null)
3905 , __pLayoutItemHandler(null)
3906 , __pPortraitLayout(null)
3907 , __pLandscapeLayout(null)
3908 , __pLayoutContainer(null)
3909 , __area(_CONTROL_AREA_NONE)
3910 , __layer(_CONTROL_LAYER_NONE)
3911 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
3912 , __rotation(_CONTROL_ROTATION_0)
3913 , __pTouchEventPreviewer(null)
3914 , __pKeyEventPreviewer(null)
3915 , __pNotificationEventPreviewer(null)
3916 , __pKeyEventListener(null)
3917 , __pFocusEventListener(null)
3918 , __pNotificationEventListener(null)
3919 , __pCoreGestureDetectors(null)
3920 , __pDetectStartedGestureMap(null)
3921 , __pDelayedTouchInfoList(null)
3922 , __touchMoveAllowance(3)
3923 , __pressThresHold(0.0f)
3924 , __inputLockRefCount(0)
3926 , __isSentDelayedEvent(false)
3927 , __isSendingDelayedEvent(false)
3928 , __isChangingEventTarget(false)
3929 , __pDataBindingContext(null)
3930 , __pControlDelegate(null)
3932 , __destroying(false)
3933 , __isEventEnableState(true)
3934 , __isEffectSoundEnabled(true)
3935 , __isControlFontChanged(false)
3938 , __fontFileName(L"")
3939 , __pPreviousFocus(null)
3940 , __pNextFocus(null)
3941 , __pDragWindow(null)
3942 , __isDragAndDropSource(false)
3946 std::unique_ptr<Tizen::Base::Collection::ArrayListT<void*> > pNewBacktrace(new (std::nothrow) ArrayListT<void*>);
3947 SysTryReturnVoidResult(NID_SHELL, pNewBacktrace, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3949 result r = pNewBacktrace->Construct();
3950 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3952 __pNewBacktrace = move(pNewBacktrace);
3954 DoBacktrace(__pNewBacktrace.get());
3956 std::unique_ptr<Tizen::Base::Collection::ArrayListT<void*> > pDeleteBacktrace(new (std::nothrow) ArrayListT<void*>);
3957 SysTryReturnVoidResult(NID_SHELL, pDeleteBacktrace, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3959 r = pDeleteBacktrace->Construct();
3960 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3962 __pDeleteBacktrace = move(pDeleteBacktrace);
3964 SetControlDelegate(*this);
3965 __pAccessibilityContainer = new (std::nothrow) _AccessibilityContainer(*this);
3966 __pAccessibilityContainer->Activate(true);
3968 __pLayoutItemHandler = new (std::nothrow) LayoutItemHandler(this);
3969 if (!__pLayoutItemHandler)
3974 __pLayoutContainer = CreateLayoutContainerN(__pLayoutItemHandler);
3975 if (!__pLayoutContainer)
3980 __pChildren = ::CreateControlListN();
3986 __pOwnees = ::CreateWindowListN();
3992 __pVisualElement = ::CreateVisualElementN();
3993 if (!__pVisualElement)
3998 __pVisualElement->SetUserData(this);
3999 __pVisualElement->SetClipChildrenEnabled(true);
4000 __pVisualElement->SetRedrawOnResizeEnabled(true);
4002 __pVisualElementContentProvider = new (std::nothrow) ControlVisualElementContentProvider(*this);
4003 SysTryCatch(NID_UI, __pVisualElementContentProvider, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4005 GetVisualElement()->SetContentProvider(__pVisualElementContentProvider);
4007 __pVisualElementEventListener = new (std::nothrow) ControlVisualElementEventListener(*this);
4008 SysTryCatch(NID_UI, __pVisualElementEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4010 GetVisualElement()->SetVisualElementEventListener(__pVisualElementEventListener);
4012 __pDetectStartedGestureMap = ::CreateGestureMapN();
4013 if (!__pDetectStartedGestureMap)
4018 __pCoreGestureDetectors = new (std::nothrow) LinkedListT<_TouchGestureDetector*>;
4019 if (!__pCoreGestureDetectors)
4024 __pDelayedTouchInfoList = new (std::nothrow) LinkedListT<_TouchInfo*>;
4025 if (!__pDelayedTouchInfoList)
4030 SetEventPreviewer<_UI_EVENT_TOUCH>(this);
4031 SetEventPreviewer<_UI_EVENT_KEY>(this);
4032 SetEventPreviewer<_UI_EVENT_NOTIFICAITON>(this);
4034 SetEventListener<_UI_EVENT_NOTIFICAITON>(this);
4035 SetEventListener<_UI_EVENT_FOCUS>(this);
4037 SetPropagatedTouchEventListener(this);
4038 SetPropagatedKeyEventListener(this);
4039 GET_COLOR_CONFIG(BASIC::background, __backgroundColor);
4041 if (IsFailed(GetLastResult()))
4043 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
4046 __screenDpi = _ControlManager::GetInstance()->GetScreenDpi();
4056 _Control::AcquireHandle(void)
4058 __controlHandle = _ControlManager::GetInstance()->Register(this); // [ToDo] exception?
4062 _Control::ReleaseHandle(void)
4064 _ControlManager::GetInstance()->Release(__controlHandle); // [ToDo] exception?
4068 _Control::SetDrawWhenVisible(bool draw)
4070 __drawWhenVisible = draw;
4074 _Control::IsDrawWhenVisible(void)
4076 return __drawWhenVisible;
4080 _Control::SetTerminatingOrder(bool postOrderTraversal)
4082 __isPostOrderTraversal = postOrderTraversal;
4086 _Control::IsPostOrderTraversal(void)
4088 return __isPostOrderTraversal;
4092 _Control::SetParent(_Control* pParent)
4095 __pParent = pParent;
4099 // Only called by _Window::SetOwner(pOwner)
4101 _Control::AttachOwnee(_Window& window)
4104 result r = E_SUCCESS;
4106 _Control* pOldOwner = window.GetOwner();
4109 pOldOwner->DetachOwnee(window);
4112 r = __pOwnees->Add(&window);
4115 SysLogException(NID_UI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4116 return E_OUT_OF_MEMORY;
4123 _Control::GetOwneeCount(void) const
4126 return __pOwnees->GetCount();
4131 _Control::GetOwnee(int index) const
4134 result r = E_SUCCESS;
4136 _Window* pOwnee = null;
4137 r = __pOwnees->GetAt(index, pOwnee);
4140 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4147 // Called by _Window::SetOwner(null)
4149 _Control::DetachOwnee(_Window& ownee)
4152 result r = E_SUCCESS;
4154 _Control* pOwner = ownee.GetOwner();
4160 r = __pOwnees->Remove(&ownee);
4163 SysLogException(NID_UI, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
4168 _Control::DetachAllOwnees(void)
4172 int owneeCount = GetOwneeCount();
4173 while (owneeCount--)
4175 _Window* pOwnee = GetOwnee(0);
4181 pOwnee->SetOwner(null);
4185 _Layout::LayoutContainer&
4186 _Control::GetLayoutContainer() const
4188 return *__pLayoutContainer;
4192 _Control::SetMultiTouchEnabled(bool enabled)
4195 __multiTouchEnabled = enabled;
4199 _Control::IsMultiTouchEnabled(void) const
4202 return __multiTouchEnabled;
4206 _Control::SetMovable(bool movable)
4209 __movable = movable;
4213 _Control::SetResizable(bool resizable)
4219 __minSize = __maxSize = GetSizeF();
4222 if (!__resizable && resizable)
4224 __minSize = FloatDimension(0.0f, 0.0f);
4225 __maxSize = FloatDimension(MAX_LENGTH, MAX_LENGTH);
4228 __resizable = resizable;
4232 _Control::GetLayout(void) const
4235 _Layout::Layout* pLayout = __pLayoutContainer->GetLayout();
4237 SysAssert(GetLastResult() == E_SUCCESS);
4242 _Control::SetCurrentLayout(_Layout::Layout& layout)
4245 return __pLayoutContainer->SetCurrentLayout(layout);
4249 _Control::AddLayout(_Layout::Layout& layout)
4252 return __pLayoutContainer->AddLayout(layout);
4256 _Control::SetUpdateLayoutState(bool state)
4258 _Layout::Layout* pLayout = GetLayout();
4261 pLayout->SetUpdateState(state);
4266 _Control::SetEffectSoundEnabled(bool enable)
4268 __isEffectSoundEnabled = enable;
4272 _Control::IsEffectSoundEnabled(void) const
4274 return __isEffectSoundEnabled;
4277 _DataBindingContext*
4278 _Control::GetDataBindingContext(void)
4280 return __pDataBindingContext;
4282 _AccessibilityContainer*
4283 _Control::GetAccessibilityContainer(void)
4285 return __pAccessibilityContainer;
4288 _Control::SetDataBindingContext(_DataBindingContext* pDataBindingContext)
4290 __pDataBindingContext = pDataBindingContext;
4294 _Control::DoBacktrace(Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList)
4296 SysTryReturnVoidResult(NID_SHELL, pBacktraceList, E_INVALID_ARG, "[E_INVALID_ARG].");
4298 const static int ADDR_SIZE = 100;
4300 void* pBuffer[ADDR_SIZE];
4302 retSize = backtrace(pBuffer, ADDR_SIZE);
4303 for (int i = 0; i < retSize; i++)
4307 pBacktraceList->Add(pBuffer[i]);
4313 _Control::GetDescription(void) const
4319 _Control::SetTouchCapture(bool allowOutOfBounds, bool allowOwnerBounds)
4321 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4322 SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4324 pTouchManager->SetCapturedControl(this, allowOutOfBounds, allowOwnerBounds);
4328 _Control::ReleaseTouchCapture(void)
4330 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4331 SysTryReturnVoidResult(NID_UI, pTouchManager != null, E_SYSTEM, "[E_SYSTEM] TouchManager Instance is null");
4333 pTouchManager->SetCapturedControl(null, false, false);
4337 _Control::GetTopmostChildAt(const Point& point) const
4339 _Control* pTouchedControl = null;
4340 FloatPoint ptf((float) point.x, (float) point.y);
4341 _ControlManager* pControlManager = _ControlManager::GetInstance();
4342 SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
4344 _Window* pRootWindow = GetRootWindow();
4345 SysTryReturn(NID_UI, pRootWindow, null, E_SYSTEM, "[E_SYSTEM] GetRootWindow() is null, this control is detached from the main trree");
4347 _ControlVisualElement* pRootControlElement = dynamic_cast <_ControlVisualElement*>(pRootWindow->GetVisualElement());
4348 SysTryReturn(NID_UI, pRootControlElement, null, E_SYSTEM, "[E_SYSTEM] pRootControlElement is null.");
4350 _ControlVisualElement* pHitTestElm = pRootControlElement->GetControlChildAtPoint(ptf);
4351 if (pHitTestElm == null)
4353 SysSecureLog(NID_UI, "pHitTestElm is null, point(%f, %f)", ptf.x, ptf.y);
4357 pTouchedControl = static_cast <_Control*>(pHitTestElm->GetUserData());
4359 return pTouchedControl;
4363 _Control::SetContentAreaBounds(const Rectangle& rect)
4367 __contentAreaBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
4371 _Control::SetContentAreaBounds(const FloatRectangle& rect)
4375 __contentAreaBounds = rect;
4379 _Control::GetContentAreaBounds(void) const
4381 return _CoordinateSystemUtils::ConvertToInteger(__contentAreaBounds);
4385 _Control::GetContentAreaBoundsF(void) const
4387 if (__contentAreaBounds != FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
4389 return __contentAreaBounds;
4393 _Layout::Layout* pLayout = GetLayout();
4396 _Layout::LayoutMatchMode widthMatchMode = _Layout::NONE_MODE;
4397 _Layout::LayoutMatchMode heightMatchMode = _Layout::NONE_MODE;
4399 _Layout::LayoutItem& layoutItem = GetLayoutContainer();
4401 pLayout->GetItemWidthMatchMode(layoutItem, widthMatchMode);
4402 pLayout->GetItemHeightMatchMode(layoutItem, heightMatchMode);
4404 bool widthWrapContent = widthMatchMode == _Layout::WRAP_CONTENT;
4405 bool heightWrapContent = heightMatchMode == _Layout::WRAP_CONTENT;
4407 if (widthWrapContent || heightWrapContent)
4409 FloatDimension contentSize = GetContentSizeF(widthWrapContent, heightWrapContent);
4410 return FloatRectangle(__bounds.x, __bounds.y, contentSize.width, contentSize.height);
4414 return __contentAreaBounds;
4421 _Control::GetCapturedBitmapN(bool includeChildren) const
4423 result r = E_SUCCESS;
4425 Canvas* pCanvas = null;
4426 Bitmap* pBitmap = null;
4428 pBitmap = GetControlDelegate().OnCapturedBitmapRequestedN();
4429 if (pBitmap == null)
4431 FloatRectangle rect;
4433 Rectangle boundsInCanvas = GetBounds();
4434 boundsInCanvas.x = boundsInCanvas.y = 0;
4436 pCanvas = new (std::nothrow) Canvas;
4437 SysTryReturn(NID_UI, pCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4439 r = pCanvas->Construct(boundsInCanvas);
4440 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4442 GetVisualElement()->Draw();
4445 rect.SetBounds(boundsInCanvas.x, boundsInCanvas.y, boundsInCanvas.width, boundsInCanvas.height);
4447 r = GetVisualElement()->Capture(*pCanvas, rect, includeChildren);
4448 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
4450 pBitmap = new (std::nothrow) Bitmap;
4451 SysTryCatch(NID_UI, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4453 r = pBitmap->Construct(*pCanvas, boundsInCanvas);
4456 SysTryCatch(NID_UI, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4459 SysLog(NID_UI, "Bitmap (width:%d, height:%d)", pBitmap->GetWidth(), pBitmap->GetHeight());
4463 _BitmapImpl::ConvertToNonpremultiplied(*pBitmap, true);
4475 Tizen::Graphics::Rectangle
4476 _Control::GetInvalidatedBounds(void) const
4478 return _CoordinateSystemUtils::ConvertToInteger(__invalidatedBounds);
4481 Tizen::Graphics::FloatRectangle
4482 _Control::GetInvalidatedBoundsF(void) const
4484 return __invalidatedBounds;
4488 _Control::AddGestureDetector(const _TouchGestureDetector& gestureDetector)
4492 bool exist = __pCoreGestureDetectors->Contains(const_cast<_TouchGestureDetector*>(&gestureDetector));
4493 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "__pCoreGestureDetectors has gesture already");
4495 result r = __pCoreGestureDetectors->Add(const_cast<_TouchGestureDetector*>(&gestureDetector));
4496 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4498 r = const_cast<_TouchGestureDetector&>(gestureDetector).SetControl(*this);
4499 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "Control handle is not valid.");
4501 const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorAdded();
4507 _Control::RemoveGestureDetector(const _TouchGestureDetector& gestureDetector)
4511 result r = __pCoreGestureDetectors->Remove(&(const_cast<_TouchGestureDetector&>(gestureDetector)));
4517 const_cast<_TouchGestureDetector&>(gestureDetector).OnTouchGestureDetectorRemoved();
4522 IListT <_TouchGestureDetector*>*
4523 _Control::GetGestureDetectorList(void) const
4525 return __pCoreGestureDetectors;
4528 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>*
4529 _Control::GetStartedGestureDetectorEnumeratorN(void) const
4531 return __pDetectStartedGestureMap->GetMapEnumeratorN();
4534 IListT <_TouchGestureDetector*>*
4535 _Control::GetStartedGestureDetectorListN(void) const
4537 return __pDetectStartedGestureMap->GetKeysN();
4541 _Control::AddStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4545 result r = E_SUCCESS;
4548 __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4552 r = __pDetectStartedGestureMap->Add(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4559 _Control::SetStartedGestureDetector(const _TouchGestureDetector& gestureDetector, _TouchGestureDetectorState state)
4563 result r = E_SUCCESS;
4566 __pDetectStartedGestureMap->ContainsKey(const_cast<_TouchGestureDetector*>(&gestureDetector), exist);
4570 r = __pDetectStartedGestureMap->SetValue(const_cast<_TouchGestureDetector*>(&gestureDetector), state);
4577 _Control::ClearStartedGestureDetectorList(void)
4581 result r = E_SUCCESS;
4583 IListT<_TouchGestureDetector*>* pList = __pDetectStartedGestureMap->GetKeysN();
4586 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pList->GetEnumeratorN();
4589 while(pEnumerator->MoveNext() == E_SUCCESS)
4591 _TouchGestureDetector* pGestureDetector = null;
4592 pEnumerator->GetCurrent(pGestureDetector);
4594 if (pGestureDetector == null)
4599 __pDetectStartedGestureMap->Remove(pGestureDetector);
4606 IEnumeratorT<_TouchInfo*>* pEnumerator = __pDelayedTouchInfoList->GetEnumeratorN();
4609 while(pEnumerator->MoveNext() == E_SUCCESS)
4611 _TouchInfo* pTouchInfo = null;
4612 pEnumerator->GetCurrent(pTouchInfo);
4613 if (pTouchInfo == null)
4621 __pDelayedTouchInfoList->RemoveAll();
4625 __isSentDelayedEvent = false;
4626 __isSendingDelayedEvent = false;
4632 _Control::IsDelayedTouchEventEnabled(void) const
4634 bool existDelayTouchEventGesture = false;
4636 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4639 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4641 _TouchGestureDetector* pGestureDetector = null;
4642 pMapEnumerator->GetKey(pGestureDetector);
4644 if (pGestureDetector == null)
4649 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4650 pMapEnumerator->GetValue(state);
4652 if (pGestureDetector->IsDelayTouchEventEnabled())
4654 existDelayTouchEventGesture = true;
4657 delete pMapEnumerator;
4660 bool delayTouchEvent = false;
4661 if (existDelayTouchEventGesture)
4663 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4666 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4668 _TouchGestureDetector* pGestureDetector = null;
4669 pMapEnumerator->GetKey(pGestureDetector);
4671 if (pGestureDetector == null)
4676 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4677 pMapEnumerator->GetValue(state);
4679 if (state == _TOUCH_GESTURE_DETECTOR_STATE_STARTED)
4681 delayTouchEvent = true;
4685 delete pMapEnumerator;
4688 return delayTouchEvent;
4697 _Control::IsPossibleToSendDelayedTouchEvent(void) const
4699 bool existDelayTouchEventGesture = false;
4701 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4704 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4706 _TouchGestureDetector* pGestureDetector = null;
4707 pMapEnumerator->GetKey(pGestureDetector);
4709 if (pGestureDetector == null)
4714 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4715 pMapEnumerator->GetValue(state);
4717 if (pGestureDetector->IsDelayTouchEventEnabled())
4719 existDelayTouchEventGesture = true;
4722 delete pMapEnumerator;
4725 bool allFailed = true;
4726 if (existDelayTouchEventGesture)
4728 pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4731 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4733 _TouchGestureDetector* pGestureDetector = null;
4734 pMapEnumerator->GetKey(pGestureDetector);
4736 if (pGestureDetector == null)
4741 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4742 pMapEnumerator->GetValue(state);
4744 if (state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS)
4750 delete pMapEnumerator;
4762 _Control::IsCancelOnGestureSuccess(void) const
4764 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4765 SysAssert(pTouchManager != null);
4767 IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState>* pMapEnumerator = __pDetectStartedGestureMap->GetMapEnumeratorN();
4770 while(pMapEnumerator->MoveNext() == E_SUCCESS)
4772 _TouchGestureDetector* pGestureDetector = null;
4773 pMapEnumerator->GetKey(pGestureDetector);
4775 if (pGestureDetector == null)
4780 _TouchGestureDetectorState state = _TOUCH_GESTURE_DETECTOR_STATE_READY;
4781 pMapEnumerator->GetValue(state);
4783 if (pGestureDetector->IsCancelTouchEventOnSuccessEnabled() && state == _TOUCH_GESTURE_DETECTOR_STATE_SUCCESS && !pTouchManager->IsTouchCanceledOnGestureSuccess())
4785 delete pMapEnumerator;
4789 delete pMapEnumerator;
4796 _Control::IsSentDelayedEvent(void) const
4798 return __isSentDelayedEvent;
4802 _Control::SetSentDelayedEvent(bool sent)
4804 __isSentDelayedEvent = sent;
4808 _Control::SetSendingDelayedEvent(bool sending)
4810 __isSendingDelayedEvent = sending;
4814 _Control::IsSendingDelayedEvent(void) const
4816 return __isSendingDelayedEvent;
4820 _Control::AddTouchInfo(const _TouchInfo& touchInfo)
4822 _TouchManager* pTouchManager = _TouchManager::GetInstance();
4823 SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] _TouchManager does not exist.");
4825 _TouchInfo* pTouchInfo = new (std::nothrow) _TouchInfo;
4826 SysTryReturnVoidResult(NID_UI, pTouchInfo, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4828 FloatPoint screenPoint = pTouchManager->GetScreenPoint(touchInfo.GetPointId());
4829 pTouchInfo->SetTouchInfo(touchInfo.GetPointId(), touchInfo.GetTouchStatus(), screenPoint, false, 0);
4830 __pDelayedTouchInfoList->Add(pTouchInfo);
4833 IListT<_TouchInfo*>*
4834 _Control::GetTouchInfoList(void)
4836 return __pDelayedTouchInfoList;
4840 _Control::SetVisualElement(_ControlVisualElement* pVisualElement)
4842 __pVisualElement = pVisualElement;
4846 _Control::GetVisualElement(void) const
4848 return __pVisualElement;
4852 _Control::PrintDescription(bool printChildren, int level)
4854 int count = PrintDescription(printChildren, 0, level);
4856 SysSecureLog(NID_UI, "%d controls were printed.", count);
4860 _Control::PrintDescription(bool printChildren, int depth, int level)
4862 const int PRINT_CONTROL_VE = 1;
4863 const int PRINT_CONTROL_EVAS = 2;
4864 const int PRINT_CONTROL_VE_EVAS = 3;
4869 format.Format(LOG_LEN_MAX, L"%d", depth);
4871 for (int i = 0; i < depth; i++)
4873 indent.Append(L" ");
4876 indent.Append(format);
4878 String delimiter(L"-------------------------------------------------------------------------------------------");
4879 SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
4882 String publicDescription = GetControlDelegate().GetDescription();
4883 if (!publicDescription.IsEmpty())
4885 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), publicDescription.GetPointer());
4888 _ControlManager* pControlManager = _ControlManager::GetInstance();
4889 SysTryReturn(NID_UI, pControlManager, null, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
4891 bool focused = false;
4892 _Control* pFocusedControl = pControlManager->GetFocusControl();
4893 if (pFocusedControl && (pFocusedControl == this))
4899 SysSecureLog(NID_UI, "%ls 0x%x(%d %ls) enable(%d) enableState(%d) visible(%d) visibleState(%d) clip(%d) movable(%d) resizable(%d)",
4900 indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer(), IsEnabled(), GetEnableState(), IsVisible(), GetVisibleState(),
4901 IsClipToParent(), IsMovable(), IsResizable());
4903 SysSecureLog(NID_UI, "%ls inputEnableState(%d) focusable(%d) focused(%d) prevFocus(0x%x) nextFocus(0x%x) font(0x%x) fontName(%ls) fontFileName(%ls)",
4904 indent.GetPointer(), GetInputEnableState(), IsFocusable(), focused, __pPreviousFocus, __pNextFocus, __pFont, __fontName.GetPointer(), __fontFileName.GetPointer());
4906 Rectangle bounds = GetBounds();
4907 Dimension min = GetMinimumSize();
4908 Dimension max = GetMaximumSize();
4909 Rectangle clientBounds = GetClientBounds();
4910 Rectangle absoluteBounds = GetAbsoluteBounds();
4912 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)",
4913 indent.GetPointer(), bounds.x, bounds.y, bounds.width, bounds.height,
4914 min.width, min.height, max.width, max.height,
4915 GetVerticalScrollPosition(), GetHorizontalScrollPosition(),
4916 clientBounds.x, clientBounds.y, clientBounds.width, clientBounds.height,
4917 absoluteBounds.x, absoluteBounds.y, absoluteBounds.width, absoluteBounds.height);
4919 SysSecureLog(NID_UI, "%ls bgColor(0x%x) layoutable(%d) orientation(%d) drag(%d) drop(%d) area(%d) layer(%d)",
4920 indent.GetPointer(), __backgroundColor.GetRGB32(), IsLayoutable(), GetOrientation(), IsDragEnabled(), IsDropEnabled(), GetArea(), GetLayer());
4922 Canvas* pCanvas = GetCanvasN();
4925 Rectangle canvasBounds = pCanvas->GetBounds();
4926 Color canvasBackgroundColor = pCanvas->GetBackgroundColor();
4927 Color canvasForegroundColor = pCanvas->GetForegroundColor();
4929 SysSecureLog(NID_UI, "%ls canvas.bounds(%d %d %d %d) canvas.bgColor(0x%x) canvas.fgColor(0x%x)",
4930 indent.GetPointer(), canvasBounds.x, canvasBounds.y, canvasBounds.width, canvasBounds.height, canvasBackgroundColor.GetRGB32(), canvasForegroundColor.GetRGB32());
4935 SysSecureLog(NID_UI, "%ls DataBindingContext(0x%x) ControlDelegate(0x%x) UserData(0x%x) destroying(%d)",
4936 indent.GetPointer(), __pDataBindingContext, __pControlDelegate, __pUserData, __destroying);
4941 for (int i = 0; i < GetOwneeCount(); ++i)
4944 _Window* pOwnee = GetOwnee(i);
4947 ownee.Format(LOG_LEN_MAX, L"0x%x ", pOwnee);
4948 ownees.Append(ownee);
4952 if (!ownees.IsEmpty())
4954 SysSecureLog(NID_UI, "%ls Ownees(%ls)", indent.GetPointer(), ownees.GetPointer());
4957 _VisualElementImpl* pVisualElementImpl = _VisualElementImpl::GetInstance(*__pVisualElement);
4959 SysSecureLog(NID_UI, "%ls _VisualElement(0x%x) _VisualElementImpl(0x%x) VisualElementContentProvider(0x%x) VisualElementEventListener(0x%x)",
4960 indent.GetPointer(), __pVisualElement, pVisualElementImpl, __pVisualElementContentProvider, __pVisualElementEventListener);
4963 SysSecureLog(NID_UI, "%ls LayoutItemHandler(0x%x) PortraitLayout(0x%x) LandscapeLayout(0x%x) LayoutContainer(0x%x)",
4964 indent.GetPointer(), __pLayoutItemHandler, __pPortraitLayout, __pLandscapeLayout, __pLayoutContainer);
4967 String description = GetDescription();
4968 if (!description.IsEmpty())
4970 SysSecureLog(NID_UI, "%ls %ls", indent.GetPointer(), description.GetPointer());
4973 // Print Gesture List
4974 IListT<_TouchGestureDetector*>* pGestureList = GetGestureDetectorList();
4975 SysTryReturn(NID_UI, pGestureList, 0, E_SYSTEM, "[E_SYSTEM] System error occurred.");
4977 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pGestureList->GetEnumeratorN();
4978 SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4980 while (pEnumerator->MoveNext() == E_SUCCESS)
4982 _TouchGestureDetector* pGestureDetector = null;
4983 pEnumerator->GetCurrent(pGestureDetector);
4984 if (pGestureDetector)
4986 SysSecureLog(NID_UI, "%ls AddedGesture : %ls", indent.GetPointer(), pGestureDetector->GetDescription().GetPointer());
4992 // Print Started Gesture List
4993 unique_ptr<IMapEnumeratorT <_TouchGestureDetector*, _TouchGestureDetectorState> > pStartedGestureEnumerator(GetStartedGestureDetectorEnumeratorN());
4994 SysTryReturn(NID_UI, pStartedGestureEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
4996 while (pStartedGestureEnumerator->MoveNext() == E_SUCCESS)
4998 _TouchGestureDetector* pStartedGestureDetector = null;
4999 pStartedGestureEnumerator->GetKey(pStartedGestureDetector);
5000 if (pStartedGestureDetector)
5002 SysSecureLog(NID_UI, "%ls StartedGesture : %ls", indent.GetPointer(), pStartedGestureDetector->GetDescription().GetPointer());
5007 unique_ptr<IEnumeratorT<void*> > pNewEnumerator(__pNewBacktrace->GetEnumeratorN());
5008 SysTryReturn(NID_SHELL, pNewEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5010 String newBacktrace;
5012 while (pNewEnumerator->MoveNext() == E_SUCCESS)
5015 pNewEnumerator->GetCurrent(pAddr);
5018 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5019 newBacktrace.Append(addr);
5022 if (!newBacktrace.IsEmpty())
5024 SysSecureLog(NID_UI, "%ls new [%ls]", indent.GetPointer(), newBacktrace.GetPointer());
5028 unique_ptr<IEnumeratorT<void*> > pDeleteEnumerator(__pDeleteBacktrace->GetEnumeratorN());
5029 SysTryReturn(NID_SHELL, pDeleteEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5031 String deleteBacktrace;
5033 while (pDeleteEnumerator->MoveNext() == E_SUCCESS)
5036 pDeleteEnumerator->GetCurrent(pAddr);
5039 addr.Format(LOG_LEN_MAX, L"0x%x ", pAddr);
5040 deleteBacktrace.Append(addr);
5043 if (!deleteBacktrace.IsEmpty())
5045 SysSecureLog(NID_UI, "%ls delete [%ls]", indent.GetPointer(), deleteBacktrace.GetPointer());
5048 // Print VE and Evas
5051 case PRINT_CONTROL_VE:
5052 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5055 case PRINT_CONTROL_EVAS:
5056 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5059 case PRINT_CONTROL_VE_EVAS:
5060 _VeDebug::DumpVeTree(pVisualElementImpl, 0);
5061 _VeDebug::DumpEvasTree(pVisualElementImpl, 0);
5068 static int totalCount = 0;
5079 int count = GetChildCount();
5080 totalCount += count;
5082 for (int i = count - 1; i >= 0; --i)
5084 _Control* pChild = GetChild(i);
5087 pChild->PrintDescription(printChildren, depth, level);
5096 _Control::PrintBacktrace(bool printChildren, bool newBacktrace)
5098 int count = PrintBacktrace(printChildren, 0, newBacktrace);
5100 SysSecureLog(NID_UI, "%d controls were printed.", count);
5104 _Control::PrintBacktrace(bool printChildren, int depth, bool newBacktrace)
5109 format.Format(LOG_LEN_MAX, L"%d", depth);
5111 for (int i = 0; i < depth; i++)
5113 indent.Append(L" ");
5116 indent.Append(format);
5118 String delimiter(L"-------------------------------------------------------------------------------------------");
5119 SysSecureLog(NID_UI, "%ls", delimiter.GetPointer());
5121 SysSecureLog(NID_UI, "%ls 0x%x(%d %ls)", indent.GetPointer(), this, __controlHandle.ToInt(), GetName().GetPointer());
5123 Tizen::Base::Collection::ArrayListT<void*>* pBacktraceList = null;
5127 pBacktraceList = __pNewBacktrace.get();
5131 pBacktraceList = __pDeleteBacktrace.get();
5134 SysTryReturn(NID_UI, pBacktraceList, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5136 int backtraceCount = pBacktraceList->GetCount();
5137 SysTryReturn(NID_UI, backtraceCount > 0, 0, E_INVALID_ARG, "[E_INVALID_ARG].");
5139 void** pBacktrace = new (std::nothrow) void*[backtraceCount];
5140 SysTryReturn(NID_UI, pBacktrace, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5142 unique_ptr<IEnumeratorT<void*> > pEnumerator(pBacktraceList->GetEnumeratorN());
5143 SysTryReturn(NID_UI, pEnumerator, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5146 while (pEnumerator->MoveNext() == E_SUCCESS)
5149 pEnumerator->GetCurrent(pAddr);
5151 pBacktrace[i++] = pAddr;
5154 char** pSymbols = backtrace_symbols(pBacktrace, backtraceCount);
5155 SysTryReturn(NID_UI, pSymbols, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5157 for (int j = 0; j < backtraceCount; j++)
5159 SysSecureLog(NID_UI, "%ls [%s]", indent.GetPointer(), pSymbols[j]);
5163 delete [] pBacktrace;
5165 static int totalCount = 0;
5176 int count = GetChildCount();
5177 totalCount += count;
5179 for (int i = count - 1; i >= 0; --i)
5181 _Control* pChild = GetChild(i);
5184 pChild->PrintBacktrace(printChildren, depth, newBacktrace);
5193 _Control::DragAndDropBegin(const _DragAndDropItem& dragAndDropItem)
5195 _Window* pRootWindow = GetRootWindow();
5201 __isDragAndDropSource = true;
5203 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5209 pEcoreEvas->SetDragAndDropState(true);
5210 pEcoreEvas->DragAndDropBegin(*pRootWindow, dragAndDropItem.GetData());
5212 __pDragWindow = GetControlDelegate().OnDragAndDropBeginning();
5216 _Control::DragAndDropDrop(void)
5218 _Window* pRootWindow = GetRootWindow();
5224 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5225 pEcoreEvas->DragAndDropDrop(*pRootWindow);
5227 GetControlDelegate().OnDragAndDropDropping();
5230 Point dropPosition = pEcoreEvas->GetDropPosition();
5231 Rectangle bounds = GetRootWindow()->GetBounds();
5232 if (bounds.Contains(dropPosition))
5234 _Control* pDropControl = _ControlManager::GetInstance()->GetTopmostTouchedControl(dropPosition, true);
5237 // Send dnd events to Source.
5239 if (pDropControl->IsDragAndDropSource() == false)
5242 int pid = pEcoreEvas->GetProcessId(pRootWindow->GetNativeHandle());
5243 String dropData = pEcoreEvas->GetDropData();
5244 SysLog(NID_UI, "[DND][S:%d] Call OnDragAndDropDropped(%ls) => %ls.", pid, dropData.GetPointer(), pDropControl->GetName().GetPointer());
5245 _DragAndDropItem* pDragAndDropItem = _DragAndDropItem::CreateInstanceN(_DRAG_AND_DROP_TYPE_TEXT, dropData);
5246 pDropControl->GetControlDelegate().OnDragAndDropDropped(*pDragAndDropItem);
5247 delete pDragAndDropItem;
5252 __isDragAndDropSource = false;
5256 _Control::GetDragWindow(void) const
5258 return __pDragWindow;
5262 _Control::IsDragAndDropSource(void) const
5264 return __isDragAndDropSource;
5268 _Control::OnDragAndDropBeginning(void)
5274 _Control::OnDragAndDropDropping(void)
5279 _Control::OnDragAndDropEntered(void)
5284 _Control::OnDragAndDropMoved(const FloatPoint& position)
5289 _Control::OnDragAndDropLeft(void)
5294 _Control::OnDragAndDropDropped(const _DragAndDropItem& dragAndDropItem)
5298 _ITouchEventPreviewer*
5299 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>) const
5301 return __pTouchEventPreviewer;
5304 _IKeyEventPreviewer*
5305 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_KEY>) const
5307 return __pKeyEventPreviewer;
5310 _INotificationEventPreviewer*
5311 _Control::GetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5313 return __pNotificationEventPreviewer;
5317 _Control::GetEventListener(_IntToType<_UI_EVENT_KEY>) const
5319 return __pKeyEventListener;
5322 _IFocusEventListener*
5323 _Control::GetEventListener(_IntToType<_UI_EVENT_FOCUS>) const
5325 return __pFocusEventListener;
5328 _INotificationEventListener*
5329 _Control::GetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>) const
5331 return __pNotificationEventListener;
5335 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_TOUCH>, _ITouchEventPreviewer* pPreviewer)
5337 __pTouchEventPreviewer = pPreviewer;
5341 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_KEY>, _IKeyEventPreviewer* pPreviewer)
5343 __pKeyEventPreviewer = pPreviewer;
5347 _Control::SetEventPreviewer(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventPreviewer* pPreviewer)
5349 __pNotificationEventPreviewer = pPreviewer;
5353 _Control::SetEventListener(_IntToType<_UI_EVENT_FOCUS>, _IFocusEventListener* pListener)
5355 __pFocusEventListener = pListener;
5359 _Control::SetEventListener(_IntToType<_UI_EVENT_NOTIFICAITON>, _INotificationEventListener* pListener)
5361 __pNotificationEventListener = pListener;
5365 _Control::IsDragEnabled(void) const
5367 return __dragEnabled;
5371 _Control::IsDropEnabled(void) const
5373 return __dropEnabled;
5377 _Control::SetDragEnabled(bool enabled)
5379 __dragEnabled = enabled;
5383 _Control::SetDropEnabled(bool enabled)
5385 __dropEnabled = enabled;
5389 _Control::SetTouchPressThreshold(float distance)
5391 __touchMoveAllowance = static_cast<int>(distance * __screenDpi);
5392 __pressThresHold = distance;
5396 _Control::GetTouchPressThreshold(void) const
5398 return __pressThresHold;
5402 _Control::GetTouchPressThresholdPixel(void) const
5404 return __touchMoveAllowance;
5408 _Control::SetChangingEventTarget(bool isChangingEventTarget)
5410 __isChangingEventTarget = isChangingEventTarget;
5414 _Control::GetChangingEventTarget(void) const
5416 return __isChangingEventTarget;
5420 _Control::SetEventEnableState(bool enableState)
5422 __isEventEnableState = enableState;
5426 _Control::IsEventEnabled(void) const
5428 return __isEventEnableState;
5432 _Control::SetPreviousFocus(_Control* pPreviousFocus)
5434 __pPreviousFocus = pPreviousFocus;
5438 _Control::SetNextFocus(_Control* pNextFocus)
5440 __pNextFocus = pNextFocus;
5443 _Control::GetPreviousFocus(void) const
5445 return __pPreviousFocus;
5448 _Control::GetNextFocus(void) const
5450 return __pNextFocus;
5454 _Control::OnDrawFocus(void)
5456 if (__pFocusVisualElement.get() == null)
5458 unique_ptr<VisualElement, _VisualElementDeleter> pFocusVisualElement (new (std::nothrow) VisualElement, _VisualElementDeleter());
5459 SysTryReturn(NID_UI, pFocusVisualElement, , E_SYSTEM, "[E_SYSTEM] System error");
5461 result r = pFocusVisualElement->Construct();
5462 SysTryReturn(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
5464 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*pFocusVisualElement);
5465 SysTryReturn(NID_UI, pImpl, , E_SYSTEM, "[E_SYSTEM] pImpl System error");
5466 pImpl->SetZOrderGroup(GetZOrderGroupOfVisualElement(_CONTROL_LAYER_SYSTEM));
5468 __pFocusVisualElement.reset(pFocusVisualElement.release());
5469 __pFocusVisualElement->SetImplicitAnimationEnabled(false);
5471 _VisualElement* pControVisualElement = this->GetVisualElement();
5472 pControVisualElement->AttachChild(*__pFocusVisualElement);
5475 if (__pFocusVisualElement)
5477 Rectangle rectangle = GetBounds();
5478 __pFocusVisualElement->SetBounds(FloatRectangle(0, 0, rectangle.width, rectangle.height));
5479 unique_ptr<Canvas>pCanvas(__pFocusVisualElement->GetCanvasN());
5482 pCanvas->SetBackgroundColor(0x55555555);
5485 Color contentHighlightedColor;
5486 GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
5487 Bitmap* pBitmap = null;
5488 Bitmap* pTempBitmap = null;
5489 result r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
5490 pBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
5494 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
5498 r = pCanvas->DrawNinePatchedBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5505 r = pCanvas->DrawBitmap(FloatRectangle(0.0f, 0.0f, rectangle.width, rectangle.height), *pBitmap);
5512 __pFocusVisualElement->SetShowState(true);
5516 _Control::OnChildControlFocusMoved(const _Control& control)
5521 _Control::OnDescendantControlFocusMoved(const _Control& control)
5526 _Control::IsChildControlFocusManage(void) const
5532 _Control::SetFontFromFile(const String& fileName)
5534 result r = E_SUCCESS;
5536 if (__fontFileName.Equals(fileName))
5541 __isControlFontChanged = true;
5542 __fontFileName = fileName;
5545 Font* pFont = GetFallbackFont();
5549 r = GetLastResult();
5550 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5556 _Control::GetFontFile(void) const
5558 return __fontFileName;
5561 _Control::DrawFocus(void)
5563 _IControlDelegate& delegate = GetControlDelegate();
5564 delegate.OnDrawFocus();
5568 _Control::MakeFocusList(const _Control* pControl, IListT<_Control*>* pFocusControlList) const
5570 int childCount = pControl->GetChildCount();
5571 for(int i = 0; i < childCount; i++)
5573 _Control* pChildControl = pControl->GetChild(i);
5574 Rectangle rect = pChildControl->GetAbsoluteBounds();
5575 unique_ptr<IEnumeratorT<_Control*> > pEnum (pFocusControlList->GetEnumeratorN());
5577 while (pEnum->MoveNext() == E_SUCCESS)
5579 _Control* pEnumeratorControl = null;
5580 pEnum->GetCurrent(pEnumeratorControl);
5581 if (pEnumeratorControl != null)
5583 Rectangle enumeratorRect = pEnumeratorControl->GetAbsoluteBounds();
5584 if(enumeratorRect.y > rect.y)
5588 else if (enumeratorRect.y == rect.y)
5590 if(enumeratorRect.x > rect.x)
5599 pFocusControlList->InsertAt(pChildControl, index);
5604 _Control::MakeChildContainerFocusList(const _Control* pControl, int startIndex , IListT<_Control*>* pFocusControlList) const
5606 unique_ptr<IListT<_Control*> > pTempList (new (std::nothrow) ArrayListT<_Control*>);
5607 SysTryReturnVoidResult(NID_UI_CTRL, pTempList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
5608 MakeFocusList(pControl, pTempList.get());
5610 unique_ptr<IEnumeratorT<_Control*> > pTempEnum(pTempList->GetEnumeratorN());
5611 int index = ++startIndex;
5612 while (pTempEnum->MoveNext() == E_SUCCESS)
5614 _Control* pEnumeratorControl = null;
5615 pTempEnum->GetCurrent(pEnumeratorControl);
5616 pFocusControlList->InsertAt(pEnumeratorControl, index);
5621 Tizen::Base::Collection::IListT<_Control*>*
5622 _Control::GetFocusListN(void) const
5624 unique_ptr<IListT<_Control*> > pControlFocusList (new (std::nothrow) ArrayListT<_Control*>);
5625 SysTryReturn(NID_UI_CTRL, pControlFocusList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5626 MakeFocusList(this, pControlFocusList.get());
5628 unique_ptr<IEnumeratorT<_Control*> > pEnum(pControlFocusList->GetEnumeratorN());
5629 SysTryReturn(NID_UI_CTRL, pEnum, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
5631 int nextContainerIndex = -1;
5632 while (pEnum->MoveNext() == E_SUCCESS)
5634 _Control* pEnumeratorControl = null;
5635 pEnum->GetCurrent(pEnumeratorControl);
5637 if (nextContainerIndex < i)
5639 if (pEnumeratorControl->IsChildControlFocusManage() == false)
5641 MakeChildContainerFocusList(pEnumeratorControl, i, pControlFocusList.get());
5642 nextContainerIndex = i;
5643 pEnum.reset(pControlFocusList->GetEnumeratorN());
5649 return pControlFocusList.release();
5653 _Control::IsChildAttachable(_Control& child) const
5655 if (dynamic_cast <_Window*>(&child) != null)