2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUi_LayoutLayoutItem.cpp
19 * @brief This is the implementation file for LayoutItem class.
21 * This file contains the implementation of LayoutItem class.
24 #include "FUi_Control.h"
25 #include "FUi_LayoutLayoutItem.h"
26 #include "FUi_LayoutLayout.h"
28 namespace Tizen { namespace Ui { namespace _Layout
31 LayoutItem::LayoutItem(void)
32 : __pOuterControl(null)
33 , __pParentContainer(null)
39 LayoutItem::~LayoutItem(void)
41 if (__pParentContainer != null)
43 __pParentContainer->OnDestroyItem(*this);
48 LayoutItem::SetItemHandler(ILayoutItemHandler* pOuterControl)
50 __pOuterControl = pOuterControl;
54 LayoutItem::SetItemWindowRect(const LayoutRect layoutRect)
56 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
58 Tizen::Graphics::Rectangle rect(layoutRect.x, layoutRect.y, layoutRect.w, layoutRect.h);
59 return __pOuterControl->SetItemBounds(rect);
63 LayoutItem::GetItemWindowRect(LayoutRect& LayoutRect) const
65 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
67 Tizen::Graphics::Rectangle rect = __pOuterControl->GetItemBounds();
69 LayoutRect.x = rect.x;
70 LayoutRect.y = rect.y;
71 LayoutRect.w = rect.width;
72 LayoutRect.h = rect.height;
76 LayoutItem::ConvertWindowToClientBounds(const LayoutRect windowRect, LayoutRect& clientRect)
78 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
80 Tizen::Graphics::Dimension size(windowRect.w, windowRect.h);
81 Tizen::Graphics::Rectangle rect = __pOuterControl->GetItemClientBoundsFromSize(size);
83 clientRect.x = rect.x;
84 clientRect.y = rect.y;
85 clientRect.w = rect.width;
86 clientRect.h = rect.height;
90 LayoutItem::Measure(int width, int height)
92 LayoutContainer* pContainer = __pParentContainer;
93 if (pContainer == null)
95 return E_INVALID_STATE;
98 Layout* pLayout = pContainer->GetLayout();
101 return E_INVALID_STATE;
104 LayoutMatchMode widthMode;
105 LayoutMatchMode heightMode;
106 result re = E_SYSTEM;
107 re = pLayout->GetItemWidthMatchMode(*this, widthMode);
112 re = pLayout->GetItemHeightMatchMode(*this, heightMode);
118 LayoutRect layoutRect = pLayout->GetLayoutRect();
120 LayoutMatchMode containerWidthMode = NONE_MODE;
121 LayoutMatchMode containerHeightMode = NONE_MODE;
123 LayoutContainer* pContainerParent = pContainer->GetParentContainer();
124 if (pContainerParent != null)
126 re = pContainerParent->GetLayout()->GetItemWidthMatchMode(*pContainer, containerWidthMode);
131 re = pContainerParent->GetLayout()->GetItemHeightMatchMode(*pContainer, containerHeightMode);
138 LayoutSize containerSize = pContainer->GetIntendedWindowSize();
140 int measuredWidth = 0;
141 int measuredHeight = 0;
143 int wrapContentWidth = 0;
144 int wrapContentHeight = 0;
146 Tizen::Graphics::Dimension size = __pOuterControl->GetItemContentSize();
148 wrapContentWidth = size.width;
149 wrapContentHeight = size.height;
151 if (widthMode == NONE_MODE)
153 measuredWidth = width;
155 else if (widthMode == WRAP_CONTENT)
157 measuredWidth = wrapContentWidth;
159 else if (widthMode == MATCH_PARENT)
161 if (containerWidthMode != WRAP_CONTENT)
163 measuredWidth = containerSize.w;
167 measuredWidth = layoutRect.w;
171 if (heightMode == NONE_MODE)
173 measuredHeight = height;
175 else if (heightMode == WRAP_CONTENT)
177 measuredHeight = wrapContentHeight;
179 else if (heightMode == MATCH_PARENT)
181 if (containerHeightMode != WRAP_CONTENT)
183 measuredHeight = containerSize.h;
187 measuredHeight = layoutRect.h;
191 RunItemMeasure(measuredWidth, measuredHeight);
196 Tizen::Graphics::Dimension controlMinSize = __pOuterControl->GetItemMinimumSize();
197 Tizen::Graphics::Dimension controlMaxSize = __pOuterControl->GetItemMaximumSize();
199 minSize.w = controlMinSize.width;
200 minSize.h = controlMinSize.height;
202 maxSize.w = controlMaxSize.width;
203 maxSize.h = controlMaxSize.height;
205 if (measuredWidth < minSize.w)
207 measuredWidth = minSize.w;
209 else if (measuredWidth > maxSize.w)
211 measuredWidth = maxSize.w;
214 if (measuredHeight < minSize.h)
216 measuredHeight = minSize.h;
218 else if (measuredHeight > maxSize.h)
220 measuredHeight = maxSize.h;
223 SetMeasuredSize(measuredWidth, measuredHeight);
229 LayoutItem::RunItemMeasure(int& width, int& height)
231 __pOuterControl->OnItemMeasure(width, height);
235 LayoutItem::Visible(bool visible)
237 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
239 __pOuterControl->SetItemVisibleState(visible);
243 LayoutItem::SetParentContainer(LayoutContainer* pParentContainer)
245 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
246 __pParentContainer = pParentContainer;
250 LayoutItem::GetParentContainer(void) const
252 return __pParentContainer;
256 LayoutItem::SetMeasuredSize(int width, int height)
258 __measuredSize.w = width;
259 __measuredSize.h = height;
263 LayoutItem::GetMeasuredSize(int& width, int& height) const
265 width = __measuredSize.w;
266 height = __measuredSize.h;
270 LayoutItem::GetMinSize(LayoutSize& minSize) const
272 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
273 Tizen::Graphics::Dimension controlMinSize = __pOuterControl->GetItemMinimumSize();
275 minSize.w = controlMinSize.width;
276 minSize.h = controlMinSize.height;
280 LayoutItem::GetMaxSize(LayoutSize& maxSize) const
282 SysAssertf(__pOuterControl != null, "Did not set a ILayoutItemHandler.");
283 Tizen::Graphics::Dimension controlMaxSize = __pOuterControl->GetItemMaximumSize();
285 maxSize.w = controlMaxSize.width;
286 maxSize.h = controlMaxSize.height;
290 LayoutItem::GetIncludedLayout(void) const
292 if (__pParentContainer != null)
294 return __pParentContainer->GetLayout();
300 LayoutItem::OnChangeBaseRect(void)
302 Layout* pLayout = GetIncludedLayout();
305 return E_INVALID_STATE;
308 GetItemWindowRect(rect);
310 return pLayout->SetItemBaseRect(*this, rect);
313 }}} // Tizen::Ui::_Layout