Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / layout / FUi_LayoutAbsoluteLayout.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUi_LayoutAbsoluteLayout.cpp
19  * @brief       This is the implementation file for AbsoluteLayout class.
20  *
21  * This file contains the implementation of AbsoluteLayout class.
22  */
23
24 #include <new>
25 #include "FUi_LayoutAbsoluteLayout.h"
26 #include "FUi_LayoutLayoutItemProxy.h"
27 #include "FUi_LayoutProxyList.h"
28 #include "FUi_LayoutLayoutItemInfo.h"
29
30 namespace Tizen { namespace Ui { namespace _Layout
31 {
32
33 AbsoluteLayout::AbsoluteLayout(void)
34         : __defaultMatchParent(false)
35 {
36         AbsoluteProxyList* pAbsoluteProxyList = new (std::nothrow) AbsoluteProxyList();
37         SysTryReturnVoidResult(NID_UI, pAbsoluteProxyList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage");
38         SetItemList(pAbsoluteProxyList);
39 }
40
41 AbsoluteLayout::~AbsoluteLayout(void)
42 {
43 }
44
45 AbsoluteLayout*
46 AbsoluteLayout::CreateAbsoluteLayoutN(bool defaultMatchParent)
47 {
48         AbsoluteLayout* pLayout = new (std::nothrow) AbsoluteLayout();
49         SysTryReturn(NID_UI, pLayout != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Absolute layout core allocation failure.");
50         if (GetLastResult() != E_SUCCESS)
51         {
52                 delete pLayout;
53                 return null;
54         }
55
56         pLayout->__defaultMatchParent = defaultMatchParent;
57
58         return pLayout;
59 }
60
61 result
62 AbsoluteLayout::AddItem(LayoutItem& addItem)
63 {
64         result r = E_SUCCESS;
65
66         r = Layout::AddItem(addItem);
67         if (r != E_SUCCESS)
68         {
69                 return r;
70         }
71
72         if (__defaultMatchParent)
73         {
74                 r = Layout::SetItemWidthMatchMode(addItem, MATCH_PARENT);
75                 if (r != E_SUCCESS)
76                 {
77                         return r;
78                 }
79
80                 r = Layout::SetItemHeightMatchMode(addItem, MATCH_PARENT);
81                 if (r != E_SUCCESS)
82                 {
83                         return r;
84                 }
85         }
86
87         return r;
88 }
89
90 result
91 AbsoluteLayout::OnLayout(int width, int height, bool layoutUpdating)
92 {
93         ProxyList* pProxyList = GetProxyList();
94         SysAssertf(pProxyList != null, "ProxyList is invalid");
95
96         if (pProxyList == null)
97         {
98                 return E_INVALID_STATE;
99         }
100
101         LayoutItemProxy* pContainerProxy = GetContainerProxy();
102         if (pContainerProxy == null)
103         {
104                 return E_INVALID_STATE;
105         }
106
107         LayoutRect intendedRect = {0, 0, width, height};
108         pContainerProxy->ConvertWindowToClientBounds(intendedRect, intendedRect);
109
110         LayoutRect layoutRect = GetLayoutRect();
111         layoutRect.w = intendedRect.w;
112         layoutRect.h = intendedRect.h;
113         SetLayoutRect(layoutRect);
114
115         ProxyListNode* pNode = pProxyList->GetFirstNode();
116         while (pNode != null)
117         {
118                 LayoutItemProxy* pItemProxy = pNode->GetItemProxy();
119                 if (pItemProxy == null)
120                 {
121                         return E_INVALID_STATE;
122                 }
123                 LayoutRect itemRect = pItemProxy->GetItemBaseRect();
124                 if (pItemProxy->Measure(itemRect.w, itemRect.h) != E_SUCCESS)
125                 {
126                         return E_INVALID_STATE;
127                 }
128                 pItemProxy->GetMeasuredSize(itemRect.w, itemRect.h);
129                 LayoutRect layoutRect = GetLayoutRect();
130                 itemRect.x += layoutRect.x;
131                 itemRect.y += layoutRect.y;
132                 if (pItemProxy->SetItemWindowRect(itemRect) != E_SUCCESS)
133                 {
134                         return E_INVALID_STATE;
135                 }
136
137                 pNode = pProxyList->GetNextNode(*pNode);
138         }
139
140         return E_SUCCESS;
141 }
142
143 }}} // Tizen::Ui::_Layout