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 FUiCtrl_SimpleItemImpl.cpp
20 * @brief This is the implementation file for _SimpleItemImpl class.
22 * This file contains the implementation of _SimpleItemImpl class.
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlSimpleItem.h>
27 #include "FUi_CoordinateSystemUtils.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_ListViewItem.h"
30 #include "FUiCtrl_SimpleItemImpl.h"
32 #ifdef MEMORY_LEAK_CHECK
33 #include "mem_leak_check.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Graphics::_Text;
40 namespace Tizen { namespace Ui { namespace Controls
43 _SimpleItemImpl::_SimpleItemImpl(SimpleItem* pPublic)
44 : _ListItemBaseImpl(pPublic)
49 _SimpleItemImpl::~_SimpleItemImpl(void)
55 _SimpleItemImpl::GetPublic(void)
57 return static_cast <SimpleItem&>(_ListItemBaseImpl::GetPublic());
61 _SimpleItemImpl::GetPublic(void) const
63 return static_cast <const SimpleItem&>(_ListItemBaseImpl::GetPublic());
67 _SimpleItemImpl::GetPublicClassName(void) const
69 return "Tizen::Ui::Controls::SimpleItem";
73 _SimpleItemImpl::CreateSimpleItemImplN(SimpleItem* pPublic, const FloatDimension& itemSize, ListAnnexStyle style)
77 _SimpleItemImpl* pImpl = new (std::nothrow) _SimpleItemImpl(pPublic);
78 SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
80 r = pImpl->Construct(itemSize, style);
81 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] Unable to construct _SimpleItemImpl.");
93 _SimpleItemImpl::Construct(const FloatDimension& itemSize, ListAnnexStyle style)
95 result r = _ListItemBaseImpl::Construct(itemSize, style);
96 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98 GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_SIMPLE);
100 SetLastResultReturn(r);
104 _SimpleItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
107 _ListViewItem* pItem = GetListViewItem();
109 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
111 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
112 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
115 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
117 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
118 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
121 FloatRectangle bitmapRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
122 FloatRectangle textRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
123 ListAnnexStyle style = GetListItemAnnexStyle();
124 float leftMargin = 0.0f;
125 float itemHeight = GetItemSize().height;
126 float annexWidth = 0.0f;
127 float elementSpacing = 0.0f;
128 float textSize = 0.0f;
129 result r = E_SUCCESS;
131 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
132 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
133 GET_SHAPE_CONFIG(LISTVIEW::ITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textSize);
135 bitmapRect.x += leftMargin;
137 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
139 bitmapRect.x += GetAnnexWidth(style) + elementSpacing;
143 annexWidth = GetAnnexWidth(style);
146 // Add Bitmap element (optional)
149 float elementWidth = itemHeight * SIMPLE_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
150 float elementHeight = elementWidth;
152 bitmapRect.y = (itemHeight - elementHeight) / 2.0f;
153 bitmapRect.width = elementWidth;
154 bitmapRect.height = elementHeight;
156 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
157 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
161 elementSpacing = 0.0f;
165 textRect.x = bitmapRect.x + bitmapRect.width + elementSpacing;
167 textRect.width = GetItemSize().width - textRect.x - ((annexWidth > 0.0f) ? (annexWidth + leftMargin) : 0.0f);
168 textRect.height = itemHeight;
170 r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
171 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
173 pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, textSize);
174 pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
179 }}} // Tizen::Ui::Controls