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.
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_ResourceManager.h"
28 #include "FUiCtrl_ListViewItem.h"
29 #include "FUiCtrl_SimpleItemImpl.h"
31 #ifdef MEMORY_LEAK_CHECK
32 #include "mem_leak_check.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
39 namespace Tizen { namespace Ui { namespace Controls
42 _SimpleItemImpl::_SimpleItemImpl(SimpleItem* pPublic)
43 : _ListItemBaseImpl(pPublic)
48 _SimpleItemImpl::~_SimpleItemImpl(void)
54 _SimpleItemImpl::GetPublic(void)
56 return static_cast <SimpleItem&>(_ListItemBaseImpl::GetPublic());
60 _SimpleItemImpl::GetPublic(void) const
62 return static_cast <const SimpleItem&>(_ListItemBaseImpl::GetPublic());
66 _SimpleItemImpl::GetPublicClassName(void) const
68 return "Tizen::Ui::Controls::SimpleItem";
72 _SimpleItemImpl::CreateSimpleItemImplN(SimpleItem* pPublic, const Dimension& itemSize, ListAnnexStyle style)
76 _SimpleItemImpl* pImpl = new (std::nothrow) _SimpleItemImpl(pPublic);
77 SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
79 r = pImpl->Construct(itemSize, style);
80 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] Unable to construct _SimpleItemImpl.");
92 _SimpleItemImpl::Construct(const Dimension& itemSize, ListAnnexStyle style)
94 result r = _ListItemBaseImpl::Construct(itemSize, style);
95 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
97 GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_SIMPLE);
99 SetLastResultReturn(r);
103 _SimpleItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
106 _ListViewItem* pItem = GetListViewItem();
108 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
110 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
111 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
114 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
116 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
117 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
120 Rectangle bitmapRect = Rectangle(0, 0, 0, 0);
121 Rectangle textRect = Rectangle(0, 0, 0, 0);
122 ListAnnexStyle style = GetListItemAnnexStyle();
124 int itemHeight = GetItemSize().height;
125 int annexWidth = GetAnnexWidth(style);
126 int elementSpacing = 0;
128 result r = E_SUCCESS;
130 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
131 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
132 GET_SHAPE_CONFIG(LISTVIEW::ITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textSize);
134 bitmapRect.x += leftMargin;
136 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
138 bitmapRect.x += GetAnnexWidth(style) + elementSpacing;
141 // Add Bitmap element (optional)
144 int elementWidth = itemHeight * SIMPLE_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
145 int elementHeight = elementWidth;
147 bitmapRect.y = (itemHeight - elementHeight) / 2;
148 bitmapRect.width = elementWidth;
149 bitmapRect.height = elementHeight;
151 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
152 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
160 textRect.x = bitmapRect.x + bitmapRect.width + elementSpacing;
162 textRect.width = GetItemSize().width - textRect.x - ((annexWidth > 0) ? (annexWidth + leftMargin) : 0);
163 textRect.height = itemHeight;
165 r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
166 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
168 pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, textSize);
169 pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
174 }}} // Tizen::Ui::Controls