Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GroupItemImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file        FUiCtrl_GroupItemImpl.cpp
20  * @brief       This is the implementation file for the GroupItemImpl class.
21  *
22  * This header file contains the declarations of the GroupItemImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlGroupItem.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUiCtrl_GroupItemImpl.h"
29 #include "FUiCtrl_ListViewItem.h"
30
31 #ifdef MEMORY_LEAK_CHECK
32 #include "mem_leak_check.h"
33 #endif
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42 _GroupItemImpl*
43 _GroupItemImpl::GetInstance(GroupItem& groupItem)
44 {
45         return groupItem._pImpl;
46 }
47
48 const _GroupItemImpl*
49 _GroupItemImpl::GetInstance(const GroupItem& groupItem)
50 {
51         return groupItem._pImpl;
52 }
53
54 _GroupItemImpl::_GroupItemImpl(GroupItem* pPublic)
55         : _ListItemBaseImpl(null)
56 {
57         GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __textSize);
58         GET_COLOR_CONFIG(LISTVIEW::GROUPITEM_TEXT_NORMAL, __textColor);
59 }
60
61 _GroupItemImpl::~_GroupItemImpl(void)
62 {
63
64 }
65
66 const char*
67 _GroupItemImpl::GetPublicClassName(void) const
68 {
69         return "Tizen::Ui::Controls::GroupItem";
70 }
71
72 _GroupItemImpl*
73 _GroupItemImpl::CreateGroupItemImpN(GroupItem* pPublic, const Dimension& itemSize)
74 {
75         result r = E_SUCCESS;
76
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.");
79
80         r = pImpl->Construct(itemSize);
81         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
82
83         return pImpl;
84
85 CATCH:
86         delete pImpl;
87         pImpl = null;
88
89         return null;
90 }
91
92 result
93 _GroupItemImpl::Construct(const Dimension& itemSize)
94 {
95         result r = _ListItemBaseImpl::Construct(itemSize, LIST_ANNEX_STYLE_NORMAL);
96         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
97
98         _ListViewItem* pItem = GetListViewItem();
99
100         pItem->SetListViewItemType(LISTVIEW_ITEM_TYPE_GROUP);
101         pItem->SetItemDividerEnabled(false);
102
103         r = SetBackgroundColor(GetBackgroundColor());
104
105         SetLastResultReturn(r);
106 }
107
108 result
109 _GroupItemImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
110 {
111         return _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL, pBitmap);
112 }
113
114 result
115 _GroupItemImpl::SetBackgroundColor(const Color& color)
116 {
117         result r = E_SUCCESS;
118
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);
122
123         return r;
124 }
125
126 Color
127 _GroupItemImpl::GetBackgroundColor(void) const
128 {
129         return _ListItemBaseImpl::GetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL);
130 }
131
132 result
133 _GroupItemImpl::SetTextColor(const Color& color)
134 {
135         _ListViewItem* pItem = GetListViewItem();
136
137         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
138         {
139                 bool ret = false;
140
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.");
143
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.");
146
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.");
149         }
150
151         __textColor = color;
152
153         return E_SUCCESS;
154 }
155
156 Color
157 _GroupItemImpl::GetTextColor(void) const
158 {
159         return __textColor;
160 }
161
162 result
163 _GroupItemImpl::SetTextSize(int size)
164 {
165         __textSize = size;
166
167         _ListViewItem* pItem = GetListViewItem();
168         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
169         {
170                 bool ret = pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, size);
171
172                 return (ret ? E_SUCCESS : E_SYSTEM);
173         }
174
175         return E_SUCCESS;
176 }
177
178 int
179 _GroupItemImpl::GetTextSize(void) const
180 {
181         return __textSize;
182 }
183
184 result
185 _GroupItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
186 {
187         bool ret = false;
188         _ListViewItem* pItem = GetListViewItem();
189
190         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
191         {
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.");
194         }
195
196         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
197         {
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.");
200         }
201
202         Rectangle bitmapRect = Rectangle(0, 0, 0, 0);
203         Rectangle textRect = Rectangle(0, 0, 0, 0);
204         int leftMargin = 0;
205         int itemHeight = GetItemSize().height;
206         int elementSpacing = 0;
207         result r = E_SUCCESS;
208
209         GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
210
211         // Add Bitmap element (optional)
212         if (pBitmap != null)
213         {
214                 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
215
216                 int elementWidth = itemHeight * GROUP_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
217                 int elementHeight = elementWidth;
218
219                 bitmapRect.x = leftMargin;
220                 bitmapRect.y = (itemHeight - elementHeight) / 2;
221                 bitmapRect.width = elementWidth;
222                 bitmapRect.height = elementHeight;
223
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()));
226         }
227
228         // Add Text element
229         textRect.x = leftMargin + bitmapRect.width + elementSpacing;
230         textRect.y = 0;
231         textRect.width = GetItemSize().width - textRect.x;
232         textRect.height = itemHeight;
233
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()));
236
237         pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, __textSize);
238         pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
239
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);
243
244         return E_SUCCESS;
245 }
246
247 }}} // Tizen::Ui::Controls