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_GroupItemImpl.cpp
20 * @brief This is the implementation file for the GroupItemImpl class.
22 * This header file contains the declarations of the GroupItemImpl class.
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlGroupItem.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUiCtrl_GroupItemImpl.h"
30 #include "FUiCtrl_ListViewItem.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
44 _GroupItemImpl::GetInstance(GroupItem& groupItem)
46 return groupItem._pImpl;
50 _GroupItemImpl::GetInstance(const GroupItem& groupItem)
52 return groupItem._pImpl;
55 _GroupItemImpl::_GroupItemImpl(GroupItem* pPublic)
56 : _ListItemBaseImpl(null)
58 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __textSize);
59 GET_COLOR_CONFIG(TABLEVIEW::GROUPITEM_TEXT_NORMAL, __textColor);
62 _GroupItemImpl::~_GroupItemImpl(void)
68 _GroupItemImpl::GetPublicClassName(void) const
70 return "Tizen::Ui::Controls::GroupItem";
74 _GroupItemImpl::CreateGroupItemImpN(GroupItem* pPublic, const FloatDimension& itemSize)
78 _GroupItemImpl* pImpl = new (std::nothrow) _GroupItemImpl(pPublic);
79 SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
81 r = pImpl->Construct(itemSize);
82 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
94 _GroupItemImpl::Construct(const FloatDimension& itemSize)
96 result r = _ListItemBaseImpl::Construct(itemSize, LIST_ANNEX_STYLE_NORMAL);
97 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
99 _ListViewItem* pItem = GetListViewItem();
101 pItem->SetListViewItemType(LISTVIEW_ITEM_TYPE_GROUP);
102 pItem->SetItemDividerEnabled(false);
103 pItem->SetItemTapSoundEnabled(false);
105 r = SetBackgroundColor(GetBackgroundColor());
107 SetLastResultReturn(r);
111 _GroupItemImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
113 result r = E_SUCCESS;
115 r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL, pBitmap);
116 r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED, pBitmap);
117 r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, pBitmap);
123 _GroupItemImpl::SetBackgroundColor(const Color& color)
125 result r = E_SUCCESS;
127 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, color);
128 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, color);
129 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, color);
135 _GroupItemImpl::GetBackgroundColor(void) const
137 return _ListItemBaseImpl::GetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL);
141 _GroupItemImpl::SetTextColor(const Color& color)
143 _ListViewItem* pItem = GetListViewItem();
145 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
149 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_NORMAL);
150 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
152 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_PRESSED);
153 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
155 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
156 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
165 _GroupItemImpl::GetTextColor(void) const
171 _GroupItemImpl::SetTextSize(float size)
175 _ListViewItem* pItem = GetListViewItem();
176 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
178 bool ret = pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, size);
180 return (ret ? E_SUCCESS : E_SYSTEM);
187 _GroupItemImpl::GetTextSize(void) const
193 _GroupItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
196 _ListViewItem* pItem = GetListViewItem();
198 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
200 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
201 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
204 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
206 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
207 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
210 FloatRectangle bitmapRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
211 FloatRectangle textRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
212 float leftMargin = 0.0f;
213 float itemHeight = GetItemSize().height;
214 float elementSpacing = 0.0f;
215 result r = E_SUCCESS;
217 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
219 // Add Bitmap element (optional)
222 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
224 float elementWidth = itemHeight * GROUP_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
225 float elementHeight = elementWidth;
227 bitmapRect.x = leftMargin;
228 bitmapRect.y = (itemHeight - elementHeight) / 2.0f;
229 bitmapRect.width = elementWidth;
230 bitmapRect.height = elementHeight;
232 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
233 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
237 textRect.x = leftMargin + bitmapRect.width + elementSpacing;
239 textRect.width = GetItemSize().width - textRect.x;
240 textRect.height = itemHeight;
242 r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
243 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
245 pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, __textSize);
246 pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
248 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_NORMAL);
249 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_PRESSED);
250 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
255 }}} // Tizen::Ui::Controls