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_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 "FUiCtrl_GroupItemImpl.h"
29 #include "FUiCtrl_ListViewItem.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
43 _GroupItemImpl::GetInstance(GroupItem& groupItem)
45 return groupItem._pImpl;
49 _GroupItemImpl::GetInstance(const GroupItem& groupItem)
51 return groupItem._pImpl;
54 _GroupItemImpl::_GroupItemImpl(GroupItem* pPublic)
55 : _ListItemBaseImpl(null)
57 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __textSize);
58 GET_COLOR_CONFIG(LISTVIEW::GROUPITEM_TEXT_NORMAL, __textColor);
61 _GroupItemImpl::~_GroupItemImpl(void)
67 _GroupItemImpl::GetPublicClassName(void) const
69 return "Tizen::Ui::Controls::GroupItem";
73 _GroupItemImpl::CreateGroupItemImpN(GroupItem* pPublic, const Dimension& itemSize)
77 _GroupItemImpl* pImpl = new (std::nothrow) _GroupItemImpl(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);
81 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
93 _GroupItemImpl::Construct(const Dimension& itemSize)
95 result r = _ListItemBaseImpl::Construct(itemSize, LIST_ANNEX_STYLE_NORMAL);
96 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98 _ListViewItem* pItem = GetListViewItem();
100 pItem->SetListViewItemType(LISTVIEW_ITEM_TYPE_GROUP);
101 pItem->SetItemDividerEnabled(false);
103 r = SetBackgroundColor(GetBackgroundColor());
105 SetLastResultReturn(r);
109 _GroupItemImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
111 return _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL, pBitmap);
115 _GroupItemImpl::SetBackgroundColor(const Color& color)
117 result r = E_SUCCESS;
119 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, color);
120 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, color);
121 r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, color);
127 _GroupItemImpl::GetBackgroundColor(void) const
129 return _ListItemBaseImpl::GetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL);
133 _GroupItemImpl::SetTextColor(const Color& color)
135 _ListViewItem* pItem = GetListViewItem();
137 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
141 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_NORMAL);
142 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
144 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_PRESSED);
145 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
147 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
148 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
157 _GroupItemImpl::GetTextColor(void) const
163 _GroupItemImpl::SetTextSize(int size)
167 _ListViewItem* pItem = GetListViewItem();
168 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
170 bool ret = pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, size);
172 return (ret ? E_SUCCESS : E_SYSTEM);
179 _GroupItemImpl::GetTextSize(void) const
185 _GroupItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
188 _ListViewItem* pItem = GetListViewItem();
190 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
192 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
193 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
196 if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
198 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
199 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
202 Rectangle bitmapRect = Rectangle(0, 0, 0, 0);
203 Rectangle textRect = Rectangle(0, 0, 0, 0);
205 int itemHeight = GetItemSize().height;
206 int elementSpacing = 0;
207 result r = E_SUCCESS;
209 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
211 // Add Bitmap element (optional)
214 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
216 int elementWidth = itemHeight * GROUP_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
217 int elementHeight = elementWidth;
219 bitmapRect.x = leftMargin;
220 bitmapRect.y = (itemHeight - elementHeight) / 2;
221 bitmapRect.width = elementWidth;
222 bitmapRect.height = elementHeight;
224 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
225 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
229 textRect.x = leftMargin + bitmapRect.width + elementSpacing;
231 textRect.width = GetItemSize().width - textRect.x;
232 textRect.height = itemHeight;
234 r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
235 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
237 pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, __textSize);
238 pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
240 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_NORMAL);
241 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_PRESSED);
242 pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
247 }}} // Tizen::Ui::Controls