Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / layout / FUi_LayoutLayoutItemProxy.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_LayoutLayoutItemProxy.cpp
19  * @brief       This is the implementation file for LayoutItemProxy class.
20  *
21  * This file contains the implementation of LayoutItemProxy class.
22  */
23
24 #include <new>
25 #include <FBaseSysLog.h>
26 #include "FUi_LayoutLayoutItemProxy.h"
27 #include "FUi_LayoutLayoutContainer.h"
28
29 namespace Tizen { namespace Ui { namespace _Layout
30 {
31
32 LayoutItemProxy::LayoutItemProxy(LayoutItem& pRealItem)
33         : __index(-1)
34         , __pItem(&pRealItem)
35         , __widthMatchmode(NONE_MODE)
36         , __heightMatchmode(NONE_MODE)
37         , __pParentLayout(null)
38 {
39         __itemAlign.HAlign = ITEM_HORIZONTAL_ALIGN_LEFT;
40         __itemAlign.VAlign = ITEM_VERTICAL_ALIGN_TOP;
41         LayoutRect rect = {0, 0, 0, 0};
42         ItemMargin margin = {0, 0, 0, 0};
43         __itemMargin = margin;
44         __baseRect = rect;
45         __calculatedRect = rect;
46 }
47
48 LayoutItemProxy::~LayoutItemProxy()
49 {
50 }
51
52 LayoutItemProxy*
53 LayoutItemProxy::Create(Layout& pLayout, LayoutItem& pRealItem)
54 {
55         LayoutItemProxy* pItemProxy = new (std::nothrow) LayoutItemProxy(pRealItem);
56
57         return pItemProxy;
58 }
59
60 void
61 LayoutItemProxy::Destroy()
62 {
63         LayoutContainer* pContainer = dynamic_cast <LayoutContainer*>(GetItem());
64         if (pContainer)
65         {
66                 pContainer->OnDestroyContainerProxy();
67         }
68         delete this;
69 }
70
71 int
72 LayoutItemProxy::GetIndex(void) const
73 {
74         return __index;
75 }
76
77 LayoutItem*
78 LayoutItemProxy::GetItem() const
79 {
80         return __pItem;
81 }
82
83 void
84 LayoutItemProxy::SetItemAlignment(ItemAlign align)
85 {
86         __itemAlign = align;
87 }
88
89 ItemAlign
90 LayoutItemProxy::GetItemAlignment(void) const
91 {
92         return __itemAlign;
93 }
94
95 void
96 LayoutItemProxy::SetItemMargin(ItemMargin margin)
97 {
98         __itemMargin = margin;
99 }
100
101 ItemMargin
102 LayoutItemProxy::GetItemMargin(void) const
103 {
104         return __itemMargin;
105 }
106
107 void
108 LayoutItemProxy::SetItemWidthMatchMode(LayoutMatchMode matchMode)
109 {
110         __widthMatchmode = matchMode;
111 }
112
113 LayoutMatchMode
114 LayoutItemProxy::GetItemWidthMatchMode(void) const
115 {
116         return __widthMatchmode;
117 }
118
119 void
120 LayoutItemProxy::SetItemHeightMatchMode(LayoutMatchMode matchMode)
121 {
122         __heightMatchmode = matchMode;
123 }
124
125 LayoutMatchMode
126 LayoutItemProxy::GetItemHeightMatchMode(void) const
127 {
128         return __heightMatchmode;
129 }
130
131 void
132 LayoutItemProxy::SetItemBaseRect(LayoutRect rect)
133 {
134         __baseRect = rect;
135 }
136
137 LayoutRect
138 LayoutItemProxy::GetItemBaseRect() const
139 {
140         return __baseRect;
141 }
142
143 void
144 LayoutItemProxy::SetMeasuredSize(int width, int height)
145 {
146         SysAssertf(__pItem != null, "LayoutItem is invalid");
147         __pItem->SetMeasuredSize(width, height);
148 }
149
150 void
151 LayoutItemProxy::GetMeasuredSize(int& width, int& height) const
152 {
153         SysAssertf(__pItem != null, "LayoutItem is invalid");
154         __pItem->GetMeasuredSize(width, height);
155 }
156
157 result
158 LayoutItemProxy::SetItemWindowRect(const LayoutRect itemRect, bool calculating)
159 {
160         SysAssertf(__pItem != null, "LayoutItem is invalid");
161         if (calculating)
162         {
163                 __calculatedRect = itemRect;
164
165                 return E_SUCCESS;
166         }
167         else
168         {
169                 return __pItem->SetItemWindowRect(itemRect);
170         }
171 }
172
173 void
174 LayoutItemProxy::GetItemWindowRect(LayoutRect& itemRect) const
175 {
176         SysAssertf(__pItem != null, "LayoutItem is invalid");
177         if (__calculatedRect.x == 0 && __calculatedRect.y == 0 && __calculatedRect.w == 0 && __calculatedRect.h == 0)
178         {
179                 __pItem->GetItemWindowRect(itemRect);
180         }
181         else
182         {
183                 itemRect = __calculatedRect;
184         }
185 }
186
187 void
188 LayoutItemProxy::ConvertWindowToClientBounds(const LayoutRect windowRect, LayoutRect& clientRect)
189 {
190         SysAssertf(__pItem != null, "LayoutItem is invalid");
191         __pItem->ConvertWindowToClientBounds(windowRect, clientRect);
192 }
193
194 result
195 LayoutItemProxy::Measure(int width, int height)
196 {
197         SysAssertf(__pItem != null, "LayoutItem is invalid");
198         return __pItem->Measure(width, height);
199 }
200
201 void
202 LayoutItemProxy::Visible(const bool visible)
203 {
204         SysAssertf(__pItem != null, "LayoutItem is invalid");
205         __pItem->Visible(visible);
206 }
207
208 void
209 LayoutItemProxy::SetParentLayout(Layout* pLayout)
210 {
211         __pParentLayout = pLayout;
212 }
213
214 Layout*
215 LayoutItemProxy::GetParentLayout() const
216 {
217         return __pParentLayout;
218 }
219
220 void
221 LayoutItemProxy::SetIndex(int index)
222 {
223         __index = index;
224 }
225
226 void
227 LayoutItemProxy::GetMinSize(LayoutSize& minSize) const
228 {
229         SysAssertf(__pItem != null, "LayoutItem is invalid");
230         __pItem->GetMinSize(minSize);
231 }
232
233 void
234 LayoutItemProxy::GetMaxSize(LayoutSize& maxSize) const
235 {
236         SysAssertf(__pItem != null, "LayoutItem is invalid");
237         __pItem->GetMaxSize(maxSize);
238 }
239
240 void
241 LayoutItemProxy::SetParentContainer(LayoutContainer* pParentContainer)
242 {
243         SysAssertf(__pItem != null, "LayoutItem is invalid");
244         __pItem->SetParentContainer(pParentContainer);
245 }
246
247 LayoutContainer*
248 LayoutItemProxy::GetParentContainer() const
249 {
250         SysAssertf(__pItem != null, "LayoutItem is invalid");
251         return __pItem->GetParentContainer();
252 }
253
254 }}} // Tizen::Ui::_Layout