modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_ContainerImpl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 85069b9..8b418d9
@@ -2,14 +2,14 @@
 // Open Service Platform
 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Apache License, Version 2.0 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://floralicense.org/license/
+//     http://www.apache.org/licenses/LICENSE-2.0/
 //
 // Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
+// distributed under the License is distributed on an ”AS IS” BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
@@ -186,6 +186,15 @@ _ContainerImpl::Destroy(void)
        {
                r = pParent->RemoveChild(this, false);
        }
+       else
+       {
+               _Control* pParent = GetCore().GetParent();
+               if (pParent)
+               {
+                       ControlList& children = pParent->GetChildList();
+                       r = children.Remove(&GetCore());
+               }
+       }
        RemoveAllChildren(true);
        Container* pContainer = &GetPublic();
        delete pContainer;
@@ -204,20 +213,23 @@ _ContainerImpl::RemoveControl(_ControlImpl* pChild, bool deallocate)
        if (pChildContainer)
        {
                _ContainerImpl* pParent = pChildContainer->GetParent();
-               if (pParent)
-               {
-                       r = pParent->RemoveChild(pChildContainer, false);
-                       SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-               }
+               SysTryReturn(NID_UI, pParent, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The control is not a child of this container.");
+
+               r = pParent->RemoveChild(pChildContainer, false);
+               SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
                pChildContainer->RemoveAllChildren(true);
                r = GetLastResult();
                SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-               Container* pContainer = &pChildContainer->GetPublic();
-               delete pContainer;
-               pContainer = null;
+               if (deallocate)
+               {
+                       Container* pContainer = &pChildContainer->GetPublic();
+                       delete pContainer;
+                       pContainer = null;
+               }
        }
        else
        {
+               SysTryReturn(NID_UI, pChild, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified child is not constructed.");
                r = RemoveChild(pChild, deallocate);
                SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
@@ -240,7 +252,7 @@ _ContainerImpl::RemoveChild(_ControlImpl* pChild, bool deallocate)
                return E_SUCCESS;
        }
 
-       GetChildIndex(pChild); 
+       GetChildIndex(pChild);
        r = GetLastResult();
        SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -262,7 +274,7 @@ _ContainerImpl::RemoveControl(int index)
        _ControlImpl* pChild = GetChild(index); // Find child control.
        r = GetLastResult();
        SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       
+
        _ContainerImpl* pChildContainer = dynamic_cast <_ContainerImpl*>(pChild);
        if (pChildContainer)
        {
@@ -279,8 +291,11 @@ _ContainerImpl::RemoveControl(int index)
                delete pContainer;
                pContainer = null;
        }
-       r = RemoveChild(index);
-       SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       else
+       {
+               r = RemoveChild(index);
+               SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       }
 
        return r;
 }
@@ -312,7 +327,7 @@ _ContainerImpl::DeleteAllChildren(_ContainerImpl* pChild, bool detachSystemChild
 {
        ArrayList* pList = static_cast <ArrayList*>(pChild->GetChildrenPublic());
        int count = pList->GetCount();
-       for (int index = count; index >= 0; index--)
+       for (int index = count - 1; index >= 0; index--)
        {
                Control* pControl = static_cast <Control*>(pList->GetAt(index));
                if (pControl)
@@ -358,10 +373,18 @@ _ContainerImpl::DeleteAllChildren(_ContainerImpl* pChild, bool detachSystemChild
 }
 
 void
-_ContainerImpl::RemoveAllChildren(bool detachSystemChild)
+_ContainerImpl::RemoveAllChildren(bool detachSystemChild, bool callOnDetachingFromMaintree)
 {
+       if (callOnDetachingFromMaintree && !GetCore().IsPostOrderTraversal())
+       {
+               GetCore().GetControlDelegate().OnDetachingFromMainTree();
+       }
        GetCore().DetachAllChildren(detachSystemChild, true);
        SysAssert(GetLastResult() == E_SUCCESS);
+       if (callOnDetachingFromMaintree && GetCore().IsPostOrderTraversal())
+       {
+               GetCore().GetControlDelegate().OnDetachingFromMainTree();
+       }
        ArrayList* pChildrenList = static_cast <ArrayList*>(GetChildrenPublic());
        DeleteAllChildren(this, detachSystemChild, pChildrenList);
 }